Skip to content

migrate: a migrated module's types are pub — the §18.1 check rejected every pub fn naming c_int or a header struct - #1309

Merged
ehartford merged 1 commit into
mainfrom
fix-pubsig-check-c-aliases
Sep 22, 2026
Merged

ehartford merged 1 commit into
mainfrom
fix-pubsig-check-c-aliases

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Root cause

Main's battery is red: every test/behavior/behav_migrate_*.w (26 tests) fails with

error: pub fn 'verify' names private type 'c_int' in its signature; a public signature names only public types (§18.1) --> lib/converted.w:221:20

The §18.1 check (#1284, SemaDecl.check_pub_signature_names_public_types) is correct and unchanged: it resolves the named type in the same module and reads its pub flag. c_int there is genuinely private — the migrator's single-file output was inconsistent with itself:

  • --no-c-export makes every non-static function pub (CiMigrate.w, visibility),
  • but the preamble emits type c_int = i32 (and the ~20 struct/typedef/enum rendering sites in CImport.w emit type X ...) with no pub.

So pub fn verify() -> c_int named a private alias; Pair make_pair(void) (behav_migrate_named_record_tags) named a private struct the same way. c_int is not a prelude/std.libc type (neither defines it); it is only the migrator's own alias, so there was nothing for the check to misclassify.

The multi-file corpus path never had the problem: it routes every type to defs.w, and ci_migrate_publicize_shared_defs prefixes pub on each declaration there — which is why lib/std/{re,zl,c_algorithms,tommyds}/defs.w already carry pub type c_int = i32 and the corpora compile under the new check.

Fix

The single-file path now applies the same rule to its type lines (ci_migrate_publicize_types, sharing one line walker with the defs.w publicizer): C has no type visibility, a migrated module's types are its public API, and static functions stay private as before (verified: static int hidden still migrates to a private fn hidden).

No corpus re-migration is needed: no corpus module carries a type line outside defs.w (rg -c '^type ' lib/std/{re,zl,c_algorithms,tommyds}/*.w is 0 everywhere), so the pass is a no-op on their output and the promoted trees are byte-identical to what a re-migrate would write.

Verification (fresh stage2 from this branch; :dev stage1 cannot run these tests — it embeds no bundles, so std.re is unresolvable from the p7 case dir)

  • 26/26 test/behavior/behav_migrate_*.w pass
  • err_pub_fn_names_private_type, err_pub_method_on_private_type, pub_fn_generic_param_not_private still pass (check unchanged, still meaningful)
  • with check src/main.w ok; with build :dev and :stage2 green

Not run here (per instructions): :fixpoint, :test.

… every pub fn naming c_int or a header struct

The §18.1 check (#1284, SemaDecl.check_pub_signature_names_public_types)
is correct: it resolves the named type in the same module and reads its
pub flag. The migrator's single-file output was genuinely inconsistent:
`--no-c-export` makes every non-static function `pub`, while the preamble
emitted `type c_int = i32` (and every struct/typedef/enum rendering site in
CImport.w emits `type X ...`) privately. So `pub fn verify() -> c_int`
named a private alias, and every behav_migrate_*.w test went red on main.

The multi-file corpus path never had the problem: it routes every type to
defs.w and ci_migrate_publicize_shared_defs prefixes `pub` on each
declaration there, which is why lib/std/{re,zl,c_algorithms,tommyds}/defs.w
already carry `pub type c_int = i32`. The single-file path now applies the
same rule to its type lines (ci_migrate_publicize_types): C has no type
visibility, a migrated module's types are its public API, and static
functions stay private as before. Corpus modules carry no `type` lines
outside defs.w, so the pass is a no-op on them and no re-migration is
needed.

Verified under the fresh stage2: 26/26 test/behavior/behav_migrate_*.w
pass; err_pub_fn_names_private_type, err_pub_method_on_private_type and
pub_fn_generic_param_not_private still pass.
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery: build rc=0, :fixpoint rc=0, :test rc=1 — all 26 behav_migrate_* now pass; the remaining reds are main's own (present in main's battery log too): examples-tests fizzbuzz (print-over-Display, in flight), rt-decl-audit (with_channel_create def spells ChannelDropFn while lib/std/channel.w's decl spells the fn-pointer type inline — from #1283), and deep-debug-tool-tests analyze-audit-rebind (its generated fixture has a pub fn naming a private P — #1284's check). Fixes for the last two follow in one small PR. This PR is mergeable on its own.

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.

1 participant