| ... | ... | @@ -6267,7 +6267,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 6267 | 6267 | const decl_name = try mod.intern_pool.getOrPutString(mod.gpa, sema.code.nullTerminatedString(extra.decl_name)); |
| 6268 | 6268 | const decl_index = if (extra.namespace != .none) index_blk: { |
| 6269 | 6269 | const container_ty = try sema.resolveType(block, operand_src, extra.namespace); |
| 6270 | | const container_namespace = container_ty.getNamespaceIndex(mod).unwrap().?; |
| 6270 | const container_namespace = container_ty.getNamespaceIndex(mod); |
| 6271 | 6271 | |
| 6272 | 6272 | const maybe_index = try sema.lookupInNamespace(block, operand_src, container_namespace, decl_name, false); |
| 6273 | 6273 | break :index_blk maybe_index orelse |
| ... | ... | @@ -6632,7 +6632,7 @@ fn lookupIdentifier(sema: *Sema, block: *Block, src: LazySrcLoc, name: InternPoo |
| 6632 | 6632 | const mod = sema.mod; |
| 6633 | 6633 | var namespace = block.namespace; |
| 6634 | 6634 | while (true) { |
| 6635 | | if (try sema.lookupInNamespace(block, src, namespace, name, false)) |decl_index| { |
| 6635 | if (try sema.lookupInNamespace(block, src, namespace.toOptional(), name, false)) |decl_index| { |
| 6636 | 6636 | return decl_index; |
| 6637 | 6637 | } |
| 6638 | 6638 | namespace = mod.namespacePtr(namespace).parent.unwrap() orelse break; |
| ... | ... | @@ -6646,12 +6646,13 @@ fn lookupInNamespace( |
| 6646 | 6646 | sema: *Sema, |
| 6647 | 6647 | block: *Block, |
| 6648 | 6648 | src: LazySrcLoc, |
| 6649 | | namespace_index: InternPool.NamespaceIndex, |
| 6649 | opt_namespace_index: InternPool.OptionalNamespaceIndex, |
| 6650 | 6650 | ident_name: InternPool.NullTerminatedString, |
| 6651 | 6651 | observe_usingnamespace: bool, |
| 6652 | 6652 | ) CompileError!?InternPool.DeclIndex { |
| 6653 | 6653 | const mod = sema.mod; |
| 6654 | 6654 | |
| 6655 | const namespace_index = opt_namespace_index.unwrap() orelse return null; |
| 6655 | 6656 | const namespace = mod.namespacePtr(namespace_index); |
| 6656 | 6657 | const namespace_decl = mod.declPtr(namespace.decl_index); |
| 6657 | 6658 | if (namespace_decl.analysis == .file_failure) { |
| ... | ... | @@ -6696,7 +6697,7 @@ fn lookupInNamespace( |
| 6696 | 6697 | } |
| 6697 | 6698 | try sema.ensureDeclAnalyzed(sub_usingnamespace_decl_index); |
| 6698 | 6699 | const ns_ty = sub_usingnamespace_decl.val.toType(); |
| 6699 | | const sub_ns = ns_ty.getNamespace(mod).?; |
| 6700 | const sub_ns = mod.namespacePtrUnwrap(ns_ty.getNamespaceIndex(mod)) orelse continue; |
| 6700 | 6701 | try checked_namespaces.put(gpa, sub_ns, src_file == sub_usingnamespace_decl.getFileScope(mod)); |
| 6701 | 6702 | } |
| 6702 | 6703 | } |
| ... | ... | @@ -9917,7 +9918,7 @@ fn zirParam( |
| 9917 | 9918 | .is_comptime = comptime_syntax, |
| 9918 | 9919 | .name = param_name, |
| 9919 | 9920 | }); |
| 9920 | | sema.inst_map.putAssumeCapacityNoClobber(inst, .generic_poison); |
| 9921 | sema.inst_map.putAssumeCapacity(inst, .generic_poison); |
| 9921 | 9922 | return; |
| 9922 | 9923 | }, |
| 9923 | 9924 | else => |e| return e, |
| ... | ... | @@ -9934,7 +9935,7 @@ fn zirParam( |
| 9934 | 9935 | .is_comptime = comptime_syntax, |
| 9935 | 9936 | .name = param_name, |
| 9936 | 9937 | }); |
| 9937 | | sema.inst_map.putAssumeCapacityNoClobber(inst, .generic_poison); |
| 9938 | sema.inst_map.putAssumeCapacity(inst, .generic_poison); |
| 9938 | 9939 | return; |
| 9939 | 9940 | }, |
| 9940 | 9941 | else => |e| return e, |
| ... | ... | @@ -9949,7 +9950,7 @@ fn zirParam( |
| 9949 | 9950 | if (is_comptime) { |
| 9950 | 9951 | // If this is a comptime parameter we can add a constant generic_poison |
| 9951 | 9952 | // since this is also a generic parameter. |
| 9952 | | sema.inst_map.putAssumeCapacityNoClobber(inst, .generic_poison); |
| 9953 | sema.inst_map.putAssumeCapacity(inst, .generic_poison); |
| 9953 | 9954 | } else { |
| 9954 | 9955 | // Otherwise we need a dummy runtime instruction. |
| 9955 | 9956 | const result_index: Air.Inst.Index = @enumFromInt(sema.air_instructions.len); |
| ... | ... | @@ -9957,7 +9958,7 @@ fn zirParam( |
| 9957 | 9958 | .tag = .alloc, |
| 9958 | 9959 | .data = .{ .ty = param_ty }, |
| 9959 | 9960 | }); |
| 9960 | | sema.inst_map.putAssumeCapacityNoClobber(inst, result_index.toRef()); |
| 9961 | sema.inst_map.putAssumeCapacity(inst, result_index.toRef()); |
| 9961 | 9962 | } |
| 9962 | 9963 | } |
| 9963 | 9964 | |
| ... | ... | @@ -13699,8 +13700,7 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 13699 | 13700 | } }); |
| 13700 | 13701 | } |
| 13701 | 13702 | |
| 13702 | | const namespace = container_type.getNamespaceIndex(mod).unwrap() orelse |
| 13703 | | return .bool_false; |
| 13703 | const namespace = container_type.getNamespaceIndex(mod); |
| 13704 | 13704 | if (try sema.lookupInNamespace(block, src, namespace, decl_name, true)) |decl_index| { |
| 13705 | 13705 | const decl = mod.declPtr(decl_index); |
| 13706 | 13706 | if (decl.is_pub or decl.getFileScope(mod) == block.getFileScope(mod)) { |
| ... | ... | @@ -17534,7 +17534,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17534 | 17534 | const fn_info_decl_index = (try sema.namespaceLookup( |
| 17535 | 17535 | block, |
| 17536 | 17536 | src, |
| 17537 | | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 17537 | type_info_ty.getNamespaceIndex(mod), |
| 17538 | 17538 | try ip.getOrPutString(gpa, "Fn"), |
| 17539 | 17539 | )).?; |
| 17540 | 17540 | try sema.ensureDeclAnalyzed(fn_info_decl_index); |
| ... | ... | @@ -17544,7 +17544,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17544 | 17544 | const param_info_decl_index = (try sema.namespaceLookup( |
| 17545 | 17545 | block, |
| 17546 | 17546 | src, |
| 17547 | | fn_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 17547 | fn_info_ty.getNamespaceIndex(mod), |
| 17548 | 17548 | try ip.getOrPutString(gpa, "Param"), |
| 17549 | 17549 | )).?; |
| 17550 | 17550 | try sema.ensureDeclAnalyzed(param_info_decl_index); |
| ... | ... | @@ -17644,7 +17644,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17644 | 17644 | const int_info_decl_index = (try sema.namespaceLookup( |
| 17645 | 17645 | block, |
| 17646 | 17646 | src, |
| 17647 | | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 17647 | type_info_ty.getNamespaceIndex(mod), |
| 17648 | 17648 | try ip.getOrPutString(gpa, "Int"), |
| 17649 | 17649 | )).?; |
| 17650 | 17650 | try sema.ensureDeclAnalyzed(int_info_decl_index); |
| ... | ... | @@ -17672,7 +17672,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17672 | 17672 | const float_info_decl_index = (try sema.namespaceLookup( |
| 17673 | 17673 | block, |
| 17674 | 17674 | src, |
| 17675 | | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 17675 | type_info_ty.getNamespaceIndex(mod), |
| 17676 | 17676 | try ip.getOrPutString(gpa, "Float"), |
| 17677 | 17677 | )).?; |
| 17678 | 17678 | try sema.ensureDeclAnalyzed(float_info_decl_index); |
| ... | ... | @@ -17704,7 +17704,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17704 | 17704 | const decl_index = (try sema.namespaceLookup( |
| 17705 | 17705 | block, |
| 17706 | 17706 | src, |
| 17707 | | (try sema.getBuiltinType("Type")).getNamespaceIndex(mod).unwrap().?, |
| 17707 | (try sema.getBuiltinType("Type")).getNamespaceIndex(mod), |
| 17708 | 17708 | try ip.getOrPutString(gpa, "Pointer"), |
| 17709 | 17709 | )).?; |
| 17710 | 17710 | try sema.ensureDeclAnalyzed(decl_index); |
| ... | ... | @@ -17715,7 +17715,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17715 | 17715 | const decl_index = (try sema.namespaceLookup( |
| 17716 | 17716 | block, |
| 17717 | 17717 | src, |
| 17718 | | pointer_ty.getNamespaceIndex(mod).unwrap().?, |
| 17718 | pointer_ty.getNamespaceIndex(mod), |
| 17719 | 17719 | try ip.getOrPutString(gpa, "Size"), |
| 17720 | 17720 | )).?; |
| 17721 | 17721 | try sema.ensureDeclAnalyzed(decl_index); |
| ... | ... | @@ -17758,7 +17758,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17758 | 17758 | const array_field_ty_decl_index = (try sema.namespaceLookup( |
| 17759 | 17759 | block, |
| 17760 | 17760 | src, |
| 17761 | | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 17761 | type_info_ty.getNamespaceIndex(mod), |
| 17762 | 17762 | try ip.getOrPutString(gpa, "Array"), |
| 17763 | 17763 | )).?; |
| 17764 | 17764 | try sema.ensureDeclAnalyzed(array_field_ty_decl_index); |
| ... | ... | @@ -17789,7 +17789,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17789 | 17789 | const vector_field_ty_decl_index = (try sema.namespaceLookup( |
| 17790 | 17790 | block, |
| 17791 | 17791 | src, |
| 17792 | | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 17792 | type_info_ty.getNamespaceIndex(mod), |
| 17793 | 17793 | try ip.getOrPutString(gpa, "Vector"), |
| 17794 | 17794 | )).?; |
| 17795 | 17795 | try sema.ensureDeclAnalyzed(vector_field_ty_decl_index); |
| ... | ... | @@ -17818,7 +17818,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17818 | 17818 | const optional_field_ty_decl_index = (try sema.namespaceLookup( |
| 17819 | 17819 | block, |
| 17820 | 17820 | src, |
| 17821 | | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 17821 | type_info_ty.getNamespaceIndex(mod), |
| 17822 | 17822 | try ip.getOrPutString(gpa, "Optional"), |
| 17823 | 17823 | )).?; |
| 17824 | 17824 | try sema.ensureDeclAnalyzed(optional_field_ty_decl_index); |
| ... | ... | @@ -17845,7 +17845,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17845 | 17845 | const set_field_ty_decl_index = (try sema.namespaceLookup( |
| 17846 | 17846 | block, |
| 17847 | 17847 | src, |
| 17848 | | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 17848 | type_info_ty.getNamespaceIndex(mod), |
| 17849 | 17849 | try ip.getOrPutString(gpa, "Error"), |
| 17850 | 17850 | )).?; |
| 17851 | 17851 | try sema.ensureDeclAnalyzed(set_field_ty_decl_index); |
| ... | ... | @@ -17950,7 +17950,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17950 | 17950 | const error_union_field_ty_decl_index = (try sema.namespaceLookup( |
| 17951 | 17951 | block, |
| 17952 | 17952 | src, |
| 17953 | | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 17953 | type_info_ty.getNamespaceIndex(mod), |
| 17954 | 17954 | try ip.getOrPutString(gpa, "ErrorUnion"), |
| 17955 | 17955 | )).?; |
| 17956 | 17956 | try sema.ensureDeclAnalyzed(error_union_field_ty_decl_index); |
| ... | ... | @@ -17980,7 +17980,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17980 | 17980 | const enum_field_ty_decl_index = (try sema.namespaceLookup( |
| 17981 | 17981 | block, |
| 17982 | 17982 | src, |
| 17983 | | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 17983 | type_info_ty.getNamespaceIndex(mod), |
| 17984 | 17984 | try ip.getOrPutString(gpa, "EnumField"), |
| 17985 | 17985 | )).?; |
| 17986 | 17986 | try sema.ensureDeclAnalyzed(enum_field_ty_decl_index); |
| ... | ... | @@ -18071,7 +18071,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18071 | 18071 | const type_enum_ty_decl_index = (try sema.namespaceLookup( |
| 18072 | 18072 | block, |
| 18073 | 18073 | src, |
| 18074 | | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 18074 | type_info_ty.getNamespaceIndex(mod), |
| 18075 | 18075 | try ip.getOrPutString(gpa, "Enum"), |
| 18076 | 18076 | )).?; |
| 18077 | 18077 | try sema.ensureDeclAnalyzed(type_enum_ty_decl_index); |
| ... | ... | @@ -18103,7 +18103,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18103 | 18103 | const type_union_ty_decl_index = (try sema.namespaceLookup( |
| 18104 | 18104 | block, |
| 18105 | 18105 | src, |
| 18106 | | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 18106 | type_info_ty.getNamespaceIndex(mod), |
| 18107 | 18107 | try ip.getOrPutString(gpa, "Union"), |
| 18108 | 18108 | )).?; |
| 18109 | 18109 | try sema.ensureDeclAnalyzed(type_union_ty_decl_index); |
| ... | ... | @@ -18115,7 +18115,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18115 | 18115 | const union_field_ty_decl_index = (try sema.namespaceLookup( |
| 18116 | 18116 | block, |
| 18117 | 18117 | src, |
| 18118 | | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 18118 | type_info_ty.getNamespaceIndex(mod), |
| 18119 | 18119 | try ip.getOrPutString(gpa, "UnionField"), |
| 18120 | 18120 | )).?; |
| 18121 | 18121 | try sema.ensureDeclAnalyzed(union_field_ty_decl_index); |
| ... | ... | @@ -18217,7 +18217,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18217 | 18217 | const decl_index = (try sema.namespaceLookup( |
| 18218 | 18218 | block, |
| 18219 | 18219 | src, |
| 18220 | | (try sema.getBuiltinType("Type")).getNamespaceIndex(mod).unwrap().?, |
| 18220 | (try sema.getBuiltinType("Type")).getNamespaceIndex(mod), |
| 18221 | 18221 | try ip.getOrPutString(gpa, "ContainerLayout"), |
| 18222 | 18222 | )).?; |
| 18223 | 18223 | try sema.ensureDeclAnalyzed(decl_index); |
| ... | ... | @@ -18250,7 +18250,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18250 | 18250 | const type_struct_ty_decl_index = (try sema.namespaceLookup( |
| 18251 | 18251 | block, |
| 18252 | 18252 | src, |
| 18253 | | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 18253 | type_info_ty.getNamespaceIndex(mod), |
| 18254 | 18254 | try ip.getOrPutString(gpa, "Struct"), |
| 18255 | 18255 | )).?; |
| 18256 | 18256 | try sema.ensureDeclAnalyzed(type_struct_ty_decl_index); |
| ... | ... | @@ -18262,7 +18262,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18262 | 18262 | const struct_field_ty_decl_index = (try sema.namespaceLookup( |
| 18263 | 18263 | block, |
| 18264 | 18264 | src, |
| 18265 | | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 18265 | type_info_ty.getNamespaceIndex(mod), |
| 18266 | 18266 | try ip.getOrPutString(gpa, "StructField"), |
| 18267 | 18267 | )).?; |
| 18268 | 18268 | try sema.ensureDeclAnalyzed(struct_field_ty_decl_index); |
| ... | ... | @@ -18447,7 +18447,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18447 | 18447 | const decl_index = (try sema.namespaceLookup( |
| 18448 | 18448 | block, |
| 18449 | 18449 | src, |
| 18450 | | (try sema.getBuiltinType("Type")).getNamespaceIndex(mod).unwrap().?, |
| 18450 | (try sema.getBuiltinType("Type")).getNamespaceIndex(mod), |
| 18451 | 18451 | try ip.getOrPutString(gpa, "ContainerLayout"), |
| 18452 | 18452 | )).?; |
| 18453 | 18453 | try sema.ensureDeclAnalyzed(decl_index); |
| ... | ... | @@ -18483,7 +18483,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18483 | 18483 | const type_opaque_ty_decl_index = (try sema.namespaceLookup( |
| 18484 | 18484 | block, |
| 18485 | 18485 | src, |
| 18486 | | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 18486 | type_info_ty.getNamespaceIndex(mod), |
| 18487 | 18487 | try ip.getOrPutString(gpa, "Opaque"), |
| 18488 | 18488 | )).?; |
| 18489 | 18489 | try sema.ensureDeclAnalyzed(type_opaque_ty_decl_index); |
| ... | ... | @@ -18526,7 +18526,7 @@ fn typeInfoDecls( |
| 18526 | 18526 | const declaration_ty_decl_index = (try sema.namespaceLookup( |
| 18527 | 18527 | block, |
| 18528 | 18528 | src, |
| 18529 | | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 18529 | type_info_ty.getNamespaceIndex(mod), |
| 18530 | 18530 | try mod.intern_pool.getOrPutString(gpa, "Declaration"), |
| 18531 | 18531 | )).?; |
| 18532 | 18532 | try sema.ensureDeclAnalyzed(declaration_ty_decl_index); |
| ... | ... | @@ -18541,10 +18541,7 @@ fn typeInfoDecls( |
| 18541 | 18541 | var seen_namespaces = std.AutoHashMap(*Namespace, void).init(gpa); |
| 18542 | 18542 | defer seen_namespaces.deinit(); |
| 18543 | 18543 | |
| 18544 | | if (opt_namespace.unwrap()) |namespace_index| { |
| 18545 | | const namespace = mod.namespacePtr(namespace_index); |
| 18546 | | try sema.typeInfoNamespaceDecls(block, namespace, declaration_ty, &decl_vals, &seen_namespaces); |
| 18547 | | } |
| 18544 | try sema.typeInfoNamespaceDecls(block, opt_namespace, declaration_ty, &decl_vals, &seen_namespaces); |
| 18548 | 18545 | |
| 18549 | 18546 | const array_decl_ty = try mod.arrayType(.{ |
| 18550 | 18547 | .len = decl_vals.items.len, |
| ... | ... | @@ -18577,23 +18574,27 @@ fn typeInfoDecls( |
| 18577 | 18574 | fn typeInfoNamespaceDecls( |
| 18578 | 18575 | sema: *Sema, |
| 18579 | 18576 | block: *Block, |
| 18580 | | namespace: *Namespace, |
| 18577 | opt_namespace_index: InternPool.OptionalNamespaceIndex, |
| 18581 | 18578 | declaration_ty: Type, |
| 18582 | 18579 | decl_vals: *std.ArrayList(InternPool.Index), |
| 18583 | 18580 | seen_namespaces: *std.AutoHashMap(*Namespace, void), |
| 18584 | 18581 | ) !void { |
| 18585 | 18582 | const mod = sema.mod; |
| 18586 | 18583 | const ip = &mod.intern_pool; |
| 18584 | |
| 18585 | const namespace_index = opt_namespace_index.unwrap() orelse return; |
| 18586 | const namespace = mod.namespacePtr(namespace_index); |
| 18587 | |
| 18587 | 18588 | const gop = try seen_namespaces.getOrPut(namespace); |
| 18588 | 18589 | if (gop.found_existing) return; |
| 18590 | |
| 18589 | 18591 | const decls = namespace.decls.keys(); |
| 18590 | 18592 | for (decls) |decl_index| { |
| 18591 | 18593 | const decl = mod.declPtr(decl_index); |
| 18592 | 18594 | if (decl.kind == .@"usingnamespace") { |
| 18593 | 18595 | if (decl.analysis == .in_progress) continue; |
| 18594 | 18596 | try mod.ensureDeclAnalyzed(decl_index); |
| 18595 | | const new_ns = decl.val.toType().getNamespace(mod).?; |
| 18596 | | try sema.typeInfoNamespaceDecls(block, new_ns, declaration_ty, decl_vals, seen_namespaces); |
| 18597 | try sema.typeInfoNamespaceDecls(block, decl.val.toType().getNamespaceIndex(mod), declaration_ty, decl_vals, seen_namespaces); |
| 18597 | 18598 | continue; |
| 18598 | 18599 | } |
| 18599 | 18600 | if (decl.kind != .named or !decl.is_pub) continue; |
| ... | ... | @@ -19744,7 +19745,8 @@ fn zirStructInitEmpty(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 19744 | 19745 | |
| 19745 | 19746 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 19746 | 19747 | const src = inst_data.src(); |
| 19747 | | const obj_ty = try sema.resolveType(block, src, inst_data.operand); |
| 19748 | const ty_src: LazySrcLoc = .{ .node_offset_init_ty = inst_data.src_node }; |
| 19749 | const obj_ty = try sema.resolveType(block, ty_src, inst_data.operand); |
| 19748 | 19750 | const mod = sema.mod; |
| 19749 | 19751 | |
| 19750 | 19752 | switch (obj_ty.zigTypeTag(mod)) { |
| ... | ... | @@ -26558,7 +26560,7 @@ fn preparePanicId(sema: *Sema, block: *Block, panic_id: Module.PanicId) !InternP |
| 26558 | 26560 | const msg_decl_index = (sema.namespaceLookup( |
| 26559 | 26561 | block, |
| 26560 | 26562 | .unneeded, |
| 26561 | | panic_messages_ty.getNamespaceIndex(mod).unwrap().?, |
| 26563 | panic_messages_ty.getNamespaceIndex(mod), |
| 26562 | 26564 | try mod.intern_pool.getOrPutString(gpa, @tagName(panic_id)), |
| 26563 | 26565 | ) catch |err| switch (err) { |
| 26564 | 26566 | error.AnalysisFail, error.NeededSourceLocation => @panic("std.builtin.panic_messages is corrupt"), |
| ... | ... | @@ -26977,10 +26979,8 @@ fn fieldVal( |
| 26977 | 26979 | } }))); |
| 26978 | 26980 | }, |
| 26979 | 26981 | .Union => { |
| 26980 | | if (child_type.getNamespaceIndex(mod).unwrap()) |namespace| { |
| 26981 | | if (try sema.namespaceLookupVal(block, src, namespace, field_name)) |inst| { |
| 26982 | | return inst; |
| 26983 | | } |
| 26982 | if (try sema.namespaceLookupVal(block, src, child_type.getNamespaceIndex(mod), field_name)) |inst| { |
| 26983 | return inst; |
| 26984 | 26984 | } |
| 26985 | 26985 | try sema.resolveTypeFields(child_type); |
| 26986 | 26986 | if (child_type.unionTagType(mod)) |enum_ty| { |
| ... | ... | @@ -26992,10 +26992,8 @@ fn fieldVal( |
| 26992 | 26992 | return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name); |
| 26993 | 26993 | }, |
| 26994 | 26994 | .Enum => { |
| 26995 | | if (child_type.getNamespaceIndex(mod).unwrap()) |namespace| { |
| 26996 | | if (try sema.namespaceLookupVal(block, src, namespace, field_name)) |inst| { |
| 26997 | | return inst; |
| 26998 | | } |
| 26995 | if (try sema.namespaceLookupVal(block, src, child_type.getNamespaceIndex(mod), field_name)) |inst| { |
| 26996 | return inst; |
| 26999 | 26997 | } |
| 27000 | 26998 | const field_index_usize = child_type.enumFieldIndex(field_name, mod) orelse |
| 27001 | 26999 | return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name); |
| ... | ... | @@ -27004,10 +27002,8 @@ fn fieldVal( |
| 27004 | 27002 | return Air.internedToRef(enum_val.toIntern()); |
| 27005 | 27003 | }, |
| 27006 | 27004 | .Struct, .Opaque => { |
| 27007 | | if (child_type.getNamespaceIndex(mod).unwrap()) |namespace| { |
| 27008 | | if (try sema.namespaceLookupVal(block, src, namespace, field_name)) |inst| { |
| 27009 | | return inst; |
| 27010 | | } |
| 27005 | if (try sema.namespaceLookupVal(block, src, child_type.getNamespaceIndex(mod), field_name)) |inst| { |
| 27006 | return inst; |
| 27011 | 27007 | } |
| 27012 | 27008 | return sema.failWithBadMemberAccess(block, child_type, src, field_name); |
| 27013 | 27009 | }, |
| ... | ... | @@ -27203,10 +27199,8 @@ fn fieldPtr( |
| 27203 | 27199 | } })); |
| 27204 | 27200 | }, |
| 27205 | 27201 | .Union => { |
| 27206 | | if (child_type.getNamespaceIndex(mod).unwrap()) |namespace| { |
| 27207 | | if (try sema.namespaceLookupRef(block, src, namespace, field_name)) |inst| { |
| 27208 | | return inst; |
| 27209 | | } |
| 27202 | if (try sema.namespaceLookupRef(block, src, child_type.getNamespaceIndex(mod), field_name)) |inst| { |
| 27203 | return inst; |
| 27210 | 27204 | } |
| 27211 | 27205 | try sema.resolveTypeFields(child_type); |
| 27212 | 27206 | if (child_type.unionTagType(mod)) |enum_ty| { |
| ... | ... | @@ -27219,10 +27213,8 @@ fn fieldPtr( |
| 27219 | 27213 | return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name); |
| 27220 | 27214 | }, |
| 27221 | 27215 | .Enum => { |
| 27222 | | if (child_type.getNamespaceIndex(mod).unwrap()) |namespace| { |
| 27223 | | if (try sema.namespaceLookupRef(block, src, namespace, field_name)) |inst| { |
| 27224 | | return inst; |
| 27225 | | } |
| 27216 | if (try sema.namespaceLookupRef(block, src, child_type.getNamespaceIndex(mod), field_name)) |inst| { |
| 27217 | return inst; |
| 27226 | 27218 | } |
| 27227 | 27219 | const field_index = child_type.enumFieldIndex(field_name, mod) orelse { |
| 27228 | 27220 | return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name); |
| ... | ... | @@ -27232,10 +27224,8 @@ fn fieldPtr( |
| 27232 | 27224 | return anonDeclRef(sema, idx_val.toIntern()); |
| 27233 | 27225 | }, |
| 27234 | 27226 | .Struct, .Opaque => { |
| 27235 | | if (child_type.getNamespaceIndex(mod).unwrap()) |namespace| { |
| 27236 | | if (try sema.namespaceLookupRef(block, src, namespace, field_name)) |inst| { |
| 27237 | | return inst; |
| 27238 | | } |
| 27227 | if (try sema.namespaceLookupRef(block, src, child_type.getNamespaceIndex(mod), field_name)) |inst| { |
| 27228 | return inst; |
| 27239 | 27229 | } |
| 27240 | 27230 | return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name); |
| 27241 | 27231 | }, |
| ... | ... | @@ -27348,73 +27338,68 @@ fn fieldCallBind( |
| 27348 | 27338 | } |
| 27349 | 27339 | |
| 27350 | 27340 | // If we get here, we need to look for a decl in the struct type instead. |
| 27351 | | const found_decl = switch (concrete_ty.zigTypeTag(mod)) { |
| 27352 | | .Struct, .Opaque, .Union, .Enum => found_decl: { |
| 27353 | | if (concrete_ty.getNamespaceIndex(mod).unwrap()) |namespace| { |
| 27354 | | if (try sema.namespaceLookup(block, src, namespace, field_name)) |decl_idx| { |
| 27355 | | try sema.addReferencedBy(block, src, decl_idx); |
| 27356 | | const decl_val = try sema.analyzeDeclVal(block, src, decl_idx); |
| 27357 | | const decl_type = sema.typeOf(decl_val); |
| 27358 | | if (mod.typeToFunc(decl_type)) |func_type| f: { |
| 27359 | | if (func_type.param_types.len == 0) break :f; |
| 27360 | | |
| 27361 | | const first_param_type = Type.fromInterned(func_type.param_types.get(ip)[0]); |
| 27362 | | // zig fmt: off |
| 27363 | | if (first_param_type.isGenericPoison() or ( |
| 27364 | | first_param_type.zigTypeTag(mod) == .Pointer and |
| 27365 | | (first_param_type.ptrSize(mod) == .One or |
| 27366 | | first_param_type.ptrSize(mod) == .C) and |
| 27367 | | first_param_type.childType(mod).eql(concrete_ty, mod))) |
| 27368 | | { |
| 27369 | | // zig fmt: on |
| 27370 | | // Note that if the param type is generic poison, we know that it must |
| 27371 | | // specifically be `anytype` since it's the first parameter, meaning we |
| 27372 | | // can safely assume it can be a pointer. |
| 27373 | | // TODO: bound fn calls on rvalues should probably |
| 27374 | | // generate a by-value argument somehow. |
| 27375 | | return .{ .method = .{ |
| 27376 | | .func_inst = decl_val, |
| 27377 | | .arg0_inst = object_ptr, |
| 27378 | | } }; |
| 27379 | | } else if (first_param_type.eql(concrete_ty, mod)) { |
| 27380 | | const deref = try sema.analyzeLoad(block, src, object_ptr, src); |
| 27381 | | return .{ .method = .{ |
| 27382 | | .func_inst = decl_val, |
| 27383 | | .arg0_inst = deref, |
| 27384 | | } }; |
| 27385 | | } else if (first_param_type.zigTypeTag(mod) == .Optional) { |
| 27386 | | const child = first_param_type.optionalChild(mod); |
| 27387 | | if (child.eql(concrete_ty, mod)) { |
| 27388 | | const deref = try sema.analyzeLoad(block, src, object_ptr, src); |
| 27389 | | return .{ .method = .{ |
| 27390 | | .func_inst = decl_val, |
| 27391 | | .arg0_inst = deref, |
| 27392 | | } }; |
| 27393 | | } else if (child.zigTypeTag(mod) == .Pointer and |
| 27394 | | child.ptrSize(mod) == .One and |
| 27395 | | child.childType(mod).eql(concrete_ty, mod)) |
| 27396 | | { |
| 27397 | | return .{ .method = .{ |
| 27398 | | .func_inst = decl_val, |
| 27399 | | .arg0_inst = object_ptr, |
| 27400 | | } }; |
| 27401 | | } |
| 27402 | | } else if (first_param_type.zigTypeTag(mod) == .ErrorUnion and |
| 27403 | | first_param_type.errorUnionPayload(mod).eql(concrete_ty, mod)) |
| 27404 | | { |
| 27405 | | const deref = try sema.analyzeLoad(block, src, object_ptr, src); |
| 27406 | | return .{ .method = .{ |
| 27407 | | .func_inst = decl_val, |
| 27408 | | .arg0_inst = deref, |
| 27409 | | } }; |
| 27410 | | } |
| 27411 | | } |
| 27412 | | break :found_decl decl_idx; |
| 27341 | const found_decl = found_decl: { |
| 27342 | const namespace = concrete_ty.getNamespace(mod) orelse |
| 27343 | break :found_decl null; |
| 27344 | const decl_idx = (try sema.namespaceLookup(block, src, namespace, field_name)) orelse |
| 27345 | break :found_decl null; |
| 27346 | |
| 27347 | try sema.addReferencedBy(block, src, decl_idx); |
| 27348 | const decl_val = try sema.analyzeDeclVal(block, src, decl_idx); |
| 27349 | const decl_type = sema.typeOf(decl_val); |
| 27350 | if (mod.typeToFunc(decl_type)) |func_type| f: { |
| 27351 | if (func_type.param_types.len == 0) break :f; |
| 27352 | |
| 27353 | const first_param_type = Type.fromInterned(func_type.param_types.get(ip)[0]); |
| 27354 | if (first_param_type.isGenericPoison() or |
| 27355 | (first_param_type.zigTypeTag(mod) == .Pointer and |
| 27356 | (first_param_type.ptrSize(mod) == .One or |
| 27357 | first_param_type.ptrSize(mod) == .C) and |
| 27358 | first_param_type.childType(mod).eql(concrete_ty, mod))) |
| 27359 | { |
| 27360 | // Note that if the param type is generic poison, we know that it must |
| 27361 | // specifically be `anytype` since it's the first parameter, meaning we |
| 27362 | // can safely assume it can be a pointer. |
| 27363 | // TODO: bound fn calls on rvalues should probably |
| 27364 | // generate a by-value argument somehow. |
| 27365 | return .{ .method = .{ |
| 27366 | .func_inst = decl_val, |
| 27367 | .arg0_inst = object_ptr, |
| 27368 | } }; |
| 27369 | } else if (first_param_type.eql(concrete_ty, mod)) { |
| 27370 | const deref = try sema.analyzeLoad(block, src, object_ptr, src); |
| 27371 | return .{ .method = .{ |
| 27372 | .func_inst = decl_val, |
| 27373 | .arg0_inst = deref, |
| 27374 | } }; |
| 27375 | } else if (first_param_type.zigTypeTag(mod) == .Optional) { |
| 27376 | const child = first_param_type.optionalChild(mod); |
| 27377 | if (child.eql(concrete_ty, mod)) { |
| 27378 | const deref = try sema.analyzeLoad(block, src, object_ptr, src); |
| 27379 | return .{ .method = .{ |
| 27380 | .func_inst = decl_val, |
| 27381 | .arg0_inst = deref, |
| 27382 | } }; |
| 27383 | } else if (child.zigTypeTag(mod) == .Pointer and |
| 27384 | child.ptrSize(mod) == .One and |
| 27385 | child.childType(mod).eql(concrete_ty, mod)) |
| 27386 | { |
| 27387 | return .{ .method = .{ |
| 27388 | .func_inst = decl_val, |
| 27389 | .arg0_inst = object_ptr, |
| 27390 | } }; |
| 27413 | 27391 | } |
| 27392 | } else if (first_param_type.zigTypeTag(mod) == .ErrorUnion and |
| 27393 | first_param_type.errorUnionPayload(mod).eql(concrete_ty, mod)) |
| 27394 | { |
| 27395 | const deref = try sema.analyzeLoad(block, src, object_ptr, src); |
| 27396 | return .{ .method = .{ |
| 27397 | .func_inst = decl_val, |
| 27398 | .arg0_inst = deref, |
| 27399 | } }; |
| 27414 | 27400 | } |
| 27415 | | break :found_decl null; |
| 27416 | | }, |
| 27417 | | else => null, |
| 27401 | } |
| 27402 | break :found_decl decl_idx; |
| 27418 | 27403 | }; |
| 27419 | 27404 | |
| 27420 | 27405 | const msg = msg: { |
| ... | ... | @@ -27480,12 +27465,12 @@ fn namespaceLookup( |
| 27480 | 27465 | sema: *Sema, |
| 27481 | 27466 | block: *Block, |
| 27482 | 27467 | src: LazySrcLoc, |
| 27483 | | namespace: InternPool.NamespaceIndex, |
| 27468 | opt_namespace: InternPool.OptionalNamespaceIndex, |
| 27484 | 27469 | decl_name: InternPool.NullTerminatedString, |
| 27485 | 27470 | ) CompileError!?InternPool.DeclIndex { |
| 27486 | 27471 | const mod = sema.mod; |
| 27487 | 27472 | const gpa = sema.gpa; |
| 27488 | | if (try sema.lookupInNamespace(block, src, namespace, decl_name, true)) |decl_index| { |
| 27473 | if (try sema.lookupInNamespace(block, src, opt_namespace, decl_name, true)) |decl_index| { |
| 27489 | 27474 | const decl = mod.declPtr(decl_index); |
| 27490 | 27475 | if (!decl.is_pub and decl.getFileScope(mod) != block.getFileScope(mod)) { |
| 27491 | 27476 | const msg = msg: { |
| ... | ... | @@ -27507,10 +27492,10 @@ fn namespaceLookupRef( |
| 27507 | 27492 | sema: *Sema, |
| 27508 | 27493 | block: *Block, |
| 27509 | 27494 | src: LazySrcLoc, |
| 27510 | | namespace: InternPool.NamespaceIndex, |
| 27495 | opt_namespace: InternPool.OptionalNamespaceIndex, |
| 27511 | 27496 | decl_name: InternPool.NullTerminatedString, |
| 27512 | 27497 | ) CompileError!?Air.Inst.Ref { |
| 27513 | | const decl = (try sema.namespaceLookup(block, src, namespace, decl_name)) orelse return null; |
| 27498 | const decl = (try sema.namespaceLookup(block, src, opt_namespace, decl_name)) orelse return null; |
| 27514 | 27499 | try sema.addReferencedBy(block, src, decl); |
| 27515 | 27500 | return try sema.analyzeDeclRef(decl); |
| 27516 | 27501 | } |
| ... | ... | @@ -27519,10 +27504,10 @@ fn namespaceLookupVal( |
| 27519 | 27504 | sema: *Sema, |
| 27520 | 27505 | block: *Block, |
| 27521 | 27506 | src: LazySrcLoc, |
| 27522 | | namespace: InternPool.NamespaceIndex, |
| 27507 | opt_namespace: InternPool.OptionalNamespaceIndex, |
| 27523 | 27508 | decl_name: InternPool.NullTerminatedString, |
| 27524 | 27509 | ) CompileError!?Air.Inst.Ref { |
| 27525 | | const decl = (try sema.namespaceLookup(block, src, namespace, decl_name)) orelse return null; |
| 27510 | const decl = (try sema.namespaceLookup(block, src, opt_namespace, decl_name)) orelse return null; |
| 27526 | 27511 | return try sema.analyzeDeclVal(block, src, decl); |
| 27527 | 27512 | } |
| 27528 | 27513 | |
| ... | ... | @@ -37580,7 +37565,7 @@ fn getBuiltinDecl(sema: *Sema, block: *Block, name: []const u8) CompileError!Int |
| 37580 | 37565 | const opt_builtin_inst = (try sema.namespaceLookupRef( |
| 37581 | 37566 | block, |
| 37582 | 37567 | src, |
| 37583 | | mod.declPtr(std_file.root_decl.unwrap().?).src_namespace, |
| 37568 | mod.declPtr(std_file.root_decl.unwrap().?).src_namespace.toOptional(), |
| 37584 | 37569 | try ip.getOrPutString(gpa, "builtin"), |
| 37585 | 37570 | )) orelse @panic("lib/std.zig is corrupt and missing 'builtin'"); |
| 37586 | 37571 | const builtin_inst = try sema.analyzeLoad(block, src, opt_builtin_inst, src); |
| ... | ... | @@ -37591,7 +37576,7 @@ fn getBuiltinDecl(sema: *Sema, block: *Block, name: []const u8) CompileError!Int |
| 37591 | 37576 | const decl_index = (try sema.namespaceLookup( |
| 37592 | 37577 | block, |
| 37593 | 37578 | src, |
| 37594 | | builtin_ty.getNamespaceIndex(mod).unwrap().?, |
| 37579 | builtin_ty.getNamespaceIndex(mod), |
| 37595 | 37580 | try ip.getOrPutString(gpa, name), |
| 37596 | 37581 | )) orelse std.debug.panic("lib/std/builtin.zig is corrupt and missing '{s}'", .{name}); |
| 37597 | 37582 | return decl_index; |