Skip to content

Commit 9be8a90

Browse files
committed
Revert "implement @expect builtin (#19658)"
This reverts commit a7de02e. This did not implement the accepted proposal, and I did not sign off on the changes. I would like a chance to review this, please.
1 parent a7de02e commit 9be8a90

25 files changed

+1
-202
lines changed

doc/langref.html.in

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4799,14 +4799,6 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
47994799
{#see_also|@export#}
48004800
{#header_close#}
48014801

4802-
{#header_open|@expect#}
4803-
<pre>{#syntax#}@expect(operand: bool, expected: bool) bool{#endsyntax#}</pre>
4804-
<p>
4805-
Informs the optimizer that {#syntax#}operand{#endsyntax#} will likely be {#syntax#}expected{#endsyntax#}, which influences branch compilation to prefer generating the true branch first.
4806-
</p>
4807-
{#code|expect_if.zig#}
4808-
{#header_close#}
4809-
48104802
{#header_open|@fence#}
48114803
<pre>{#syntax#}@fence(order: AtomicOrder) void{#endsyntax#}</pre>
48124804
<p>

doc/langref/expect_if.zig

Lines changed: 0 additions & 15 deletions
This file was deleted.

lib/std/zig/AstGen.zig

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2823,7 +2823,6 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As
28232823
.set_float_mode,
28242824
.set_align_stack,
28252825
.set_cold,
2826-
.expect,
28272826
=> break :b true,
28282827
else => break :b false,
28292828
},
@@ -9293,14 +9292,7 @@ fn builtinCall(
92939292
});
92949293
return rvalue(gz, ri, .void_value, node);
92959294
},
9296-
.expect => {
9297-
const val = try gz.addExtendedPayload(.expect, Zir.Inst.BinNode{
9298-
.node = gz.nodeIndexToRelative(node),
9299-
.lhs = try expr(gz, scope, .{ .rl = .{ .ty = .bool_type } }, params[0]),
9300-
.rhs = try expr(gz, scope, .{ .rl = .{ .ty = .bool_type } }, params[1]),
9301-
});
9302-
return rvalue(gz, ri, val, node);
9303-
},
9295+
93049296
.src => {
93059297
const token_starts = tree.tokens.items(.start);
93069298
const node_start = token_starts[tree.firstToken(node)];

lib/std/zig/AstRlAnnotate.zig

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,10 +1100,5 @@ fn builtinCall(astrl: *AstRlAnnotate, block: ?*Block, ri: ResultInfo, node: Ast.
11001100
_ = try astrl.expr(args[4], block, ResultInfo.type_only);
11011101
return false;
11021102
},
1103-
.expect => {
1104-
_ = try astrl.expr(args[0], block, ResultInfo.none);
1105-
_ = try astrl.expr(args[1], block, ResultInfo.none);
1106-
return false;
1107-
},
11081103
}
11091104
}

lib/std/zig/BuiltinFn.zig

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ pub const Tag = enum {
8282
select,
8383
set_align_stack,
8484
set_cold,
85-
expect,
8685
set_eval_branch_quota,
8786
set_float_mode,
8887
set_runtime_safety,
@@ -744,13 +743,6 @@ pub const list = list: {
744743
.illegal_outside_function = true,
745744
},
746745
},
747-
.{
748-
"@expect",
749-
.{
750-
.tag = .expect,
751-
.param_count = 2,
752-
},
753-
},
754746
.{
755747
"@setEvalBranchQuota",
756748
.{

lib/std/zig/Zir.zig

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2060,9 +2060,6 @@ pub const Inst = struct {
20602060
/// Guaranteed to not have the `ptr_cast` flag.
20612061
/// Uses the `pl_node` union field with payload `FieldParentPtr`.
20622062
field_parent_ptr,
2063-
/// Implements the `@expect` builtin.
2064-
/// `operand` is BinOp
2065-
expect,
20662063

20672064
pub const InstData = struct {
20682065
opcode: Extended,

lib/zig.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,12 +318,6 @@ typedef char bool;
318318
#define zig_noreturn
319319
#endif
320320

321-
#if defined(__GNUC__) || defined(__clang__)
322-
#define zig_expect(op, exp) __builtin_expect(op, exp)
323-
#else
324-
#define zig_expect(op, exp) (op)
325-
#endif
326-
327321
#define zig_bitSizeOf(T) (CHAR_BIT * sizeof(T))
328322

329323
#define zig_compiler_rt_abbrev_uint32_t si

src/Air.zig

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -848,10 +848,6 @@ pub const Inst = struct {
848848
/// Operand is unused and set to Ref.none
849849
work_group_id,
850850

851-
/// Implements @expect builtin.
852-
/// Uses the `bin_op` field.
853-
expect,
854-
855851
pub fn fromCmpOp(op: std.math.CompareOperator, optimized: bool) Tag {
856852
switch (op) {
857853
.lt => return if (optimized) .cmp_lt_optimized else .cmp_lt,
@@ -1521,8 +1517,6 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
15211517
.work_group_id,
15221518
=> return Type.u32,
15231519

1524-
.expect => return Type.bool,
1525-
15261520
.inferred_alloc => unreachable,
15271521
.inferred_alloc_comptime => unreachable,
15281522
}
@@ -1640,7 +1634,6 @@ pub fn mustLower(air: Air, inst: Air.Inst.Index, ip: *const InternPool) bool {
16401634
.add_safe,
16411635
.sub_safe,
16421636
.mul_safe,
1643-
.expect,
16441637
=> true,
16451638

16461639
.add,

src/Liveness.zig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,6 @@ pub fn categorizeOperand(
286286
.cmp_gte_optimized,
287287
.cmp_gt_optimized,
288288
.cmp_neq_optimized,
289-
.expect,
290289
=> {
291290
const o = air_datas[@intFromEnum(inst)].bin_op;
292291
if (o.lhs == operand_ref) return matchOperandSmallIndex(l, inst, 0, .none);
@@ -956,7 +955,6 @@ fn analyzeInst(
956955
.memset,
957956
.memset_safe,
958957
.memcpy,
959-
.expect,
960958
=> {
961959
const o = inst_datas[@intFromEnum(inst)].bin_op;
962960
return analyzeOperands(a, pass, data, inst, .{ o.lhs, o.rhs, .none });

src/Liveness/Verify.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
257257
.memset,
258258
.memset_safe,
259259
.memcpy,
260-
.expect,
261260
=> {
262261
const bin_op = data[@intFromEnum(inst)].bin_op;
263262
try self.verifyInstOperands(inst, .{ bin_op.lhs, bin_op.rhs, .none });

src/Module.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5546,7 +5546,6 @@ pub const Feature = enum {
55465546
/// to generate better machine code in the backends. All backends should migrate to
55475547
/// enabling this feature.
55485548
safety_checked_instructions,
5549-
can_expect,
55505549
};
55515550

55525551
pub fn backendSupportsFeature(zcu: Module, feature: Feature) bool {

src/Sema.zig

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,6 @@ fn analyzeBodyInner(
12581258
.work_group_size => try sema.zirWorkItem( block, extended, extended.opcode),
12591259
.work_group_id => try sema.zirWorkItem( block, extended, extended.opcode),
12601260
.in_comptime => try sema.zirInComptime( block),
1261-
.expect => try sema.zirExpect( block, extended),
12621261
.closure_get => try sema.zirClosureGet( block, extended),
12631262
// zig fmt: on
12641263

@@ -17554,34 +17553,6 @@ fn zirThis(
1755417553
return sema.analyzeDeclVal(block, src, this_decl_index);
1755517554
}
1755617555

17557-
fn zirExpect(sema: *Sema, block: *Block, inst: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
17558-
const bin_op = sema.code.extraData(Zir.Inst.BinNode, inst.operand).data;
17559-
const operand = try sema.resolveInst(bin_op.lhs);
17560-
const expected = try sema.resolveInst(bin_op.rhs);
17561-
17562-
const expected_src = LazySrcLoc{ .node_offset_builtin_call_arg1 = bin_op.node };
17563-
17564-
if (!try sema.isComptimeKnown(expected)) {
17565-
return sema.fail(block, expected_src, "@expect 'expected' must be comptime-known", .{});
17566-
}
17567-
17568-
if (try sema.resolveValue(operand)) |op| {
17569-
return Air.internedToRef(op.toIntern());
17570-
}
17571-
17572-
if (sema.mod.backendSupportsFeature(.can_expect) and sema.mod.optimizeMode() != .Debug) {
17573-
return try block.addInst(.{
17574-
.tag = .expect,
17575-
.data = .{ .bin_op = .{
17576-
.lhs = operand,
17577-
.rhs = expected,
17578-
} },
17579-
});
17580-
} else {
17581-
return operand;
17582-
}
17583-
}
17584-
1758517556
fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
1758617557
const mod = sema.mod;
1758717558
const ip = &mod.intern_pool;

src/arch/aarch64/CodeGen.zig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -803,8 +803,6 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
803803
.@"try" => try self.airTry(inst),
804804
.try_ptr => try self.airTryPtr(inst),
805805

806-
.expect => unreachable,
807-
808806
.dbg_stmt => try self.airDbgStmt(inst),
809807
.dbg_inline_block => try self.airDbgInlineBlock(inst),
810808
.dbg_var_ptr,

src/arch/arm/CodeGen.zig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -844,8 +844,6 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
844844
.wrap_errunion_payload => try self.airWrapErrUnionPayload(inst),
845845
.wrap_errunion_err => try self.airWrapErrUnionErr(inst),
846846

847-
.expect => unreachable,
848-
849847
.add_optimized,
850848
.sub_optimized,
851849
.mul_optimized,

src/arch/riscv64/CodeGen.zig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,8 +1200,6 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
12001200
.@"try" => try self.airTry(inst),
12011201
.try_ptr => return self.fail("TODO: try_ptr", .{}),
12021202

1203-
.expect => unreachable,
1204-
12051203
.dbg_var_ptr,
12061204
.dbg_var_val,
12071205
=> try self.airDbgVar(inst),

src/arch/sparc64/CodeGen.zig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,8 +636,6 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
636636
.@"try" => try self.airTry(inst),
637637
.try_ptr => @panic("TODO try self.airTryPtr(inst)"),
638638

639-
.expect => unreachable,
640-
641639
.dbg_stmt => try self.airDbgStmt(inst),
642640
.dbg_inline_block => try self.airDbgInlineBlock(inst),
643641
.dbg_var_ptr,

src/arch/wasm/CodeGen.zig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2016,8 +2016,6 @@ fn genInst(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
20162016
.c_va_start,
20172017
=> |tag| return func.fail("TODO: Implement wasm inst: {s}", .{@tagName(tag)}),
20182018

2019-
.expect => unreachable,
2020-
20212019
.atomic_load => func.airAtomicLoad(inst),
20222020
.atomic_store_unordered,
20232021
.atomic_store_monotonic,

src/arch/x86_64/CodeGen.zig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,8 +2014,6 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
20142014

20152015
.abs => try self.airAbs(inst),
20162016

2017-
.expect => unreachable,
2018-
20192017
.add_with_overflow => try self.airAddSubWithOverflow(inst),
20202018
.sub_with_overflow => try self.airAddSubWithOverflow(inst),
20212019
.mul_with_overflow => try self.airMulWithOverflow(inst),

src/codegen/c.zig

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3343,8 +3343,6 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail,
33433343

33443344
.@"try" => try airTry(f, inst),
33453345
.try_ptr => try airTryPtr(f, inst),
3346-
3347-
.expect => try airExpect(f, inst),
33483346

33493347
.dbg_stmt => try airDbgStmt(f, inst),
33503348
.dbg_inline_block => try airDbgInlineBlock(f, inst),
@@ -4706,27 +4704,6 @@ fn airTryPtr(f: *Function, inst: Air.Inst.Index) !CValue {
47064704
return lowerTry(f, inst, extra.data.ptr, body, err_union_ty, true);
47074705
}
47084706

4709-
fn airExpect(f: *Function, inst: Air.Inst.Index) !CValue {
4710-
const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
4711-
const operand = try f.resolveInst(bin_op.lhs);
4712-
const expected = try f.resolveInst(bin_op.rhs);
4713-
4714-
const writer = f.object.writer();
4715-
const local = try f.allocLocal(inst, Type.bool);
4716-
const a = try Assignment.start(f, writer, CType.bool);
4717-
try f.writeCValue(writer, local, .Other);
4718-
try a.assign(f, writer);
4719-
4720-
try writer.writeAll("zig_expect(");
4721-
try f.writeCValue(writer, operand, .FunctionArgument);
4722-
try writer.writeAll(", ");
4723-
try f.writeCValue(writer, expected, .FunctionArgument);
4724-
try writer.writeAll(")");
4725-
4726-
try a.end(f, writer);
4727-
return local;
4728-
}
4729-
47304707
fn lowerTry(
47314708
f: *Function,
47324709
inst: Air.Inst.Index,

src/codegen/llvm.zig

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5038,8 +5038,6 @@ pub const FuncGen = struct {
50385038
.slice_ptr => try self.airSliceField(inst, 0),
50395039
.slice_len => try self.airSliceField(inst, 1),
50405040

5041-
.expect => try self.airExpect(inst),
5042-
50435041
.call => try self.airCall(inst, .auto),
50445042
.call_always_tail => try self.airCall(inst, .always_tail),
50455043
.call_never_tail => try self.airCall(inst, .never_tail),
@@ -6367,26 +6365,6 @@ pub const FuncGen = struct {
63676365
return result;
63686366
}
63696367

6370-
// Note that the LowerExpectPass only runs in Release modes
6371-
fn airExpect(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
6372-
const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
6373-
6374-
const operand = try self.resolveInst(bin_op.lhs);
6375-
const expected = try self.resolveInst(bin_op.rhs);
6376-
6377-
return try self.wip.callIntrinsic(
6378-
.normal,
6379-
.none,
6380-
.expect,
6381-
&.{operand.typeOfWip(&self.wip)},
6382-
&.{
6383-
operand,
6384-
expected,
6385-
},
6386-
"",
6387-
);
6388-
}
6389-
63906368
fn sliceOrArrayPtr(fg: *FuncGen, ptr: Builder.Value, ty: Type) Allocator.Error!Builder.Value {
63916369
const o = fg.dg.object;
63926370
const mod = o.module;

src/print_air.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ const Writer = struct {
162162
.memcpy,
163163
.memset,
164164
.memset_safe,
165-
.expect,
166165
=> try w.writeBinOp(s, inst),
167166

168167
.is_null,

src/print_zir.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,6 @@ const Writer = struct {
591591
.wasm_memory_grow,
592592
.prefetch,
593593
.c_va_arg,
594-
.expect,
595594
=> {
596595
const inst_data = self.code.extraData(Zir.Inst.BinNode, extended.operand).data;
597596
const src = LazySrcLoc.nodeOffset(inst_data.node);

src/target.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,5 @@ pub fn backendSupportsFeature(
535535
.error_set_has_value => use_llvm or cpu_arch.isWasm(),
536536
.field_reordering => ofmt == .c or use_llvm,
537537
.safety_checked_instructions => use_llvm,
538-
.can_expect => use_llvm or ofmt == .c,
539538
};
540539
}

0 commit comments

Comments
 (0)