materialize string literals into memory(string)#479
Draft
mbenke wants to merge 1 commit into
Draft
Conversation
`string` is a comptime-only type with no runtime representation. String literals and comptime concatenations are now polymorphic via a primitive `Str` class and are materialized into `memory(string)` at runtime sites, mirroring the comptime `integer`/`Int.fromInteger` design. - StrLiteralDesugar: untyped pre-typecheck pass wrapping every string literal and every `concatLit(...)` in `Str.fromString(...)`, resolved by the type checker per use site (identity at `string`, materialization at `memory(string)`). Wrapping `concatLit` makes it effectively result-polymorphic, so `concatLit(...)` (incl. nested) works at a `memory(string)` site without a manual `Str.fromString`. - Primitives/TcEnv/NameResolution: `Str` class with bodyless `string` and `memory(string)` instances; `memStringFromLit` backend marker. - Specialise: `Str.fromString` resolves by result type to identity or `memStringFromLit`. - MastEval: `Str.fromString` identity fold; `memStringFromLit` kept impure. - EmitHull: intercept `memStringFromLit [StrLit]` -> per-literal, content- deduped `__strlit_<n>` allocator (alloc + length + char words); clean guards when a comptime-only type reaches emission. - TcStmt: generalize markIntegerComptime -> markComptimeOnly (integer+string). - ComptimeCheck: classify comptime-only-typed params/returns as comptime, so `concatLit` and string functions are implicitly comptime without cascading the annotation to callers. Tests: comptime materialization (basic, concat, nested, dedup, negative) and an end-to-end dispatch case returning "Hello, world!" verified via evmone. Documented in doc/comptime-string.md. Assisted-By: Claude Opus 4.8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
stringis a comptime-only type with no runtime representation. String literals and comptime concatenations are now polymorphic via a primitiveStrclass and are materialized intomemory(string)at runtime sites, mirroring the comptimeinteger/Int.fromIntegerdesign.concatLit(...)inStr.fromString(...), resolved by the type checker per use site (identity atstring, materialization atmemory(string)). WrappingconcatLitmakes it effectively result-polymorphic, soconcatLit(...)(incl. nested) works at amemory(string)site without a manualStr.fromString.Strclass with bodylessstringandmemory(string)instances;memStringFromLitbackend marker.Str.fromStringresolves by result type to identity ormemStringFromLit.Str.fromStringidentity fold;memStringFromLitkept impure.memStringFromLit [StrLit]-> per-literal, content- deduped__strlit_<n>allocator (alloc + length + char words); clean guards when a comptime-only type reaches emission.concatLitand string functions are implicitly comptime without cascading the annotation to callers.Tests: comptime materialization (basic, concat, nested, dedup, negative) and an end-to-end dispatch case returning "Hello, world!" verified via evmone. Documented in doc/comptime-string.md.