authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2021-12-20 03:58:19+01:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2021-12-21 01:41:51+01:00
log58d67a6718d5d0673389fa19f5bb20812b4bb22a
treef18a6306939c3564929548b4e7a4f0a026fc8c00
parentc47ed0c912d2f445710fe4486fa071dd63601989

stage2: make anyopaque sized

While this is technically incorrect, proper handling of anyopaque, as well as regular opaque, is probably best left until pointers to zero-sized types having no bits is abolished.

2 files changed, 17 insertions(+), 13 deletions(-)

src/codegen/llvm.zig+16-12
......@@ -761,21 +761,25 @@ pub const DeclGen = struct {
761761 dg.context.intType(8);
762762 return llvm_elem_ty.pointerType(llvm_addrspace);
763763 },
764 .Opaque => {
765 const gop = try dg.object.type_map.getOrPut(gpa, t);
766 if (gop.found_existing) return gop.value_ptr.*;
764 .Opaque => switch (t.tag()) {
765 .@"opaque" => {
766 const gop = try dg.object.type_map.getOrPut(gpa, t);
767 if (gop.found_existing) return gop.value_ptr.*;
767768
768 // The Type memory is ephemeral; since we want to store a longer-lived
769 // reference, we need to copy it here.
770 gop.key_ptr.* = try t.copy(dg.object.type_map_arena.allocator());
769 // The Type memory is ephemeral; since we want to store a longer-lived
770 // reference, we need to copy it here.
771 gop.key_ptr.* = try t.copy(dg.object.type_map_arena.allocator());
771772
772 const opaque_obj = t.castTag(.@"opaque").?.data;
773 const name = try opaque_obj.getFullyQualifiedName(gpa);
774 defer gpa.free(name);
773 const opaque_obj = t.castTag(.@"opaque").?.data;
774 const name = try opaque_obj.getFullyQualifiedName(gpa);
775 defer gpa.free(name);
775776
776 const llvm_struct_ty = dg.context.structCreateNamed(name);
777 gop.value_ptr.* = llvm_struct_ty; // must be done before any recursive calls
778 return llvm_struct_ty;
777 const llvm_struct_ty = dg.context.structCreateNamed(name);
778 gop.value_ptr.* = llvm_struct_ty; // must be done before any recursive calls
779 return llvm_struct_ty;
780 },
781 .anyopaque => return dg.context.intType(8),
782 else => unreachable,
779783 },
780784 .Array => {
781785 const elem_type = try dg.llvmType(t.childType());
src/type.zig+1-1
......@@ -1575,6 +1575,7 @@ pub const Type = extern union {
15751575 .extern_options,
15761576 .@"anyframe",
15771577 .anyframe_T,
1578 .anyopaque,
15781579 .@"opaque",
15791580 .single_const_pointer,
15801581 .single_mut_pointer,
......@@ -1654,7 +1655,6 @@ pub const Type = extern union {
16541655 return payload.error_set.hasCodeGenBits() or payload.payload.hasCodeGenBits();
16551656 },
16561657
1657 .anyopaque,
16581658 .void,
16591659 .type,
16601660 .comptime_int,