Repository navigation
Sema: a module that uses c_import resolves the program's C types as it already resolves its C values (#1372) - #1526
Merged
ehartford merged 1 commit intoSep 23, 2026
Conversation
This was referenced Sep 23, 2026
Contributor
Author
|
Stack #1528 battery (seed-driven, new seed, cold c_import cache, with :drop-audit/:move-audit) on main + #1522 → … → #1527 (head 33e6ba5; every PR head is a tested commit): build ok, :fixpoint ok, :drop-audit ok, :move-audit ok, :test ok (no reds), :test-green ok, :last-green ok. Merges cleanly into main. Merge the stack: |
ehartford
marked this pull request as ready for review
September 23, 2026 16:45
…t already resolves its C values (#1372) A root module and a module it imports each `use c_import(...)`. The frontend deduplicates C declarations across every c_import of a compilation (expand_c_imports_frontend: "Emitted names deduplicate declarations only within this compilation"): cu.w's <stdio.h> expansion declares `c_uint`, `c_ulonglong`, `_opaque_pthread_attr_t`, ..., and the root's <stdlib.h> expansion names them without declaring them again. Those declarations are cu.w's, and not `pub`. Values were designed for this: symbol_visible_from_current returns 1 for a c_import symbol when the current module itself uses c_import (is_ci_visible, a6951bc "a c_import symbol is visible only when the current module itself uses c_import"), so the root calls cu.w's `atoi` today. Type lookup (lookup_named_type_filtered) had no such rule and applied module privacy: the root failed with 825 errors ("'c_ulonglong' requires an explicit import (§18.1); add: use std.re.defs.c_ulonglong", "symbol '_opaque_pthread_attr_t' is private to module 'cu.w'"). Each named-type candidate now records whether a c_import expansion declared it (named_type_candidate_ci, from decl_is_c_import of the declaring node), and lookup_named_type_filtered, when no candidate is visible by the ordinary rules — the module's own declarations first (§18.1) — returns a c_import candidate to a module that uses c_import. Which modules use c_import is registered before declarations are collected (register_c_import_modules), since the root's expansion's types resolve during collection; build_ci_scoping still derives the rest after it. A module with no c_import still sees no C type (test_no_leak's rule). The issue proposed the other model — every module's c_import surface its own, complete expansion. That contradicts the value rule above and the frontend's one-expansion-per-header dedup, and would make one C struct two nominal With types in two modules; this change makes types follow the existing rule instead. If per-module surfaces are wanted, that is a ruling on the dedup and on is_ci_visible together. Fixture: test/behavior/behav_1372_two_modules_c_import.w: the issue's two modules run and print, and a module without c_import still cannot name `c_uint`. It runs the programs from src/ by bare name: only then is module privacy enforced at all (#1520, filed); spelled `src/m.w`, main passes the issue's program on every platform. From src/, main fails it on darwin and on native Windows alike.
ehartford
force-pushed
the
fix-1372-c-import-shared-types
branch
from
September 23, 2026 19:40
1be67d4 to
33d278f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A root module and a module it imports each
use c_import(...). Thefrontend deduplicates C declarations across every c_import of a
compilation (expand_c_imports_frontend: "Emitted names deduplicate
declarations only within this compilation"): cu.w's <stdio.h> expansion
declares
c_uint,c_ulonglong,_opaque_pthread_attr_t, ..., and theroot's <stdlib.h> expansion names them without declaring them again. Those
declarations are cu.w's, and not
pub.Values were designed for this: symbol_visible_from_current returns 1 for a
c_import symbol when the current module itself uses c_import
(is_ci_visible, a6951bc "a c_import symbol is visible only when the current
module itself uses c_import"), so the root calls cu.w's
atoitoday. Typelookup (lookup_named_type_filtered) had no such rule and applied module
privacy: the root failed with 825 errors ("'c_ulonglong' requires an
explicit import (§18.1); add: use std.re.defs.c_ulonglong", "symbol
'_opaque_pthread_attr_t' is private to module 'cu.w'").
Each named-type candidate now records whether a c_import expansion declared
it (named_type_candidate_ci, from decl_is_c_import of the declaring node),
and lookup_named_type_filtered, when no candidate is visible by the
ordinary rules — the module's own declarations first (§18.1) — returns a
c_import candidate to a module that uses c_import. Which modules use
c_import is registered before declarations are collected
(register_c_import_modules), since the root's expansion's types resolve
during collection; build_ci_scoping still derives the rest after it. A
module with no c_import still sees no C type (test_no_leak's rule).
The issue proposed the other model — every module's c_import surface its
own, complete expansion. That contradicts the value rule above and the
frontend's one-expansion-per-header dedup, and would make one C struct two
nominal With types in two modules; this change makes types follow the
existing rule instead. If per-module surfaces are wanted, that is a ruling
on the dedup and on is_ci_visible together.
Fixture: test/behavior/behav_1372_two_modules_c_import.w: the issue's two
modules run and print, and a module without c_import still cannot name
c_uint. It runs the programs from src/ by bare name: only then is moduleprivacy enforced at all (#1520, filed); spelled
src/m.w, main passes theissue's program on every platform. From src/, main fails it on darwin and
on native Windows alike.
Closes #1372
Stack #1528, bottom to top: #1522 (#1411) → #1523 (#1413) → #1524 (#1429) → #1525 (#1414) → #1526 (#1372) → #1527 (#1417). Each layer holds only its own commit.
Verification (iterate tier; no battery yet — draft until the seed-driven battery is green): stage1 and stage2 built from the stack top on darwin-aarch64 (SDKROOT CLT 15.4) and on native Windows 10 x64; fixtures below pass on both;
check --validate-allswept over test/, examples/, lib/std (3188 files) with base stage2 (main f1e3bd2) vs the stack's stage2.