Skip to content

Commit

Permalink
fix IC, remove redundant logic from semgnrc, consider nested owners
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Dec 18, 2023
1 parent 98f71e1 commit fd76586
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
10 changes: 6 additions & 4 deletions compiler/ic/ic.nim
Original file line number Diff line number Diff line change
Expand Up @@ -433,11 +433,11 @@ proc addModuleRef(n: PNode; ir: var PackedTree; c: var PackedEncoder; m: var Pac
let info = n.info.toPackedInfo(c, m)
if n.typ != n.sym.typ:
ir.addNode(kind = nkModuleRef, operand = 3.int32, # spans 3 nodes in total
info = info,
info = info, flags = n.flags,
typeId = storeTypeLater(n.typ, c, m))
else:
ir.addNode(kind = nkModuleRef, operand = 3.int32, # spans 3 nodes in total
info = info)
info = info, flags = n.flags)
ir.addNode(kind = nkNone, info = info,
operand = toLitId(n.sym.itemId.module.FileIndex, c, m).int32)
ir.addNode(kind = nkNone, info = info,
Expand Down Expand Up @@ -829,7 +829,8 @@ proc loadNodes*(c: var PackedDecoder; g: var PackedModuleGraph; thisModule: int;
result.ident = getIdent(c.cache, g[thisModule].fromDisk.strings[n.litId])
of nkSym:
result.sym = loadSym(c, g, thisModule, PackedItemId(module: LitId(0), item: tree[n].soperand))
if result.typ == nil: result.typ = result.sym.typ
if result.typ == nil and nfOpenSym notin result.flags:
result.typ = result.sym.typ
of externIntLit:
result.intVal = g[thisModule].fromDisk.numbers[n.litId]
of nkStrLit..nkTripleStrLit:
Expand All @@ -842,7 +843,8 @@ proc loadNodes*(c: var PackedDecoder; g: var PackedModuleGraph; thisModule: int;
assert n2.kind == nkNone
transitionNoneToSym(result)
result.sym = loadSym(c, g, thisModule, PackedItemId(module: n1.litId, item: tree[n2].soperand))
if result.typ == nil: result.typ = result.sym.typ
if result.typ == nil and nfOpenSym notin result.flags:
result.typ = result.sym.typ
else:
for n0 in sonsReadonly(tree, n):
result.addAllowNil loadNodes(c, g, thisModule, tree, n0)
Expand Down
11 changes: 8 additions & 3 deletions compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3071,9 +3071,14 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}, expectedType: PType
let id = newIdentNode(s.name, n.info)
c.isAmbiguous = false
let s2 = qualifiedLookUp(c, id, {})
if s2 != nil and s2 != s and not c.isAmbiguous and s2.owner == c.p.owner:
result = semExpr(c, id, flags, expectedType)
return
if s2 != nil and s2 != s and not c.isAmbiguous:
# only consider symbols defined under current proc:
var o = s2.owner
while o != nil:
if o == c.p.owner:
result = semExpr(c, id, flags, expectedType)
return
o = o.owner
# because of the changed symbol binding, this does not mean that we
# don't have to check the symbol for semantics here again!
result = semSym(c, n, s, flags)
Expand Down
11 changes: 1 addition & 10 deletions compiler/semgnrc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -237,16 +237,7 @@ proc semGenericStmt(c: PContext, n: PNode,
var dummy: bool
result = fuzzyLookup(c, n, flags, ctx, dummy)
of nkSym:
var a = n.sym
if nfOpenSym in n.flags:
let id = newIdentNode(a.name, n.info)
c.isAmbiguous = false
let s2 = qualifiedLookUp(c, id, {})
if s2 != nil and s2 != a and not c.isAmbiguous and s2.owner == c.p.owner:
n.sym = s2
a = s2
if {withinMixin, withinConcept} * flags != {withinMixin}:
n.flags.excl nfOpenSym
let a = n.sym
let b = getGenSym(c, a)
if b != a: n.sym = b
of nkEmpty, succ(nkSym)..nkNilLit, nkComesFrom:
Expand Down

0 comments on commit fd76586

Please sign in to comment.