Skip to content

Conversation

@ringabout
Copy link
Member

@ringabout ringabout commented Jan 18, 2023

fixes #20139

hashTypeSym is used to calculate the hash of a type symbol. To differentiate modules with the same name but in the different paths of a package, we can consider its relative path to its package path.

c &= relativePath(conf.toFullPath(s.info), conf.toFullPath(getPackageSymbol(s).info), '/')

@ringabout ringabout changed the title fixes #20139; hash types based on its path relative to its project path fixes #20139; hash types based on its path relative to its package path Jan 18, 2023
@ringabout ringabout marked this pull request as ready for review January 18, 2023 12:09
@Varriount Varriount requested a review from Araq January 18, 2023 18:08
@Varriount Varriount added the Requires Araq To Merge PR should only be merged by Araq label Jan 18, 2023
@Araq
Copy link
Member

Araq commented Jan 18, 2023

Seems excessive, isn't there an easier way?

@quantimnot
Copy link
Contributor

@ringabout How about including ast.hash(ast.ItemId) into the symbol hashes? I'm not sure of negative consequences, but it seems to work for me. I haven't run the full test suite though.

Here is what I tried:

+template includeIdHash(c: var MD5Context, s: PSym) =
+  # Include the symbol ID to disambiguate symbols with identical names and
+  # identical module names. (bug #20139)
+  c &= hash(s.itemId)

proc hashSym(c: var MD5Context, s: PSym) =
+  includeIdHash(c, s)
  if sfAnon in s.flags or s.kind == skGenericParam:
    c &= ":anon"
  else:
    var it = s
    while it != nil:
      c &= it.name.s
      c &= "."
      it = it.owner

proc hashTypeSym(c: var MD5Context, s: PSym) =
+  includeIdHash(c, s)
  if sfAnon in s.flags or s.kind == skGenericParam:
    c &= ":anon"
  else:
    var it = s
    while it != nil:
      if sfFromGeneric in it.flags and it.kind in routineKinds and
          it.typ != nil:
        hashType c, it.typ, {CoProc}
      c &= it.name.s
      c &= "."
      it = it.owner

@ringabout
Copy link
Member Author

I'm not sure whether it is consistent enough, see also #20564 (comment)

@ringabout
Copy link
Member Author

@Araq Could we use what @quantimnot suggested or is there another way out?

arnetheduck added a commit to status-im/Nim that referenced this pull request Feb 25, 2023
@Araq
Copy link
Member

Araq commented Mar 1, 2023

My own "superior" solution ended up being nearly identical... :-)

@Araq Araq added merge_when_passes_CI mergeable once green and removed Requires Araq To Merge PR should only be merged by Araq labels Mar 1, 2023
@arnetheduck
Copy link
Contributor

a backport to 1.6 would be appreciated here - this completely cripples 1.6 both compile-time and runtime depending on the shape of objects

@Araq Araq removed the merge_when_passes_CI mergeable once green label Mar 1, 2023
@Araq
Copy link
Member

Araq commented Mar 1, 2023

"path relative to its package path" is still wrong or at least inflexible. --> Wait for my change on top of this PR.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2023

Thanks for your hard work on this PR!
The lines below are statistics of the Nim compiler built from 38d299d

Hint: mm: orc; opt: speed; options: -d:release
166278 lines; 8.249s; 612.445MiB peakmem

@ringabout ringabout mentioned this pull request Mar 6, 2023
mjfh added a commit to status-im/Nim that referenced this pull request Mar 8, 2023
narimiran pushed a commit to narimiran/Nim that referenced this pull request Mar 9, 2023
…ckage path (nim-lang#21274) [backport:1.6]

* fixes nim-lang#20139; hash types based on its path relative its project

* add a test case

* fixes procs

* better implementation and test case

---------

Co-authored-by: Andreas Rumpf <[email protected]>
(cherry picked from commit 38d299d)
narimiran pushed a commit that referenced this pull request Mar 9, 2023
…th (#21274) [backport:1.6]

* fixes #20139; hash types based on its path relative its project

* add a test case

* fixes procs

* better implementation and test case

---------

Co-authored-by: Andreas Rumpf <[email protected]>
(cherry picked from commit 38d299d)
capocasa pushed a commit to capocasa/Nim that referenced this pull request Mar 31, 2023
…ckage path (nim-lang#21274) [backport:1.6]

* fixes nim-lang#20139; hash types based on its path relative its project

* add a test case

* fixes procs

* better implementation and test case

---------

Co-authored-by: Andreas Rumpf <[email protected]>
bung87 pushed a commit to bung87/Nim that referenced this pull request Jul 29, 2023
…ckage path (nim-lang#21274) [backport:1.6]

* fixes nim-lang#20139; hash types based on its path relative its project

* add a test case

* fixes procs

* better implementation and test case

---------

Co-authored-by: Andreas Rumpf <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gcc error when constructing an object that has the same name in the same file name in 2 different directories

6 participants