authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-05-30 02:18:07-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-10 20:47:57-07:00
logd0cd1c89da5d688634cdcd3fd645799b14553660
treef0b47c875ac351024fc349feaf0c1f78522608ba
parent61978c8c9473bc06fa1fde75e37374dd330ed614

Sema: port lazy value usage to be InternPool aware


1 files changed, 187 insertions(+), 73 deletions(-)

src/Sema.zig+187-73
......@@ -1915,6 +1915,18 @@ fn resolveConstValue(
19151915 return sema.failWithNeededComptime(block, src, reason);
19161916}
19171917
1918/// Will not return Value Tags: `variable`, `undef`. Instead they will emit compile errors.
1919/// Lazy values are recursively resolved.
1920fn resolveConstLazyValue(
1921 sema: *Sema,
1922 block: *Block,
1923 src: LazySrcLoc,
1924 air_ref: Air.Inst.Ref,
1925 reason: []const u8,
1926) CompileError!Value {
1927 return sema.resolveLazyValue(try sema.resolveConstValue(block, src, air_ref, reason));
1928}
1929
19181930/// Value Tag `variable` causes this function to return `null`.
19191931/// Value Tag `undef` causes this function to return a compile error.
19201932fn resolveDefinedValue(
......@@ -1952,10 +1964,22 @@ fn resolveMaybeUndefVal(
19521964 }
19531965}
19541966
1967/// Value Tag `variable` causes this function to return `null`.
1968/// Value Tag `undef` causes this function to return the Value.
1969/// Value Tag `generic_poison` causes `error.GenericPoison` to be returned.
1970/// Lazy values are recursively resolved.
1971fn resolveMaybeUndefLazyVal(
1972 sema: *Sema,
1973 inst: Air.Inst.Ref,
1974) CompileError!?Value {
1975 return try sema.resolveLazyValue((try sema.resolveMaybeUndefVal(inst)) orelse return null);
1976}
1977
19551978/// Value Tag `variable` results in `null`.
19561979/// Value Tag `undef` results in the Value.
19571980/// Value Tag `generic_poison` causes `error.GenericPoison` to be returned.
19581981/// Value Tag `decl_ref` and `decl_ref_mut` or any nested such value results in `null`.
1982/// Lazy values are recursively resolved.
19591983fn resolveMaybeUndefValIntable(
19601984 sema: *Sema,
19611985 inst: Air.Inst.Ref,
......@@ -1976,8 +2000,7 @@ fn resolveMaybeUndefValIntable(
19762000 else => break,
19772001 },
19782002 };
1979 try sema.resolveLazyValue(val);
1980 return val;
2003 return try sema.resolveLazyValue(val);
19812004}
19822005
19832006/// Returns all Value tags including `variable` and `undef`.
......@@ -5257,8 +5280,7 @@ fn zirCompileLog(
52575280
52585281 const arg = try sema.resolveInst(arg_ref);
52595282 const arg_ty = sema.typeOf(arg);
5260 if (try sema.resolveMaybeUndefVal(arg)) |val| {
5261 try sema.resolveLazyValue(val);
5283 if (try sema.resolveMaybeUndefLazyVal(arg)) |val| {
52625284 try writer.print("@as({}, {})", .{
52635285 arg_ty.fmt(sema.mod), val.fmtValue(arg_ty, sema.mod),
52645286 });
......@@ -7266,15 +7288,14 @@ fn analyzeInlineCallArg(
72667288 // parameter or return type.
72677289 return error.GenericPoison;
72687290 },
7269 else => {
7270 // Needed so that lazy values do not trigger
7271 // assertion due to type not being resolved
7272 // when the hash function is called.
7273 try sema.resolveLazyValue(arg_val);
7274 },
7291 else => {},
72757292 }
7276 should_memoize.* = should_memoize.* and !arg_val.canMutateComptimeVarState(mod);
7277 memoized_arg_values[arg_i.*] = try arg_val.intern(param_ty.toType(), mod);
7293 // Needed so that lazy values do not trigger
7294 // assertion due to type not being resolved
7295 // when the hash function is called.
7296 const resolved_arg_val = try sema.resolveLazyValue(arg_val);
7297 should_memoize.* = should_memoize.* and !resolved_arg_val.canMutateComptimeVarState(mod);
7298 memoized_arg_values[arg_i.*] = try resolved_arg_val.intern(param_ty.toType(), mod);
72787299 } else {
72797300 sema.inst_map.putAssumeCapacityNoClobber(inst, casted_arg);
72807301 }
......@@ -7302,15 +7323,14 @@ fn analyzeInlineCallArg(
73027323 // parameter or return type.
73037324 return error.GenericPoison;
73047325 },
7305 else => {
7306 // Needed so that lazy values do not trigger
7307 // assertion due to type not being resolved
7308 // when the hash function is called.
7309 try sema.resolveLazyValue(arg_val);
7310 },
7326 else => {},
73117327 }
7312 should_memoize.* = should_memoize.* and !arg_val.canMutateComptimeVarState(mod);
7313 memoized_arg_values[arg_i.*] = try arg_val.intern(sema.typeOf(uncasted_arg), mod);
7328 // Needed so that lazy values do not trigger
7329 // assertion due to type not being resolved
7330 // when the hash function is called.
7331 const resolved_arg_val = try sema.resolveLazyValue(arg_val);
7332 should_memoize.* = should_memoize.* and !resolved_arg_val.canMutateComptimeVarState(mod);
7333 memoized_arg_values[arg_i.*] = try resolved_arg_val.intern(sema.typeOf(uncasted_arg), mod);
73147334 } else {
73157335 if (zir_tags[inst] == .param_anytype_comptime) {
73167336 _ = try sema.resolveConstMaybeUndefVal(arg_block, arg_src, uncasted_arg, "parameter is comptime");
......@@ -7369,9 +7389,7 @@ fn analyzeGenericCallArg(
73697389}
73707390
73717391fn analyzeGenericCallArgVal(sema: *Sema, block: *Block, arg_src: LazySrcLoc, uncasted_arg: Air.Inst.Ref) !Value {
7372 const arg_val = try sema.resolveValue(block, arg_src, uncasted_arg, "parameter is comptime");
7373 try sema.resolveLazyValue(arg_val);
7374 return arg_val;
7392 return sema.resolveLazyValue(try sema.resolveValue(block, arg_src, uncasted_arg, "parameter is comptime"));
73757393}
73767394
73777395fn instantiateGenericCall(
......@@ -7903,7 +7921,8 @@ fn resolveTupleLazyValues(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type)
79037921 for (tuple.types, tuple.values) |field_ty, field_val| {
79047922 try sema.resolveTupleLazyValues(block, src, field_ty.toType());
79057923 if (field_val == .none) continue;
7906 try sema.resolveLazyValue(field_val.toValue());
7924 // TODO: mutate in intern pool
7925 _ = try sema.resolveLazyValue(field_val.toValue());
79077926 }
79087927}
79097928
......@@ -10104,8 +10123,9 @@ fn zirSwitchCapture(
1010410123
1010510124 if (block.inline_case_capture != .none) {
1010610125 const item_val = sema.resolveConstValue(block, .unneeded, block.inline_case_capture, undefined) catch unreachable;
10126 const resolved_item_val = try sema.resolveLazyValue(item_val);
1010710127 if (operand_ty.zigTypeTag(mod) == .Union) {
10108 const field_index = @intCast(u32, operand_ty.unionTagFieldIndex(item_val, sema.mod).?);
10128 const field_index = @intCast(u32, operand_ty.unionTagFieldIndex(resolved_item_val, sema.mod).?);
1010910129 const union_obj = mod.typeToUnion(operand_ty).?;
1011010130 const field_ty = union_obj.fields.values()[field_index].ty;
1011110131 if (try sema.resolveDefinedValue(block, sema.src, operand_ptr)) |union_val| {
......@@ -10141,7 +10161,7 @@ fn zirSwitchCapture(
1014110161 return block.addStructFieldVal(operand_ptr, field_index, field_ty);
1014210162 }
1014310163 } else if (is_ref) {
10144 return sema.addConstantMaybeRef(block, operand_ty, item_val, true);
10164 return sema.addConstantMaybeRef(block, operand_ty, resolved_item_val, true);
1014510165 } else {
1014610166 return block.inline_case_capture;
1014710167 }
......@@ -10249,7 +10269,7 @@ fn zirSwitchCapture(
1024910269 for (items) |item| {
1025010270 const item_ref = try sema.resolveInst(item);
1025110271 // Previous switch validation ensured this will succeed
10252 const item_val = sema.resolveConstValue(block, .unneeded, item_ref, "") catch unreachable;
10272 const item_val = sema.resolveConstLazyValue(block, .unneeded, item_ref, "") catch unreachable;
1025310273 const name_ip = try mod.intern_pool.getOrPutString(gpa, item_val.getError(mod).?);
1025410274 names.putAssumeCapacityNoClobber(name_ip, {});
1025510275 }
......@@ -10259,7 +10279,7 @@ fn zirSwitchCapture(
1025910279 } else {
1026010280 const item_ref = try sema.resolveInst(items[0]);
1026110281 // Previous switch validation ensured this will succeed
10262 const item_val = sema.resolveConstValue(block, .unneeded, item_ref, "") catch unreachable;
10282 const item_val = sema.resolveConstLazyValue(block, .unneeded, item_ref, "") catch unreachable;
1026310283
1026410284 const item_ty = try mod.singleErrorSetType(item_val.getError(mod).?);
1026510285 return sema.bitCast(block, item_ty, operand, operand_src, null);
......@@ -10993,6 +11013,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1099311013 defer merges.deinit(gpa);
1099411014
1099511015 if (try sema.resolveDefinedValue(&child_block, src, operand)) |operand_val| {
11016 const resolved_operand_val = try sema.resolveLazyValue(operand_val);
1099611017 var extra_index: usize = special.end;
1099711018 {
1099811019 var scalar_i: usize = 0;
......@@ -11007,8 +11028,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1100711028
1100811029 const item = try sema.resolveInst(item_ref);
1100911030 // Validation above ensured these will succeed.
11010 const item_val = sema.resolveConstValue(&child_block, .unneeded, item, "") catch unreachable;
11011 if (operand_val.eql(item_val, operand_ty, mod)) {
11031 const item_val = sema.resolveConstLazyValue(&child_block, .unneeded, item, "") catch unreachable;
11032 if (resolved_operand_val.eql(item_val, operand_ty, mod)) {
1101211033 if (is_inline) child_block.inline_case_capture = operand;
1101311034
1101411035 if (err_set) try sema.maybeErrorUnwrapComptime(&child_block, body, operand);
......@@ -11033,8 +11054,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1103311054 for (items) |item_ref| {
1103411055 const item = try sema.resolveInst(item_ref);
1103511056 // Validation above ensured these will succeed.
11036 const item_val = sema.resolveConstValue(&child_block, .unneeded, item, "") catch unreachable;
11037 if (operand_val.eql(item_val, operand_ty, mod)) {
11057 const item_val = sema.resolveConstLazyValue(&child_block, .unneeded, item, "") catch unreachable;
11058 if (resolved_operand_val.eql(item_val, operand_ty, mod)) {
1103811059 if (is_inline) child_block.inline_case_capture = operand;
1103911060
1104011061 if (err_set) try sema.maybeErrorUnwrapComptime(&child_block, body, operand);
......@@ -11052,8 +11073,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1105211073 // Validation above ensured these will succeed.
1105311074 const first_tv = sema.resolveInstConst(&child_block, .unneeded, item_first, "") catch unreachable;
1105411075 const last_tv = sema.resolveInstConst(&child_block, .unneeded, item_last, "") catch unreachable;
11055 if ((try sema.compareAll(operand_val, .gte, first_tv.val, operand_ty)) and
11056 (try sema.compareAll(operand_val, .lte, last_tv.val, operand_ty)))
11076 if ((try sema.compareAll(resolved_operand_val, .gte, first_tv.val, operand_ty)) and
11077 (try sema.compareAll(resolved_operand_val, .lte, last_tv.val, operand_ty)))
1105711078 {
1105811079 if (is_inline) child_block.inline_case_capture = operand;
1105911080 if (err_set) try sema.maybeErrorUnwrapComptime(&child_block, body, operand);
......@@ -11135,7 +11156,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1113511156 // `item` is already guaranteed to be constant known.
1113611157
1113711158 const analyze_body = if (union_originally) blk: {
11138 const item_val = sema.resolveConstValue(block, .unneeded, item, "") catch unreachable;
11159 const item_val = sema.resolveConstLazyValue(block, .unneeded, item, "") catch unreachable;
1113911160 const field_ty = maybe_union_ty.unionFieldType(item_val, mod);
1114011161 break :blk field_ty.zigTypeTag(mod) != .NoReturn;
1114111162 } else true;
......@@ -11683,8 +11704,7 @@ fn resolveSwitchItemVal(
1168311704 // Constructing a LazySrcLoc is costly because we only have the switch AST node.
1168411705 // Only if we know for sure we need to report a compile error do we resolve the
1168511706 // full source locations.
11686 if (sema.resolveConstValue(block, .unneeded, item, "")) |val| {
11687 try sema.resolveLazyValue(val);
11707 if (sema.resolveConstLazyValue(block, .unneeded, item, "")) |val| {
1168811708 return val.toIntern();
1168911709 } else |err| switch (err) {
1169011710 error.NeededSourceLocation => {
......@@ -20634,9 +20654,8 @@ fn zirBitCount(
2063420654 }
2063520655 },
2063620656 .Int => {
20637 if (try sema.resolveMaybeUndefVal(operand)) |val| {
20657 if (try sema.resolveMaybeUndefLazyVal(operand)) |val| {
2063820658 if (val.isUndef(mod)) return sema.addConstUndef(result_scalar_ty);
20639 try sema.resolveLazyValue(val);
2064020659 return sema.addIntUnsigned(result_scalar_ty, comptimeOp(val, operand_ty, mod));
2064120660 } else {
2064220661 try sema.requireRuntimeBlock(block, src, operand_src);
......@@ -22311,18 +22330,18 @@ fn analyzeMinMax(
2231122330 continue;
2231222331 }
2231322332
22314 try sema.resolveLazyValue(cur_val);
22315 try sema.resolveLazyValue(operand_val);
22333 const resolved_cur_val = try sema.resolveLazyValue(cur_val);
22334 const resolved_operand_val = try sema.resolveLazyValue(operand_val);
2231622335
2231722336 const vec_len = simd_op.len orelse {
22318 const result_val = opFunc(cur_val, operand_val, mod);
22337 const result_val = opFunc(resolved_cur_val, resolved_operand_val, mod);
2231922338 cur_minmax = try sema.addConstant(simd_op.result_ty, result_val);
2232022339 continue;
2232122340 };
2232222341 const elems = try sema.arena.alloc(InternPool.Index, vec_len);
2232322342 for (elems, 0..) |*elem, i| {
22324 const lhs_elem_val = try cur_val.elemValue(mod, i);
22325 const rhs_elem_val = try operand_val.elemValue(mod, i);
22343 const lhs_elem_val = try resolved_cur_val.elemValue(mod, i);
22344 const rhs_elem_val = try resolved_operand_val.elemValue(mod, i);
2232622345 elem.* = try opFunc(lhs_elem_val, rhs_elem_val, mod).intern(simd_op.scalar_ty, mod);
2232722346 }
2232822347 cur_minmax = try sema.addConstant(simd_op.result_ty, (try mod.intern(.{ .aggregate = .{
......@@ -30360,13 +30379,11 @@ fn cmpNumeric(
3036030379 if (try sema.resolveMaybeUndefVal(rhs)) |rhs_val| {
3036130380 // Compare ints: const vs. undefined (or vice versa)
3036230381 if (!lhs_val.isUndef(mod) and (lhs_ty.isInt(mod) or lhs_ty_tag == .ComptimeInt) and rhs_ty.isInt(mod) and rhs_val.isUndef(mod)) {
30363 try sema.resolveLazyValue(lhs_val);
30364 if (try sema.compareIntsOnlyPossibleResult(lhs_val, op, rhs_ty)) |res| {
30382 if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(lhs_val), op, rhs_ty)) |res| {
3036530383 return if (res) Air.Inst.Ref.bool_true else Air.Inst.Ref.bool_false;
3036630384 }
3036730385 } else if (!rhs_val.isUndef(mod) and (rhs_ty.isInt(mod) or rhs_ty_tag == .ComptimeInt) and lhs_ty.isInt(mod) and lhs_val.isUndef(mod)) {
30368 try sema.resolveLazyValue(rhs_val);
30369 if (try sema.compareIntsOnlyPossibleResult(rhs_val, op.reverse(), lhs_ty)) |res| {
30386 if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(rhs_val), op.reverse(), lhs_ty)) |res| {
3037030387 return if (res) Air.Inst.Ref.bool_true else Air.Inst.Ref.bool_false;
3037130388 }
3037230389 }
......@@ -30389,19 +30406,17 @@ fn cmpNumeric(
3038930406 } else {
3039030407 if (!lhs_val.isUndef(mod) and (lhs_ty.isInt(mod) or lhs_ty_tag == .ComptimeInt) and rhs_ty.isInt(mod)) {
3039130408 // Compare ints: const vs. var
30392 try sema.resolveLazyValue(lhs_val);
30393 if (try sema.compareIntsOnlyPossibleResult(lhs_val, op, rhs_ty)) |res| {
30409 if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(lhs_val), op, rhs_ty)) |res| {
3039430410 return if (res) Air.Inst.Ref.bool_true else Air.Inst.Ref.bool_false;
3039530411 }
3039630412 }
3039730413 break :src rhs_src;
3039830414 }
3039930415 } else {
30400 if (try sema.resolveMaybeUndefVal(rhs)) |rhs_val| {
30416 if (try sema.resolveMaybeUndefLazyVal(rhs)) |rhs_val| {
3040130417 if (!rhs_val.isUndef(mod) and (rhs_ty.isInt(mod) or rhs_ty_tag == .ComptimeInt) and lhs_ty.isInt(mod)) {
3040230418 // Compare ints: var vs. const
30403 try sema.resolveLazyValue(rhs_val);
30404 if (try sema.compareIntsOnlyPossibleResult(rhs_val, op.reverse(), lhs_ty)) |res| {
30419 if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(rhs_val), op.reverse(), lhs_ty)) |res| {
3040530420 return if (res) Air.Inst.Ref.bool_true else Air.Inst.Ref.bool_false;
3040630421 }
3040730422 }
......@@ -30465,8 +30480,7 @@ fn cmpNumeric(
3046530480 var dest_float_type: ?Type = null;
3046630481
3046730482 var lhs_bits: usize = undefined;
30468 if (try sema.resolveMaybeUndefVal(lhs)) |lhs_val| {
30469 try sema.resolveLazyValue(lhs_val);
30483 if (try sema.resolveMaybeUndefLazyVal(lhs)) |lhs_val| {
3047030484 if (lhs_val.isUndef(mod))
3047130485 return sema.addConstUndef(Type.bool);
3047230486 if (lhs_val.isNan(mod)) switch (op) {
......@@ -30524,8 +30538,7 @@ fn cmpNumeric(
3052430538 }
3052530539
3052630540 var rhs_bits: usize = undefined;
30527 if (try sema.resolveMaybeUndefVal(rhs)) |rhs_val| {
30528 try sema.resolveLazyValue(rhs_val);
30541 if (try sema.resolveMaybeUndefLazyVal(rhs)) |rhs_val| {
3052930542 if (rhs_val.isUndef(mod))
3053030543 return sema.addConstUndef(Type.bool);
3053130544 if (rhs_val.isNan(mod)) switch (op) {
......@@ -31467,32 +31480,133 @@ pub fn resolveFnTypes(sema: *Sema, fn_info: InternPool.Key.FuncType) CompileErro
3146731480
3146831481/// Make it so that calling hash() and eql() on `val` will not assert due
3146931482/// to a type not having its layout resolved.
31470fn resolveLazyValue(sema: *Sema, val: Value) CompileError!void {
31471 switch (sema.mod.intern_pool.indexToKey(val.toIntern())) {
31483fn resolveLazyValue(sema: *Sema, val: Value) CompileError!Value {
31484 const mod = sema.mod;
31485 switch (mod.intern_pool.indexToKey(val.toIntern())) {
3147231486 .int => |int| switch (int.storage) {
31473 .u64, .i64, .big_int => {},
31474 .lazy_align, .lazy_size => |lazy_ty| try sema.resolveTypeLayout(lazy_ty.toType()),
31487 .u64, .i64, .big_int => return val,
31488 .lazy_align, .lazy_size => return (try mod.intern(.{ .int = .{
31489 .ty = int.ty,
31490 .storage = .{ .u64 = (try val.getUnsignedIntAdvanced(mod, sema)).? },
31491 } })).toValue(),
3147531492 },
3147631493 .ptr => |ptr| {
31494 const resolved_len = switch (ptr.len) {
31495 .none => .none,
31496 else => (try sema.resolveLazyValue(ptr.len.toValue())).toIntern(),
31497 };
3147731498 switch (ptr.addr) {
31478 .decl, .mut_decl => {},
31479 .int => |int| try sema.resolveLazyValue(int.toValue()),
31480 .eu_payload, .opt_payload => |base| try sema.resolveLazyValue(base.toValue()),
31481 .comptime_field => |comptime_field| try sema.resolveLazyValue(comptime_field.toValue()),
31482 .elem, .field => |base_index| try sema.resolveLazyValue(base_index.base.toValue()),
31499 .decl, .mut_decl => return if (resolved_len == ptr.len)
31500 val
31501 else
31502 (try mod.intern(.{ .ptr = .{
31503 .ty = ptr.ty,
31504 .addr = switch (ptr.addr) {
31505 .decl => |decl| .{ .decl = decl },
31506 .mut_decl => |mut_decl| .{ .mut_decl = mut_decl },
31507 else => unreachable,
31508 },
31509 .len = resolved_len,
31510 } })).toValue(),
31511 .comptime_field => |field_val| {
31512 const resolved_field_val =
31513 (try sema.resolveLazyValue(field_val.toValue())).toIntern();
31514 return if (resolved_field_val == field_val and resolved_len == ptr.len)
31515 val
31516 else
31517 (try mod.intern(.{ .ptr = .{
31518 .ty = ptr.ty,
31519 .addr = .{ .comptime_field = resolved_field_val },
31520 .len = resolved_len,
31521 } })).toValue();
31522 },
31523 .int => |int| {
31524 const resolved_int = (try sema.resolveLazyValue(int.toValue())).toIntern();
31525 return if (resolved_int == int and resolved_len == ptr.len)
31526 val
31527 else
31528 (try mod.intern(.{ .ptr = .{
31529 .ty = ptr.ty,
31530 .addr = .{ .int = resolved_int },
31531 .len = resolved_len,
31532 } })).toValue();
31533 },
31534 .eu_payload, .opt_payload => |base| {
31535 const resolved_base = (try sema.resolveLazyValue(base.toValue())).toIntern();
31536 return if (resolved_base == base and resolved_len == ptr.len)
31537 val
31538 else
31539 (try mod.intern(.{ .ptr = .{
31540 .ty = ptr.ty,
31541 .addr = switch (ptr.addr) {
31542 .eu_payload => .{ .eu_payload = resolved_base },
31543 .opt_payload => .{ .opt_payload = resolved_base },
31544 else => unreachable,
31545 },
31546 .len = ptr.len,
31547 } })).toValue();
31548 },
31549 .elem, .field => |base_index| {
31550 const resolved_base = (try sema.resolveLazyValue(base_index.base.toValue())).toIntern();
31551 return if (resolved_base == base_index.base and resolved_len == ptr.len)
31552 val
31553 else
31554 (try mod.intern(.{ .ptr = .{
31555 .ty = ptr.ty,
31556 .addr = switch (ptr.addr) {
31557 .elem => .{ .elem = .{
31558 .base = resolved_base,
31559 .index = base_index.index,
31560 } },
31561 .field => .{ .field = .{
31562 .base = resolved_base,
31563 .index = base_index.index,
31564 } },
31565 else => unreachable,
31566 },
31567 .len = ptr.len,
31568 } })).toValue();
31569 },
3148331570 }
31484 if (ptr.len != .none) try sema.resolveLazyValue(ptr.len.toValue());
3148531571 },
3148631572 .aggregate => |aggregate| switch (aggregate.storage) {
31487 .bytes => {},
31488 .elems => |elems| for (elems) |elem| try sema.resolveLazyValue(elem.toValue()),
31489 .repeated_elem => |elem| try sema.resolveLazyValue(elem.toValue()),
31573 .bytes => return val,
31574 .elems => |elems| {
31575 var resolved_elems: []InternPool.Index = &.{};
31576 for (elems, 0..) |elem, i| {
31577 const resolved_elem = (try sema.resolveLazyValue(elem.toValue())).toIntern();
31578 if (resolved_elems.len == 0 and resolved_elem != elem) {
31579 resolved_elems = try sema.arena.alloc(InternPool.Index, elems.len);
31580 @memcpy(resolved_elems[0..i], elems[0..i]);
31581 }
31582 if (resolved_elems.len > 0) resolved_elems[i] = resolved_elem;
31583 }
31584 return if (resolved_elems.len == 0) val else (try mod.intern(.{ .aggregate = .{
31585 .ty = aggregate.ty,
31586 .storage = .{ .elems = resolved_elems },
31587 } })).toValue();
31588 },
31589 .repeated_elem => |elem| {
31590 const resolved_elem = (try sema.resolveLazyValue(elem.toValue())).toIntern();
31591 return if (resolved_elem == elem) val else (try mod.intern(.{ .aggregate = .{
31592 .ty = aggregate.ty,
31593 .storage = .{ .repeated_elem = resolved_elem },
31594 } })).toValue();
31595 },
3149031596 },
3149131597 .un => |un| {
31492 try sema.resolveLazyValue(un.tag.toValue());
31493 try sema.resolveLazyValue(un.val.toValue());
31598 const resolved_tag = (try sema.resolveLazyValue(un.tag.toValue())).toIntern();
31599 const resolved_val = (try sema.resolveLazyValue(un.val.toValue())).toIntern();
31600 return if (resolved_tag == un.tag and resolved_val == un.val)
31601 val
31602 else
31603 (try mod.intern(.{ .un = .{
31604 .ty = un.ty,
31605 .tag = resolved_tag,
31606 .val = resolved_val,
31607 } })).toValue();
3149431608 },
31495 else => {},
31609 else => return val,
3149631610 }
3149731611}
3149831612