| ... | @@ -2993,7 +2993,12 @@ fn zirEnumDecl( | ... | @@ -2993,7 +2993,12 @@ fn zirEnumDecl( |
| 2993 | }, | 2993 | }, |
| 2994 | .existing => |ty| return Air.internedToRef(ty), | 2994 | .existing => |ty| return Air.internedToRef(ty), |
| 2995 | }; | 2995 | }; |
| 2996 | errdefer wip_ty.cancel(ip); | 2996 | |
| | 2997 | // Once this is `true`, we will not delete the decl or type even upon failure, since we |
| | 2998 | // have finished constructing the type and are in the process of analyzing it. |
| | 2999 | var done = false; |
| | 3000 | |
| | 3001 | errdefer if (!done) wip_ty.cancel(ip); |
| 2997 | | 3002 | |
| 2998 | const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, src, .{ | 3003 | const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, src, .{ |
| 2999 | .ty = Type.type, | 3004 | .ty = Type.type, |
| ... | @@ -3001,7 +3006,7 @@ fn zirEnumDecl( | ... | @@ -3001,7 +3006,7 @@ fn zirEnumDecl( |
| 3001 | }, small.name_strategy, "enum", inst); | 3006 | }, small.name_strategy, "enum", inst); |
| 3002 | const new_decl = mod.declPtr(new_decl_index); | 3007 | const new_decl = mod.declPtr(new_decl_index); |
| 3003 | new_decl.owns_tv = true; | 3008 | new_decl.owns_tv = true; |
| 3004 | errdefer mod.abortAnonDecl(new_decl_index); | 3009 | errdefer if (!done) mod.abortAnonDecl(new_decl_index); |
| 3005 | | 3010 | |
| 3006 | if (sema.mod.comp.debug_incremental) { | 3011 | if (sema.mod.comp.debug_incremental) { |
| 3007 | try mod.intern_pool.addDependency( | 3012 | try mod.intern_pool.addDependency( |
| ... | @@ -3017,12 +3022,17 @@ fn zirEnumDecl( | ... | @@ -3017,12 +3022,17 @@ fn zirEnumDecl( |
| 3017 | .decl_index = new_decl_index, | 3022 | .decl_index = new_decl_index, |
| 3018 | .file_scope = block.getFileScope(mod), | 3023 | .file_scope = block.getFileScope(mod), |
| 3019 | })).toOptional() else .none; | 3024 | })).toOptional() else .none; |
| 3020 | errdefer if (new_namespace_index.unwrap()) |ns| mod.destroyNamespace(ns); | 3025 | errdefer if (!done) if (new_namespace_index.unwrap()) |ns| mod.destroyNamespace(ns); |
| 3021 | | 3026 | |
| 3022 | if (new_namespace_index.unwrap()) |ns| { | 3027 | if (new_namespace_index.unwrap()) |ns| { |
| 3023 | try mod.scanNamespace(ns, decls, new_decl); | 3028 | try mod.scanNamespace(ns, decls, new_decl); |
| 3024 | } | 3029 | } |
| 3025 | | 3030 | |
| | 3031 | // We've finished the initial construction of this type, and are about to perform analysis. |
| | 3032 | // Set the decl and namespace appropriately, and don't destroy anything on failure. |
| | 3033 | wip_ty.prepare(ip, new_decl_index, new_namespace_index); |
| | 3034 | done = true; |
| | 3035 | |
| 3026 | const int_tag_ty = ty: { | 3036 | const int_tag_ty = ty: { |
| 3027 | // We create a block for the field type instructions because they | 3037 | // We create a block for the field type instructions because they |
| 3028 | // may need to reference Decls from inside the enum namespace. | 3038 | // may need to reference Decls from inside the enum namespace. |
| ... | @@ -3075,7 +3085,7 @@ fn zirEnumDecl( | ... | @@ -3075,7 +3085,7 @@ fn zirEnumDecl( |
| 3075 | } | 3085 | } |
| 3076 | }; | 3086 | }; |
| 3077 | | 3087 | |
| 3078 | wip_ty.prepare(ip, new_decl_index, new_namespace_index, int_tag_ty.toIntern()); | 3088 | wip_ty.setTagTy(ip, int_tag_ty.toIntern()); |
| 3079 | | 3089 | |
| 3080 | if (small.nonexhaustive and int_tag_ty.toIntern() != .comptime_int_type) { | 3090 | if (small.nonexhaustive and int_tag_ty.toIntern() != .comptime_int_type) { |
| 3081 | if (fields_len > 1 and std.math.log2_int(u64, fields_len) == int_tag_ty.bitSize(mod)) { | 3091 | if (fields_len > 1 and std.math.log2_int(u64, fields_len) == int_tag_ty.bitSize(mod)) { |
| ... | @@ -3177,7 +3187,7 @@ fn zirEnumDecl( | ... | @@ -3177,7 +3187,7 @@ fn zirEnumDecl( |
| 3177 | } | 3187 | } |
| 3178 | | 3188 | |
| 3179 | try mod.finalizeAnonDecl(new_decl_index); | 3189 | try mod.finalizeAnonDecl(new_decl_index); |
| 3180 | return Air.internedToRef(wip_ty.finish(ip)); | 3190 | return Air.internedToRef(wip_ty.index); |
| 3181 | } | 3191 | } |
| 3182 | | 3192 | |
| 3183 | fn zirUnionDecl( | 3193 | fn zirUnionDecl( |
| ... | @@ -21537,7 +21547,8 @@ fn reifyEnum( | ... | @@ -21537,7 +21547,8 @@ fn reifyEnum( |
| 21537 | mod.declPtr(new_decl_index).owns_tv = true; | 21547 | mod.declPtr(new_decl_index).owns_tv = true; |
| 21538 | errdefer mod.abortAnonDecl(new_decl_index); | 21548 | errdefer mod.abortAnonDecl(new_decl_index); |
| 21539 | | 21549 | |
| 21540 | wip_ty.prepare(ip, new_decl_index, .none, tag_ty.toIntern()); | 21550 | wip_ty.prepare(ip, new_decl_index, .none); |
| | 21551 | wip_ty.setTagTy(ip, tag_ty.toIntern()); |
| 21541 | | 21552 | |
| 21542 | for (0..fields_len) |field_idx| { | 21553 | for (0..fields_len) |field_idx| { |
| 21543 | const field_info = try fields_val.elemValue(mod, field_idx); | 21554 | const field_info = try fields_val.elemValue(mod, field_idx); |
| ... | @@ -21582,7 +21593,7 @@ fn reifyEnum( | ... | @@ -21582,7 +21593,7 @@ fn reifyEnum( |
| 21582 | } | 21593 | } |
| 21583 | | 21594 | |
| 21584 | try mod.finalizeAnonDecl(new_decl_index); | 21595 | try mod.finalizeAnonDecl(new_decl_index); |
| 21585 | return Air.internedToRef(wip_ty.finish(ip)); | 21596 | return Air.internedToRef(wip_ty.index); |
| 21586 | } | 21597 | } |
| 21587 | | 21598 | |
| 21588 | fn reifyUnion( | 21599 | fn reifyUnion( |