-
-
Couldn't load subscription status.
- Fork 1.5k
Refactor and doc package handling, module name mangling #19821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
* Consolidate, de-duplicate and extend package handling * Alter how duplicate module names of a package are handled * Alter how module names are mangled * Fix crash when another package is named 'stdlib' (test case added) * Doc what defines a package in the manual Modules with duplicate names within a package used to be given 'fake' packages to resolve conflicts. That prevented the ability to discern if a module belonged to the current project package or a foreign package. They now have the proper package owner and the names are mangled in a consistent manner to prevent codegen clashes. All module names are now mangled the same. Stdlib was treated special before, but now it is same as any other package. This fixes a crash when a foreign package is named 'stdlib'. Module mangling is altered for both file paths and symbols used by the backends. Removed an unused module name to package mapping that may have been intended for IC. The mapping was removed because it wasn't being used and was complicating the issue of package modules with duplicate names not having the proper package owner assigned.
370f0ed to
027e599
Compare
|
This is awesome! For name mangling I suggest to think about this algorithm: proc mangleModuleName(s: string): string =
result = s & "_0"
var i = 1
while fileExists("$nimcache" / result):
result = s & "_" & $i
inc i
|
* Remove `packagehandling.withPackageName` and its uses * Move module path mangling from `packagehandling` to `modulepaths` * Move `options.toRodFile` to `ic` to break import cycle
|
Using that algorithm doesn't work as a direct replacement of
I tried some alternatives, but I can't come up with anything better at the moment. Could that be considered for a future PR? I just noticed that However, I also just reviewed the contributing guide and read the section on backwards compatibility. Do I need to do the whole deprecation deal with the what I've moved around? I'm not sure of what constitutes the public API of the compiler. |
making name mangling depend on what's on the drive already seems like a good way to run into a number of issues such as exploding nimcaches etc as well as bugs when two developers are working on the same project and get different outcomes - what prevents mangling from being deterministic? |
The fact that eventually you create names that contain the mangled form of |
* Refactor and doc package handling, module name mangling * Consolidate, de-duplicate and extend package handling * Alter how duplicate module names of a package are handled * Alter how module names are mangled * Fix crash when another package is named 'stdlib' (test case added) * Doc what defines a package in the manual Modules with duplicate names within a package used to be given 'fake' packages to resolve conflicts. That prevented the ability to discern if a module belonged to the current project package or a foreign package. They now have the proper package owner and the names are mangled in a consistent manner to prevent codegen clashes. All module names are now mangled the same. Stdlib was treated special before, but now it is same as any other package. This fixes a crash when a foreign package is named 'stdlib'. Module mangling is altered for both file paths and symbols used by the backends. Removed an unused module name to package mapping that may have been intended for IC. The mapping was removed because it wasn't being used and was complicating the issue of package modules with duplicate names not having the proper package owner assigned. * Fix some tests * Refactor `packagehandling` * Remove `packagehandling.withPackageName` and its uses * Move module path mangling from `packagehandling` to `modulepaths` * Move `options.toRodFile` to `ic` to break import cycle * Changed import style to match preferred style Co-authored-by: quantimnot <[email protected]> (cherry picked from commit d30c641)
@quantimnot Hello, I'm looking into #20139 how does it prevent cases mentioned in that issue? I'm trying to use |
|
@ringabout Hi, sorry for the late response. Life has been hectic for a while. Anyway, I've now looked into the issue. The mangling change in this PR is only for handling the paths in the nimcache directory. You could resolve the issue by including the relative paths as you have done in #21274, but as you can see, it is noisy propagating |
follow up #19821 dights cannot clash with letters 'Z' and 'O' For `threading-0.2.0-288108d1dfa34d5ade5ce4d922af51909c83cebf` Before: raiseNilAccess__OOZOOZOnimbleZpkgs50Zthreading4548O50O4845505656494856d49dfa5152d53ade53ce52d575050af5349574857c5651cebfZthreadingZsmartptrs_u4 After: raiseNilAccess__OOZOOZOnimbleZpkgs2Zthreading450O2O045288108d1dfa34d5ade5ce4d922af51909c83cebfZthreadingZsmartptrs_u4 <del> nimble or something might use `git rev-parse --short HEAD` to shorten the length of package version names ref nim-lang/nimble#913 </del>
Modules with duplicate names within a package used to be given 'fake'
packages to resolve conflicts. That prevented the ability to discern if
a module belonged to the current project package or a foreign package.
They now have the proper package owner and the names are mangled in a
consistent manner to prevent codegen clashes.
All module names are now mangled the same. Stdlib was treated special
before, but now it is same as any other package. This fixes a crash
when a foreign package is named 'stdlib'.
Module mangling is altered for both file paths and symbols used by the
backends.
Removed an unused module name to package mapping that may have been
intended for IC. The mapping was removed because it wasn't being used
and was complicating the issue of package modules with duplicate names
not having the proper package owner assigned.
PR Reviewers
styleCheckonly consider the project's package instead of foreign packages. See ChangestyleCheckto ignore foreign packages #19822.astmodule without any cyclical imports.modulegraphscouldn't go intopackagesbecause of cyclical imports.packagehandlingcouldn't go intopackagesbecause of cyclical imports.packagehandling.mangleModuleNamecgen.getSomeNameForModule