authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-14 21:11:49-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-14 21:43:03-07:00
log2f92d1a0264b6827cb67a55726c4c9a082337508
treed6691a25a828b44cb4c17365fb8549d339046810
parent50a1ca24ca2a4311097132d660b8244f252da82f

stage2: fixups for topolarity-comptime-memory-reinterp branch

* don't store `has_well_defined_layout` in memory. * remove struct `hasWellDefinedLayout` logic. it's just `layout != .Auto`. This means we only need one implementation, in Type. * fix some of the cases being wrong in `hasWellDefinedLayout`, such as optional pointers. * move `tag_ty_inferred` field into a position that makes it more obvious how the struct layout will be done. Also we don't have a compiler that intelligently moves fields around so this layout is better. * Sema: don't `resolveTypeLayout` in `zirCoerceResultPtr` unless necessary. * Rename `ComptimePtrLoadKit` `target` field to `pointee` to avoid confusion with `target`.

8 files changed, 76 insertions(+), 271 deletions(-)

src/Module.zig+2-4
......@@ -885,7 +885,6 @@ pub const Struct = struct {
885885 /// one possible value.
886886 known_non_opv: bool,
887887 requires_comptime: PropertyBoolean = .unknown,
888 has_well_defined_layout: PropertyBoolean = .unknown,
889888
890889 pub const Fields = std.StringArrayHashMapUnmanaged(Field);
891890
......@@ -1080,8 +1079,6 @@ pub const EnumFull = struct {
10801079 /// An integer type which is used for the numerical value of the enum.
10811080 /// Whether zig chooses this type or the user specifies it, it is stored here.
10821081 tag_ty: Type,
1083 /// true if zig inferred this tag type, false if user specified it
1084 tag_ty_inferred: bool,
10851082 /// Set of field names in declaration order.
10861083 fields: NameMap,
10871084 /// Maps integer tag value to field index.
......@@ -1092,6 +1089,8 @@ pub const EnumFull = struct {
10921089 namespace: Namespace,
10931090 /// Offset from `owner_decl`, points to the enum decl AST node.
10941091 node_offset: i32,
1092 /// true if zig inferred this tag type, false if user specified it
1093 tag_ty_inferred: bool,
10951094
10961095 pub const NameMap = std.StringArrayHashMapUnmanaged(void);
10971096 pub const ValueMap = std.ArrayHashMapUnmanaged(Value, void, Value.ArrayHashContext, false);
......@@ -1136,7 +1135,6 @@ pub const Union = struct {
11361135 fully_resolved,
11371136 },
11381137 requires_comptime: PropertyBoolean = .unknown,
1139 has_well_defined_layout: PropertyBoolean = .unknown,
11401138
11411139 pub const Field = struct {
11421140 /// undefined until `status` is `have_field_types` or `have_layout`.
src/Sema.zig+30-205
......@@ -1579,8 +1579,6 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
15791579 const target = sema.mod.getTarget();
15801580 const addr_space = target_util.defaultAddressSpace(target, .local);
15811581
1582 try sema.resolveTypeLayout(block, src, pointee_ty);
1583
15841582 if (Air.refToIndex(ptr)) |ptr_inst| {
15851583 if (sema.air_instructions.items(.tag)[ptr_inst] == .constant) {
15861584 const air_datas = sema.air_instructions.items(.data);
......@@ -1617,6 +1615,9 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
16171615 try pointee_ty.copy(anon_decl.arena()),
16181616 Value.undef,
16191617 );
1618 if (iac.data.alignment != 0) {
1619 try sema.resolveTypeLayout(block, src, pointee_ty);
1620 }
16201621 const ptr_ty = try Type.ptr(sema.arena, target, .{
16211622 .pointee_type = pointee_ty,
16221623 .@"align" = iac.data.alignment,
......@@ -1886,7 +1887,7 @@ fn zirEnumDecl(
18861887
18871888 enum_obj.* = .{
18881889 .owner_decl = new_decl,
1889 .tag_ty = Type.initTag(.@"null"),
1890 .tag_ty = Type.@"null",
18901891 .tag_ty_inferred = true,
18911892 .fields = .{},
18921893 .values = .{},
......@@ -17867,13 +17868,13 @@ const TypedValueAndOffset = struct {
1786717868};
1786817869
1786917870const ComptimePtrLoadKit = struct {
17870 /// The Value and Type corresponding to the target of the provided pointer.
17871 /// The Value and Type corresponding to the pointee of the provided pointer.
1787117872 /// If a direct dereference is not possible, this is null.
17872 target: ?TypedValue,
17873 /// The largest parent Value containing `target` and having a well-defined memory layout.
17874 /// This is used for bitcasting, if direct dereferencing failed (i.e. `target` is null).
17873 pointee: ?TypedValue,
17874 /// The largest parent Value containing `pointee` and having a well-defined memory layout.
17875 /// This is used for bitcasting, if direct dereferencing failed (i.e. `pointee` is null).
1787517876 parent: ?TypedValueAndOffset,
17876 /// Whether the `target` could be mutated by further
17877 /// Whether the `pointee` could be mutated by further
1787717878 /// semantic analysis and a copy must be performed.
1787817879 is_mutable: bool,
1787917880 /// If the root decl could not be used as `parent`, this is the type that
......@@ -17885,7 +17886,7 @@ const ComptimePtrLoadError = CompileError || error{
1788517886 RuntimeLoad,
1788617887};
1788717888
17888/// If `maybe_array_ty` is provided, it will be used to directly dereference an
17889/// If `maybe_array_ty` is provided, it will be used to directly dereference an
1788917890/// .elem_ptr of type T to a value of [N]T, if necessary.
1789017891fn beginComptimePtrLoad(
1789117892 sema: *Sema,
......@@ -17908,10 +17909,10 @@ fn beginComptimePtrLoad(
1790817909 const decl_tv = try decl.typedValue();
1790917910 if (decl_tv.val.tag() == .variable) return error.RuntimeLoad;
1791017911
17911 const layout_defined = try sema.typeHasWellDefinedLayout(block, src, decl.ty);
17912 const layout_defined = decl.ty.hasWellDefinedLayout();
1791217913 break :blk ComptimePtrLoadKit{
1791317914 .parent = if (layout_defined) .{ .tv = decl_tv, .byte_offset = 0 } else null,
17914 .target = decl_tv,
17915 .pointee = decl_tv,
1791517916 .is_mutable = is_mutable,
1791617917 .ty_without_well_defined_layout = if (!layout_defined) decl.ty else null,
1791717918 };
......@@ -17923,7 +17924,7 @@ fn beginComptimePtrLoad(
1792317924 var deref = try beginComptimePtrLoad(sema, block, src, elem_ptr.array_ptr, null);
1792417925
1792517926 if (elem_ptr.index != 0) {
17926 if (try sema.typeHasWellDefinedLayout(block, src, elem_ty)) {
17927 if (elem_ty.hasWellDefinedLayout()) {
1792717928 if (deref.parent) |*parent| {
1792817929 // Update the byte offset (in-place)
1792917930 const elem_size = try sema.typeAbiSize(block, src, elem_ty);
......@@ -17938,17 +17939,17 @@ fn beginComptimePtrLoad(
1793817939
1793917940 // If we're loading an elem_ptr that was derived from a different type
1794017941 // than the true type of the underlying decl, we cannot deref directly
17941 const ty_matches = if (deref.target != null and deref.target.?.ty.isArrayLike()) x: {
17942 const deref_elem_ty = deref.target.?.ty.childType();
17942 const ty_matches = if (deref.pointee != null and deref.pointee.?.ty.isArrayLike()) x: {
17943 const deref_elem_ty = deref.pointee.?.ty.childType();
1794317944 break :x (try sema.coerceInMemoryAllowed(block, deref_elem_ty, elem_ty, false, target, src, src)) == .ok or
1794417945 (try sema.coerceInMemoryAllowed(block, elem_ty, deref_elem_ty, false, target, src, src)) == .ok;
1794517946 } else false;
1794617947 if (!ty_matches) {
17947 deref.target = null;
17948 deref.pointee = null;
1794817949 break :blk deref;
1794917950 }
1795017951
17951 var array_tv = deref.target.?;
17952 var array_tv = deref.pointee.?;
1795217953 const check_len = array_tv.ty.arrayLenIncludingSentinel();
1795317954 if (elem_ptr.index >= check_len) {
1795417955 // TODO have the deref include the decl so we can say "declared here"
......@@ -17959,10 +17960,10 @@ fn beginComptimePtrLoad(
1795917960
1796017961 if (maybe_array_ty) |load_ty| {
1796117962 // It's possible that we're loading a [N]T, in which case we'd like to slice
17962 // the target array directly from our parent array.
17963 // the pointee array directly from our parent array.
1796317964 if (load_ty.isArrayLike() and load_ty.childType().eql(elem_ty)) {
1796417965 const N = try sema.usizeCast(block, src, load_ty.arrayLenIncludingSentinel());
17965 deref.target = if (elem_ptr.index + N <= check_len) TypedValue{
17966 deref.pointee = if (elem_ptr.index + N <= check_len) TypedValue{
1796617967 .ty = try Type.array(sema.arena, N, null, elem_ty),
1796717968 .val = try array_tv.val.sliceArray(sema.arena, elem_ptr.index, elem_ptr.index + N),
1796817969 } else null;
......@@ -17970,7 +17971,7 @@ fn beginComptimePtrLoad(
1797017971 }
1797117972 }
1797217973
17973 deref.target = .{
17974 deref.pointee = .{
1797417975 .ty = elem_ty,
1797517976 .val = try array_tv.val.elemValue(sema.arena, elem_ptr.index),
1797617977 };
......@@ -17983,7 +17984,7 @@ fn beginComptimePtrLoad(
1798317984 const field_ty = field_ptr.container_ty.structFieldType(field_index);
1798417985 var deref = try beginComptimePtrLoad(sema, block, src, field_ptr.container_ptr, field_ptr.container_ty);
1798517986
17986 if (try sema.typeHasWellDefinedLayout(block, src, field_ptr.container_ty)) {
17987 if (field_ptr.container_ty.hasWellDefinedLayout()) {
1798717988 if (deref.parent) |*parent| {
1798817989 // Update the byte offset (in-place)
1798917990 try sema.resolveTypeLayout(block, src, field_ptr.container_ty);
......@@ -17995,19 +17996,19 @@ fn beginComptimePtrLoad(
1799517996 deref.ty_without_well_defined_layout = field_ptr.container_ty;
1799617997 }
1799717998
17998 if (deref.target) |*tv| {
17999 if (deref.pointee) |*tv| {
1799918000 const coerce_in_mem_ok =
1800018001 (try sema.coerceInMemoryAllowed(block, field_ptr.container_ty, tv.ty, false, target, src, src)) == .ok or
1800118002 (try sema.coerceInMemoryAllowed(block, tv.ty, field_ptr.container_ty, false, target, src, src)) == .ok;
1800218003 if (coerce_in_mem_ok) {
18003 deref.target = TypedValue{
18004 deref.pointee = TypedValue{
1800418005 .ty = field_ty,
1800518006 .val = try tv.val.fieldValue(sema.arena, field_index),
1800618007 };
1800718008 break :blk deref;
1800818009 }
1800918010 }
18010 deref.target = null;
18011 deref.pointee = null;
1801118012 break :blk deref;
1801218013 },
1801318014
......@@ -18028,7 +18029,7 @@ fn beginComptimePtrLoad(
1802818029 deref.ty_without_well_defined_layout = payload_ptr.container_ty;
1802918030 }
1803018031
18031 if (deref.target) |*tv| {
18032 if (deref.pointee) |*tv| {
1803218033 const coerce_in_mem_ok =
1803318034 (try sema.coerceInMemoryAllowed(block, payload_ptr.container_ty, tv.ty, false, target, src, src)) == .ok or
1803418035 (try sema.coerceInMemoryAllowed(block, tv.ty, payload_ptr.container_ty, false, target, src, src)) == .ok;
......@@ -18042,7 +18043,7 @@ fn beginComptimePtrLoad(
1804218043 break :blk deref;
1804318044 }
1804418045 }
18045 deref.target = null;
18046 deref.pointee = null;
1804618047 break :blk deref;
1804718048 },
1804818049
......@@ -18060,7 +18061,7 @@ fn beginComptimePtrLoad(
1806018061 else => unreachable,
1806118062 };
1806218063
18063 if (deref.target) |tv| {
18064 if (deref.pointee) |tv| {
1806418065 if (deref.parent == null and tv.ty.hasWellDefinedLayout()) {
1806518066 deref.parent = .{ .tv = tv, .byte_offset = 0 };
1806618067 }
......@@ -21157,7 +21158,7 @@ fn pointerDeref(sema: *Sema, block: *Block, src: LazySrcLoc, ptr_val: Value, ptr
2115721158 else => |e| return e,
2115821159 };
2115921160
21160 if (deref.target) |tv| {
21161 if (deref.pointee) |tv| {
2116121162 const coerce_in_mem_ok =
2116221163 (try sema.coerceInMemoryAllowed(block, load_ty, tv.ty, false, target, src, src)) == .ok or
2116321164 (try sema.coerceInMemoryAllowed(block, tv.ty, load_ty, false, target, src, src)) == .ok;
......@@ -21176,13 +21177,13 @@ fn pointerDeref(sema: *Sema, block: *Block, src: LazySrcLoc, ptr_val: Value, ptr
2117621177
2117721178 // The type is not in-memory coercible or the direct dereference failed, so it must
2117821179 // be bitcast according to the pointer type we are performing the load through.
21179 if (!(try sema.typeHasWellDefinedLayout(block, src, load_ty)))
21180 if (!load_ty.hasWellDefinedLayout())
2118021181 return sema.fail(block, src, "comptime dereference requires {} to have a well-defined layout, but it does not.", .{load_ty});
2118121182
2118221183 const load_sz = try sema.typeAbiSize(block, src, load_ty);
2118321184
2118421185 // Try the smaller bit-cast first, since that's more efficient than using the larger `parent`
21185 if (deref.target) |tv| if (load_sz <= try sema.typeAbiSize(block, src, tv.ty))
21186 if (deref.pointee) |tv| if (load_sz <= try sema.typeAbiSize(block, src, tv.ty))
2118621187 return try sema.bitCastVal(block, src, tv.val, tv.ty, load_ty, 0);
2118721188
2118821189 // If that fails, try to bit-cast from the largest parent value with a well-defined layout
......@@ -21271,182 +21272,6 @@ fn typePtrOrOptionalPtrTy(
2127121272 }
2127221273}
2127321274
21274fn typeHasWellDefinedLayout(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!bool {
21275 return switch (ty.tag()) {
21276 .u1,
21277 .u8,
21278 .i8,
21279 .u16,
21280 .i16,
21281 .u32,
21282 .i32,
21283 .u64,
21284 .i64,
21285 .u128,
21286 .i128,
21287 .usize,
21288 .isize,
21289 .c_short,
21290 .c_ushort,
21291 .c_int,
21292 .c_uint,
21293 .c_long,
21294 .c_ulong,
21295 .c_longlong,
21296 .c_ulonglong,
21297 .c_longdouble,
21298 .f16,
21299 .f32,
21300 .f64,
21301 .f80,
21302 .f128,
21303 .bool,
21304 .void,
21305 .manyptr_u8,
21306 .manyptr_const_u8,
21307 .manyptr_const_u8_sentinel_0,
21308 .anyerror_void_error_union,
21309 .empty_struct_literal,
21310 .empty_struct,
21311 .array_u8,
21312 .array_u8_sentinel_0,
21313 .int_signed,
21314 .int_unsigned,
21315 .pointer,
21316 .single_const_pointer,
21317 .single_mut_pointer,
21318 .many_const_pointer,
21319 .many_mut_pointer,
21320 .c_const_pointer,
21321 .c_mut_pointer,
21322 .single_const_pointer_to_comptime_int,
21323 .enum_numbered,
21324 => true,
21325
21326 .anyopaque,
21327 .anyerror,
21328 .noreturn,
21329 .@"null",
21330 .@"anyframe",
21331 .@"undefined",
21332 .atomic_order,
21333 .atomic_rmw_op,
21334 .calling_convention,
21335 .address_space,
21336 .float_mode,
21337 .reduce_op,
21338 .call_options,
21339 .prefetch_options,
21340 .export_options,
21341 .extern_options,
21342 .error_set,
21343 .error_set_single,
21344 .error_set_inferred,
21345 .error_set_merged,
21346 .@"opaque",
21347 .generic_poison,
21348 .type,
21349 .comptime_int,
21350 .comptime_float,
21351 .enum_literal,
21352 .type_info,
21353 // These are function bodies, not function pointers.
21354 .fn_noreturn_no_args,
21355 .fn_void_no_args,
21356 .fn_naked_noreturn_no_args,
21357 .fn_ccc_void_no_args,
21358 .function,
21359 .const_slice_u8,
21360 .const_slice_u8_sentinel_0,
21361 .const_slice,
21362 .mut_slice,
21363 .enum_simple,
21364 .error_union,
21365 .anyframe_T,
21366 .tuple,
21367 .anon_struct,
21368 => false,
21369
21370 .enum_full,
21371 .enum_nonexhaustive,
21372 => !ty.cast(Type.Payload.EnumFull).?.data.tag_ty_inferred,
21373
21374 .var_args_param => unreachable,
21375 .inferred_alloc_mut => unreachable,
21376 .inferred_alloc_const => unreachable,
21377 .bound_fn => unreachable,
21378
21379 .array,
21380 .array_sentinel,
21381 .vector,
21382 => sema.typeHasWellDefinedLayout(block, src, ty.childType()),
21383
21384 .optional,
21385 .optional_single_mut_pointer,
21386 .optional_single_const_pointer,
21387 => blk: {
21388 var buf: Type.Payload.ElemType = undefined;
21389 break :blk sema.typeHasWellDefinedLayout(block, src, ty.optionalChild(&buf));
21390 },
21391
21392 .@"struct" => {
21393 const struct_obj = ty.castTag(.@"struct").?.data;
21394 if (struct_obj.layout == .Auto) {
21395 struct_obj.has_well_defined_layout = .no;
21396 return false;
21397 }
21398 switch (struct_obj.has_well_defined_layout) {
21399 .no => return false,
21400 .yes, .wip => return true,
21401 .unknown => {
21402 if (struct_obj.status == .field_types_wip)
21403 return true;
21404
21405 try sema.resolveTypeFieldsStruct(block, src, ty, struct_obj);
21406
21407 struct_obj.has_well_defined_layout = .wip;
21408 for (struct_obj.fields.values()) |field| {
21409 if (!(try sema.typeHasWellDefinedLayout(block, src, field.ty))) {
21410 struct_obj.has_well_defined_layout = .no;
21411 return false;
21412 }
21413 }
21414 struct_obj.has_well_defined_layout = .yes;
21415 return true;
21416 },
21417 }
21418 },
21419
21420 .@"union", .union_tagged => {
21421 const union_obj = ty.cast(Type.Payload.Union).?.data;
21422 if (union_obj.layout == .Auto) {
21423 union_obj.has_well_defined_layout = .no;
21424 return false;
21425 }
21426 switch (union_obj.has_well_defined_layout) {
21427 .no => return false,
21428 .yes, .wip => return true,
21429 .unknown => {
21430 if (union_obj.status == .field_types_wip)
21431 return true;
21432
21433 try sema.resolveTypeFieldsUnion(block, src, ty, union_obj);
21434
21435 union_obj.has_well_defined_layout = .wip;
21436 for (union_obj.fields.values()) |field| {
21437 if (!(try sema.typeHasWellDefinedLayout(block, src, field.ty))) {
21438 union_obj.has_well_defined_layout = .no;
21439 return false;
21440 }
21441 }
21442 union_obj.has_well_defined_layout = .yes;
21443 return true;
21444 },
21445 }
21446 },
21447 };
21448}
21449
2145021275/// `generic_poison` will return false.
2145121276/// This function returns false negatives when structs and unions are having their
2145221277/// field types resolved.
src/codegen/llvm.zig+4-1
......@@ -2829,7 +2829,10 @@ pub const DeclGen = struct {
28292829 // (void) payload is the same.
28302830 break :blk parent_llvm_ptr;
28312831 }
2832 const llvm_pl_index = if (layout.tag_size == 0) 0 else @boolToInt(layout.tag_align >= layout.payload_align);
2832 const llvm_pl_index = if (layout.tag_size == 0)
2833 0
2834 else
2835 @boolToInt(layout.tag_align >= layout.payload_align);
28332836 const indices: [2]*const llvm.Value = .{
28342837 llvm_u32.constInt(0, .False),
28352838 llvm_u32.constInt(llvm_pl_index, .False),
src/type.zig+15-36
......@@ -2210,9 +2210,6 @@ pub const Type = extern union {
22102210 .manyptr_u8,
22112211 .manyptr_const_u8,
22122212 .manyptr_const_u8_sentinel_0,
2213 .anyerror_void_error_union,
2214 .empty_struct_literal,
2215 .empty_struct,
22162213 .array_u8,
22172214 .array_u8_sentinel_0,
22182215 .int_signed,
......@@ -2226,6 +2223,9 @@ pub const Type = extern union {
22262223 .c_mut_pointer,
22272224 .single_const_pointer_to_comptime_int,
22282225 .enum_numbered,
2226 .vector,
2227 .optional_single_mut_pointer,
2228 .optional_single_const_pointer,
22292229 => true,
22302230
22312231 .anyopaque,
......@@ -2267,9 +2267,12 @@ pub const Type = extern union {
22672267 .mut_slice,
22682268 .enum_simple,
22692269 .error_union,
2270 .anyerror_void_error_union,
22702271 .anyframe_T,
22712272 .tuple,
22722273 .anon_struct,
2274 .empty_struct_literal,
2275 .empty_struct,
22732276 => false,
22742277
22752278 .enum_full,
......@@ -2283,36 +2286,12 @@ pub const Type = extern union {
22832286
22842287 .array,
22852288 .array_sentinel,
2286 .vector,
22872289 => ty.childType().hasWellDefinedLayout(),
22882290
2289 .optional,
2290 .optional_single_mut_pointer,
2291 .optional_single_const_pointer,
2292 => {
2293 var buf: Type.Payload.ElemType = undefined;
2294 return ty.optionalChild(&buf).hasWellDefinedLayout();
2295 },
2296
2297 .@"struct" => {
2298 const struct_obj = ty.castTag(.@"struct").?.data;
2299 if (struct_obj.layout == .Auto) return false;
2300 switch (struct_obj.has_well_defined_layout) {
2301 .wip, .unknown => unreachable, // This function asserts types already resolved.
2302 .no => return false,
2303 .yes => return true,
2304 }
2305 },
2306
2307 .@"union", .union_tagged => {
2308 const union_obj = ty.cast(Type.Payload.Union).?.data;
2309 if (union_obj.layout == .Auto) return false;
2310 switch (union_obj.has_well_defined_layout) {
2311 .wip, .unknown => unreachable, // This function asserts types already resolved.
2312 .no => return false,
2313 .yes => return true,
2314 }
2315 },
2291 .optional => ty.isPtrLikeOptional(),
2292 .@"struct" => ty.castTag(.@"struct").?.data.layout != .Auto,
2293 .@"union" => ty.castTag(.@"union").?.data.layout != .Auto,
2294 .union_tagged => false,
23162295 };
23172296 }
23182297
......@@ -3299,13 +3278,12 @@ pub const Type = extern union {
32993278 => return true,
33003279
33013280 .optional => {
3302 var buf: Payload.ElemType = undefined;
3303 const child_type = self.optionalChild(&buf);
3281 const child_ty = self.castTag(.optional).?.data;
33043282 // optionals of zero sized types behave like bools, not pointers
3305 if (!child_type.hasRuntimeBits()) return false;
3306 if (child_type.zigTypeTag() != .Pointer) return false;
3283 if (!child_ty.hasRuntimeBits()) return false;
3284 if (child_ty.zigTypeTag() != .Pointer) return false;
33073285
3308 const info = child_type.ptrInfo().data;
3286 const info = child_ty.ptrInfo().data;
33093287 switch (info.size) {
33103288 .Slice, .C => return false,
33113289 .Many, .One => return !info.@"allowzero",
......@@ -5496,6 +5474,7 @@ pub const Type = extern union {
54965474 pub const @"type" = initTag(.type);
54975475 pub const @"anyerror" = initTag(.anyerror);
54985476 pub const @"anyopaque" = initTag(.anyopaque);
5477 pub const @"null" = initTag(.@"null");
54995478
55005479 pub fn ptr(arena: Allocator, target: Target, data: Payload.Pointer.Data) !Type {
55015480 var d = data;
src/value.zig+2-2
......@@ -2417,7 +2417,7 @@ pub const Value = extern union {
24172417 return switch (val.tag()) {
24182418 .empty_array_sentinel => if (start == 0 and end == 1) val else Value.initTag(.empty_array),
24192419 .bytes => Tag.bytes.create(arena, val.castTag(.bytes).?.data[start..end]),
2420 .array => Tag.array.create(arena, val.castTag(.array).?.data[start..end]),
2420 .aggregate => Tag.aggregate.create(arena, val.castTag(.aggregate).?.data[start..end]),
24212421 .slice => sliceArray(val.castTag(.slice).?.data.ptr, arena, start, end),
24222422
24232423 .decl_ref => sliceArray(val.castTag(.decl_ref).?.data.val, arena, start, end),
......@@ -2466,7 +2466,7 @@ pub const Value = extern union {
24662466 pub fn elemPtr(val: Value, ty: Type, arena: Allocator, index: usize) Allocator.Error!Value {
24672467 const elem_ty = ty.elemType2();
24682468 const ptr_val = switch (val.tag()) {
2469 .slice => val.slicePtr(),
2469 .slice => val.castTag(.slice).?.data.ptr,
24702470 else => val,
24712471 };
24722472
test/behavior/bugs/11139.zig+3-3
......@@ -3,9 +3,9 @@ const builtin = @import("builtin");
33const expect = std.testing.expect;
44
55test "store array of array of structs at comptime" {
6 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
7 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
8 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
6 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
7 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
8 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
99
1010 try expect(storeArrayOfArrayOfStructs() == 15);
1111 comptime try expect(storeArrayOfArrayOfStructs() == 15);
test/behavior/cast.zig+4-4
......@@ -871,7 +871,7 @@ test "peer cast [N:x]T to [N]T" {
871871}
872872
873873test "peer cast *[N:x]T to *[N]T" {
874 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
874 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
875875 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
876876 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
877877
......@@ -887,9 +887,9 @@ test "peer cast *[N:x]T to *[N]T" {
887887}
888888
889889test "peer cast [*:x]T to [*]T" {
890 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
891 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
892 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
890 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
891 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
892 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
893893
894894 const S = struct {
895895 fn doTheTest() !void {
test/behavior/ptrcast.zig+16-16
......@@ -23,9 +23,9 @@ fn testReinterpretBytesAsInteger() !void {
2323
2424test "reinterpret an array over multiple elements, with no well-defined layout" {
2525 if (builtin.zig_backend == .stage1) return error.SkipZigTest;
26 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
27 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
28 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
26 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
27 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
28 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
2929
3030 try testReinterpretWithOffsetAndNoWellDefinedLayout();
3131 comptime try testReinterpretWithOffsetAndNoWellDefinedLayout();
......@@ -40,9 +40,9 @@ fn testReinterpretWithOffsetAndNoWellDefinedLayout() !void {
4040}
4141
4242test "reinterpret bytes inside auto-layout struct as integer with nonzero offset" {
43 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
44 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
45 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
43 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
44 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
45 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
4646
4747 try testReinterpretStructWrappedBytesAsInteger();
4848 comptime try testReinterpretStructWrappedBytesAsInteger();
......@@ -59,9 +59,9 @@ fn testReinterpretStructWrappedBytesAsInteger() !void {
5959}
6060
6161test "reinterpret bytes of an array into an extern struct" {
62 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
63 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
64 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
62 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
63 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
64 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
6565
6666 try testReinterpretBytesAsExternStruct();
6767 comptime try testReinterpretBytesAsExternStruct();
......@@ -83,8 +83,8 @@ fn testReinterpretBytesAsExternStruct() !void {
8383
8484test "reinterpret bytes of an extern struct into another" {
8585 if (builtin.zig_backend == .stage1) return error.SkipZigTest;
86 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
87 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
86 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
87 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
8888
8989 try testReinterpretExternStructAsExternStruct();
9090 comptime try testReinterpretExternStructAsExternStruct();
......@@ -109,11 +109,11 @@ fn testReinterpretExternStructAsExternStruct() !void {
109109
110110test "lower reinterpreted comptime field ptr" {
111111 if (builtin.zig_backend == .stage1) return error.SkipZigTest;
112 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
113 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
114 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
115 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
116 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
112 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
113 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
114 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
115 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
116 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
117117
118118 // Test lowering a field ptr
119119 comptime var bytes align(2) = [_]u8{ 1, 2, 3, 4, 5, 6 };