From dbf02ad100c95995708a8dbe3f9820512311ae4e Mon Sep 17 00:00:00 2001 From: Lucile Rose Nihlen Date: Fri, 13 Nov 2026 16:48:52 +0000 Subject: [PATCH] Adds an `AddrOfAction` for deferred checking of dependent types (#8122) For `template` generics specifically, when trying check the address of `&` a dependent expression would always fail with `AddrOfNonRef` diagnostic. Adds a test both of successful deferred checking and a fail test for an invalid dependent type. --- toolchain/check/handle_operator.cpp | 43 ++++++++++++--- .../testdata/generic/template/argument.carbon | 47 +++++++++++++++- .../impl/lookup/fail_function_types.carbon | 25 +-------- .../testdata/index/fail_expr_category.carbon | 53 +++++-------------- toolchain/sem_ir/inst_kind.def | 1 + toolchain/sem_ir/typed_insts.h | 12 +++++ 6 files changed, 110 insertions(+), 71 deletions(-) diff --git a/toolchain/check/handle_operator.cpp b/toolchain/check/handle_operator.cpp index 47ccea51d6a2..ba5e64751c7e 100644 --- a/toolchain/check/handle_operator.cpp +++ b/toolchain/check/handle_operator.cpp @@ -2,6 +2,7 @@ // Exceptions. See /LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +#include "toolchain/check/action.h" #include "toolchain/check/context.h" #include "toolchain/check/control_flow.h" #include "toolchain/check/convert.h" @@ -264,29 +265,55 @@ auto HandleParseNode(Context& context, Parse::PostfixOperatorStarId node_id) return true; } -auto HandleParseNode(Context& context, Parse::PrefixOperatorAmpId node_id) - -> bool { - auto value_id = context.node_stack().PopExpr(); - auto type_id = context.insts().Get(value_id).type_id(); +auto PerformAction(Context& context, SemIR::LocId loc_id, + SemIR::AddrOfAction action) -> SemIR::InstId { + auto value_id = action.lvalue_id; // Only durable reference expressions can have their address taken. switch (SemIR::GetExprCategory(context.sem_ir(), value_id)) { case SemIR::ExprCategory::DurableRef: case SemIR::ExprCategory::Error: break; default: + // TODO: If this is a dependent action the `loc_id` provided is not + // associated with a parse tree `node_id` and so we can't extract the + // token location for the `&` operator, which is the normal location to + // issue the error. Therefore deferred types will have the error in the + // less ideal location of the non-addressable expression. Repair to make + // these locations consistent. CARBON_DIAGNOSTIC(AddrOfNonRef, Error, "cannot take the address of non-reference expression"); - context.emitter().Emit(LocIdForDiagnostics::TokenOnly(node_id), - AddrOfNonRef); + auto diag_loc_id = loc_id.kind() == SemIR::LocId::Kind::NodeId + ? LocIdForDiagnostics::TokenOnly(loc_id.node_id()) + : LocIdForDiagnostics(loc_id); + context.emitter().Emit(diag_loc_id, AddrOfNonRef); value_id = SemIR::ErrorInst::InstId; break; } + // TODO: Preserve spelling of type of operand where possible. + auto type_id = context.insts().Get(value_id).type_id(); auto type_inst_id = context.types().GetTypeInstId(type_id); - AddInstAndPush( - context, node_id, + return AddInst( + context, loc_id, SemIR::AddrOf{.type_id = GetPointerType(context, type_inst_id), .lvalue_id = value_id}); +} + +auto HandleParseNode(Context& context, Parse::PrefixOperatorAmpId node_id) + -> bool { + auto value_id = context.node_stack().PopExpr(); + auto loc_id = SemIR::LocId(node_id); + + // Determine the expected type of the AddrOf instruction. + auto type_id = context.insts().Get(value_id).type_id(); + auto type_inst_id = context.types().GetTypeInstId(type_id); + auto expected_type_id = GetPointerType(context, type_inst_id); + + // If the value is still symbolic, defer checking until monomorphization. + auto inst_id = HandleAction( + context, loc_id, context.types().GetTypeInstId(expected_type_id), + {.type_id = SemIR::InstType::TypeId, .lvalue_id = value_id}); + context.node_stack().Push(node_id, inst_id); return true; } diff --git a/toolchain/check/testdata/generic/template/argument.carbon b/toolchain/check/testdata/generic/template/argument.carbon index b89b5193fa15..68ef44ae2db5 100644 --- a/toolchain/check/testdata/generic/template/argument.carbon +++ b/toolchain/check/testdata/generic/template/argument.carbon @@ -2,7 +2,7 @@ // Exceptions. See /LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // -// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/destroy.carbon +// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/convert.carbon // // AUTOUPDATE // TIP: To test this file alone, run: @@ -65,6 +65,51 @@ fn G() { F(type, X); } +// --- addr_of_dependent_type.carbon +library "[[@TEST_NAME]]"; + +class C {}; +impl C as Core.Copy { + fn Op(unused self) -> C { return {} as C; } +} +class D(template T: type) { + fn F(ref self) -> C* { return &self.c; } + var c: C; +} + +var d: D(C) = {.c = {} as C}; +let e: C* = d.F(); + +// --- fail_addr_of_non_addressable_dependent_type.carbon +library "[[@TEST_NAME]]"; + +class C {}; +impl C as Core.Copy { + fn Op(unused self) -> C { return {} as C; } +} +class D(template T: type) { + // Note thae missing `ref` qualifier on the `self` parameter, which makes + // the expression `self.c` non-addressable. + fn F(self) -> C* { return &self.c; } + var c: C; +} + +var d: D(C) = {.c = {} as C}; +// CHECK:STDERR: ╭─┤ fail_addr_of_non_addressable_dependent_type.carbon:[[@LINE+13]]:13 +// CHECK:STDERR: │ fn F(self) -> C* { return &self.c; } +// CHECK:STDERR: · ┬────── +// CHECK:STDERR: · ╰──┤ cannot take the address of non-reference +// CHECK:STDERR: · │ expression +// CHECK:STDERR: · │ [AddrOfNonRef] +// CHECK:STDERR: ┆ +// CHECK:STDERR: -> │ let e: C* = d.F(); +// CHECK:STDERR: · ━┳━ +// CHECK:STDERR: · ┗━━┫ error: unable to monomorphize specific `F(C)` +// CHECK:STDERR: · ┃ [ResolvingSpecificHere] +// CHECK:STDERR: ╰──── +// CHECK:STDERR: +let e: C* = d.F(); + // --- fail_non_constant_type_argument.carbon library "[[@TEST_NAME]]"; diff --git a/toolchain/check/testdata/impl/lookup/fail_function_types.carbon b/toolchain/check/testdata/impl/lookup/fail_function_types.carbon index 28bbfbda46fd..131aec577332 100644 --- a/toolchain/check/testdata/impl/lookup/fail_function_types.carbon +++ b/toolchain/check/testdata/impl/lookup/fail_function_types.carbon @@ -22,23 +22,12 @@ impl forall [T: type] T as Z { } fn F() { - // CHECK:STDERR: ╭─┤ fail_function_type_with_self_type.carbon:[[@LINE+17]]:3 + // CHECK:STDERR: ╭─┤ fail_function_type_with_self_type.carbon:[[@LINE+6]]:3 // CHECK:STDERR: -> │ &(().(Z.G)) as type; // CHECK:STDERR: · ┳ // CHECK:STDERR: · ┗━━┫ error: cannot take the address of non-reference expression [AddrOfNonRef] // CHECK:STDERR: ╰──── // CHECK:STDERR: - // CHECK:STDERR: ╭─┤ fail_function_type_with_self_type.carbon:[[@LINE+11]]:3 - // CHECK:STDERR: -> │ &(().(Z.G)) as type; - // CHECK:STDERR: · ┳━━━━━━━━━━━━━━━━━━ - // CHECK:STDERR: · ┗━━┫ error: cannot convert non-type value of type `*` to - // CHECK:STDERR: · │ ┃ `type` with `as` - // CHECK:STDERR: · │ ┃ [ConversionFailureNonTypeToFacet] - // CHECK:STDERR: · ╰────┤ type `*` does not implement interface - // CHECK:STDERR: · │ `Core.As(type)` - // CHECK:STDERR: · │ [MissingImplInMemberAccessInContext] - // CHECK:STDERR: ╰──── - // CHECK:STDERR: &(().(Z.G)) as type; } @@ -48,21 +37,11 @@ library "[[@TEST_NAME]]"; fn F() { // This does an impl lookup for `As` with `FunctionType` in the self type. // - // CHECK:STDERR: ╭─┤ fail_function_type.carbon:[[@LINE+16]]:3 + // CHECK:STDERR: ╭─┤ fail_function_type.carbon:[[@LINE+6]]:3 // CHECK:STDERR: -> │ &F as type; // CHECK:STDERR: · ┳ // CHECK:STDERR: · ┗━━┫ error: cannot take the address of non-reference expression [AddrOfNonRef] // CHECK:STDERR: ╰──── // CHECK:STDERR: - // CHECK:STDERR: ╭─┤ fail_function_type.carbon:[[@LINE+10]]:3 - // CHECK:STDERR: -> │ &F as type; - // CHECK:STDERR: · ┳━━━━━━━━━ - // CHECK:STDERR: · ┗━━┫ error: cannot convert non-type value of type `*` to `type` - // CHECK:STDERR: · │ ┃ with `as` - // CHECK:STDERR: · │ ┃ [ConversionFailureNonTypeToFacet] - // CHECK:STDERR: · ╰────┤ type `*` does not implement interface `Core.As(type)` - // CHECK:STDERR: · │ [MissingImplInMemberAccessInContext] - // CHECK:STDERR: ╰──── - // CHECK:STDERR: &F as type; } diff --git a/toolchain/check/testdata/index/fail_expr_category.carbon b/toolchain/check/testdata/index/fail_expr_category.carbon index 64263443a998..2ffecbacee69 100644 --- a/toolchain/check/testdata/index/fail_expr_category.carbon +++ b/toolchain/check/testdata/index/fail_expr_category.carbon @@ -65,7 +65,6 @@ fn G(b: array(i32, 3)) { // CHECK:STDOUT: %int_3: Core.IntLiteral = int_value 3 [concrete] // CHECK:STDOUT: %Array.type: type = parameterized_class_name_type @Array [concrete] // CHECK:STDOUT: %Array.generic: %Array.type = struct_value () [concrete] -// CHECK:STDOUT: %T.67d: type = symbolic_binding T, 0 [symbolic] // CHECK:STDOUT: %Array.95c: type = class_type @Array, @Array(%i32, %int_3) [concrete] // CHECK:STDOUT: %.d35: Core.Form = init_form %Array.95c [concrete] // CHECK:STDOUT: %pattern_type.d4e: type = pattern_type %Array.95c [concrete] @@ -98,16 +97,6 @@ fn G(b: array(i32, 3)) { // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn: = specific_function %Core.IntLiteral.as.ImplicitAs.impl.Convert.f60, @Core.IntLiteral.as.ImplicitAs.impl.Convert(%int_32) [concrete] // CHECK:STDOUT: %bound_method.036: = bound_method %int_0.5c6, %Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn [concrete] // CHECK:STDOUT: %int_0.753: %i32 = int_value 0 [concrete] -// CHECK:STDOUT: %Copy.type: type = facet_type <@Copy> [concrete] -// CHECK:STDOUT: %ptr.as.Copy.impl.Op.type.20f: type = fn_type @ptr.as.Copy.impl.Op, @ptr.as.Copy.impl(%T.67d) [symbolic] -// CHECK:STDOUT: %ptr.as.Copy.impl.Op.f12: %ptr.as.Copy.impl.Op.type.20f = struct_value () [symbolic] -// CHECK:STDOUT: %Copy.impl_witness.83a: = impl_witness imports.%Copy.impl_witness_table.fb0, @ptr.as.Copy.impl(%i32) [concrete] -// CHECK:STDOUT: %Copy.facet: %Copy.type = facet_value %ptr.a17, (%Copy.impl_witness.83a) [concrete] -// CHECK:STDOUT: %Copy.WithSelf.Op.type.9a2: type = fn_type @Copy.WithSelf.Op, @Copy.WithSelf(%Copy.facet) [concrete] -// CHECK:STDOUT: %.309: type = fn_type_with_self_type %Copy.WithSelf.Op.type.9a2, %Copy.facet [concrete] -// CHECK:STDOUT: %ptr.as.Copy.impl.Op.type.dfc: type = fn_type @ptr.as.Copy.impl.Op, @ptr.as.Copy.impl(%i32) [concrete] -// CHECK:STDOUT: %ptr.as.Copy.impl.Op.81f: %ptr.as.Copy.impl.Op.type.dfc = struct_value () [concrete] -// CHECK:STDOUT: %ptr.as.Copy.impl.Op.specific_fn: = specific_function %ptr.as.Copy.impl.Op.81f, @ptr.as.Copy.impl.Op(%i32) [concrete] // CHECK:STDOUT: %int_4.0c1: Core.IntLiteral = int_value 4 [concrete] // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.bound.776: = bound_method %int_4.0c1, %Core.IntLiteral.as.ImplicitAs.impl.Convert.f60 [concrete] // CHECK:STDOUT: %bound_method.7fa: = bound_method %int_4.0c1, %Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn [concrete] @@ -151,7 +140,6 @@ fn G(b: array(i32, 3)) { // CHECK:STDOUT: .Int = %Core.Int // CHECK:STDOUT: .Array = %Core.Array // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs -// CHECK:STDOUT: .Copy = %Core.Copy // CHECK:STDOUT: .SelfDestruct = %Core.SelfDestruct // CHECK:STDOUT: import Core//prelude // CHECK:STDOUT: import Core//prelude/... @@ -159,11 +147,8 @@ fn G(b: array(i32, 3)) { // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/parts/int, Int, loaded [concrete = constants.%Int.generic] // CHECK:STDOUT: %Core.Array: %Array.type = import_ref Core//prelude/parts/array, Array, loaded [concrete = constants.%Array.generic] // CHECK:STDOUT: %Core.ImplicitAs: %ImplicitAs.type.0ff = import_ref Core//prelude/parts/as, ImplicitAs, loaded [concrete = constants.%ImplicitAs.generic] -// CHECK:STDOUT: %Core.import_ref.e474: @Core.IntLiteral.as.ImplicitAs.impl.%Core.IntLiteral.as.ImplicitAs.impl.Convert.type (%Core.IntLiteral.as.ImplicitAs.impl.Convert.type.3c6) = import_ref Core//prelude/parts/int, loc{{\d+_\d+}}, loaded [symbolic = @Core.IntLiteral.as.ImplicitAs.impl.%Core.IntLiteral.as.ImplicitAs.impl.Convert (constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.6f2)] -// CHECK:STDOUT: %ImplicitAs.impl_witness_table.f53 = impl_witness_table (%Core.import_ref.e474), @Core.IntLiteral.as.ImplicitAs.impl [concrete] -// CHECK:STDOUT: %Core.Copy: type = import_ref Core//prelude/parts/copy, Copy, loaded [concrete = constants.%Copy.type] -// CHECK:STDOUT: %Core.import_ref.06a: @ptr.as.Copy.impl.%ptr.as.Copy.impl.Op.type (%ptr.as.Copy.impl.Op.type.20f) = import_ref Core//prelude/parts/copy, loc{{\d+_\d+}}, loaded [symbolic = @ptr.as.Copy.impl.%ptr.as.Copy.impl.Op (constants.%ptr.as.Copy.impl.Op.f12)] -// CHECK:STDOUT: %Copy.impl_witness_table.fb0 = impl_witness_table (%Core.import_ref.06a), @ptr.as.Copy.impl [concrete] +// CHECK:STDOUT: %Core.import_ref.e47: @Core.IntLiteral.as.ImplicitAs.impl.%Core.IntLiteral.as.ImplicitAs.impl.Convert.type (%Core.IntLiteral.as.ImplicitAs.impl.Convert.type.3c6) = import_ref Core//prelude/parts/int, loc{{\d+_\d+}}, loaded [symbolic = @Core.IntLiteral.as.ImplicitAs.impl.%Core.IntLiteral.as.ImplicitAs.impl.Convert (constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.6f2)] +// CHECK:STDOUT: %ImplicitAs.impl_witness_table.f53 = impl_witness_table (%Core.import_ref.e47), @Core.IntLiteral.as.ImplicitAs.impl [concrete] // CHECK:STDOUT: %Core.SelfDestruct: %SelfDestruct.type = import_ref Core//prelude/parts/destroy, SelfDestruct, loaded [concrete = constants.%SelfDestruct] // CHECK:STDOUT: %Core.import_ref.74d: @T.as_type.as.DestroyImpl.impl.%T.as_type.as.DestroyImpl.impl.Op.type (%T.as_type.as.DestroyImpl.impl.Op.type.dea) = import_ref Core//prelude/parts/destroy, loc{{\d+_\d+}}, loaded [symbolic = @T.as_type.as.DestroyImpl.impl.%T.as_type.as.DestroyImpl.impl.Op (constants.%T.as_type.as.DestroyImpl.impl.Op.6e5)] // CHECK:STDOUT: %DestroyImpl.impl_witness_table = impl_witness_table (%Core.import_ref.74d), @T.as_type.as.DestroyImpl.impl [concrete] @@ -208,23 +193,18 @@ fn G(b: array(i32, 3)) { // CHECK:STDOUT: %pb.var: ref %ptr.a17 = var_storage %pb.var_patt // CHECK:STDOUT: %b.ref.loc27: %Array.95c = name_ref b, %b // CHECK:STDOUT: %int_0.loc27: Core.IntLiteral = int_value 0 [concrete = constants.%int_0.5c6] -// CHECK:STDOUT: %impl.elem0.loc27_28: %.33a = impl_witness_access constants.%ImplicitAs.impl_witness.d73, element0 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.f60] -// CHECK:STDOUT: %bound_method.loc27_28.1: = bound_method %int_0.loc27, %impl.elem0.loc27_28 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.bound.762] -// CHECK:STDOUT: %specific_fn.loc27_28: = specific_function %impl.elem0.loc27_28, @Core.IntLiteral.as.ImplicitAs.impl.Convert(constants.%int_32) [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn] -// CHECK:STDOUT: %bound_method.loc27_28.2: = bound_method %int_0.loc27, %specific_fn.loc27_28 [concrete = constants.%bound_method.036] +// CHECK:STDOUT: %impl.elem0.loc27: %.33a = impl_witness_access constants.%ImplicitAs.impl_witness.d73, element0 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.f60] +// CHECK:STDOUT: %bound_method.loc27_28.1: = bound_method %int_0.loc27, %impl.elem0.loc27 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.bound.762] +// CHECK:STDOUT: %specific_fn.loc27: = specific_function %impl.elem0.loc27, @Core.IntLiteral.as.ImplicitAs.impl.Convert(constants.%int_32) [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn] +// CHECK:STDOUT: %bound_method.loc27_28.2: = bound_method %int_0.loc27, %specific_fn.loc27 [concrete = constants.%bound_method.036] // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc27: init %i32 = call %bound_method.loc27_28.2(%int_0.loc27) [concrete = constants.%int_0.753] // CHECK:STDOUT: %.loc27_28.1: %i32 = value_of_initializer %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc27 [concrete = constants.%int_0.753] // CHECK:STDOUT: %.loc27_28.2: %i32 = converted %int_0.loc27, %.loc27_28.1 [concrete = constants.%int_0.753] // CHECK:STDOUT: %.loc27_29.1: ref %Array.95c = value_as_ref %b.ref.loc27 // CHECK:STDOUT: %.loc27_29.2: ref %i32 = array_index %.loc27_29.1, %.loc27_28.2 // CHECK:STDOUT: %.loc27_29.3: %i32 = acquire_value %.loc27_29.2 -// CHECK:STDOUT: %addr.loc27: %ptr.a17 = addr_of [concrete = ] -// CHECK:STDOUT: %impl.elem0.loc27_25: %.309 = impl_witness_access constants.%Copy.impl_witness.83a, element0 [concrete = constants.%ptr.as.Copy.impl.Op.81f] -// CHECK:STDOUT: %bound_method.loc27_25.1: = bound_method %addr.loc27, %impl.elem0.loc27_25 [concrete = ] -// CHECK:STDOUT: %specific_fn.loc27_25: = specific_function %impl.elem0.loc27_25, @ptr.as.Copy.impl.Op(constants.%i32) [concrete = constants.%ptr.as.Copy.impl.Op.specific_fn] -// CHECK:STDOUT: %bound_method.loc27_25.2: = bound_method %addr.loc27, %specific_fn.loc27_25 [concrete = ] -// CHECK:STDOUT: %ptr.as.Copy.impl.Op.call.loc27: init %ptr.a17 = call %bound_method.loc27_25.2(%addr.loc27) [concrete = ] -// CHECK:STDOUT: assign %pb.var, %ptr.as.Copy.impl.Op.call.loc27 +// CHECK:STDOUT: %addr.loc27: = addr_of [concrete = ] +// CHECK:STDOUT: assign %pb.var, // CHECK:STDOUT: %.loc27_21: type = splice_block %ptr.loc27 [concrete = constants.%ptr.a17] { // CHECK:STDOUT: %i32.loc27: type = type_literal constants.%i32 [concrete = constants.%i32] // CHECK:STDOUT: %ptr.loc27: type = ptr_type %i32.loc27 [concrete = constants.%ptr.a17] @@ -260,22 +240,17 @@ fn G(b: array(i32, 3)) { // CHECK:STDOUT: %F.call.loc46: init %Array.95c to %.loc46_28.1 = call %F.ref.loc46() // CHECK:STDOUT: %int_0.loc46: Core.IntLiteral = int_value 0 [concrete = constants.%int_0.5c6] // CHECK:STDOUT: %.loc46_28.2: ref %Array.95c = temporary %.loc46_28.1, %F.call.loc46 -// CHECK:STDOUT: %impl.elem0.loc46_30: %.33a = impl_witness_access constants.%ImplicitAs.impl_witness.d73, element0 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.f60] -// CHECK:STDOUT: %bound_method.loc46_30.1: = bound_method %int_0.loc46, %impl.elem0.loc46_30 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.bound.762] -// CHECK:STDOUT: %specific_fn.loc46_30: = specific_function %impl.elem0.loc46_30, @Core.IntLiteral.as.ImplicitAs.impl.Convert(constants.%int_32) [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn] -// CHECK:STDOUT: %bound_method.loc46_30.2: = bound_method %int_0.loc46, %specific_fn.loc46_30 [concrete = constants.%bound_method.036] +// CHECK:STDOUT: %impl.elem0.loc46: %.33a = impl_witness_access constants.%ImplicitAs.impl_witness.d73, element0 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.f60] +// CHECK:STDOUT: %bound_method.loc46_30.1: = bound_method %int_0.loc46, %impl.elem0.loc46 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.bound.762] +// CHECK:STDOUT: %specific_fn.loc46: = specific_function %impl.elem0.loc46, @Core.IntLiteral.as.ImplicitAs.impl.Convert(constants.%int_32) [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn] +// CHECK:STDOUT: %bound_method.loc46_30.2: = bound_method %int_0.loc46, %specific_fn.loc46 [concrete = constants.%bound_method.036] // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc46: init %i32 = call %bound_method.loc46_30.2(%int_0.loc46) [concrete = constants.%int_0.753] // CHECK:STDOUT: %.loc46_30.1: %i32 = value_of_initializer %Core.IntLiteral.as.ImplicitAs.impl.Convert.call.loc46 [concrete = constants.%int_0.753] // CHECK:STDOUT: %.loc46_30.2: %i32 = converted %int_0.loc46, %.loc46_30.1 [concrete = constants.%int_0.753] // CHECK:STDOUT: %.loc46_31.1: ref %i32 = array_index %.loc46_28.2, %.loc46_30.2 // CHECK:STDOUT: %.loc46_31.2: %i32 = acquire_value %.loc46_31.1 -// CHECK:STDOUT: %addr.loc46: %ptr.a17 = addr_of [concrete = ] -// CHECK:STDOUT: %impl.elem0.loc46_25: %.309 = impl_witness_access constants.%Copy.impl_witness.83a, element0 [concrete = constants.%ptr.as.Copy.impl.Op.81f] -// CHECK:STDOUT: %bound_method.loc46_25.1: = bound_method %addr.loc46, %impl.elem0.loc46_25 [concrete = ] -// CHECK:STDOUT: %specific_fn.loc46_25: = specific_function %impl.elem0.loc46_25, @ptr.as.Copy.impl.Op(constants.%i32) [concrete = constants.%ptr.as.Copy.impl.Op.specific_fn] -// CHECK:STDOUT: %bound_method.loc46_25.2: = bound_method %addr.loc46, %specific_fn.loc46_25 [concrete = ] -// CHECK:STDOUT: %ptr.as.Copy.impl.Op.call.loc46: init %ptr.a17 = call %bound_method.loc46_25.2(%addr.loc46) [concrete = ] -// CHECK:STDOUT: assign %pf.var, %ptr.as.Copy.impl.Op.call.loc46 +// CHECK:STDOUT: %addr.loc46: = addr_of [concrete = ] +// CHECK:STDOUT: assign %pf.var, // CHECK:STDOUT: %.loc46_21: type = splice_block %ptr.loc46 [concrete = constants.%ptr.a17] { // CHECK:STDOUT: %i32.loc46: type = type_literal constants.%i32 [concrete = constants.%i32] // CHECK:STDOUT: %ptr.loc46: type = ptr_type %i32.loc46 [concrete = constants.%ptr.a17] diff --git a/toolchain/sem_ir/inst_kind.def b/toolchain/sem_ir/inst_kind.def index 89346f5f2180..652b6bfe254c 100644 --- a/toolchain/sem_ir/inst_kind.def +++ b/toolchain/sem_ir/inst_kind.def @@ -23,6 +23,7 @@ CARBON_SEM_IR_INST_KIND(AccessOptionalMemberAction) CARBON_SEM_IR_INST_KIND(AcquireValue) CARBON_SEM_IR_INST_KIND(AdaptDecl) CARBON_SEM_IR_INST_KIND(AddrOf) +CARBON_SEM_IR_INST_KIND(AddrOfAction) CARBON_SEM_IR_INST_KIND(AliasBinding) CARBON_SEM_IR_INST_KIND(ArrayIndex) CARBON_SEM_IR_INST_KIND(ArrayInit) diff --git a/toolchain/sem_ir/typed_insts.h b/toolchain/sem_ir/typed_insts.h index 72c424461812..b6a7b04ad1ea 100644 --- a/toolchain/sem_ir/typed_insts.h +++ b/toolchain/sem_ir/typed_insts.h @@ -139,6 +139,18 @@ struct AddrOf { InstId lvalue_id; }; +// An action that performs the AddressOf operation on a reference expression. +struct AddrOfAction { + static constexpr auto Kind = InstKind::AddrOfAction.Define( + {.ir_name = "addr_of_action", + .expr_category = ActionExprCategory(ExprCategory::Dependent), + .constant_kind = InstConstantKind::InstAction, + .is_lowered = false}); + + TypeId type_id; + MetaInstId lvalue_id; +}; + // Binds a name as an alias. See AnyBinding for member documentation. struct AliasBinding { static constexpr auto Kind = InstKind::AliasBinding.Define(