@@ -17732,10 +17732,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1773217732 try ty.resolveStructFieldInits(pt);
1773317733
1773417734 for (struct_field_vals, 0..) |*field_val, field_index| {
17735- const field_name = if (struct_type.fieldName(ip, field_index).unwrap()) |field_name|
17736- field_name
17737- else
17738- try ip.getOrPutStringFmt(gpa, pt.tid, "{d}", .{field_index}, .no_embedded_nulls);
17735+ const field_name = struct_type.fieldName(ip, field_index);
1773917736 const field_name_len = field_name.length(ip);
1774017737 const field_ty: Type = .fromInterned(struct_type.field_types.get(ip)[field_index]);
1774117738 const field_init = struct_type.fieldInit(ip, field_index);
@@ -28334,6 +28331,10 @@ fn elemPtrArray(
2833428331 break :o index;
2833528332 } else null;
2833628333
28334+ if (offset == null and array_ty.zigTypeTag(zcu) == .vector) {
28335+ return sema.fail(block, elem_index_src, "vector index not comptime known", .{});
28336+ }
28337+
2833728338 const elem_ptr_ty = try array_ptr_ty.elemPtrType(offset, pt);
2833828339
2833928340 if (maybe_undef_array_ptr_val) |array_ptr_val| {
@@ -28351,10 +28352,6 @@ fn elemPtrArray(
2835128352 try sema.validateRuntimeValue(block, array_ptr_src, array_ptr);
2835228353 }
2835328354
28354- if (offset == null and array_ty.zigTypeTag(zcu) == .vector) {
28355- return sema.fail(block, elem_index_src, "vector index not comptime known", .{});
28356- }
28357-
2835828355 // Runtime check is only needed if unable to comptime check.
2835928356 if (oob_safety and block.wantSafety() and offset == null) {
2836028357 const len_inst = try pt.intRef(.usize, array_len);
@@ -30386,22 +30383,6 @@ fn storePtr2(
3038630383
3038730384 const is_ret = air_tag == .ret_ptr;
3038830385
30389- // Detect if we are storing an array operand to a bitcasted vector pointer.
30390- // If so, we instead reach through the bitcasted pointer to the vector pointer,
30391- // bitcast the array operand to a vector, and then lower this as a store of
30392- // a vector value to a vector pointer. This generally results in better code,
30393- // as well as working around an LLVM bug:
30394- // https://github.com/ziglang/zig/issues/11154
30395- if (sema.obtainBitCastedVectorPtr(ptr)) |vector_ptr| {
30396- const vector_ty = sema.typeOf(vector_ptr).childType(zcu);
30397- const vector = sema.coerceExtra(block, vector_ty, uncasted_operand, operand_src, .{ .is_ret = is_ret }) catch |err| switch (err) {
30398- error.NotCoercible => unreachable,
30399- else => |e| return e,
30400- };
30401- try sema.storePtr2(block, src, vector_ptr, ptr_src, vector, operand_src, .store);
30402- return;
30403- }
30404-
3040530386 const operand = sema.coerceExtra(block, elem_ty, uncasted_operand, operand_src, .{ .is_ret = is_ret }) catch |err| switch (err) {
3040630387 error.NotCoercible => unreachable,
3040730388 else => |e| return e,
@@ -30434,29 +30415,6 @@ fn storePtr2(
3043430415
3043530416 try sema.requireRuntimeBlock(block, src, runtime_src);
3043630417
30437- if (ptr_ty.ptrInfo(zcu).flags.vector_index == .runtime) {
30438- const ptr_inst = ptr.toIndex().?;
30439- const air_tags = sema.air_instructions.items(.tag);
30440- if (air_tags[@intFromEnum(ptr_inst)] == .ptr_elem_ptr) {
30441- const ty_pl = sema.air_instructions.items(.data)[@intFromEnum(ptr_inst)].ty_pl;
30442- const bin_op = sema.getTmpAir().extraData(Air.Bin, ty_pl.payload).data;
30443- _ = try block.addInst(.{
30444- .tag = .vector_store_elem,
30445- .data = .{ .vector_store_elem = .{
30446- .vector_ptr = bin_op.lhs,
30447- .payload = try block.sema.addExtra(Air.Bin{
30448- .lhs = bin_op.rhs,
30449- .rhs = operand,
30450- }),
30451- } },
30452- });
30453- return;
30454- }
30455- return sema.fail(block, ptr_src, "unable to determine vector element index of type '{f}'", .{
30456- ptr_ty.fmt(pt),
30457- });
30458- }
30459-
3046030418 const store_inst = if (is_ret)
3046130419 try block.addBinOp(.store, ptr, operand)
3046230420 else
@@ -30556,37 +30514,6 @@ fn markMaybeComptimeAllocRuntime(sema: *Sema, block: *Block, alloc_inst: Air.Ins
3055630514 }
3055730515}
3055830516
30559- /// Traverse an arbitrary number of bitcasted pointers and return the underyling vector
30560- /// pointer. Only if the final element type matches the vector element type, and the
30561- /// lengths match.
30562- fn obtainBitCastedVectorPtr(sema: *Sema, ptr: Air.Inst.Ref) ?Air.Inst.Ref {
30563- const pt = sema.pt;
30564- const zcu = pt.zcu;
30565- const array_ty = sema.typeOf(ptr).childType(zcu);
30566- if (array_ty.zigTypeTag(zcu) != .array) return null;
30567- var ptr_ref = ptr;
30568- var ptr_inst = ptr_ref.toIndex() orelse return null;
30569- const air_datas = sema.air_instructions.items(.data);
30570- const air_tags = sema.air_instructions.items(.tag);
30571- const vector_ty = while (air_tags[@intFromEnum(ptr_inst)] == .bitcast) {
30572- ptr_ref = air_datas[@intFromEnum(ptr_inst)].ty_op.operand;
30573- if (!sema.isKnownZigType(ptr_ref, .pointer)) return null;
30574- const child_ty = sema.typeOf(ptr_ref).childType(zcu);
30575- if (child_ty.zigTypeTag(zcu) == .vector) break child_ty;
30576- ptr_inst = ptr_ref.toIndex() orelse return null;
30577- } else return null;
30578-
30579- // We have a pointer-to-array and a pointer-to-vector. If the elements and
30580- // lengths match, return the result.
30581- if (array_ty.childType(zcu).eql(vector_ty.childType(zcu), zcu) and
30582- array_ty.arrayLen(zcu) == vector_ty.vectorLen(zcu))
30583- {
30584- return ptr_ref;
30585- } else {
30586- return null;
30587- }
30588- }
30589-
3059030517/// Call when you have Value objects rather than Air instructions, and you want to
3059130518/// assert the store must be done at comptime.
3059230519fn storePtrVal(
@@ -35566,8 +35493,13 @@ fn structFieldInits(
3556635493 const default_val = try sema.resolveConstValue(&block_scope, init_src, coerced, null);
3556735494
3556835495 if (default_val.canMutateComptimeVarState(zcu)) {
35569- const field_name = struct_type.fieldName(ip, field_i).unwrap().?;
35570- return sema.failWithContainsReferenceToComptimeVar(&block_scope, init_src, field_name, "field default value", default_val);
35496+ return sema.failWithContainsReferenceToComptimeVar(
35497+ &block_scope,
35498+ init_src,
35499+ struct_type.fieldName(ip, field_i),
35500+ "field default value",
35501+ default_val,
35502+ );
3557135503 }
3557235504 struct_type.field_inits.get(ip)[field_i] = default_val.toIntern();
3557335505 }
0 commit comments