| ... | @@ -71,27 +71,25 @@ const const_tzir_inst_list = blk: { | ... | @@ -71,27 +71,25 @@ const const_tzir_inst_list = blk: { |
| 71 | | 71 | |
| 72 | pub fn root(sema: *Sema, root_block: *Scope.Block) !void { | 72 | pub fn root(sema: *Sema, root_block: *Scope.Block) !void { |
| 73 | const root_body = sema.code.extra[sema.code.root_start..][0..sema.code.root_len]; | 73 | const root_body = sema.code.extra[sema.code.root_start..][0..sema.code.root_len]; |
| 74 | return sema.body(root_block, root_body); | 74 | return sema.analyzeBody(root_block, root_body); |
| 75 | } | 75 | } |
| 76 | | 76 | |
| 77 | pub fn rootAsType( | 77 | pub fn rootAsType( |
| 78 | sema: *Sema, | 78 | sema: *Sema, |
| 79 | root_block: *Scope.Block, | 79 | root_block: *Scope.Block, |
| 80 | zir_result_inst: zir.Inst.Index, | 80 | zir_result_inst: zir.Inst.Index, |
| 81 | body: zir.Body, | | |
| 82 | ) !Type { | 81 | ) !Type { |
| 83 | const root_body = sema.code.extra[sema.code.root_start..][0..sema.code.root_len]; | 82 | const root_body = sema.code.extra[sema.code.root_start..][0..sema.code.root_len]; |
| 84 | try sema.body(root_block, root_body); | 83 | try sema.analyzeBody(root_block, root_body); |
| 85 | | 84 | |
| 86 | const result_inst = sema.inst_map[zir_result_inst]; | 85 | const result_inst = sema.inst_map[zir_result_inst]; |
| 87 | // Source location is unneeded because resolveConstValue must have already | 86 | // Source location is unneeded because resolveConstValue must have already |
| 88 | // been successfully called when coercing the value to a type, from the | 87 | // been successfully called when coercing the value to a type, from the |
| 89 | // result location. | 88 | // result location. |
| 90 | const val = try sema.resolveConstValue(root_block, .unneeded, result_inst); | 89 | return sema.resolveType(root_block, .unneeded, result_inst); |
| 91 | return val.toType(root_block.arena); | | |
| 92 | } | 90 | } |
| 93 | | 91 | |
| 94 | pub fn body(sema: *Sema, block: *Scope.Block, body: []const zir.Inst.Index) !void { | 92 | pub fn analyzeBody(sema: *Sema, block: *Scope.Block, body: []const zir.Inst.Index) !void { |
| 95 | const tracy = trace(@src()); | 93 | const tracy = trace(@src()); |
| 96 | defer tracy.end(); | 94 | defer tracy.end(); |
| 97 | | 95 | |
| ... | @@ -154,7 +152,7 @@ pub fn body(sema: *Sema, block: *Scope.Block, body: []const zir.Inst.Index) !voi | ... | @@ -154,7 +152,7 @@ pub fn body(sema: *Sema, block: *Scope.Block, body: []const zir.Inst.Index) !voi |
| 154 | .field_val => try sema.zirFieldVal(block, zir_inst), | 152 | .field_val => try sema.zirFieldVal(block, zir_inst), |
| 155 | .field_ptr_named => try sema.zirFieldPtrNamed(block, zir_inst), | 153 | .field_ptr_named => try sema.zirFieldPtrNamed(block, zir_inst), |
| 156 | .field_val_named => try sema.zirFieldValNamed(block, zir_inst), | 154 | .field_val_named => try sema.zirFieldValNamed(block, zir_inst), |
| 157 | .deref => try sema.zirDeref(block, zir_inst), | 155 | .deref_node => try sema.zirDerefNode(block, zir_inst), |
| 158 | .as => try sema.zirAs(block, zir_inst), | 156 | .as => try sema.zirAs(block, zir_inst), |
| 159 | .@"asm" => try sema.zirAsm(block, zir_inst, false), | 157 | .@"asm" => try sema.zirAsm(block, zir_inst, false), |
| 160 | .asm_volatile => try sema.zirAsm(block, zir_inst, true), | 158 | .asm_volatile => try sema.zirAsm(block, zir_inst, true), |
| ... | @@ -162,8 +160,10 @@ pub fn body(sema: *Sema, block: *Scope.Block, body: []const zir.Inst.Index) !voi | ... | @@ -162,8 +160,10 @@ pub fn body(sema: *Sema, block: *Scope.Block, body: []const zir.Inst.Index) !voi |
| 162 | .unreachable_unsafe => try sema.zirUnreachable(block, zir_inst, false), | 160 | .unreachable_unsafe => try sema.zirUnreachable(block, zir_inst, false), |
| 163 | .ret_tok => try sema.zirRetTok(block, zir_inst), | 161 | .ret_tok => try sema.zirRetTok(block, zir_inst), |
| 164 | .ret_node => try sema.zirRetNode(block, zir_inst), | 162 | .ret_node => try sema.zirRetNode(block, zir_inst), |
| 165 | .fn_type => try sema.zirFnType(block, zir_inst), | 163 | .fn_type => try sema.zirFnType(block, zir_inst, false), |
| 166 | .fn_type_cc => try sema.zirFnTypeCc(block, zir_inst), | 164 | .fn_type_cc => try sema.zirFnTypeCc(block, zir_inst, false), |
| | 165 | .fn_type_var_args => try sema.zirFnType(block, zir_inst, true), |
| | 166 | .fn_type_cc_var_args => try sema.zirFnTypeCc(block, zir_inst, true), |
| 167 | .intcast => try sema.zirIntcast(block, zir_inst), | 167 | .intcast => try sema.zirIntcast(block, zir_inst), |
| 168 | .bitcast => try sema.zirBitcast(block, zir_inst), | 168 | .bitcast => try sema.zirBitcast(block, zir_inst), |
| 169 | .floatcast => try sema.zirFloatcast(block, zir_inst), | 169 | .floatcast => try sema.zirFloatcast(block, zir_inst), |
| ... | @@ -230,10 +230,15 @@ pub fn body(sema: *Sema, block: *Scope.Block, body: []const zir.Inst.Index) !voi | ... | @@ -230,10 +230,15 @@ pub fn body(sema: *Sema, block: *Scope.Block, body: []const zir.Inst.Index) !voi |
| 230 | .import => try sema.zirImport(block, zir_inst), | 230 | .import => try sema.zirImport(block, zir_inst), |
| 231 | .bool_and => try sema.zirBoolOp(block, zir_inst, false), | 231 | .bool_and => try sema.zirBoolOp(block, zir_inst, false), |
| 232 | .bool_or => try sema.zirBoolOp(block, zir_inst, true), | 232 | .bool_or => try sema.zirBoolOp(block, zir_inst, true), |
| 233 | .void_value => try sema.mod.constVoid(block.arena, .unneeded), | 233 | .@"await" => try sema.zirAwait(block, zir_inst), |
| 234 | .switchbr => try sema.zirSwitchBr(block, zir_inst, false), | 234 | .nosuspend_await => try sema.zirNosuspendAwait(block, zir_inst), |
| 235 | .switchbr_ref => try sema.zirSwitchBr(block, zir_inst, true), | 235 | .suspend_block_one => @panic("TODO"), |
| 236 | .switch_range => try sema.zirSwitchRange(block, zir_inst), | 236 | .suspend_block => @panic("TODO"), |
| | 237 | .@"resume" => @panic("TODO"), |
| | 238 | // TODO |
| | 239 | //.switchbr => try sema.zirSwitchBr(block, zir_inst, false), |
| | 240 | //.switchbr_ref => try sema.zirSwitchBr(block, zir_inst, true), |
| | 241 | //.switch_range => try sema.zirSwitchRange(block, zir_inst), |
| 237 | }; | 242 | }; |
| 238 | if (map[zir_inst].ty.isNoReturn()) { | 243 | if (map[zir_inst].ty.isNoReturn()) { |
| 239 | break; | 244 | break; |
| ... | @@ -241,7 +246,7 @@ pub fn body(sema: *Sema, block: *Scope.Block, body: []const zir.Inst.Index) !voi | ... | @@ -241,7 +246,7 @@ pub fn body(sema: *Sema, block: *Scope.Block, body: []const zir.Inst.Index) !voi |
| 241 | } | 246 | } |
| 242 | } | 247 | } |
| 243 | | 248 | |
| 244 | fn resolveInst(sema: *Sema, block: *Scope.Block, zir_ref: zir.Inst.Ref) *const ir.Inst { | 249 | pub fn resolveInst(sema: *Sema, block: *Scope.Block, zir_ref: zir.Inst.Ref) *const ir.Inst { |
| 245 | var i = zir_ref; | 250 | var i = zir_ref; |
| 246 | | 251 | |
| 247 | // First section of indexes correspond to a set number of constant values. | 252 | // First section of indexes correspond to a set number of constant values. |
| ... | @@ -277,7 +282,7 @@ fn resolveConstString( | ... | @@ -277,7 +282,7 @@ fn resolveConstString( |
| 277 | const wanted_type = Type.initTag(.const_slice_u8); | 282 | const wanted_type = Type.initTag(.const_slice_u8); |
| 278 | const coerced_inst = try sema.coerce(block, wanted_type, tzir_inst); | 283 | const coerced_inst = try sema.coerce(block, wanted_type, tzir_inst); |
| 279 | const val = try sema.resolveConstValue(block, src, coerced_inst); | 284 | const val = try sema.resolveConstValue(block, src, coerced_inst); |
| 280 | return val.toAllocatedBytes(block.arena); | 285 | return val.toAllocatedBytes(sema.arena); |
| 281 | } | 286 | } |
| 282 | | 287 | |
| 283 | fn resolveType(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, zir_ref: zir.Inst.Ref) !Type { | 288 | fn resolveType(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, zir_ref: zir.Inst.Ref) !Type { |
| ... | @@ -355,7 +360,7 @@ fn zirConst(sema: *Sema, block: *Scope.Block, const_inst: zir.Inst.Index) InnerE | ... | @@ -355,7 +360,7 @@ fn zirConst(sema: *Sema, block: *Scope.Block, const_inst: zir.Inst.Index) InnerE |
| 355 | defer tracy.end(); | 360 | defer tracy.end(); |
| 356 | // Move the TypedValue from old memory to new memory. This allows freeing the ZIR instructions | 361 | // Move the TypedValue from old memory to new memory. This allows freeing the ZIR instructions |
| 357 | // after analysis. | 362 | // after analysis. |
| 358 | const typed_value_copy = try const_inst.positionals.typed_value.copy(block.arena); | 363 | const typed_value_copy = try const_inst.positionals.typed_value.copy(sema.arena); |
| 359 | return sema.mod.constInst(scope, const_inst.base.src, typed_value_copy); | 364 | return sema.mod.constInst(scope, const_inst.base.src, typed_value_copy); |
| 360 | } | 365 | } |
| 361 | | 366 | |
| ... | @@ -377,14 +382,14 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) In | ... | @@ -377,14 +382,14 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) In |
| 377 | return sema.mod.fail(&block.base, inst.base.src, "TODO implement zirCoerceResultPtr", .{}); | 382 | return sema.mod.fail(&block.base, inst.base.src, "TODO implement zirCoerceResultPtr", .{}); |
| 378 | } | 383 | } |
| 379 | | 384 | |
| 380 | fn zirRetPtr(sema: *Module, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { | 385 | fn zirRetPtr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { |
| 381 | const tracy = trace(@src()); | 386 | const tracy = trace(@src()); |
| 382 | defer tracy.end(); | 387 | defer tracy.end(); |
| 383 | | 388 | |
| 384 | try sema.requireFunctionBlock(block, inst.base.src); | 389 | try sema.requireFunctionBlock(block, inst.base.src); |
| 385 | const fn_ty = block.func.?.owner_decl.typed_value.most_recent.typed_value.ty; | 390 | const fn_ty = block.func.?.owner_decl.typed_value.most_recent.typed_value.ty; |
| 386 | const ret_type = fn_ty.fnReturnType(); | 391 | const ret_type = fn_ty.fnReturnType(); |
| 387 | const ptr_type = try sema.mod.simplePtrType(block.arena, ret_type, true, .One); | 392 | const ptr_type = try sema.mod.simplePtrType(sema.arena, ret_type, true, .One); |
| 388 | return block.addNoOp(inst.base.src, ptr_type, .alloc); | 393 | return block.addNoOp(inst.base.src, ptr_type, .alloc); |
| 389 | } | 394 | } |
| 390 | | 395 | |
| ... | @@ -403,7 +408,7 @@ fn zirRetType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError | ... | @@ -403,7 +408,7 @@ fn zirRetType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError |
| 403 | try sema.requireFunctionBlock(block, inst.base.src); | 408 | try sema.requireFunctionBlock(block, inst.base.src); |
| 404 | const fn_ty = b.func.?.owner_decl.typed_value.most_recent.typed_value.ty; | 409 | const fn_ty = b.func.?.owner_decl.typed_value.most_recent.typed_value.ty; |
| 405 | const ret_type = fn_ty.fnReturnType(); | 410 | const ret_type = fn_ty.fnReturnType(); |
| 406 | return sema.mod.constType(block.arena, inst.base.src, ret_type); | 411 | return sema.mod.constType(sema.arena, inst.base.src, ret_type); |
| 407 | } | 412 | } |
| 408 | | 413 | |
| 409 | fn zirEnsureResultUsed(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { | 414 | fn zirEnsureResultUsed(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { |
| ... | @@ -414,7 +419,7 @@ fn zirEnsureResultUsed(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) I | ... | @@ -414,7 +419,7 @@ fn zirEnsureResultUsed(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) I |
| 414 | const operand = sema.resolveInst(block, inst_data.operand); | 419 | const operand = sema.resolveInst(block, inst_data.operand); |
| 415 | const src = inst_data.src(); | 420 | const src = inst_data.src(); |
| 416 | switch (operand.ty.zigTypeTag()) { | 421 | switch (operand.ty.zigTypeTag()) { |
| 417 | .Void, .NoReturn => return sema.mod.constVoid(block.arena, .unneeded), | 422 | .Void, .NoReturn => return sema.mod.constVoid(sema.arena, .unneeded), |
| 418 | else => return sema.mod.fail(&block.base, src, "expression value is ignored", .{}), | 423 | else => return sema.mod.fail(&block.base, src, "expression value is ignored", .{}), |
| 419 | } | 424 | } |
| 420 | } | 425 | } |
| ... | @@ -428,7 +433,7 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Inde | ... | @@ -428,7 +433,7 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Inde |
| 428 | const src = inst_data.src(); | 433 | const src = inst_data.src(); |
| 429 | switch (operand.ty.zigTypeTag()) { | 434 | switch (operand.ty.zigTypeTag()) { |
| 430 | .ErrorSet, .ErrorUnion => return sema.mod.fail(&block.base, src, "error is discarded", .{}), | 435 | .ErrorSet, .ErrorUnion => return sema.mod.fail(&block.base, src, "error is discarded", .{}), |
| 431 | else => return sema.mod.constVoid(block.arena, .unneeded), | 436 | else => return sema.mod.constVoid(sema.arena, .unneeded), |
| 432 | } | 437 | } |
| 433 | } | 438 | } |
| 434 | | 439 | |
| ... | @@ -473,7 +478,7 @@ fn zirAlloc(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!* | ... | @@ -473,7 +478,7 @@ fn zirAlloc(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!* |
| 473 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; | 478 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; |
| 474 | const var_decl_src = inst_data.src(); | 479 | const var_decl_src = inst_data.src(); |
| 475 | const var_type = try sema.resolveType(block, ty_src, inst_data.operand); | 480 | const var_type = try sema.resolveType(block, ty_src, inst_data.operand); |
| 476 | const ptr_type = try sema.mod.simplePtrType(block.arena, var_type, true, .One); | 481 | const ptr_type = try sema.mod.simplePtrType(sema.arena, var_type, true, .One); |
| 477 | try sema.requireRuntimeBlock(block, var_decl_src); | 482 | try sema.requireRuntimeBlock(block, var_decl_src); |
| 478 | return block.addNoOp(var_decl_src, ptr_type, .alloc); | 483 | return block.addNoOp(var_decl_src, ptr_type, .alloc); |
| 479 | } | 484 | } |
| ... | @@ -487,7 +492,7 @@ fn zirAllocMut(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErro | ... | @@ -487,7 +492,7 @@ fn zirAllocMut(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErro |
| 487 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; | 492 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; |
| 488 | const var_type = try sema.resolveType(block, ty_src, inst_data.operand); | 493 | const var_type = try sema.resolveType(block, ty_src, inst_data.operand); |
| 489 | try sema.validateVarType(block, ty_src, var_type); | 494 | try sema.validateVarType(block, ty_src, var_type); |
| 490 | const ptr_type = try sema.mod.simplePtrType(block.arena, var_type, true, .One); | 495 | const ptr_type = try sema.mod.simplePtrType(sema.arena, var_type, true, .One); |
| 491 | try sema.requireRuntimeBlock(block, var_decl_src); | 496 | try sema.requireRuntimeBlock(block, var_decl_src); |
| 492 | return block.addNoOp(var_decl_src, ptr_type, .alloc); | 497 | return block.addNoOp(var_decl_src, ptr_type, .alloc); |
| 493 | } | 498 | } |
| ... | @@ -500,7 +505,7 @@ fn zirAllocInferred( | ... | @@ -500,7 +505,7 @@ fn zirAllocInferred( |
| 500 | ) InnerError!*Inst { | 505 | ) InnerError!*Inst { |
| 501 | const tracy = trace(@src()); | 506 | const tracy = trace(@src()); |
| 502 | defer tracy.end(); | 507 | defer tracy.end(); |
| 503 | const val_payload = try block.arena.create(Value.Payload.InferredAlloc); | 508 | const val_payload = try sema.arena.create(Value.Payload.InferredAlloc); |
| 504 | val_payload.* = .{ | 509 | val_payload.* = .{ |
| 505 | .data = .{}, | 510 | .data = .{}, |
| 506 | }; | 511 | }; |
| ... | @@ -540,13 +545,13 @@ fn zirResolveInferredAlloc( | ... | @@ -540,13 +545,13 @@ fn zirResolveInferredAlloc( |
| 540 | if (var_is_mut) { | 545 | if (var_is_mut) { |
| 541 | try sema.validateVarType(block, ty_src, final_elem_ty); | 546 | try sema.validateVarType(block, ty_src, final_elem_ty); |
| 542 | } | 547 | } |
| 543 | const final_ptr_ty = try sema.mod.simplePtrType(block.arena, final_elem_ty, true, .One); | 548 | const final_ptr_ty = try sema.mod.simplePtrType(sema.arena, final_elem_ty, true, .One); |
| 544 | | 549 | |
| 545 | // Change it to a normal alloc. | 550 | // Change it to a normal alloc. |
| 546 | ptr.ty = final_ptr_ty; | 551 | ptr.ty = final_ptr_ty; |
| 547 | ptr.tag = .alloc; | 552 | ptr.tag = .alloc; |
| 548 | | 553 | |
| 549 | return sema.mod.constVoid(block.arena, .unneeded); | 554 | return sema.mod.constVoid(sema.arena, .unneeded); |
| 550 | } | 555 | } |
| 551 | | 556 | |
| 552 | fn zirStoreToBlockPtr( | 557 | fn zirStoreToBlockPtr( |
| ... | @@ -560,7 +565,7 @@ fn zirStoreToBlockPtr( | ... | @@ -560,7 +565,7 @@ fn zirStoreToBlockPtr( |
| 560 | const bin_inst = sema.code.instructions.items(.data)[inst].bin; | 565 | const bin_inst = sema.code.instructions.items(.data)[inst].bin; |
| 561 | const ptr = sema.resolveInst(bin_inst.lhs); | 566 | const ptr = sema.resolveInst(bin_inst.lhs); |
| 562 | const value = sema.resolveInst(bin_inst.rhs); | 567 | const value = sema.resolveInst(bin_inst.rhs); |
| 563 | const ptr_ty = try sema.mod.simplePtrType(block.arena, value.ty, true, .One); | 568 | const ptr_ty = try sema.mod.simplePtrType(sema.arena, value.ty, true, .One); |
| 564 | // TODO detect when this store should be done at compile-time. For example, | 569 | // TODO detect when this store should be done at compile-time. For example, |
| 565 | // if expressions should force it when the condition is compile-time known. | 570 | // if expressions should force it when the condition is compile-time known. |
| 566 | try sema.requireRuntimeBlock(block, src); | 571 | try sema.requireRuntimeBlock(block, src); |
| ... | @@ -582,9 +587,9 @@ fn zirStoreToInferredPtr( | ... | @@ -582,9 +587,9 @@ fn zirStoreToInferredPtr( |
| 582 | const inferred_alloc = ptr.castTag(.constant).?.val.castTag(.inferred_alloc).?; | 587 | const inferred_alloc = ptr.castTag(.constant).?.val.castTag(.inferred_alloc).?; |
| 583 | // Add the stored instruction to the set we will use to resolve peer types | 588 | // Add the stored instruction to the set we will use to resolve peer types |
| 584 | // for the inferred allocation. | 589 | // for the inferred allocation. |
| 585 | try inferred_alloc.data.stored_inst_list.append(block.arena, value); | 590 | try inferred_alloc.data.stored_inst_list.append(sema.arena, value); |
| 586 | // Create a runtime bitcast instruction with exactly the type the pointer wants. | 591 | // Create a runtime bitcast instruction with exactly the type the pointer wants. |
| 587 | const ptr_ty = try sema.mod.simplePtrType(block.arena, value.ty, true, .One); | 592 | const ptr_ty = try sema.mod.simplePtrType(sema.arena, value.ty, true, .One); |
| 588 | try sema.requireRuntimeBlock(block, src); | 593 | try sema.requireRuntimeBlock(block, src); |
| 589 | const bitcasted_ptr = try block.addUnOp(inst.base.src, ptr_ty, .bitcast, ptr); | 594 | const bitcasted_ptr = try block.addUnOp(inst.base.src, ptr_ty, .bitcast, ptr); |
| 590 | return mod.storePtr(scope, inst.base.src, bitcasted_ptr, value); | 595 | return mod.storePtr(scope, inst.base.src, bitcasted_ptr, value); |
| ... | @@ -601,7 +606,7 @@ fn zirSetEvalBranchQuota( | ... | @@ -601,7 +606,7 @@ fn zirSetEvalBranchQuota( |
| 601 | const quota = try sema.resolveAlreadyCoercedInt(block, src, inst_data.operand, u32); | 606 | const quota = try sema.resolveAlreadyCoercedInt(block, src, inst_data.operand, u32); |
| 602 | if (sema.branch_quota < quota) | 607 | if (sema.branch_quota < quota) |
| 603 | sema.branch_quota = quota; | 608 | sema.branch_quota = quota; |
| 604 | return sema.mod.constVoid(block.arena, .unneeded); | 609 | return sema.mod.constVoid(sema.arena, .unneeded); |
| 605 | } | 610 | } |
| 606 | | 611 | |
| 607 | fn zirStore(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { | 612 | fn zirStore(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { |
| ... | @@ -635,7 +640,7 @@ fn zirParamType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErr | ... | @@ -635,7 +640,7 @@ fn zirParamType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErr |
| 635 | const param_count = fn_ty.fnParamLen(); | 640 | const param_count = fn_ty.fnParamLen(); |
| 636 | if (param_index >= param_count) { | 641 | if (param_index >= param_count) { |
| 637 | if (fn_ty.fnIsVarArgs()) { | 642 | if (fn_ty.fnIsVarArgs()) { |
| 638 | return sema.mod.constType(block.arena, inst.base.src, Type.initTag(.var_args_param)); | 643 | return sema.mod.constType(sema.arena, inst.base.src, Type.initTag(.var_args_param)); |
| 639 | } | 644 | } |
| 640 | return sema.mod.fail(&block.base, inst.base.src, "arg index {d} out of bounds; '{}' has {d} argument(s)", .{ | 645 | return sema.mod.fail(&block.base, inst.base.src, "arg index {d} out of bounds; '{}' has {d} argument(s)", .{ |
| 641 | param_index, | 646 | param_index, |
| ... | @@ -646,7 +651,7 @@ fn zirParamType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErr | ... | @@ -646,7 +651,7 @@ fn zirParamType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErr |
| 646 | | 651 | |
| 647 | // TODO support generic functions | 652 | // TODO support generic functions |
| 648 | const param_type = fn_ty.fnParamType(param_index); | 653 | const param_type = fn_ty.fnParamType(param_index); |
| 649 | return sema.mod.constType(block.arena, inst.base.src, param_type); | 654 | return sema.mod.constType(sema.arena, inst.base.src, param_type); |
| 650 | } | 655 | } |
| 651 | | 656 | |
| 652 | fn zirStr(sema: *Sema, block: *Scope.Block, str_inst: zir.Inst.Index) InnerError!*Inst { | 657 | fn zirStr(sema: *Sema, block: *Scope.Block, str_inst: zir.Inst.Index) InnerError!*Inst { |
| ... | @@ -714,7 +719,7 @@ fn zirCompileLog(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerEr | ... | @@ -714,7 +719,7 @@ fn zirCompileLog(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerEr |
| 714 | .lazy = inst_data.src(), | 719 | .lazy = inst_data.src(), |
| 715 | }; | 720 | }; |
| 716 | } | 721 | } |
| 717 | return sema.mod.constVoid(block.arena, .unneeded); | 722 | return sema.mod.constVoid(sema.arena, .unneeded); |
| 718 | } | 723 | } |
| 719 | | 724 | |
| 720 | fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { | 725 | fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { |
| ... | @@ -724,7 +729,7 @@ fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: zir.Inst.Index) InnerE | ... | @@ -724,7 +729,7 @@ fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: zir.Inst.Index) InnerE |
| 724 | // Reserve space for a Loop instruction so that generated Break instructions can | 729 | // Reserve space for a Loop instruction so that generated Break instructions can |
| 725 | // point to it, even if it doesn't end up getting used because the code ends up being | 730 | // point to it, even if it doesn't end up getting used because the code ends up being |
| 726 | // comptime evaluated. | 731 | // comptime evaluated. |
| 727 | const loop_inst = try parent_block.arena.create(Inst.Loop); | 732 | const loop_inst = try sema.arena.create(Inst.Loop); |
| 728 | loop_inst.* = .{ | 733 | loop_inst.* = .{ |
| 729 | .base = .{ | 734 | .base = .{ |
| 730 | .tag = Inst.Loop.base_tag, | 735 | .tag = Inst.Loop.base_tag, |
| ... | @@ -741,19 +746,19 @@ fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: zir.Inst.Index) InnerE | ... | @@ -741,19 +746,19 @@ fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: zir.Inst.Index) InnerE |
| 741 | .owner_decl = parent_block.owner_decl, | 746 | .owner_decl = parent_block.owner_decl, |
| 742 | .src_decl = parent_block.src_decl, | 747 | .src_decl = parent_block.src_decl, |
| 743 | .instructions = .{}, | 748 | .instructions = .{}, |
| 744 | .arena = parent_block.arena, | 749 | .arena = sema.arena, |
| 745 | .inlining = parent_block.inlining, | 750 | .inlining = parent_block.inlining, |
| 746 | .is_comptime = parent_block.is_comptime, | 751 | .is_comptime = parent_block.is_comptime, |
| 747 | .branch_quota = parent_block.branch_quota, | 752 | .branch_quota = parent_block.branch_quota, |
| 748 | }; | 753 | }; |
| 749 | defer child_block.instructions.deinit(mod.gpa); | 754 | defer child_block.instructions.deinit(mod.gpa); |
| 750 | | 755 | |
| 751 | try sema.body(&child_block, inst.positionals.body); | 756 | try sema.analyzeBody(&child_block, inst.positionals.body); |
| 752 | | 757 | |
| 753 | // Loop repetition is implied so the last instruction may or may not be a noreturn instruction. | 758 | // Loop repetition is implied so the last instruction may or may not be a noreturn instruction. |
| 754 | | 759 | |
| 755 | try parent_block.instructions.append(mod.gpa, &loop_inst.base); | 760 | try parent_block.instructions.append(mod.gpa, &loop_inst.base); |
| 756 | loop_inst.body = .{ .instructions = try parent_block.arena.dupe(*Inst, child_block.instructions.items) }; | 761 | loop_inst.body = .{ .instructions = try sema.arena.dupe(*Inst, child_block.instructions.items) }; |
| 757 | return &loop_inst.base; | 762 | return &loop_inst.base; |
| 758 | } | 763 | } |
| 759 | | 764 | |
| ... | @@ -765,10 +770,10 @@ fn zirBlockFlat(sema: *Sema, parent_block: *Scope.Block, inst: zir.Inst.Index, i | ... | @@ -765,10 +770,10 @@ fn zirBlockFlat(sema: *Sema, parent_block: *Scope.Block, inst: zir.Inst.Index, i |
| 765 | defer child_block.instructions.deinit(mod.gpa); | 770 | defer child_block.instructions.deinit(mod.gpa); |
| 766 | child_block.is_comptime = child_block.is_comptime or is_comptime; | 771 | child_block.is_comptime = child_block.is_comptime or is_comptime; |
| 767 | | 772 | |
| 768 | try sema.body(&child_block, inst.positionals.body); | 773 | try sema.analyzeBody(&child_block, inst.positionals.body); |
| 769 | | 774 | |
| 770 | // Move the analyzed instructions into the parent block arena. | 775 | // Move the analyzed instructions into the parent block arena. |
| 771 | const copied_instructions = try parent_block.arena.dupe(*Inst, child_block.instructions.items); | 776 | const copied_instructions = try sema.arena.dupe(*Inst, child_block.instructions.items); |
| 772 | try parent_block.instructions.appendSlice(mod.gpa, copied_instructions); | 777 | try parent_block.instructions.appendSlice(mod.gpa, copied_instructions); |
| 773 | | 778 | |
| 774 | // The result of a flat block is the last instruction. | 779 | // The result of a flat block is the last instruction. |
| ... | @@ -789,7 +794,7 @@ fn zirBlock( | ... | @@ -789,7 +794,7 @@ fn zirBlock( |
| 789 | // Reserve space for a Block instruction so that generated Break instructions can | 794 | // Reserve space for a Block instruction so that generated Break instructions can |
| 790 | // point to it, even if it doesn't end up getting used because the code ends up being | 795 | // point to it, even if it doesn't end up getting used because the code ends up being |
| 791 | // comptime evaluated. | 796 | // comptime evaluated. |
| 792 | const block_inst = try parent_block.arena.create(Inst.Block); | 797 | const block_inst = try sema.arena.create(Inst.Block); |
| 793 | block_inst.* = .{ | 798 | block_inst.* = .{ |
| 794 | .base = .{ | 799 | .base = .{ |
| 795 | .tag = Inst.Block.base_tag, | 800 | .tag = Inst.Block.base_tag, |
| ... | @@ -806,7 +811,7 @@ fn zirBlock( | ... | @@ -806,7 +811,7 @@ fn zirBlock( |
| 806 | .owner_decl = parent_block.owner_decl, | 811 | .owner_decl = parent_block.owner_decl, |
| 807 | .src_decl = parent_block.src_decl, | 812 | .src_decl = parent_block.src_decl, |
| 808 | .instructions = .{}, | 813 | .instructions = .{}, |
| 809 | .arena = parent_block.arena, | 814 | .arena = sema.arena, |
| 810 | // TODO @as here is working around a stage1 miscompilation bug :( | 815 | // TODO @as here is working around a stage1 miscompilation bug :( |
| 811 | .label = @as(?Scope.Block.Label, Scope.Block.Label{ | 816 | .label = @as(?Scope.Block.Label, Scope.Block.Label{ |
| 812 | .zir_block = inst, | 817 | .zir_block = inst, |
| ... | @@ -826,7 +831,7 @@ fn zirBlock( | ... | @@ -826,7 +831,7 @@ fn zirBlock( |
| 826 | defer merges.results.deinit(mod.gpa); | 831 | defer merges.results.deinit(mod.gpa); |
| 827 | defer merges.br_list.deinit(mod.gpa); | 832 | defer merges.br_list.deinit(mod.gpa); |
| 828 | | 833 | |
| 829 | try sema.body(&child_block, inst.positionals.body); | 834 | try sema.analyzeBody(&child_block, inst.positionals.body); |
| 830 | | 835 | |
| 831 | return analyzeBlockBody(mod, scope, &child_block, merges); | 836 | return analyzeBlockBody(mod, scope, &child_block, merges); |
| 832 | } | 837 | } |
| ... | @@ -847,7 +852,7 @@ fn analyzeBlockBody( | ... | @@ -847,7 +852,7 @@ fn analyzeBlockBody( |
| 847 | if (merges.results.items.len == 0) { | 852 | if (merges.results.items.len == 0) { |
| 848 | // No need for a block instruction. We can put the new instructions | 853 | // No need for a block instruction. We can put the new instructions |
| 849 | // directly into the parent block. | 854 | // directly into the parent block. |
| 850 | const copied_instructions = try parent_block.arena.dupe(*Inst, child_block.instructions.items); | 855 | const copied_instructions = try sema.arena.dupe(*Inst, child_block.instructions.items); |
| 851 | try parent_block.instructions.appendSlice(mod.gpa, copied_instructions); | 856 | try parent_block.instructions.appendSlice(mod.gpa, copied_instructions); |
| 852 | return copied_instructions[copied_instructions.len - 1]; | 857 | return copied_instructions[copied_instructions.len - 1]; |
| 853 | } | 858 | } |
| ... | @@ -858,7 +863,7 @@ fn analyzeBlockBody( | ... | @@ -858,7 +863,7 @@ fn analyzeBlockBody( |
| 858 | if (br_block == merges.block_inst) { | 863 | if (br_block == merges.block_inst) { |
| 859 | // No need for a block instruction. We can put the new instructions directly | 864 | // No need for a block instruction. We can put the new instructions directly |
| 860 | // into the parent block. Here we omit the break instruction. | 865 | // into the parent block. Here we omit the break instruction. |
| 861 | const copied_instructions = try parent_block.arena.dupe(*Inst, child_block.instructions.items[0..last_inst_index]); | 866 | const copied_instructions = try sema.arena.dupe(*Inst, child_block.instructions.items[0..last_inst_index]); |
| 862 | try parent_block.instructions.appendSlice(mod.gpa, copied_instructions); | 867 | try parent_block.instructions.appendSlice(mod.gpa, copied_instructions); |
| 863 | return merges.results.items[0]; | 868 | return merges.results.items[0]; |
| 864 | } | 869 | } |
| ... | @@ -873,7 +878,7 @@ fn analyzeBlockBody( | ... | @@ -873,7 +878,7 @@ fn analyzeBlockBody( |
| 873 | const resolved_ty = try sema.resolvePeerTypes(parent_block, merges.results.items); | 878 | const resolved_ty = try sema.resolvePeerTypes(parent_block, merges.results.items); |
| 874 | merges.block_inst.base.ty = resolved_ty; | 879 | merges.block_inst.base.ty = resolved_ty; |
| 875 | merges.block_inst.body = .{ | 880 | merges.block_inst.body = .{ |
| 876 | .instructions = try parent_block.arena.dupe(*Inst, child_block.instructions.items), | 881 | .instructions = try sema.arena.dupe(*Inst, child_block.instructions.items), |
| 877 | }; | 882 | }; |
| 878 | // Now that the block has its type resolved, we need to go back into all the break | 883 | // Now that the block has its type resolved, we need to go back into all the break |
| 879 | // instructions, and insert type coercion on the operands. | 884 | // instructions, and insert type coercion on the operands. |
| ... | @@ -905,7 +910,7 @@ fn analyzeBlockBody( | ... | @@ -905,7 +910,7 @@ fn analyzeBlockBody( |
| 905 | }, | 910 | }, |
| 906 | .block = merges.block_inst, | 911 | .block = merges.block_inst, |
| 907 | .body = .{ | 912 | .body = .{ |
| 908 | .instructions = try parent_block.arena.dupe(*Inst, coerce_block.instructions.items), | 913 | .instructions = try sema.arena.dupe(*Inst, coerce_block.instructions.items), |
| 909 | }, | 914 | }, |
| 910 | }; | 915 | }; |
| 911 | } | 916 | } |
| ... | @@ -936,7 +941,7 @@ fn zirBreakVoidTok(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) Inner | ... | @@ -936,7 +941,7 @@ fn zirBreakVoidTok(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) Inner |
| 936 | | 941 | |
| 937 | const inst_data = sema.code.instructions.items(.data)[inst].un_tok; | 942 | const inst_data = sema.code.instructions.items(.data)[inst].un_tok; |
| 938 | const zir_block = inst_data.operand; | 943 | const zir_block = inst_data.operand; |
| 939 | const void_inst = try sema.mod.constVoid(block.arena, .unneeded); | 944 | const void_inst = try sema.mod.constVoid(sema.arena, .unneeded); |
| 940 | return analyzeBreak(mod, block, inst_data.src(), zir_block, void_inst); | 945 | return analyzeBreak(mod, block, inst_data.src(), zir_block, void_inst); |
| 941 | } | 946 | } |
| 942 | | 947 | |
| ... | @@ -984,7 +989,7 @@ fn zirDbgStmtNode(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerE | ... | @@ -984,7 +989,7 @@ fn zirDbgStmtNode(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerE |
| 984 | defer tracy.end(); | 989 | defer tracy.end(); |
| 985 | | 990 | |
| 986 | if (b.is_comptime) { | 991 | if (b.is_comptime) { |
| 987 | return sema.mod.constVoid(block.arena, .unneeded); | 992 | return sema.mod.constVoid(sema.arena, .unneeded); |
| 988 | } | 993 | } |
| 989 | | 994 | |
| 990 | const src_node = sema.code.instructions.items(.data)[inst].node; | 995 | const src_node = sema.code.instructions.items(.data)[inst].node; |
| ... | @@ -1090,7 +1095,7 @@ fn analyzeCall( | ... | @@ -1090,7 +1095,7 @@ fn analyzeCall( |
| 1090 | } | 1095 | } |
| 1091 | | 1096 | |
| 1092 | // TODO handle function calls of generic functions | 1097 | // TODO handle function calls of generic functions |
| 1093 | const casted_args = try block.arena.alloc(*Inst, zir_args.len); | 1098 | const casted_args = try sema.arena.alloc(*Inst, zir_args.len); |
| 1094 | for (zir_args) |zir_arg, i| { | 1099 | for (zir_args) |zir_arg, i| { |
| 1095 | // the args are already casted to the result of a param type instruction. | 1100 | // the args are already casted to the result of a param type instruction. |
| 1096 | casted_args[i] = sema.resolveInst(block, zir_arg); | 1101 | casted_args[i] = sema.resolveInst(block, zir_arg); |
| ... | @@ -1117,7 +1122,7 @@ fn analyzeCall( | ... | @@ -1117,7 +1122,7 @@ fn analyzeCall( |
| 1117 | // set to in the `Scope.Block`. | 1122 | // set to in the `Scope.Block`. |
| 1118 | // This block instruction will be used to capture the return value from the | 1123 | // This block instruction will be used to capture the return value from the |
| 1119 | // inlined function. | 1124 | // inlined function. |
| 1120 | const block_inst = try block.arena.create(Inst.Block); | 1125 | const block_inst = try sema.arena.create(Inst.Block); |
| 1121 | block_inst.* = .{ | 1126 | block_inst.* = .{ |
| 1122 | .base = .{ | 1127 | .base = .{ |
| 1123 | .tag = Inst.Block.base_tag, | 1128 | .tag = Inst.Block.base_tag, |
| ... | @@ -1154,7 +1159,7 @@ fn analyzeCall( | ... | @@ -1154,7 +1159,7 @@ fn analyzeCall( |
| 1154 | .owner_decl = scope.ownerDecl().?, | 1159 | .owner_decl = scope.ownerDecl().?, |
| 1155 | .src_decl = module_fn.owner_decl, | 1160 | .src_decl = module_fn.owner_decl, |
| 1156 | .instructions = .{}, | 1161 | .instructions = .{}, |
| 1157 | .arena = block.arena, | 1162 | .arena = sema.arena, |
| 1158 | .label = null, | 1163 | .label = null, |
| 1159 | .inlining = &inlining, | 1164 | .inlining = &inlining, |
| 1160 | .is_comptime = is_comptime_call, | 1165 | .is_comptime = is_comptime_call, |
| ... | @@ -1171,7 +1176,7 @@ fn analyzeCall( | ... | @@ -1171,7 +1176,7 @@ fn analyzeCall( |
| 1171 | | 1176 | |
| 1172 | // This will have return instructions analyzed as break instructions to | 1177 | // This will have return instructions analyzed as break instructions to |
| 1173 | // the block_inst above. | 1178 | // the block_inst above. |
| 1174 | try sema.body(&child_block, module_fn.zir); | 1179 | try sema.analyzeBody(&child_block, module_fn.zir); |
| 1175 | | 1180 | |
| 1176 | return analyzeBlockBody(mod, scope, &child_block, merges); | 1181 | return analyzeBlockBody(mod, scope, &child_block, merges); |
| 1177 | } | 1182 | } |
| ... | @@ -1191,9 +1196,9 @@ fn zirOptionalType(sema: *Sema, block: *Scope.Block, optional: zir.Inst.Index) I | ... | @@ -1191,9 +1196,9 @@ fn zirOptionalType(sema: *Sema, block: *Scope.Block, optional: zir.Inst.Index) I |
| 1191 | | 1196 | |
| 1192 | const inst_data = sema.code.instructions.items(.data)[inst].un_tok; | 1197 | const inst_data = sema.code.instructions.items(.data)[inst].un_tok; |
| 1193 | const child_type = try sema.resolveType(block, inst_data.operand); | 1198 | const child_type = try sema.resolveType(block, inst_data.operand); |
| 1194 | const opt_type = try mod.optionalType(block.arena, child_type); | 1199 | const opt_type = try mod.optionalType(sema.arena, child_type); |
| 1195 | | 1200 | |
| 1196 | return sema.mod.constType(block.arena, inst_data.src(), opt_type); | 1201 | return sema.mod.constType(sema.arena, inst_data.src(), opt_type); |
| 1197 | } | 1202 | } |
| 1198 | | 1203 | |
| 1199 | fn zirOptionalTypeFromPtrElem(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { | 1204 | fn zirOptionalTypeFromPtrElem(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { |
| ... | @@ -1203,9 +1208,9 @@ fn zirOptionalTypeFromPtrElem(sema: *Sema, block: *Scope.Block, inst: zir.Inst.I | ... | @@ -1203,9 +1208,9 @@ fn zirOptionalTypeFromPtrElem(sema: *Sema, block: *Scope.Block, inst: zir.Inst.I |
| 1203 | const inst_data = sema.code.instructions.items(.data)[inst].un_tok; | 1208 | const inst_data = sema.code.instructions.items(.data)[inst].un_tok; |
| 1204 | const ptr = sema.resolveInst(block, inst_data.operand); | 1209 | const ptr = sema.resolveInst(block, inst_data.operand); |
| 1205 | const elem_ty = ptr.ty.elemType(); | 1210 | const elem_ty = ptr.ty.elemType(); |
| 1206 | const opt_ty = try mod.optionalType(block.arena, elem_ty); | 1211 | const opt_ty = try mod.optionalType(sema.arena, elem_ty); |
| 1207 | | 1212 | |
| 1208 | return sema.mod.constType(block.arena, inst_data.src(), opt_ty); | 1213 | return sema.mod.constType(sema.arena, inst_data.src(), opt_ty); |
| 1209 | } | 1214 | } |
| 1210 | | 1215 | |
| 1211 | fn zirArrayType(sema: *Sema, block: *Scope.Block, array: zir.Inst.Index) InnerError!*Inst { | 1216 | fn zirArrayType(sema: *Sema, block: *Scope.Block, array: zir.Inst.Index) InnerError!*Inst { |
| ... | @@ -1215,7 +1220,7 @@ fn zirArrayType(sema: *Sema, block: *Scope.Block, array: zir.Inst.Index) InnerEr | ... | @@ -1215,7 +1220,7 @@ fn zirArrayType(sema: *Sema, block: *Scope.Block, array: zir.Inst.Index) InnerEr |
| 1215 | const len = try resolveInstConst(mod, scope, array.positionals.lhs); | 1220 | const len = try resolveInstConst(mod, scope, array.positionals.lhs); |
| 1216 | const elem_type = try sema.resolveType(block, array.positionals.rhs); | 1221 | const elem_type = try sema.resolveType(block, array.positionals.rhs); |
| 1217 | | 1222 | |
| 1218 | return sema.mod.constType(block.arena, array.base.src, try mod.arrayType(scope, len.val.toUnsignedInt(), null, elem_type)); | 1223 | return sema.mod.constType(sema.arena, array.base.src, try mod.arrayType(scope, len.val.toUnsignedInt(), null, elem_type)); |
| 1219 | } | 1224 | } |
| 1220 | | 1225 | |
| 1221 | fn zirArrayTypeSentinel(sema: *Sema, block: *Scope.Block, array: zir.Inst.Index) InnerError!*Inst { | 1226 | fn zirArrayTypeSentinel(sema: *Sema, block: *Scope.Block, array: zir.Inst.Index) InnerError!*Inst { |
| ... | @@ -1226,7 +1231,7 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Scope.Block, array: zir.Inst.Index) | ... | @@ -1226,7 +1231,7 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Scope.Block, array: zir.Inst.Index) |
| 1226 | const sentinel = try resolveInstConst(mod, scope, array.positionals.sentinel); | 1231 | const sentinel = try resolveInstConst(mod, scope, array.positionals.sentinel); |
| 1227 | const elem_type = try sema.resolveType(block, array.positionals.elem_type); | 1232 | const elem_type = try sema.resolveType(block, array.positionals.elem_type); |
| 1228 | | 1233 | |
| 1229 | return sema.mod.constType(block.arena, array.base.src, try mod.arrayType(scope, len.val.toUnsignedInt(), sentinel.val, elem_type)); | 1234 | return sema.mod.constType(sema.arena, array.base.src, try mod.arrayType(scope, len.val.toUnsignedInt(), sentinel.val, elem_type)); |
| 1230 | } | 1235 | } |
| 1231 | | 1236 | |
| 1232 | fn zirErrorUnionType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { | 1237 | fn zirErrorUnionType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { |
| ... | @@ -1241,7 +1246,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) Inn | ... | @@ -1241,7 +1246,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) Inn |
| 1241 | return sema.mod.fail(&block.base, inst.base.src, "expected error set type, found {}", .{error_union.elemType()}); | 1246 | return sema.mod.fail(&block.base, inst.base.src, "expected error set type, found {}", .{error_union.elemType()}); |
| 1242 | } | 1247 | } |
| 1243 | | 1248 | |
| 1244 | return sema.mod.constType(block.arena, inst.base.src, try mod.errorUnionType(scope, error_union, payload)); | 1249 | return sema.mod.constType(sema.arena, inst.base.src, try mod.errorUnionType(scope, error_union, payload)); |
| 1245 | } | 1250 | } |
| 1246 | | 1251 | |
| 1247 | fn zirAnyframeType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { | 1252 | fn zirAnyframeType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { |
| ... | @@ -1252,9 +1257,9 @@ fn zirAnyframeType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) Inner | ... | @@ -1252,9 +1257,9 @@ fn zirAnyframeType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) Inner |
| 1252 | const src = inst_data.src(); | 1257 | const src = inst_data.src(); |
| 1253 | const operand_src: LazySrcLoc = .{ .node_offset_anyframe_type = inst_data.src_node }; | 1258 | const operand_src: LazySrcLoc = .{ .node_offset_anyframe_type = inst_data.src_node }; |
| 1254 | const return_type = try sema.resolveType(block, operand_src, inst_data.operand); | 1259 | const return_type = try sema.resolveType(block, operand_src, inst_data.operand); |
| 1255 | const anyframe_type = try sema.mod.anyframeType(block.arena, return_type); | 1260 | const anyframe_type = try sema.mod.anyframeType(sema.arena, return_type); |
| 1256 | | 1261 | |
| 1257 | return sema.mod.constType(block.arena, src, anyframe_type); | 1262 | return sema.mod.constType(sema.arena, src, anyframe_type); |
| 1258 | } | 1263 | } |
| 1259 | | 1264 | |
| 1260 | fn zirErrorSet(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { | 1265 | fn zirErrorSet(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { |
| ... | @@ -1296,10 +1301,10 @@ fn zirErrorValue(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerEr | ... | @@ -1296,10 +1301,10 @@ fn zirErrorValue(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerEr |
| 1296 | | 1301 | |
| 1297 | // Create an anonymous error set type with only this error value, and return the value. | 1302 | // Create an anonymous error set type with only this error value, and return the value. |
| 1298 | const entry = try mod.getErrorValue(inst.positionals.name); | 1303 | const entry = try mod.getErrorValue(inst.positionals.name); |
| 1299 | const result_type = try Type.Tag.error_set_single.create(block.arena, entry.key); | 1304 | const result_type = try Type.Tag.error_set_single.create(sema.arena, entry.key); |
| 1300 | return sema.mod.constInst(scope, inst.base.src, .{ | 1305 | return sema.mod.constInst(scope, inst.base.src, .{ |
| 1301 | .ty = result_type, | 1306 | .ty = result_type, |
| 1302 | .val = try Value.Tag.@"error".create(block.arena, .{ | 1307 | .val = try Value.Tag.@"error".create(sema.arena, .{ |
| 1303 | .name = entry.key, | 1308 | .name = entry.key, |
| 1304 | }), | 1309 | }), |
| 1305 | }); | 1310 | }); |
| ... | @@ -1388,10 +1393,10 @@ fn zirEnumLiteral(sema: *Sema, block: *Scope.Block, zir_inst: zir.Inst.Index) In | ... | @@ -1388,10 +1393,10 @@ fn zirEnumLiteral(sema: *Sema, block: *Scope.Block, zir_inst: zir.Inst.Index) In |
| 1388 | const tracy = trace(@src()); | 1393 | const tracy = trace(@src()); |
| 1389 | defer tracy.end(); | 1394 | defer tracy.end(); |
| 1390 | | 1395 | |
| 1391 | const duped_name = try block.arena.dupe(u8, inst.positionals.name); | 1396 | const duped_name = try sema.arena.dupe(u8, inst.positionals.name); |
| 1392 | return sema.mod.constInst(scope, inst.base.src, .{ | 1397 | return sema.mod.constInst(scope, inst.base.src, .{ |
| 1393 | .ty = Type.initTag(.enum_literal), | 1398 | .ty = Type.initTag(.enum_literal), |
| 1394 | .val = try Value.Tag.enum_literal.create(block.arena, duped_name), | 1399 | .val = try Value.Tag.enum_literal.create(sema.arena, duped_name), |
| 1395 | }); | 1400 | }); |
| 1396 | } | 1401 | } |
| 1397 | | 1402 | |
| ... | @@ -1415,11 +1420,11 @@ fn zirOptionalPayloadPtr( | ... | @@ -1415,11 +1420,11 @@ fn zirOptionalPayloadPtr( |
| 1415 | return sema.mod.fail(&block.base, src, "expected optional type, found {}", .{opt_type}); | 1420 | return sema.mod.fail(&block.base, src, "expected optional type, found {}", .{opt_type}); |
| 1416 | } | 1421 | } |
| 1417 | | 1422 | |
| 1418 | const child_type = try opt_type.optionalChildAlloc(block.arena); | 1423 | const child_type = try opt_type.optionalChildAlloc(sema.arena); |
| 1419 | const child_pointer = try sema.mod.simplePtrType(block.arena, child_type, !optional_ptr.ty.isConstPtr(), .One); | 1424 | const child_pointer = try sema.mod.simplePtrType(sema.arena, child_type, !optional_ptr.ty.isConstPtr(), .One); |
| 1420 | | 1425 | |
| 1421 | if (optional_ptr.value()) |pointer_val| { | 1426 | if (optional_ptr.value()) |pointer_val| { |
| 1422 | const val = try pointer_val.pointerDeref(block.arena); | 1427 | const val = try pointer_val.pointerDeref(sema.arena); |
| 1423 | if (val.isNull()) { | 1428 | if (val.isNull()) { |
| 1424 | return sema.mod.fail(&block.base, src, "unable to unwrap null", .{}); | 1429 | return sema.mod.fail(&block.base, src, "unable to unwrap null", .{}); |
| 1425 | } | 1430 | } |
| ... | @@ -1456,7 +1461,7 @@ fn zirOptionalPayload( | ... | @@ -1456,7 +1461,7 @@ fn zirOptionalPayload( |
| 1456 | return sema.mod.fail(&block.base, src, "expected optional type, found {}", .{opt_type}); | 1461 | return sema.mod.fail(&block.base, src, "expected optional type, found {}", .{opt_type}); |
| 1457 | } | 1462 | } |
| 1458 | | 1463 | |
| 1459 | const child_type = try opt_type.optionalChildAlloc(block.arena); | 1464 | const child_type = try opt_type.optionalChildAlloc(sema.arena); |
| 1460 | | 1465 | |
| 1461 | if (operand.value()) |val| { | 1466 | if (operand.value()) |val| { |
| 1462 | if (val.isNull()) { | 1467 | if (val.isNull()) { |
| ... | @@ -1528,10 +1533,10 @@ fn zirErrUnionPayloadPtr( | ... | @@ -1528,10 +1533,10 @@ fn zirErrUnionPayloadPtr( |
| 1528 | if (operand.ty.elemType().zigTypeTag() != .ErrorUnion) | 1533 | if (operand.ty.elemType().zigTypeTag() != .ErrorUnion) |
| 1529 | return sema.mod.fail(&block.base, src, "expected error union type, found {}", .{operand.ty.elemType()}); | 1534 | return sema.mod.fail(&block.base, src, "expected error union type, found {}", .{operand.ty.elemType()}); |
| 1530 | | 1535 | |
| 1531 | const operand_pointer_ty = try sema.mod.simplePtrType(block.arena, operand.ty.elemType().castTag(.error_union).?.data.payload, !operand.ty.isConstPtr(), .One); | 1536 | const operand_pointer_ty = try sema.mod.simplePtrType(sema.arena, operand.ty.elemType().castTag(.error_union).?.data.payload, !operand.ty.isConstPtr(), .One); |
| 1532 | | 1537 | |
| 1533 | if (operand.value()) |pointer_val| { | 1538 | if (operand.value()) |pointer_val| { |
| 1534 | const val = try pointer_val.pointerDeref(block.arena); | 1539 | const val = try pointer_val.pointerDeref(sema.arena); |
| 1535 | if (val.getError()) |name| { | 1540 | if (val.getError()) |name| { |
| 1536 | return sema.mod.fail(&block.base, src, "caught unexpected error '{s}'", .{name}); | 1541 | return sema.mod.fail(&block.base, src, "caught unexpected error '{s}'", .{name}); |
| 1537 | } | 1542 | } |
| ... | @@ -1540,7 +1545,7 @@ fn zirErrUnionPayloadPtr( | ... | @@ -1540,7 +1545,7 @@ fn zirErrUnionPayloadPtr( |
| 1540 | return sema.mod.constInst(scope, src, .{ | 1545 | return sema.mod.constInst(scope, src, .{ |
| 1541 | .ty = operand_pointer_ty, | 1546 | .ty = operand_pointer_ty, |
| 1542 | .val = try Value.Tag.ref_val.create( | 1547 | .val = try Value.Tag.ref_val.create( |
| 1543 | block.arena, | 1548 | sema.arena, |
| 1544 | data, | 1549 | data, |
| 1545 | ), | 1550 | ), |
| 1546 | }); | 1551 | }); |
| ... | @@ -1592,7 +1597,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) In | ... | @@ -1592,7 +1597,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) In |
| 1592 | return sema.mod.fail(&block.base, src, "expected error union type, found {}", .{operand.ty.elemType()}); | 1597 | return sema.mod.fail(&block.base, src, "expected error union type, found {}", .{operand.ty.elemType()}); |
| 1593 | | 1598 | |
| 1594 | if (operand.value()) |pointer_val| { | 1599 | if (operand.value()) |pointer_val| { |
| 1595 | const val = try pointer_val.pointerDeref(block.arena); | 1600 | const val = try pointer_val.pointerDeref(sema.arena); |
| 1596 | assert(val.getError() != null); | 1601 | assert(val.getError() != null); |
| 1597 | const data = val.castTag(.error_union).?.data; | 1602 | const data = val.castTag(.error_union).?.data; |
| 1598 | return sema.mod.constInst(scope, src, .{ | 1603 | return sema.mod.constInst(scope, src, .{ |
| ... | @@ -1617,40 +1622,46 @@ fn zirEnsureErrPayloadVoid(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Inde | ... | @@ -1617,40 +1622,46 @@ fn zirEnsureErrPayloadVoid(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Inde |
| 1617 | if (operand.ty.castTag(.error_union).?.data.payload.zigTypeTag() != .Void) { | 1622 | if (operand.ty.castTag(.error_union).?.data.payload.zigTypeTag() != .Void) { |
| 1618 | return sema.mod.fail(&block.base, src, "expression value is ignored", .{}); | 1623 | return sema.mod.fail(&block.base, src, "expression value is ignored", .{}); |
| 1619 | } | 1624 | } |
| 1620 | return sema.mod.constVoid(block.arena, .unneeded); | 1625 | return sema.mod.constVoid(sema.arena, .unneeded); |
| 1621 | } | 1626 | } |
| 1622 | | 1627 | |
| 1623 | fn zirFnType(sema: *Sema, block: *Scope.Block, fntype: zir.Inst.Index, var_args: bool) InnerError!*Inst { | 1628 | fn zirFnType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index, var_args: bool) InnerError!*Inst { |
| 1624 | const tracy = trace(@src()); | 1629 | const tracy = trace(@src()); |
| 1625 | defer tracy.end(); | 1630 | defer tracy.end(); |
| 1626 | | 1631 | |
| 1627 | return fnTypeCommon( | 1632 | const inst_data = sema.code.instructions.items(.data)[inst].fn_type; |
| 1628 | mod, | 1633 | const extra = sema.code.extraData(zir.Inst.FnType, inst_data.payload_index); |
| 1629 | scope, | 1634 | const param_types = sema.code.extra[extra.end..][0..extra.data.param_types_len]; |
| 1630 | &fntype.base, | 1635 | |
| 1631 | fntype.positionals.param_types, | 1636 | return sema.fnTypeCommon( |
| 1632 | fntype.positionals.return_type, | 1637 | block, |
| | 1638 | .unneeded, |
| | 1639 | param_types, |
| | 1640 | inst_data.return_type, |
| 1633 | .Unspecified, | 1641 | .Unspecified, |
| 1634 | var_args, | 1642 | var_args, |
| 1635 | ); | 1643 | ); |
| 1636 | } | 1644 | } |
| 1637 | | 1645 | |
| 1638 | fn zirFnTypeCc(sema: *Sema, block: *Scope.Block, fntype: zir.Inst.Index, var_args: bool) InnerError!*Inst { | 1646 | fn zirFnTypeCc(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index, var_args: bool) InnerError!*Inst { |
| 1639 | const tracy = trace(@src()); | 1647 | const tracy = trace(@src()); |
| 1640 | defer tracy.end(); | 1648 | defer tracy.end(); |
| 1641 | | 1649 | |
| 1642 | const cc_tv = try resolveInstConst(mod, scope, fntype.positionals.cc); | 1650 | const inst_data = sema.code.instructions.items(.data)[inst].fn_type; |
| | 1651 | const extra = sema.code.extraData(zir.Inst.FnTypeCc, inst_data.payload_index); |
| | 1652 | const param_types = sema.code.extra[extra.end..][0..extra.data.param_types_len]; |
| | 1653 | |
| | 1654 | const cc_tv = try resolveInstConst(mod, scope, extra.data.cc); |
| 1643 | // TODO once we're capable of importing and analyzing decls from | 1655 | // TODO once we're capable of importing and analyzing decls from |
| 1644 | // std.builtin, this needs to change | 1656 | // std.builtin, this needs to change |
| 1645 | const cc_str = cc_tv.val.castTag(.enum_literal).?.data; | 1657 | const cc_str = cc_tv.val.castTag(.enum_literal).?.data; |
| 1646 | const cc = std.meta.stringToEnum(std.builtin.CallingConvention, cc_str) orelse | 1658 | const cc = std.meta.stringToEnum(std.builtin.CallingConvention, cc_str) orelse |
| 1647 | return sema.mod.fail(&block.base, fntype.positionals.cc.src, "Unknown calling convention {s}", .{cc_str}); | 1659 | return sema.mod.fail(&block.base, .todo, "Unknown calling convention {s}", .{cc_str}); |
| 1648 | return fnTypeCommon( | 1660 | return sema.fnTypeCommon( |
| 1649 | mod, | 1661 | block, |
| 1650 | scope, | 1662 | .unneeded, |
| 1651 | &fntype.base, | 1663 | param_types, |
| 1652 | fntype.positionals.param_types, | 1664 | inst_data.return_type, |
| 1653 | fntype.positionals.return_type, | | |
| 1654 | cc, | 1665 | cc, |
| 1655 | var_args, | 1666 | var_args, |
| 1656 | ); | 1667 | ); |
| ... | @@ -1659,9 +1670,9 @@ fn zirFnTypeCc(sema: *Sema, block: *Scope.Block, fntype: zir.Inst.Index, var_arg | ... | @@ -1659,9 +1670,9 @@ fn zirFnTypeCc(sema: *Sema, block: *Scope.Block, fntype: zir.Inst.Index, var_arg |
| 1659 | fn fnTypeCommon( | 1670 | fn fnTypeCommon( |
| 1660 | sema: *Sema, | 1671 | sema: *Sema, |
| 1661 | block: *Scope.Block, | 1672 | block: *Scope.Block, |
| 1662 | zir_inst: zir.Inst.Index, | 1673 | src: LazySrcLoc, |
| 1663 | zir_param_types: []zir.Inst.Index, | 1674 | zir_param_types: []const zir.Inst.Ref, |
| 1664 | zir_return_type: zir.Inst.Index, | 1675 | zir_return_type: zir.Inst.Ref, |
| 1665 | cc: std.builtin.CallingConvention, | 1676 | cc: std.builtin.CallingConvention, |
| 1666 | var_args: bool, | 1677 | var_args: bool, |
| 1667 | ) InnerError!*Inst { | 1678 | ) InnerError!*Inst { |
| ... | @@ -1670,39 +1681,39 @@ fn fnTypeCommon( | ... | @@ -1670,39 +1681,39 @@ fn fnTypeCommon( |
| 1670 | // Hot path for some common function types. | 1681 | // Hot path for some common function types. |
| 1671 | if (zir_param_types.len == 0 and !var_args) { | 1682 | if (zir_param_types.len == 0 and !var_args) { |
| 1672 | if (return_type.zigTypeTag() == .NoReturn and cc == .Unspecified) { | 1683 | if (return_type.zigTypeTag() == .NoReturn and cc == .Unspecified) { |
| 1673 | return sema.mod.constType(block.arena, zir_inst.src, Type.initTag(.fn_noreturn_no_args)); | 1684 | return sema.mod.constType(sema.arena, src, Type.initTag(.fn_noreturn_no_args)); |
| 1674 | } | 1685 | } |
| 1675 | | 1686 | |
| 1676 | if (return_type.zigTypeTag() == .Void and cc == .Unspecified) { | 1687 | if (return_type.zigTypeTag() == .Void and cc == .Unspecified) { |
| 1677 | return sema.mod.constType(block.arena, zir_inst.src, Type.initTag(.fn_void_no_args)); | 1688 | return sema.mod.constType(sema.arena, src, Type.initTag(.fn_void_no_args)); |
| 1678 | } | 1689 | } |
| 1679 | | 1690 | |
| 1680 | if (return_type.zigTypeTag() == .NoReturn and cc == .Naked) { | 1691 | if (return_type.zigTypeTag() == .NoReturn and cc == .Naked) { |
| 1681 | return sema.mod.constType(block.arena, zir_inst.src, Type.initTag(.fn_naked_noreturn_no_args)); | 1692 | return sema.mod.constType(sema.arena, src, Type.initTag(.fn_naked_noreturn_no_args)); |
| 1682 | } | 1693 | } |
| 1683 | | 1694 | |
| 1684 | if (return_type.zigTypeTag() == .Void and cc == .C) { | 1695 | if (return_type.zigTypeTag() == .Void and cc == .C) { |
| 1685 | return sema.mod.constType(block.arena, zir_inst.src, Type.initTag(.fn_ccc_void_no_args)); | 1696 | return sema.mod.constType(sema.arena, src, Type.initTag(.fn_ccc_void_no_args)); |
| 1686 | } | 1697 | } |
| 1687 | } | 1698 | } |
| 1688 | | 1699 | |
| 1689 | const param_types = try block.arena.alloc(Type, zir_param_types.len); | 1700 | const param_types = try sema.arena.alloc(Type, zir_param_types.len); |
| 1690 | for (zir_param_types) |param_type, i| { | 1701 | for (zir_param_types) |param_type, i| { |
| 1691 | const resolved = try sema.resolveType(block, param_type); | 1702 | const resolved = try sema.resolveType(block, param_type); |
| 1692 | // TODO skip for comptime params | 1703 | // TODO skip for comptime params |
| 1693 | if (!resolved.isValidVarType(false)) { | 1704 | if (!resolved.isValidVarType(false)) { |
| 1694 | return sema.mod.fail(&block.base, param_type.src, "parameter of type '{}' must be declared comptime", .{resolved}); | 1705 | return sema.mod.fail(&block.base, .todo, "parameter of type '{}' must be declared comptime", .{resolved}); |
| 1695 | } | 1706 | } |
| 1696 | param_types[i] = resolved; | 1707 | param_types[i] = resolved; |
| 1697 | } | 1708 | } |
| 1698 | | 1709 | |
| 1699 | const fn_ty = try Type.Tag.function.create(block.arena, .{ | 1710 | const fn_ty = try Type.Tag.function.create(sema.arena, .{ |
| 1700 | .param_types = param_types, | 1711 | .param_types = param_types, |
| 1701 | .return_type = return_type, | 1712 | .return_type = return_type, |
| 1702 | .cc = cc, | 1713 | .cc = cc, |
| 1703 | .is_var_args = var_args, | 1714 | .is_var_args = var_args, |
| 1704 | }); | 1715 | }); |
| 1705 | return sema.mod.constType(block.arena, zir_inst.src, fn_ty); | 1716 | return sema.mod.constType(sema.arena, src, fn_ty); |
| 1706 | } | 1717 | } |
| 1707 | | 1718 | |
| 1708 | fn zirAs(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { | 1719 | fn zirAs(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { |
| ... | @@ -1981,11 +1992,11 @@ fn zirSwitchRange(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerE | ... | @@ -1981,11 +1992,11 @@ fn zirSwitchRange(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerE |
| 1981 | | 1992 | |
| 1982 | switch (start.ty.zigTypeTag()) { | 1993 | switch (start.ty.zigTypeTag()) { |
| 1983 | .Int, .ComptimeInt => {}, | 1994 | .Int, .ComptimeInt => {}, |
| 1984 | else => return sema.mod.constVoid(block.arena, .unneeded), | 1995 | else => return sema.mod.constVoid(sema.arena, .unneeded), |
| 1985 | } | 1996 | } |
| 1986 | switch (end.ty.zigTypeTag()) { | 1997 | switch (end.ty.zigTypeTag()) { |
| 1987 | .Int, .ComptimeInt => {}, | 1998 | .Int, .ComptimeInt => {}, |
| 1988 | else => return sema.mod.constVoid(block.arena, .unneeded), | 1999 | else => return sema.mod.constVoid(sema.arena, .unneeded), |
| 1989 | } | 2000 | } |
| 1990 | // .switch_range must be inside a comptime scope | 2001 | // .switch_range must be inside a comptime scope |
| 1991 | const start_val = start.value().?; | 2002 | const start_val = start.value().?; |
| ... | @@ -1993,7 +2004,7 @@ fn zirSwitchRange(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerE | ... | @@ -1993,7 +2004,7 @@ fn zirSwitchRange(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerE |
| 1993 | if (start_val.compare(.gte, end_val)) { | 2004 | if (start_val.compare(.gte, end_val)) { |
| 1994 | return sema.mod.fail(&block.base, inst.base.src, "range start value must be smaller than the end value", .{}); | 2005 | return sema.mod.fail(&block.base, inst.base.src, "range start value must be smaller than the end value", .{}); |
| 1995 | } | 2006 | } |
| 1996 | return sema.mod.constVoid(block.arena, .unneeded); | 2007 | return sema.mod.constVoid(sema.arena, .unneeded); |
| 1997 | } | 2008 | } |
| 1998 | | 2009 | |
| 1999 | fn zirSwitchBr( | 2010 | fn zirSwitchBr( |
| ... | @@ -2021,22 +2032,22 @@ fn zirSwitchBr( | ... | @@ -2021,22 +2032,22 @@ fn zirSwitchBr( |
| 2021 | const item = try sema.resolveConstValue(parent_block, case_src, casted); | 2032 | const item = try sema.resolveConstValue(parent_block, case_src, casted); |
| 2022 | | 2033 | |
| 2023 | if (target_val.eql(item)) { | 2034 | if (target_val.eql(item)) { |
| 2024 | try sema.body(scope.cast(Scope.Block).?, case.body); | 2035 | try sema.analyzeBody(scope.cast(Scope.Block).?, case.body); |
| 2025 | return mod.constNoReturn(scope, inst.base.src); | 2036 | return mod.constNoReturn(scope, inst.base.src); |
| 2026 | } | 2037 | } |
| 2027 | } | 2038 | } |
| 2028 | try sema.body(scope.cast(Scope.Block).?, inst.positionals.else_body); | 2039 | try sema.analyzeBody(scope.cast(Scope.Block).?, inst.positionals.else_body); |
| 2029 | return mod.constNoReturn(scope, inst.base.src); | 2040 | return mod.constNoReturn(scope, inst.base.src); |
| 2030 | } | 2041 | } |
| 2031 | | 2042 | |
| 2032 | if (inst.positionals.cases.len == 0) { | 2043 | if (inst.positionals.cases.len == 0) { |
| 2033 | // no cases just analyze else_branch | 2044 | // no cases just analyze else_branch |
| 2034 | try sema.body(scope.cast(Scope.Block).?, inst.positionals.else_body); | 2045 | try sema.analyzeBody(scope.cast(Scope.Block).?, inst.positionals.else_body); |
| 2035 | return mod.constNoReturn(scope, inst.base.src); | 2046 | return mod.constNoReturn(scope, inst.base.src); |
| 2036 | } | 2047 | } |
| 2037 | | 2048 | |
| 2038 | try sema.requireRuntimeBlock(parent_block, inst.base.src); | 2049 | try sema.requireRuntimeBlock(parent_block, inst.base.src); |
| 2039 | const cases = try parent_block.arena.alloc(Inst.SwitchBr.Case, inst.positionals.cases.len); | 2050 | const cases = try sema.arena.alloc(Inst.SwitchBr.Case, inst.positionals.cases.len); |
| 2040 | | 2051 | |
| 2041 | var case_block: Scope.Block = .{ | 2052 | var case_block: Scope.Block = .{ |
| 2042 | .parent = parent_block, | 2053 | .parent = parent_block, |
| ... | @@ -2045,7 +2056,7 @@ fn zirSwitchBr( | ... | @@ -2045,7 +2056,7 @@ fn zirSwitchBr( |
| 2045 | .owner_decl = parent_block.owner_decl, | 2056 | .owner_decl = parent_block.owner_decl, |
| 2046 | .src_decl = parent_block.src_decl, | 2057 | .src_decl = parent_block.src_decl, |
| 2047 | .instructions = .{}, | 2058 | .instructions = .{}, |
| 2048 | .arena = parent_block.arena, | 2059 | .arena = sema.arena, |
| 2049 | .inlining = parent_block.inlining, | 2060 | .inlining = parent_block.inlining, |
| 2050 | .is_comptime = parent_block.is_comptime, | 2061 | .is_comptime = parent_block.is_comptime, |
| 2051 | .branch_quota = parent_block.branch_quota, | 2062 | .branch_quota = parent_block.branch_quota, |
| ... | @@ -2060,19 +2071,19 @@ fn zirSwitchBr( | ... | @@ -2060,19 +2071,19 @@ fn zirSwitchBr( |
| 2060 | const casted = try sema.coerce(scope, target.ty, resolved); | 2071 | const casted = try sema.coerce(scope, target.ty, resolved); |
| 2061 | const item = try sema.resolveConstValue(parent_block, case_src, casted); | 2072 | const item = try sema.resolveConstValue(parent_block, case_src, casted); |
| 2062 | | 2073 | |
| 2063 | try sema.body(&case_block, case.body); | 2074 | try sema.analyzeBody(&case_block, case.body); |
| 2064 | | 2075 | |
| 2065 | cases[i] = .{ | 2076 | cases[i] = .{ |
| 2066 | .item = item, | 2077 | .item = item, |
| 2067 | .body = .{ .instructions = try parent_block.arena.dupe(*Inst, case_block.instructions.items) }, | 2078 | .body = .{ .instructions = try sema.arena.dupe(*Inst, case_block.instructions.items) }, |
| 2068 | }; | 2079 | }; |
| 2069 | } | 2080 | } |
| 2070 | | 2081 | |
| 2071 | case_block.instructions.items.len = 0; | 2082 | case_block.instructions.items.len = 0; |
| 2072 | try sema.body(&case_block, inst.positionals.else_body); | 2083 | try sema.analyzeBody(&case_block, inst.positionals.else_body); |
| 2073 | | 2084 | |
| 2074 | const else_body: ir.Body = .{ | 2085 | const else_body: ir.Body = .{ |
| 2075 | .instructions = try parent_block.arena.dupe(*Inst, case_block.instructions.items), | 2086 | .instructions = try sema.arena.dupe(*Inst, case_block.instructions.items), |
| 2076 | }; | 2087 | }; |
| 2077 | | 2088 | |
| 2078 | return mod.addSwitchBr(parent_block, inst.base.src, target, cases, else_body); | 2089 | return mod.addSwitchBr(parent_block, inst.base.src, target, cases, else_body); |
| ... | @@ -2232,7 +2243,7 @@ fn zirImport(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError! | ... | @@ -2232,7 +2243,7 @@ fn zirImport(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError! |
| 2232 | return sema.mod.fail(&block.base, src, "unable to open '{s}': {s}", .{ operand, @errorName(err) }); | 2243 | return sema.mod.fail(&block.base, src, "unable to open '{s}': {s}", .{ operand, @errorName(err) }); |
| 2233 | }, | 2244 | }, |
| 2234 | }; | 2245 | }; |
| 2235 | return sema.mod.constType(block.arena, src, file_scope.root_container.ty); | 2246 | return sema.mod.constType(sema.arena, src, file_scope.root_container.ty); |
| 2236 | } | 2247 | } |
| 2237 | | 2248 | |
| 2238 | fn zirShl(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { | 2249 | fn zirShl(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { |
| ... | @@ -2412,14 +2423,14 @@ fn analyzeInstComptimeOp(sema: *Sema, block: *Scope.Block, res_type: Type, inst: | ... | @@ -2412,14 +2423,14 @@ fn analyzeInstComptimeOp(sema: *Sema, block: *Scope.Block, res_type: Type, inst: |
| 2412 | const value = switch (inst.base.tag) { | 2423 | const value = switch (inst.base.tag) { |
| 2413 | .add => blk: { | 2424 | .add => blk: { |
| 2414 | const val = if (is_int) | 2425 | const val = if (is_int) |
| 2415 | try Module.intAdd(block.arena, lhs_val, rhs_val) | 2426 | try Module.intAdd(sema.arena, lhs_val, rhs_val) |
| 2416 | else | 2427 | else |
| 2417 | try mod.floatAdd(scope, res_type, inst.base.src, lhs_val, rhs_val); | 2428 | try mod.floatAdd(scope, res_type, inst.base.src, lhs_val, rhs_val); |
| 2418 | break :blk val; | 2429 | break :blk val; |
| 2419 | }, | 2430 | }, |
| 2420 | .sub => blk: { | 2431 | .sub => blk: { |
| 2421 | const val = if (is_int) | 2432 | const val = if (is_int) |
| 2422 | try Module.intSub(block.arena, lhs_val, rhs_val) | 2433 | try Module.intSub(sema.arena, lhs_val, rhs_val) |
| 2423 | else | 2434 | else |
| 2424 | try mod.floatSub(scope, res_type, inst.base.src, lhs_val, rhs_val); | 2435 | try mod.floatSub(scope, res_type, inst.base.src, lhs_val, rhs_val); |
| 2425 | break :blk val; | 2436 | break :blk val; |
| ... | @@ -2435,7 +2446,7 @@ fn analyzeInstComptimeOp(sema: *Sema, block: *Scope.Block, res_type: Type, inst: | ... | @@ -2435,7 +2446,7 @@ fn analyzeInstComptimeOp(sema: *Sema, block: *Scope.Block, res_type: Type, inst: |
| 2435 | }); | 2446 | }); |
| 2436 | } | 2447 | } |
| 2437 | | 2448 | |
| 2438 | fn zirDeref(sema: *Sema, block: *Scope.Block, deref: zir.Inst.Index) InnerError!*Inst { | 2449 | fn zirDerefNode(sema: *Sema, block: *Scope.Block, deref: zir.Inst.Index) InnerError!*Inst { |
| 2439 | const tracy = trace(@src()); | 2450 | const tracy = trace(@src()); |
| 2440 | defer tracy.end(); | 2451 | defer tracy.end(); |
| 2441 | | 2452 | |
| ... | @@ -2473,9 +2484,9 @@ fn zirAsm( | ... | @@ -2473,9 +2484,9 @@ fn zirAsm( |
| 2473 | }; | 2484 | }; |
| 2474 | } else null; | 2485 | } else null; |
| 2475 | | 2486 | |
| 2476 | const args = try block.arena.alloc(*Inst, extra.data.args.len); | 2487 | const args = try sema.arena.alloc(*Inst, extra.data.args.len); |
| 2477 | const inputs = try block.arena.alloc([]const u8, extra.data.args_len); | 2488 | const inputs = try sema.arena.alloc([]const u8, extra.data.args_len); |
| 2478 | const clobbers = try block.arena.alloc([]const u8, extra.data.clobbers_len); | 2489 | const clobbers = try sema.arena.alloc([]const u8, extra.data.clobbers_len); |
| 2479 | | 2490 | |
| 2480 | for (args) |*arg| { | 2491 | for (args) |*arg| { |
| 2481 | const uncasted = sema.resolveInst(block, sema.code.extra[extra_i]); | 2492 | const uncasted = sema.resolveInst(block, sema.code.extra[extra_i]); |
| ... | @@ -2492,7 +2503,7 @@ fn zirAsm( | ... | @@ -2492,7 +2503,7 @@ fn zirAsm( |
| 2492 | } | 2503 | } |
| 2493 | | 2504 | |
| 2494 | try sema.requireRuntimeBlock(block, src); | 2505 | try sema.requireRuntimeBlock(block, src); |
| 2495 | const inst = try block.arena.create(Inst.Assembly); | 2506 | const inst = try sema.arena.create(Inst.Assembly); |
| 2496 | inst.* = .{ | 2507 | inst.* = .{ |
| 2497 | .base = .{ | 2508 | .base = .{ |
| 2498 | .tag = .assembly, | 2509 | .tag = .assembly, |
| ... | @@ -2532,7 +2543,7 @@ fn zirCmp( | ... | @@ -2532,7 +2543,7 @@ fn zirCmp( |
| 2532 | const rhs_ty_tag = rhs.ty.zigTypeTag(); | 2543 | const rhs_ty_tag = rhs.ty.zigTypeTag(); |
| 2533 | if (is_equality_cmp and lhs_ty_tag == .Null and rhs_ty_tag == .Null) { | 2544 | if (is_equality_cmp and lhs_ty_tag == .Null and rhs_ty_tag == .Null) { |
| 2534 | // null == null, null != null | 2545 | // null == null, null != null |
| 2535 | return mod.constBool(block.arena, inst.base.src, op == .eq); | 2546 | return mod.constBool(sema.arena, inst.base.src, op == .eq); |
| 2536 | } else if (is_equality_cmp and | 2547 | } else if (is_equality_cmp and |
| 2537 | ((lhs_ty_tag == .Null and rhs_ty_tag == .Optional) or | 2548 | ((lhs_ty_tag == .Null and rhs_ty_tag == .Optional) or |
| 2538 | rhs_ty_tag == .Null and lhs_ty_tag == .Optional)) | 2549 | rhs_ty_tag == .Null and lhs_ty_tag == .Optional)) |
| ... | @@ -2559,7 +2570,7 @@ fn zirCmp( | ... | @@ -2559,7 +2570,7 @@ fn zirCmp( |
| 2559 | if (rhs.value()) |rval| { | 2570 | if (rhs.value()) |rval| { |
| 2560 | if (lhs.value()) |lval| { | 2571 | if (lhs.value()) |lval| { |
| 2561 | // TODO optimisation oppurtunity: evaluate if std.mem.eql is faster with the names, or calling to Module.getErrorValue to get the values and then compare them is faster | 2572 | // TODO optimisation oppurtunity: evaluate if std.mem.eql is faster with the names, or calling to Module.getErrorValue to get the values and then compare them is faster |
| 2562 | return mod.constBool(block.arena, inst.base.src, std.mem.eql(u8, lval.castTag(.@"error").?.data.name, rval.castTag(.@"error").?.data.name) == (op == .eq)); | 2573 | return mod.constBool(sema.arena, inst.base.src, std.mem.eql(u8, lval.castTag(.@"error").?.data.name, rval.castTag(.@"error").?.data.name) == (op == .eq)); |
| 2563 | } | 2574 | } |
| 2564 | } | 2575 | } |
| 2565 | try sema.requireRuntimeBlock(block, inst.base.src); | 2576 | try sema.requireRuntimeBlock(block, inst.base.src); |
| ... | @@ -2573,7 +2584,7 @@ fn zirCmp( | ... | @@ -2573,7 +2584,7 @@ fn zirCmp( |
| 2573 | if (!is_equality_cmp) { | 2584 | if (!is_equality_cmp) { |
| 2574 | return sema.mod.fail(&block.base, inst.base.src, "{s} operator not allowed for types", .{@tagName(op)}); | 2585 | return sema.mod.fail(&block.base, inst.base.src, "{s} operator not allowed for types", .{@tagName(op)}); |
| 2575 | } | 2586 | } |
| 2576 | return mod.constBool(block.arena, inst.base.src, lhs.value().?.eql(rhs.value().?) == (op == .eq)); | 2587 | return mod.constBool(sema.arena, inst.base.src, lhs.value().?.eql(rhs.value().?) == (op == .eq)); |
| 2577 | } | 2588 | } |
| 2578 | return sema.mod.fail(&block.base, inst.base.src, "TODO implement more cmp analysis", .{}); | 2589 | return sema.mod.fail(&block.base, inst.base.src, "TODO implement more cmp analysis", .{}); |
| 2579 | } | 2590 | } |
| ... | @@ -2584,7 +2595,7 @@ fn zirTypeof(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError! | ... | @@ -2584,7 +2595,7 @@ fn zirTypeof(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError! |
| 2584 | | 2595 | |
| 2585 | const inst_data = sema.code.instructions.items(.data)[inst].un_tok; | 2596 | const inst_data = sema.code.instructions.items(.data)[inst].un_tok; |
| 2586 | const operand = sema.resolveInst(block, inst_data.operand); | 2597 | const operand = sema.resolveInst(block, inst_data.operand); |
| 2587 | return sema.mod.constType(block.arena, inst_data.src(), operand.ty); | 2598 | return sema.mod.constType(sema.arena, inst_data.src(), operand.ty); |
| 2588 | } | 2599 | } |
| 2589 | | 2600 | |
| 2590 | fn zirTypeofPeer(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { | 2601 | fn zirTypeofPeer(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { |
| ... | @@ -2607,7 +2618,7 @@ fn zirTypeofPeer(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerEr | ... | @@ -2607,7 +2618,7 @@ fn zirTypeofPeer(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerEr |
| 2607 | } | 2618 | } |
| 2608 | | 2619 | |
| 2609 | const result_type = try sema.resolvePeerTypes(block, inst_list, src_list); | 2620 | const result_type = try sema.resolvePeerTypes(block, inst_list, src_list); |
| 2610 | return sema.mod.constType(block.arena, src, result_type); | 2621 | return sema.mod.constType(sema.arena, src, result_type); |
| 2611 | } | 2622 | } |
| 2612 | | 2623 | |
| 2613 | fn zirBoolNot(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { | 2624 | fn zirBoolNot(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { |
| ... | @@ -2621,7 +2632,7 @@ fn zirBoolNot(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError | ... | @@ -2621,7 +2632,7 @@ fn zirBoolNot(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError |
| 2621 | const bool_type = Type.initTag(.bool); | 2632 | const bool_type = Type.initTag(.bool); |
| 2622 | const operand = try sema.coerce(scope, bool_type, uncasted_operand); | 2633 | const operand = try sema.coerce(scope, bool_type, uncasted_operand); |
| 2623 | if (try mod.resolveDefinedValue(scope, operand)) |val| { | 2634 | if (try mod.resolveDefinedValue(scope, operand)) |val| { |
| 2624 | return mod.constBool(block.arena, src, !val.toBool()); | 2635 | return mod.constBool(sema.arena, src, !val.toBool()); |
| 2625 | } | 2636 | } |
| 2626 | try sema.requireRuntimeBlock(block, src); | 2637 | try sema.requireRuntimeBlock(block, src); |
| 2627 | return block.addUnOp(src, bool_type, .not, operand); | 2638 | return block.addUnOp(src, bool_type, .not, operand); |
| ... | @@ -2646,9 +2657,9 @@ fn zirBoolOp( | ... | @@ -2646,9 +2657,9 @@ fn zirBoolOp( |
| 2646 | if (lhs.value()) |lhs_val| { | 2657 | if (lhs.value()) |lhs_val| { |
| 2647 | if (rhs.value()) |rhs_val| { | 2658 | if (rhs.value()) |rhs_val| { |
| 2648 | if (is_bool_or) { | 2659 | if (is_bool_or) { |
| 2649 | return mod.constBool(block.arena, inst.base.src, lhs_val.toBool() or rhs_val.toBool()); | 2660 | return mod.constBool(sema.arena, inst.base.src, lhs_val.toBool() or rhs_val.toBool()); |
| 2650 | } else { | 2661 | } else { |
| 2651 | return mod.constBool(block.arena, inst.base.src, lhs_val.toBool() and rhs_val.toBool()); | 2662 | return mod.constBool(sema.arena, inst.base.src, lhs_val.toBool() and rhs_val.toBool()); |
| 2652 | } | 2663 | } |
| 2653 | } | 2664 | } |
| 2654 | } | 2665 | } |
| ... | @@ -2717,7 +2728,7 @@ fn zirCondbr(sema: *Sema, parent_block: *Scope.Block, inst: zir.Inst.Index) Inne | ... | @@ -2717,7 +2728,7 @@ fn zirCondbr(sema: *Sema, parent_block: *Scope.Block, inst: zir.Inst.Index) Inne |
| 2717 | | 2728 | |
| 2718 | if (try mod.resolveDefinedValue(scope, cond)) |cond_val| { | 2729 | if (try mod.resolveDefinedValue(scope, cond)) |cond_val| { |
| 2719 | const body = if (cond_val.toBool()) &inst.positionals.then_body else &inst.positionals.else_body; | 2730 | const body = if (cond_val.toBool()) &inst.positionals.then_body else &inst.positionals.else_body; |
| 2720 | try sema.body(parent_block, body.*); | 2731 | try sema.analyzeBody(parent_block, body.*); |
| 2721 | return mod.constNoReturn(scope, inst.base.src); | 2732 | return mod.constNoReturn(scope, inst.base.src); |
| 2722 | } | 2733 | } |
| 2723 | | 2734 | |
| ... | @@ -2728,13 +2739,13 @@ fn zirCondbr(sema: *Sema, parent_block: *Scope.Block, inst: zir.Inst.Index) Inne | ... | @@ -2728,13 +2739,13 @@ fn zirCondbr(sema: *Sema, parent_block: *Scope.Block, inst: zir.Inst.Index) Inne |
| 2728 | .owner_decl = parent_block.owner_decl, | 2739 | .owner_decl = parent_block.owner_decl, |
| 2729 | .src_decl = parent_block.src_decl, | 2740 | .src_decl = parent_block.src_decl, |
| 2730 | .instructions = .{}, | 2741 | .instructions = .{}, |
| 2731 | .arena = parent_block.arena, | 2742 | .arena = sema.arena, |
| 2732 | .inlining = parent_block.inlining, | 2743 | .inlining = parent_block.inlining, |
| 2733 | .is_comptime = parent_block.is_comptime, | 2744 | .is_comptime = parent_block.is_comptime, |
| 2734 | .branch_quota = parent_block.branch_quota, | 2745 | .branch_quota = parent_block.branch_quota, |
| 2735 | }; | 2746 | }; |
| 2736 | defer true_block.instructions.deinit(mod.gpa); | 2747 | defer true_block.instructions.deinit(mod.gpa); |
| 2737 | try sema.body(&true_block, inst.positionals.then_body); | 2748 | try sema.analyzeBody(&true_block, inst.positionals.then_body); |
| 2738 | | 2749 | |
| 2739 | var false_block: Scope.Block = .{ | 2750 | var false_block: Scope.Block = .{ |
| 2740 | .parent = parent_block, | 2751 | .parent = parent_block, |
| ... | @@ -2743,16 +2754,16 @@ fn zirCondbr(sema: *Sema, parent_block: *Scope.Block, inst: zir.Inst.Index) Inne | ... | @@ -2743,16 +2754,16 @@ fn zirCondbr(sema: *Sema, parent_block: *Scope.Block, inst: zir.Inst.Index) Inne |
| 2743 | .owner_decl = parent_block.owner_decl, | 2754 | .owner_decl = parent_block.owner_decl, |
| 2744 | .src_decl = parent_block.src_decl, | 2755 | .src_decl = parent_block.src_decl, |
| 2745 | .instructions = .{}, | 2756 | .instructions = .{}, |
| 2746 | .arena = parent_block.arena, | 2757 | .arena = sema.arena, |
| 2747 | .inlining = parent_block.inlining, | 2758 | .inlining = parent_block.inlining, |
| 2748 | .is_comptime = parent_block.is_comptime, | 2759 | .is_comptime = parent_block.is_comptime, |
| 2749 | .branch_quota = parent_block.branch_quota, | 2760 | .branch_quota = parent_block.branch_quota, |
| 2750 | }; | 2761 | }; |
| 2751 | defer false_block.instructions.deinit(mod.gpa); | 2762 | defer false_block.instructions.deinit(mod.gpa); |
| 2752 | try sema.body(&false_block, inst.positionals.else_body); | 2763 | try sema.analyzeBody(&false_block, inst.positionals.else_body); |
| 2753 | | 2764 | |
| 2754 | const then_body: ir.Body = .{ .instructions = try block.arena.dupe(*Inst, true_block.instructions.items) }; | 2765 | const then_body: ir.Body = .{ .instructions = try sema.arena.dupe(*Inst, true_block.instructions.items) }; |
| 2755 | const else_body: ir.Body = .{ .instructions = try block.arena.dupe(*Inst, false_block.instructions.items) }; | 2766 | const else_body: ir.Body = .{ .instructions = try sema.arena.dupe(*Inst, false_block.instructions.items) }; |
| 2756 | return mod.addCondBr(parent_block, inst.base.src, cond, then_body, else_body); | 2767 | return mod.addCondBr(parent_block, inst.base.src, cond, then_body, else_body); |
| 2757 | } | 2768 | } |
| 2758 | | 2769 | |
| ... | @@ -2797,7 +2808,7 @@ fn zirPtrTypeSimple(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) Inne | ... | @@ -2797,7 +2808,7 @@ fn zirPtrTypeSimple(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) Inne |
| 2797 | const inst_data = sema.code.instructions.items(.data)[inst].ptr_type_simple; | 2808 | const inst_data = sema.code.instructions.items(.data)[inst].ptr_type_simple; |
| 2798 | const elem_type = try sema.resolveType(block, .unneeded, inst_data.elem_type); | 2809 | const elem_type = try sema.resolveType(block, .unneeded, inst_data.elem_type); |
| 2799 | const ty = try sema.mod.ptrType( | 2810 | const ty = try sema.mod.ptrType( |
| 2800 | block.arena, | 2811 | sema.arena, |
| 2801 | elem_type, | 2812 | elem_type, |
| 2802 | null, | 2813 | null, |
| 2803 | 0, | 2814 | 0, |
| ... | @@ -2808,7 +2819,7 @@ fn zirPtrTypeSimple(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) Inne | ... | @@ -2808,7 +2819,7 @@ fn zirPtrTypeSimple(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) Inne |
| 2808 | inst_data.is_volatile, | 2819 | inst_data.is_volatile, |
| 2809 | inst_data.size, | 2820 | inst_data.size, |
| 2810 | ); | 2821 | ); |
| 2811 | return sema.mod.constType(block.arena, .unneeded, ty); | 2822 | return sema.mod.constType(sema.arena, .unneeded, ty); |
| 2812 | } | 2823 | } |
| 2813 | | 2824 | |
| 2814 | fn zirPtrType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { | 2825 | fn zirPtrType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { |
| ... | @@ -2861,7 +2872,17 @@ fn zirPtrType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError | ... | @@ -2861,7 +2872,17 @@ fn zirPtrType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError |
| 2861 | inst_data.flags.is_volatile, | 2872 | inst_data.flags.is_volatile, |
| 2862 | inst_data.size, | 2873 | inst_data.size, |
| 2863 | ); | 2874 | ); |
| 2864 | return sema.mod.constType(block.arena, .unneeded, ty); | 2875 | return sema.mod.constType(sema.arena, .unneeded, ty); |
| | 2876 | } |
| | 2877 | |
| | 2878 | fn zirAwait(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { |
| | 2879 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| | 2880 | return sema.mod.fail(&block.base, inst_data.src(), "TODO implement Sema await", .{}); |
| | 2881 | } |
| | 2882 | |
| | 2883 | fn zirNosuspendAwait(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst { |
| | 2884 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| | 2885 | return sema.mod.fail(&block.base, inst_data.src(), "TODO implement Sema nosuspend_await", .{}); |
| 2865 | } | 2886 | } |
| 2866 | | 2887 | |
| 2867 | fn requireFunctionBlock(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) !void { | 2888 | fn requireFunctionBlock(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) !void { |
| ... | @@ -2877,7 +2898,7 @@ fn requireRuntimeBlock(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) !void | ... | @@ -2877,7 +2898,7 @@ fn requireRuntimeBlock(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) !void |
| 2877 | } | 2898 | } |
| 2878 | } | 2899 | } |
| 2879 | | 2900 | |
| 2880 | fn validateVarType(sema: *Module, block: *Scope.Block, src: LazySrcLoc, ty: Type) !void { | 2901 | fn validateVarType(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type) !void { |
| 2881 | if (!ty.isValidVarType(false)) { | 2902 | if (!ty.isValidVarType(false)) { |
| 2882 | return mod.fail(&block.base, src, "variable of type '{}' must be const or comptime", .{ty}); | 2903 | return mod.fail(&block.base, src, "variable of type '{}' must be const or comptime", .{ty}); |
| 2883 | } | 2904 | } |
| ... | @@ -2890,7 +2911,7 @@ pub const PanicId = enum { | ... | @@ -2890,7 +2911,7 @@ pub const PanicId = enum { |
| 2890 | }; | 2911 | }; |
| 2891 | | 2912 | |
| 2892 | fn addSafetyCheck(sema: *Sema, parent_block: *Scope.Block, ok: *Inst, panic_id: PanicId) !void { | 2913 | fn addSafetyCheck(sema: *Sema, parent_block: *Scope.Block, ok: *Inst, panic_id: PanicId) !void { |
| 2893 | const block_inst = try parent_block.arena.create(Inst.Block); | 2914 | const block_inst = try sema.arena.create(Inst.Block); |
| 2894 | block_inst.* = .{ | 2915 | block_inst.* = .{ |
| 2895 | .base = .{ | 2916 | .base = .{ |
| 2896 | .tag = Inst.Block.base_tag, | 2917 | .tag = Inst.Block.base_tag, |
| ... | @@ -2898,14 +2919,14 @@ fn addSafetyCheck(sema: *Sema, parent_block: *Scope.Block, ok: *Inst, panic_id: | ... | @@ -2898,14 +2919,14 @@ fn addSafetyCheck(sema: *Sema, parent_block: *Scope.Block, ok: *Inst, panic_id: |
| 2898 | .src = ok.src, | 2919 | .src = ok.src, |
| 2899 | }, | 2920 | }, |
| 2900 | .body = .{ | 2921 | .body = .{ |
| 2901 | .instructions = try parent_block.arena.alloc(*Inst, 1), // Only need space for the condbr. | 2922 | .instructions = try sema.arena.alloc(*Inst, 1), // Only need space for the condbr. |
| 2902 | }, | 2923 | }, |
| 2903 | }; | 2924 | }; |
| 2904 | | 2925 | |
| 2905 | const ok_body: ir.Body = .{ | 2926 | const ok_body: ir.Body = .{ |
| 2906 | .instructions = try parent_block.arena.alloc(*Inst, 1), // Only need space for the br_void. | 2927 | .instructions = try sema.arena.alloc(*Inst, 1), // Only need space for the br_void. |
| 2907 | }; | 2928 | }; |
| 2908 | const br_void = try parent_block.arena.create(Inst.BrVoid); | 2929 | const br_void = try sema.arena.create(Inst.BrVoid); |
| 2909 | br_void.* = .{ | 2930 | br_void.* = .{ |
| 2910 | .base = .{ | 2931 | .base = .{ |
| 2911 | .tag = .br_void, | 2932 | .tag = .br_void, |
| ... | @@ -2923,7 +2944,7 @@ fn addSafetyCheck(sema: *Sema, parent_block: *Scope.Block, ok: *Inst, panic_id: | ... | @@ -2923,7 +2944,7 @@ fn addSafetyCheck(sema: *Sema, parent_block: *Scope.Block, ok: *Inst, panic_id: |
| 2923 | .owner_decl = parent_block.owner_decl, | 2944 | .owner_decl = parent_block.owner_decl, |
| 2924 | .src_decl = parent_block.src_decl, | 2945 | .src_decl = parent_block.src_decl, |
| 2925 | .instructions = .{}, | 2946 | .instructions = .{}, |
| 2926 | .arena = parent_block.arena, | 2947 | .arena = sema.arena, |
| 2927 | .inlining = parent_block.inlining, | 2948 | .inlining = parent_block.inlining, |
| 2928 | .is_comptime = parent_block.is_comptime, | 2949 | .is_comptime = parent_block.is_comptime, |
| 2929 | .branch_quota = parent_block.branch_quota, | 2950 | .branch_quota = parent_block.branch_quota, |
| ... | @@ -2933,9 +2954,9 @@ fn addSafetyCheck(sema: *Sema, parent_block: *Scope.Block, ok: *Inst, panic_id: | ... | @@ -2933,9 +2954,9 @@ fn addSafetyCheck(sema: *Sema, parent_block: *Scope.Block, ok: *Inst, panic_id: |
| 2933 | | 2954 | |
| 2934 | _ = try mod.safetyPanic(&fail_block, ok.src, panic_id); | 2955 | _ = try mod.safetyPanic(&fail_block, ok.src, panic_id); |
| 2935 | | 2956 | |
| 2936 | const fail_body: ir.Body = .{ .instructions = try parent_block.arena.dupe(*Inst, fail_block.instructions.items) }; | 2957 | const fail_body: ir.Body = .{ .instructions = try sema.arena.dupe(*Inst, fail_block.instructions.items) }; |
| 2937 | | 2958 | |
| 2938 | const condbr = try parent_block.arena.create(Inst.CondBr); | 2959 | const condbr = try sema.arena.create(Inst.CondBr); |
| 2939 | condbr.* = .{ | 2960 | condbr.* = .{ |
| 2940 | .base = .{ | 2961 | .base = .{ |
| 2941 | .tag = .condbr, | 2962 | .tag = .condbr, |
| ... | @@ -3296,7 +3317,7 @@ fn storePtr(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ptr: *Inst, uncas | ... | @@ -3296,7 +3317,7 @@ fn storePtr(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ptr: *Inst, uncas |
| 3296 | const elem_ty = ptr.ty.elemType(); | 3317 | const elem_ty = ptr.ty.elemType(); |
| 3297 | const value = try sema.coerce(scope, elem_ty, uncasted_value); | 3318 | const value = try sema.coerce(scope, elem_ty, uncasted_value); |
| 3298 | if (elem_ty.onePossibleValue() != null) | 3319 | if (elem_ty.onePossibleValue() != null) |
| 3299 | return sema.mod.constVoid(block.arena, .unneeded); | 3320 | return sema.mod.constVoid(sema.arena, .unneeded); |
| 3300 | | 3321 | |
| 3301 | // TODO handle comptime pointer writes | 3322 | // TODO handle comptime pointer writes |
| 3302 | // TODO handle if the element type requires comptime | 3323 | // TODO handle if the element type requires comptime |
| ... | @@ -3438,7 +3459,7 @@ fn analyzeIsNull( | ... | @@ -3438,7 +3459,7 @@ fn analyzeIsNull( |
| 3438 | if (operand.value()) |opt_val| { | 3459 | if (operand.value()) |opt_val| { |
| 3439 | const is_null = opt_val.isNull(); | 3460 | const is_null = opt_val.isNull(); |
| 3440 | const bool_value = if (invert_logic) !is_null else is_null; | 3461 | const bool_value = if (invert_logic) !is_null else is_null; |
| 3441 | return mod.constBool(block.arena, src, bool_value); | 3462 | return mod.constBool(sema.arena, src, bool_value); |
| 3442 | } | 3463 | } |
| 3443 | try sema.requireRuntimeBlock(block, src); | 3464 | try sema.requireRuntimeBlock(block, src); |
| 3444 | const inst_tag: Inst.Tag = if (invert_logic) .is_non_null else .is_null; | 3465 | const inst_tag: Inst.Tag = if (invert_logic) .is_non_null else .is_null; |
| ... | @@ -3447,11 +3468,11 @@ fn analyzeIsNull( | ... | @@ -3447,11 +3468,11 @@ fn analyzeIsNull( |
| 3447 | | 3468 | |
| 3448 | fn analyzeIsErr(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, operand: *Inst) InnerError!*Inst { | 3469 | fn analyzeIsErr(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, operand: *Inst) InnerError!*Inst { |
| 3449 | const ot = operand.ty.zigTypeTag(); | 3470 | const ot = operand.ty.zigTypeTag(); |
| 3450 | if (ot != .ErrorSet and ot != .ErrorUnion) return mod.constBool(block.arena, src, false); | 3471 | if (ot != .ErrorSet and ot != .ErrorUnion) return mod.constBool(sema.arena, src, false); |
| 3451 | if (ot == .ErrorSet) return mod.constBool(block.arena, src, true); | 3472 | if (ot == .ErrorSet) return mod.constBool(sema.arena, src, true); |
| 3452 | assert(ot == .ErrorUnion); | 3473 | assert(ot == .ErrorUnion); |
| 3453 | if (operand.value()) |err_union| { | 3474 | if (operand.value()) |err_union| { |
| 3454 | return mod.constBool(block.arena, src, err_union.getError() != null); | 3475 | return mod.constBool(sema.arena, src, err_union.getError() != null); |
| 3455 | } | 3476 | } |
| 3456 | try sema.requireRuntimeBlock(block, src); | 3477 | try sema.requireRuntimeBlock(block, src); |
| 3457 | return mod.addUnOp(b, src, Type.initTag(.bool), .is_err, operand); | 3478 | return mod.addUnOp(b, src, Type.initTag(.bool), .is_err, operand); |
| ... | @@ -3616,7 +3637,7 @@ fn cmpNumeric( | ... | @@ -3616,7 +3637,7 @@ fn cmpNumeric( |
| 3616 | | 3637 | |
| 3617 | if (lhs.value()) |lhs_val| { | 3638 | if (lhs.value()) |lhs_val| { |
| 3618 | if (rhs.value()) |rhs_val| { | 3639 | if (rhs.value()) |rhs_val| { |
| 3619 | return mod.constBool(block.arena, src, Value.compare(lhs_val, op, rhs_val)); | 3640 | return mod.constBool(sema.arena, src, Value.compare(lhs_val, op, rhs_val)); |
| 3620 | } | 3641 | } |
| 3621 | } | 3642 | } |
| 3622 | | 3643 | |
| ... | @@ -3684,8 +3705,8 @@ fn cmpNumeric( | ... | @@ -3684,8 +3705,8 @@ fn cmpNumeric( |
| 3684 | const zcmp = lhs_val.orderAgainstZero(); | 3705 | const zcmp = lhs_val.orderAgainstZero(); |
| 3685 | if (lhs_val.floatHasFraction()) { | 3706 | if (lhs_val.floatHasFraction()) { |
| 3686 | switch (op) { | 3707 | switch (op) { |
| 3687 | .eq => return mod.constBool(block.arena, src, false), | 3708 | .eq => return mod.constBool(sema.arena, src, false), |
| 3688 | .neq => return mod.constBool(block.arena, src, true), | 3709 | .neq => return mod.constBool(sema.arena, src, true), |
| 3689 | else => {}, | 3710 | else => {}, |
| 3690 | } | 3711 | } |
| 3691 | if (zcmp == .lt) { | 3712 | if (zcmp == .lt) { |
| ... | @@ -3719,8 +3740,8 @@ fn cmpNumeric( | ... | @@ -3719,8 +3740,8 @@ fn cmpNumeric( |
| 3719 | const zcmp = rhs_val.orderAgainstZero(); | 3740 | const zcmp = rhs_val.orderAgainstZero(); |
| 3720 | if (rhs_val.floatHasFraction()) { | 3741 | if (rhs_val.floatHasFraction()) { |
| 3721 | switch (op) { | 3742 | switch (op) { |
| 3722 | .eq => return mod.constBool(block.arena, src, false), | 3743 | .eq => return mod.constBool(sema.arena, src, false), |
| 3723 | .neq => return mod.constBool(block.arena, src, true), | 3744 | .neq => return mod.constBool(sema.arena, src, true), |
| 3724 | else => {}, | 3745 | else => {}, |
| 3725 | } | 3746 | } |
| 3726 | if (zcmp == .lt) { | 3747 | if (zcmp == .lt) { |