Skip to content

FixedString's methods are declared in the library; as_view is a view of its value (part of #3483) - #3611

Merged
ehartford merged 1 commit into
mainfrom
builtins-fixed-string
Nov 25, 2026
Merged

ehartford merged 1 commit into
mainfrom
builtins-fixed-string

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Part of #3483; the issue stays open.

Moved. Ten of FixedString's methods are library declarations in lib/std/fixed_string.with (impl[Storage] FixedString[Storage]): len, len_i32, len_i64, capacity, is_empty, clear, push_byte, push_str, as_view, equals. new stays built in: it needs a zeroed value of a generic type, which the library cannot spell yet.

Deleted with them: their MirIntrinsic members, about 190 lines of hand-built IR in CodegenDispatch, the three BuiltinSigs rows, and in SemaCheck the name-based receiver modes, arity checks, return types and the FixedString__N signature fallback. The MIR shows the calls going to the library bodies (FixedString.len, .capacity, …).

Two soundness holes close with the move. The built-in as_view returned a str that aliased the buffer, and nothing tied it to the value:

fn label() -> str:
    var s = FixedString[8].new()
    let _ = s.push_str("gone")
    s.as_view()                 // compiled; the caller read dead stack memory

let v = s.as_view()
s.clear()
let _ = s.push_str("SECOND")
print(v)                        // printed "SECON"

The library declaration is as_view() -> &str from self. A binding of it is its own copy (D111), text returned as str is a copy, and returning the view itself is refused ("returned view may outlive its origin 's'").

This changes a signature and what safe code may do, by closing the holes: as_view is &str, not str. Every existing use in the tree compiles unchanged. Flagged for your veto.

Tests: behav_fixed_string passes unchanged; new behav_fixed_string_view_is_a_view and err_fixed_string_view_outlives_buffer, both failing on main.

Evidence at 8cb6621: both compilers check the source; release build; :unit-return-review, :ceremony-census, :self-audit, :native-compile-error-tests, :behavior-tests, :d-acceptance-corpus green; battery green; :release-checks survey: all targets green (the emit-C lanes among them).

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant