authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-05-21 04:29:34-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-10 20:47:54-07:00
loga6fcf469fc8982d36597586ac0dbba94027b2429
tree728ea43b19c84f34aaa8d1b4b52573b469dd24b7
parent84099e50fc0af3719f3819c6c2d37dedba1aaae4

Value: remove legacy type values


5 files changed, 22 insertions(+), 41 deletions(-)

src/Module.zig+6-6
......@@ -841,16 +841,16 @@ pub const Decl = struct {
841841
842842 pub fn getStructIndex(decl: *Decl, mod: *Module) Struct.OptionalIndex {
843843 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);
846846 }
847847
848848 /// If the Decl has a value and it is a union, return it,
849849 /// otherwise null.
850850 pub fn getUnion(decl: *Decl, mod: *Module) ?*Union {
851851 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());
854854 }
855855
856856 /// 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 {
46954695 return sema.fail(&block_scope, ty_src, "type {} has no namespace", .{ty.fmt(mod)});
46964696 }
46974697
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();
47004700 decl.@"align" = 0;
47014701 decl.@"linksection" = null;
47024702 decl.has_tv = true;
src/Sema.zig+11-11
......@@ -6131,7 +6131,7 @@ fn lookupInNamespace(
61316131 continue;
61326132 }
61336133 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();
61356135 const sub_ns = ns_ty.getNamespace(mod).?;
61366136 try checked_namespaces.put(gpa, sub_ns, src_file == sub_usingnamespace_decl.getFileScope(mod));
61376137 }
......@@ -16131,7 +16131,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1613116131 // address_space: AddressSpace
1613216132 try mod.enumValueFieldIndex(addrspace_ty, @enumToInt(info.@"addrspace")),
1613316133 // child: type,
16134 try Value.Tag.ty.create(sema.arena, info.pointee_type),
16134 info.pointee_type.toValue(),
1613516135 // is_allowzero: bool,
1613616136 Value.makeBool(info.@"allowzero"),
1613716137 // sentinel: ?*const anyopaque,
......@@ -16152,7 +16152,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1615216152 // len: comptime_int,
1615316153 field_values[0] = try mod.intValue(Type.comptime_int, info.len);
1615416154 // child: type,
16155 field_values[1] = try Value.Tag.ty.create(sema.arena, info.elem_type);
16155 field_values[1] = info.elem_type.toValue();
1615616156 // sentinel: ?*const anyopaque,
1615716157 field_values[2] = try sema.optRefValue(block, info.elem_type, info.sentinel);
1615816158
......@@ -16170,7 +16170,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1617016170 // len: comptime_int,
1617116171 field_values[0] = try mod.intValue(Type.comptime_int, info.len);
1617216172 // child: type,
16173 field_values[1] = try Value.Tag.ty.create(sema.arena, info.elem_type);
16173 field_values[1] = info.elem_type.toValue();
1617416174
1617516175 return sema.addConstant(
1617616176 type_info_ty,
......@@ -16183,7 +16183,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1618316183 .Optional => {
1618416184 const field_values = try sema.arena.alloc(Value, 1);
1618516185 // child: type,
16186 field_values[0] = try Value.Tag.ty.create(sema.arena, ty.optionalChild(mod));
16186 field_values[0] = ty.optionalChild(mod).toValue();
1618716187
1618816188 return sema.addConstant(
1618916189 type_info_ty,
......@@ -16286,9 +16286,9 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1628616286 .ErrorUnion => {
1628716287 const field_values = try sema.arena.alloc(Value, 2);
1628816288 // 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();
1629016290 // payload: type,
16291 field_values[1] = try Value.Tag.ty.create(sema.arena, ty.errorUnionPayload(mod));
16291 field_values[1] = ty.errorUnionPayload(mod).toValue();
1629216292
1629316293 return sema.addConstant(
1629416294 type_info_ty,
......@@ -16436,7 +16436,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1643616436 // name: []const u8,
1643716437 name_val,
1643816438 // type: type,
16439 try Value.Tag.ty.create(fields_anon_decl.arena(), field.ty),
16439 field.ty.toValue(),
1644016440 // alignment: comptime_int,
1644116441 try mod.intValue(Type.comptime_int, alignment),
1644216442 };
......@@ -16465,7 +16465,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1646516465 const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, union_ty.getNamespaceIndex(mod));
1646616466
1646716467 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();
1646916469 break :v try Value.Tag.opt_payload.create(sema.arena, ty_val);
1647016470 } else Value.null;
1647116471
......@@ -16602,7 +16602,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1660216602 // name: []const u8,
1660316603 name_val,
1660416604 // type: type,
16605 try Value.Tag.ty.create(fields_anon_decl.arena(), field.ty),
16605 field.ty.toValue(),
1660616606 // default_value: ?*const anyopaque,
1660716607 try default_val_ptr.copy(fields_anon_decl.arena()),
1660816608 // is_comptime: bool,
......@@ -16641,7 +16641,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1664116641 const struct_obj = mod.typeToStruct(struct_ty).?;
1664216642 assert(struct_obj.haveLayout());
1664316643 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();
1664516645 break :blk try Value.Tag.opt_payload.create(sema.arena, backing_int_ty_val);
1664616646 } else {
1664716647 break :blk Value.null;
src/TypedValue.zig+2-13
......@@ -103,7 +103,6 @@ pub fn print(
103103 return writer.writeAll(" }");
104104 },
105105 .the_only_possible_value => return writer.writeAll("0"),
106 .ty => return val.castTag(.ty).?.data.print(writer, mod),
107106 .lazy_align => {
108107 const sub_ty = val.castTag(.lazy_align).?.data;
109108 const x = sub_ty.abiAlignment(mod);
......@@ -301,15 +300,10 @@ pub fn print(
301300
302301 const data = val.castTag(.eu_payload_ptr).?.data;
303302
304 var ty_val: Value.Payload.Ty = .{
305 .base = .{ .tag = .ty },
306 .data = ty,
307 };
308
309303 try writer.writeAll("@as(");
310304 try print(.{
311305 .ty = Type.type,
312 .val = Value.initPayload(&ty_val.base),
306 .val = ty.toValue(),
313307 }, writer, level - 1, mod);
314308
315309 try writer.writeAll(", &(payload of ");
......@@ -329,15 +323,10 @@ pub fn print(
329323
330324 const data = val.castTag(.opt_payload_ptr).?.data;
331325
332 var ty_val: Value.Payload.Ty = .{
333 .base = .{ .tag = .ty },
334 .data = ty,
335 };
336
337326 try writer.writeAll("@as(");
338327 try print(.{
339328 .ty = Type.type,
340 .val = Value.initPayload(&ty_val.base),
329 .val = ty.toValue(),
341330 }, writer, level - 1, mod);
342331
343332 try writer.writeAll(", &(payload of ");
src/link.zig+1-1
......@@ -1124,7 +1124,7 @@ pub const File = struct {
11241124
11251125 pub fn initDecl(kind: Kind, decl: ?Module.Decl.Index, mod: *Module) LazySymbol {
11261126 return .{ .kind = kind, .ty = if (decl) |decl_index|
1127 mod.declPtr(decl_index).val.castTag(.ty).?.data
1127 mod.declPtr(decl_index).val.toType()
11281128 else
11291129 Type.anyerror };
11301130 }
src/value.zig+2-10
......@@ -39,7 +39,6 @@ pub const Value = struct {
3939 empty_array, // See last_no_payload_tag below.
4040 // After this, the tag requires a payload.
4141
42 ty,
4342 function,
4443 extern_fn,
4544 /// A comptime-known pointer can point to the address of a global
......@@ -141,7 +140,6 @@ pub const Value = struct {
141140 .str_lit => Payload.StrLit,
142141 .slice => Payload.Slice,
143142
144 .ty,
145143 .lazy_align,
146144 .lazy_size,
147145 => Payload.Ty,
......@@ -255,7 +253,7 @@ pub const Value = struct {
255253 .empty_array,
256254 => unreachable,
257255
258 .ty, .lazy_align, .lazy_size => {
256 .lazy_align, .lazy_size => {
259257 const payload = self.cast(Payload.Ty).?;
260258 const new_payload = try arena.create(Payload.Ty);
261259 new_payload.* = .{
......@@ -472,7 +470,6 @@ pub const Value = struct {
472470 return out_stream.writeAll("(union value)");
473471 },
474472 .the_only_possible_value => return out_stream.writeAll("(the only possible value)"),
475 .ty => return val.castTag(.ty).?.data.dump("", options, out_stream),
476473 .lazy_align => {
477474 try out_stream.writeAll("@alignOf(");
478475 try val.castTag(.lazy_align).?.data.dump("", options, out_stream);
......@@ -695,12 +692,7 @@ pub const Value = struct {
695692
696693 /// Asserts that the value is representable as a type.
697694 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();
704696 }
705697
706698 pub fn enumToInt(val: Value, ty: Type, mod: *Module) Allocator.Error!Value {