authorgravatar for david@vortan.devDavid Rubin <david@vortan.dev> 2024-08-11 21:19:01-07:00
committergravatar for david@vortan.devDavid Rubin <david@vortan.dev> 2024-08-25 15:16:46-07:00
log8d2b495b2aa38cc1e0dfe0a7a0c3ffd39d7e7dcc
treeb3c4c01f168e68b9fe91ffa7dc98d4f4bd092701
parent80cd53d3bbf5cdc82715a4400592b40fb93cd5c9
signaturelock-open Commit is signed but in an unrecognized format.

value: remove deprecated `Module` usages


1 files changed, 26 insertions(+), 28 deletions(-)

src/Value.zig+26-28
......@@ -7,8 +7,6 @@ const BigIntMutable = std.math.big.int.Mutable;
77const Target = std.Target;
88const Allocator = std.mem.Allocator;
99const Zcu = @import("Zcu.zig");
10/// Deprecated.
11const Module = Zcu;
1210const Sema = @import("Sema.zig");
1311const InternPool = @import("InternPool.zig");
1412const print_value = @import("print_value.zig");
......@@ -193,7 +191,7 @@ pub fn toBigIntAdvanced(
193191 comptime strat: ResolveStrat,
194192 zcu: *Zcu,
195193 tid: strat.Tid(),
196) Module.CompileError!BigIntConst {
194) Zcu.CompileError!BigIntConst {
197195 return switch (val.toIntern()) {
198196 .bool_false => BigIntMutable.init(&space.limbs, 0).toConst(),
199197 .bool_true => BigIntMutable.init(&space.limbs, 1).toConst(),
......@@ -221,18 +219,18 @@ pub fn toBigIntAdvanced(
221219 };
222220}
223221
224pub fn isFuncBody(val: Value, zcu: *Module) bool {
222pub fn isFuncBody(val: Value, zcu: *Zcu) bool {
225223 return zcu.intern_pool.isFuncBody(val.toIntern());
226224}
227225
228pub fn getFunction(val: Value, zcu: *Module) ?InternPool.Key.Func {
226pub fn getFunction(val: Value, zcu: *Zcu) ?InternPool.Key.Func {
229227 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
230228 .func => |x| x,
231229 else => null,
232230 };
233231}
234232
235pub fn getVariable(val: Value, mod: *Module) ?InternPool.Key.Variable {
233pub fn getVariable(val: Value, mod: *Zcu) ?InternPool.Key.Variable {
236234 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
237235 .variable => |variable| variable,
238236 else => null,
......@@ -1036,7 +1034,7 @@ pub fn floatCast(val: Value, dest_ty: Type, pt: Zcu.PerThread) !Value {
10361034}
10371035
10381036/// Asserts the value is a float
1039pub fn floatHasFraction(self: Value, zcu: *const Module) bool {
1037pub fn floatHasFraction(self: Value, zcu: *const Zcu) bool {
10401038 return switch (zcu.intern_pool.indexToKey(self.toIntern())) {
10411039 .float => |float| switch (float.storage) {
10421040 inline else => |x| @rem(x, 1) != 0,
......@@ -1058,7 +1056,7 @@ pub fn orderAgainstZeroInner(
10581056 comptime strat: ResolveStrat,
10591057 zcu: *Zcu,
10601058 tid: strat.Tid(),
1061) Module.CompileError!std.math.Order {
1059) Zcu.CompileError!std.math.Order {
10621060 return switch (lhs.toIntern()) {
10631061 .bool_false => .eq,
10641062 .bool_true => .gt,
......@@ -1218,7 +1216,7 @@ pub fn compareAllWithZeroSema(
12181216 lhs: Value,
12191217 op: std.math.CompareOperator,
12201218 pt: Zcu.PerThread,
1221) Module.CompileError!bool {
1219) Zcu.CompileError!bool {
12221220 return compareAllWithZeroAdvancedExtra(lhs, op, .sema, pt.zcu, pt.tid);
12231221}
12241222
......@@ -1228,7 +1226,7 @@ pub fn compareAllWithZeroAdvancedExtra(
12281226 comptime strat: ResolveStrat,
12291227 zcu: *Zcu,
12301228 tid: strat.Tid(),
1231) Module.CompileError!bool {
1229) Zcu.CompileError!bool {
12321230 if (lhs.isInf(zcu)) {
12331231 switch (op) {
12341232 .neq => return true,
......@@ -1257,7 +1255,7 @@ pub fn compareAllWithZeroAdvancedExtra(
12571255 return (try orderAgainstZeroInner(lhs, strat, zcu, tid)).compare(op);
12581256}
12591257
1260pub fn eql(a: Value, b: Value, ty: Type, zcu: *Module) bool {
1258pub fn eql(a: Value, b: Value, ty: Type, zcu: *Zcu) bool {
12611259 assert(zcu.intern_pool.typeOf(a.toIntern()) == ty.toIntern());
12621260 assert(zcu.intern_pool.typeOf(b.toIntern()) == ty.toIntern());
12631261 return a.toIntern() == b.toIntern();
......@@ -1311,7 +1309,7 @@ pub fn pointerNav(val: Value, zcu: *Zcu) ?InternPool.Nav.Index {
13111309pub const slice_ptr_index = 0;
13121310pub const slice_len_index = 1;
13131311
1314pub fn slicePtr(val: Value, zcu: *Module) Value {
1312pub fn slicePtr(val: Value, zcu: *Zcu) Value {
13151313 return Value.fromInterned(zcu.intern_pool.slicePtr(val.toIntern()));
13161314}
13171315
......@@ -1346,14 +1344,14 @@ pub fn elemValue(val: Value, pt: Zcu.PerThread, index: usize) Allocator.Error!Va
13461344 }
13471345}
13481346
1349pub fn isLazyAlign(val: Value, zcu: *Module) bool {
1347pub fn isLazyAlign(val: Value, zcu: *Zcu) bool {
13501348 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
13511349 .int => |int| int.storage == .lazy_align,
13521350 else => false,
13531351 };
13541352}
13551353
1356pub fn isLazySize(val: Value, zcu: *Module) bool {
1354pub fn isLazySize(val: Value, zcu: *Zcu) bool {
13571355 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
13581356 .int => |int| int.storage == .lazy_size,
13591357 else => false,
......@@ -1430,7 +1428,7 @@ pub fn fieldValue(val: Value, pt: Zcu.PerThread, index: usize) !Value {
14301428 };
14311429}
14321430
1433pub fn unionTag(val: Value, zcu: *Module) ?Value {
1431pub fn unionTag(val: Value, zcu: *Zcu) ?Value {
14341432 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
14351433 .undef, .enum_tag => val,
14361434 .un => |un| if (un.tag != .none) Value.fromInterned(un.tag) else return null,
......@@ -1438,27 +1436,27 @@ pub fn unionTag(val: Value, zcu: *Module) ?Value {
14381436 };
14391437}
14401438
1441pub fn unionValue(val: Value, zcu: *Module) Value {
1439pub fn unionValue(val: Value, zcu: *Zcu) Value {
14421440 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
14431441 .un => |un| Value.fromInterned(un.val),
14441442 else => unreachable,
14451443 };
14461444}
14471445
1448pub fn isUndef(val: Value, zcu: *Module) bool {
1446pub fn isUndef(val: Value, zcu: *Zcu) bool {
14491447 return zcu.intern_pool.isUndef(val.toIntern());
14501448}
14511449
14521450/// TODO: check for cases such as array that is not marked undef but all the element
14531451/// values are marked undef, or struct that is not marked undef but all fields are marked
14541452/// undef, etc.
1455pub fn isUndefDeep(val: Value, zcu: *Module) bool {
1453pub fn isUndefDeep(val: Value, zcu: *Zcu) bool {
14561454 return val.isUndef(zcu);
14571455}
14581456
14591457/// Asserts the value is not undefined and not unreachable.
14601458/// C pointers with an integer value of 0 are also considered null.
1461pub fn isNull(val: Value, zcu: *Module) bool {
1459pub fn isNull(val: Value, zcu: *Zcu) bool {
14621460 return switch (val.toIntern()) {
14631461 .undef => unreachable,
14641462 .unreachable_value => unreachable,
......@@ -1476,7 +1474,7 @@ pub fn isNull(val: Value, zcu: *Module) bool {
14761474}
14771475
14781476/// Valid only for error (union) types. Asserts the value is not undefined and not unreachable.
1479pub fn getErrorName(val: Value, zcu: *const Module) InternPool.OptionalNullTerminatedString {
1477pub fn getErrorName(val: Value, zcu: *const Zcu) InternPool.OptionalNullTerminatedString {
14801478 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
14811479 .err => |err| err.name.toOptional(),
14821480 .error_union => |error_union| switch (error_union.val) {
......@@ -1487,7 +1485,7 @@ pub fn getErrorName(val: Value, zcu: *const Module) InternPool.OptionalNullTermi
14871485 };
14881486}
14891487
1490pub fn getErrorInt(val: Value, zcu: *Zcu) Module.ErrorInt {
1488pub fn getErrorInt(val: Value, zcu: *Zcu) Zcu.ErrorInt {
14911489 return if (getErrorName(val, zcu).unwrap()) |err_name|
14921490 zcu.intern_pool.getErrorValueIfExists(err_name).?
14931491 else
......@@ -1496,12 +1494,12 @@ pub fn getErrorInt(val: Value, zcu: *Zcu) Module.ErrorInt {
14961494
14971495/// Assumes the type is an error union. Returns true if and only if the value is
14981496/// the error union payload, not an error.
1499pub fn errorUnionIsPayload(val: Value, zcu: *const Module) bool {
1497pub fn errorUnionIsPayload(val: Value, zcu: *const Zcu) bool {
15001498 return zcu.intern_pool.indexToKey(val.toIntern()).error_union.val == .payload;
15011499}
15021500
15031501/// Value of the optional, null if optional has no payload.
1504pub fn optionalValue(val: Value, zcu: *const Module) ?Value {
1502pub fn optionalValue(val: Value, zcu: *const Zcu) ?Value {
15051503 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
15061504 .opt => |opt| switch (opt.val) {
15071505 .none => null,
......@@ -1513,7 +1511,7 @@ pub fn optionalValue(val: Value, zcu: *const Module) ?Value {
15131511}
15141512
15151513/// Valid for all types. Asserts the value is not undefined.
1516pub fn isFloat(self: Value, zcu: *const Module) bool {
1514pub fn isFloat(self: Value, zcu: *const Zcu) bool {
15171515 return switch (self.toIntern()) {
15181516 .undef => unreachable,
15191517 else => switch (zcu.intern_pool.indexToKey(self.toIntern())) {
......@@ -1524,7 +1522,7 @@ pub fn isFloat(self: Value, zcu: *const Module) bool {
15241522 };
15251523}
15261524
1527pub fn floatFromInt(val: Value, arena: Allocator, int_ty: Type, float_ty: Type, zcu: *Module) !Value {
1525pub fn floatFromInt(val: Value, arena: Allocator, int_ty: Type, float_ty: Type, zcu: *Zcu) !Value {
15281526 return floatFromIntAdvanced(val, arena, int_ty, float_ty, zcu, .normal) catch |err| switch (err) {
15291527 error.OutOfMemory => return error.OutOfMemory,
15301528 else => unreachable,
......@@ -2320,7 +2318,7 @@ pub fn intModScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt:
23202318}
23212319
23222320/// Returns true if the value is a floating point type and is NaN. Returns false otherwise.
2323pub fn isNan(val: Value, zcu: *const Module) bool {
2321pub fn isNan(val: Value, zcu: *const Zcu) bool {
23242322 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
23252323 .float => |float| switch (float.storage) {
23262324 inline else => |x| std.math.isNan(x),
......@@ -2330,7 +2328,7 @@ pub fn isNan(val: Value, zcu: *const Module) bool {
23302328}
23312329
23322330/// Returns true if the value is a floating point type and is infinite. Returns false otherwise.
2333pub fn isInf(val: Value, zcu: *const Module) bool {
2331pub fn isInf(val: Value, zcu: *const Zcu) bool {
23342332 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
23352333 .float => |float| switch (float.storage) {
23362334 inline else => |x| std.math.isInf(x),
......@@ -2339,7 +2337,7 @@ pub fn isInf(val: Value, zcu: *const Module) bool {
23392337 };
23402338}
23412339
2342pub fn isNegativeInf(val: Value, zcu: *const Module) bool {
2340pub fn isNegativeInf(val: Value, zcu: *const Zcu) bool {
23432341 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
23442342 .float => |float| switch (float.storage) {
23452343 inline else => |x| std.math.isNegativeInf(x),