Switch symbol mangling from the import leaf clause to the full dotted import path for directory packages; single-file imports keep package-clause mangling (isdir-gate: imported<=>directory-import). The root build unit's fn main stays bare, every other top-level decl mangles, closing #31's duplicate-main hazard by construction (#32). Both stages, byte-identical. Single commit, not split: the bare rename (f244af3) is red on its own because it unmasks cross-module resolution gaps that do not reproduce pre-M1, so the fixes are intrinsic to making the rename correct. Included: wwstage fnret/fnparamslookupmod map import alias->path (#199b cross-module union-variant scrutinee resolved the wrong fn's union); cstage use_path prefers the referencing module's import for an ambiguous leaf alias (sha256 crypto.math vs strconv math). Tests table-driven: 989_m1mangle_run/_sym, 989_m1union_run (gate-visible per-arm exit codes + cs==ww byte-id).
This commit is contained in:
@@ -218,7 +218,7 @@ enumerate_dir_ww(const char *dirpath, char ***out_files)
|
||||
}
|
||||
|
||||
static void expand(FILE *out, const char *path, struct ImportSet *visited,
|
||||
const char *libdir);
|
||||
const char *libdir, const char *modpath);
|
||||
|
||||
/* Scan `path` for its first non-comment-non-blank line; if it starts
|
||||
* with `package <name>;` write the name into `out` (NUL-terminated)
|
||||
@@ -299,7 +299,7 @@ unit_has_package(const char *path, const char *leaf)
|
||||
* dir-enum). */
|
||||
static void
|
||||
expand_dir(FILE *out, const char *dirpath, struct ImportSet *visited,
|
||||
const char *libdir)
|
||||
const char *libdir, const char *modpath)
|
||||
{
|
||||
char **files = NULL;
|
||||
int n = enumerate_dir_ww(dirpath, &files);
|
||||
@@ -318,7 +318,7 @@ expand_dir(FILE *out, const char *dirpath, struct ImportSet *visited,
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
expand(out, fp, visited, libdir);
|
||||
expand(out, fp, visited, libdir, modpath);
|
||||
free(files[i]);
|
||||
}
|
||||
free(files);
|
||||
@@ -331,7 +331,7 @@ expand_dir(FILE *out, const char *dirpath, struct ImportSet *visited,
|
||||
* it). */
|
||||
static void
|
||||
expand(FILE *out, const char *path, struct ImportSet *visited,
|
||||
const char *libdir)
|
||||
const char *libdir, const char *modpath)
|
||||
{
|
||||
if (import_seen(visited, path)) return;
|
||||
import_add(visited, path);
|
||||
@@ -377,8 +377,13 @@ expand(FILE *out, const char *path, struct ImportSet *visited,
|
||||
fprintf(stderr, "ww: cannot find package %s\n", name);
|
||||
exit(1);
|
||||
}
|
||||
if (is_dir) expand_dir(out, ipath, visited, libdir);
|
||||
else expand(out, ipath, visited, libdir);
|
||||
/* M1 #22 (isdir-gated, rob-ratified): a package IS a directory, so
|
||||
* only DIRECTORY imports are package boundaries that path-mangle.
|
||||
* A single-file import (`import opcodes;` → opcodes.ww declaring
|
||||
* `package w6a`) is an intra-package file-split — it keeps its
|
||||
* in-file `package` clause as its module (no directive). */
|
||||
if (is_dir) expand_dir(out, ipath, visited, libdir, name);
|
||||
else expand(out, ipath, visited, libdir, NULL);
|
||||
}
|
||||
|
||||
/* #16 option-B: a package-less file's decls would otherwise inherit
|
||||
@@ -389,10 +394,19 @@ expand(FILE *out, const char *path, struct ImportSet *visited,
|
||||
* `package main`, which would main-prefix them). A packaged file's own
|
||||
* `package` decl already sets curmod, so it needs nothing — keeping
|
||||
* the directive out of every tracked combined.ww. (Task #11.) */
|
||||
{
|
||||
char pkg[128];
|
||||
if (!peek_package(path, pkg, sizeof pkg))
|
||||
fputs("//ww:module-reset\n", out);
|
||||
if (modpath != NULL && modpath[0] != '\0') {
|
||||
/* M1 (#22): an import-reached file carries its full dotted
|
||||
* import path so codegen mangles symbols on the path, not the
|
||||
* leaf `package` clause. The directive's absence is the root
|
||||
* marker (#32): root/primary files take the branch below. */
|
||||
fprintf(out, "//ww:module %s\n", modpath);
|
||||
} else {
|
||||
/* Root/primary file: reset the bundle boundary so a preceding
|
||||
* imported section's sticky pathmod (M1 #22) is cleared. A
|
||||
* package-less file then stays primary ("") as before; a
|
||||
* packaged primary's own `package` clause sets curmod fresh
|
||||
* (pathmod now NULL → real clause, not an assertion). */
|
||||
fputs("//ww:module-reset\n", out);
|
||||
}
|
||||
rewind(in);
|
||||
int ch;
|
||||
@@ -505,12 +519,12 @@ build_one(const char *src, int entry_is_dir, const char *out,
|
||||
char tpath[1024];
|
||||
int tdir = 0;
|
||||
if (locate_import(srcdir, "test", tpath, sizeof tpath, &tdir)) {
|
||||
if (tdir) expand_dir(cf, tpath, &visited, srcdir);
|
||||
else expand(cf, tpath, &visited, srcdir);
|
||||
if (tdir) expand_dir(cf, tpath, &visited, srcdir, "test");
|
||||
else expand(cf, tpath, &visited, srcdir, NULL);
|
||||
}
|
||||
}
|
||||
if (entry_is_dir) expand_dir(cf, srcd, &visited, srcdir);
|
||||
else expand(cf, src, &visited, srcdir);
|
||||
if (entry_is_dir) expand_dir(cf, srcd, &visited, srcdir, NULL);
|
||||
else expand(cf, src, &visited, srcdir, NULL);
|
||||
fclose(cf);
|
||||
for (int i = 0; i < visited.n; i++) free(visited.paths[i]);
|
||||
free(visited.paths);
|
||||
|
||||
Reference in New Issue
Block a user