authorgravatar for jacoblevgw@gmail.comJacob G-W <jacoblevgw@gmail.com> 2021-06-23 14:32:21-04:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2021-06-25 08:57:03+03:00
log2d2a6ed1a46349355650bfdd68688738c67bbf9c
tree9f3b593da5ea52f083143cc3c536695d6e04f3d2
parent4adcd560ce4c742791cf1c1d34cdb16f805ffcfd

stage2: implement @setRuntimeSafety


2 files changed, 11 insertions(+), 4 deletions(-)

src/Module.zig+5-2
...@@ -1151,6 +1151,9 @@ pub const Scope = struct {...@@ -1151,6 +1151,9 @@ pub const Scope = struct {
11511151
1152 is_comptime: bool,1152 is_comptime: bool,
11531153
1154 /// when null, it is determined by build mode, changed by @setRuntimeSafety
1155 want_safety: ?bool = null,
1156
1154 /// This `Block` maps a block ZIR instruction to the corresponding1157 /// This `Block` maps a block ZIR instruction to the corresponding
1155 /// AIR instruction for break instruction analysis.1158 /// AIR instruction for break instruction analysis.
1156 pub const Label = struct {1159 pub const Label = struct {
...@@ -1195,12 +1198,12 @@ pub const Scope = struct {...@@ -1195,12 +1198,12 @@ pub const Scope = struct {
1195 .runtime_cond = parent.runtime_cond,1198 .runtime_cond = parent.runtime_cond,
1196 .runtime_loop = parent.runtime_loop,1199 .runtime_loop = parent.runtime_loop,
1197 .runtime_index = parent.runtime_index,1200 .runtime_index = parent.runtime_index,
1201 .want_safety = parent.want_safety,
1198 };1202 };
1199 }1203 }
12001204
1201 pub fn wantSafety(block: *const Block) bool {1205 pub fn wantSafety(block: *const Block) bool {
1202 // TODO take into account scope's safety overrides1206 return block.want_safety orelse switch (block.sema.mod.optimizeMode()) {
1203 return switch (block.sema.mod.optimizeMode()) {
1204 .Debug => true,1207 .Debug => true,
1205 .ReleaseSafe => true,1208 .ReleaseSafe => true,
1206 .ReleaseFast => false,1209 .ReleaseFast => false,
src/Sema.zig+6-2
...@@ -2040,8 +2040,12 @@ fn zirSetFloatMode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inner...@@ -2040,8 +2040,12 @@ fn zirSetFloatMode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inner
20402040
2041fn zirSetRuntimeSafety(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!void {2041fn zirSetRuntimeSafety(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!void {
2042 const inst_data = sema.code.instructions.items(.data)[inst].un_node;2042 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
2043 const src: LazySrcLoc = inst_data.src();2043 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
2044 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirSetRuntimeSafety", .{});2044
2045 const op = try sema.resolveInst(inst_data.operand);
2046 const op_coerced = try sema.coerce(block, Type.initTag(.bool), op, operand_src);
2047 const b = (try sema.resolveConstValue(block, operand_src, op_coerced)).toBool();
2048 block.want_safety = b;
2045}2049}
20462050
2047fn zirBreakpoint(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!void {2051fn zirBreakpoint(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!void {