Skip to content

Frontend: a root extern fn no longer drops the @[c_export] definition of its symbol; a bare @[c_export] is refused (#2554) - #2642

Merged
ehartford merged 1 commit into
fix-2561from
fix-2554
Oct 25, 2026
Merged

ehartford merged 1 commit into
fix-2561from
fix-2554

Conversation

@ehartford

@ehartford ehartford commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Root cause: frontend_fn_tier_verdict (src/compiler/Frontend.w) drops a
user-import fn that a higher tier names, unless the fn is displaceable, and
a c_export fn is not displaceable. The higher-tier name list
(root_fn_names) counted the root's extern fn declarations, so the root's
extern fn assert_bool (its view of the C symbol) dropped the module's
@[c_export("assert_bool")] definition of that symbol; the link failed
with undefined symbol: _assert_bool. A c_export definition is now
checked against the root's DEFINITIONS only (root_defined_fn_names), the
rule D30 R2c already applies to the runtime's definitions.

And the parser stored a c_export only from @[c_export("name")]; a bare
@[c_export] (or an empty name) exported nothing and said nothing. It is
now refused with the §16.5 spelling.

Evidence:
before behav_2554_c_export_extern_caller.w: ld64.lld: error: undefined symbol: _c2554_bump
after 20 30 5 (stage1)
before err_2554_bare_c_export.w: check ok
after error: @[c_export] needs the C name it exports: @[c_export("name")] (§16.5)

Tests: test/behavior/behav_2554_c_export_{owner,extern_caller}.w,
test/compile_errors/err_2554_bare_c_export.w

Closes #2554

… of its symbol; a bare @[c_export] is refused (#2554)

Root cause: frontend_fn_tier_verdict (src/compiler/Frontend.w) drops a
user-import fn that a higher tier names, unless the fn is displaceable, and
a c_export fn is not displaceable. The higher-tier name list
(root_fn_names) counted the root's `extern fn` declarations, so the root's
`extern fn assert_bool` (its view of the C symbol) dropped the module's
`@[c_export("assert_bool")]` definition of that symbol; the link failed
with `undefined symbol: _assert_bool`. A c_export definition is now
checked against the root's DEFINITIONS only (root_defined_fn_names), the
rule D30 R2c already applies to the runtime's definitions.

And the parser stored a c_export only from `@[c_export("name")]`; a bare
`@[c_export]` (or an empty name) exported nothing and said nothing. It is
now refused with the §16.5 spelling.

Evidence:
before  behav_2554_c_export_extern_caller.w: ld64.lld: error: undefined symbol: _c2554_bump
after   20 30 5 (stage1)
before  err_2554_bare_c_export.w: check ok
after   error: `@[c_export]` needs the C name it exports: `@[c_export("name")]` (§16.5)

Tests: test/behavior/behav_2554_c_export_{owner,extern_caller}.w,
test/compile_errors/err_2554_bare_c_export.w
@ehartford
ehartford added this pull request to stack #2645 October 25, 2026 19:58
@ehartford ehartford changed the title fix 2554 Frontend: a root extern fn no longer drops the @[c_export] definition of its symbol; a bare @[c_export] is refused (#2554) Oct 25, 2026
@ehartford
ehartford marked this pull request as ready for review October 25, 2026 20:07
@ehartford
ehartford merged commit 0356939 into main Oct 25, 2026
@ehartford
ehartford deleted the fix-2554 branch October 25, 2026 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A @[c_export] definition is silently dropped when an importer declares the same name extern fn; a bare @[c_export] exports nothing

1 participant