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
c_import: a c_import-origin function name is global and captures a std bundle module's own calls (lib/std/re/defs.w resolves u128_mul_would_overflow to the header's function) #1882
Found fixing #1877 (c_import defining the overflow helpers its inline bodies call).
A function a c_import header defines is registered as a global name (SemaDecl's c_import scoping, the D29 "every extern is global" rule), and the .wo bundles' shared defs (lib/std/re/defs.w, tommyds, zl, c_algorithms) reach every compilation over the prelude edge. So a c_import function that spells a bundle-private helper's name captures the bundle's own calls:
use c_import("static inline int u128_mul_would_overflow(int a) { return a + 1; }\n")
fn main:
print(u128_mul_would_overflow(1))
error: function 'u128_mul_would_overflow' expects 1 argument(s), found 2
--> lib/std/re/defs.w:235:8
235 | if u128_mul_would_overflow(ua, ub): return true
With an identical signature there is no Sema error and MIR lowering fails instead: invalid MIR before codegen: body index map mismatch for fn symbol N (two declarations, one symbol, one body index). The same definition placed in the user module is fine: the cross-module case resolves in favor of the local declaration (SemaCheck, math_extern_yields neighbourhood), only a c_import-origin declaration collides.
Expected: a c_import module's declarations are scoped to their importer like any module's (§18.2); a header function never shadows a std module's private function, and never a bundle's. This is the #1457 (symbol carries its declaration) / #752 (engine-leak closure) class.
Workaround in #1877's fix: the import's own helpers are spelled __c_import_<op>_overflow_<ty> / __c_import_u128_mul_would_overflow, distinct from the bundles' __with_builtin_* / u128_mul_would_overflow, so they cannot collide; the general collision remains.
Fixed on main by 7b56d3f (stack #1979, battery green on 029574d). A header's function belongs to its importing module (displace_colliding_c_import_fns); a module's own fn outranks its c_import's same-named fn, which stays reachable through the namespace.
Activity
c_import: full SDL.h imports — zero-parameter macro return types, D42…
c_import/migrate/emit-c: no `-> Unit` on void C fns (#1838); header f…
ehartford commentedon Oct 3, 2026
Fixed on main by 7b56d3f (stack #1979, battery green on 029574d). A header's function belongs to its importing module (displace_colliding_c_import_fns); a module's own fn outranks its c_import's same-named fn, which stays reachable through the namespace.