Value: remove legacy type values

This commit is contained in:
Jacob Young 2023-05-21 04:29:34 -04:00 committed by Andrew Kelley
parent 84099e50fc
commit a6fcf469fc
5 changed files with 22 additions and 41 deletions

View file

@ -841,16 +841,16 @@ pub const Decl = struct {
pub fn getStructIndex(decl: *Decl, mod: *Module) Struct.OptionalIndex {
if (!decl.owns_tv) return .none;
const ty = (decl.val.castTag(.ty) orelse return .none).data;
return mod.intern_pool.indexToStructType(ty.ip_index);
if (decl.val.ip_index == .none) return .none;
return mod.intern_pool.indexToStructType(decl.val.ip_index);
}
/// If the Decl has a value and it is a union, return it,
/// otherwise null.
pub fn getUnion(decl: *Decl, mod: *Module) ?*Union {
if (!decl.owns_tv) return null;
const ty = (decl.val.castTag(.ty) orelse return null).data;
return mod.typeToUnion(ty);
if (decl.val.ip_index == .none) return null;
return mod.typeToUnion(decl.val.toType());
}
/// 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 {
return sema.fail(&block_scope, ty_src, "type {} has no namespace", .{ty.fmt(mod)});
}
decl.ty = Type.type;
decl.val = try Value.Tag.ty.create(decl_arena_allocator, ty);
decl.ty = InternPool.Index.type_type.toType();
decl.val = ty.toValue();
decl.@"align" = 0;
decl.@"linksection" = null;
decl.has_tv = true;

View file

