| author | |
| committer | |
| log | 2d2a6ed1a46349355650bfdd68688738c67bbf9c |
| tree | 9f3b593da5ea52f083143cc3c536695d6e04f3d2 |
| parent | 4adcd560ce4c742791cf1c1d34cdb16f805ffcfd |
2 files changed, 11 insertions(+), 4 deletions(-)
src/Module.zig+5-2| ... | ... | @@ -1151,6 +1151,9 @@ pub const Scope = struct { |
| 1151 | 1151 | |
| 1152 | 1152 | is_comptime: bool, |
| 1153 | 1153 | |
| 1154 | /// when null, it is determined by build mode, changed by @setRuntimeSafety | |
| 1155 | want_safety: ?bool = null, | |
| 1156 | ||
| 1154 | 1157 | /// This `Block` maps a block ZIR instruction to the corresponding |
| 1155 | 1158 | /// AIR instruction for break instruction analysis. |
| 1156 | 1159 | pub const Label = struct { |
| ... | ... | @@ -1195,12 +1198,12 @@ pub const Scope = struct { |
| 1195 | 1198 | .runtime_cond = parent.runtime_cond, |
| 1196 | 1199 | .runtime_loop = parent.runtime_loop, |
| 1197 | 1200 | .runtime_index = parent.runtime_index, |
| 1201 | .want_safety = parent.want_safety, | |
| 1198 | 1202 | }; |
| 1199 | 1203 | } |
| 1200 | 1204 | |
| 1201 | 1205 | pub fn wantSafety(block: *const Block) bool { |
| 1202 | // TODO take into account scope's safety overrides | |
| 1203 | return switch (block.sema.mod.optimizeMode()) { | |
| 1206 | return block.want_safety orelse switch (block.sema.mod.optimizeMode()) { | |
| 1204 | 1207 | .Debug => true, |
| 1205 | 1208 | .ReleaseSafe => true, |
| 1206 | 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 | 2040 | |
| 2041 | 2041 | fn zirSetRuntimeSafety(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!void { |
| 2042 | 2042 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 2043 | const src: LazySrcLoc = inst_data.src(); | |
| 2044 | return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirSetRuntimeSafety", .{}); | |
| 2043 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | |
| 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 | } |
| 2046 | 2050 | |
| 2047 | 2051 | fn zirBreakpoint(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!void { |