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;...@@ -7,8 +7,6 @@ const BigIntMutable = std.math.big.int.Mutable;
7const Target = std.Target;7const Target = std.Target;
8const Allocator = std.mem.Allocator;8const Allocator = std.mem.Allocator;
9const Zcu = @import("Zcu.zig");9const Zcu = @import("Zcu.zig");
10/// Deprecated.
11const Module = Zcu;
12const Sema = @import("Sema.zig");10const Sema = @import("Sema.zig");
13const InternPool = @import("InternPool.zig");11const InternPool = @import("InternPool.zig");
14const print_value = @import("print_value.zig");12const print_value = @import("print_value.zig");
...@@ -193,7 +191,7 @@ pub fn toBigIntAdvanced(...@@ -193,7 +191,7 @@ pub fn toBigIntAdvanced(
193 comptime strat: ResolveStrat,191 comptime strat: ResolveStrat,
194 zcu: *Zcu,192 zcu: *Zcu,
195 tid: strat.Tid(),193 tid: strat.Tid(),
196) Module.CompileError!BigIntConst {194) Zcu.CompileError!BigIntConst {
197 return switch (val.toIntern()) {195 return switch (val.toIntern()) {
198 .bool_false => BigIntMutable.init(&space.limbs, 0).toConst(),196 .bool_false => BigIntMutable.init(&space.limbs, 0).toConst(),
199 .bool_true => BigIntMutable.init(&space.limbs, 1).toConst(),197 .bool_true => BigIntMutable.init(&space.limbs, 1).toConst(),
...@@ -221,18 +219,18 @@ pub fn toBigIntAdvanced(...@@ -221,18 +219,18 @@ pub fn toBigIntAdvanced(
221 };219 };
222}220}
223221
224pub fn isFuncBody(val: Value, zcu: *Module) bool {222pub fn isFuncBody(val: Value, zcu: *Zcu) bool {
225 return zcu.intern_pool.isFuncBody(val.toIntern());223 return zcu.intern_pool.isFuncBody(val.toIntern());
226}224}
227225
228pub fn getFunction(val: Value, zcu: *Module) ?InternPool.Key.Func {226pub fn getFunction(val: Value, zcu: *Zcu) ?InternPool.Key.Func {
229 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {227 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
230 .func => |x| x,228 .func => |x| x,
231 else => null,229 else => null,
232 };230 };
233}231}
234232
235pub fn getVariable(val: Value, mod: *Module) ?InternPool.Key.Variable {233pub fn getVariable(val: Value, mod: *Zcu) ?InternPool.Key.Variable {
236 return switch (mod.intern_pool.indexToKey(val.toIntern())) {234 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
237 .variable => |variable| variable,235 .variable => |variable| variable,
238 else => null,236 else => null,
...@@ -1036,7 +1034,7 @@ pub fn floatCast(val: Value, dest_ty: Type, pt: Zcu.PerThread) !Value {...@@ -1036,7 +1034,7 @@ pub fn floatCast(val: Value, dest_ty: Type, pt: Zcu.PerThread) !Value {
1036}1034}
10371035
1038/// Asserts the value is a float1036/// Asserts the value is a float
1039pub fn floatHasFraction(self: Value, zcu: *const Module) bool {1037pub fn floatHasFraction(self: Value, zcu: *const Zcu) bool {
1040 return switch (zcu.intern_pool.indexToKey(self.toIntern())) {1038 return switch (zcu.intern_pool.indexToKey(self.toIntern())) {
1041 .float => |float| switch (float.storage) {1039 .float => |float| switch (float.storage) {
1042 inline else => |x| @rem(x, 1) != 0,1040 inline else => |x| @rem(x, 1) != 0,
...@@ -1058,7 +1056,7 @@ pub fn orderAgainstZeroInner(...@@ -1058,7 +1056,7 @@ pub fn orderAgainstZeroInner(
1058 comptime strat: ResolveStrat,1056 comptime strat: ResolveStrat,
1059 zcu: *Zcu,1057 zcu: *Zcu,
1060 tid: strat.Tid(),1058 tid: strat.Tid(),
1061) Module.CompileError!std.math.Order {1059) Zcu.CompileError!std.math.Order {
1062 return switch (lhs.toIntern()) {1060 return switch (lhs.toIntern()) {
1063 .bool_false => .eq,1061 .bool_false => .eq,
1064 .bool_true => .gt,1062 .bool_true => .gt,
...@@ -1218,7 +1216,7 @@ pub fn compareAllWithZeroSema(...@@ -1218,7 +1216,7 @@ pub fn compareAllWithZeroSema(
1218 lhs: Value,1216 lhs: Value,
1219 op: std.math.CompareOperator,1217 op: std.math.CompareOperator,
1220 pt: Zcu.PerThread,1218 pt: Zcu.PerThread,
1221) Module.CompileError!bool {1219) Zcu.CompileError!bool {
1222 return compareAllWithZeroAdvancedExtra(lhs, op, .sema, pt.zcu, pt.tid);1220 return compareAllWithZeroAdvancedExtra(lhs, op, .sema, pt.zcu, pt.tid);
1223}1221}
12241222
...@@ -1228,7 +1226,7 @@ pub fn compareAllWithZeroAdvancedExtra(...@@ -1228,7 +1226,7 @@ pub fn compareAllWithZeroAdvancedExtra(
1228 comptime strat: ResolveStrat,1226 comptime strat: ResolveStrat,
1229 zcu: *Zcu,1227 zcu: *Zcu,
1230 tid: strat.Tid(),1228 tid: strat.Tid(),
1231) Module.CompileError!bool {1229) Zcu.CompileError!bool {
1232 if (lhs.isInf(zcu)) {1230 if (lhs.isInf(zcu)) {
1233 switch (op) {1231 switch (op) {
1234 .neq => return true,1232 .neq => return true,
...@@ -1257,7 +1255,7 @@ pub fn compareAllWithZeroAdvancedExtra(...@@ -1257,7 +1255,7 @@ pub fn compareAllWithZeroAdvancedExtra(
1257 return (try orderAgainstZeroInner(lhs, strat, zcu, tid)).compare(op);1255 return (try orderAgainstZeroInner(lhs, strat, zcu, tid)).compare(op);
1258}1256}
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 {
1261 assert(zcu.intern_pool.typeOf(a.toIntern()) == ty.toIntern());1259 assert(zcu.intern_pool.typeOf(a.toIntern()) == ty.toIntern());
1262 assert(zcu.intern_pool.typeOf(b.toIntern()) == ty.toIntern());1260 assert(zcu.intern_pool.typeOf(b.toIntern()) == ty.toIntern());
1263 return a.toIntern() == b.toIntern();1261 return a.toIntern() == b.toIntern();
...@@ -1311,7 +1309,7 @@ pub fn pointerNav(val: Value, zcu: *Zcu) ?InternPool.Nav.Index {...@@ -1311,7 +1309,7 @@ pub fn pointerNav(val: Value, zcu: *Zcu) ?InternPool.Nav.Index {
1311pub const slice_ptr_index = 0;1309pub const slice_ptr_index = 0;
1312pub const slice_len_index = 1;1310pub const slice_len_index = 1;
13131311
1314pub fn slicePtr(val: Value, zcu: *Module) Value {1312pub fn slicePtr(val: Value, zcu: *Zcu) Value {
1315 return Value.fromInterned(zcu.intern_pool.slicePtr(val.toIntern()));1313 return Value.fromInterned(zcu.intern_pool.slicePtr(val.toIntern()));
1316}1314}
13171315
...@@ -1346,14 +1344,14 @@ pub fn elemValue(val: Value, pt: Zcu.PerThread, index: usize) Allocator.Error!Va...@@ -1346,14 +1344,14 @@ pub fn elemValue(val: Value, pt: Zcu.PerThread, index: usize) Allocator.Error!Va
1346 }1344 }
1347}1345}
13481346
1349pub fn isLazyAlign(val: Value, zcu: *Module) bool {1347pub fn isLazyAlign(val: Value, zcu: *Zcu) bool {
1350 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {1348 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
1351 .int => |int| int.storage == .lazy_align,1349 .int => |int| int.storage == .lazy_align,
1352 else => false,1350 else => false,
1353 };1351 };
1354}1352}
13551353
1356pub fn isLazySize(val: Value, zcu: *Module) bool {1354pub fn isLazySize(val: Value, zcu: *Zcu) bool {
1357 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {1355 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
1358 .int => |int| int.storage == .lazy_size,1356 .int => |int| int.storage == .lazy_size,
1359 else => false,1357 else => false,
...@@ -1430,7 +1428,7 @@ pub fn fieldValue(val: Value, pt: Zcu.PerThread, index: usize) !Value {...@@ -1430,7 +1428,7 @@ pub fn fieldValue(val: Value, pt: Zcu.PerThread, index: usize) !Value {
1430 };1428 };
1431}1429}
14321430
1433pub fn unionTag(val: Value, zcu: *Module) ?Value {1431pub fn unionTag(val: Value, zcu: *Zcu) ?Value {
1434 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {1432 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
1435 .undef, .enum_tag => val,1433 .undef, .enum_tag => val,
1436 .un => |un| if (un.tag != .none) Value.fromInterned(un.tag) else return null,1434 .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 {...@@ -1438,27 +1436,27 @@ pub fn unionTag(val: Value, zcu: *Module) ?Value {
1438 };1436 };
1439}1437}
14401438
1441pub fn unionValue(val: Value, zcu: *Module) Value {1439pub fn unionValue(val: Value, zcu: *Zcu) Value {
1442 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {1440 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
1443 .un => |un| Value.fromInterned(un.val),1441 .un => |un| Value.fromInterned(un.val),
1444 else => unreachable,1442 else => unreachable,
1445 };1443 };
1446}1444}
14471445
1448pub fn isUndef(val: Value, zcu: *Module) bool {1446pub fn isUndef(val: Value, zcu: *Zcu) bool {
1449 return zcu.intern_pool.isUndef(val.toIntern());1447 return zcu.intern_pool.isUndef(val.toIntern());
1450}1448}
14511449
1452/// TODO: check for cases such as array that is not marked undef but all the element1450/// TODO: check for cases such as array that is not marked undef but all the element
1453/// values are marked undef, or struct that is not marked undef but all fields are marked1451/// values are marked undef, or struct that is not marked undef but all fields are marked
1454/// undef, etc.1452/// undef, etc.
1455pub fn isUndefDeep(val: Value, zcu: *Module) bool {1453pub fn isUndefDeep(val: Value, zcu: *Zcu) bool {
1456 return val.isUndef(zcu);1454 return val.isUndef(zcu);
1457}1455}
14581456
1459/// Asserts the value is not undefined and not unreachable.1457/// Asserts the value is not undefined and not unreachable.
1460/// C pointers with an integer value of 0 are also considered null.1458/// 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 {
1462 return switch (val.toIntern()) {1460 return switch (val.toIntern()) {
1463 .undef => unreachable,1461 .undef => unreachable,
1464 .unreachable_value => unreachable,1462 .unreachable_value => unreachable,
...@@ -1476,7 +1474,7 @@ pub fn isNull(val: Value, zcu: *Module) bool {...@@ -1476,7 +1474,7 @@ pub fn isNull(val: Value, zcu: *Module) bool {
1476}1474}
14771475
1478/// Valid only for error (union) types. Asserts the value is not undefined and not unreachable.1476/// 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 {
1480 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {1478 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
1481 .err => |err| err.name.toOptional(),1479 .err => |err| err.name.toOptional(),
1482 .error_union => |error_union| switch (error_union.val) {1480 .error_union => |error_union| switch (error_union.val) {
...@@ -1487,7 +1485,7 @@ pub fn getErrorName(val: Value, zcu: *const Module) InternPool.OptionalNullTermi...@@ -1487,7 +1485,7 @@ pub fn getErrorName(val: Value, zcu: *const Module) InternPool.OptionalNullTermi
1487 };1485 };
1488}1486}
14891487
1490pub fn getErrorInt(val: Value, zcu: *Zcu) Module.ErrorInt {1488pub fn getErrorInt(val: Value, zcu: *Zcu) Zcu.ErrorInt {
1491 return if (getErrorName(val, zcu).unwrap()) |err_name|1489 return if (getErrorName(val, zcu).unwrap()) |err_name|
1492 zcu.intern_pool.getErrorValueIfExists(err_name).?1490 zcu.intern_pool.getErrorValueIfExists(err_name).?
1493 else1491 else
...@@ -1496,12 +1494,12 @@ pub fn getErrorInt(val: Value, zcu: *Zcu) Module.ErrorInt {...@@ -1496,12 +1494,12 @@ pub fn getErrorInt(val: Value, zcu: *Zcu) Module.ErrorInt {
14961494
1497/// Assumes the type is an error union. Returns true if and only if the value is1495/// Assumes the type is an error union. Returns true if and only if the value is
1498/// the error union payload, not an error.1496/// 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 {
1500 return zcu.intern_pool.indexToKey(val.toIntern()).error_union.val == .payload;1498 return zcu.intern_pool.indexToKey(val.toIntern()).error_union.val == .payload;
1501}1499}
15021500
1503/// Value of the optional, null if optional has no payload.1501/// 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 {
1505 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {1503 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
1506 .opt => |opt| switch (opt.val) {1504 .opt => |opt| switch (opt.val) {
1507 .none => null,1505 .none => null,
...@@ -1513,7 +1511,7 @@ pub fn optionalValue(val: Value, zcu: *const Module) ?Value {...@@ -1513,7 +1511,7 @@ pub fn optionalValue(val: Value, zcu: *const Module) ?Value {
1513}1511}
15141512
1515/// Valid for all types. Asserts the value is not undefined.1513/// 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 {
1517 return switch (self.toIntern()) {1515 return switch (self.toIntern()) {
1518 .undef => unreachable,1516 .undef => unreachable,
1519 else => switch (zcu.intern_pool.indexToKey(self.toIntern())) {1517 else => switch (zcu.intern_pool.indexToKey(self.toIntern())) {
...@@ -1524,7 +1522,7 @@ pub fn isFloat(self: Value, zcu: *const Module) bool {...@@ -1524,7 +1522,7 @@ pub fn isFloat(self: Value, zcu: *const Module) bool {
1524 };1522 };
1525}1523}
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 {
1528 return floatFromIntAdvanced(val, arena, int_ty, float_ty, zcu, .normal) catch |err| switch (err) {1526 return floatFromIntAdvanced(val, arena, int_ty, float_ty, zcu, .normal) catch |err| switch (err) {
1529 error.OutOfMemory => return error.OutOfMemory,1527 error.OutOfMemory => return error.OutOfMemory,
1530 else => unreachable,1528 else => unreachable,
...@@ -2320,7 +2318,7 @@ pub fn intModScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt:...@@ -2320,7 +2318,7 @@ pub fn intModScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt:
2320}2318}
23212319
2322/// Returns true if the value is a floating point type and is NaN. Returns false otherwise.2320/// 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 {
2324 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {2322 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
2325 .float => |float| switch (float.storage) {2323 .float => |float| switch (float.storage) {
2326 inline else => |x| std.math.isNan(x),2324 inline else => |x| std.math.isNan(x),
...@@ -2330,7 +2328,7 @@ pub fn isNan(val: Value, zcu: *const Module) bool {...@@ -2330,7 +2328,7 @@ pub fn isNan(val: Value, zcu: *const Module) bool {
2330}2328}
23312329
2332/// Returns true if the value is a floating point type and is infinite. Returns false otherwise.2330/// 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 {
2334 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {2332 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
2335 .float => |float| switch (float.storage) {2333 .float => |float| switch (float.storage) {
2336 inline else => |x| std.math.isInf(x),2334 inline else => |x| std.math.isInf(x),
...@@ -2339,7 +2337,7 @@ pub fn isInf(val: Value, zcu: *const Module) bool {...@@ -2339,7 +2337,7 @@ pub fn isInf(val: Value, zcu: *const Module) bool {
2339 };2337 };
2340}2338}
23412339
2342pub fn isNegativeInf(val: Value, zcu: *const Module) bool {2340pub fn isNegativeInf(val: Value, zcu: *const Zcu) bool {
2343 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {2341 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
2344 .float => |float| switch (float.storage) {2342 .float => |float| switch (float.storage) {
2345 inline else => |x| std.math.isNegativeInf(x),2343 inline else => |x| std.math.isNegativeInf(x),