| ... | ... | @@ -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 | } |
| ... | ... | @@ -13700,8 +13701,7 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 13700 | 13701 | } }); |
| 13701 | 13702 | } |
| 13702 | 13703 | |
| 13703 | | const namespace = container_type.getNamespaceIndex(mod).unwrap() orelse |
| 13704 | | return .bool_false; |
| 13704 | const namespace = container_type.getNamespaceIndex(mod); |
| 13705 | 13705 | if (try sema.lookupInNamespace(block, src, namespace, decl_name, true)) |decl_index| { |
| 13706 | 13706 | const decl = mod.declPtr(decl_index); |
| 13707 | 13707 | if (decl.is_pub or decl.getFileScope(mod) == block.getFileScope(mod)) { |
| ... | ... | @@ -17535,7 +17535,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17535 | 17535 | const fn_info_decl_index = (try sema.namespaceLookup( |
| 17536 | 17536 | block, |
| 17537 | 17537 | src, |
| 17538 | | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 17538 | type_info_ty.getNamespaceIndex(mod), |
| 17539 | 17539 | try ip.getOrPutString(gpa, "Fn"), |
| 17540 | 17540 | )).?; |
| 17541 | 17541 | try sema.ensureDeclAnalyzed(fn_info_decl_index); |
| ... | ... | @@ -17545,7 +17545,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17545 | 17545 | const param_info_decl_index = (try sema.namespaceLookup( |
| 17546 | 17546 | block, |
| 17547 | 17547 | src, |
| 17548 | | fn_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 17548 | fn_info_ty.getNamespaceIndex(mod), |
| 17549 | 17549 | try ip.getOrPutString(gpa, "Param"), |
| 17550 | 17550 | )).?; |
| 17551 | 17551 | try sema.ensureDeclAnalyzed(param_info_decl_index); |
| ... | ... | @@ -17647,7 +17647,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17647 | 17647 | const int_info_decl_index = (try sema.namespaceLookup( |
| 17648 | 17648 | block, |
| 17649 | 17649 | src, |
| 17650 | | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 17650 | type_info_ty.getNamespaceIndex(mod), |
| 17651 | 17651 | try ip.getOrPutString(gpa, "Int"), |
| 17652 | 17652 | )).?; |
| 17653 | 17653 | try sema.ensureDeclAnalyzed(int_info_decl_index); |
| ... | ... | @@ -17675,7 +17675,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17675 | 17675 | const float_info_decl_index = (try sema.namespaceLookup( |
| 17676 | 17676 | block, |
| 17677 | 17677 | src, |
| 17678 | | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 17678 | type_info_ty.getNamespaceIndex(mod), |
| 17679 | 17679 | try ip.getOrPutString(gpa, "Float"), |
| 17680 | 17680 | )).?; |
| 17681 | 17681 | try sema.ensureDeclAnalyzed(float_info_decl_index); |
| ... | ... | @@ -17707,7 +17707,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17707 | 17707 | const decl_index = (try sema.namespaceLookup( |
| 17708 | 17708 | block, |
| 17709 | 17709 | src, |
| 17710 | | (try sema.getBuiltinType("Type")).getNamespaceIndex(mod).unwrap().?, |
| 17710 | (try sema.getBuiltinType("Type")).getNamespaceIndex(mod), |
| 17711 | 17711 | try ip.getOrPutString(gpa, "Pointer"), |
| 17712 | 17712 | )).?; |
| 17713 | 17713 | try sema.ensureDeclAnalyzed(decl_index); |
| ... | ... | @@ -17718,7 +17718,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17718 | 17718 | const decl_index = (try sema.namespaceLookup( |
| 17719 | 17719 | block, |
| 17720 | 17720 | src, |
| 17721 | | pointer_ty.getNamespaceIndex(mod).unwrap().?, |
| 17721 | pointer_ty.getNamespaceIndex(mod), |
| 17722 | 17722 | try ip.getOrPutString(gpa, "Size"), |
| 17723 | 17723 | )).?; |
| 17724 | 17724 | try sema.ensureDeclAnalyzed(decl_index); |
| ... | ... | @@ -17761,7 +17761,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17761 | 17761 | const array_field_ty_decl_index = (try sema.namespaceLookup( |
| 17762 | 17762 | block, |
| 17763 | 17763 | src, |
| 17764 | | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 17764 | type_info_ty.getNamespaceIndex(mod), |
| 17765 | 17765 | try ip.getOrPutString(gpa, "Array"), |
| 17766 | 17766 | )).?; |
| 17767 | 17767 | try sema.ensureDeclAnalyzed(array_field_ty_decl_index); |
| ... | ... | @@ -17792,7 +17792,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17792 | 17792 | const vector_field_ty_decl_index = (try sema.namespaceLookup( |
| 17793 | 17793 | block, |
| 17794 | 17794 | src, |
| 17795 | | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 17795 | type_info_ty.getNamespaceIndex(mod), |
| 17796 | 17796 | try ip.getOrPutString(gpa, "Vector"), |
| 17797 | 17797 | )).?; |
| 17798 | 17798 | try sema.ensureDeclAnalyzed(vector_field_ty_decl_index); |
| ... | ... | @@ -17821,7 +17821,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17821 | 17821 | const optional_field_ty_decl_index = (try sema.namespaceLookup( |
| 17822 | 17822 | block, |
| 17823 | 17823 | src, |
| 17824 | | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 17824 | type_info_ty.getNamespaceIndex(mod), |
| 17825 | 17825 | try ip.getOrPutString(gpa, "Optional"), |
| 17826 | 17826 | )).?; |
| 17827 | 17827 | try sema.ensureDeclAnalyzed(optional_field_ty_decl_index); |
| ... | ... | @@ -17848,7 +17848,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17848 | 17848 | const set_field_ty_decl_index = (try sema.namespaceLookup( |
| 17849 | 17849 | block, |
| 17850 | 17850 | src, |
| 17851 | | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 17851 | type_info_ty.getNamespaceIndex(mod), |
| 17852 | 17852 | try ip.getOrPutString(gpa, "Error"), |
| 17853 | 17853 | )).?; |
| 17854 | 17854 | try sema.ensureDeclAnalyzed(set_field_ty_decl_index); |
| ... | ... | @@ -17953,7 +17953,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17953 | 17953 | const error_union_field_ty_decl_index = (try sema.namespaceLookup( |
| 17954 | 17954 | block, |
| 17955 | 17955 | src, |
| 17956 | | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 17956 | type_info_ty.getNamespaceIndex(mod), |
| 17957 | 17957 | try ip.getOrPutString(gpa, "ErrorUnion"), |
| 17958 | 17958 | )).?; |
| 17959 | 17959 | try sema.ensureDeclAnalyzed(error_union_field_ty_decl_index); |
| ... | ... | @@ -17983,7 +17983,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17983 | 17983 | const enum_field_ty_decl_index = (try sema.namespaceLookup( |
| 17984 | 17984 | block, |
| 17985 | 17985 | src, |
| 17986 | | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 17986 | type_info_ty.getNamespaceIndex(mod), |
| 17987 | 17987 | try ip.getOrPutString(gpa, "EnumField"), |
| 17988 | 17988 | )).?; |
| 17989 | 17989 | try sema.ensureDeclAnalyzed(enum_field_ty_decl_index); |
| ... | ... | @@ -18074,7 +18074,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18074 | 18074 | const type_enum_ty_decl_index = (try sema.namespaceLookup( |
| 18075 | 18075 | block, |
| 18076 | 18076 | src, |
| 18077 | | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 18077 | type_info_ty.getNamespaceIndex(mod), |
| 18078 | 18078 | try ip.getOrPutString(gpa, "Enum"), |
| 18079 | 18079 | )).?; |
| 18080 | 18080 | try sema.ensureDeclAnalyzed(type_enum_ty_decl_index); |
| ... | ... | @@ -18106,7 +18106,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18106 | 18106 | const type_union_ty_decl_index = (try sema.namespaceLookup( |
| 18107 | 18107 | block, |
| 18108 | 18108 | src, |
| 18109 | | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 18109 | type_info_ty.getNamespaceIndex(mod), |
| 18110 | 18110 | try ip.getOrPutString(gpa, "Union"), |
| 18111 | 18111 | )).?; |
| 18112 | 18112 | try sema.ensureDeclAnalyzed(type_union_ty_decl_index); |
| ... | ... | @@ -18118,7 +18118,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18118 | 18118 | const union_field_ty_decl_index = (try sema.namespaceLookup( |
| 18119 | 18119 | block, |
| 18120 | 18120 | src, |
| 18121 | | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 18121 | type_info_ty.getNamespaceIndex(mod), |
| 18122 | 18122 | try ip.getOrPutString(gpa, "UnionField"), |
| 18123 | 18123 | )).?; |
| 18124 | 18124 | try sema.ensureDeclAnalyzed(union_field_ty_decl_index); |
| ... | ... | @@ -18220,7 +18220,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18220 | 18220 | const decl_index = (try sema.namespaceLookup( |
| 18221 | 18221 | block, |
| 18222 | 18222 | src, |
| 18223 | | (try sema.getBuiltinType("Type")).getNamespaceIndex(mod).unwrap().?, |
| 18223 | (try sema.getBuiltinType("Type")).getNamespaceIndex(mod), |
| 18224 | 18224 | try ip.getOrPutString(gpa, "ContainerLayout"), |
| 18225 | 18225 | )).?; |
| 18226 | 18226 | try sema.ensureDeclAnalyzed(decl_index); |
| ... | ... | @@ -18253,7 +18253,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18253 | 18253 | const type_struct_ty_decl_index = (try sema.namespaceLookup( |
| 18254 | 18254 | block, |
| 18255 | 18255 | src, |
| 18256 | | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 18256 | type_info_ty.getNamespaceIndex(mod), |
| 18257 | 18257 | try ip.getOrPutString(gpa, "Struct"), |
| 18258 | 18258 | )).?; |
| 18259 | 18259 | try sema.ensureDeclAnalyzed(type_struct_ty_decl_index); |
| ... | ... | @@ -18265,7 +18265,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18265 | 18265 | const struct_field_ty_decl_index = (try sema.namespaceLookup( |
| 18266 | 18266 | block, |
| 18267 | 18267 | src, |
| 18268 | | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 18268 | type_info_ty.getNamespaceIndex(mod), |
| 18269 | 18269 | try ip.getOrPutString(gpa, "StructField"), |
| 18270 | 18270 | )).?; |
| 18271 | 18271 | try sema.ensureDeclAnalyzed(struct_field_ty_decl_index); |
| ... | ... | @@ -18450,7 +18450,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18450 | 18450 | const decl_index = (try sema.namespaceLookup( |
| 18451 | 18451 | block, |
| 18452 | 18452 | src, |
| 18453 | | (try sema.getBuiltinType("Type")).getNamespaceIndex(mod).unwrap().?, |
| 18453 | (try sema.getBuiltinType("Type")).getNamespaceIndex(mod), |
| 18454 | 18454 | try ip.getOrPutString(gpa, "ContainerLayout"), |
| 18455 | 18455 | )).?; |
| 18456 | 18456 | try sema.ensureDeclAnalyzed(decl_index); |
| ... | ... | @@ -18486,7 +18486,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18486 | 18486 | const type_opaque_ty_decl_index = (try sema.namespaceLookup( |
| 18487 | 18487 | block, |
| 18488 | 18488 | src, |
| 18489 | | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 18489 | type_info_ty.getNamespaceIndex(mod), |
| 18490 | 18490 | try ip.getOrPutString(gpa, "Opaque"), |
| 18491 | 18491 | )).?; |
| 18492 | 18492 | try sema.ensureDeclAnalyzed(type_opaque_ty_decl_index); |
| ... | ... | @@ -18529,7 +18529,7 @@ fn typeInfoDecls( |
| 18529 | 18529 | const declaration_ty_decl_index = (try sema.namespaceLookup( |
| 18530 | 18530 | block, |
| 18531 | 18531 | src, |
| 18532 | | type_info_ty.getNamespaceIndex(mod).unwrap().?, |
| 18532 | type_info_ty.getNamespaceIndex(mod), |
| 18533 | 18533 | try mod.intern_pool.getOrPutString(gpa, "Declaration"), |
| 18534 | 18534 | )).?; |
| 18535 | 18535 | try sema.ensureDeclAnalyzed(declaration_ty_decl_index); |
| ... | ... | @@ -18544,10 +18544,7 @@ fn typeInfoDecls( |
| 18544 | 18544 | var seen_namespaces = std.AutoHashMap(*Namespace, void).init(gpa); |
| 18545 | 18545 | defer seen_namespaces.deinit(); |
| 18546 | 18546 | |
| 18547 | | if (opt_namespace.unwrap()) |namespace_index| { |
| 18548 | | const namespace = mod.namespacePtr(namespace_index); |
| 18549 | | try sema.typeInfoNamespaceDecls(block, namespace, declaration_ty, &decl_vals, &seen_namespaces); |
| 18550 | | } |
| 18547 | try sema.typeInfoNamespaceDecls(block, opt_namespace, declaration_ty, &decl_vals, &seen_namespaces); |
| 18551 | 18548 | |
| 18552 | 18549 | const array_decl_ty = try mod.arrayType(.{ |
| 18553 | 18550 | .len = decl_vals.items.len, |
| ... | ... | @@ -18580,23 +18577,27 @@ fn typeInfoDecls( |
| 18580 | 18577 | fn typeInfoNamespaceDecls( |
| 18581 | 18578 | sema: *Sema, |
| 18582 | 18579 | block: *Block, |
| 18583 | | namespace: *Namespace, |
| 18580 | opt_namespace_index: InternPool.OptionalNamespaceIndex, |
| 18584 | 18581 | declaration_ty: Type, |
| 18585 | 18582 | decl_vals: *std.ArrayList(InternPool.Index), |
| 18586 | 18583 | seen_namespaces: *std.AutoHashMap(*Namespace, void), |
| 18587 | 18584 | ) !void { |
| 18588 | 18585 | const mod = sema.mod; |
| 18589 | 18586 | const ip = &mod.intern_pool; |
| 18587 | |
| 18588 | const namespace_index = opt_namespace_index.unwrap() orelse return; |
| 18589 | const namespace = mod.namespacePtr(namespace_index); |
| 18590 | |
| 18590 | 18591 | const gop = try seen_namespaces.getOrPut(namespace); |
| 18591 | 18592 | if (gop.found_existing) return; |
| 18593 | |
| 18592 | 18594 | const decls = namespace.decls.keys(); |
| 18593 | 18595 | for (decls) |decl_index| { |
| 18594 | 18596 | const decl = mod.declPtr(decl_index); |
| 18595 | 18597 | if (decl.kind == .@"usingnamespace") { |
| 18596 | 18598 | if (decl.analysis == .in_progress) continue; |
| 18597 | 18599 | try mod.ensureDeclAnalyzed(decl_index); |
| 18598 | | const new_ns = decl.val.toType().getNamespace(mod).?; |
| 18599 | | try sema.typeInfoNamespaceDecls(block, new_ns, declaration_ty, decl_vals, seen_namespaces); |
| 18600 | try sema.typeInfoNamespaceDecls(block, decl.val.toType().getNamespaceIndex(mod), declaration_ty, decl_vals, seen_namespaces); |
| 18600 | 18601 | continue; |
| 18601 | 18602 | } |
| 18602 | 18603 | if (decl.kind != .named or !decl.is_pub) continue; |
| ... | ... | @@ -26585,7 +26586,7 @@ fn preparePanicId(sema: *Sema, block: *Block, panic_id: Module.PanicId) !InternP |
| 26585 | 26586 | const msg_decl_index = (sema.namespaceLookup( |
| 26586 | 26587 | block, |
| 26587 | 26588 | .unneeded, |
| 26588 | | panic_messages_ty.getNamespaceIndex(mod).unwrap().?, |
| 26589 | panic_messages_ty.getNamespaceIndex(mod), |
| 26589 | 26590 | try mod.intern_pool.getOrPutString(gpa, @tagName(panic_id)), |
| 26590 | 26591 | ) catch |err| switch (err) { |
| 26591 | 26592 | error.AnalysisFail, error.NeededSourceLocation => @panic("std.builtin.panic_messages is corrupt"), |
| ... | ... | @@ -27004,10 +27005,8 @@ fn fieldVal( |
| 27004 | 27005 | } }))); |
| 27005 | 27006 | }, |
| 27006 | 27007 | .Union => { |
| 27007 | | if (child_type.getNamespaceIndex(mod).unwrap()) |namespace| { |
| 27008 | | if (try sema.namespaceLookupVal(block, src, namespace, field_name)) |inst| { |
| 27009 | | return inst; |
| 27010 | | } |
| 27008 | if (try sema.namespaceLookupVal(block, src, child_type.getNamespaceIndex(mod), field_name)) |inst| { |
| 27009 | return inst; |
| 27011 | 27010 | } |
| 27012 | 27011 | try sema.resolveTypeFields(child_type); |
| 27013 | 27012 | if (child_type.unionTagType(mod)) |enum_ty| { |
| ... | ... | @@ -27019,10 +27018,8 @@ fn fieldVal( |
| 27019 | 27018 | return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name); |
| 27020 | 27019 | }, |
| 27021 | 27020 | .Enum => { |
| 27022 | | if (child_type.getNamespaceIndex(mod).unwrap()) |namespace| { |
| 27023 | | if (try sema.namespaceLookupVal(block, src, namespace, field_name)) |inst| { |
| 27024 | | return inst; |
| 27025 | | } |
| 27021 | if (try sema.namespaceLookupVal(block, src, child_type.getNamespaceIndex(mod), field_name)) |inst| { |
| 27022 | return inst; |
| 27026 | 27023 | } |
| 27027 | 27024 | const field_index_usize = child_type.enumFieldIndex(field_name, mod) orelse |
| 27028 | 27025 | return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name); |
| ... | ... | @@ -27031,10 +27028,8 @@ fn fieldVal( |
| 27031 | 27028 | return Air.internedToRef(enum_val.toIntern()); |
| 27032 | 27029 | }, |
| 27033 | 27030 | .Struct, .Opaque => { |
| 27034 | | if (child_type.getNamespaceIndex(mod).unwrap()) |namespace| { |
| 27035 | | if (try sema.namespaceLookupVal(block, src, namespace, field_name)) |inst| { |
| 27036 | | return inst; |
| 27037 | | } |
| 27031 | if (try sema.namespaceLookupVal(block, src, child_type.getNamespaceIndex(mod), field_name)) |inst| { |
| 27032 | return inst; |
| 27038 | 27033 | } |
| 27039 | 27034 | return sema.failWithBadMemberAccess(block, child_type, src, field_name); |
| 27040 | 27035 | }, |
| ... | ... | @@ -27230,10 +27225,8 @@ fn fieldPtr( |
| 27230 | 27225 | } })); |
| 27231 | 27226 | }, |
| 27232 | 27227 | .Union => { |
| 27233 | | if (child_type.getNamespaceIndex(mod).unwrap()) |namespace| { |
| 27234 | | if (try sema.namespaceLookupRef(block, src, namespace, field_name)) |inst| { |
| 27235 | | return inst; |
| 27236 | | } |
| 27228 | if (try sema.namespaceLookupRef(block, src, child_type.getNamespaceIndex(mod), field_name)) |inst| { |
| 27229 | return inst; |
| 27237 | 27230 | } |
| 27238 | 27231 | try sema.resolveTypeFields(child_type); |
| 27239 | 27232 | if (child_type.unionTagType(mod)) |enum_ty| { |
| ... | ... | @@ -27246,10 +27239,8 @@ fn fieldPtr( |
| 27246 | 27239 | return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name); |
| 27247 | 27240 | }, |
| 27248 | 27241 | .Enum => { |
| 27249 | | if (child_type.getNamespaceIndex(mod).unwrap()) |namespace| { |
| 27250 | | if (try sema.namespaceLookupRef(block, src, namespace, field_name)) |inst| { |
| 27251 | | return inst; |
| 27252 | | } |
| 27242 | if (try sema.namespaceLookupRef(block, src, child_type.getNamespaceIndex(mod), field_name)) |inst| { |
| 27243 | return inst; |
| 27253 | 27244 | } |
| 27254 | 27245 | const field_index = child_type.enumFieldIndex(field_name, mod) orelse { |
| 27255 | 27246 | return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name); |
| ... | ... | @@ -27259,10 +27250,8 @@ fn fieldPtr( |
| 27259 | 27250 | return anonDeclRef(sema, idx_val.toIntern()); |
| 27260 | 27251 | }, |
| 27261 | 27252 | .Struct, .Opaque => { |
| 27262 | | if (child_type.getNamespaceIndex(mod).unwrap()) |namespace| { |
| 27263 | | if (try sema.namespaceLookupRef(block, src, namespace, field_name)) |inst| { |
| 27264 | | return inst; |
| 27265 | | } |
| 27253 | if (try sema.namespaceLookupRef(block, src, child_type.getNamespaceIndex(mod), field_name)) |inst| { |
| 27254 | return inst; |
| 27266 | 27255 | } |
| 27267 | 27256 | return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name); |
| 27268 | 27257 | }, |
| ... | ... | @@ -27375,73 +27364,68 @@ fn fieldCallBind( |
| 27375 | 27364 | } |
| 27376 | 27365 | |
| 27377 | 27366 | // If we get here, we need to look for a decl in the struct type instead. |
| 27378 | | const found_decl = switch (concrete_ty.zigTypeTag(mod)) { |
| 27379 | | .Struct, .Opaque, .Union, .Enum => found_decl: { |
| 27380 | | if (concrete_ty.getNamespaceIndex(mod).unwrap()) |namespace| { |
| 27381 | | if (try sema.namespaceLookup(block, src, namespace, field_name)) |decl_idx| { |
| 27382 | | try sema.addReferencedBy(block, src, decl_idx); |
| 27383 | | const decl_val = try sema.analyzeDeclVal(block, src, decl_idx); |
| 27384 | | const decl_type = sema.typeOf(decl_val); |
| 27385 | | if (mod.typeToFunc(decl_type)) |func_type| f: { |
| 27386 | | if (func_type.param_types.len == 0) break :f; |
| 27387 | | |
| 27388 | | const first_param_type = Type.fromInterned(func_type.param_types.get(ip)[0]); |
| 27389 | | // zig fmt: off |
| 27390 | | if (first_param_type.isGenericPoison() or ( |
| 27391 | | first_param_type.zigTypeTag(mod) == .Pointer and |
| 27392 | | (first_param_type.ptrSize(mod) == .One or |
| 27393 | | first_param_type.ptrSize(mod) == .C) and |
| 27394 | | first_param_type.childType(mod).eql(concrete_ty, mod))) |
| 27395 | | { |
| 27396 | | // zig fmt: on |
| 27397 | | // Note that if the param type is generic poison, we know that it must |
| 27398 | | // specifically be `anytype` since it's the first parameter, meaning we |
| 27399 | | // can safely assume it can be a pointer. |
| 27400 | | // TODO: bound fn calls on rvalues should probably |
| 27401 | | // generate a by-value argument somehow. |
| 27402 | | return .{ .method = .{ |
| 27403 | | .func_inst = decl_val, |
| 27404 | | .arg0_inst = object_ptr, |
| 27405 | | } }; |
| 27406 | | } else if (first_param_type.eql(concrete_ty, mod)) { |
| 27407 | | const deref = try sema.analyzeLoad(block, src, object_ptr, src); |
| 27408 | | return .{ .method = .{ |
| 27409 | | .func_inst = decl_val, |
| 27410 | | .arg0_inst = deref, |
| 27411 | | } }; |
| 27412 | | } else if (first_param_type.zigTypeTag(mod) == .Optional) { |
| 27413 | | const child = first_param_type.optionalChild(mod); |
| 27414 | | if (child.eql(concrete_ty, mod)) { |
| 27415 | | const deref = try sema.analyzeLoad(block, src, object_ptr, src); |
| 27416 | | return .{ .method = .{ |
| 27417 | | .func_inst = decl_val, |
| 27418 | | .arg0_inst = deref, |
| 27419 | | } }; |
| 27420 | | } else if (child.zigTypeTag(mod) == .Pointer and |
| 27421 | | child.ptrSize(mod) == .One and |
| 27422 | | child.childType(mod).eql(concrete_ty, mod)) |
| 27423 | | { |
| 27424 | | return .{ .method = .{ |
| 27425 | | .func_inst = decl_val, |
| 27426 | | .arg0_inst = object_ptr, |
| 27427 | | } }; |
| 27428 | | } |
| 27429 | | } else if (first_param_type.zigTypeTag(mod) == .ErrorUnion and |
| 27430 | | first_param_type.errorUnionPayload(mod).eql(concrete_ty, mod)) |
| 27431 | | { |
| 27432 | | const deref = try sema.analyzeLoad(block, src, object_ptr, src); |
| 27433 | | return .{ .method = .{ |
| 27434 | | .func_inst = decl_val, |
| 27435 | | .arg0_inst = deref, |
| 27436 | | } }; |
| 27437 | | } |
| 27438 | | } |
| 27439 | | break :found_decl decl_idx; |
| 27367 | const found_decl = found_decl: { |
| 27368 | const namespace = concrete_ty.getNamespace(mod) orelse |
| 27369 | break :found_decl null; |
| 27370 | const decl_idx = (try sema.namespaceLookup(block, src, namespace, field_name)) orelse |
| 27371 | break :found_decl null; |
| 27372 | |
| 27373 | try sema.addReferencedBy(block, src, decl_idx); |
| 27374 | const decl_val = try sema.analyzeDeclVal(block, src, decl_idx); |
| 27375 | const decl_type = sema.typeOf(decl_val); |
| 27376 | if (mod.typeToFunc(decl_type)) |func_type| f: { |
| 27377 | if (func_type.param_types.len == 0) break :f; |
| 27378 | |
| 27379 | const first_param_type = Type.fromInterned(func_type.param_types.get(ip)[0]); |
| 27380 | if (first_param_type.isGenericPoison() or |
| 27381 | (first_param_type.zigTypeTag(mod) == .Pointer and |
| 27382 | (first_param_type.ptrSize(mod) == .One or |
| 27383 | first_param_type.ptrSize(mod) == .C) and |
| 27384 | first_param_type.childType(mod).eql(concrete_ty, mod))) |
| 27385 | { |
| 27386 | // Note that if the param type is generic poison, we know that it must |
| 27387 | // specifically be `anytype` since it's the first parameter, meaning we |
| 27388 | // can safely assume it can be a pointer. |
| 27389 | // TODO: bound fn calls on rvalues should probably |
| 27390 | // generate a by-value argument somehow. |
| 27391 | return .{ .method = .{ |
| 27392 | .func_inst = decl_val, |
| 27393 | .arg0_inst = object_ptr, |
| 27394 | } }; |
| 27395 | } else if (first_param_type.eql(concrete_ty, mod)) { |
| 27396 | const deref = try sema.analyzeLoad(block, src, object_ptr, src); |
| 27397 | return .{ .method = .{ |
| 27398 | .func_inst = decl_val, |
| 27399 | .arg0_inst = deref, |
| 27400 | } }; |
| 27401 | } else if (first_param_type.zigTypeTag(mod) == .Optional) { |
| 27402 | const child = first_param_type.optionalChild(mod); |
| 27403 | if (child.eql(concrete_ty, mod)) { |
| 27404 | const deref = try sema.analyzeLoad(block, src, object_ptr, src); |
| 27405 | return .{ .method = .{ |
| 27406 | .func_inst = decl_val, |
| 27407 | .arg0_inst = deref, |
| 27408 | } }; |
| 27409 | } else if (child.zigTypeTag(mod) == .Pointer and |
| 27410 | child.ptrSize(mod) == .One and |
| 27411 | child.childType(mod).eql(concrete_ty, mod)) |
| 27412 | { |
| 27413 | return .{ .method = .{ |
| 27414 | .func_inst = decl_val, |
| 27415 | .arg0_inst = object_ptr, |
| 27416 | } }; |
| 27440 | 27417 | } |
| 27418 | } else if (first_param_type.zigTypeTag(mod) == .ErrorUnion and |
| 27419 | first_param_type.errorUnionPayload(mod).eql(concrete_ty, mod)) |
| 27420 | { |
| 27421 | const deref = try sema.analyzeLoad(block, src, object_ptr, src); |
| 27422 | return .{ .method = .{ |
| 27423 | .func_inst = decl_val, |
| 27424 | .arg0_inst = deref, |
| 27425 | } }; |
| 27441 | 27426 | } |
| 27442 | | break :found_decl null; |
| 27443 | | }, |
| 27444 | | else => null, |
| 27427 | } |
| 27428 | break :found_decl decl_idx; |
| 27445 | 27429 | }; |
| 27446 | 27430 | |
| 27447 | 27431 | const msg = msg: { |
| ... | ... | @@ -27507,12 +27491,12 @@ fn namespaceLookup( |
| 27507 | 27491 | sema: *Sema, |
| 27508 | 27492 | block: *Block, |
| 27509 | 27493 | src: LazySrcLoc, |
| 27510 | | namespace: InternPool.NamespaceIndex, |
| 27494 | opt_namespace: InternPool.OptionalNamespaceIndex, |
| 27511 | 27495 | decl_name: InternPool.NullTerminatedString, |
| 27512 | 27496 | ) CompileError!?InternPool.DeclIndex { |
| 27513 | 27497 | const mod = sema.mod; |
| 27514 | 27498 | const gpa = sema.gpa; |
| 27515 | | if (try sema.lookupInNamespace(block, src, namespace, decl_name, true)) |decl_index| { |
| 27499 | if (try sema.lookupInNamespace(block, src, opt_namespace, decl_name, true)) |decl_index| { |
| 27516 | 27500 | const decl = mod.declPtr(decl_index); |
| 27517 | 27501 | if (!decl.is_pub and decl.getFileScope(mod) != block.getFileScope(mod)) { |
| 27518 | 27502 | const msg = msg: { |
| ... | ... | @@ -27534,10 +27518,10 @@ fn namespaceLookupRef( |
| 27534 | 27518 | sema: *Sema, |
| 27535 | 27519 | block: *Block, |
| 27536 | 27520 | src: LazySrcLoc, |
| 27537 | | namespace: InternPool.NamespaceIndex, |
| 27521 | opt_namespace: InternPool.OptionalNamespaceIndex, |
| 27538 | 27522 | decl_name: InternPool.NullTerminatedString, |
| 27539 | 27523 | ) CompileError!?Air.Inst.Ref { |
| 27540 | | const decl = (try sema.namespaceLookup(block, src, namespace, decl_name)) orelse return null; |
| 27524 | const decl = (try sema.namespaceLookup(block, src, opt_namespace, decl_name)) orelse return null; |
| 27541 | 27525 | try sema.addReferencedBy(block, src, decl); |
| 27542 | 27526 | return try sema.analyzeDeclRef(decl); |
| 27543 | 27527 | } |
| ... | ... | @@ -27546,10 +27530,10 @@ fn namespaceLookupVal( |
| 27546 | 27530 | sema: *Sema, |
| 27547 | 27531 | block: *Block, |
| 27548 | 27532 | src: LazySrcLoc, |
| 27549 | | namespace: InternPool.NamespaceIndex, |
| 27533 | opt_namespace: InternPool.OptionalNamespaceIndex, |
| 27550 | 27534 | decl_name: InternPool.NullTerminatedString, |
| 27551 | 27535 | ) CompileError!?Air.Inst.Ref { |
| 27552 | | const decl = (try sema.namespaceLookup(block, src, namespace, decl_name)) orelse return null; |
| 27536 | const decl = (try sema.namespaceLookup(block, src, opt_namespace, decl_name)) orelse return null; |
| 27553 | 27537 | return try sema.analyzeDeclVal(block, src, decl); |
| 27554 | 27538 | } |
| 27555 | 27539 | |
| ... | ... | @@ -37602,7 +37586,7 @@ fn getBuiltinDecl(sema: *Sema, block: *Block, name: []const u8) CompileError!Int |
| 37602 | 37586 | const opt_builtin_inst = (try sema.namespaceLookupRef( |
| 37603 | 37587 | block, |
| 37604 | 37588 | src, |
| 37605 | | mod.declPtr(std_file.root_decl.unwrap().?).src_namespace, |
| 37589 | mod.declPtr(std_file.root_decl.unwrap().?).src_namespace.toOptional(), |
| 37606 | 37590 | try ip.getOrPutString(gpa, "builtin"), |
| 37607 | 37591 | )) orelse @panic("lib/std.zig is corrupt and missing 'builtin'"); |
| 37608 | 37592 | const builtin_inst = try sema.analyzeLoad(block, src, opt_builtin_inst, src); |
| ... | ... | @@ -37613,7 +37597,7 @@ fn getBuiltinDecl(sema: *Sema, block: *Block, name: []const u8) CompileError!Int |
| 37613 | 37597 | const decl_index = (try sema.namespaceLookup( |
| 37614 | 37598 | block, |
| 37615 | 37599 | src, |
| 37616 | | builtin_ty.getNamespaceIndex(mod).unwrap().?, |
| 37600 | builtin_ty.getNamespaceIndex(mod), |
| 37617 | 37601 | try ip.getOrPutString(gpa, name), |
| 37618 | 37602 | )) orelse std.debug.panic("lib/std/builtin.zig is corrupt and missing '{s}'", .{name}); |
| 37619 | 37603 | return decl_index; |