diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-09-30 00:14:55 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-30 00:14:55 -0400 |
| commit | 34835bbbcfe81cc87e823d14dc9b25e698ad5edc (patch) | |
| tree | 28a56101f900d2b5a098b78ee800f4df909ae577 /src | |
| parent | f6312e4b6933b8c8d163d6e6b20da135c5fa986a (diff) | |
| parent | 2a4e89e0c9428b1ca59bc23c7c1d667c8ddb2304 (diff) | |
| download | zig-34835bbbcfe81cc87e823d14dc9b25e698ad5edc.tar.gz zig-34835bbbcfe81cc87e823d14dc9b25e698ad5edc.zip | |
Merge pull request #13010 from Vexu/stage2-fixes
fix stack trace line numbers
Diffstat (limited to 'src')
| -rw-r--r-- | src/AstGen.zig | 11 | ||||
| -rw-r--r-- | src/Module.zig | 1 | ||||
| -rw-r--r-- | src/Sema.zig | 17 | ||||
| -rw-r--r-- | src/type.zig | 20 |
4 files changed, 36 insertions, 13 deletions
diff --git a/src/AstGen.zig b/src/AstGen.zig index 8e6721d7bc..422827c673 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -4233,13 +4233,10 @@ fn structDeclInner( // are in scope, so that field types, alignments, and default value expressions // can refer to decls within the struct itself. astgen.advanceSourceCursorToNode(node); - // If `node == 0` then this is the root struct and all the declarations should - // be relative to the beginning of the file. - const decl_line = if (node == 0) 0 else astgen.source_line; var block_scope: GenZir = .{ .parent = &namespace.base, .decl_node_index = node, - .decl_line = decl_line, + .decl_line = gz.decl_line, .astgen = astgen, .force_comptime = true, .instructions = gz.instructions, @@ -4439,7 +4436,7 @@ fn unionDeclInner( var block_scope: GenZir = .{ .parent = &namespace.base, .decl_node_index = node, - .decl_line = astgen.source_line, + .decl_line = gz.decl_line, .astgen = astgen, .force_comptime = true, .instructions = gz.instructions, @@ -4722,7 +4719,7 @@ fn containerDecl( var block_scope: GenZir = .{ .parent = &namespace.base, .decl_node_index = node, - .decl_line = astgen.source_line, + .decl_line = gz.decl_line, .astgen = astgen, .force_comptime = true, .instructions = gz.instructions, @@ -4827,7 +4824,7 @@ fn containerDecl( var block_scope: GenZir = .{ .parent = &namespace.base, .decl_node_index = node, - .decl_line = astgen.source_line, + .decl_line = gz.decl_line, .astgen = astgen, .force_comptime = true, .instructions = gz.instructions, diff --git a/src/Module.zig b/src/Module.zig index e756cc3dfd..6056c385e3 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -4435,6 +4435,7 @@ pub fn semaFile(mod: *Module, file: *File) SemaError!void { new_decl.alive = true; // This Decl corresponds to a File and is therefore always alive. new_decl.analysis = .in_progress; new_decl.generation = mod.generation; + new_decl.name_fully_qualified = true; if (file.status == .success_zir) { assert(file.zir_loaded); diff --git a/src/Sema.zig b/src/Sema.zig index 5e65132510..aed09d6201 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -4353,6 +4353,11 @@ fn failWithBadMemberAccess( .Enum => "enum", else => unreachable, }; + if (sema.mod.declIsRoot(agg_ty.getOwnerDecl())) { + return sema.fail(block, field_src, "root struct of file '{}' has no member named '{s}'", .{ + agg_ty.fmt(sema.mod), field_name, + }); + } const msg = msg: { const msg = try sema.errMsg(block, field_src, "{s} '{}' has no member named '{s}'", .{ kw_name, agg_ty.fmt(sema.mod), field_name, @@ -21664,14 +21669,17 @@ fn fieldPtr( else object_ptr; + const attr_ptr_ty = if (is_pointer_to) object_ty else object_ptr_ty; + if (mem.eql(u8, field_name, "ptr")) { const buf = try sema.arena.create(Type.SlicePtrFieldTypeBuffer); const slice_ptr_ty = inner_ty.slicePtrFieldType(buf); const result_ty = try Type.ptr(sema.arena, sema.mod, .{ .pointee_type = slice_ptr_ty, - .mutable = object_ptr_ty.ptrIsMutable(), - .@"addrspace" = object_ptr_ty.ptrAddressSpace(), + .mutable = attr_ptr_ty.ptrIsMutable(), + .@"volatile" = attr_ptr_ty.isVolatilePtr(), + .@"addrspace" = attr_ptr_ty.ptrAddressSpace(), }); if (try sema.resolveDefinedValue(block, object_ptr_src, inner_ptr)) |val| { @@ -21690,8 +21698,9 @@ fn fieldPtr( } else if (mem.eql(u8, field_name, "len")) { const result_ty = try Type.ptr(sema.arena, sema.mod, .{ .pointee_type = Type.usize, - .mutable = object_ptr_ty.ptrIsMutable(), - .@"addrspace" = object_ptr_ty.ptrAddressSpace(), + .mutable = attr_ptr_ty.ptrIsMutable(), + .@"volatile" = attr_ptr_ty.isVolatilePtr(), + .@"addrspace" = attr_ptr_ty.ptrAddressSpace(), }); if (try sema.resolveDefinedValue(block, object_ptr_src, inner_ptr)) |val| { diff --git a/src/type.zig b/src/type.zig index 3e2e395d07..1fef525062 100644 --- a/src/type.zig +++ b/src/type.zig @@ -3458,12 +3458,21 @@ pub const Type = extern union { else => {}, } + const payload_size = switch (try child_type.abiSizeAdvanced(target, strat)) { + .scalar => |elem_size| elem_size, + .val => switch (strat) { + .sema_kit => unreachable, + .eager => unreachable, + .lazy => |arena| return AbiSizeAdvanced{ .val = try Value.Tag.lazy_size.create(arena, ty) }, + }, + }; + // Optional types are represented as a struct with the child type as the first // field and a boolean as the second. Since the child type's abi alignment is // guaranteed to be >= that of bool's (1 byte) the added size is exactly equal // to the child type's ABI alignment. return AbiSizeAdvanced{ - .scalar = child_type.abiAlignment(target) + child_type.abiSize(target), + .scalar = child_type.abiAlignment(target) + payload_size, }; }, @@ -3478,7 +3487,14 @@ pub const Type = extern union { } const code_align = abiAlignment(Type.anyerror, target); const payload_align = abiAlignment(data.payload, target); - const payload_size = abiSize(data.payload, target); + const payload_size = switch (try data.payload.abiSizeAdvanced(target, strat)) { + .scalar => |elem_size| elem_size, + .val => switch (strat) { + .sema_kit => unreachable, + .eager => unreachable, + .lazy => |arena| return AbiSizeAdvanced{ .val = try Value.Tag.lazy_size.create(arena, ty) }, + }, + }; var size: u64 = 0; if (code_align > payload_align) { |
