Appearance
| 1 | namespace IR.Values.Load is | |
| 2 | use TypeTyped = Semantic.Types.Typed; | |
| 3 | use Semantic.Types.Type; | |
| 4 | use SymbolBase = Semantic.Symbols.Symbol; | |
| 5 | ||
| 6 | class SYMBOL: Value, TypeTyped is | |
| 7 | symbol: SymbolBase; | |
| 8 | symbol_as_typed: TypeTyped => cast TypeTyped?(symbol)!; | |
| 9 | has_symbol: bool => true; | |
| 10 | has_address: bool => true; | |
| 11 | is_consumable: bool => false; | |
| 12 | ||
| 13 | // Concrete type at construction time. Snapshotted so later | |
| 14 | // mutation of `symbol.type` (e.g. type-narrowing release | |
| 15 | // restoring a Variable's declared type) doesn't change the | |
| 16 | // type observed by IR consumers — the load *was* of a value | |
| 17 | // of `_snapshot_type`, regardless of where the symbol's | |
| 18 | // type ends up later. Null when the symbol's type was an | |
| 19 | // inference placeholder at load time; that case stays lazy | |
| 20 | // so iterative-inference resolution still flows through. | |
| 21 | _snapshot_type: Type?; | |
| 22 | ||
| 23 | type: Type => | |
| 24 | if _snapshot_type? then | |
| 25 | _snapshot_type | |
| 26 | else | |
| 27 | symbol_as_typed.type! | |
| 28 | fi; | |
| 29 | ||
| 30 | // Pin the snapshotted type to a flow-narrowed form. Used | |
| 31 | // when optional-narrowing establishes the loaded variable is | |
| 32 | // non-null at this use site: the load *is* of the | |
| 33 | // non-optional type, even though the symbol's declared type | |
| 34 | // still carries `?`. Mirrors how `isa`-narrowing reaches the | |
| 35 | // snapshot via a mutated `symbol.type` at construction time. | |
| 36 | narrow_snapshot_type(narrowed: Type) is | |
| 37 | _snapshot_type = narrowed; | |
| 38 | si | |
| 39 | ||
| 40 | from: Value?; | |
| 41 | ||
| 42 | init(from: Value?, symbol: SymbolBase) is | |
| 43 | super.init(); | |
| 44 | ||
| 45 | self.from = from; | |
| 46 | self.symbol = symbol; | |
| 47 | ||
| 48 | let typed = cast TypeTyped?(symbol); | |
| 49 | ||
| 50 | if typed? then | |
| 51 | let typed_type = typed.type; | |
| 52 | ||
| 53 | if typed_type? /\ !typed_type.is_sentinel then | |
| 54 | _snapshot_type = typed_type; | |
| 55 | fi | |
| 56 | fi | |
| 57 | si | |
| 58 | ||
| 59 | gen(context: IR.CONTEXT) is | |
| 60 | gen(from, context); | |
| 61 | context.fixme("load member {symbol.get_il_reference()}"); | |
| 62 | si | |
| 63 | ||
| 64 | gen_address(context: IR.CONTEXT) is | |
| 65 | gen(from, context); | |
| 66 | context.fixme("load member address {symbol.get_il_reference()}"); | |
| 67 | si | |
| 68 | ||
| 69 | to_string() -> string => | |
| 70 | "load:[{type}]({from},\"{symbol.name}\")"; | |
| 71 | si | |
| 72 | si |