stage2: implement @setRuntimeSafety
This commit is contained in:
committed by
Veikka Tuominen
parent
4adcd560ce
commit
2d2a6ed1a4
@@ -1151,6 +1151,9 @@ pub const Scope = struct {
|
||||
|
||||
is_comptime: bool,
|
||||
|
||||
/// when null, it is determined by build mode, changed by @setRuntimeSafety
|
||||
want_safety: ?bool = null,
|
||||
|
||||
/// This `Block` maps a block ZIR instruction to the corresponding
|
||||
/// AIR instruction for break instruction analysis.
|
||||
pub const Label = struct {
|
||||
@@ -1195,12 +1198,12 @@ pub const Scope = struct {
|
||||
.runtime_cond = parent.runtime_cond,
|
||||
.runtime_loop = parent.runtime_loop,
|
||||
.runtime_index = parent.runtime_index,
|
||||
.want_safety = parent.want_safety,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn wantSafety(block: *const Block) bool {
|
||||
// TODO take into account scope's safety overrides
|
||||
return switch (block.sema.mod.optimizeMode()) {
|
||||
return block.want_safety orelse switch (block.sema.mod.optimizeMode()) {
|
||||
.Debug => true,
|
||||
.ReleaseSafe => true,
|
||||
.ReleaseFast => false,
|
||||
|
||||
@@ -2040,8 +2040,12 @@ fn zirSetFloatMode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inner
|
||||
|
||||
fn zirSetRuntimeSafety(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!void {
|
||||
const inst_data = sema.code.instructions.items(.data)[inst].un_node;
|
||||
const src: LazySrcLoc = inst_data.src();
|
||||
return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirSetRuntimeSafety", .{});
|
||||
const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
|
||||
|
||||
const op = try sema.resolveInst(inst_data.operand);
|
||||
const op_coerced = try sema.coerce(block, Type.initTag(.bool), op, operand_src);
|
||||
const b = (try sema.resolveConstValue(block, operand_src, op_coerced)).toBool();
|
||||
block.want_safety = b;
|
||||
}
|
||||
|
||||
fn zirBreakpoint(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!void {
|
||||
|
||||
Reference in New Issue
Block a user