Sema: remove redundant addConstant functions

After ff37ccd, interned values are trivial to convert to Air refs, using
`Air.internedToRef`. This made functions like `Sema.addConstant` effectively
redundant. This commit removes `Sema.addConstant` and `Sema.addType`, replacing
them with direct usages of `Air.internedToRef`.

Additionally, a new helper `Module.undefValue` is added, and the following
functions are moved into Module:
* `Sema.addConstUndef` -> `Module.undefRef`
* `Sema.addUnsignedInt` -> `Module.intRef` (now also works for signed types)

The general pattern here is that any `Module.xyzValue` helper may also have a
corresponding `Module.xyzRef` helper, which just wraps the call in
`Air.internedToRef`.
This commit is contained in:
mlugg 2023-08-11 14:02:52 +01:00 committed by Andrew Kelley
parent 8b9161179d
commit 5e0107fbce
2 changed files with 595 additions and 670 deletions

View File

@ -6612,6 +6612,14 @@ pub fn enumValueFieldIndex(mod: *Module, ty: Type, field_index: u32) Allocator.E
} })).toValue();
}
pub fn undefValue(mod: *Module, ty: Type) Allocator.Error!Value {
return (try mod.intern(.{ .undef = ty.toIntern() })).toValue();
}
pub fn undefRef(mod: *Module, ty: Type) Allocator.Error!Air.Inst.Ref {
return Air.internedToRef((try mod.undefValue(ty)).toIntern());
}
pub fn intValue(mod: *Module, ty: Type, x: anytype) Allocator.Error!Value {
if (std.math.cast(u64, x)) |casted| return intValue_u64(mod, ty, casted);
if (std.math.cast(i64, x)) |casted| return intValue_i64(mod, ty, casted);
@ -6620,6 +6628,10 @@ pub fn intValue(mod: *Module, ty: Type, x: anytype) Allocator.Error!Value {
return intValue_big(mod, ty, big_int.toConst());
}
pub fn intRef(mod: *Module, ty: Type, x: anytype) Allocator.Error!Air.Inst.Ref {
return Air.internedToRef((try mod.intValue(ty, x)).toIntern());
}
pub fn intValue_big(mod: *Module, ty: Type, x: BigIntConst) Allocator.Error!Value {
const i = try intern(mod, .{ .int = .{
.ty = ty.toIntern(),

File diff suppressed because it is too large Load Diff