Skip to content

Commit

Permalink
explain some stuff, remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Dec 25, 2023
1 parent d6dac90 commit affa6c9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
6 changes: 2 additions & 4 deletions compiler/lookups.nim
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@ type
mode*: TOverloadIterMode
symChoiceIndex*: int
symChoiceLastPreferred: bool
fallback: PSym
currentScope: PScope
importIdx: int
marked: IntSet
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
14 changes: 8 additions & 6 deletions compiler/semtempl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit affa6c9

Please sign in to comment.