Repository navigation
Closed
Description
Summary
Complete the c_import omission manifest per §16.2: each omitted construct must be recorded with its source location and, for dependent bindings, a reason chain; and the compile error for referencing an omitted symbol must give directional guidance (use the raw surface vs. accept that the construct is genuinely inexpressible). Today the manifest records name+reason only, and the reference diagnostic names the symbol and reason but offers no alternative.
Spec
§16.2 Macro Handling — Honest generated surface:
- "Such constructs are omitted from the generated binding surface and recorded in the import manifest with their name, source location, and reason. Dependent bindings that require an omitted inexpressible construct are also omitted and recorded with the same reason chain." (16.2.1.13, 16.2.1.14)
- "Referencing an omitted symbol is a directional compile error that names the symbol, why it could not be translated, and the alternative: use the raw surface if this is a §16.1 unsafe/raw-modeling case, or accept that the C construct has no With representation if it is genuinely inexpressible." (16.2.1.23)
Current state
- Manifest storage is a flat string of
|name|reason\nrecords:ci_record_omitted_symbol(name, reason)(src/CImport.w:239-245) appends tog_cimport_omitted_symbols(CImport.w:20), dedup via substring check; rendered into the generated source as// @with-cimport-omitted|name|reasoncomment lines byci_omitted_manifest_comments(CImport.w:252-277), prepended to the output at CImport.w:560. - Record sites: untranslated macro (CImport.w:292), inline body translation failure (1143), untranslatable decl types (1207, 1825). No location is recorded even though
ci_get_decl_location(session, name)exists (CImport.w:9219) and is already used for enum/forward-decl comments (1526, 1760, 13538). - No dependency chain: when a function is omitted because its parameter type was omitted, the reason is a fresh
"untranslatable: <reason>"string (1207) with no link to the originating omission. - Reference diagnostic:
SemaCheck.check_identconsultsci_omitted_symbolsand emitsc_import symbol '{name}' was omitted: {detail}(src/SemaCheck.w:3496-3501). No directional alternative text. (Campaign verdict 16.2.1.23: "names symbol+reason; no alternative guidance".) - Related, working pieces: allow-list acknowledgment errors (Frontend.w:471), allow-list in cache key (Frontend.w:361-364), omitted-macro reference test
err_c_import_omitted_macro_reference.w.
Implementation plan
- Structured manifest records (CImport.w): replace the two-field record with
|name|location|category|reason\nwherecategory ∈ {raw-modelable, inexpressible}andlocationcomes fromci_get_decl_location(session, name)(empty allowed for synthetic/macro cases where libclang gives none — macros do have locations via the macro cursor; thread the session intoci_record_omitted_symbolcall sites or resolve location at each call site and pass it in). Updateci_omitted_manifest_comments(252-277) and the@with-cimport-omittedcomment format; keep dedup on name. - Reason chains: when omitting a dependent binding, look up the dependency's existing record and append
; depends on omitted '<dep>': <dep reason>— concretely, at the unsupported-type omission sites (CImport.w:1151-1207 for functions, 1821-1825 for decls), when the unsupported type names a previously omitted record (ci_omitted_symbol_recorded, CImport.w:247), build the chained reason instead of a bare "untranslatable". Chains are transitive automatically because the dep's stored reason already contains its own chain. - Categorize for direction: at each record site choose the category — constructs that are ABI-expressible but not safely modeled (e.g. unmodelable ownership contract) are
raw-modelable; token-paste macros, bitfield-dependent layouts, compiler extensions areinexpressible. Default conservatively toinexpressibleonly where no raw binding could exist; the §16.1 classification logic (what could be a raw binding) is the guide. Persist the category in the record (step 1). - Directional diagnostic (
src/SemaCheck.w:3496-3501): parse the structured record (the sema-sideci_omitted_symbolsmap is populated from the manifest comments — extend the parser of@with-cimport-omittedlines wherever it fills that map; grepci_omitted_symbols.insert) and emit:- raw-modelable:
c_import symbol 'X' was omitted: <reason> (at <loc>); this contract can be used via the raw surface — declare a manual extern "C" binding and call it under unsafe (§16.1); - inexpressible:
c_import symbol 'X' was omitted: <reason> (at <loc>); this C construct has no With representation — wrap it in a C shim or use allow_untranslated to acknowledge the omission (§16.2); - chained: include the chain text so the user sees the root cause.
- raw-modelable:
- Cache compatibility: the manifest format lives inside cached generated text (fs cache, Frontend.w fs_cache paths). Bump the cache format tag (
#format:cimport-v10→v11inZcu.c_import_cache_key_frontend, Frontend.w:353) so stale caches with the old comment format are not misparsed. - No rt/Link.w impact; CImport + Frontend + SemaCheck only. Keep record ordering deterministic (append order of translation, already deterministic).
Test plan
- Extend
test/compile_errors/err_c_import_omitted_macro_reference.w(or adderr_c_import_omitted_directional_raw.w/err_c_import_omitted_directional_inexpressible.w): inline header with (a) a function taking an untranslatable construct → referencing it expects the raw-surface guidance text; (b) a token-paste macro → referencing expects the no-representation guidance.//! expect-error:on the distinctive fragments ("raw surface" / "no With representation"). test/compile_errors/err_c_import_omitted_reason_chain.w: header wherestruct Weirdis inexpressible andvoid use_weird(struct Weird w)depends on it; referencinguse_weirdexpects the chain textdepends on omitted 'Weird'.test/behavior/behav_c_import_manifest_location.w: import a header with one omission; the program compiles (omission alone is not an error) — assert via the import diagnostics/manifest comment that the record carries afile:line(internals-level assertion onci_omitted_manifest_commentsoutput, or a driver test grepping the generated cache text).- Regression:
behav_c_import_allow_untranslated.w,err_c_import_untranslated_macro_requires_allow.wkeep passing (allow-list flow unchanged).
Acceptance criteria
- Every omission record carries name, source location (where libclang provides one), category, and reason; dependent omissions carry the originating chain.
- Referencing an omitted symbol produces the §16.2 directional error: raw-surface guidance for raw-modelable cases, no-representation guidance for inexpressible ones, with location and chain.
- Cache format tag bumped; no stale-format misparses.
-
with build && with build :fixpoint && with build :testpass.
Dependencies
- c_import: selective import and strict completeness flag (§16.2) #418 (selective import / strict completeness — consumes the same categorized manifest to decide whole-import failure).
- CoreFoundation's reference-counted type family: model it as a D51 convention profile #357 (candidate-pairing notes may ride this manifest channel).
Traceability
From the requirements campaign (docs/requirements.md, spec v7.1). Affected requirement IDs: 16.2.1.13, 16.2.1.14, 16.2.1.23.
Metadata
Metadata
Assignees
Labels
No labels
Activity
c_import omission manifest: locations, categories, directional errors (…
ehartford commentedon Jun 16, 2026
Implemented in 1d9ce53. Omission records now carry source location (ci_get_decl_location) and a directional category — raw-modelable (reachable via a manual extern under unsafe) vs inexpressible (no With representation); the @with-cimport-omitted manifest line is now |name|location|category|reason. Function/var/inline omissions are raw-modelable with their location; macros/prelude collisions stay inexpressible; dependent omissions append the originating reason chain. check_ident emits the §16.2 directional error (raw-surface vs no-representation guidance) with location. Cache format bumped v12→v13. Tests: err_c_import_omitted_directional_raw, err_c_import_omitted_directional_inexpressible; existing omitted-macro test still passes. build + fixpoint + compile-error/spec/behavior suites pass.