Skip to content

Commit c3ae909

Browse files
committed
Revert "AstGen: preserve inferred ptr result loc for breaks"
This reverts commit 8bf3e1f, which introduced miscompilations for peer expressions any time they needed coercions to runtime types. I opened #11957 as a proposal to accomplish the goal of the reverted commit. Closes #11898
1 parent a058696 commit c3ae909

File tree

7 files changed

+21
-51
lines changed

7 files changed

+21
-51
lines changed

lib/std/priority_queue.zig

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,6 @@ const PQlt = PriorityQueue(u32, void, lessThan);
286286
const PQgt = PriorityQueue(u32, void, greaterThan);
287287

288288
test "std.PriorityQueue: add and remove min heap" {
289-
if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
290289
var queue = PQlt.init(testing.allocator, {});
291290
defer queue.deinit();
292291

@@ -305,7 +304,6 @@ test "std.PriorityQueue: add and remove min heap" {
305304
}
306305

307306
test "std.PriorityQueue: add and remove same min heap" {
308-
if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
309307
var queue = PQlt.init(testing.allocator, {});
310308
defer queue.deinit();
311309

@@ -355,7 +353,6 @@ test "std.PriorityQueue: peek" {
355353
}
356354

357355
test "std.PriorityQueue: sift up with odd indices" {
358-
if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
359356
var queue = PQlt.init(testing.allocator, {});
360357
defer queue.deinit();
361358
const items = [_]u32{ 15, 7, 21, 14, 13, 22, 12, 6, 7, 25, 5, 24, 11, 16, 15, 24, 2, 1 };
@@ -370,7 +367,6 @@ test "std.PriorityQueue: sift up with odd indices" {
370367
}
371368

372369
test "std.PriorityQueue: addSlice" {
373-
if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
374370
var queue = PQlt.init(testing.allocator, {});
375371
defer queue.deinit();
376372
const items = [_]u32{ 15, 7, 21, 14, 13, 22, 12, 6, 7, 25, 5, 24, 11, 16, 15, 24, 2, 1 };
@@ -403,7 +399,6 @@ test "std.PriorityQueue: fromOwnedSlice trivial case 1" {
403399
}
404400

405401
test "std.PriorityQueue: fromOwnedSlice" {
406-
if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest;
407402
const items = [_]u32{ 15, 7, 21, 14, 13, 22, 12, 6, 7, 25, 5, 24, 11, 16, 15, 24, 2, 1 };
408403
const heap_items = try testing.allocator.dupe(u32, items[0..]);
409404
var queue = PQlt.fromOwnedSlice(testing.allocator, heap_items[0..], {});
@@ -416,7 +411,6 @@ test "std.PriorityQueue: fromOwnedSlice" {
416411
}
417412

418413
test "std.PriorityQueue: add and remove max heap" {
419-
if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
420414
var queue = PQgt.init(testing.allocator, {});
421415
defer queue.deinit();
422416

@@ -435,7 +429,6 @@ test "std.PriorityQueue: add and remove max heap" {
435429
}
436430

437431
test "std.PriorityQueue: add and remove same max heap" {
438-
if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
439432
var queue = PQgt.init(testing.allocator, {});
440433
defer queue.deinit();
441434

@@ -476,7 +469,6 @@ test "std.PriorityQueue: iterator" {
476469
}
477470

478471
test "std.PriorityQueue: remove at index" {
479-
if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
480472
var queue = PQlt.init(testing.allocator, {});
481473
defer queue.deinit();
482474

@@ -512,7 +504,6 @@ test "std.PriorityQueue: iterator while empty" {
512504
}
513505

514506
test "std.PriorityQueue: shrinkAndFree" {
515-
if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
516507
var queue = PQlt.init(testing.allocator, {});
517508
defer queue.deinit();
518509

@@ -536,7 +527,6 @@ test "std.PriorityQueue: shrinkAndFree" {
536527
}
537528

538529
test "std.PriorityQueue: update min heap" {
539-
if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
540530
var queue = PQlt.init(testing.allocator, {});
541531
defer queue.deinit();
542532

@@ -552,7 +542,6 @@ test "std.PriorityQueue: update min heap" {
552542
}
553543

554544
test "std.PriorityQueue: update same min heap" {
555-
if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
556545
var queue = PQlt.init(testing.allocator, {});
557546
defer queue.deinit();
558547

@@ -569,7 +558,6 @@ test "std.PriorityQueue: update same min heap" {
569558
}
570559

571560
test "std.PriorityQueue: update max heap" {
572-
if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
573561
var queue = PQgt.init(testing.allocator, {});
574562
defer queue.deinit();
575563

@@ -585,7 +573,6 @@ test "std.PriorityQueue: update max heap" {
585573
}
586574

587575
test "std.PriorityQueue: update same max heap" {
588-
if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
589576
var queue = PQgt.init(testing.allocator, {});
590577
defer queue.deinit();
591578

@@ -602,7 +589,6 @@ test "std.PriorityQueue: update same max heap" {
602589
}
603590

604591
test "std.PriorityQueue: siftUp in remove" {
605-
if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
606592
var queue = PQlt.init(testing.allocator, {});
607593
defer queue.deinit();
608594

@@ -623,7 +609,6 @@ fn contextLessThan(context: []const u32, a: usize, b: usize) Order {
623609
const CPQlt = PriorityQueue(usize, []const u32, contextLessThan);
624610

625611
test "std.PriorityQueue: add and remove min heap with contextful comparator" {
626-
if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
627612
const context = [_]u32{ 5, 3, 4, 2, 2, 8, 0 };
628613

629614
var queue = CPQlt.init(testing.allocator, context[0..]);

src/AstGen.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10007,7 +10007,7 @@ const GenZir = struct {
1000710007
.inferred_ptr => |ptr| {
1000810008
gz.rl_ty_inst = .none;
1000910009
gz.rl_ptr = ptr;
10010-
gz.break_result_loc = parent_rl;
10010+
gz.break_result_loc = .{ .block_ptr = gz };
1001110011
},
1001210012

1001310013
.block_ptr => |parent_block_scope| {

src/Sema.zig

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3079,28 +3079,6 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
30793079

30803080
if (var_is_mut) {
30813081
try sema.validateVarType(block, ty_src, final_elem_ty, false);
3082-
3083-
// The value might have been bitcasted into a comptime only
3084-
// pointer type such as `*@Type(.EnumLiteral)` so we must now
3085-
// update all the stores to not give backends invalid AIR.
3086-
3087-
var air_tags = sema.air_instructions.items(.tag);
3088-
var air_data = sema.air_instructions.items(.data);
3089-
var peer_inst_index: usize = 0;
3090-
var i = ptr_inst;
3091-
while (i < air_tags.len and peer_inst_index < peer_inst_list.len) : (i += 1) {
3092-
if (air_tags[i] != .store) continue;
3093-
if (air_data[i].bin_op.rhs == peer_inst_list[peer_inst_index]) {
3094-
peer_inst_index += 1;
3095-
_ = (try sema.resolveMaybeUndefVal(block, .unneeded, air_data[i].bin_op.rhs)) orelse continue;
3096-
const coerced_val = try sema.coerce(block, final_elem_ty, air_data[i].bin_op.rhs, .unneeded);
3097-
air_tags = sema.air_instructions.items(.tag);
3098-
air_data = sema.air_instructions.items(.data);
3099-
3100-
air_data[i].bin_op.lhs = ptr;
3101-
air_data[i].bin_op.rhs = coerced_val;
3102-
}
3103-
}
31043082
} else ct: {
31053083
// Detect if the value is comptime known. In such case, the
31063084
// last 3 AIR instructions of the block will look like this:

test/behavior/basic.zig

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -928,18 +928,6 @@ test "try in labeled block doesn't cast to wrong type" {
928928
_ = s;
929929
}
930930

931-
test "comptime int in switch in catch is casted to correct inferred type" {
932-
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
933-
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
934-
935-
var a: error{ A, B }!u64 = 0;
936-
var b = a catch |err| switch (err) {
937-
error.A => 0,
938-
else => unreachable,
939-
};
940-
_ = b;
941-
}
942-
943931
test "vector initialized with array init syntax has proper type" {
944932
comptime {
945933
const actual = -@Vector(4, i32){ 1, 2, 3, 4 };

test/behavior/cast.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,7 @@ test "peer type resolution: error union after non-error" {
812812
}
813813

814814
test "peer cast *[0]T to E![]const T" {
815+
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
815816
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
816817
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
817818
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
@@ -826,6 +827,7 @@ test "peer cast *[0]T to E![]const T" {
826827
}
827828

828829
test "peer cast *[0]T to []const T" {
830+
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
829831
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
830832
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
831833
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO

test/behavior/error.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ test "simple else prong allowed even when all errors handled" {
709709
}
710710
};
711711
var value = S.foo() catch |err| switch (err) {
712-
error.Foo => 255,
712+
error.Foo => @as(u8, 255),
713713
else => |e| return e,
714714
};
715715
try expect(value == 255);

test/behavior/if.zig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,20 @@ test "if prongs cast to expected type instead of peer type resolution" {
111111
try S.doTheTest(false);
112112
comptime try S.doTheTest(false);
113113
}
114+
115+
test "if peer expressions inferred optional type" {
116+
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
117+
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
118+
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
119+
120+
var self: []const u8 = "abcdef";
121+
var index: usize = 0;
122+
var left_index = (index << 1) + 1;
123+
var right_index = left_index + 1;
124+
var left = if (left_index < self.len) self[left_index] else null;
125+
var right = if (right_index < self.len) self[right_index] else null;
126+
try expect(left_index < self.len);
127+
try expect(right_index < self.len);
128+
try expect(left.? == 98);
129+
try expect(right.? == 99);
130+
}

0 commit comments

Comments
 (0)