Repository navigation
Description
Summary
Implement the remaining c_import completeness controls: explicit selective imports must fail when they name inexpressible symbols, and a strict-completeness mode must turn any omission into a non-zero import failure. The importer already records omitted/untranslated symbols and supports allow_untranslated, but the user cannot request a strict complete import or select a specific symbol from c_import.
Spec
§16.2 reserves whole-import non-zero failure for selective imports, strict completeness, and real import failures. The interop rule is the same as the repository's no-silent-fallback policy: an importer that cannot produce correct bindings must fail loudly when the user asked for that symbol or for strict completeness.
use c_import("lib.h", only: ["needed_fn"], strict: true)
Current state
Parser.parse_c_import accepts link: and allow_untranslated: only; unknown options emit unknown c_import option (src/Parser.w:2272, src/Parser.w:2285, src/Parser.w:2301, src/Parser.w:2327). It does not parse only, exclude, or strict.
The frontend can emit untranslated diagnostics (src/compiler/Frontend.w:464) and checks allow_untranslated names (src/compiler/Frontend.w:473, src/compiler/Frontend.w:486). It records omitted symbols from generated manifest comments (src/compiler/Frontend.w:419). Ordinary use Foo.{Bar} selector handling exists for local type/enum selectors (src/Parser.w:2187, src/SemaDecl.w:124, src/compiler/Frontend.w:1771), but that is not wired to c_import.
Implementation plan
- Extend
NK_C_IMPORToption storage in the parser to includeonlyandstrictwhile preserving existinglinkandallow_untranslatedpacking. If the packed count field is too small, replace it with an extra-record layout. - Define exact syntax in parser tests. Recommended:
only: ["foo", "Bar"],exclude: ["..."]optional later, andstrict: true. - Thread selected symbol names into
Zcu.expand_c_imports_frontend. After synthetic source generation and omission recording, filter declarations to the selected set. - If
onlynames a symbol that was omitted or untranslated, emit a primary diagnostic at the c_import declaration and return non-zero from check/build. The diagnostic should include the symbol name and omission reason when available. - If
strict: true, fail on the first omitted symbol not listed inallow_untranslated, using the existingc_import_emit_untranslated_error_frontendstyle. - Keep non-strict whole imports permissive for omitted unsupported declarations, but never generate stubs or extern fallbacks for bodies that failed translation.
- Include selector names and strict mode in the c_import cache key (
src/compiler/Frontend.w:352) so cached non-strict output cannot satisfy strict/selective imports.
Test plan
Add parser tests for c_import("x.h", only: ["foo"], strict: true) and malformed option values.
Add test/wave*/cases/c_import_selective_ok.w with a header containing multiple declarations and asserting only requested names are visible.
Add test/compile_errors/err_c_import_selective_missing_symbol.w with //! expect-error: c_import: requested symbol.
Add test/compile_errors/err_c_import_strict_omitted_symbol.w using a deliberately inexpressible macro/declaration and strict: true.
Add a cache regression test showing strict and non-strict imports of the same header do not share incompatible cached output.
Acceptance criteria
c_importaccepts a documented selective import option and strict-completeness flag.- Explicitly requested but inexpressible symbols fail loudly.
strict: trueturns unallowed omissions into non-zero import failure.- Existing
allow_untranslatedbehavior still acknowledges known omissions. with build && with build :fixpoint && with build :testpass.
Dependencies
None.
Traceability
From the requirements campaign (docs/requirements.md, spec v7.1). Affected requirement IDs: 16.2.1.24.
Activity
c_import: selective import (only) and strict completeness (#418)
ehartford commentedon Jun 17, 2026
Implemented in 0307fdc.
Parser accepts
only: [...]andstrict: true, stored in a selective-import record appended to theNK_C_IMPORTextra array (the packed d2 counts field was full) and folded into the c_import cache key.Frontend (
expand_c_imports_frontend):c_*primitive typedefs they resolve through; a requested symbol the header doesn't provide fails loudly (c_import: requested symbol '…').allow_untranslatedturns the whole import non-zero (c_import: strict import omitted '…').Acceptance criteria
c_importaccepts a selective-import option and strict flagstrict: trueturns unallowed omissions into non-zero failureallow_untranslatedbehavior preserved (full suite green)Tests: spec_ss16_2_c_import_selective, err_c_import_selective_missing_symbol, err_c_import_selective_excludes_others, err_c_import_strict_omitted_symbol.
Note: a requested type's non-primitive dependencies must themselves be listed in
only(onlyc_*scaffolding is auto-kept); a full transitive-dependency closure is left as a follow-up refinement.