authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-07-15 13:36:46-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-07-20 12:19:16-07:00
log12c10139e3e0166e91d2dbb1801c2054ca12d413
treef084c36fecb08bd36eb0733263647b12ac1fbb05
parent0da66339096c21d9ca524ff7a0c11a5707b60041

Sema: finish reworking for AIR memory layout except switch


2 files changed, 332 insertions(+), 285 deletions(-)

src/Sema.zig+331-284
......@@ -276,101 +276,101 @@ pub fn analyzeBody(
276276 //.switch_capture_multi_ref => try sema.zirSwitchCapture(block, inst, true, true),
277277 //.switch_capture_else => try sema.zirSwitchCaptureElse(block, inst, false),
278278 //.switch_capture_else_ref => try sema.zirSwitchCaptureElse(block, inst, true),
279 //.type_info => try sema.zirTypeInfo(block, inst),
280 //.size_of => try sema.zirSizeOf(block, inst),
281 //.bit_size_of => try sema.zirBitSizeOf(block, inst),
282 //.typeof => try sema.zirTypeof(block, inst),
283 //.typeof_elem => try sema.zirTypeofElem(block, inst),
284 //.log2_int_type => try sema.zirLog2IntType(block, inst),
285 //.typeof_log2_int_type => try sema.zirTypeofLog2IntType(block, inst),
286 //.xor => try sema.zirBitwise(block, inst, .xor),
287 //.struct_init_empty => try sema.zirStructInitEmpty(block, inst),
288 //.struct_init => try sema.zirStructInit(block, inst, false),
289 //.struct_init_ref => try sema.zirStructInit(block, inst, true),
290 //.struct_init_anon => try sema.zirStructInitAnon(block, inst, false),
291 //.struct_init_anon_ref => try sema.zirStructInitAnon(block, inst, true),
292 //.array_init => try sema.zirArrayInit(block, inst, false),
293 //.array_init_ref => try sema.zirArrayInit(block, inst, true),
294 //.array_init_anon => try sema.zirArrayInitAnon(block, inst, false),
295 //.array_init_anon_ref => try sema.zirArrayInitAnon(block, inst, true),
296 //.union_init_ptr => try sema.zirUnionInitPtr(block, inst),
297 //.field_type => try sema.zirFieldType(block, inst),
298 //.field_type_ref => try sema.zirFieldTypeRef(block, inst),
299 //.ptr_to_int => try sema.zirPtrToInt(block, inst),
300 //.align_of => try sema.zirAlignOf(block, inst),
301 //.bool_to_int => try sema.zirBoolToInt(block, inst),
302 //.embed_file => try sema.zirEmbedFile(block, inst),
303 //.error_name => try sema.zirErrorName(block, inst),
304 //.tag_name => try sema.zirTagName(block, inst),
305 //.reify => try sema.zirReify(block, inst),
306 //.type_name => try sema.zirTypeName(block, inst),
307 //.frame_type => try sema.zirFrameType(block, inst),
308 //.frame_size => try sema.zirFrameSize(block, inst),
309 //.float_to_int => try sema.zirFloatToInt(block, inst),
310 //.int_to_float => try sema.zirIntToFloat(block, inst),
311 //.int_to_ptr => try sema.zirIntToPtr(block, inst),
312 //.float_cast => try sema.zirFloatCast(block, inst),
313 //.int_cast => try sema.zirIntCast(block, inst),
314 //.err_set_cast => try sema.zirErrSetCast(block, inst),
315 //.ptr_cast => try sema.zirPtrCast(block, inst),
316 //.truncate => try sema.zirTruncate(block, inst),
317 //.align_cast => try sema.zirAlignCast(block, inst),
318 //.has_decl => try sema.zirHasDecl(block, inst),
319 //.has_field => try sema.zirHasField(block, inst),
320 //.clz => try sema.zirClz(block, inst),
321 //.ctz => try sema.zirCtz(block, inst),
322 //.pop_count => try sema.zirPopCount(block, inst),
323 //.byte_swap => try sema.zirByteSwap(block, inst),
324 //.bit_reverse => try sema.zirBitReverse(block, inst),
325 //.div_exact => try sema.zirDivExact(block, inst),
326 //.div_floor => try sema.zirDivFloor(block, inst),
327 //.div_trunc => try sema.zirDivTrunc(block, inst),
328 //.mod => try sema.zirMod(block, inst),
329 //.rem => try sema.zirRem(block, inst),
330 //.shl_exact => try sema.zirShlExact(block, inst),
331 //.shr_exact => try sema.zirShrExact(block, inst),
332 //.bit_offset_of => try sema.zirBitOffsetOf(block, inst),
333 //.offset_of => try sema.zirOffsetOf(block, inst),
334 //.cmpxchg_strong => try sema.zirCmpxchg(block, inst),
335 //.cmpxchg_weak => try sema.zirCmpxchg(block, inst),
336 //.splat => try sema.zirSplat(block, inst),
337 //.reduce => try sema.zirReduce(block, inst),
338 //.shuffle => try sema.zirShuffle(block, inst),
339 //.atomic_load => try sema.zirAtomicLoad(block, inst),
340 //.atomic_rmw => try sema.zirAtomicRmw(block, inst),
341 //.atomic_store => try sema.zirAtomicStore(block, inst),
342 //.mul_add => try sema.zirMulAdd(block, inst),
343 //.builtin_call => try sema.zirBuiltinCall(block, inst),
344 //.field_ptr_type => try sema.zirFieldPtrType(block, inst),
345 //.field_parent_ptr => try sema.zirFieldParentPtr(block, inst),
346 //.memcpy => try sema.zirMemcpy(block, inst),
347 //.memset => try sema.zirMemset(block, inst),
348 //.builtin_async_call => try sema.zirBuiltinAsyncCall(block, inst),
349 //.@"resume" => try sema.zirResume(block, inst),
350 //.@"await" => try sema.zirAwait(block, inst, false),
351 //.await_nosuspend => try sema.zirAwait(block, inst, true),
352 //.extended => try sema.zirExtended(block, inst),
353
354 //.sqrt => try sema.zirUnaryMath(block, inst),
355 //.sin => try sema.zirUnaryMath(block, inst),
356 //.cos => try sema.zirUnaryMath(block, inst),
357 //.exp => try sema.zirUnaryMath(block, inst),
358 //.exp2 => try sema.zirUnaryMath(block, inst),
359 //.log => try sema.zirUnaryMath(block, inst),
360 //.log2 => try sema.zirUnaryMath(block, inst),
361 //.log10 => try sema.zirUnaryMath(block, inst),
362 //.fabs => try sema.zirUnaryMath(block, inst),
363 //.floor => try sema.zirUnaryMath(block, inst),
364 //.ceil => try sema.zirUnaryMath(block, inst),
365 //.trunc => try sema.zirUnaryMath(block, inst),
366 //.round => try sema.zirUnaryMath(block, inst),
367
368 //.opaque_decl => try sema.zirOpaqueDecl(block, inst, .parent),
369 //.opaque_decl_anon => try sema.zirOpaqueDecl(block, inst, .anon),
370 //.opaque_decl_func => try sema.zirOpaqueDecl(block, inst, .func),
371 //.error_set_decl => try sema.zirErrorSetDecl(block, inst, .parent),
372 //.error_set_decl_anon => try sema.zirErrorSetDecl(block, inst, .anon),
373 //.error_set_decl_func => try sema.zirErrorSetDecl(block, inst, .func),
279 .type_info => try sema.zirTypeInfo(block, inst),
280 .size_of => try sema.zirSizeOf(block, inst),
281 .bit_size_of => try sema.zirBitSizeOf(block, inst),
282 .typeof => try sema.zirTypeof(block, inst),
283 .typeof_elem => try sema.zirTypeofElem(block, inst),
284 .log2_int_type => try sema.zirLog2IntType(block, inst),
285 .typeof_log2_int_type => try sema.zirTypeofLog2IntType(block, inst),
286 .xor => try sema.zirBitwise(block, inst, .xor),
287 .struct_init_empty => try sema.zirStructInitEmpty(block, inst),
288 .struct_init => try sema.zirStructInit(block, inst, false),
289 .struct_init_ref => try sema.zirStructInit(block, inst, true),
290 .struct_init_anon => try sema.zirStructInitAnon(block, inst, false),
291 .struct_init_anon_ref => try sema.zirStructInitAnon(block, inst, true),
292 .array_init => try sema.zirArrayInit(block, inst, false),
293 .array_init_ref => try sema.zirArrayInit(block, inst, true),
294 .array_init_anon => try sema.zirArrayInitAnon(block, inst, false),
295 .array_init_anon_ref => try sema.zirArrayInitAnon(block, inst, true),
296 .union_init_ptr => try sema.zirUnionInitPtr(block, inst),
297 .field_type => try sema.zirFieldType(block, inst),
298 .field_type_ref => try sema.zirFieldTypeRef(block, inst),
299 .ptr_to_int => try sema.zirPtrToInt(block, inst),
300 .align_of => try sema.zirAlignOf(block, inst),
301 .bool_to_int => try sema.zirBoolToInt(block, inst),
302 .embed_file => try sema.zirEmbedFile(block, inst),
303 .error_name => try sema.zirErrorName(block, inst),
304 .tag_name => try sema.zirTagName(block, inst),
305 .reify => try sema.zirReify(block, inst),
306 .type_name => try sema.zirTypeName(block, inst),
307 .frame_type => try sema.zirFrameType(block, inst),
308 .frame_size => try sema.zirFrameSize(block, inst),
309 .float_to_int => try sema.zirFloatToInt(block, inst),
310 .int_to_float => try sema.zirIntToFloat(block, inst),
311 .int_to_ptr => try sema.zirIntToPtr(block, inst),
312 .float_cast => try sema.zirFloatCast(block, inst),
313 .int_cast => try sema.zirIntCast(block, inst),
314 .err_set_cast => try sema.zirErrSetCast(block, inst),
315 .ptr_cast => try sema.zirPtrCast(block, inst),
316 .truncate => try sema.zirTruncate(block, inst),
317 .align_cast => try sema.zirAlignCast(block, inst),
318 .has_decl => try sema.zirHasDecl(block, inst),
319 .has_field => try sema.zirHasField(block, inst),
320 .clz => try sema.zirClz(block, inst),
321 .ctz => try sema.zirCtz(block, inst),
322 .pop_count => try sema.zirPopCount(block, inst),
323 .byte_swap => try sema.zirByteSwap(block, inst),
324 .bit_reverse => try sema.zirBitReverse(block, inst),
325 .div_exact => try sema.zirDivExact(block, inst),
326 .div_floor => try sema.zirDivFloor(block, inst),
327 .div_trunc => try sema.zirDivTrunc(block, inst),
328 .mod => try sema.zirMod(block, inst),
329 .rem => try sema.zirRem(block, inst),
330 .shl_exact => try sema.zirShlExact(block, inst),
331 .shr_exact => try sema.zirShrExact(block, inst),
332 .bit_offset_of => try sema.zirBitOffsetOf(block, inst),
333 .offset_of => try sema.zirOffsetOf(block, inst),
334 .cmpxchg_strong => try sema.zirCmpxchg(block, inst),
335 .cmpxchg_weak => try sema.zirCmpxchg(block, inst),
336 .splat => try sema.zirSplat(block, inst),
337 .reduce => try sema.zirReduce(block, inst),
338 .shuffle => try sema.zirShuffle(block, inst),
339 .atomic_load => try sema.zirAtomicLoad(block, inst),
340 .atomic_rmw => try sema.zirAtomicRmw(block, inst),
341 .atomic_store => try sema.zirAtomicStore(block, inst),
342 .mul_add => try sema.zirMulAdd(block, inst),
343 .builtin_call => try sema.zirBuiltinCall(block, inst),
344 .field_ptr_type => try sema.zirFieldPtrType(block, inst),
345 .field_parent_ptr => try sema.zirFieldParentPtr(block, inst),
346 .memcpy => try sema.zirMemcpy(block, inst),
347 .memset => try sema.zirMemset(block, inst),
348 .builtin_async_call => try sema.zirBuiltinAsyncCall(block, inst),
349 .@"resume" => try sema.zirResume(block, inst),
350 .@"await" => try sema.zirAwait(block, inst, false),
351 .await_nosuspend => try sema.zirAwait(block, inst, true),
352 .extended => try sema.zirExtended(block, inst),
353
354 .sqrt => try sema.zirUnaryMath(block, inst),
355 .sin => try sema.zirUnaryMath(block, inst),
356 .cos => try sema.zirUnaryMath(block, inst),
357 .exp => try sema.zirUnaryMath(block, inst),
358 .exp2 => try sema.zirUnaryMath(block, inst),
359 .log => try sema.zirUnaryMath(block, inst),
360 .log2 => try sema.zirUnaryMath(block, inst),
361 .log10 => try sema.zirUnaryMath(block, inst),
362 .fabs => try sema.zirUnaryMath(block, inst),
363 .floor => try sema.zirUnaryMath(block, inst),
364 .ceil => try sema.zirUnaryMath(block, inst),
365 .trunc => try sema.zirUnaryMath(block, inst),
366 .round => try sema.zirUnaryMath(block, inst),
367
368 .opaque_decl => try sema.zirOpaqueDecl(block, inst, .parent),
369 .opaque_decl_anon => try sema.zirOpaqueDecl(block, inst, .anon),
370 .opaque_decl_func => try sema.zirOpaqueDecl(block, inst, .func),
371 .error_set_decl => try sema.zirErrorSetDecl(block, inst, .parent),
372 .error_set_decl_anon => try sema.zirErrorSetDecl(block, inst, .anon),
373 .error_set_decl_func => try sema.zirErrorSetDecl(block, inst, .func),
374374
375375 .add => try sema.zirArithmetic(block, inst),
376376 .addwrap => try sema.zirArithmetic(block, inst),
......@@ -396,106 +396,106 @@ pub fn analyzeBody(
396396 .panic => return sema.zirPanic(block, inst),
397397 // zig fmt: on
398398
399 //// Instructions that we know can *never* be noreturn based solely on
400 //// their tag. We avoid needlessly checking if they are noreturn and
401 //// continue the loop.
402 //// We also know that they cannot be referenced later, so we avoid
403 //// putting them into the map.
404 //.breakpoint => {
405 // try sema.zirBreakpoint(block, inst);
406 // i += 1;
407 // continue;
408 //},
409 //.fence => {
410 // try sema.zirFence(block, inst);
411 // i += 1;
412 // continue;
413 //},
414 //.dbg_stmt => {
415 // try sema.zirDbgStmt(block, inst);
416 // i += 1;
417 // continue;
418 //},
419 //.ensure_err_payload_void => {
420 // try sema.zirEnsureErrPayloadVoid(block, inst);
421 // i += 1;
422 // continue;
423 //},
424 //.ensure_result_non_error => {
425 // try sema.zirEnsureResultNonError(block, inst);
426 // i += 1;
427 // continue;
428 //},
429 //.ensure_result_used => {
430 // try sema.zirEnsureResultUsed(block, inst);
431 // i += 1;
432 // continue;
433 //},
434 //.set_eval_branch_quota => {
435 // try sema.zirSetEvalBranchQuota(block, inst);
436 // i += 1;
437 // continue;
438 //},
439 //.store => {
440 // try sema.zirStore(block, inst);
441 // i += 1;
442 // continue;
443 //},
444 //.store_node => {
445 // try sema.zirStoreNode(block, inst);
446 // i += 1;
447 // continue;
448 //},
449 //.store_to_block_ptr => {
450 // try sema.zirStoreToBlockPtr(block, inst);
451 // i += 1;
452 // continue;
453 //},
454 //.store_to_inferred_ptr => {
455 // try sema.zirStoreToInferredPtr(block, inst);
456 // i += 1;
457 // continue;
458 //},
459 //.resolve_inferred_alloc => {
460 // try sema.zirResolveInferredAlloc(block, inst);
461 // i += 1;
462 // continue;
463 //},
464 //.validate_struct_init_ptr => {
465 // try sema.zirValidateStructInitPtr(block, inst);
466 // i += 1;
467 // continue;
468 //},
469 //.validate_array_init_ptr => {
470 // try sema.zirValidateArrayInitPtr(block, inst);
471 // i += 1;
472 // continue;
473 //},
474 //.@"export" => {
475 // try sema.zirExport(block, inst);
476 // i += 1;
477 // continue;
478 //},
479 //.set_align_stack => {
480 // try sema.zirSetAlignStack(block, inst);
481 // i += 1;
482 // continue;
483 //},
484 //.set_cold => {
485 // try sema.zirSetCold(block, inst);
486 // i += 1;
487 // continue;
488 //},
489 //.set_float_mode => {
490 // try sema.zirSetFloatMode(block, inst);
491 // i += 1;
492 // continue;
493 //},
494 //.set_runtime_safety => {
495 // try sema.zirSetRuntimeSafety(block, inst);
496 // i += 1;
497 // continue;
498 //},
399 // Instructions that we know can *never* be noreturn based solely on
400 // their tag. We avoid needlessly checking if they are noreturn and
401 // continue the loop.
402 // We also know that they cannot be referenced later, so we avoid
403 // putting them into the map.
404 .breakpoint => {
405 try sema.zirBreakpoint(block, inst);
406 i += 1;
407 continue;
408 },
409 .fence => {
410 try sema.zirFence(block, inst);
411 i += 1;
412 continue;
413 },
414 .dbg_stmt => {
415 try sema.zirDbgStmt(block, inst);
416 i += 1;
417 continue;
418 },
419 .ensure_err_payload_void => {
420 try sema.zirEnsureErrPayloadVoid(block, inst);
421 i += 1;
422 continue;
423 },
424 .ensure_result_non_error => {
425 try sema.zirEnsureResultNonError(block, inst);
426 i += 1;
427 continue;
428 },
429 .ensure_result_used => {
430 try sema.zirEnsureResultUsed(block, inst);
431 i += 1;
432 continue;
433 },
434 .set_eval_branch_quota => {
435 try sema.zirSetEvalBranchQuota(block, inst);
436 i += 1;
437 continue;
438 },
439 .store => {
440 try sema.zirStore(block, inst);
441 i += 1;
442 continue;
443 },
444 .store_node => {
445 try sema.zirStoreNode(block, inst);
446 i += 1;
447 continue;
448 },
449 .store_to_block_ptr => {
450 try sema.zirStoreToBlockPtr(block, inst);
451 i += 1;
452 continue;
453 },
454 .store_to_inferred_ptr => {
455 try sema.zirStoreToInferredPtr(block, inst);
456 i += 1;
457 continue;
458 },
459 .resolve_inferred_alloc => {
460 try sema.zirResolveInferredAlloc(block, inst);
461 i += 1;
462 continue;
463 },
464 .validate_struct_init_ptr => {
465 try sema.zirValidateStructInitPtr(block, inst);
466 i += 1;
467 continue;
468 },
469 .validate_array_init_ptr => {
470 try sema.zirValidateArrayInitPtr(block, inst);
471 i += 1;
472 continue;
473 },
474 .@"export" => {
475 try sema.zirExport(block, inst);
476 i += 1;
477 continue;
478 },
479 .set_align_stack => {
480 try sema.zirSetAlignStack(block, inst);
481 i += 1;
482 continue;
483 },
484 .set_cold => {
485 try sema.zirSetCold(block, inst);
486 i += 1;
487 continue;
488 },
489 .set_float_mode => {
490 try sema.zirSetFloatMode(block, inst);
491 i += 1;
492 continue;
493 },
494 .set_runtime_safety => {
495 try sema.zirSetRuntimeSafety(block, inst);
496 i += 1;
497 continue;
498 },
499499
500500 // Special case instructions to handle comptime control flow.
501501 .repeat_inline => {
......@@ -562,7 +562,7 @@ fn zirExtended(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr
562562 .frame_address => return sema.zirFrameAddress( block, extended),
563563 .alloc => return sema.zirAllocExtended( block, extended),
564564 .builtin_extern => return sema.zirBuiltinExtern( block, extended),
565 .@"asm" => return sema.zirAsm( block, extended),
565 .@"asm" => return sema.zirAsm( block, extended, inst),
566566 .typeof_peer => return sema.zirTypeofPeer( block, extended),
567567 .compile_log => return sema.zirCompileLog( block, extended),
568568 .add_with_overflow => return sema.zirOverflowArithmetic(block, extended),
......@@ -1400,11 +1400,14 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde
14001400 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
14011401 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node };
14021402 const ptr = sema.resolveInst(inst_data.operand);
1403 const ptr_val = ptr.castTag(.constant).?.val;
1403 const ptr_inst = refToIndex(ptr).?;
1404 assert(sema.air_instructions.items(.tag)[ptr_inst] == .constant);
1405 const air_datas = sema.air_instructions.items(.data);
1406 const ptr_val = sema.air_values.items[air_datas[ptr_inst].ty_pl.payload];
14041407 const inferred_alloc = ptr_val.castTag(.inferred_alloc).?;
14051408 const peer_inst_list = inferred_alloc.data.stored_inst_list.items;
14061409 const final_elem_ty = try sema.resolvePeerTypes(block, ty_src, peer_inst_list);
1407 const var_is_mut = switch (ptr.ty.tag()) {
1410 const var_is_mut = switch (sema.typeOf(ptr).tag()) {
14081411 .inferred_alloc_const => false,
14091412 .inferred_alloc_mut => true,
14101413 else => unreachable,
......@@ -1415,8 +1418,10 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde
14151418 const final_ptr_ty = try Module.simplePtrType(sema.arena, final_elem_ty, true, .One);
14161419
14171420 // Change it to a normal alloc.
1418 ptr.ty = final_ptr_ty;
1419 ptr.tag = .alloc;
1421 sema.air_instructions.set(ptr_inst, .{
1422 .tag = .alloc,
1423 .data = .{ .ty = final_ptr_ty },
1424 });
14201425}
14211426
14221427fn zirValidateStructInitPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void {
......@@ -1434,7 +1439,7 @@ fn zirValidateStructInitPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Ind
14341439 const field_ptr_data = sema.code.instructions.items(.data)[instrs[0]].pl_node;
14351440 const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data;
14361441 const object_ptr = sema.resolveInst(field_ptr_extra.lhs);
1437 break :s object_ptr.ty.elemType().castTag(.@"struct").?.data;
1442 break :s sema.typeOf(object_ptr).elemType().castTag(.@"struct").?.data;
14381443 };
14391444
14401445 // Maps field index to field_ptr index of where it was already initialized.
......@@ -1564,7 +1569,7 @@ fn zirStoreToBlockPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co
15641569 }
15651570 const ptr = sema.resolveInst(bin_inst.lhs);
15661571 const value = sema.resolveInst(bin_inst.rhs);
1567 const ptr_ty = try Module.simplePtrType(sema.arena, value.ty, true, .One);
1572 const ptr_ty = try Module.simplePtrType(sema.arena, sema.typeOf(value), true, .One);
15681573 // TODO detect when this store should be done at compile-time. For example,
15691574 // if expressions should force it when the condition is compile-time known.
15701575 const src: LazySrcLoc = .unneeded;
......@@ -1581,12 +1586,16 @@ fn zirStoreToInferredPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index)
15811586 const bin_inst = sema.code.instructions.items(.data)[inst].bin;
15821587 const ptr = sema.resolveInst(bin_inst.lhs);
15831588 const value = sema.resolveInst(bin_inst.rhs);
1584 const inferred_alloc = ptr.castTag(.constant).?.val.castTag(.inferred_alloc).?;
1589 const ptr_inst = refToIndex(ptr).?;
1590 assert(sema.air_instructions.items(.tag)[ptr_inst] == .constant);
1591 const air_datas = sema.air_instructions.items(.data);
1592 const ptr_val = sema.air_values.items[air_datas[ptr_inst].ty_pl.payload];
1593 const inferred_alloc = ptr_val.castTag(.inferred_alloc).?;
15851594 // Add the stored instruction to the set we will use to resolve peer types
15861595 // for the inferred allocation.
15871596 try inferred_alloc.data.stored_inst_list.append(sema.arena, value);
15881597 // Create a runtime bitcast instruction with exactly the type the pointer wants.
1589 const ptr_ty = try Module.simplePtrType(sema.arena, value.ty, true, .One);
1598 const ptr_ty = try Module.simplePtrType(sema.arena, sema.typeOf(value), true, .One);
15901599 try sema.requireRuntimeBlock(block, src);
15911600 const bitcasted_ptr = try block.addTyOp(.bitcast, ptr_ty, ptr);
15921601 return sema.storePtr(block, src, bitcasted_ptr, value);
......@@ -1767,10 +1776,11 @@ fn zirCompileLog(
17671776 if (i != 0) try writer.print(", ", .{});
17681777
17691778 const arg = sema.resolveInst(arg_ref);
1779 const arg_ty = sema.typeOf(arg);
17701780 if (try sema.resolvePossiblyUndefinedValue(block, src, arg)) |val| {
1771 try writer.print("@as({}, {})", .{ arg.ty, val });
1781 try writer.print("@as({}, {})", .{ arg_ty, val });
17721782 } else {
1773 try writer.print("@as({}, [runtime value])", .{arg.ty});
1783 try writer.print("@as({}, [runtime value])", .{arg_ty});
17741784 }
17751785 }
17761786 try writer.print("\n", .{});
......@@ -2157,7 +2167,13 @@ fn zirDbgStmt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr
21572167 if (block.is_comptime) return;
21582168
21592169 const inst_data = sema.code.instructions.items(.data)[inst].dbg_stmt;
2160 _ = try block.addDbgStmt(.unneeded, inst_data.line, inst_data.column);
2170 _ = try block.addInst(.{
2171 .tag = .dbg_stmt,
2172 .data = .{ .dbg_stmt = .{
2173 .line = inst_data.line,
2174 .column = inst_data.column,
2175 } },
2176 });
21612177}
21622178
21632179fn zirDeclRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
......@@ -3263,9 +3279,10 @@ fn zirPtrToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr
32633279
32643280 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
32653281 const ptr = sema.resolveInst(inst_data.operand);
3266 if (ptr.ty.zigTypeTag() != .Pointer) {
3282 const ptr_ty = sema.typeOf(ptr);
3283 if (ptr_ty.zigTypeTag() != .Pointer) {
32673284 const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
3268 return sema.mod.fail(&block.base, ptr_src, "expected pointer, found '{}'", .{ptr.ty});
3285 return sema.mod.fail(&block.base, ptr_src, "expected pointer, found '{}'", .{ptr_ty});
32693286 }
32703287 // TODO handle known-pointer-address
32713288 const src = inst_data.src();
......@@ -3368,7 +3385,7 @@ fn zirIntCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr
33683385 ),
33693386 }
33703387
3371 if (operand.value() != null) {
3388 if (try sema.isComptimeKnown(block, operand_src, operand)) {
33723389 return sema.coerce(block, dest_type, operand, operand_src);
33733390 } else if (dest_is_comptime_int) {
33743391 return sema.mod.fail(&block.base, src, "unable to cast runtime value to 'comptime_int'", .{});
......@@ -3426,7 +3443,7 @@ fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE
34263443 ),
34273444 }
34283445
3429 if (operand.value() != null) {
3446 if (try sema.isComptimeKnown(block, operand_src, operand)) {
34303447 return sema.coerce(block, dest_type, operand, operand_src);
34313448 } else if (dest_is_comptime_float) {
34323449 return sema.mod.fail(&block.base, src, "unable to cast runtime value to 'comptime_float'", .{});
......@@ -4843,19 +4860,17 @@ fn zirAsm(
48434860 sema: *Sema,
48444861 block: *Scope.Block,
48454862 extended: Zir.Inst.Extended.InstData,
4863 inst: Zir.Inst.Index,
48464864) CompileError!Air.Inst.Ref {
48474865 const tracy = trace(@src());
48484866 defer tracy.end();
48494867
48504868 const extra = sema.code.extraData(Zir.Inst.Asm, extended.operand);
48514869 const src: LazySrcLoc = .{ .node_offset = extra.data.src_node };
4852 const asm_source_src: LazySrcLoc = .{ .node_offset_asm_source = extra.data.src_node };
48534870 const ret_ty_src: LazySrcLoc = .{ .node_offset_asm_ret_ty = extra.data.src_node };
4854 const asm_source = try sema.resolveConstString(block, asm_source_src, extra.data.asm_source);
48554871 const outputs_len = @truncate(u5, extended.small);
48564872 const inputs_len = @truncate(u5, extended.small >> 5);
48574873 const clobbers_len = @truncate(u5, extended.small >> 10);
4858 const is_volatile = @truncate(u1, extended.small >> 15) != 0;
48594874
48604875 if (outputs_len > 1) {
48614876 return sema.mod.fail(&block.base, src, "TODO implement Sema for asm with more than 1 output", .{});
......@@ -4883,7 +4898,7 @@ fn zirAsm(
48834898 };
48844899 };
48854900
4886 const args = try sema.arena.alloc(Air.Inst.Index, inputs_len);
4901 const args = try sema.arena.alloc(Air.Inst.Ref, inputs_len);
48874902 const inputs = try sema.arena.alloc([]const u8, inputs_len);
48884903
48894904 for (args) |*arg, arg_i| {
......@@ -4904,22 +4919,19 @@ fn zirAsm(
49044919 }
49054920
49064921 try sema.requireRuntimeBlock(block, src);
4907 const asm_air = try sema.arena.create(Inst.Assembly);
4908 asm_air.* = .{
4909 .base = .{
4910 .tag = .assembly,
4911 .ty = if (output) |o| o.ty else Type.initTag(.void),
4912 .src = src,
4913 },
4914 .asm_source = asm_source,
4915 .is_volatile = is_volatile,
4916 .output_constraint = if (output) |o| o.constraint else null,
4917 .inputs = inputs,
4918 .clobbers = clobbers,
4919 .args = args,
4920 };
4921 try block.instructions.append(sema.gpa, &asm_air.base);
4922 return &asm_air.base;
4922 const gpa = sema.gpa;
4923 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Asm).Struct.fields.len + args.len);
4924 const asm_air = try block.addInst(.{
4925 .tag = .assembly,
4926 .data = .{ .ty_pl = .{
4927 .ty = if (output) |o| try sema.addType(o.ty) else Air.Inst.Ref.void_type,
4928 .payload = sema.addExtraAssumeCapacity(Air.Asm{
4929 .zir_index = inst,
4930 }),
4931 } },
4932 });
4933 sema.appendRefsAssumeCapacity(args);
4934 return asm_air;
49234935}
49244936
49254937fn zirCmp(
......@@ -5153,7 +5165,7 @@ fn zirTypeofElem(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile
51535165 _ = block;
51545166 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
51555167 const operand_ptr = sema.resolveInst(inst_data.operand);
5156 const elem_ty = operand_ptr.ty.elemType();
5168 const elem_ty = sema.typeOf(operand_ptr).elemType();
51575169 return sema.addType(elem_ty);
51585170}
51595171
......@@ -5181,7 +5193,7 @@ fn zirTypeofPeer(
51815193 const src: LazySrcLoc = .{ .node_offset = extra.data.src_node };
51825194 const args = sema.code.refSlice(extra.end, extended.small);
51835195
5184 const inst_list = try sema.gpa.alloc(Air.Inst.Index, args.len);
5196 const inst_list = try sema.gpa.alloc(Air.Inst.Ref, args.len);
51855197 defer sema.gpa.free(inst_list);
51865198
51875199 for (args) |arg_ref, i| {
......@@ -5623,7 +5635,7 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref:
56235635 mem.set(Zir.Inst.Index, found_fields, 0);
56245636
56255637 // The init values to use for the struct instance.
5626 const field_inits = try gpa.alloc(Air.Inst.Index, struct_obj.fields.count());
5638 const field_inits = try gpa.alloc(Air.Inst.Ref, struct_obj.fields.count());
56275639 defer gpa.free(field_inits);
56285640
56295641 var field_i: u32 = 0;
......@@ -5692,7 +5704,7 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref:
56925704 }
56935705
56945706 const is_comptime = for (field_inits) |field_init| {
5695 if (field_init.value() == null) {
5707 if (!(try sema.isComptimeKnown(block, src, field_init))) {
56965708 break false;
56975709 }
56985710 } else true;
......@@ -5700,7 +5712,7 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref:
57005712 if (is_comptime) {
57015713 const values = try sema.arena.alloc(Value, field_inits.len);
57025714 for (field_inits) |field_init, i| {
5703 values[i] = field_init.value().?;
5715 values[i] = (sema.resolvePossiblyUndefinedValue(block, src, field_init) catch unreachable).?;
57045716 }
57055717 return sema.addConstant(struct_ty, try Value.Tag.@"struct".create(sema.arena, values.ptr));
57065718 }
......@@ -6835,17 +6847,13 @@ fn coerce(
68356847 }
68366848 assert(inst_ty.zigTypeTag() != .Undefined);
68376849
6838 if (true) {
6839 @panic("TODO finish AIR memory layout rework");
6840 }
6841
68426850 // T to E!T or E to E!T
68436851 if (dest_type.tag() == .error_union) {
68446852 return try sema.wrapErrorUnion(block, dest_type, inst, inst_src);
68456853 }
68466854
68476855 // comptime known number to other number
6848 if (try sema.coerceNum(block, dest_type, inst)) |some|
6856 if (try sema.coerceNum(block, dest_type, inst, inst_src)) |some|
68496857 return some;
68506858
68516859 const target = mod.getTarget();
......@@ -6861,9 +6869,9 @@ fn coerce(
68616869 var buf: Type.Payload.ElemType = undefined;
68626870 const child_type = dest_type.optionalChild(&buf);
68636871 if (child_type.eql(inst_ty)) {
6864 return sema.wrapOptional(block, dest_type, inst);
6865 } else if (try sema.coerceNum(block, child_type, inst)) |some| {
6866 return sema.wrapOptional(block, dest_type, some);
6872 return sema.wrapOptional(block, dest_type, inst, inst_src);
6873 } else if (try sema.coerceNum(block, child_type, inst, inst_src)) |some| {
6874 return sema.wrapOptional(block, dest_type, some, inst_src);
68676875 }
68686876 },
68696877 .Pointer => {
......@@ -6885,11 +6893,11 @@ fn coerce(
68856893 switch (dest_type.ptrSize()) {
68866894 .Slice => {
68876895 // *[N]T to []T
6888 return sema.coerceArrayPtrToSlice(block, dest_type, inst);
6896 return sema.coerceArrayPtrToSlice(block, dest_type, inst, inst_src);
68896897 },
68906898 .C => {
68916899 // *[N]T to [*c]T
6892 return sema.coerceArrayPtrToMany(block, dest_type, inst);
6900 return sema.coerceArrayPtrToMany(block, dest_type, inst, inst_src);
68936901 },
68946902 .Many => {
68956903 // *[N]T to [*]T
......@@ -6897,12 +6905,12 @@ fn coerce(
68976905 const src_sentinel = array_type.sentinel();
68986906 const dst_sentinel = dest_type.sentinel();
68996907 if (src_sentinel == null and dst_sentinel == null)
6900 return sema.coerceArrayPtrToMany(block, dest_type, inst);
6908 return sema.coerceArrayPtrToMany(block, dest_type, inst, inst_src);
69016909
69026910 if (src_sentinel) |src_s| {
69036911 if (dst_sentinel) |dst_s| {
69046912 if (src_s.eql(dst_s)) {
6905 return sema.coerceArrayPtrToMany(block, dest_type, inst);
6913 return sema.coerceArrayPtrToMany(block, dest_type, inst, inst_src);
69066914 }
69076915 }
69086916 }
......@@ -6914,7 +6922,7 @@ fn coerce(
69146922 .Int => {
69156923 // integer widening
69166924 if (inst_ty.zigTypeTag() == .Int) {
6917 assert(inst.value() == null); // handled above
6925 assert(!(try sema.isComptimeKnown(block, inst_src, inst))); // handled above
69186926
69196927 const dst_info = dest_type.intInfo(target);
69206928 const src_info = inst_ty.intInfo(target);
......@@ -6930,7 +6938,7 @@ fn coerce(
69306938 .Float => {
69316939 // float widening
69326940 if (inst_ty.zigTypeTag() == .Float) {
6933 assert(inst.value() == null); // handled above
6941 assert(!(try sema.isComptimeKnown(block, inst_src, inst))); // handled above
69346942
69356943 const src_bits = inst_ty.floatBits(target);
69366944 const dst_bits = dest_type.floatBits(target);
......@@ -6991,9 +6999,16 @@ fn coerceInMemoryAllowed(dest_type: Type, src_type: Type) InMemoryCoercionResult
69916999 return .no_match;
69927000}
69937001
6994fn coerceNum(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: Air.Inst.Ref) CompileError!?Air.Inst.Index {
6995 const val = inst.value() orelse return null;
6996 const src_zig_tag = inst.ty.zigTypeTag();
7002fn coerceNum(
7003 sema: *Sema,
7004 block: *Scope.Block,
7005 dest_type: Type,
7006 inst: Air.Inst.Ref,
7007 inst_src: LazySrcLoc,
7008) CompileError!?Air.Inst.Ref {
7009 const val = (try sema.resolveDefinedValue(block, inst_src, inst)) orelse return null;
7010 const inst_ty = sema.typeOf(inst);
7011 const src_zig_tag = inst_ty.zigTypeTag();
69977012 const dst_zig_tag = dest_type.zigTypeTag();
69987013
69997014 const target = sema.mod.getTarget();
......@@ -7001,29 +7016,29 @@ fn coerceNum(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: Air.Inst.R
70017016 if (dst_zig_tag == .ComptimeInt or dst_zig_tag == .Int) {
70027017 if (src_zig_tag == .Float or src_zig_tag == .ComptimeFloat) {
70037018 if (val.floatHasFraction()) {
7004 return sema.mod.fail(&block.base, inst.src, "fractional component prevents float value {} from being casted to type '{}'", .{ val, inst.ty });
7019 return sema.mod.fail(&block.base, inst_src, "fractional component prevents float value {} from being casted to type '{}'", .{ val, inst_ty });
70057020 }
7006 return sema.mod.fail(&block.base, inst.src, "TODO float to int", .{});
7021 return sema.mod.fail(&block.base, inst_src, "TODO float to int", .{});
70077022 } else if (src_zig_tag == .Int or src_zig_tag == .ComptimeInt) {
70087023 if (!val.intFitsInType(dest_type, target)) {
7009 return sema.mod.fail(&block.base, inst.src, "type {} cannot represent integer value {}", .{ inst.ty, val });
7024 return sema.mod.fail(&block.base, inst_src, "type {} cannot represent integer value {}", .{ inst_ty, val });
70107025 }
7011 return sema.addConstant(dest_type, val);
7026 return try sema.addConstant(dest_type, val);
70127027 }
70137028 } else if (dst_zig_tag == .ComptimeFloat or dst_zig_tag == .Float) {
70147029 if (src_zig_tag == .Float or src_zig_tag == .ComptimeFloat) {
70157030 const res = val.floatCast(sema.arena, dest_type, target) catch |err| switch (err) {
70167031 error.Overflow => return sema.mod.fail(
70177032 &block.base,
7018 inst.src,
7033 inst_src,
70197034 "cast of value {} to type '{}' loses information",
70207035 .{ val, dest_type },
70217036 ),
70227037 error.OutOfMemory => return error.OutOfMemory,
70237038 };
7024 return sema.addConstant(dest_type, res);
7039 return try sema.addConstant(dest_type, res);
70257040 } else if (src_zig_tag == .Int or src_zig_tag == .ComptimeInt) {
7026 return sema.mod.fail(&block.base, inst.src, "TODO int to float", .{});
7041 return sema.mod.fail(&block.base, inst_src, "TODO int to float", .{});
70277042 }
70287043 }
70297044 return null;
......@@ -7051,10 +7066,11 @@ fn storePtr(
70517066 ptr: Air.Inst.Ref,
70527067 uncasted_value: Air.Inst.Ref,
70537068) !void {
7054 if (ptr.ty.isConstPtr())
7069 const ptr_ty = sema.typeOf(ptr);
7070 if (ptr_ty.isConstPtr())
70557071 return sema.mod.fail(&block.base, src, "cannot assign to constant", .{});
70567072
7057 const elem_ty = ptr.ty.elemType();
7073 const elem_ty = ptr_ty.elemType();
70587074 const value = try sema.coerce(block, elem_ty, uncasted_value, src);
70597075 if ((try sema.typeHasOnePossibleValue(block, src, elem_ty)) != null)
70607076 return;
......@@ -7113,20 +7129,32 @@ fn bitcast(
71137129 return block.addTyOp(.bitcast, dest_type, inst);
71147130}
71157131
7116fn coerceArrayPtrToSlice(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: Air.Inst.Ref) CompileError!Air.Inst.Ref {
7117 if (inst.value()) |val| {
7132fn coerceArrayPtrToSlice(
7133 sema: *Sema,
7134 block: *Scope.Block,
7135 dest_type: Type,
7136 inst: Air.Inst.Ref,
7137 inst_src: LazySrcLoc,
7138) CompileError!Air.Inst.Ref {
7139 if (try sema.resolveDefinedValue(block, inst_src, inst)) |val| {
71187140 // The comptime Value representation is compatible with both types.
71197141 return sema.addConstant(dest_type, val);
71207142 }
7121 return sema.mod.fail(&block.base, inst.src, "TODO implement coerceArrayPtrToSlice runtime instruction", .{});
7143 return sema.mod.fail(&block.base, inst_src, "TODO implement coerceArrayPtrToSlice runtime instruction", .{});
71227144}
71237145
7124fn coerceArrayPtrToMany(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: Air.Inst.Ref) !Air.Inst.Ref {
7125 if (inst.value()) |val| {
7146fn coerceArrayPtrToMany(
7147 sema: *Sema,
7148 block: *Scope.Block,
7149 dest_type: Type,
7150 inst: Air.Inst.Ref,
7151 inst_src: LazySrcLoc,
7152) !Air.Inst.Ref {
7153 if (try sema.resolveDefinedValue(block, inst_src, inst)) |val| {
71267154 // The comptime Value representation is compatible with both types.
71277155 return sema.addConstant(dest_type, val);
71287156 }
7129 return sema.mod.fail(&block.base, inst.src, "TODO implement coerceArrayPtrToMany runtime instruction", .{});
7157 return sema.mod.fail(&block.base, inst_src, "TODO implement coerceArrayPtrToMany runtime instruction", .{});
71307158}
71317159
71327160fn analyzeDeclVal(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, decl: *Decl) CompileError!Air.Inst.Ref {
......@@ -7531,12 +7559,18 @@ fn cmpNumeric(
75317559 return block.addBinOp(Air.Inst.Tag.fromCmpOp(op), casted_lhs, casted_rhs);
75327560}
75337561
7534fn wrapOptional(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: Air.Inst.Ref) !Air.Inst.Index {
7562fn wrapOptional(
7563 sema: *Sema,
7564 block: *Scope.Block,
7565 dest_type: Type,
7566 inst: Air.Inst.Ref,
7567 inst_src: LazySrcLoc,
7568) !Air.Inst.Ref {
75357569 if (try sema.resolvePossiblyUndefinedValue(block, inst_src, inst)) |val| {
75367570 return sema.addConstant(dest_type, val);
75377571 }
75387572
7539 try sema.requireRuntimeBlock(block, inst.src);
7573 try sema.requireRuntimeBlock(block, inst_src);
75407574 return block.addTyOp(.wrap_optional, dest_type, inst);
75417575}
75427576
......@@ -7546,11 +7580,12 @@ fn wrapErrorUnion(
75467580 dest_type: Type,
75477581 inst: Air.Inst.Ref,
75487582 inst_src: LazySrcLoc,
7549) !Air.Inst.Index {
7583) !Air.Inst.Ref {
7584 const inst_ty = sema.typeOf(inst);
75507585 const err_union = dest_type.castTag(.error_union).?;
75517586 if (try sema.resolvePossiblyUndefinedValue(block, inst_src, inst)) |val| {
7552 if (inst.ty.zigTypeTag() != .ErrorSet) {
7553 _ = try sema.coerce(block, err_union.data.payload, inst, inst.src);
7587 if (inst_ty.zigTypeTag() != .ErrorSet) {
7588 _ = try sema.coerce(block, err_union.data.payload, inst, inst_src);
75547589 } else switch (err_union.data.error_set.tag()) {
75557590 .anyerror => {},
75567591 .error_set_single => {
......@@ -7559,9 +7594,9 @@ fn wrapErrorUnion(
75597594 if (!mem.eql(u8, expected_name, n)) {
75607595 return sema.mod.fail(
75617596 &block.base,
7562 inst.src,
7597 inst_src,
75637598 "expected type '{}', found type '{}'",
7564 .{ err_union.data.error_set, inst.ty },
7599 .{ err_union.data.error_set, inst_ty },
75657600 );
75667601 }
75677602 },
......@@ -7577,9 +7612,9 @@ fn wrapErrorUnion(
75777612 if (!found) {
75787613 return sema.mod.fail(
75797614 &block.base,
7580 inst.src,
7615 inst_src,
75817616 "expected type '{}', found type '{}'",
7582 .{ err_union.data.error_set, inst.ty },
7617 .{ err_union.data.error_set, inst_ty },
75837618 );
75847619 }
75857620 },
......@@ -7589,9 +7624,9 @@ fn wrapErrorUnion(
75897624 if (!map.contains(expected_name)) {
75907625 return sema.mod.fail(
75917626 &block.base,
7592 inst.src,
7627 inst_src,
75937628 "expected type '{}', found type '{}'",
7594 .{ err_union.data.error_set, inst.ty },
7629 .{ err_union.data.error_set, inst_ty },
75957630 );
75967631 }
75977632 },
......@@ -7602,14 +7637,14 @@ fn wrapErrorUnion(
76027637 return sema.addConstant(dest_type, try Value.Tag.error_union.create(sema.arena, val));
76037638 }
76047639
7605 try sema.requireRuntimeBlock(block, inst.src);
7640 try sema.requireRuntimeBlock(block, inst_src);
76067641
76077642 // we are coercing from E to E!T
7608 if (inst.ty.zigTypeTag() == .ErrorSet) {
7609 var coerced = try sema.coerce(block, err_union.data.error_set, inst, inst.src);
7643 if (inst_ty.zigTypeTag() == .ErrorSet) {
7644 var coerced = try sema.coerce(block, err_union.data.error_set, inst, inst_src);
76107645 return block.addTyOp(.wrap_errunion_err, dest_type, coerced);
76117646 } else {
7612 var coerced = try sema.coerce(block, err_union.data.payload, inst, inst.src);
7647 var coerced = try sema.coerce(block, err_union.data.payload, inst, inst_src);
76137648 return block.addTyOp(.wrap_errunion_payload, dest_type, coerced);
76147649 }
76157650}
......@@ -8081,7 +8116,10 @@ fn typeOf(sema: *Sema, inst: Air.Inst.Ref) Type {
80818116
80828117 .ptrtoint => return Type.initTag(.usize),
80838118
8084 .call => @panic("TODO Sema.typeOf call"),
8119 .call => {
8120 const callee_ty = sema.typeOf(air_datas[i].pl_op.operand);
8121 return callee_ty.fnReturnType();
8122 },
80858123 }
80868124}
80878125
......@@ -8219,3 +8257,12 @@ fn getBreakBlock(sema: *Sema, inst_index: Air.Inst.Index) ?Air.Inst.Index {
82198257 else => return null,
82208258 }
82218259}
8260
8261fn isComptimeKnown(
8262 sema: *Sema,
8263 block: *Scope.Block,
8264 src: LazySrcLoc,
8265 inst: Air.Inst.Ref,
8266) !bool {
8267 return (try sema.resolvePossiblyUndefinedValue(block, src, inst)) != null;
8268}
src/value.zig+1-1
......@@ -1700,7 +1700,7 @@ pub const Value = extern union {
17001700 /// peer type resolution. This is stored in a separate list so that
17011701 /// the items are contiguous in memory and thus can be passed to
17021702 /// `Module.resolvePeerTypes`.
1703 stored_inst_list: std.ArrayListUnmanaged(Air.Inst.Index) = .{},
1703 stored_inst_list: std.ArrayListUnmanaged(Air.Inst.Ref) = .{},
17041704 },
17051705 };
17061706