Skip to content

c_import: real-header macro omission diagnostics and regression coverage #582

Closed

Description

@ehartford

Summary

Simple function-like expression macros now translate and execute correctly.
The remaining work is real-header omission accounting, precise omission
reasons, real-header regression coverage, and one internal specification
inconsistency.

Current state (revalidated 2026-07-15)

From an actual header file, the current compiler correctly imports and
evaluates:

  • object-like integer and string constants;
  • constant expressions;
  • simple MAX/ABS/doubling-style function macros.

The old headline enhancement is therefore implemented.

Unsupported macros are still incomplete for real headers. Token-paste imported
from a real file currently becomes a bare “undefined variable” when referenced.
The same macro supplied through an inline header specification gets the
directional §16.2 omission diagnostic.

The implementation explains the split:
ci_should_report_untranslated_macros enables omission recording only when
the header-spec text itself contains #define, which identifies inline
specifications but skips ordinary header files.

All unsupported causes also collapse to the generic reason “untranslated
macro,” rather than identifying token pasting, stringification, variadics,
statement expressions, or another unsupported construct.

Finally, §16.1 still says function-like macros are not translated while §16.2
correctly says simple expression macros are translated. Those sections must
agree.

Work

  1. Record untranslated macro symbols for actual header files, not only inline
    header text.
  2. Carry a precise omission reason from classification to the directional
    diagnostic.
  3. Add real-header fixtures for one constant, one supported function-like
    expression macro, and one unsupported macro reference.
  4. Align §16.1 with §16.2's supported subset.

Complex macros must remain omitted or fail loudly. Do not generate placeholder
functions, fake externs, TODO bodies, or translations with different
evaluation semantics.

Acceptance criteria

  • Supported real-header expression macros evaluate correctly.
  • Referencing an omitted real-header macro names the macro, source, reason, and
    allowed remediation.
  • Selective/strict imports fail when a requested macro cannot be translated.
  • Omission reasons distinguish major unsupported classes.
  • §16.1 and §16.2 describe the same behavior.
  • Full build, fixpoint, and test gates pass.

Activity

  1. changed the title [-]c_import: complete simple macro expression translation without silent stubs (§16.2)[/-] [+]c_import: function-like expression macro translation (object-like constants already work)[/+] on Jul 2, 2026
  2. ehartford commented on Jul 2, 2026

    @ehartford
    ContributorAuthor

    Retitled to match current reality (skepticism pass, 2026-07-02): object-like integer-constant macros translate fine on HEAD (INT_MAX → 2147483647; #348's pure-With expander also handles recursive object-like expansion for the migrator). What remains is the enhancement: translating function-like expression macros into With (per §16.2), with loud untranslatable diagnostics in the meantime — which is current behavior, so this is a feature tracker, not a bug.

  3. changed the title [-]c_import: function-like expression macro translation (object-like constants already work)[/-] [+]c_import: real-header macro omission diagnostics and regression coverage[/+] on Jul 15, 2026
  4. ehartford commented on Oct 25, 2026

    @ehartford
    ContributorAuthor

    Triage 2026-10-25, with v0.15.3.0 (main a261b65): still reproduces. A token-paste macro from a real header is still a bare undefined variable, with no §16.2 omission diagnostic naming the macro and the reason:

    // paste.h
    #define CAT(a, b) a ## b
    #define ANSWER 42
    
    use c_import("paste.h")
    print(ANSWER)
    print(CAT(get, _x))
    
    error: undefined variable
     --> main3.w:3:7
    3 | print(CAT(get, _x))
      |       ^^^
    

    pre-release: a misleading diagnostic every c_import user meets on a real header; the inline-header path already emits the right one, so the fix is to route real-header omissions through the same reporter.

  5. ehartford commented on Oct 26, 2026

    @ehartford
    ContributorAuthor

    Fix campaign, 2026-10-25: the code half is on main in 5ba83a4 (#2728); the spec half is flagged human attn needed.

    Fixed (test test/compile_errors/err_582_real_header_token_paste_macro.w with its header). A function-like macro from a real header that does not translate is now recorded and reported by name, the same as from an inline spec (ci_record_untranslated_fn_macro; a system header's macros stay recorded only for an inline spec). Each omission carries what stopped it: token pasting, a statement expression, stringification, variadics, a cleanup attribute, a bare NULL, or a function-pointer result. PASTE(1, 2) from paste.h is now "c_import symbol 'PASTE' was omitted … untranslated macro: token pasting (##)" instead of "undefined variable".

    Open: item 4, aligning §16.1 with §16.2. §16.1 still says function-like macros are not translated, while §16.2 says simple expression macros are, and the implementation does translate them. This is C-interop spec text, so it is Eric's. Proposed words for §16.1, replacing the sentence that says function-like macros are not translated:

    Function-like macros whose body is a single expression over their parameters are translated as generic functions (§16.2). A macro that pastes tokens, stringifies, takes variadic arguments, or expands to a statement is omitted, and a reference to it names the macro and the construct (§16.2).

    Prediction (85%): Eric takes §16.2's behaviour as the rule and adjusts the wording. Left on do-before-release until the spec text lands.

  6. ehartford commented on Oct 27, 2026

    @ehartford
    ContributorAuthor

    Phase-3 fix campaign, 2026-10-26: confirmed unchanged on current main (dee141b79) — the code half is on main (real-header macro omissions are reported by name and reason), and §16.1 (docs/spec/016_ffi.md:27) still says "Function-like macros → not translated" while §16.2 (line 232) and the implementation translate simple expression macros. The proposed §16.1 wording from 2026-10-25 stands; it is C-interop spec text, so it stays human attn needed on do-before-release for your words.

  7. ehartford commented on Oct 27, 2026

    @ehartford
    ContributorAuthor

    Blessed and landed: the proposed words are on main in 8b297e3 (#2756). §16.1 now says single-expression function-like macros translate as generic functions and the rest are omitted with the macro and construct named; §16.2's stale MAX-as-untranslated example now shows a token-paste omission (verified against the installed compiler: MAX(3, 7) prints 7). Spec-only, inventory check green.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions