Skip to content

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

Closed

Description

@ehartford

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.

Activity

  1. added
    bug
    on Sep 28, 2026
  2. ehartford commented on Oct 3, 2026

    @ehartford
    ContributorAuthor

    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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions