Skip to content

Commit 8c4727f

Browse files
committed
Sema: remove generic function from monomorphed_funcs on any error
1 parent 3e084d8 commit 8c4727f

3 files changed

Lines changed: 31 additions & 8 deletions

File tree

src/Module.zig

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3519,14 +3519,6 @@ pub fn deinit(mod: *Module) void {
35193519
pub fn destroyDecl(mod: *Module, decl_index: Decl.Index) void {
35203520
const gpa = mod.gpa;
35213521
{
3522-
if (mod.failed_decls.contains(decl_index)) {
3523-
blk: {
3524-
const errs = mod.comp.getAllErrorsAlloc() catch break :blk;
3525-
for (errs.list) |err| Compilation.AllErrors.Message.renderToStdErr(err, .no_color);
3526-
}
3527-
// TODO restore test case triggering this panic
3528-
@panic("Zig compiler bug: attempted to destroy declaration with an attached error");
3529-
}
35303522
const decl = mod.declPtr(decl_index);
35313523
log.debug("destroy {*} ({s})", .{ decl, decl.name });
35323524
_ = mod.test_functions.swapRemove(decl_index);

src/Sema.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7174,6 +7174,7 @@ fn instantiateGenericCall(
71747174
return err;
71757175
},
71767176
else => {
7177+
assert(mod.monomorphed_funcs.remove(new_module_func));
71777178
{
71787179
errdefer new_decl_arena.deinit();
71797180
try new_decl.finalizeNewArena(&new_decl_arena);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
pub export fn entry1() void {
2+
@setEvalBranchQuota(1001);
3+
// Return type evaluation should inherit both the
4+
// parent's branch quota and count meaning
5+
// at least 2002 backwards branches are required.
6+
comptime var i = 0;
7+
inline while (i < 1000) : (i += 1) {}
8+
_ = simple(10);
9+
}
10+
pub export fn entry2() void {
11+
@setEvalBranchQuota(2001);
12+
comptime var i = 0;
13+
inline while (i < 1000) : (i += 1) {}
14+
_ = simple(10);
15+
}
16+
fn simple(comptime n: usize) Type(n) {
17+
return n;
18+
}
19+
fn Type(comptime n: usize) type {
20+
if (n <= 1) return usize;
21+
return Type(n - 1);
22+
}
23+
24+
// error
25+
// backend=stage2
26+
// target=native
27+
//
28+
// :21:16: error: evaluation exceeded 1001 backwards branches
29+
// :21:16: note: use @setEvalBranchQuota() to raise the branch limit from 1001
30+
// :16:34: note: called from here

0 commit comments

Comments
 (0)