summary refs log tree commit diff stats
path: root/compiler/ic/cbackend.nim
diff options
context:
space:
mode:
authorquantimnot <54247259+quantimnot@users.noreply.github.com>2022-05-30 12:52:19 -0400
committerGitHub <noreply@github.com>2022-05-30 18:52:19 +0200
commitd30c6419a051a815e3fdb354ac79522f17e55bda (patch)
tree9f812bcb61f57b31f7282268a4d24b0b647e6e48 /compiler/ic/cbackend.nim
parent15f0b4867679120580b2f14bbb7a8b302505b34d (diff)
downloadNim-d30c6419a051a815e3fdb354ac79522f17e55bda.tar.gz
Refactor and doc package handling, module name mangling (#19821)
* 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 <quantimnot@users.noreply.github.com>
Diffstat (limited to 'compiler/ic/cbackend.nim')
-rw-r--r--compiler/ic/cbackend.nim5
1 files changed, 3 insertions, 2 deletions
diff --git a/compiler/ic/cbackend.nim b/compiler/ic/cbackend.nim
index e7ab000e6..815078a36 100644
--- a/compiler/ic/cbackend.nim
+++ b/compiler/ic/cbackend.nim
@@ -24,7 +24,7 @@ when defined(nimPreviewSlimSystem):
   import std/assertions
 
 import ".."/[ast, options, lineinfos, modulegraphs, cgendata, cgen,
-  pathutils, extccomp, msgs]
+  pathutils, extccomp, msgs, modulepaths]
 
 import packed_ast, ic, dce, rodfiles
 
@@ -64,7 +64,8 @@ proc addFileToLink(config: ConfigRef; m: PSym) =
       if config.backend == backendCpp: ".nim.cpp"
       elif config.backend == backendObjc: ".nim.m"
       else: ".nim.c"
-  let cfile = changeFileExt(completeCfilePath(config, withPackageName(config, filename)), ext)
+  let cfile = changeFileExt(completeCfilePath(config,
+                            mangleModuleName(config, filename).AbsoluteFile), ext)
   let objFile = completeCfilePath(config, toObjFile(config, cfile))
   if fileExists(objFile):
     var cf = Cfile(nimname: m.name.s, cname: cfile,