Class ConstantCopyOnAccessLoader
A named constant is NOT a local: it lives in module-level constant storage, so it must be read with
an explicit LOAD_CONSTANT. Naming it as a bare operand instead (STORE _temp, Two)
leaves the IR referencing a value that is declared nowhere in the function - no back-end can process
that mechanically. The JVM back-end resolves the operand to a local slot, finds none, and emits a
load of an unset slot (VerifyError: bad local variable type); the native back-end has the same
problem with no SSA value or alloca of that name. The defect is in the IR, not in either back-end.
The load is always followed by a COPY via the copy constructor. Constants are shared objects, so every access hands out a fresh copy - otherwise a caller mutating what it read would silently change the constant for everything else in the module.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordThe instructions reading a constant, and the variable now holding the fresh copy. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionRead the constant into resultVariable as a fresh copy.applyToNewTemp(ISymbol constantSymbol, DebugInfo debugInfo) Read the constant into a freshly generated temp, returning both the instructions and that temp.booleanisCopyOnAccessConstant(ISymbol symbol) Does this symbol need the copy-on-access constant read?
-
Constructor Details
-
ConstantCopyOnAccessLoader
-
-
Method Details
-
isCopyOnAccessConstant
Does this symbol need the copy-on-access constant read?A literal-derived 'constant' is materialised in place by the literal loader, so it is excluded - only a declared, module-scope constant lives in constant storage.
- Parameters:
symbol- The resolved symbol behind an identifier- Returns:
- true if the symbol must be read via
apply(ISymbol, String, DebugInfo)
-
apply
Read the constant into resultVariable as a fresh copy.- Parameters:
constantSymbol- The constant to readresultVariable- The variable to hold the fresh copydebugInfo- Debug information for the instructions- Returns:
- LOAD_CONSTANT followed by the copy constructor call
-
applyToNewTemp
public ConstantCopyOnAccessLoader.LoadedConstant applyToNewTemp(ISymbol constantSymbol, DebugInfo debugInfo) Read the constant into a freshly generated temp, returning both the instructions and that temp.For callers that do not already hold a result variable. The raw temp is allocated BEFORE the result temp, which is the historical ordering the IR goldens were captured with.
- Parameters:
constantSymbol- The constant to readdebugInfo- Debug information for the instructions- Returns:
- The instructions and the temp now holding the fresh copy
-