fix: add .break_inline ir instruction to ensure interned values can be referenced
This commit is contained in:
parent
aad95a75ee
commit
01cc996183
4 changed files with 15 additions and 4 deletions
|
|
@ -1173,7 +1173,7 @@ fn choiceStmt(gi: *GenIr, scope: *Scope, node: *const Ast.Node) InnerError!void
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var body_block = gi.makeSubBlock();
|
var body_block = block_3.makeSubBlock();
|
||||||
defer body_block.unstack();
|
defer body_block.unstack();
|
||||||
|
|
||||||
if (trailing_divert) |trailing| {
|
if (trailing_divert) |trailing| {
|
||||||
|
|
@ -1190,7 +1190,7 @@ fn choiceStmt(gi: *GenIr, scope: *Scope, node: *const Ast.Node) InnerError!void
|
||||||
const rhs_body = block_3.instructionsSliceUpto(&body_block);
|
const rhs_body = block_3.instructionsSliceUpto(&body_block);
|
||||||
const body = body_block.instructionsSlice();
|
const body = body_block.instructionsSlice();
|
||||||
const case_extra_len =
|
const case_extra_len =
|
||||||
@typeInfo(Ir.Inst.SwitchBr.Case).@"struct".fields.len +
|
@typeInfo(Ir.Inst.ChoiceBr.Case).@"struct".fields.len +
|
||||||
lhs_body.len + mhs_body.len + rhs_body.len + body.len;
|
lhs_body.len + mhs_body.len + rhs_body.len + body.len;
|
||||||
|
|
||||||
try astgen.extra.ensureUnusedCapacity(gpa, case_extra_len);
|
try astgen.extra.ensureUnusedCapacity(gpa, case_extra_len);
|
||||||
|
|
@ -1441,9 +1441,10 @@ fn varDecl(gi: *GenIr, scope: *Scope, decl_node: *const Ast.Node) !void {
|
||||||
var decl_block = gi.makeSubBlock();
|
var decl_block = gi.makeSubBlock();
|
||||||
defer decl_block.unstack();
|
defer decl_block.unstack();
|
||||||
|
|
||||||
const var_inst = try decl_block.makePayloadNode(.decl_var);
|
|
||||||
_ = try expr(&decl_block, scope, expr_node);
|
|
||||||
const name_str = try astgen.strFromNode(identifier_node);
|
const name_str = try astgen.strFromNode(identifier_node);
|
||||||
|
const var_inst = try decl_block.makePayloadNode(.decl_var);
|
||||||
|
const rvalue_inst = try expr(&decl_block, scope, expr_node);
|
||||||
|
_ = try decl_block.addBinaryNode(.break_inline, var_inst.toRef(), rvalue_inst);
|
||||||
|
|
||||||
try setDeclVarPayload(var_inst, &decl_block, identifier_node);
|
try setDeclVarPayload(var_inst, &decl_block, identifier_node);
|
||||||
try setDeclaration(decl_inst, .{
|
try setDeclaration(decl_inst, .{
|
||||||
|
|
|
||||||
|
|
@ -201,6 +201,7 @@ pub const Inst = struct {
|
||||||
block,
|
block,
|
||||||
condbr,
|
condbr,
|
||||||
@"break",
|
@"break",
|
||||||
|
break_inline,
|
||||||
switch_br,
|
switch_br,
|
||||||
/// Uses the `un` union field.
|
/// Uses the `un` union field.
|
||||||
content_push,
|
content_push,
|
||||||
|
|
@ -388,6 +389,7 @@ pub const Inst = struct {
|
||||||
.ret,
|
.ret,
|
||||||
.implicit_ret,
|
.implicit_ret,
|
||||||
.@"break",
|
.@"break",
|
||||||
|
.break_inline,
|
||||||
.done,
|
.done,
|
||||||
.exit,
|
.exit,
|
||||||
=> true,
|
=> true,
|
||||||
|
|
|
||||||
|
|
@ -629,6 +629,12 @@ fn irBreak(sema: *Sema, inst: Ir.Inst.Index) InnerError!void {
|
||||||
_ = inst;
|
_ = inst;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn irBreakInline(sema: *Sema, inst: Ir.Inst.Index) InnerError!ValueInfo {
|
||||||
|
const data = sema.ir.instructions[@intFromEnum(inst)].data.bin;
|
||||||
|
const rvalue_inst = sema.resolveInst(data.rhs);
|
||||||
|
return rvalue_inst;
|
||||||
|
}
|
||||||
|
|
||||||
fn irBlock(sema: *Sema, builder: *Builder, inst: Ir.Inst.Index) InnerError!void {
|
fn irBlock(sema: *Sema, builder: *Builder, inst: Ir.Inst.Index) InnerError!void {
|
||||||
const data = sema.ir.instructions[@intFromEnum(inst)].data.payload;
|
const data = sema.ir.instructions[@intFromEnum(inst)].data.payload;
|
||||||
const extra = sema.ir.extraData(Ir.Inst.Block, data.extra_index);
|
const extra = sema.ir.extraData(Ir.Inst.Block, data.extra_index);
|
||||||
|
|
@ -1002,6 +1008,7 @@ fn analyzeBodyInner(
|
||||||
try irBreak(sema, inst);
|
try irBreak(sema, inst);
|
||||||
continue;
|
continue;
|
||||||
},
|
},
|
||||||
|
.break_inline => try irBreakInline(sema, inst),
|
||||||
.block => {
|
.block => {
|
||||||
try irBlock(sema, builder, inst);
|
try irBlock(sema, builder, inst);
|
||||||
continue;
|
continue;
|
||||||
|
|
|
||||||
|
|
@ -318,6 +318,7 @@ pub const Writer = struct {
|
||||||
.decl_ref => try self.writeStrTokInst(w, inst),
|
.decl_ref => try self.writeStrTokInst(w, inst),
|
||||||
.condbr => try self.writeCondbrInst(w, inst),
|
.condbr => try self.writeCondbrInst(w, inst),
|
||||||
.@"break" => try self.writeBreakInst(w, inst),
|
.@"break" => try self.writeBreakInst(w, inst),
|
||||||
|
.break_inline => try self.writeBinaryInst(w, inst),
|
||||||
.switch_br => try self.writeSwitchBrInst(w, inst),
|
.switch_br => try self.writeSwitchBrInst(w, inst),
|
||||||
.alloc => {},
|
.alloc => {},
|
||||||
.load => try self.writeUnaryInst(w, inst),
|
.load => try self.writeUnaryInst(w, inst),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue