From affa6c9f6865ff4e57d4a34e94b65b2fae323401 Mon Sep 17 00:00:00 2001 From: metagn <10591326+metagn@users.noreply.github.com> Date: Mon, 25 Dec 2023 20:40:54 +0300 Subject: [PATCH] explain some stuff, remove unused code --- compiler/lookups.nim | 6 ++---- compiler/semtempl.nim | 14 ++++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/compiler/lookups.nim b/compiler/lookups.nim index be5bfca736d64..2607dc18baa3b 100644 --- a/compiler/lookups.nim +++ b/compiler/lookups.nim @@ -330,7 +330,6 @@ type mode*: TOverloadIterMode symChoiceIndex*: int symChoiceLastPreferred: bool - fallback: PSym currentScope: PScope importIdx: int marked: IntSet @@ -728,6 +727,8 @@ proc initOverloadIter*(o: var TOverloadIter, c: PContext, n: PNode): PSym = of nkSym: result = n.sym if nfPreferredSym in n.flags: + # standalone sym node with nfPreferredSym acts like an open symchoice, + # see semtempl.symChoice for reasoning o.mode = oimSymChoiceLocalLookup o.symChoiceLastPreferred = true o.currentScope = c.currentScope @@ -839,9 +840,6 @@ proc nextOverloadIter*(o: var TOverloadIter, c: PContext, n: PNode): PSym = result = nextOverloadIterImports(o, c, n) else: result = nil - if result == nil and o.fallback != nil and o.fallback.id notin o.marked: - result = o.fallback - o.fallback = nil of oimSelfModule: result = nextIdentIter(o.it, c.topLevelScope.symbols) of oimOtherModule: diff --git a/compiler/semtempl.nim b/compiler/semtempl.nim index ae1d48d1d9ef0..fdfe3161a892a 100644 --- a/compiler/semtempl.nim +++ b/compiler/semtempl.nim @@ -66,20 +66,22 @@ proc symChoice(c: PContext, n: PNode, s: PSym, r: TSymChoiceRule; a = nextOverloadIter(o, c, n) let info = getCallLineInfo(n) if i <= 1 and r != scForceOpen: - # XXX this makes more sense but breaks bootstrapping for now: - # (s.kind notin routineKinds or s.magic != mNone): - # for instance 'nextTry' is both in tables.nim and astalgo.nim ... if not isField or sfGenSym notin s.flags: result = newSymNode(s, info) if r == scClosed or n.kind == nkDotExpr or + # also bind magic procs: (s.magic != mNone and s.kind in routineKinds): markUsed(c, info, s) onUse(info, s) else: - # could maybe instead generate a open symchoice with a preferred sym, - # which the logic for is in the top else branch - # XXX why have this then + # we need a node with a type here so things like default parameters, + # which use semGenericStmt, can infer the parameter type + # from expressions like `false` + # but symchoices having types can mislead the compiler + # instead we allow standalone sym nodes to have nfPreferredSym + # which acts like an open symchoice in initOverloadIter result.flags.incl nfPreferredSym + #result = newTreeIT(nkOpenSymChoice, info, result.typ, result) incl(s.flags, sfUsed) markOwnerModuleAsUsed(c, s) else: