Skip to content

Commit d43a595

Browse files
authored
remove nontoplevel type hack + consider symbol disamb in type hash (#23969)
fixes #22571 Removes the hack added in #13589 which made non-top-level object type symbols `gensym` because they couldn't be mangled into different names for codegen vs. top-level types. Now we consider the new `disamb` field (added in #21667) of the type symbols in the type hash (which is used for the mangled name) to differentiate between the types. In other parts of the compiler, specifically the [proc mangling](https://github.com/nim-lang/Nim/blob/298ada3412c9cf5971abc2b3b891b9bb8612e170/compiler/mangleutils.nim#L59), `itemId.item` is used instead of the `disamb` field, but I didn't use it in case it's the outdated method.
1 parent 298ada3 commit d43a595

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

compiler/semstmts.nim

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1785,10 +1785,6 @@ proc typeSectionFinalPass(c: PContext, n: PNode) =
17851785
checkForMetaFields(c, baseType.n, hasError)
17861786
if not hasError:
17871787
checkConstructedType(c.config, s.info, s.typ)
1788-
1789-
# fix bug #5170, bug #17162, bug #15526: ensure locally scoped types get a unique name:
1790-
if s.typ.kind in {tyEnum, tyRef, tyObject} and not isTopLevel(c):
1791-
incl(s.flags, sfGenSym)
17921788
#instAllTypeBoundOp(c, n.info)
17931789

17941790

compiler/sighashes.nim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ proc hashSym(c: var MD5Context, s: PSym) =
5555
c &= it.name.s
5656
c &= "."
5757
it = it.owner
58+
c &= "#"
59+
c &= s.disamb
5860

5961
proc hashTypeSym(c: var MD5Context, s: PSym; conf: ConfigRef) =
6062
if sfAnon in s.flags or s.kind == skGenericParam:
@@ -69,6 +71,8 @@ proc hashTypeSym(c: var MD5Context, s: PSym; conf: ConfigRef) =
6971
c &= it.name.s
7072
c &= "."
7173
it = it.owner
74+
c &= "#"
75+
c &= s.disamb
7276

7377
proc hashTree(c: var MD5Context, n: PNode; flags: set[ConsiderFlag]; conf: ConfigRef) =
7478
if n == nil:

tests/ccgbugs/tsamename3.nim

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,12 @@ block: # make sure `hashType` doesn't recurse infinitely
109109
a, b: PFoo
110110
c: int
111111
var a: PFoo
112+
113+
block: # issue #22571
114+
macro foo(x: typed) =
115+
result = x
116+
117+
block: # or `proc main =`
118+
foo:
119+
type Foo = object
120+
doAssert $Foo() == "()"

0 commit comments

Comments
 (0)