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