Class InterpolatedStringGenerator
- All Implemented Interfaces:
Function<ExprProcessingDetails, List<IRInstr>>
Handles the syntax: "Hello ${name}, you are ${age} years old"
IR Generation Strategy:
String interpolation generates a high-level STRING_INTERPOLATION instruction
that provides structured data to backends for optimal concatenation:
- Evaluate each expression part and convert to String (if not already)
- Collect all parts (literals and converted variables)
- Create STRING_INTERPOLATION instruction with parts list
Backend Optimization:
The bespoke instruction allows backends to choose optimal strategies:
- JVM: invokedynamic StringConcatFactory.makeConcatWithConstants()
- LLVM: Single allocation with pre-calculated length and memcpy
Pre-conversion:
All expressions are converted to String BEFORE the interpolation instruction,
keeping backends purely mechanical and enabling Phase 12 optimization
(reusing previously converted Strings if source hasn't been mutated).
-
Field Summary
Fields inherited from class AbstractGenerator
constantCopyOnAccessLoader, debugInfoCreator, instructionBuilder, MAX_MESSAGE_LENGTH, stackContext, synthesisedCallMetaData, typeNameOrException -
Constructor Summary
ConstructorsConstructorDescriptionInterpolatedStringGenerator(IRGenerationContext stackContext, GeneratorSet generators) Constructor for interpolated string IR generator. -
Method Summary
Modifier and TypeMethodDescriptionapply(ExprProcessingDetails details) interpolate(EK9Parser.StringLitContext stringLitCtx, VariableDetails resultDetails) THE interpolation entry point for callers that already hold a stringLit - use this, do not re-derive it.Methods inherited from class AbstractGenerator
addCoverageProbe, createTempVariable, createTempVariableFromContext, extractReturnType, getRecordedSymbolOrException, processBlockStatements, processBlockStatements, truncateMessage, truncateMessage
-
Constructor Details
-
InterpolatedStringGenerator
InterpolatedStringGenerator(IRGenerationContext stackContext, GeneratorSet generators) Constructor for interpolated string IR generator.- Parameters:
stackContext- IRGenerationContext for scope and symbol accessgenerators- GeneratorSet for accessing other generators (expression processor, etc.)
-
-
Method Details
-
apply
- Specified by:
applyin interfaceFunction<ExprProcessingDetails, List<IRInstr>>
-
interpolate
public List<IRInstr> interpolate(EK9Parser.StringLitContext stringLitCtx, VariableDetails resultDetails) THE interpolation entry point for callers that already hold a stringLit - use this, do not re-derive it.A text body's string is a
stringLitdirectly rather than one wrapped in an expression, so it cannot useapply(ExprProcessingDetails). That is the only difference, and it is not a reason to hand-roll the lowering:TextBodyMethodGeneratorpreviously copied this class's part processing and drifted from it three ways - trait dispatch emitted as a non-trait call,#^promotion omitted entirely, and escapes read raw from the token instead of from the phase-1 ConstantSymbol.- Parameters:
stringLitCtx- the stringLit containing the interpolation partsresultDetails- where the resulting String goes, plus debug info- Returns:
- the single STRING_INTERPOLATION instruction (its setup is carried inside it)
-