Repository navigation
gen-rust: a string parameter lowers to &'static str, so every host must leak its input #7449
Copy link
Copy link
Open
Labels
Description
Problem
t27c gen-rust lowers every string / str / []const u8 type to &'static str. That covers parameters too (bootstrap/src/compiler.rs:28328 and :28350). Generated code can only be called with a string that lives for the whole process, so a host that reads text at run time has to leak it first.
There are two callers today, and both do this:
bootstrap/src/main.rs:7418(t27c asm, t27a MVP: TRI-27 assembler/disassembler with a round-tripping field table (T735, T736) #6507):Box::leak(read_t27a_input(input)?.into_boxed_str()).cli/tri/src/mutate.rs, themutate censusglue for tri mutate census: one table and one exit code for a directory of specs #7433: oneBox::leakof each spec's stdout before callingcensus::is_summary_line/summary_adds_up/count_at.
For a short-lived CLI process the leak costs nothing. But any long-running host (the Queen, a server, a loop over many inputs) has two bad choices: leak without bound, or hand-write the rule again in Rust. The only-t27 rule exists to prevent the second.
Expected
- A function parameter of type
stringlowers to&str, with an elided lifetime. - A
pub const NAME : str = "..."keeps&'static str. - A function that returns a string slice of a parameter would need a named lifetime. If gen-rust cannot express that yet, it should refuse loudly rather than emit
'static.
Acceptance
t27c gen-rust specs/tri/mutate/census.t27emitspub fn is_summary_line(line: &str) -> boolandpub fn after_count(line: &str, at: usize, tail: &str) -> usize.- With the regenerated files, the
Box::leakincli/tri/src/mutate.rs(census) and the one inbootstrap/src/main.rs(t27c asm) can be removed. Both crates still build:cargo build -p tri -p t27c. tools/l2_regen_check.pystays green: the generated files undergen/rust/andbootstrap/gen/rust/are regenerated in the same change.
Notes
- The fix is in
bootstrap/src/compiler.rs, which movesFROZEN_HASH, so it lands through the owner's path. - Found while wiring tri mutate census: one table and one exit code for a directory of specs #7433 slice 2b.
Boundary
specs/tri/mutate/census.t27bootstrap/src/compiler.rsbootstrap/src/main.rscli/tri/src/mutate.rstools/l2_regen_check.py
User Scenarios
- Given a
.t27spec declares a function parameter of typestring, whent27c gen-rustcompiles it, then the generated Rust function signature uses&strwith an elided lifetime instead of&'static str. - Given a
.t27spec declares apub const NAME : str = "...", whent27c gen-rustcompiles it, then the generated Rust constant keeps type&'static str. - Given a
.t27spec declares a function that returns a string slice derived from a parameter, whent27c gen-rustcannot express the required named lifetime, then compilation fails with a clear error rather than emitting'static.
Requirements
- FR-001: Function parameters of type
string/str/[]const u8MUST lower to&strwith an elided lifetime in generated Rust code. - FR-002:
pub constdeclarations of typestrwith string literals MUST continue to lower to&'static str. - FR-003: If a function returns a string slice tied to a parameter lifetime and gen-rust cannot express the required named lifetime, the compiler MUST emit a diagnostic error and stop rather than generate
'static. - FR-004: The generated files under
gen/rust/andbootstrap/gen/rust/MUST be regenerated in the same change so thattools/l2_regen_check.pypasses. - FR-005: After regeneration, the
Box::leakcalls inbootstrap/src/main.rs(fort27c asm) andcli/tri/src/mutate.rs(for census) MUST be removable while both crates still build withcargo build -p tri -p t27c.
Reactions are currently unavailable
Activity
tri mutate census --dir D: one exit and one killed share for a direct…
gHashTag commentedon Oct 7, 2026
Reopened 2026-10-07: the bulk close of issues without a
## Boundarysection was reverted by the owner. Nothing to do here; this comment replaces the earlier close notice.t27b: which calls lower as the .len field, decided by lencall.t27 (Cl…