| ... | ... | @@ -24,8 +24,6 @@ inst_map: InstMap = .{}, |
| 24 | 24 | /// and `src_decl` of `Scope.Block` is the `Decl` of the callee. |
| 25 | 25 | /// This `Decl` owns the arena memory of this `Sema`. |
| 26 | 26 | owner_decl: *Decl, |
| 27 | | /// How to look up decl names. |
| 28 | | namespace: *Scope.Namespace, |
| 29 | 27 | /// For an inline or comptime function call, this will be the root parent function |
| 30 | 28 | /// which contains the callsite. Corresponds to `owner_decl`. |
| 31 | 29 | owner_func: ?*Module.Fn, |
| ... | ... | @@ -1048,6 +1046,8 @@ pub fn analyzeStructDecl( |
| 1048 | 1046 | } else 0; |
| 1049 | 1047 | |
| 1050 | 1048 | _ = try sema.mod.scanNamespace(&struct_obj.namespace, extra_index, decls_len, new_decl); |
| 1049 | |
| 1050 | new_decl.namespace = &struct_obj.namespace; |
| 1051 | 1051 | } |
| 1052 | 1052 | |
| 1053 | 1053 | fn zirStructDecl( |
| ... | ... | @@ -1084,7 +1084,7 @@ fn zirStructDecl( |
| 1084 | 1084 | .status = .none, |
| 1085 | 1085 | .known_has_bits = undefined, |
| 1086 | 1086 | .namespace = .{ |
| 1087 | | .parent = sema.owner_decl.namespace, |
| 1087 | .parent = block.src_decl.namespace, |
| 1088 | 1088 | .ty = struct_ty, |
| 1089 | 1089 | .file_scope = block.getFileScope(), |
| 1090 | 1090 | }, |
| ... | ... | @@ -1194,7 +1194,7 @@ fn zirEnumDecl( |
| 1194 | 1194 | .values = .{}, |
| 1195 | 1195 | .node_offset = src.node_offset, |
| 1196 | 1196 | .namespace = .{ |
| 1197 | | .parent = sema.owner_decl.namespace, |
| 1197 | .parent = block.src_decl.namespace, |
| 1198 | 1198 | .ty = enum_ty, |
| 1199 | 1199 | .file_scope = block.getFileScope(), |
| 1200 | 1200 | }, |
| ... | ... | @@ -1205,6 +1205,8 @@ fn zirEnumDecl( |
| 1205 | 1205 | |
| 1206 | 1206 | extra_index = try mod.scanNamespace(&enum_obj.namespace, extra_index, decls_len, new_decl); |
| 1207 | 1207 | |
| 1208 | new_decl.namespace = &enum_obj.namespace; |
| 1209 | |
| 1208 | 1210 | const body = sema.code.extra[extra_index..][0..body_len]; |
| 1209 | 1211 | if (fields_len == 0) { |
| 1210 | 1212 | assert(body.len == 0); |
| ... | ... | @@ -1227,10 +1229,6 @@ fn zirEnumDecl( |
| 1227 | 1229 | sema.owner_decl = new_decl; |
| 1228 | 1230 | defer sema.owner_decl = prev_owner_decl; |
| 1229 | 1231 | |
| 1230 | | const prev_namespace = sema.namespace; |
| 1231 | | sema.namespace = &enum_obj.namespace; |
| 1232 | | defer sema.namespace = prev_namespace; |
| 1233 | | |
| 1234 | 1232 | const prev_owner_func = sema.owner_func; |
| 1235 | 1233 | sema.owner_func = null; |
| 1236 | 1234 | defer sema.owner_func = prev_owner_func; |
| ... | ... | @@ -1385,7 +1383,7 @@ fn zirUnionDecl( |
| 1385 | 1383 | .layout = small.layout, |
| 1386 | 1384 | .status = .none, |
| 1387 | 1385 | .namespace = .{ |
| 1388 | | .parent = sema.owner_decl.namespace, |
| 1386 | .parent = block.src_decl.namespace, |
| 1389 | 1387 | .ty = union_ty, |
| 1390 | 1388 | .file_scope = block.getFileScope(), |
| 1391 | 1389 | }, |
| ... | ... | @@ -1396,6 +1394,8 @@ fn zirUnionDecl( |
| 1396 | 1394 | |
| 1397 | 1395 | _ = try sema.mod.scanNamespace(&union_obj.namespace, extra_index, decls_len, new_decl); |
| 1398 | 1396 | |
| 1397 | new_decl.namespace = &union_obj.namespace; |
| 1398 | |
| 1399 | 1399 | try sema.types_pending_resolution.ensureUnusedCapacity(sema.gpa, 1); |
| 1400 | 1400 | try new_decl.finalizeNewArena(&new_decl_arena); |
| 1401 | 1401 | sema.types_pending_resolution.appendAssumeCapacity(union_ty); |
| ... | ... | @@ -2692,7 +2692,7 @@ fn zirDeclVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 2692 | 2692 | } |
| 2693 | 2693 | |
| 2694 | 2694 | fn lookupIdentifier(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, name: []const u8) !*Decl { |
| 2695 | | var namespace = sema.namespace; |
| 2695 | var namespace = block.src_decl.namespace; |
| 2696 | 2696 | while (true) { |
| 2697 | 2697 | if (try sema.lookupInNamespace(block, src, namespace, name, false)) |decl| { |
| 2698 | 2698 | return decl; |
| ... | ... | @@ -3010,10 +3010,6 @@ fn analyzeCall( |
| 3010 | 3010 | sema.inst_map = parent_inst_map; |
| 3011 | 3011 | } |
| 3012 | 3012 | |
| 3013 | | const parent_namespace = sema.namespace; |
| 3014 | | sema.namespace = module_fn.owner_decl.namespace; |
| 3015 | | defer sema.namespace = parent_namespace; |
| 3016 | | |
| 3017 | 3013 | const parent_func = sema.func; |
| 3018 | 3014 | sema.func = module_fn; |
| 3019 | 3015 | defer sema.func = parent_func; |
| ... | ... | @@ -3276,12 +3272,12 @@ fn analyzeCall( |
| 3276 | 3272 | |
| 3277 | 3273 | // Create a Decl for the new function. |
| 3278 | 3274 | const src_decl = namespace.getDecl(); |
| 3279 | | const new_decl = try mod.allocateNewDecl(namespace, module_fn.owner_decl.src_node, src_decl.src_scope); |
| 3280 | 3275 | // TODO better names for generic function instantiations |
| 3281 | 3276 | const name_index = mod.getNextAnonNameIndex(); |
| 3282 | | new_decl.name = try std.fmt.allocPrintZ(gpa, "{s}__anon_{d}", .{ |
| 3277 | const decl_name = try std.fmt.allocPrintZ(gpa, "{s}__anon_{d}", .{ |
| 3283 | 3278 | module_fn.owner_decl.name, name_index, |
| 3284 | 3279 | }); |
| 3280 | const new_decl = try mod.allocateNewDecl(decl_name, namespace, module_fn.owner_decl.src_node, src_decl.src_scope); |
| 3285 | 3281 | new_decl.src_line = module_fn.owner_decl.src_line; |
| 3286 | 3282 | new_decl.is_pub = module_fn.owner_decl.is_pub; |
| 3287 | 3283 | new_decl.is_exported = module_fn.owner_decl.is_exported; |
| ... | ... | @@ -3311,7 +3307,6 @@ fn analyzeCall( |
| 3311 | 3307 | .perm_arena = &new_decl_arena.allocator, |
| 3312 | 3308 | .code = fn_zir, |
| 3313 | 3309 | .owner_decl = new_decl, |
| 3314 | | .namespace = namespace, |
| 3315 | 3310 | .func = null, |
| 3316 | 3311 | .fn_ret_ty = Type.initTag(.void), |
| 3317 | 3312 | .owner_func = null, |
| ... | ... | @@ -11809,7 +11804,7 @@ pub fn resolveDeclFields(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: |
| 11809 | 11804 | switch (ty.tag()) { |
| 11810 | 11805 | .@"struct" => { |
| 11811 | 11806 | const struct_obj = ty.castTag(.@"struct").?.data; |
| 11812 | | if (struct_obj.owner_decl.namespace != sema.owner_decl.namespace) return; |
| 11807 | if (struct_obj.owner_decl.namespace.parent != sema.owner_decl.namespace) return; |
| 11813 | 11808 | switch (struct_obj.status) { |
| 11814 | 11809 | .none => {}, |
| 11815 | 11810 | .field_types_wip => { |
| ... | ... | @@ -11817,10 +11812,6 @@ pub fn resolveDeclFields(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: |
| 11817 | 11812 | }, |
| 11818 | 11813 | .have_field_types, .have_layout, .layout_wip => return, |
| 11819 | 11814 | } |
| 11820 | | const prev_namespace = sema.namespace; |
| 11821 | | sema.namespace = &struct_obj.namespace; |
| 11822 | | defer sema.namespace = prev_namespace; |
| 11823 | | |
| 11824 | 11815 | const old_src = block.src_decl; |
| 11825 | 11816 | defer block.src_decl = old_src; |
| 11826 | 11817 | block.src_decl = struct_obj.owner_decl; |
| ... | ... | @@ -11831,7 +11822,7 @@ pub fn resolveDeclFields(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: |
| 11831 | 11822 | }, |
| 11832 | 11823 | .@"union", .union_tagged => { |
| 11833 | 11824 | const union_obj = ty.cast(Type.Payload.Union).?.data; |
| 11834 | | if (union_obj.owner_decl.namespace != sema.owner_decl.namespace) return; |
| 11825 | if (union_obj.owner_decl.namespace.parent != sema.owner_decl.namespace) return; |
| 11835 | 11826 | switch (union_obj.status) { |
| 11836 | 11827 | .none => {}, |
| 11837 | 11828 | .field_types_wip => { |
| ... | ... | @@ -11839,10 +11830,6 @@ pub fn resolveDeclFields(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: |
| 11839 | 11830 | }, |
| 11840 | 11831 | .have_field_types, .have_layout, .layout_wip => return, |
| 11841 | 11832 | } |
| 11842 | | const prev_namespace = sema.namespace; |
| 11843 | | sema.namespace = &union_obj.namespace; |
| 11844 | | defer sema.namespace = prev_namespace; |
| 11845 | | |
| 11846 | 11833 | const old_src = block.src_decl; |
| 11847 | 11834 | defer block.src_decl = old_src; |
| 11848 | 11835 | block.src_decl = union_obj.owner_decl; |