| ... | ... | @@ -47,8 +47,6 @@ pub const Type = struct { |
| 47 | 47 | .inferred_alloc_mut, |
| 48 | 48 | => return .Pointer, |
| 49 | 49 | |
| 50 | | .optional => return .Optional, |
| 51 | | |
| 52 | 50 | .error_union => return .ErrorUnion, |
| 53 | 51 | }, |
| 54 | 52 | else => return switch (mod.intern_pool.indexToKey(ty.ip_index)) { |
| ... | ... | @@ -283,10 +281,6 @@ pub const Type = struct { |
| 283 | 281 | return switch (ty.ip_index) { |
| 284 | 282 | .none => switch (ty.tag()) { |
| 285 | 283 | .pointer => ty.castTag(.pointer).?.data, |
| 286 | | .optional => b: { |
| 287 | | const child_type = ty.optionalChild(mod); |
| 288 | | break :b child_type.ptrInfo(mod); |
| 289 | | }, |
| 290 | 284 | |
| 291 | 285 | else => unreachable, |
| 292 | 286 | }, |
| ... | ... | @@ -387,12 +381,6 @@ pub const Type = struct { |
| 387 | 381 | return true; |
| 388 | 382 | }, |
| 389 | 383 | |
| 390 | | .optional => { |
| 391 | | if (b.zigTypeTag(mod) != .Optional) return false; |
| 392 | | |
| 393 | | return a.optionalChild(mod).eql(b.optionalChild(mod), mod); |
| 394 | | }, |
| 395 | | |
| 396 | 384 | .error_union => { |
| 397 | 385 | if (b.zigTypeTag(mod) != .ErrorUnion) return false; |
| 398 | 386 | |
| ... | ... | @@ -466,12 +454,6 @@ pub const Type = struct { |
| 466 | 454 | std.hash.autoHash(hasher, info.size); |
| 467 | 455 | }, |
| 468 | 456 | |
| 469 | | .optional => { |
| 470 | | std.hash.autoHash(hasher, std.builtin.TypeId.Optional); |
| 471 | | |
| 472 | | hashWithHasher(ty.optionalChild(mod), hasher, mod); |
| 473 | | }, |
| 474 | | |
| 475 | 457 | .error_union => { |
| 476 | 458 | std.hash.autoHash(hasher, std.builtin.TypeId.ErrorUnion); |
| 477 | 459 | |
| ... | ... | @@ -530,19 +512,6 @@ pub const Type = struct { |
| 530 | 512 | .inferred_alloc_mut, |
| 531 | 513 | => unreachable, |
| 532 | 514 | |
| 533 | | .optional => { |
| 534 | | const payload = self.cast(Payload.ElemType).?; |
| 535 | | const new_payload = try allocator.create(Payload.ElemType); |
| 536 | | new_payload.* = .{ |
| 537 | | .base = .{ .tag = payload.base.tag }, |
| 538 | | .data = try payload.data.copy(allocator), |
| 539 | | }; |
| 540 | | return Type{ |
| 541 | | .ip_index = .none, |
| 542 | | .legacy = .{ .ptr_otherwise = &new_payload.base }, |
| 543 | | }; |
| 544 | | }, |
| 545 | | |
| 546 | 515 | .pointer => { |
| 547 | 516 | const payload = self.castTag(.pointer).?.data; |
| 548 | 517 | const sent: ?Value = if (payload.sentinel) |some| |
| ... | ... | @@ -654,13 +623,6 @@ pub const Type = struct { |
| 654 | 623 | while (true) { |
| 655 | 624 | const t = ty.tag(); |
| 656 | 625 | switch (t) { |
| 657 | | .optional => { |
| 658 | | const child_type = ty.castTag(.optional).?.data; |
| 659 | | try writer.writeByte('?'); |
| 660 | | ty = child_type; |
| 661 | | continue; |
| 662 | | }, |
| 663 | | |
| 664 | 626 | .pointer => { |
| 665 | 627 | const payload = ty.castTag(.pointer).?.data; |
| 666 | 628 | if (payload.sentinel) |some| switch (payload.size) { |
| ... | ... | @@ -813,11 +775,6 @@ pub const Type = struct { |
| 813 | 775 | try print(info.pointee_type, writer, mod); |
| 814 | 776 | }, |
| 815 | 777 | |
| 816 | | .optional => { |
| 817 | | const child_type = ty.castTag(.optional).?.data; |
| 818 | | try writer.writeByte('?'); |
| 819 | | try print(child_type, writer, mod); |
| 820 | | }, |
| 821 | 778 | .error_set => { |
| 822 | 779 | const names = ty.castTag(.error_set).?.data.names.keys(); |
| 823 | 780 | try writer.writeAll("error{"); |
| ... | ... | @@ -911,8 +868,7 @@ pub const Type = struct { |
| 911 | 868 | }, |
| 912 | 869 | .opt_type => |child| { |
| 913 | 870 | try writer.writeByte('?'); |
| 914 | | try print(child.toType(), writer, mod); |
| 915 | | return; |
| 871 | return print(child.toType(), writer, mod); |
| 916 | 872 | }, |
| 917 | 873 | .error_union_type => |error_union_type| { |
| 918 | 874 | try print(error_union_type.error_set_type.toType(), writer, mod); |
| ... | ... | @@ -1090,21 +1046,6 @@ pub const Type = struct { |
| 1090 | 1046 | } |
| 1091 | 1047 | }, |
| 1092 | 1048 | |
| 1093 | | .optional => { |
| 1094 | | const child_ty = ty.optionalChild(mod); |
| 1095 | | if (child_ty.isNoReturn()) { |
| 1096 | | // Then the optional is comptime-known to be null. |
| 1097 | | return false; |
| 1098 | | } |
| 1099 | | if (ignore_comptime_only) { |
| 1100 | | return true; |
| 1101 | | } else if (strat == .sema) { |
| 1102 | | return !(try strat.sema.typeRequiresComptime(child_ty)); |
| 1103 | | } else { |
| 1104 | | return !comptimeOnly(child_ty, mod); |
| 1105 | | } |
| 1106 | | }, |
| 1107 | | |
| 1108 | 1049 | .inferred_alloc_const => unreachable, |
| 1109 | 1050 | .inferred_alloc_mut => unreachable, |
| 1110 | 1051 | }, |
| ... | ... | @@ -1301,8 +1242,6 @@ pub const Type = struct { |
| 1301 | 1242 | |
| 1302 | 1243 | .inferred_alloc_mut => unreachable, |
| 1303 | 1244 | .inferred_alloc_const => unreachable, |
| 1304 | | |
| 1305 | | .optional => ty.isPtrLikeOptional(mod), |
| 1306 | 1245 | }, |
| 1307 | 1246 | else => switch (mod.intern_pool.indexToKey(ty.ip_index)) { |
| 1308 | 1247 | .int_type, |
| ... | ... | @@ -1319,7 +1258,7 @@ pub const Type = struct { |
| 1319 | 1258 | => false, |
| 1320 | 1259 | |
| 1321 | 1260 | .array_type => |array_type| array_type.child.toType().hasWellDefinedLayout(mod), |
| 1322 | | .opt_type => |child| child.toType().isPtrLikeOptional(mod), |
| 1261 | .opt_type => ty.isPtrLikeOptional(mod), |
| 1323 | 1262 | |
| 1324 | 1263 | .simple_type => |t| switch (t) { |
| 1325 | 1264 | .f16, |
| ... | ... | @@ -1484,7 +1423,6 @@ pub const Type = struct { |
| 1484 | 1423 | return (ptr_info.pointee_type.abiAlignmentAdvanced(mod, .eager) catch unreachable).scalar; |
| 1485 | 1424 | } |
| 1486 | 1425 | }, |
| 1487 | | .optional => return ty.castTag(.optional).?.data.ptrAlignmentAdvanced(mod, opt_sema), |
| 1488 | 1426 | |
| 1489 | 1427 | else => unreachable, |
| 1490 | 1428 | }, |
| ... | ... | @@ -1510,11 +1448,6 @@ pub const Type = struct { |
| 1510 | 1448 | .none => switch (ty.tag()) { |
| 1511 | 1449 | .pointer => ty.castTag(.pointer).?.data.@"addrspace", |
| 1512 | 1450 | |
| 1513 | | .optional => { |
| 1514 | | const child_type = ty.optionalChild(mod); |
| 1515 | | return child_type.ptrAddressSpace(mod); |
| 1516 | | }, |
| 1517 | | |
| 1518 | 1451 | else => unreachable, |
| 1519 | 1452 | }, |
| 1520 | 1453 | else => switch (mod.intern_pool.indexToKey(ty.ip_index)) { |
| ... | ... | @@ -1580,7 +1513,6 @@ pub const Type = struct { |
| 1580 | 1513 | .error_set_merged, |
| 1581 | 1514 | => return AbiAlignmentAdvanced{ .scalar = 2 }, |
| 1582 | 1515 | |
| 1583 | | .optional => return abiAlignmentAdvancedOptional(ty, mod, strat), |
| 1584 | 1516 | .error_union => return abiAlignmentAdvancedErrorUnion(ty, mod, strat), |
| 1585 | 1517 | |
| 1586 | 1518 | .inferred_alloc_const, |
| ... | ... | @@ -1962,8 +1894,6 @@ pub const Type = struct { |
| 1962 | 1894 | .error_set_single, |
| 1963 | 1895 | => return AbiSizeAdvanced{ .scalar = 2 }, |
| 1964 | 1896 | |
| 1965 | | .optional => return ty.abiSizeAdvancedOptional(mod, strat), |
| 1966 | | |
| 1967 | 1897 | .error_union => { |
| 1968 | 1898 | // This code needs to be kept in sync with the equivalent switch prong |
| 1969 | 1899 | // in abiAlignmentAdvanced. |
| ... | ... | @@ -2282,7 +2212,7 @@ pub const Type = struct { |
| 2282 | 2212 | .error_set_merged, |
| 2283 | 2213 | => return 16, // TODO revisit this when we have the concept of the error tag type |
| 2284 | 2214 | |
| 2285 | | .optional, .error_union => { |
| 2215 | .error_union => { |
| 2286 | 2216 | // Optionals and error unions are not packed so their bitsize |
| 2287 | 2217 | // includes padding bits. |
| 2288 | 2218 | return (try abiSizeAdvanced(ty, mod, strat)).scalar * 8; |
| ... | ... | @@ -2310,7 +2240,11 @@ pub const Type = struct { |
| 2310 | 2240 | const elem_bit_size = try bitSizeAdvanced(child_ty, mod, opt_sema); |
| 2311 | 2241 | return elem_bit_size * vector_type.len; |
| 2312 | 2242 | }, |
| 2313 | | .opt_type => @panic("TODO"), |
| 2243 | .opt_type => { |
| 2244 | // Optionals and error unions are not packed so their bitsize |
| 2245 | // includes padding bits. |
| 2246 | return (try abiSizeAdvanced(ty, mod, strat)).scalar * 8; |
| 2247 | }, |
| 2314 | 2248 | .error_union_type => @panic("TODO"), |
| 2315 | 2249 | .func_type => unreachable, // represents machine code; not a pointer |
| 2316 | 2250 | .simple_type => |t| switch (t) { |
| ... | ... | @@ -2499,7 +2433,6 @@ pub const Type = struct { |
| 2499 | 2433 | } |
| 2500 | 2434 | |
| 2501 | 2435 | pub const SlicePtrFieldTypeBuffer = union { |
| 2502 | | elem_type: Payload.ElemType, |
| 2503 | 2436 | pointer: Payload.Pointer, |
| 2504 | 2437 | }; |
| 2505 | 2438 | |
| ... | ... | @@ -2600,16 +2533,6 @@ pub const Type = struct { |
| 2600 | 2533 | .One, .Many, .C => return true, |
| 2601 | 2534 | }, |
| 2602 | 2535 | |
| 2603 | | .optional => { |
| 2604 | | const child_type = ty.optionalChild(mod); |
| 2605 | | if (child_type.zigTypeTag(mod) != .Pointer) return false; |
| 2606 | | const info = child_type.ptrInfo(mod); |
| 2607 | | switch (info.size) { |
| 2608 | | .Slice, .C => return false, |
| 2609 | | .Many, .One => return !info.@"allowzero", |
| 2610 | | } |
| 2611 | | }, |
| 2612 | | |
| 2613 | 2536 | else => return false, |
| 2614 | 2537 | }, |
| 2615 | 2538 | else => return switch (mod.intern_pool.indexToKey(ty.ip_index)) { |
| ... | ... | @@ -2655,21 +2578,6 @@ pub const Type = struct { |
| 2655 | 2578 | else => false, |
| 2656 | 2579 | }; |
| 2657 | 2580 | switch (ty.tag()) { |
| 2658 | | .optional => { |
| 2659 | | const child_ty = ty.castTag(.optional).?.data; |
| 2660 | | switch (child_ty.zigTypeTag(mod)) { |
| 2661 | | .Pointer => { |
| 2662 | | const info = child_ty.ptrInfo(mod); |
| 2663 | | switch (info.size) { |
| 2664 | | .C => return false, |
| 2665 | | .Slice, .Many, .One => return !info.@"allowzero", |
| 2666 | | } |
| 2667 | | }, |
| 2668 | | .ErrorSet => return true, |
| 2669 | | else => return false, |
| 2670 | | } |
| 2671 | | }, |
| 2672 | | |
| 2673 | 2581 | .pointer => return ty.castTag(.pointer).?.data.size == .C, |
| 2674 | 2582 | |
| 2675 | 2583 | else => return false, |
| ... | ... | @@ -2692,16 +2600,6 @@ pub const Type = struct { |
| 2692 | 2600 | else => false, |
| 2693 | 2601 | }; |
| 2694 | 2602 | switch (ty.tag()) { |
| 2695 | | .optional => { |
| 2696 | | const child_ty = ty.castTag(.optional).?.data; |
| 2697 | | if (child_ty.zigTypeTag(mod) != .Pointer) return false; |
| 2698 | | const info = child_ty.ptrInfo(mod); |
| 2699 | | switch (info.size) { |
| 2700 | | .Slice, .C => return false, |
| 2701 | | .Many, .One => return !info.@"allowzero", |
| 2702 | | } |
| 2703 | | }, |
| 2704 | | |
| 2705 | 2603 | .pointer => return ty.castTag(.pointer).?.data.size == .C, |
| 2706 | 2604 | |
| 2707 | 2605 | else => return false, |
| ... | ... | @@ -2747,7 +2645,6 @@ pub const Type = struct { |
| 2747 | 2645 | return child_ty; |
| 2748 | 2646 | } |
| 2749 | 2647 | }, |
| 2750 | | .optional => ty.castTag(.optional).?.data.childType(mod), |
| 2751 | 2648 | |
| 2752 | 2649 | else => unreachable, |
| 2753 | 2650 | }, |
| ... | ... | @@ -2784,13 +2681,10 @@ pub const Type = struct { |
| 2784 | 2681 | } |
| 2785 | 2682 | |
| 2786 | 2683 | /// Asserts that the type is an optional. |
| 2787 | | /// Resulting `Type` will have inner memory referencing `buf`. |
| 2788 | 2684 | /// Note that for C pointers this returns the type unmodified. |
| 2789 | 2685 | pub fn optionalChild(ty: Type, mod: *const Module) Type { |
| 2790 | 2686 | return switch (ty.ip_index) { |
| 2791 | 2687 | .none => switch (ty.tag()) { |
| 2792 | | .optional => ty.castTag(.optional).?.data, |
| 2793 | | |
| 2794 | 2688 | .pointer, // here we assume it is a C pointer |
| 2795 | 2689 | => return ty, |
| 2796 | 2690 | |
| ... | ... | @@ -3305,15 +3199,6 @@ pub const Type = struct { |
| 3305 | 3199 | .pointer, |
| 3306 | 3200 | => return null, |
| 3307 | 3201 | |
| 3308 | | .optional => { |
| 3309 | | const child_ty = ty.optionalChild(mod); |
| 3310 | | if (child_ty.isNoReturn()) { |
| 3311 | | return Value.null; |
| 3312 | | } else { |
| 3313 | | return null; |
| 3314 | | } |
| 3315 | | }, |
| 3316 | | |
| 3317 | 3202 | .inferred_alloc_const => unreachable, |
| 3318 | 3203 | .inferred_alloc_mut => unreachable, |
| 3319 | 3204 | }, |
| ... | ... | @@ -3524,10 +3409,6 @@ pub const Type = struct { |
| 3524 | 3409 | } |
| 3525 | 3410 | }, |
| 3526 | 3411 | |
| 3527 | | .optional => { |
| 3528 | | return ty.optionalChild(mod).comptimeOnly(mod); |
| 3529 | | }, |
| 3530 | | |
| 3531 | 3412 | .error_union => return ty.errorUnionPayload().comptimeOnly(mod), |
| 3532 | 3413 | }, |
| 3533 | 3414 | else => switch (mod.intern_pool.indexToKey(ty.ip_index)) { |
| ... | ... | @@ -4216,7 +4097,6 @@ pub const Type = struct { |
| 4216 | 4097 | // After this, the tag requires a payload. |
| 4217 | 4098 | |
| 4218 | 4099 | pointer, |
| 4219 | | optional, |
| 4220 | 4100 | error_union, |
| 4221 | 4101 | error_set, |
| 4222 | 4102 | error_set_single, |
| ... | ... | @@ -4233,8 +4113,6 @@ pub const Type = struct { |
| 4233 | 4113 | .inferred_alloc_mut, |
| 4234 | 4114 | => @compileError("Type Tag " ++ @tagName(t) ++ " has no payload"), |
| 4235 | 4115 | |
| 4236 | | .optional => Payload.ElemType, |
| 4237 | | |
| 4238 | 4116 | .error_set => Payload.ErrorSet, |
| 4239 | 4117 | .error_set_inferred => Payload.ErrorSetInferred, |
| 4240 | 4118 | .error_set_merged => Payload.ErrorSetMerged, |
| ... | ... | @@ -4326,11 +4204,6 @@ pub const Type = struct { |
| 4326 | 4204 | data: u64, |
| 4327 | 4205 | }; |
| 4328 | 4206 | |
| 4329 | | pub const ElemType = struct { |
| 4330 | | base: Payload, |
| 4331 | | data: Type, |
| 4332 | | }; |
| 4333 | | |
| 4334 | 4207 | pub const Bits = struct { |
| 4335 | 4208 | base: Payload, |
| 4336 | 4209 | data: u16, |
| ... | ... | @@ -4570,11 +4443,11 @@ pub const Type = struct { |
| 4570 | 4443 | } |
| 4571 | 4444 | |
| 4572 | 4445 | pub fn optional(arena: Allocator, child_type: Type, mod: *Module) Allocator.Error!Type { |
| 4573 | | if (child_type.ip_index != .none) { |
| 4574 | | return mod.optionalType(child_type.ip_index); |
| 4575 | | } else { |
| 4576 | | return Type.Tag.optional.create(arena, child_type); |
| 4577 | | } |
| 4446 | // TODO: update callsites of this function to directly call |
| 4447 | // mod.optionalType and then delete this function. |
| 4448 | _ = arena; |
| 4449 | |
| 4450 | return mod.optionalType(child_type.ip_index); |
| 4578 | 4451 | } |
| 4579 | 4452 | |
| 4580 | 4453 | pub fn errorUnion( |