ww: separate package identity from declared name

This commit is contained in:
2026-08-14 03:07:58 +09:00
parent 028da6323e
commit 6efe9b70d4
37 changed files with 1678 additions and 886 deletions

View File

@@ -173,7 +173,7 @@ typedef enum {
* that replaces the withdrawn `package main` inject). */
TK_MODPATH, /* `//ww:module <dotted-path>` — driver import boundary:
* the following file's decls mangle on the full import
* path, not the leaf `package` clause (M1 #22). Token
* path independently of the `package` clause (M1 #22). Token
* text carries the dotted path. */
TK_LAST /* sentinel for tables */
@@ -344,10 +344,16 @@ struct Node {
* this is the importing (owning)
* module. */
const char *usepath; /* M1 #22: on an N_USE node, the full
* dotted IMPORT path (`encoding.utf8`)
* vs the leaf alias in `str`. Drives
* canonical import path (`encoding.utf8`);
* `str` is the declared default qualifier. Drives
* the path-keyed decl_mod match and the
* qualified-ref codegen hint. */
* qualified-ref codegen hint. */
const char *pkgname; /* declared package name for this source/export
* section; independent of canonical `module`. */
int sourceid; /* lexical source-file scope within the parsed
* owner unit; module-reset/module boundaries
* advance it deterministically. */
int used; /* N_USE: checker observed this file-local binding. */
int imported; /* M1 #22: decl reached through an
* `//ww:module <path>` import boundary
* (vs root/primary). Gates the root-only
@@ -373,12 +379,12 @@ struct Parser {
* import path; while set, decls stamp
* module=pathmod and imported=1, and the
* in-file `package` clause is an assertion. */
const char *resetmod; /* #57: active `//ww:module-reset <path>` dotted
* path; mangles decls on the path WITHOUT
* imported=1 (primary-ness for -c and the #32
* bare-main rule stay intact), and the in-file
* `package` clause asserts (leaf == last
* component) instead of overwriting curmod. */
const char *resetmod; /* #57: active `//ww:module-reset <path>` canonical
* identity; decls mangle on it without becoming
* imported. The package clause independently
* supplies the declared name. */
const char *curpkg; /* declared name of the active source section. */
int sourceid; /* deterministic lexical source-section ordinal. */
const char *testmodule; /* hidden package-driver alias for toolchain
* `package test`; NULL outside that compile */
int commandpackage; /* selected command family: package main/main_test
@@ -581,8 +587,10 @@ struct Checker {
* currently being checked; NULL for primary
* compilation unit. Drives same-module
* preference in bare-leaf lookups so a bare
* `read` inside lib/os resolves to os.read
* rather than colliding io.read. */
* `read` inside lib/os resolves to os.read
* rather than colliding io.read. */
int cur_source; /* lexical source-file scope of the declaration
* currently being checked. */
Node *file; /* current N_FILE root; used by check_module_shadow
* to consult the declaring source file's own `use`
* directives when refusing param/let names that
@@ -596,6 +604,8 @@ struct Checker {
* bodies and export compiler-private metadata,
* but do not synthesize an entry. */
const char *test_module; /* generated dispatcher support qualifier */
const char *test_target; /* canonical target path used only as the
* compiler-owned generated-main qualifier */
int sep_mode; /* -c package compilation: imported interfaces are
* present, so absent members are hard export errors. */
Node *synth_test_run; /* exact compiler-generated support.run DOT;
@@ -620,6 +630,6 @@ int fold_int_literal(Node*, u64*);
/* Re-evaluate a checked integer constant under the declaration owner's
* import scope. The compiler export writer uses this to canonicalize array
* dimensions without serializing source-level constant dependencies. */
int check_eval_const(Checker*, Node*, const char *owner, u64*);
int check_eval_const(Checker*, Node*, const char *owner, int source, u64*);
#endif /* WW_H */