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
emit-c: prelude programs fail to compile — regex runtime functions used without extern declarations #300
The C backend (--emit-c) emits calls to with_regex_* runtime functions but never emits extern declarations for them. Because the prelude always pulls in lib/std/regex.w, every prelude program produces C that fails to compile (implicit-function-declaration errors, plus int→with_str/pointer type mismatches from the default int return type).
This is independent of any single program — even an empty print reproduces it.
Reproduction
fn main:
print("hi")
with build --emit-c trivial.w -o trivial.c
cc -I runtime trivial.c out/lib/rt_core.o out/lib/fiber_runtime.o \
out/lib/regex_runtime.o out/lib/rt_darwin_aarch64.o \
runtime/fiber_asm_aarch64.s -o trivial_c
Expected
Emitted C compiles and links against the runtime.
Actual
error: call to undeclared function 'with_regex_error_message'
error: assigning to 'with_str' from incompatible type 'int'
...
10 distinct undeclared functions; 13 with_regex_* references in the emitted C, 0 extern declarations:
CCodegen.emit_module (src/CCodegen.w, the runtime-extern block ending around with_str_clone at src/CCodegen.w:7506) declares the fmt/alloc/str runtime functions but omits the regex family. The fix is to emit extern prototypes for the with_regex_* functions there (matching the signatures in runtime/with_runtime.h / rt/regex_runtime.w).
Notes
Pre-existing; reproduces on an untouched code path. Found while completing the §18.6 collection length methods (Implement skipped test: test/spec/spec_ss18_6_collection_length_methods.w #282), where it blocked end-to-end C-backend run verification. The length-method C emission itself is correct; this is a separate emit-c/regex gap.
The LLVM backend is unaffected.
The emit-c smoke test passes, so the gap isn't currently caught — a prelude-using emit-c→cc→run roundtrip test would surface it.
Repro env: with v0.13.1-g7104bb5d7, darwin-aarch64.
Plan: wire in the (migrated) PCRE2 regex runtime for emit-c
The regex runtime is PCRE2 migrated into With — rt/regex_runtime.w wraps the std.re.pcre2_* modules and @[c_export]s a with_regex_* surface. It is not an external libpcre2, so there's no system lib to link; the gap is purely that the C backend never declares these exports (it hardcodes externs for fmt/alloc/str in CCodegen.emit_module and the regex family was missed).
Fix
Emit extern prototypes for the full with_regex_* surface in the runtime-extern block of CCodegen.emit_module (src/CCodegen.w, near the with_str_clone declaration at src/CCodegen.w:7506), and ensure out/lib/regex_runtime.o (+ the std.re.pcre2_* objects) is on the emit-c link line.
Prototypes (from the @[c_export] signatures in rt/regex_runtime.w; str→with_str, *const i8→int8_t*, *mut i32/*const i32→int32_t*):
Preferred approach: rather than hardcoding another extern list (which is exactly how this family got missed), have the C backend derive externs for all@[c_export] runtime functions referenced by the emitted module from their declared signatures. That closes this class of bug permanently.
Per maintainer: assert_matches is gaining a regex-string-matching form backed by this same PCRE2 runtime, so a regex assert_matches used in an emit-c program will hit this gap. #283 depends on this being fulfilled for the C backend.
Activity
ehartford commentedon May 30, 2026
Plan: wire in the (migrated) PCRE2 regex runtime for emit-c
The regex runtime is PCRE2 migrated into With —
rt/regex_runtime.wwraps thestd.re.pcre2_*modules and@[c_export]s awith_regex_*surface. It is not an externallibpcre2, so there's no system lib to link; the gap is purely that the C backend never declares these exports (it hardcodes externs for fmt/alloc/str inCCodegen.emit_moduleand the regex family was missed).Fix
Emit
externprototypes for the fullwith_regex_*surface in the runtime-extern block ofCCodegen.emit_module(src/CCodegen.w, near thewith_str_clonedeclaration at src/CCodegen.w:7506), and ensureout/lib/regex_runtime.o(+ thestd.re.pcre2_*objects) is on the emit-c link line.Prototypes (from the
@[c_export]signatures inrt/regex_runtime.w;str→with_str,*const i8→int8_t*,*mut i32/*const i32→int32_t*):Preferred approach: rather than hardcoding another extern list (which is exactly how this family got missed), have the C backend derive externs for all
@[c_export]runtime functions referenced by the emitted module from their declared signatures. That closes this class of bug permanently.Relationship to assert_matches (#283)
Per maintainer:
assert_matchesis gaining a regex-string-matching form backed by this same PCRE2 runtime, so a regexassert_matchesused in an emit-c program will hit this gap. #283 depends on this being fulfilled for the C backend.Emit regex runtime declarations in C output