Repository navigation
self-host P2 slice 4: strings, byte-identical to gen-c; slices refused #8014
Description
Part of #5980 (phase P2: "strings/slices"). This is the fourth P2 slice; it follows #8000, #8007 and #8012.
Probed with t27c gen-c on master df0c185 (t27c lab):
strandstringbecomeconst char*;- a string literal is written back with
zig_escape; .lenon astringparameter or local becomesstrlen(with<string.h>);- a string const becomes a
#define.
Every lossy shape is listed in #8013. Today the core refuses every string with E_LEX and every slice type with E_TYPE.
This slice
-
specs/compiler/core/t27core.t27accepts, byte-identical with gen-c:- string literals: printable ASCII, the escapes
\n \t \\ \", and no??; - the types
strandstringfor parameters, returns, locals, module vars and consts; - a string value only where a string is declared: an initializer, an argument, a return value, an assignment, or a switch arm in one of those;
.lenon astringparameter or local, with gen-c's<string.h>;- indexing a string.
- string literals: printable ASCII, the escapes
-
New code E_STRING (15). The core refuses with it every lossy shape of gen-c: strings and slices lowered to bare pointers -- == compares addresses, .len on str and on slices is not C, escapes and trigraphs change value, a string where an integer goes compiles #8013:
- a string operand of an operator;
- a string where the declared type is not a string, or a non-string where it is;
.lenon astror on a module name;- an escape other than
\n \t \\ \", and??; - a repeated string.
Slice types
[]Tstay refused (E_TYPE, gen-c: strings and slices lowered to bare pointers -- == compares addresses, .len on str and on slices is not C, escapes and trigraphs change value, a string where an integer goes compiles #8013). So do struct fields and array elements of string type, because the core cannot follow the type of such an element without the P3 type checker. -
A string-typed name is bound once in its function and module, so a name's string type is never ambiguous.
-
Fixtures: an accept file that runs, and one refusal per shape. The
return "s"row ofREFUSALSincore_selfhost.rsmoves to a data fixture with its new code. -
t27core_ddc.t27is repinned.
Gate: cargo test -p t27c --test core_selfhost on the t27c lab, with the fixpoint, the core tests, every fixture and the corpus differential. The DDC also passes under Zig and t27b.
User Scenarios
- Given a valid string literal with printable ASCII and escapes
\n \t \\ \", when compiled witht27c, then the core accepts it and emits byte-identical C togen-c. - Given a string operand used with an operator, when compiled with
t27c, then the core refuses it with error codeE_STRING(15). - Given a
.lenaccess on astrtype or module name, when compiled witht27c, then the core refuses it withE_STRING.
Requirements
- FR-001: The core MUST accept string literals containing printable ASCII and the escapes
\n,\t,\\,\", and no??. - FR-002: The core MUST accept types
strandstringfor parameters, returns, locals, module vars, and consts. - FR-003: The core MUST accept
.lenon astringparameter or local and emit<string.h>withstrlen. - FR-004: The core MUST accept indexing a string.
- FR-005: The core MUST refuse every lossy shape from gen-c: strings and slices lowered to bare pointers -- == compares addresses, .len on str and on slices is not C, escapes and trigraphs change value, a string where an integer goes compiles #8013 with error code
E_STRING(15). - FR-006: Slice types
[]TMUST remain refused withE_TYPE. - FR-007: A string-typed name MUST be bound once in its function and module so its type is never ambiguous.
- FR-008: Fixtures MUST include one accept file that runs and one refusal per lossy shape; the
return "s"row fromREFUSALSincore_selfhost.rsMUST move to a data fixture. - FR-009:
t27core_ddc.t27MUST be repinned.
Success Criteria
cargo test -p t27c --test core_selfhostexits 0 on the t27c lab (fixpoint, core tests, every fixture, corpus differential).- The DDC passes under Zig and t27b (exit 0).
specs/compiler/core/t27core.t27compiles string literals,str/stringtypes,.len, and indexing byte-identical togen-coutput.- Each lossy shape from gen-c: strings and slices lowered to bare pointers -- == compares addresses, .len on str and on slices is not C, escapes and trigraphs change value, a string where an integer goes compiles #8013 produces
E_STRING(15) in its refusal fixture.
Boundary
- specs/compiler/core/t27core.t27
- specs/tri/utils/string.t27
- bootstrap/tests/fixtures/trinity_matrix/strings.t27
- .trinity/seals/String.json
Activity
t27core: strings, byte-identical to gen-c; slices refused (Closes #8014…