Implement interpolated string function calls#2261
Draft
rofrankel wants to merge 6 commits intoluau-lang:masterfrom
Draft
Implement interpolated string function calls#2261rofrankel wants to merge 6 commits intoluau-lang:masterfrom
rofrankel wants to merge 6 commits intoluau-lang:masterfrom
Conversation
Desugar parentheses-free interpolated string calls into 3-argument function calls: (template, values, offsets). Gated behind the LuauInterpStringFunctionCalls feature flag. Co-authored-by: Cursor <cursoragent@cursor.com>
Simplify call desugaring from 3 args (template, values, offsets) to 2 args (template, values) per updated RFC. Add string.interpparse and string.interp core library functions for extracting expression names and rendering templates at runtime. Template strings use doubled braces ({{ / }}) to escape literal braces from \{ in source.
Made-with: Cursor
Replace character-by-character luaL_addchar with luaL_addlstring for runs of literal text between expression boundaries. Made-with: Cursor
The logInfo example now returns a key-value table mapping expression names to values, and demonstrates the same function working with both paren-free (sequential values) and parenthesized (associative values) calling conventions. Made-with: Cursor
Since Luau interns strings, repeated interpparse calls with the same template (e.g. from a hot logging path) return the same frozen table in O(1) via registry-based cache lookup. Cache miss falls through to normal parsing. Made-with: Cursor
When the compiler encounters a desugared interpolated string call, it records the template's constant index and expression name strings as trailing metadata in the bytecode. The VM loader reads this metadata after loading all protos and populates the interpparse registry cache with frozen tables, eliminating the first-call parsing cost for string.interpparse on compile-time-known templates. Made-with: Cursor
|
Aaaand I accidentally posted that on the language PR not the RFC PR. Sorry! |
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.
Summary
f hello {x}) into 2-argument function calls:f("hello {x}", {x})f "hello")string.interpparse(extracts expression names from a template) andstring.interp(renders a template with values, supporting both sequential and associative tables)Changes
Ast/include/Luau/Parser.h,Ast/src/Parser.cpp): AddparseInterpStringCallwhich constructs the template string and values table. Template uses doubled braces ({{/}}) to escape literal braces from\{in source.VM/src/lstrlib.cpp): Implementstring.interpparse(template) -> {string}andstring.interp(template, values) -> stringAnalysis/src/BuiltinDefinitions.cpp): Add type signatures for both new functionstests/Parser.test.cpp): 7 test cases covering simple, expressions, method calls, multiple expressions, complex expressions, flag-off behavior, and chainingtests/Compiler.test.cpp): 3 test cases verifying bytecode outputtests/conformance/stringinterpcall.luau): End-to-end runtime tests for call desugaring,string.interpparse,string.interp, escaped braces, side effects, and the currying/integration patterns from the RFCtests/Autocomplete.test.cpp): Updated string completion count for new library functionsTest plan