@@ -128,7 +128,7 @@ pub const Block = struct {
128
128
/// Shared among all child blocks.
129
129
sema: *Sema,
130
130
/// The namespace to use for lookups from this source block
131
- /// When analyzing fields, this is different from src_decl.src_namepsace .
131
+ /// When analyzing fields, this is different from src_decl.src_namespace .
132
132
namespace: *Namespace,
133
133
/// The AIR instructions generated for this block.
134
134
instructions: std.ArrayListUnmanaged(Air.Inst.Index),
@@ -1897,10 +1897,15 @@ fn resolveMaybeUndefValAllowVariablesMaybeRuntime(
1897
1897
}
1898
1898
i -= Air.Inst.Ref.typed_value_map.len;
1899
1899
1900
+ const air_tags = sema.air_instructions.items(.tag);
1900
1901
if (try sema.typeHasOnePossibleValue(sema.typeOf(inst))) |opv| {
1902
+ if (air_tags[i] == .constant) {
1903
+ const ty_pl = sema.air_instructions.items(.data)[i].ty_pl;
1904
+ const val = sema.air_values.items[ty_pl.payload];
1905
+ if (val.tag() == .variable) return val;
1906
+ }
1901
1907
return opv;
1902
1908
}
1903
- const air_tags = sema.air_instructions.items(.tag);
1904
1909
switch (air_tags[i]) {
1905
1910
.constant => {
1906
1911
const ty_pl = sema.air_instructions.items(.data)[i].ty_pl;
@@ -4106,6 +4111,7 @@ fn validateStructInit(
4106
4111
.{fqn},
4107
4112
);
4108
4113
}
4114
+ root_msg = null;
4109
4115
return sema.failWithOwnedErrorMsg(msg);
4110
4116
}
4111
4117
@@ -4225,7 +4231,6 @@ fn validateStructInit(
4225
4231
}
4226
4232
4227
4233
if (root_msg) |msg| {
4228
- root_msg = null;
4229
4234
if (struct_ty.castTag(.@"struct")) |struct_obj| {
4230
4235
const fqn = try struct_obj.data.getFullyQualifiedName(sema.mod);
4231
4236
defer gpa.free(fqn);
@@ -4236,6 +4241,7 @@ fn validateStructInit(
4236
4241
.{fqn},
4237
4242
);
4238
4243
}
4244
+ root_msg = null;
4239
4245
return sema.failWithOwnedErrorMsg(msg);
4240
4246
}
4241
4247
@@ -4283,29 +4289,42 @@ fn zirValidateArrayInit(
4283
4289
const array_ty = sema.typeOf(array_ptr).childType();
4284
4290
const array_len = array_ty.arrayLen();
4285
4291
4286
- if (instrs.len != array_len and array_ty.isTuple()) {
4287
- const struct_obj = array_ty.castTag(.tuple).?.data;
4288
- var root_msg: ?*Module.ErrorMsg = null;
4289
- errdefer if (root_msg) |msg| msg.destroy(sema.gpa);
4292
+ if (instrs.len != array_len) switch (array_ty.zigTypeTag()) {
4293
+ .Struct => {
4294
+ const struct_obj = array_ty.castTag(.tuple).?.data;
4295
+ var root_msg: ?*Module.ErrorMsg = null;
4296
+ errdefer if (root_msg) |msg| msg.destroy(sema.gpa);
4290
4297
4291
- for (struct_obj.values) |default_val, i| {
4292
- if (i < instrs.len) continue;
4298
+ for (struct_obj.values) |default_val, i| {
4299
+ if (i < instrs.len) continue;
4293
4300
4294
- if (default_val.tag() == .unreachable_value) {
4295
- const template = "missing tuple field with index {d}";
4296
- if (root_msg) |msg| {
4297
- try sema.errNote(block, init_src, msg, template, .{i});
4298
- } else {
4299
- root_msg = try sema.errMsg(block, init_src, template, .{i});
4301
+ if (default_val.tag() == .unreachable_value) {
4302
+ const template = "missing tuple field with index {d}";
4303
+ if (root_msg) |msg| {
4304
+ try sema.errNote(block, init_src, msg, template, .{i});
4305
+ } else {
4306
+ root_msg = try sema.errMsg(block, init_src, template, .{i});
4307
+ }
4300
4308
}
4301
4309
}
4302
- }
4303
4310
4304
- if (root_msg) |msg| {
4305
- root_msg = null;
4306
- return sema.failWithOwnedErrorMsg(msg);
4307
- }
4308
- }
4311
+ if (root_msg) |msg| {
4312
+ root_msg = null;
4313
+ return sema.failWithOwnedErrorMsg(msg);
4314
+ }
4315
+ },
4316
+ .Array => {
4317
+ return sema.fail(block, init_src, "expected {d} array elements; found {d}", .{
4318
+ array_len, instrs.len,
4319
+ });
4320
+ },
4321
+ .Vector => {
4322
+ return sema.fail(block, init_src, "expected {d} vector elements; found {d}", .{
4323
+ array_len, instrs.len,
4324
+ });
4325
+ },
4326
+ else => unreachable,
4327
+ };
4309
4328
4310
4329
if ((is_comptime or block.is_comptime) and
4311
4330
(try sema.resolveDefinedValue(block, init_src, array_ptr)) != null)
@@ -17054,7 +17073,6 @@ fn finishStructInit(
17054
17073
}
17055
17074
17056
17075
if (root_msg) |msg| {
17057
- root_msg = null;
17058
17076
if (struct_ty.castTag(.@"struct")) |struct_obj| {
17059
17077
const fqn = try struct_obj.data.getFullyQualifiedName(sema.mod);
17060
17078
defer gpa.free(fqn);
@@ -17065,6 +17083,7 @@ fn finishStructInit(
17065
17083
.{fqn},
17066
17084
);
17067
17085
}
17086
+ root_msg = null;
17068
17087
return sema.failWithOwnedErrorMsg(msg);
17069
17088
}
17070
17089
@@ -18752,8 +18771,8 @@ fn zirIntToPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18752
18771
18753
18772
const type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
18754
18773
const ptr_ty = try sema.resolveType(block, src, extra.lhs);
18755
- const elem_ty = ptr_ty.elemType2();
18756
18774
try sema.checkPtrType(block, type_src, ptr_ty);
18775
+ const elem_ty = ptr_ty.elemType2();
18757
18776
const target = sema.mod.getTarget();
18758
18777
const ptr_align = try ptr_ty.ptrAlignmentAdvanced(target, sema);
18759
18778
@@ -24281,7 +24300,10 @@ fn coerceExtra(
24281
24300
},
24282
24301
.Int, .ComptimeInt => switch (inst_ty.zigTypeTag()) {
24283
24302
.Float, .ComptimeFloat => float: {
24284
- const val = (try sema.resolveDefinedValue(block, inst_src, inst)) orelse {
24303
+ if (is_undef) {
24304
+ return sema.addConstUndef(dest_ty);
24305
+ }
24306
+ const val = (try sema.resolveMaybeUndefVal(inst)) orelse {
24285
24307
if (dest_ty.zigTypeTag() == .ComptimeInt) {
24286
24308
if (!opts.report_err) return error.NotCoercible;
24287
24309
return sema.failWithNeededComptime(block, inst_src, "value being casted to 'comptime_int' must be comptime-known");
@@ -24301,7 +24323,10 @@ fn coerceExtra(
24301
24323
return try sema.addConstant(dest_ty, result_val);
24302
24324
},
24303
24325
.Int, .ComptimeInt => {
24304
- if (try sema.resolveDefinedValue(block, inst_src, inst)) |val| {
24326
+ if (is_undef) {
24327
+ return sema.addConstUndef(dest_ty);
24328
+ }
24329
+ if (try sema.resolveMaybeUndefVal(inst)) |val| {
24305
24330
// comptime-known integer to other number
24306
24331
if (!(try sema.intFitsInType(val, dest_ty, null))) {
24307
24332
if (!opts.report_err) return error.NotCoercible;
@@ -24338,7 +24363,10 @@ fn coerceExtra(
24338
24363
return try sema.addConstant(dest_ty, result_val);
24339
24364
},
24340
24365
.Float => {
24341
- if (try sema.resolveDefinedValue(block, inst_src, inst)) |val| {
24366
+ if (is_undef) {
24367
+ return sema.addConstUndef(dest_ty);
24368
+ }
24369
+ if (try sema.resolveMaybeUndefVal(inst)) |val| {
24342
24370
const result_val = try val.floatCast(sema.arena, dest_ty, target);
24343
24371
if (!val.eql(result_val, dest_ty, sema.mod)) {
24344
24372
return sema.fail(
@@ -24363,7 +24391,10 @@ fn coerceExtra(
24363
24391
}
24364
24392
},
24365
24393
.Int, .ComptimeInt => int: {
24366
- const val = (try sema.resolveDefinedValue(block, inst_src, inst)) orelse {
24394
+ if (is_undef) {
24395
+ return sema.addConstUndef(dest_ty);
24396
+ }
24397
+ const val = (try sema.resolveMaybeUndefVal(inst)) orelse {
24367
24398
if (dest_ty.zigTypeTag() == .ComptimeFloat) {
24368
24399
if (!opts.report_err) return error.NotCoercible;
24369
24400
return sema.failWithNeededComptime(block, inst_src, "value being casted to 'comptime_float' must be comptime-known");
@@ -26517,6 +26548,10 @@ fn beginComptimePtrLoad(
26517
26548
.null_value => {
26518
26549
return sema.fail(block, src, "attempt to use null value", .{});
26519
26550
},
26551
+ .opt_payload => blk: {
26552
+ const opt_payload = ptr_val.castTag(.opt_payload).?.data;
26553
+ break :blk try sema.beginComptimePtrLoad(block, src, opt_payload, null);
26554
+ },
26520
26555
26521
26556
.zero,
26522
26557
.one,
@@ -27165,8 +27200,8 @@ fn coerceTupleToStruct(
27165
27200
}
27166
27201
27167
27202
if (root_msg) |msg| {
27168
- root_msg = null;
27169
27203
try sema.addDeclaredHereNote(msg, struct_ty);
27204
+ root_msg = null;
27170
27205
return sema.failWithOwnedErrorMsg(msg);
27171
27206
}
27172
27207
@@ -27271,8 +27306,8 @@ fn coerceTupleToTuple(
27271
27306
}
27272
27307
27273
27308
if (root_msg) |msg| {
27274
- root_msg = null;
27275
27309
try sema.addDeclaredHereNote(msg, tuple_ty);
27310
+ root_msg = null;
27276
27311
return sema.failWithOwnedErrorMsg(msg);
27277
27312
}
27278
27313
@@ -31262,7 +31297,10 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
31262
31297
}
31263
31298
31264
31299
pub fn typeHasRuntimeBits(sema: *Sema, ty: Type) CompileError!bool {
31265
- return ty.hasRuntimeBitsAdvanced(false, sema);
31300
+ return ty.hasRuntimeBitsAdvanced(false, .{ .sema = sema }) catch |err| switch (err) {
31301
+ error.NeedLazy => unreachable,
31302
+ else => |e| return e,
31303
+ };
31266
31304
}
31267
31305
31268
31306
fn typeAbiSize(sema: *Sema, ty: Type) !u64 {
0 commit comments