@ -6131,7 +6131,7 @@ fn lookupInNamespace(
continue;
}
try sema.ensureDeclAnalyzed(sub_usingnamespace_decl_index);
const ns_ty = sub_usingnamespace_decl.val.castTag(.ty).?.data;
const ns_ty = sub_usingnamespace_decl.val.toType();
const sub_ns = ns_ty.getNamespace(mod).?;
try checked_namespaces.put(gpa, sub_ns, src_file == sub_usingnamespace_decl.getFileScope(mod));
}
@ -16131,7 +16131,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
// address_space: AddressSpace
try mod.enumValueFieldIndex(addrspace_ty, @enumToInt(info.@"addrspace")),
// child: type,
try Value.Tag.ty.create(sema.arena, info.pointee_type),
info.pointee_type.toValue(),
// is_allowzero: bool,
Value.makeBool(info.@"allowzero"),
// sentinel: ?*const anyopaque,
@ -16152,7 +16152,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
// len: comptime_int,
field_values[0] = try mod.intValue(Type.comptime_int, info.len);
// child: type,
field_values[1] = try Value.Tag.ty.create(sema.arena, info.elem_type);
field_values[1] = info.elem_type.toValue();
// sentinel: ?*const anyopaque,
field_values[2] = try sema.optRefValue(block, info.elem_type, info.sentinel);
@ -16170,7 +16170,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
// len: comptime_int,
field_values[0] = try mod.intValue(Type.comptime_int, info.len);
// child: type,
field_values[1] = try Value.Tag.ty.create(sema.arena, info.elem_type);
field_values[1] = info.elem_type.toValue();
return sema.addConstant(
type_info_ty,
@ -16183,7 +16183,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
.Optional => {
const field_values = try sema.arena.alloc(Value, 1);
// child: type,
field_values[0] = try Value.Tag.ty.create(sema.arena, ty.optionalChild(mod));
field_values[0] = ty.optionalChild(mod).toValue();
return sema.addConstant(
type_info_ty,
@ -16286,9 +16286,9 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
.ErrorUnion => {
const field_values = try sema.arena.alloc(Value, 2);
// error_set: type,
field_values[0] = try Value.Tag.ty.create(sema.arena, ty.errorUnionSet(mod));
field_values[0] = ty.errorUnionSet(mod).toValue();
// payload: type,
field_values[1] = try Value.Tag.ty.create(sema.arena, ty.errorUnionPayload(mod));
field_values[1] = ty.errorUnionPayload(mod).toValue();
return sema.addConstant(
type_info_ty,
@ -16436,7 +16436,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
// name: []const u8,
name_val,
// type: type,
try Value.Tag.ty.create(fields_anon_decl.arena(), field.ty),
field.ty.toValue(),
// alignment: comptime_int,
try mod.intValue(Type.comptime_int, alignment),
};
@ -16465,7 +16465,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, union_ty.getNamespaceIndex(mod));
const enum_tag_ty_val = if (union_ty.unionTagType(mod)) |tag_ty| v: {
const ty_val = try Value.Tag.ty.create(sema.arena, tag_ty);
const ty_val = tag_ty.toValue();
break :v try Value.Tag.opt_payload.create(sema.arena, ty_val);
} else Value.null;
@ -16602,7 +16602,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
// name: []const u8,
name_val,
// type: type,
try Value.Tag.ty.create(fields_anon_decl.arena(), field.ty),
field.ty.toValue(),
// default_value: ?*const anyopaque,
try default_val_ptr.copy(fields_anon_decl.arena()),
// is_comptime: bool,
@ -16641,7 +16641,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
const struct_obj = mod.typeToStruct(struct_ty).?;
assert(struct_obj.haveLayout());
assert(struct_obj.backing_int_ty.isInt(mod));
const backing_int_ty_val = try Value.Tag.ty.create(sema.arena, struct_obj.backing_int_ty);
const backing_int_ty_val = struct_obj.backing_int_ty.toValue();
break :blk try Value.Tag.opt_payload.create(sema.arena, backing_int_ty_val);
} else {
break :blk Value.null;

View file

@ -103,7 +103,6 @@ pub fn print(
return writer.writeAll(" }");
},
.the_only_possible_value => return writer.writeAll("0"),
.ty => return val.castTag(.ty).?.data.print(writer, mod),
.lazy_align => {
const sub_ty = val.castTag(.lazy_align).?.data;
const x = sub_ty.abiAlignment(mod);
@ -301,15 +300,10 @@ pub fn print(
const data = val.castTag(.eu_payload_ptr).?.data;
var ty_val: Value.Payload.Ty = .{
.base = .{ .tag = .ty },
.data = ty,
};
try writer.writeAll("@as(");
try print(.{
.ty = Type.type,
.val = Value.initPayload(&ty_val.base),
.val = ty.toValue(),
}, writer, level - 1, mod);
try writer.writeAll(", &(payload of ");
@ -329,15 +323,10 @@ pub fn print(
const data = val.castTag(.opt_payload_ptr).?.data;
var ty_val: Value.Payload.Ty = .{
.base = .{ .tag = .ty },
.data = ty,
};
try writer.writeAll("@as(");
try print(.{
.ty = Type.type,
.val = Value.initPayload(&ty_val.base),
.val = ty.toValue(),
}, writer, level - 1, mod);
try writer.writeAll(", &(payload of ");

View file

@ -1124,7 +1124,7 @@ pub const File = struct {
pub fn initDecl(kind: Kind, decl: ?Module.Decl.Index, mod: *Module) LazySymbol {
return .{ .kind = kind, .ty = if (decl) |decl_index|
mod.declPtr(decl_index).val.castTag(.ty).?.data
mod.declPtr(decl_index).val.toType()
else
Type.anyerror };
}

View file

@ -39,7 +39,6 @@ pub const Value = struct {
empty_array, // See last_no_payload_tag below.
// After this, the tag requires a payload.
ty,
function,
extern_fn,
/// A comptime-known pointer can point to the address of a global
@ -141,7 +140,6 @@ pub const Value = struct {
.str_lit => Payload.StrLit,
.slice => Payload.Slice,
.ty,
.lazy_align,
.lazy_size,
=> Payload.Ty,
@ -255,7 +253,7 @@ pub const Value = struct {
.empty_array,
=> unreachable,
.ty, .lazy_align, .lazy_size => {
.lazy_align, .lazy_size => {
const payload = self.cast(Payload.Ty).?;
const new_payload = try arena.create(Payload.Ty);
new_payload.* = .{
@ -472,7 +470,6 @@ pub const Value = struct {
return out_stream.writeAll("(union value)");
},
.the_only_possible_value => return out_stream.writeAll("(the only possible value)"),
.ty => return val.castTag(.ty).?.data.dump("", options, out_stream),
.lazy_align => {
try out_stream.writeAll("@alignOf(");
try val.castTag(.lazy_align).?.data.dump("", options, out_stream);
@ -695,12 +692,7 @@ pub const Value = struct {
/// Asserts that the value is representable as a type.
pub fn toType(self: Value) Type {
if (self.ip_index != .none) return self.ip_index.toType();
return switch (self.tag()) {
.ty => self.castTag(.ty).?.data,
else => unreachable,
};
return self.ip_index.toType();
}
pub fn enumToInt(val: Value, ty: Type, mod: *Module) Allocator.Error!Value {