diff options
author | metagn <metagngn@gmail.com> | 2024-08-16 07:33:43 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-16 06:33:43 +0200 |
commit | d43a5954c5e179c5ef270bb7b48bcab7288ddba5 (patch) | |
tree | dd0785a3c5dae4e81c655294f9b8ea46eb7b4dbe | |
parent | 298ada3412c9cf5971abc2b3b891b9bb8612e170 (diff) | |
download | Nim-d43a5954c5e179c5ef270bb7b48bcab7288ddba5.tar.gz |
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.
-rw-r--r-- | compiler/semstmts.nim | 4 | ||||
-rw-r--r-- | compiler/sighashes.nim | 4 | ||||
-rw-r--r-- | tests/ccgbugs/tsamename3.nim | 9 |
3 files changed, 13 insertions, 4 deletions
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 915f2dcb6..5e7aabe01 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -1785,10 +1785,6 @@ proc typeSectionFinalPass(c: PContext, n: PNode) = checkForMetaFields(c, baseType.n, hasError) if not hasError: checkConstructedType(c.config, s.info, s.typ) - - # fix bug #5170, bug #17162, bug #15526: ensure locally scoped types get a unique name: - if s.typ.kind in {tyEnum, tyRef, tyObject} and not isTopLevel(c): - incl(s.flags, sfGenSym) #instAllTypeBoundOp(c, n.info) diff --git a/compiler/sighashes.nim b/compiler/sighashes.nim index f86f86679..d8dfe1828 100644 --- a/compiler/sighashes.nim +++ b/compiler/sighashes.nim @@ -55,6 +55,8 @@ proc hashSym(c: var MD5Context, s: PSym) = c &= it.name.s c &= "." it = it.owner + c &= "#" + c &= s.disamb proc hashTypeSym(c: var MD5Context, s: PSym; conf: ConfigRef) = if sfAnon in s.flags or s.kind == skGenericParam: @@ -69,6 +71,8 @@ proc hashTypeSym(c: var MD5Context, s: PSym; conf: ConfigRef) = c &= it.name.s c &= "." it = it.owner + c &= "#" + c &= s.disamb proc hashTree(c: var MD5Context, n: PNode; flags: set[ConsiderFlag]; conf: ConfigRef) = if n == nil: diff --git a/tests/ccgbugs/tsamename3.nim b/tests/ccgbugs/tsamename3.nim index a69391e5c..ded18e9f8 100644 --- a/tests/ccgbugs/tsamename3.nim +++ b/tests/ccgbugs/tsamename3.nim @@ -109,3 +109,12 @@ block: # make sure `hashType` doesn't recurse infinitely a, b: PFoo c: int var a: PFoo + +block: # issue #22571 + macro foo(x: typed) = + result = x + + block: # or `proc main =` + foo: + type Foo = object + doAssert $Foo() == "()" |