You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
with migrate: a function that reads or writes an extern C global, or indexes an extern incomplete array, is emitted without unsafe and the output does not check #3344
with migrate $PWD/file.c -o $PWD/out/file.w writes
pub fn look(__param_i: u32) -> u32:
(counter = (((counter + 1) as i32)))
return ((tab[__param_i] as u32))
extern let tab: *u8
extern var counter: i32
and then reports file.w does not check (3 error(s) above):
E0921: mutation of C global counter may race and E0921: read of C global counter may race (§31.4: a C global that is not const or thread-local is raw to touch),
raw pointer indexing requires unsafe context for tab[__param_i] (extern const uint8_t tab[] is rendered *u8).
Expected: the migrator emits what it cannot prove safe inside unsafe (§16.11, D159), as it does for a raw pointer parameter; the output checks. The translation unit shows neither global is thread-local and that counter is not const, so both accesses are raw by §31.4 and the function body, or the two expressions, belong in unsafe.
Where to look: the body lowering's unsafe accounting (the N unsafe count the migrator prints) does not count a DeclRef to a file-scope variable with no definition in the project, nor an index through an extern incomplete array.
Narrowed (installed compiler, main 8d6e104), directory mode:
intget(int*p) { returnp[1]; } /* -> pub unsafe fn get: correct */externintcounter;
intbump(void) { counter=counter+1; returncounter; } /* -> pub fn bump: does not check (E0921 twice) */externconstunsigned chartab[];
intlook(inti) { returntab[i]; } /* -> pub fn look: does not check (raw pointer indexing) */staticintown=3;
intmine(void) { own=own+1; returnown; } /* -> pub fn mine over a With `var`: fine */
Directory mode does not run the check that single-file mode runs, so with migrate dir -o out reports "4 functions translated" over output that does not compile. That silence is part of the defect.
What decides it. A raw pointer parameter makes the function unsafe fn, and a call of an unsafe fn from a safe body is wrapped (ci_migrate_call_requires_unsafe_wrapper, exprs.unsafe_expr). Nothing does the same for a reference to a file-scope variable that this migration renders as extern var / extern let (no definition in the project: ci_migrate_project_var_owner_path is empty and the declaration is CI_VAR_DECL_ONLY), nor for an index through one rendered *T.
Fix. In the body lowering, a DeclRef to such a variable is wrapped as the unsafe call is (exprs.unsafe_expr, skipped inside an unsafe fn body): a read or write of a non-const, non-thread-local extern, and an index or dereference of an extern rendered as a pointer. The body lowering (CImport.w) needs the project's answer to "does a unit here define it", which today is only asked when the declarations are rendered (CiMigrate.w). And directory mode runs the same check single-file mode runs, or says it did not.
The unsafe half is fixed in #3353: a raw extern global's read and write print inside unsafe, and an extern array of unknown size is indexed as a pointer; the migrated file checks. Open here: with migrate <dir> -o <out> does not run the check the single-file form runs, so a directory migration can still report success over output that does not compile.
Activity
ehartford commentedon Nov 15, 2026
Narrowed (installed compiler, main 8d6e104), directory mode:
Directory mode does not run the check that single-file mode runs, so
with migrate dir -o outreports "4 functions translated" over output that does not compile. That silence is part of the defect.What decides it. A raw pointer parameter makes the function
unsafe fn, and a call of anunsafe fnfrom a safe body is wrapped (ci_migrate_call_requires_unsafe_wrapper,exprs.unsafe_expr). Nothing does the same for a reference to a file-scope variable that this migration renders asextern var/extern let(no definition in the project:ci_migrate_project_var_owner_pathis empty and the declaration isCI_VAR_DECL_ONLY), nor for an index through one rendered*T.Fix. In the body lowering, a DeclRef to such a variable is wrapped as the unsafe call is (
exprs.unsafe_expr, skipped inside anunsafe fnbody): a read or write of a non-const, non-thread-local extern, and an index or dereference of an extern rendered as a pointer. The body lowering (CImport.w) needs the project's answer to "does a unit here define it", which today is only asked when the declarations are rendered (CiMigrate.w). And directory mode runs the same check single-file mode runs, or says it did not.with migrate: an extern global the unit only declares prints inside u…
ehartford commentedon Nov 15, 2026
The unsafe half is fixed in #3353: a raw extern global's read and write print inside
unsafe, and an extern array of unknown size is indexed as a pointer; the migrated file checks. Open here:with migrate <dir> -o <out>does not run the check the single-file form runs, so a directory migration can still report success over output that does not compile.with migrate checks a directory's output as it checks a file's (#3344)…