| author | |
| committer | |
| log | a6fcf469fc8982d36597586ac0dbba94027b2429 |
| tree | 728ea43b19c84f34aaa8d1b4b52573b469dd24b7 |
| parent | 84099e50fc0af3719f3819c6c2d37dedba1aaae4 |
5 files changed, 22 insertions(+), 41 deletions(-)
src/Module.zig+6-6| ... | @@ -841,16 +841,16 @@ pub const Decl = struct { | ... | @@ -841,16 +841,16 @@ pub const Decl = struct { |
| 841 | 841 | ||
| 842 | pub fn getStructIndex(decl: *Decl, mod: *Module) Struct.OptionalIndex { | 842 | pub fn getStructIndex(decl: *Decl, mod: *Module) Struct.OptionalIndex { |
| 843 | if (!decl.owns_tv) return .none; | 843 | if (!decl.owns_tv) return .none; |
| 844 | const ty = (decl.val.castTag(.ty) orelse return .none).data; | 844 | if (decl.val.ip_index == .none) return .none; |
| 845 | return mod.intern_pool.indexToStructType(ty.ip_index); | 845 | return mod.intern_pool.indexToStructType(decl.val.ip_index); |
| 846 | } | 846 | } |
| 847 | 847 | ||
| 848 | /// If the Decl has a value and it is a union, return it, | 848 | /// If the Decl has a value and it is a union, return it, |
| 849 | /// otherwise null. | 849 | /// otherwise null. |
| 850 | pub fn getUnion(decl: *Decl, mod: *Module) ?*Union { | 850 | pub fn getUnion(decl: *Decl, mod: *Module) ?*Union { |
| 851 | if (!decl.owns_tv) return null; | 851 | if (!decl.owns_tv) return null; |
| 852 | const ty = (decl.val.castTag(.ty) orelse return null).data; | 852 | if (decl.val.ip_index == .none) return null; |
| 853 | return mod.typeToUnion(ty); | 853 | return mod.typeToUnion(decl.val.toType()); |
| 854 | } | 854 | } |
| 855 | 855 | ||
| 856 | /// If the Decl has a value and it is a function, return it, | 856 | /// If the Decl has a value and it is a function, return it, |
| ... | @@ -4695,8 +4695,8 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool { | ... | @@ -4695,8 +4695,8 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool { |
| 4695 | return sema.fail(&block_scope, ty_src, "type {} has no namespace", .{ty.fmt(mod)}); | 4695 | return sema.fail(&block_scope, ty_src, "type {} has no namespace", .{ty.fmt(mod)}); |
| 4696 | } | 4696 | } |
| 4697 | 4697 | ||
| 4698 | decl.ty = Type.type; | 4698 | decl.ty = InternPool.Index.type_type.toType(); |
| 4699 | decl.val = try Value.Tag.ty.create(decl_arena_allocator, ty); | 4699 | decl.val = ty.toValue(); |
| 4700 | decl.@"align" = 0; | 4700 | decl.@"align" = 0; |
| 4701 | decl.@"linksection" = null; | 4701 | decl.@"linksection" = null; |
| 4702 | decl.has_tv = true; | 4702 | decl.has_tv = true; |
src/Sema.zig+11-11| ... | @@ -6131,7 +6131,7 @@ fn lookupInNamespace( | ... | @@ -6131,7 +6131,7 @@ fn lookupInNamespace( |
| 6131 | continue; | 6131 | continue; |
| 6132 | } | 6132 | } |
| 6133 | try sema.ensureDeclAnalyzed(sub_usingnamespace_decl_index); | 6133 | try sema.ensureDeclAnalyzed(sub_usingnamespace_decl_index); |
| 6134 | const ns_ty = sub_usingnamespace_decl.val.castTag(.ty).?.data; | 6134 | const ns_ty = sub_usingnamespace_decl.val.toType(); |
| 6135 | const sub_ns = ns_ty.getNamespace(mod).?; | 6135 | const sub_ns = ns_ty.getNamespace(mod).?; |
| 6136 | try checked_namespaces.put(gpa, sub_ns, src_file == sub_usingnamespace_decl.getFileScope(mod)); | 6136 | try checked_namespaces.put(gpa, sub_ns, src_file == sub_usingnamespace_decl.getFileScope(mod)); |
| 6137 | } | 6137 | } |
| ... | @@ -16131,7 +16131,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16131,7 +16131,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16131 | // address_space: AddressSpace | 16131 | // address_space: AddressSpace |
| 16132 | try mod.enumValueFieldIndex(addrspace_ty, @enumToInt(info.@"addrspace")), | 16132 | try mod.enumValueFieldIndex(addrspace_ty, @enumToInt(info.@"addrspace")), |
| 16133 | // child: type, | 16133 | // child: type, |
| 16134 | try Value.Tag.ty.create(sema.arena, info.pointee_type), | 16134 | info.pointee_type.toValue(), |
| 16135 | // is_allowzero: bool, | 16135 | // is_allowzero: bool, |
| 16136 | Value.makeBool(info.@"allowzero"), | 16136 | Value.makeBool(info.@"allowzero"), |
| 16137 | // sentinel: ?*const anyopaque, | 16137 | // sentinel: ?*const anyopaque, |
| ... | @@ -16152,7 +16152,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16152,7 +16152,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16152 | // len: comptime_int, | 16152 | // len: comptime_int, |
| 16153 | field_values[0] = try mod.intValue(Type.comptime_int, info.len); | 16153 | field_values[0] = try mod.intValue(Type.comptime_int, info.len); |
| 16154 | // child: type, | 16154 | // child: type, |
| 16155 | field_values[1] = try Value.Tag.ty.create(sema.arena, info.elem_type); | 16155 | field_values[1] = info.elem_type.toValue(); |
| 16156 | // sentinel: ?*const anyopaque, | 16156 | // sentinel: ?*const anyopaque, |
| 16157 | field_values[2] = try sema.optRefValue(block, info.elem_type, info.sentinel); | 16157 | field_values[2] = try sema.optRefValue(block, info.elem_type, info.sentinel); |
| 16158 | 16158 | ||
| ... | @@ -16170,7 +16170,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16170,7 +16170,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16170 | // len: comptime_int, | 16170 | // len: comptime_int, |
| 16171 | field_values[0] = try mod.intValue(Type.comptime_int, info.len); | 16171 | field_values[0] = try mod.intValue(Type.comptime_int, info.len); |
| 16172 | // child: type, | 16172 | // child: type, |
| 16173 | field_values[1] = try Value.Tag.ty.create(sema.arena, info.elem_type); | 16173 | field_values[1] = info.elem_type.toValue(); |
| 16174 | 16174 | ||
| 16175 | return sema.addConstant( | 16175 | return sema.addConstant( |
| 16176 | type_info_ty, | 16176 | type_info_ty, |
| ... | @@ -16183,7 +16183,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16183,7 +16183,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16183 | .Optional => { | 16183 | .Optional => { |
| 16184 | const field_values = try sema.arena.alloc(Value, 1); | 16184 | const field_values = try sema.arena.alloc(Value, 1); |
| 16185 | // child: type, | 16185 | // child: type, |
| 16186 | field_values[0] = try Value.Tag.ty.create(sema.arena, ty.optionalChild(mod)); | 16186 | field_values[0] = ty.optionalChild(mod).toValue(); |
| 16187 | 16187 | ||
| 16188 | return sema.addConstant( | 16188 | return sema.addConstant( |
| 16189 | type_info_ty, | 16189 | type_info_ty, |
| ... | @@ -16286,9 +16286,9 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16286,9 +16286,9 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16286 | .ErrorUnion => { | 16286 | .ErrorUnion => { |
| 16287 | const field_values = try sema.arena.alloc(Value, 2); | 16287 | const field_values = try sema.arena.alloc(Value, 2); |
| 16288 | // error_set: type, | 16288 | // error_set: type, |
| 16289 | field_values[0] = try Value.Tag.ty.create(sema.arena, ty.errorUnionSet(mod)); | 16289 | field_values[0] = ty.errorUnionSet(mod).toValue(); |
| 16290 | // payload: type, | 16290 | // payload: type, |
| 16291 | field_values[1] = try Value.Tag.ty.create(sema.arena, ty.errorUnionPayload(mod)); | 16291 | field_values[1] = ty.errorUnionPayload(mod).toValue(); |
| 16292 | 16292 | ||
| 16293 | return sema.addConstant( | 16293 | return sema.addConstant( |
| 16294 | type_info_ty, | 16294 | type_info_ty, |
| ... | @@ -16436,7 +16436,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16436,7 +16436,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16436 | // name: []const u8, | 16436 | // name: []const u8, |
| 16437 | name_val, | 16437 | name_val, |
| 16438 | // type: type, | 16438 | // type: type, |
| 16439 | try Value.Tag.ty.create(fields_anon_decl.arena(), field.ty), | 16439 | field.ty.toValue(), |
| 16440 | // alignment: comptime_int, | 16440 | // alignment: comptime_int, |
| 16441 | try mod.intValue(Type.comptime_int, alignment), | 16441 | try mod.intValue(Type.comptime_int, alignment), |
| 16442 | }; | 16442 | }; |
| ... | @@ -16465,7 +16465,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16465,7 +16465,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16465 | const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, union_ty.getNamespaceIndex(mod)); | 16465 | const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, union_ty.getNamespaceIndex(mod)); |
| 16466 | 16466 | ||
| 16467 | const enum_tag_ty_val = if (union_ty.unionTagType(mod)) |tag_ty| v: { | 16467 | const enum_tag_ty_val = if (union_ty.unionTagType(mod)) |tag_ty| v: { |
| 16468 | const ty_val = try Value.Tag.ty.create(sema.arena, tag_ty); | 16468 | const ty_val = tag_ty.toValue(); |
| 16469 | break :v try Value.Tag.opt_payload.create(sema.arena, ty_val); | 16469 | break :v try Value.Tag.opt_payload.create(sema.arena, ty_val); |
| 16470 | } else Value.null; | 16470 | } else Value.null; |
| 16471 | 16471 | ||
| ... | @@ -16602,7 +16602,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16602,7 +16602,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16602 | // name: []const u8, | 16602 | // name: []const u8, |
| 16603 | name_val, | 16603 | name_val, |
| 16604 | // type: type, | 16604 | // type: type, |
| 16605 | try Value.Tag.ty.create(fields_anon_decl.arena(), field.ty), | 16605 | field.ty.toValue(), |
| 16606 | // default_value: ?*const anyopaque, | 16606 | // default_value: ?*const anyopaque, |
| 16607 | try default_val_ptr.copy(fields_anon_decl.arena()), | 16607 | try default_val_ptr.copy(fields_anon_decl.arena()), |
| 16608 | // is_comptime: bool, | 16608 | // is_comptime: bool, |
| ... | @@ -16641,7 +16641,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16641,7 +16641,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16641 | const struct_obj = mod.typeToStruct(struct_ty).?; | 16641 | const struct_obj = mod.typeToStruct(struct_ty).?; |
| 16642 | assert(struct_obj.haveLayout()); | 16642 | assert(struct_obj.haveLayout()); |
| 16643 | assert(struct_obj.backing_int_ty.isInt(mod)); | 16643 | assert(struct_obj.backing_int_ty.isInt(mod)); |
| 16644 | const backing_int_ty_val = try Value.Tag.ty.create(sema.arena, struct_obj.backing_int_ty); | 16644 | const backing_int_ty_val = struct_obj.backing_int_ty.toValue(); |
| 16645 | break :blk try Value.Tag.opt_payload.create(sema.arena, backing_int_ty_val); | 16645 | break :blk try Value.Tag.opt_payload.create(sema.arena, backing_int_ty_val); |
| 16646 | } else { | 16646 | } else { |
| 16647 | break :blk Value.null; | 16647 | break :blk Value.null; |
src/TypedValue.zig+2-13| ... | @@ -103,7 +103,6 @@ pub fn print( | ... | @@ -103,7 +103,6 @@ pub fn print( |
| 103 | return writer.writeAll(" }"); | 103 | return writer.writeAll(" }"); |
| 104 | }, | 104 | }, |
| 105 | .the_only_possible_value => return writer.writeAll("0"), | 105 | .the_only_possible_value => return writer.writeAll("0"), |
| 106 | .ty => return val.castTag(.ty).?.data.print(writer, mod), | ||
| 107 | .lazy_align => { | 106 | .lazy_align => { |
| 108 | const sub_ty = val.castTag(.lazy_align).?.data; | 107 | const sub_ty = val.castTag(.lazy_align).?.data; |
| 109 | const x = sub_ty.abiAlignment(mod); | 108 | const x = sub_ty.abiAlignment(mod); |
| ... | @@ -301,15 +300,10 @@ pub fn print( | ... | @@ -301,15 +300,10 @@ pub fn print( |
| 301 | 300 | ||
| 302 | const data = val.castTag(.eu_payload_ptr).?.data; | 301 | const data = val.castTag(.eu_payload_ptr).?.data; |
| 303 | 302 | ||
| 304 | var ty_val: Value.Payload.Ty = .{ | ||
| 305 | .base = .{ .tag = .ty }, | ||
| 306 | .data = ty, | ||
| 307 | }; | ||
| 308 | |||
| 309 | try writer.writeAll("@as("); | 303 | try writer.writeAll("@as("); |
| 310 | try print(.{ | 304 | try print(.{ |
| 311 | .ty = Type.type, | 305 | .ty = Type.type, |
| 312 | .val = Value.initPayload(&ty_val.base), | 306 | .val = ty.toValue(), |
| 313 | }, writer, level - 1, mod); | 307 | }, writer, level - 1, mod); |
| 314 | 308 | ||
| 315 | try writer.writeAll(", &(payload of "); | 309 | try writer.writeAll(", &(payload of "); |
| ... | @@ -329,15 +323,10 @@ pub fn print( | ... | @@ -329,15 +323,10 @@ pub fn print( |
| 329 | 323 | ||
| 330 | const data = val.castTag(.opt_payload_ptr).?.data; | 324 | const data = val.castTag(.opt_payload_ptr).?.data; |
| 331 | 325 | ||
| 332 | var ty_val: Value.Payload.Ty = .{ | ||
| 333 | .base = .{ .tag = .ty }, | ||
| 334 | .data = ty, | ||
| 335 | }; | ||
| 336 | |||
| 337 | try writer.writeAll("@as("); | 326 | try writer.writeAll("@as("); |
| 338 | try print(.{ | 327 | try print(.{ |
| 339 | .ty = Type.type, | 328 | .ty = Type.type, |
| 340 | .val = Value.initPayload(&ty_val.base), | 329 | .val = ty.toValue(), |
| 341 | }, writer, level - 1, mod); | 330 | }, writer, level - 1, mod); |
| 342 | 331 | ||
| 343 | try writer.writeAll(", &(payload of "); | 332 | try writer.writeAll(", &(payload of "); |
src/link.zig+1-1| ... | @@ -1124,7 +1124,7 @@ pub const File = struct { | ... | @@ -1124,7 +1124,7 @@ pub const File = struct { |
| 1124 | 1124 | ||
| 1125 | pub fn initDecl(kind: Kind, decl: ?Module.Decl.Index, mod: *Module) LazySymbol { | 1125 | pub fn initDecl(kind: Kind, decl: ?Module.Decl.Index, mod: *Module) LazySymbol { |
| 1126 | return .{ .kind = kind, .ty = if (decl) |decl_index| | 1126 | return .{ .kind = kind, .ty = if (decl) |decl_index| |
| 1127 | mod.declPtr(decl_index).val.castTag(.ty).?.data | 1127 | mod.declPtr(decl_index).val.toType() |
| 1128 | else | 1128 | else |
| 1129 | Type.anyerror }; | 1129 | Type.anyerror }; |
| 1130 | } | 1130 | } |
src/value.zig+2-10| ... | @@ -39,7 +39,6 @@ pub const Value = struct { | ... | @@ -39,7 +39,6 @@ pub const Value = struct { |
| 39 | empty_array, // See last_no_payload_tag below. | 39 | empty_array, // See last_no_payload_tag below. |
| 40 | // After this, the tag requires a payload. | 40 | // After this, the tag requires a payload. |
| 41 | 41 | ||
| 42 | ty, | ||
| 43 | function, | 42 | function, |
| 44 | extern_fn, | 43 | extern_fn, |
| 45 | /// A comptime-known pointer can point to the address of a global | 44 | /// A comptime-known pointer can point to the address of a global |
| ... | @@ -141,7 +140,6 @@ pub const Value = struct { | ... | @@ -141,7 +140,6 @@ pub const Value = struct { |
| 141 | .str_lit => Payload.StrLit, | 140 | .str_lit => Payload.StrLit, |
| 142 | .slice => Payload.Slice, | 141 | .slice => Payload.Slice, |
| 143 | 142 | ||
| 144 | .ty, | ||
| 145 | .lazy_align, | 143 | .lazy_align, |
| 146 | .lazy_size, | 144 | .lazy_size, |
| 147 | => Payload.Ty, | 145 | => Payload.Ty, |
| ... | @@ -255,7 +253,7 @@ pub const Value = struct { | ... | @@ -255,7 +253,7 @@ pub const Value = struct { |
| 255 | .empty_array, | 253 | .empty_array, |
| 256 | => unreachable, | 254 | => unreachable, |
| 257 | 255 | ||
| 258 | .ty, .lazy_align, .lazy_size => { | 256 | .lazy_align, .lazy_size => { |
| 259 | const payload = self.cast(Payload.Ty).?; | 257 | const payload = self.cast(Payload.Ty).?; |
| 260 | const new_payload = try arena.create(Payload.Ty); | 258 | const new_payload = try arena.create(Payload.Ty); |
| 261 | new_payload.* = .{ | 259 | new_payload.* = .{ |
| ... | @@ -472,7 +470,6 @@ pub const Value = struct { | ... | @@ -472,7 +470,6 @@ pub const Value = struct { |
| 472 | return out_stream.writeAll("(union value)"); | 470 | return out_stream.writeAll("(union value)"); |
| 473 | }, | 471 | }, |
| 474 | .the_only_possible_value => return out_stream.writeAll("(the only possible value)"), | 472 | .the_only_possible_value => return out_stream.writeAll("(the only possible value)"), |
| 475 | .ty => return val.castTag(.ty).?.data.dump("", options, out_stream), | ||
| 476 | .lazy_align => { | 473 | .lazy_align => { |
| 477 | try out_stream.writeAll("@alignOf("); | 474 | try out_stream.writeAll("@alignOf("); |
| 478 | try val.castTag(.lazy_align).?.data.dump("", options, out_stream); | 475 | try val.castTag(.lazy_align).?.data.dump("", options, out_stream); |
| ... | @@ -695,12 +692,7 @@ pub const Value = struct { | ... | @@ -695,12 +692,7 @@ pub const Value = struct { |
| 695 | 692 | ||
| 696 | /// Asserts that the value is representable as a type. | 693 | /// Asserts that the value is representable as a type. |
| 697 | pub fn toType(self: Value) Type { | 694 | pub fn toType(self: Value) Type { |
| 698 | if (self.ip_index != .none) return self.ip_index.toType(); | 695 | return self.ip_index.toType(); |
| 699 | return switch (self.tag()) { | ||
| 700 | .ty => self.castTag(.ty).?.data, | ||
| 701 | |||
| 702 | else => unreachable, | ||
| 703 | }; | ||
| 704 | } | 696 | } |
| 705 | 697 | ||
| 706 | pub fn enumToInt(val: Value, ty: Type, mod: *Module) Allocator.Error!Value { | 698 | pub fn enumToInt(val: Value, ty: Type, mod: *Module) Allocator.Error!Value { |