Skip to content

c_import omission manifest: source locations, reason chains, directional diagnostics (§16.2) #417

Closed

Description

@ehartford

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\n records: ci_record_omitted_symbol(name, reason) (src/CImport.w:239-245) appends to g_cimport_omitted_symbols (CImport.w:20), dedup via substring check; rendered into the generated source as // @with-cimport-omitted|name|reason comment lines by ci_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_ident consults ci_omitted_symbols and emits c_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

  1. Structured manifest records (CImport.w): replace the two-field record with |name|location|category|reason\n where category ∈ {raw-modelable, inexpressible} and location comes from ci_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 into ci_record_omitted_symbol call sites or resolve location at each call site and pass it in). Update ci_omitted_manifest_comments (252-277) and the @with-cimport-omitted comment format; keep dedup on name.
  2. 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.
  3. 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 are inexpressible. Default conservatively to inexpressible only 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).
  4. Directional diagnostic (src/SemaCheck.w:3496-3501): parse the structured record (the sema-side ci_omitted_symbols map is populated from the manifest comments — extend the parser of @with-cimport-omitted lines wherever it fills that map; grep ci_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.
  5. 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 → v11 in Zcu.c_import_cache_key_frontend, Frontend.w:353) so stale caches with the old comment format are not misparsed.
  6. 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 add err_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 where struct Weird is inexpressible and void use_weird(struct Weird w) depends on it; referencing use_weird expects the chain text depends 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 a file:line (internals-level assertion on ci_omitted_manifest_comments output, or a driver test grepping the generated cache text).
  • Regression: behav_c_import_allow_untranslated.w, err_c_import_untranslated_macro_requires_allow.w keep 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 :test pass.

Dependencies

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.

Activity

  1. ehartford commented on Jun 16, 2026

    @ehartford
    ContributorAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions