| ... | @@ -45,6 +45,7 @@ branch_count: u32 = 0, | ... | @@ -45,6 +45,7 @@ branch_count: u32 = 0, |
| 45 | /// contain a mapped source location. | 45 | /// contain a mapped source location. |
| 46 | src: LazySrcLoc = .{ .token_offset = 0 }, | 46 | src: LazySrcLoc = .{ .token_offset = 0 }, |
| 47 | next_arg_index: usize = 0, | 47 | next_arg_index: usize = 0, |
| | 48 | decl_val_table: std.AutoHashMapUnmanaged(*Decl, Air.Inst.Ref) = .{}, |
| 48 | | 49 | |
| 49 | const std = @import("std"); | 50 | const std = @import("std"); |
| 50 | const mem = std.mem; | 51 | const mem = std.mem; |
| ... | @@ -77,6 +78,7 @@ pub fn deinit(sema: *Sema) void { | ... | @@ -77,6 +78,7 @@ pub fn deinit(sema: *Sema) void { |
| 77 | sema.air_values.deinit(gpa); | 78 | sema.air_values.deinit(gpa); |
| 78 | sema.air_variables.deinit(gpa); | 79 | sema.air_variables.deinit(gpa); |
| 79 | sema.inst_map.deinit(gpa); | 80 | sema.inst_map.deinit(gpa); |
| | 81 | sema.decl_val_table.deinit(gpa); |
| 80 | sema.* = undefined; | 82 | sema.* = undefined; |
| 81 | } | 83 | } |
| 82 | | 84 | |
| ... | @@ -7159,9 +7161,23 @@ fn coerceArrayPtrToMany( | ... | @@ -7159,9 +7161,23 @@ fn coerceArrayPtrToMany( |
| 7159 | return sema.mod.fail(&block.base, inst_src, "TODO implement coerceArrayPtrToMany runtime instruction", .{}); | 7161 | return sema.mod.fail(&block.base, inst_src, "TODO implement coerceArrayPtrToMany runtime instruction", .{}); |
| 7160 | } | 7162 | } |
| 7161 | | 7163 | |
| 7162 | fn analyzeDeclVal(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, decl: *Decl) CompileError!Air.Inst.Ref { | 7164 | fn analyzeDeclVal( |
| | 7165 | sema: *Sema, |
| | 7166 | block: *Scope.Block, |
| | 7167 | src: LazySrcLoc, |
| | 7168 | decl: *Decl, |
| | 7169 | ) CompileError!Air.Inst.Ref { |
| | 7170 | if (sema.decl_val_table.get(decl)) |result| { |
| | 7171 | return result; |
| | 7172 | } |
| 7163 | const decl_ref = try sema.analyzeDeclRef(block, src, decl); | 7173 | const decl_ref = try sema.analyzeDeclRef(block, src, decl); |
| 7164 | return sema.analyzeLoad(block, src, decl_ref, src); | 7174 | const result = try sema.analyzeLoad(block, src, decl_ref, src); |
| | 7175 | if (Air.refToIndex(result)) |index| { |
| | 7176 | if (sema.air_instructions.items(.tag)[index] == .constant) { |
| | 7177 | sema.decl_val_table.put(sema.gpa, decl, result) catch {}; |
| | 7178 | } |
| | 7179 | } |
| | 7180 | return result; |
| 7165 | } | 7181 | } |
| 7166 | | 7182 | |
| 7167 | fn analyzeDeclRef(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, decl: *Decl) CompileError!Air.Inst.Ref { | 7183 | fn analyzeDeclRef(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, decl: *Decl) CompileError!Air.Inst.Ref { |