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