From 8e956baca84e3b0579813fa4e676509c20399170 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Mon, 4 Mar 2024 13:23:06 -0800 Subject: [PATCH] Basic support for associated constant declarations (#3737) --- toolchain/check/context.cpp | 1 + toolchain/check/eval.cpp | 1 + toolchain/check/handle_let.cpp | 79 +++++- toolchain/check/node_stack.h | 1 + .../testdata/interface/assoc_const.carbon | 40 +++ .../fail_assoc_const_bad_default.carbon | 39 +++ .../fail_assoc_const_not_binding.carbon | 26 ++ .../fail_assoc_const_not_constant.carbon | 46 ++++ .../fail_assoc_const_template.carbon | 26 ++ .../interface/fail_member_lookup.carbon | 30 ++- .../fail_todo_assoc_const_default.carbon | 52 ++++ .../interface/fail_todo_import.carbon | 242 ++++++++++++++++++ .../check/testdata/interface/import.carbon | 145 ++++++++--- .../testdata/let/fail_missing_value.carbon | 34 +++ toolchain/diagnostics/diagnostic_kind.def | 5 +- toolchain/lower/handle.cpp | 6 + toolchain/parse/handle_let.cpp | 8 - toolchain/parse/node_kind.def | 10 +- toolchain/parse/state.def | 6 +- .../parse/testdata/let/fail_empty.carbon | 2 +- ...sing_value.carbon => missing_value.carbon} | 25 +- toolchain/parse/typed_nodes.h | 8 +- toolchain/sem_ir/file.cpp | 3 + toolchain/sem_ir/formatter.cpp | 15 +- toolchain/sem_ir/inst_kind.def | 1 + toolchain/sem_ir/typed_insts.h | 9 + 26 files changed, 778 insertions(+), 82 deletions(-) create mode 100644 toolchain/check/testdata/interface/assoc_const.carbon create mode 100644 toolchain/check/testdata/interface/fail_assoc_const_bad_default.carbon create mode 100644 toolchain/check/testdata/interface/fail_assoc_const_not_binding.carbon create mode 100644 toolchain/check/testdata/interface/fail_assoc_const_not_constant.carbon create mode 100644 toolchain/check/testdata/interface/fail_assoc_const_template.carbon create mode 100644 toolchain/check/testdata/interface/fail_todo_assoc_const_default.carbon create mode 100644 toolchain/check/testdata/interface/fail_todo_import.carbon create mode 100644 toolchain/check/testdata/let/fail_missing_value.carbon rename toolchain/parse/testdata/let/{fail_missing_value.carbon => missing_value.carbon} (61%) diff --git a/toolchain/check/context.cpp b/toolchain/check/context.cpp index 7a8fdd82f4f4..a36fa9a85aad 100644 --- a/toolchain/check/context.cpp +++ b/toolchain/check/context.cpp @@ -819,6 +819,7 @@ class TypeCompleter { case SemIR::ArrayIndex::Kind: case SemIR::ArrayInit::Kind: case SemIR::Assign::Kind: + case SemIR::AssociatedConstantDecl::Kind: case SemIR::AssociatedEntity::Kind: case SemIR::BaseDecl::Kind: case SemIR::BindAlias::Kind: diff --git a/toolchain/check/eval.cpp b/toolchain/check/eval.cpp index 9ee1c427d5c6..912a0ac5915d 100644 --- a/toolchain/check/eval.cpp +++ b/toolchain/check/eval.cpp @@ -396,6 +396,7 @@ auto TryEvalInst(Context& context, SemIR::InstId inst_id, SemIR::Inst inst) // corresponding constant value. // TODO: This doesn't properly handle redeclarations. Consider adding a // corresponding `Value` inst for each of these cases. + case SemIR::AssociatedConstantDecl::Kind: case SemIR::BaseDecl::Kind: case SemIR::FieldDecl::Kind: case SemIR::FunctionDecl::Kind: diff --git a/toolchain/check/handle_let.cpp b/toolchain/check/handle_let.cpp index 3b7db5089169..275bff1ffc75 100644 --- a/toolchain/check/handle_let.cpp +++ b/toolchain/check/handle_let.cpp @@ -4,8 +4,11 @@ #include "toolchain/check/context.h" #include "toolchain/check/convert.h" +#include "toolchain/check/interface.h" #include "toolchain/check/modifiers.h" +#include "toolchain/diagnostics/diagnostic_emitter.h" #include "toolchain/sem_ir/inst.h" +#include "toolchain/sem_ir/typed_insts.h" namespace Carbon::Check { @@ -17,13 +20,54 @@ auto HandleLetIntroducer(Context& context, Parse::LetIntroducerId parse_node) return true; } -auto HandleLetInitializer(Context& /*context*/, - Parse::LetInitializerId /*parse_node*/) -> bool { +auto HandleLetInitializer(Context& context, Parse::LetInitializerId parse_node) + -> bool { + context.node_stack().Push(parse_node); return true; } +static auto BuildAssociatedConstantDecl( + Context& context, Parse::LetDeclId parse_node, SemIR::InstId pattern_id, + SemIR::ParseNodeAndInst pattern, SemIR::InterfaceId interface_id) -> void { + auto& interface_info = context.interfaces().Get(interface_id); + + auto binding_pattern = pattern.inst.TryAs(); + if (!binding_pattern) { + CARBON_DIAGNOSTIC(ExpectedSymbolicBindingInAssociatedConstant, Error, + "Pattern in associated constant declaration must be a " + "single `:!` binding."); + context.emitter().Emit(pattern.parse_node, + ExpectedSymbolicBindingInAssociatedConstant); + context.name_scopes().Get(interface_info.scope_id).has_error = true; + return; + } + + // Replace the tentative BindName instruction with the associated constant + // declaration. + auto name_id = + context.bind_names().Get(binding_pattern->bind_name_id).name_id; + context.ReplaceInstBeforeConstantUse( + pattern_id, {parse_node, SemIR::AssociatedConstantDecl{ + binding_pattern->type_id, name_id}}); + auto decl_id = pattern_id; + context.inst_block_stack().AddInstId(decl_id); + + // Add an associated entity name to the interface scope. + auto assoc_id = BuildAssociatedEntity(context, interface_id, decl_id); + auto name_context = context.decl_name_stack().MakeUnqualifiedName( + pattern.parse_node, name_id); + context.decl_name_stack().AddNameToLookup(name_context, assoc_id); +} + auto HandleLetDecl(Context& context, Parse::LetDeclId parse_node) -> bool { - auto value_id = context.node_stack().PopExpr(); + // Pop the optional initializer. + std::optional value_id; + if (context.node_stack().PeekNextIs()) { + value_id = context.node_stack().PopExpr(); + context.node_stack() + .PopAndDiscardSoloParseNode(); + } + if (context.node_stack().PeekIs()) { return context.TODO(parse_node, "tuple pattern in let"); } @@ -52,10 +96,31 @@ auto HandleLetDecl(Context& context, Parse::LetDeclId parse_node) -> bool { } context.decl_state_stack().Pop(DeclState::Let); - // Convert the value to match the type of the pattern. auto pattern = context.insts().GetWithParseNode(pattern_id); - value_id = ConvertToValueOfType(context, parse_node, value_id, - pattern.inst.type_id()); + auto interface_scope = context.GetCurrentScopeAs(); + + if (value_id) { + // Convert the value to match the type of the pattern. + value_id = ConvertToValueOfType(context, parse_node, *value_id, + pattern.inst.type_id()); + } + + // At interface scope, we are forming an associated constant, which has + // different rules. + if (interface_scope) { + BuildAssociatedConstantDecl(context, parse_node, pattern_id, pattern, + interface_scope->interface_id); + return true; + } + + if (!value_id) { + CARBON_DIAGNOSTIC( + ExpectedInitializerAfterLet, Error, + "Expected `=`; `let` declaration must have an initializer."); + context.emitter().Emit(Parse::TokenOnly(parse_node), + ExpectedInitializerAfterLet); + value_id = SemIR::InstId::BuiltinError; + } // Update the binding with its value and add it to the current block, after // the computation of the value. @@ -63,7 +128,7 @@ auto HandleLetDecl(Context& context, Parse::LetDeclId parse_node) -> bool { auto bind_name = pattern.inst.As(); CARBON_CHECK(!bind_name.value_id.is_valid()) << "Binding should not already have a value!"; - bind_name.value_id = value_id; + bind_name.value_id = *value_id; pattern.inst = bind_name; context.ReplaceInstBeforeConstantUse(pattern_id, pattern); context.inst_block_stack().AddInstId(pattern_id); diff --git a/toolchain/check/node_stack.h b/toolchain/check/node_stack.h index 2878534bbb30..2af2525f3095 100644 --- a/toolchain/check/node_stack.h +++ b/toolchain/check/node_stack.h @@ -474,6 +474,7 @@ class NodeStack { case Parse::NodeKind::ImplicitParamListStart: case Parse::NodeKind::ImplIntroducer: case Parse::NodeKind::InterfaceIntroducer: + case Parse::NodeKind::LetInitializer: case Parse::NodeKind::LetIntroducer: case Parse::NodeKind::QualifiedName: case Parse::NodeKind::ReturnedModifier: diff --git a/toolchain/check/testdata/interface/assoc_const.carbon b/toolchain/check/testdata/interface/assoc_const.carbon new file mode 100644 index 000000000000..07e193b91407 --- /dev/null +++ b/toolchain/check/testdata/interface/assoc_const.carbon @@ -0,0 +1,40 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE + +interface I { + let T:! type; + let N:! i32; +} + +// CHECK:STDOUT: --- assoc_const.carbon +// CHECK:STDOUT: +// CHECK:STDOUT: constants { +// CHECK:STDOUT: %.1: type = interface_type @I [template] +// CHECK:STDOUT: %.2: type = assoc_entity_type @I, type [template] +// CHECK:STDOUT: %.3: = assoc_entity element0, @I.%T [template] +// CHECK:STDOUT: %.4: type = assoc_entity_type @I, i32 [template] +// CHECK:STDOUT: %.5: = assoc_entity element1, @I.%N [template] +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: file { +// CHECK:STDOUT: package: = namespace [template] { +// CHECK:STDOUT: .I = %I.decl +// CHECK:STDOUT: } +// CHECK:STDOUT: %I.decl = interface_decl @I [template = constants.%.1] {} +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: interface @I { +// CHECK:STDOUT: %T: type = assoc_const_decl T [template] +// CHECK:STDOUT: %.loc8: = assoc_entity element0, %T [template = constants.%.3] +// CHECK:STDOUT: %N: i32 = assoc_const_decl N [template] +// CHECK:STDOUT: %.loc9: = assoc_entity element1, %N [template = constants.%.5] +// CHECK:STDOUT: +// CHECK:STDOUT: !members: +// CHECK:STDOUT: .T = %.loc8 +// CHECK:STDOUT: .N = %.loc9 +// CHECK:STDOUT: witness = (%T, %N) +// CHECK:STDOUT: } +// CHECK:STDOUT: diff --git a/toolchain/check/testdata/interface/fail_assoc_const_bad_default.carbon b/toolchain/check/testdata/interface/fail_assoc_const_bad_default.carbon new file mode 100644 index 000000000000..cb7a08448ea0 --- /dev/null +++ b/toolchain/check/testdata/interface/fail_assoc_const_bad_default.carbon @@ -0,0 +1,39 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE + +interface I { + // CHECK:STDERR: fail_assoc_const_bad_default.carbon:[[@LINE+3]]:3: ERROR: Cannot implicitly convert from `i32` to `type`. + // CHECK:STDERR: let T:! type = 42; + // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~ + let T:! type = 42; +} + +// CHECK:STDOUT: --- fail_assoc_const_bad_default.carbon +// CHECK:STDOUT: +// CHECK:STDOUT: constants { +// CHECK:STDOUT: %.1: type = interface_type @I [template] +// CHECK:STDOUT: %.2: i32 = int_literal 42 [template] +// CHECK:STDOUT: %.3: type = assoc_entity_type @I, type [template] +// CHECK:STDOUT: %.4: = assoc_entity element0, @I.%T [template] +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: file { +// CHECK:STDOUT: package: = namespace [template] { +// CHECK:STDOUT: .I = %I.decl +// CHECK:STDOUT: } +// CHECK:STDOUT: %I.decl = interface_decl @I [template = constants.%.1] {} +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: interface @I { +// CHECK:STDOUT: %.loc11_18: i32 = int_literal 42 [template = constants.%.2] +// CHECK:STDOUT: %T: type = assoc_const_decl T [template] +// CHECK:STDOUT: %.loc11_20: = assoc_entity element0, %T [template = constants.%.4] +// CHECK:STDOUT: +// CHECK:STDOUT: !members: +// CHECK:STDOUT: .T = %.loc11_20 +// CHECK:STDOUT: witness = (%T) +// CHECK:STDOUT: } +// CHECK:STDOUT: diff --git a/toolchain/check/testdata/interface/fail_assoc_const_not_binding.carbon b/toolchain/check/testdata/interface/fail_assoc_const_not_binding.carbon new file mode 100644 index 000000000000..635cb3edc216 --- /dev/null +++ b/toolchain/check/testdata/interface/fail_assoc_const_not_binding.carbon @@ -0,0 +1,26 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE + +interface I { + // CHECK:STDERR: fail_assoc_const_not_binding.carbon:[[@LINE+3]]:3: ERROR: Semantics TODO: `tuple pattern in let`. + // CHECK:STDERR: let (T:! type, U:! type); + // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~ + let (T:! type, U:! type); +} + +// CHECK:STDOUT: --- fail_assoc_const_not_binding.carbon +// CHECK:STDOUT: +// CHECK:STDOUT: constants { +// CHECK:STDOUT: %.1: type = interface_type @I [template] +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: file {} +// CHECK:STDOUT: +// CHECK:STDOUT: interface @I { +// CHECK:STDOUT: !members: +// CHECK:STDOUT: witness = invalid +// CHECK:STDOUT: } +// CHECK:STDOUT: diff --git a/toolchain/check/testdata/interface/fail_assoc_const_not_constant.carbon b/toolchain/check/testdata/interface/fail_assoc_const_not_constant.carbon new file mode 100644 index 000000000000..59625e433789 --- /dev/null +++ b/toolchain/check/testdata/interface/fail_assoc_const_not_constant.carbon @@ -0,0 +1,46 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE + +interface I { + // CHECK:STDERR: fail_assoc_const_not_constant.carbon:[[@LINE+3]]:7: ERROR: Pattern in associated constant declaration must be a single `:!` binding. + // CHECK:STDERR: let a: i32; + // CHECK:STDERR: ^ + let a: i32; +} + +// We shouldn't issue further errors on uses of the invalid name. +alias UseA = I.a; + +// Ideally we would still diagnose this, but it's OK that we don't. +alias UseOther = I.other; + +// CHECK:STDOUT: --- fail_assoc_const_not_constant.carbon +// CHECK:STDOUT: +// CHECK:STDOUT: constants { +// CHECK:STDOUT: %.1: type = interface_type @I [template] +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: file { +// CHECK:STDOUT: package: = namespace [template] { +// CHECK:STDOUT: .I = %I.decl +// CHECK:STDOUT: .UseA = %UseA +// CHECK:STDOUT: .UseOther = %UseOther +// CHECK:STDOUT: } +// CHECK:STDOUT: %I.decl = interface_decl @I [template = constants.%.1] {} +// CHECK:STDOUT: %I.ref.loc15: type = name_ref I, %I.decl [template = constants.%.1] +// CHECK:STDOUT: %a.ref: = name_ref a, [template = ] +// CHECK:STDOUT: %UseA: = bind_alias UseA, [template = ] +// CHECK:STDOUT: %I.ref.loc18: type = name_ref I, %I.decl [template = constants.%.1] +// CHECK:STDOUT: %other.ref: = name_ref other, [template = ] +// CHECK:STDOUT: %UseOther: = bind_alias UseOther, [template = ] +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: interface @I { +// CHECK:STDOUT: !members: +// CHECK:STDOUT: has_error +// CHECK:STDOUT: witness = () +// CHECK:STDOUT: } +// CHECK:STDOUT: diff --git a/toolchain/check/testdata/interface/fail_assoc_const_template.carbon b/toolchain/check/testdata/interface/fail_assoc_const_template.carbon new file mode 100644 index 000000000000..2c97a761842b --- /dev/null +++ b/toolchain/check/testdata/interface/fail_assoc_const_template.carbon @@ -0,0 +1,26 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE + +interface I { + // CHECK:STDERR: fail_assoc_const_template.carbon:[[@LINE+3]]:7: ERROR: Semantics TODO: `HandleTemplate`. + // CHECK:STDERR: let template T:! type; + // CHECK:STDERR: ^~~~~~~~~~~~~~~~~ + let template T:! type; +} + +// CHECK:STDOUT: --- fail_assoc_const_template.carbon +// CHECK:STDOUT: +// CHECK:STDOUT: constants { +// CHECK:STDOUT: %.1: type = interface_type @I [template] +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: file {} +// CHECK:STDOUT: +// CHECK:STDOUT: interface @I { +// CHECK:STDOUT: !members: +// CHECK:STDOUT: witness = invalid +// CHECK:STDOUT: } +// CHECK:STDOUT: diff --git a/toolchain/check/testdata/interface/fail_member_lookup.carbon b/toolchain/check/testdata/interface/fail_member_lookup.carbon index 8f102d548f54..af7e52ac711c 100644 --- a/toolchain/check/testdata/interface/fail_member_lookup.carbon +++ b/toolchain/check/testdata/interface/fail_member_lookup.carbon @@ -4,13 +4,22 @@ // // AUTOUPDATE -interface Interface { fn F(); } +interface Interface { + fn F(); + + let T:! type; +} fn F() { // CHECK:STDERR: fail_member_lookup.carbon:[[@LINE+3]]:3: ERROR: Value of type ` in Interface>` is not callable. // CHECK:STDERR: Interface.F(); // CHECK:STDERR: ^~~~~~~~~~~~ Interface.F(); + + // CHECK:STDERR: fail_member_lookup.carbon:[[@LINE+3]]:10: ERROR: Cannot implicitly convert from `` to `type`. + // CHECK:STDERR: var v: Interface.T; + // CHECK:STDERR: ^~~~~~~~~~~ + var v: Interface.T; } // CHECK:STDOUT: --- fail_member_lookup.carbon @@ -19,6 +28,8 @@ fn F() { // CHECK:STDOUT: %.1: type = interface_type @Interface [template] // CHECK:STDOUT: %.2: type = assoc_entity_type @Interface, [template] // CHECK:STDOUT: %.3: in Interface> = assoc_entity element0, @Interface.%F [template] +// CHECK:STDOUT: %.4: type = assoc_entity_type @Interface, type [template] +// CHECK:STDOUT: %.5: = assoc_entity element1, @Interface.%T [template] // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: file { @@ -32,19 +43,26 @@ fn F() { // CHECK:STDOUT: // CHECK:STDOUT: interface @Interface { // CHECK:STDOUT: %F: = fn_decl @F.1 [template] {} -// CHECK:STDOUT: %.loc7: in Interface> = assoc_entity element0, %F [template = constants.%.3] +// CHECK:STDOUT: %.loc8: in Interface> = assoc_entity element0, %F [template = constants.%.3] +// CHECK:STDOUT: %T: type = assoc_const_decl T [template] +// CHECK:STDOUT: %.loc10: = assoc_entity element1, %T [template = constants.%.5] // CHECK:STDOUT: // CHECK:STDOUT: !members: -// CHECK:STDOUT: .F = %.loc7 -// CHECK:STDOUT: witness = (%F) +// CHECK:STDOUT: .F = %.loc8 +// CHECK:STDOUT: .T = %.loc10 +// CHECK:STDOUT: witness = (%F, %T) // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: fn @F.1(); // CHECK:STDOUT: // CHECK:STDOUT: fn @F.2() { // CHECK:STDOUT: !entry: -// CHECK:STDOUT: %Interface.ref: type = name_ref Interface, file.%Interface.decl [template = constants.%.1] -// CHECK:STDOUT: %F.ref: in Interface> = name_ref F, @Interface.%.loc7 [template = constants.%.3] +// CHECK:STDOUT: %Interface.ref.loc17: type = name_ref Interface, file.%Interface.decl [template = constants.%.1] +// CHECK:STDOUT: %F.ref: in Interface> = name_ref F, @Interface.%.loc8 [template = constants.%.3] +// CHECK:STDOUT: %Interface.ref.loc22: type = name_ref Interface, file.%Interface.decl [template = constants.%.1] +// CHECK:STDOUT: %T.ref: = name_ref T, @Interface.%.loc10 [template = constants.%.5] +// CHECK:STDOUT: %v.var: ref = var v +// CHECK:STDOUT: %v: ref = bind_name v, %v.var // CHECK:STDOUT: return // CHECK:STDOUT: } // CHECK:STDOUT: diff --git a/toolchain/check/testdata/interface/fail_todo_assoc_const_default.carbon b/toolchain/check/testdata/interface/fail_todo_assoc_const_default.carbon new file mode 100644 index 000000000000..520b7d258e77 --- /dev/null +++ b/toolchain/check/testdata/interface/fail_todo_assoc_const_default.carbon @@ -0,0 +1,52 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE + +interface I { + // CHECK:STDERR: fail_todo_assoc_const_default.carbon:[[@LINE+3]]:3: ERROR: Semantics TODO: `interface modifier`. + // CHECK:STDERR: default let T:! type = (i32, i32); + // CHECK:STDERR: ^~~~~~~ + default let T:! type = (i32, i32); + // CHECK:STDERR: fail_todo_assoc_const_default.carbon:[[@LINE+3]]:3: ERROR: Semantics TODO: `interface modifier`. + // CHECK:STDERR: default let N:! i32 = 42; + // CHECK:STDERR: ^~~~~~~ + default let N:! i32 = 42; +} + +// CHECK:STDOUT: --- fail_todo_assoc_const_default.carbon +// CHECK:STDOUT: +// CHECK:STDOUT: constants { +// CHECK:STDOUT: %.1: type = interface_type @I [template] +// CHECK:STDOUT: %.2: type = tuple_type (type, type) [template] +// CHECK:STDOUT: %.3: type = tuple_type (i32, i32) [template] +// CHECK:STDOUT: %.4: type = assoc_entity_type @I, type [template] +// CHECK:STDOUT: %.5: = assoc_entity element0, @I.%T [template] +// CHECK:STDOUT: %.6: i32 = int_literal 42 [template] +// CHECK:STDOUT: %.7: type = assoc_entity_type @I, i32 [template] +// CHECK:STDOUT: %.8: = assoc_entity element1, @I.%N [template] +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: file { +// CHECK:STDOUT: package: = namespace [template] { +// CHECK:STDOUT: .I = %I.decl +// CHECK:STDOUT: } +// CHECK:STDOUT: %I.decl = interface_decl @I [template = constants.%.1] {} +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: interface @I { +// CHECK:STDOUT: %.loc11_35.1: (type, type) = tuple_literal (i32, i32) +// CHECK:STDOUT: %.loc11_35.2: type = converted %.loc11_35.1, constants.%.3 [template = constants.%.3] +// CHECK:STDOUT: %T: type = assoc_const_decl T [template] +// CHECK:STDOUT: %.loc11_36: = assoc_entity element0, %T [template = constants.%.5] +// CHECK:STDOUT: %.loc15_25: i32 = int_literal 42 [template = constants.%.6] +// CHECK:STDOUT: %N: i32 = assoc_const_decl N [template] +// CHECK:STDOUT: %.loc15_27: = assoc_entity element1, %N [template = constants.%.8] +// CHECK:STDOUT: +// CHECK:STDOUT: !members: +// CHECK:STDOUT: .T = %.loc11_36 +// CHECK:STDOUT: .N = %.loc15_27 +// CHECK:STDOUT: witness = (%T, %N) +// CHECK:STDOUT: } +// CHECK:STDOUT: diff --git a/toolchain/check/testdata/interface/fail_todo_import.carbon b/toolchain/check/testdata/interface/fail_todo_import.carbon new file mode 100644 index 000000000000..767fb24770ab --- /dev/null +++ b/toolchain/check/testdata/interface/fail_todo_import.carbon @@ -0,0 +1,242 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE +// CHECK:STDERR: b.carbon: ERROR: Semantics TODO: `TryResolveInst on AssociatedEntityType`. +// CHECK:STDERR: b.carbon: ERROR: Semantics TODO: `TryResolveInst on AssociatedEntity`. +// CHECK:STDERR: b.carbon: ERROR: Semantics TODO: `TryResolveInst on AssociatedEntityType`. +// CHECK:STDERR: b.carbon: ERROR: Semantics TODO: `TryResolveInst on AssociatedEntity`. +// CHECK:STDERR: b.carbon: ERROR: Semantics TODO: `TryResolveInst on AssociatedEntityType`. +// CHECK:STDERR: b.carbon: ERROR: Semantics TODO: `TryResolveInst on AssociatedEntity`. +// CHECK:STDERR: b.carbon: ERROR: Semantics TODO: `TryResolveInst on AssociatedEntityType`. +// CHECK:STDERR: b.carbon: ERROR: Semantics TODO: `TryResolveInst on AssociatedEntity`. + +// --- a.carbon + +library "a" api; + +interface Empty { +} + +interface Basic { + let T:! type; + fn F(); +} + +interface ForwardDeclared; + +interface ForwardDeclared { + let T:! type; + fn F(); +} + +var f_ref: {.f: ForwardDeclared}; + +// --- b.carbon + +library "b" api; + +import library "a"; + +fn UseEmpty(e: Empty) {} +fn UseBasic(e: Basic) {} +fn UseForwardDeclared(f: ForwardDeclared) {} + +alias UseBasicT = Basic.T; +alias UseBasicF = Basic.F; + +alias UseForwardDeclaredT = ForwardDeclared.T; +alias UseForwardDeclaredF = ForwardDeclared.F; + +var f: ForwardDeclared* = &f_ref.f; + +// CHECK:STDOUT: --- a.carbon +// CHECK:STDOUT: +// CHECK:STDOUT: constants { +// CHECK:STDOUT: %.1: type = interface_type @Empty [template] +// CHECK:STDOUT: %.2: type = interface_type @Basic [template] +// CHECK:STDOUT: %.3: type = assoc_entity_type @Basic, type [template] +// CHECK:STDOUT: %.4: = assoc_entity element0, @Basic.%T [template] +// CHECK:STDOUT: %.5: type = assoc_entity_type @Basic, [template] +// CHECK:STDOUT: %.6: in Basic> = assoc_entity element1, @Basic.%F [template] +// CHECK:STDOUT: %.7: type = interface_type @ForwardDeclared [template] +// CHECK:STDOUT: %.8: type = assoc_entity_type @ForwardDeclared, type [template] +// CHECK:STDOUT: %.9: = assoc_entity element0, @ForwardDeclared.%T [template] +// CHECK:STDOUT: %.10: type = assoc_entity_type @ForwardDeclared, [template] +// CHECK:STDOUT: %.11: in ForwardDeclared> = assoc_entity element1, @ForwardDeclared.%F [template] +// CHECK:STDOUT: %.12: type = struct_type {.f: ForwardDeclared} [template] +// CHECK:STDOUT: %.13: type = tuple_type () [template] +// CHECK:STDOUT: %.14: type = struct_type {.f: ()} [template] +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: file { +// CHECK:STDOUT: package: = namespace [template] { +// CHECK:STDOUT: .Empty = %Empty.decl +// CHECK:STDOUT: .Basic = %Basic.decl +// CHECK:STDOUT: .ForwardDeclared = %ForwardDeclared.decl.loc12 +// CHECK:STDOUT: .f_ref = %f_ref +// CHECK:STDOUT: } +// CHECK:STDOUT: %Empty.decl = interface_decl @Empty [template = constants.%.1] {} +// CHECK:STDOUT: %Basic.decl = interface_decl @Basic [template = constants.%.2] {} +// CHECK:STDOUT: %ForwardDeclared.decl.loc12 = interface_decl @ForwardDeclared [template = constants.%.7] {} +// CHECK:STDOUT: %ForwardDeclared.decl.loc14 = interface_decl @ForwardDeclared [template = constants.%.7] {} +// CHECK:STDOUT: %ForwardDeclared.ref: type = name_ref ForwardDeclared, %ForwardDeclared.decl.loc12 [template = constants.%.7] +// CHECK:STDOUT: %.loc19: type = struct_type {.f: ForwardDeclared} [template = constants.%.12] +// CHECK:STDOUT: %f_ref.var: ref {.f: ForwardDeclared} = var f_ref +// CHECK:STDOUT: %f_ref: ref {.f: ForwardDeclared} = bind_name f_ref, %f_ref.var +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: interface @Empty { +// CHECK:STDOUT: !members: +// CHECK:STDOUT: witness = () +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: interface @Basic { +// CHECK:STDOUT: %T: type = assoc_const_decl T [template] +// CHECK:STDOUT: %.loc8: = assoc_entity element0, %T [template = constants.%.4] +// CHECK:STDOUT: %F: = fn_decl @F.1 [template] {} +// CHECK:STDOUT: %.loc9: in Basic> = assoc_entity element1, %F [template = constants.%.6] +// CHECK:STDOUT: +// CHECK:STDOUT: !members: +// CHECK:STDOUT: .T = %.loc8 +// CHECK:STDOUT: .F = %.loc9 +// CHECK:STDOUT: witness = (%T, %F) +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: interface @ForwardDeclared { +// CHECK:STDOUT: %T: type = assoc_const_decl T [template] +// CHECK:STDOUT: %.loc15: = assoc_entity element0, %T [template = constants.%.9] +// CHECK:STDOUT: %F: = fn_decl @F.2 [template] {} +// CHECK:STDOUT: %.loc16: in ForwardDeclared> = assoc_entity element1, %F [template = constants.%.11] +// CHECK:STDOUT: +// CHECK:STDOUT: !members: +// CHECK:STDOUT: .T = %.loc15 +// CHECK:STDOUT: .F = %.loc16 +// CHECK:STDOUT: witness = (%T, %F) +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @F.1(); +// CHECK:STDOUT: +// CHECK:STDOUT: fn @F.2(); +// CHECK:STDOUT: +// CHECK:STDOUT: --- b.carbon +// CHECK:STDOUT: +// CHECK:STDOUT: constants { +// CHECK:STDOUT: %.1: type = interface_type @Empty [template] +// CHECK:STDOUT: %.2: type = tuple_type () [template] +// CHECK:STDOUT: %.3: type = interface_type @Basic [template] +// CHECK:STDOUT: %.4: type = interface_type @ForwardDeclared [template] +// CHECK:STDOUT: %.5: type = ptr_type ForwardDeclared [template] +// CHECK:STDOUT: %.6: type = struct_type {.f: ForwardDeclared} [template] +// CHECK:STDOUT: %.7: type = struct_type {.f: ()} [template] +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: file { +// CHECK:STDOUT: package: = namespace [template] { +// CHECK:STDOUT: .Empty = %import_ref.1 +// CHECK:STDOUT: .Basic = %import_ref.2 +// CHECK:STDOUT: .ForwardDeclared = %import_ref.3 +// CHECK:STDOUT: .f_ref = %import_ref.4 +// CHECK:STDOUT: .UseEmpty = %UseEmpty +// CHECK:STDOUT: .UseBasic = %UseBasic +// CHECK:STDOUT: .UseForwardDeclared = %UseForwardDeclared +// CHECK:STDOUT: .UseBasicT = %UseBasicT +// CHECK:STDOUT: .UseBasicF = %UseBasicF +// CHECK:STDOUT: .UseForwardDeclaredT = %UseForwardDeclaredT +// CHECK:STDOUT: .UseForwardDeclaredF = %UseForwardDeclaredF +// CHECK:STDOUT: .f = %f.loc16 +// CHECK:STDOUT: } +// CHECK:STDOUT: %import_ref.1: type = import_ref ir1, inst+1, used [template = constants.%.1] +// CHECK:STDOUT: %import_ref.2: type = import_ref ir1, inst+3, used [template = constants.%.3] +// CHECK:STDOUT: %import_ref.3: type = import_ref ir1, inst+13, used [template = constants.%.4] +// CHECK:STDOUT: %import_ref.4: ref {.f: ForwardDeclared} = import_ref ir1, inst+33, used +// CHECK:STDOUT: %UseEmpty: = fn_decl @UseEmpty [template] { +// CHECK:STDOUT: %Empty.decl = interface_decl @Empty [template = constants.%.1] {} +// CHECK:STDOUT: %Empty.ref: type = name_ref Empty, %import_ref.1 [template = constants.%.1] +// CHECK:STDOUT: %e.loc6_13.1: Empty = param e +// CHECK:STDOUT: @UseEmpty.%e: Empty = bind_name e, %e.loc6_13.1 +// CHECK:STDOUT: } +// CHECK:STDOUT: %UseBasic: = fn_decl @UseBasic [template] { +// CHECK:STDOUT: %Basic.decl = interface_decl @Basic [template = constants.%.3] {} +// CHECK:STDOUT: %Basic.ref.loc7: type = name_ref Basic, %import_ref.2 [template = constants.%.3] +// CHECK:STDOUT: %e.loc7_13.1: Basic = param e +// CHECK:STDOUT: @UseBasic.%e: Basic = bind_name e, %e.loc7_13.1 +// CHECK:STDOUT: } +// CHECK:STDOUT: %UseForwardDeclared: = fn_decl @UseForwardDeclared [template] { +// CHECK:STDOUT: %ForwardDeclared.decl = interface_decl @ForwardDeclared [template = constants.%.4] {} +// CHECK:STDOUT: %ForwardDeclared.ref.loc8: type = name_ref ForwardDeclared, %import_ref.3 [template = constants.%.4] +// CHECK:STDOUT: %f.loc8_23.1: ForwardDeclared = param f +// CHECK:STDOUT: @UseForwardDeclared.%f: ForwardDeclared = bind_name f, %f.loc8_23.1 +// CHECK:STDOUT: } +// CHECK:STDOUT: %Basic.ref.loc10: type = name_ref Basic, %import_ref.2 [template = constants.%.3] +// CHECK:STDOUT: %T.ref.loc10: = name_ref T, @Basic.%import_ref.2 [template = ] +// CHECK:STDOUT: %UseBasicT: = bind_alias UseBasicT, @Basic.%import_ref.2 [template = ] +// CHECK:STDOUT: %Basic.ref.loc11: type = name_ref Basic, %import_ref.2 [template = constants.%.3] +// CHECK:STDOUT: %F.ref.loc11: = name_ref F, @Basic.%import_ref.1 [template = ] +// CHECK:STDOUT: %UseBasicF: = bind_alias UseBasicF, @Basic.%import_ref.1 [template = ] +// CHECK:STDOUT: %ForwardDeclared.ref.loc13: type = name_ref ForwardDeclared, %import_ref.3 [template = constants.%.4] +// CHECK:STDOUT: %T.ref.loc13: = name_ref T, @ForwardDeclared.%import_ref.2 [template = ] +// CHECK:STDOUT: %UseForwardDeclaredT: = bind_alias UseForwardDeclaredT, @ForwardDeclared.%import_ref.2 [template = ] +// CHECK:STDOUT: %ForwardDeclared.ref.loc14: type = name_ref ForwardDeclared, %import_ref.3 [template = constants.%.4] +// CHECK:STDOUT: %F.ref.loc14: = name_ref F, @ForwardDeclared.%import_ref.1 [template = ] +// CHECK:STDOUT: %UseForwardDeclaredF: = bind_alias UseForwardDeclaredF, @ForwardDeclared.%import_ref.1 [template = ] +// CHECK:STDOUT: %ForwardDeclared.ref.loc16: type = name_ref ForwardDeclared, %import_ref.3 [template = constants.%.4] +// CHECK:STDOUT: %.loc16: type = ptr_type ForwardDeclared [template = constants.%.5] +// CHECK:STDOUT: %f.var: ref ForwardDeclared* = var f +// CHECK:STDOUT: %f.loc16: ref ForwardDeclared* = bind_name f, %f.var +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: interface @Empty { +// CHECK:STDOUT: !members: +// CHECK:STDOUT: witness = () +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: interface @Basic { +// CHECK:STDOUT: %import_ref.1: = import_ref ir1, inst+11, used [template = ] +// CHECK:STDOUT: %import_ref.2: = import_ref ir1, inst+7, used [template = ] +// CHECK:STDOUT: %import_ref.3 = import_ref ir1, inst+5, unused +// CHECK:STDOUT: %import_ref.4 = import_ref ir1, inst+9, unused +// CHECK:STDOUT: +// CHECK:STDOUT: !members: +// CHECK:STDOUT: .F = %import_ref.1 +// CHECK:STDOUT: .T = %import_ref.2 +// CHECK:STDOUT: witness = (%import_ref.3, %import_ref.4) +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: interface @ForwardDeclared { +// CHECK:STDOUT: %import_ref.1: = import_ref ir1, inst+22, used [template = ] +// CHECK:STDOUT: %import_ref.2: = import_ref ir1, inst+18, used [template = ] +// CHECK:STDOUT: %import_ref.3 = import_ref ir1, inst+16, unused +// CHECK:STDOUT: %import_ref.4 = import_ref ir1, inst+20, unused +// CHECK:STDOUT: +// CHECK:STDOUT: !members: +// CHECK:STDOUT: .F = %import_ref.1 +// CHECK:STDOUT: .T = %import_ref.2 +// CHECK:STDOUT: witness = (%import_ref.3, %import_ref.4) +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @UseEmpty(%e: Empty) { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @UseBasic(%e: Basic) { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @UseForwardDeclared(%f: ForwardDeclared) { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @__global_init() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %f_ref.ref: ref {.f: ForwardDeclared} = name_ref f_ref, file.%import_ref.4 +// CHECK:STDOUT: %.loc16_33: ref ForwardDeclared = struct_access %f_ref.ref, element0 +// CHECK:STDOUT: %.loc16_27: ForwardDeclared* = addr_of %.loc16_33 +// CHECK:STDOUT: assign file.%f.var, %.loc16_27 +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: diff --git a/toolchain/check/testdata/interface/import.carbon b/toolchain/check/testdata/interface/import.carbon index bf67bc9576cd..8bde83818992 100644 --- a/toolchain/check/testdata/interface/import.carbon +++ b/toolchain/check/testdata/interface/import.carbon @@ -11,9 +11,15 @@ library "a" api; interface Empty { } +interface Basic { + let T:! type; + fn F(); +} + interface ForwardDeclared; interface ForwardDeclared { + let T:! type; fn F(); } @@ -26,6 +32,7 @@ library "b" api; import library "a"; fn UseEmpty(e: Empty) {} +fn UseBasic(e: Basic) {} fn UseForwardDeclared(f: ForwardDeclared) {} var f: ForwardDeclared* = &f_ref.f; @@ -34,25 +41,34 @@ var f: ForwardDeclared* = &f_ref.f; // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %.1: type = interface_type @Empty [template] -// CHECK:STDOUT: %.2: type = interface_type @ForwardDeclared [template] -// CHECK:STDOUT: %.3: type = assoc_entity_type @ForwardDeclared, [template] -// CHECK:STDOUT: %.4: in ForwardDeclared> = assoc_entity element0, @ForwardDeclared.%F [template] -// CHECK:STDOUT: %.5: type = struct_type {.f: ForwardDeclared} [template] -// CHECK:STDOUT: %.6: type = tuple_type () [template] -// CHECK:STDOUT: %.7: type = struct_type {.f: ()} [template] +// CHECK:STDOUT: %.2: type = interface_type @Basic [template] +// CHECK:STDOUT: %.3: type = assoc_entity_type @Basic, type [template] +// CHECK:STDOUT: %.4: = assoc_entity element0, @Basic.%T [template] +// CHECK:STDOUT: %.5: type = assoc_entity_type @Basic, [template] +// CHECK:STDOUT: %.6: in Basic> = assoc_entity element1, @Basic.%F [template] +// CHECK:STDOUT: %.7: type = interface_type @ForwardDeclared [template] +// CHECK:STDOUT: %.8: type = assoc_entity_type @ForwardDeclared, type [template] +// CHECK:STDOUT: %.9: = assoc_entity element0, @ForwardDeclared.%T [template] +// CHECK:STDOUT: %.10: type = assoc_entity_type @ForwardDeclared, [template] +// CHECK:STDOUT: %.11: in ForwardDeclared> = assoc_entity element1, @ForwardDeclared.%F [template] +// CHECK:STDOUT: %.12: type = struct_type {.f: ForwardDeclared} [template] +// CHECK:STDOUT: %.13: type = tuple_type () [template] +// CHECK:STDOUT: %.14: type = struct_type {.f: ()} [template] // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: file { // CHECK:STDOUT: package: = namespace [template] { // CHECK:STDOUT: .Empty = %Empty.decl -// CHECK:STDOUT: .ForwardDeclared = %ForwardDeclared.decl.loc7 +// CHECK:STDOUT: .Basic = %Basic.decl +// CHECK:STDOUT: .ForwardDeclared = %ForwardDeclared.decl.loc12 // CHECK:STDOUT: .f_ref = %f_ref // CHECK:STDOUT: } // CHECK:STDOUT: %Empty.decl = interface_decl @Empty [template = constants.%.1] {} -// CHECK:STDOUT: %ForwardDeclared.decl.loc7 = interface_decl @ForwardDeclared [template = constants.%.2] {} -// CHECK:STDOUT: %ForwardDeclared.decl.loc9 = interface_decl @ForwardDeclared [template = constants.%.2] {} -// CHECK:STDOUT: %ForwardDeclared.ref: type = name_ref ForwardDeclared, %ForwardDeclared.decl.loc7 [template = constants.%.2] -// CHECK:STDOUT: %.loc13: type = struct_type {.f: ForwardDeclared} [template = constants.%.5] +// CHECK:STDOUT: %Basic.decl = interface_decl @Basic [template = constants.%.2] {} +// CHECK:STDOUT: %ForwardDeclared.decl.loc12 = interface_decl @ForwardDeclared [template = constants.%.7] {} +// CHECK:STDOUT: %ForwardDeclared.decl.loc14 = interface_decl @ForwardDeclared [template = constants.%.7] {} +// CHECK:STDOUT: %ForwardDeclared.ref: type = name_ref ForwardDeclared, %ForwardDeclared.decl.loc12 [template = constants.%.7] +// CHECK:STDOUT: %.loc19: type = struct_type {.f: ForwardDeclared} [template = constants.%.12] // CHECK:STDOUT: %f_ref.var: ref {.f: ForwardDeclared} = var f_ref // CHECK:STDOUT: %f_ref: ref {.f: ForwardDeclared} = bind_name f_ref, %f_ref.var // CHECK:STDOUT: } @@ -62,56 +78,83 @@ var f: ForwardDeclared* = &f_ref.f; // CHECK:STDOUT: witness = () // CHECK:STDOUT: } // CHECK:STDOUT: -// CHECK:STDOUT: interface @ForwardDeclared { -// CHECK:STDOUT: %F: = fn_decl @F [template] {} -// CHECK:STDOUT: %.loc10: in ForwardDeclared> = assoc_entity element0, %F [template = constants.%.4] +// CHECK:STDOUT: interface @Basic { +// CHECK:STDOUT: %T: type = assoc_const_decl T [template] +// CHECK:STDOUT: %.loc8: = assoc_entity element0, %T [template = constants.%.4] +// CHECK:STDOUT: %F: = fn_decl @F.1 [template] {} +// CHECK:STDOUT: %.loc9: in Basic> = assoc_entity element1, %F [template = constants.%.6] // CHECK:STDOUT: // CHECK:STDOUT: !members: -// CHECK:STDOUT: .F = %.loc10 -// CHECK:STDOUT: witness = (%F) +// CHECK:STDOUT: .T = %.loc8 +// CHECK:STDOUT: .F = %.loc9 +// CHECK:STDOUT: witness = (%T, %F) // CHECK:STDOUT: } // CHECK:STDOUT: -// CHECK:STDOUT: fn @F(); +// CHECK:STDOUT: interface @ForwardDeclared { +// CHECK:STDOUT: %T: type = assoc_const_decl T [template] +// CHECK:STDOUT: %.loc15: = assoc_entity element0, %T [template = constants.%.9] +// CHECK:STDOUT: %F: = fn_decl @F.2 [template] {} +// CHECK:STDOUT: %.loc16: in ForwardDeclared> = assoc_entity element1, %F [template = constants.%.11] +// CHECK:STDOUT: +// CHECK:STDOUT: !members: +// CHECK:STDOUT: .T = %.loc15 +// CHECK:STDOUT: .F = %.loc16 +// CHECK:STDOUT: witness = (%T, %F) +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @F.1(); +// CHECK:STDOUT: +// CHECK:STDOUT: fn @F.2(); // CHECK:STDOUT: // CHECK:STDOUT: --- b.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %.1: type = interface_type @Empty [template] // CHECK:STDOUT: %.2: type = tuple_type () [template] -// CHECK:STDOUT: %.3: type = interface_type @ForwardDeclared [template] -// CHECK:STDOUT: %.4: type = ptr_type ForwardDeclared [template] -// CHECK:STDOUT: %.5: type = struct_type {.f: ForwardDeclared} [template] -// CHECK:STDOUT: %.6: type = struct_type {.f: ()} [template] +// CHECK:STDOUT: %.3: type = interface_type @Basic [template] +// CHECK:STDOUT: %.4: type = interface_type @ForwardDeclared [template] +// CHECK:STDOUT: %.5: type = ptr_type ForwardDeclared [template] +// CHECK:STDOUT: %.6: type = struct_type {.f: ForwardDeclared} [template] +// CHECK:STDOUT: %.7: type = struct_type {.f: ()} [template] // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: file { // CHECK:STDOUT: package: = namespace [template] { // CHECK:STDOUT: .Empty = %import_ref.1 -// CHECK:STDOUT: .ForwardDeclared = %import_ref.2 -// CHECK:STDOUT: .f_ref = %import_ref.3 +// CHECK:STDOUT: .Basic = %import_ref.2 +// CHECK:STDOUT: .ForwardDeclared = %import_ref.3 +// CHECK:STDOUT: .f_ref = %import_ref.4 // CHECK:STDOUT: .UseEmpty = %UseEmpty +// CHECK:STDOUT: .UseBasic = %UseBasic // CHECK:STDOUT: .UseForwardDeclared = %UseForwardDeclared -// CHECK:STDOUT: .f = %f.loc9 +// CHECK:STDOUT: .f = %f.loc10 // CHECK:STDOUT: } // CHECK:STDOUT: %import_ref.1: type = import_ref ir1, inst+1, used [template = constants.%.1] // CHECK:STDOUT: %import_ref.2: type = import_ref ir1, inst+3, used [template = constants.%.3] -// CHECK:STDOUT: %import_ref.3: ref {.f: ForwardDeclared} = import_ref ir1, inst+19, used +// CHECK:STDOUT: %import_ref.3: type = import_ref ir1, inst+13, used [template = constants.%.4] +// CHECK:STDOUT: %import_ref.4: ref {.f: ForwardDeclared} = import_ref ir1, inst+33, used // CHECK:STDOUT: %UseEmpty: = fn_decl @UseEmpty [template] { // CHECK:STDOUT: %Empty.decl = interface_decl @Empty [template = constants.%.1] {} // CHECK:STDOUT: %Empty.ref: type = name_ref Empty, %import_ref.1 [template = constants.%.1] // CHECK:STDOUT: %e.loc6_13.1: Empty = param e // CHECK:STDOUT: @UseEmpty.%e: Empty = bind_name e, %e.loc6_13.1 // CHECK:STDOUT: } -// CHECK:STDOUT: %UseForwardDeclared: = fn_decl @UseForwardDeclared [template] { -// CHECK:STDOUT: %ForwardDeclared.decl = interface_decl @ForwardDeclared [template = constants.%.3] {} -// CHECK:STDOUT: %ForwardDeclared.ref.loc7: type = name_ref ForwardDeclared, %import_ref.2 [template = constants.%.3] -// CHECK:STDOUT: %f.loc7_23.1: ForwardDeclared = param f -// CHECK:STDOUT: @UseForwardDeclared.%f: ForwardDeclared = bind_name f, %f.loc7_23.1 +// CHECK:STDOUT: %UseBasic: = fn_decl @UseBasic [template] { +// CHECK:STDOUT: %Basic.decl = interface_decl @Basic [template = constants.%.3] {} +// CHECK:STDOUT: %Basic.ref: type = name_ref Basic, %import_ref.2 [template = constants.%.3] +// CHECK:STDOUT: %e.loc7_13.1: Basic = param e +// CHECK:STDOUT: @UseBasic.%e: Basic = bind_name e, %e.loc7_13.1 // CHECK:STDOUT: } -// CHECK:STDOUT: %ForwardDeclared.ref.loc9: type = name_ref ForwardDeclared, %import_ref.2 [template = constants.%.3] -// CHECK:STDOUT: %.loc9: type = ptr_type ForwardDeclared [template = constants.%.4] +// CHECK:STDOUT: %UseForwardDeclared: = fn_decl @UseForwardDeclared [template] { +// CHECK:STDOUT: %ForwardDeclared.decl = interface_decl @ForwardDeclared [template = constants.%.4] {} +// CHECK:STDOUT: %ForwardDeclared.ref.loc8: type = name_ref ForwardDeclared, %import_ref.3 [template = constants.%.4] +// CHECK:STDOUT: %f.loc8_23.1: ForwardDeclared = param f +// CHECK:STDOUT: @UseForwardDeclared.%f: ForwardDeclared = bind_name f, %f.loc8_23.1 +// CHECK:STDOUT: } +// CHECK:STDOUT: %ForwardDeclared.ref.loc10: type = name_ref ForwardDeclared, %import_ref.3 [template = constants.%.4] +// CHECK:STDOUT: %.loc10: type = ptr_type ForwardDeclared [template = constants.%.5] // CHECK:STDOUT: %f.var: ref ForwardDeclared* = var f -// CHECK:STDOUT: %f.loc9: ref ForwardDeclared* = bind_name f, %f.var +// CHECK:STDOUT: %f.loc10: ref ForwardDeclared* = bind_name f, %f.var // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: interface @Empty { @@ -119,13 +162,28 @@ var f: ForwardDeclared* = &f_ref.f; // CHECK:STDOUT: witness = () // CHECK:STDOUT: } // CHECK:STDOUT: -// CHECK:STDOUT: interface @ForwardDeclared { -// CHECK:STDOUT: %import_ref.1 = import_ref ir1, inst+8, unused -// CHECK:STDOUT: %import_ref.2 = import_ref ir1, inst+6, unused +// CHECK:STDOUT: interface @Basic { +// CHECK:STDOUT: %import_ref.1 = import_ref ir1, inst+11, unused +// CHECK:STDOUT: %import_ref.2 = import_ref ir1, inst+7, unused +// CHECK:STDOUT: %import_ref.3 = import_ref ir1, inst+5, unused +// CHECK:STDOUT: %import_ref.4 = import_ref ir1, inst+9, unused // CHECK:STDOUT: // CHECK:STDOUT: !members: // CHECK:STDOUT: .F = %import_ref.1 -// CHECK:STDOUT: witness = (%import_ref.2) +// CHECK:STDOUT: .T = %import_ref.2 +// CHECK:STDOUT: witness = (%import_ref.3, %import_ref.4) +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: interface @ForwardDeclared { +// CHECK:STDOUT: %import_ref.1 = import_ref ir1, inst+22, unused +// CHECK:STDOUT: %import_ref.2 = import_ref ir1, inst+18, unused +// CHECK:STDOUT: %import_ref.3 = import_ref ir1, inst+16, unused +// CHECK:STDOUT: %import_ref.4 = import_ref ir1, inst+20, unused +// CHECK:STDOUT: +// CHECK:STDOUT: !members: +// CHECK:STDOUT: .F = %import_ref.1 +// CHECK:STDOUT: .T = %import_ref.2 +// CHECK:STDOUT: witness = (%import_ref.3, %import_ref.4) // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: fn @UseEmpty(%e: Empty) { @@ -133,6 +191,11 @@ var f: ForwardDeclared* = &f_ref.f; // CHECK:STDOUT: return // CHECK:STDOUT: } // CHECK:STDOUT: +// CHECK:STDOUT: fn @UseBasic(%e: Basic) { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: // CHECK:STDOUT: fn @UseForwardDeclared(%f: ForwardDeclared) { // CHECK:STDOUT: !entry: // CHECK:STDOUT: return @@ -140,10 +203,10 @@ var f: ForwardDeclared* = &f_ref.f; // CHECK:STDOUT: // CHECK:STDOUT: fn @__global_init() { // CHECK:STDOUT: !entry: -// CHECK:STDOUT: %f_ref.ref: ref {.f: ForwardDeclared} = name_ref f_ref, file.%import_ref.3 -// CHECK:STDOUT: %.loc9_33: ref ForwardDeclared = struct_access %f_ref.ref, element0 -// CHECK:STDOUT: %.loc9_27: ForwardDeclared* = addr_of %.loc9_33 -// CHECK:STDOUT: assign file.%f.var, %.loc9_27 +// CHECK:STDOUT: %f_ref.ref: ref {.f: ForwardDeclared} = name_ref f_ref, file.%import_ref.4 +// CHECK:STDOUT: %.loc10_33: ref ForwardDeclared = struct_access %f_ref.ref, element0 +// CHECK:STDOUT: %.loc10_27: ForwardDeclared* = addr_of %.loc10_33 +// CHECK:STDOUT: assign file.%f.var, %.loc10_27 // CHECK:STDOUT: return // CHECK:STDOUT: } // CHECK:STDOUT: diff --git a/toolchain/check/testdata/let/fail_missing_value.carbon b/toolchain/check/testdata/let/fail_missing_value.carbon new file mode 100644 index 000000000000..1998695d3913 --- /dev/null +++ b/toolchain/check/testdata/let/fail_missing_value.carbon @@ -0,0 +1,34 @@ +// Part of the Carbon Language project, under the Apache License v2.0 with LLVM +// Exceptions. See /LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// AUTOUPDATE + +// CHECK:STDERR: fail_missing_value.carbon:[[@LINE+3]]:11: ERROR: Expected `=`; `let` declaration must have an initializer. +// CHECK:STDERR: let n: i32; +// CHECK:STDERR: ^ +let n: i32; + +fn F() { + // CHECK:STDERR: fail_missing_value.carbon:[[@LINE+3]]:13: ERROR: Expected `=`; `let` declaration must have an initializer. + // CHECK:STDERR: let n: i32; + // CHECK:STDERR: ^ + let n: i32; +} + +// CHECK:STDOUT: --- fail_missing_value.carbon +// CHECK:STDOUT: +// CHECK:STDOUT: file { +// CHECK:STDOUT: package: = namespace [template] { +// CHECK:STDOUT: .F = %F +// CHECK:STDOUT: } +// CHECK:STDOUT: %n: i32 = bind_name n, +// CHECK:STDOUT: %F: = fn_decl @F [template] {} +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: fn @F() { +// CHECK:STDOUT: !entry: +// CHECK:STDOUT: %n: i32 = bind_name n, +// CHECK:STDOUT: return +// CHECK:STDOUT: } +// CHECK:STDOUT: diff --git a/toolchain/diagnostics/diagnostic_kind.def b/toolchain/diagnostics/diagnostic_kind.def index 981f08424595..0a331d2825f1 100644 --- a/toolchain/diagnostics/diagnostic_kind.def +++ b/toolchain/diagnostics/diagnostic_kind.def @@ -111,7 +111,6 @@ CARBON_DIAGNOSTIC_KIND(ExpectedElseAfterIf) CARBON_DIAGNOSTIC_KIND(ExpectedDeclName) CARBON_DIAGNOSTIC_KIND(ExpectedDeclSemi) CARBON_DIAGNOSTIC_KIND(ExpectedDeclSemiOrDefinition) -CARBON_DIAGNOSTIC_KIND(ExpectedInitializerAfterLet) CARBON_DIAGNOSTIC_KIND(ParamsRequiredAfterImplicit) CARBON_DIAGNOSTIC_KIND(ParamsRequiredByIntroducer) CARBON_DIAGNOSTIC_KIND(ExpectedAfterBase) @@ -184,6 +183,10 @@ CARBON_DIAGNOSTIC_KIND(ImplAsOutsideClass) CARBON_DIAGNOSTIC_KIND(ImplPreviousDefinition) CARBON_DIAGNOSTIC_KIND(ImplRedefinition) +// Let declaration checking. +CARBON_DIAGNOSTIC_KIND(ExpectedInitializerAfterLet) +CARBON_DIAGNOSTIC_KIND(ExpectedSymbolicBindingInAssociatedConstant) + CARBON_DIAGNOSTIC_KIND(AddrOfEphemeralRef) CARBON_DIAGNOSTIC_KIND(AddrOfNonRef) CARBON_DIAGNOSTIC_KIND(AddrOnNonSelfParam) diff --git a/toolchain/lower/handle.cpp b/toolchain/lower/handle.cpp index 290bfbafb96b..24405795ad6e 100644 --- a/toolchain/lower/handle.cpp +++ b/toolchain/lower/handle.cpp @@ -60,6 +60,12 @@ auto HandleAssign(FunctionContext& context, SemIR::InstId /*inst_id*/, context.FinishInit(storage_type_id, inst.lhs_id, inst.rhs_id); } +auto HandleAssociatedConstantDecl(FunctionContext& /*context*/, + SemIR::InstId /*inst_id*/, + SemIR::AssociatedConstantDecl inst) -> void { + FatalErrorIfEncountered(inst); +} + auto HandleAssociatedEntity(FunctionContext& /*context*/, SemIR::InstId /*inst_id*/, SemIR::AssociatedEntity inst) -> void { diff --git a/toolchain/parse/handle_let.cpp b/toolchain/parse/handle_let.cpp index 4f3eb3f62b67..9b66ef779682 100644 --- a/toolchain/parse/handle_let.cpp +++ b/toolchain/parse/handle_let.cpp @@ -30,14 +30,6 @@ auto HandleLetAfterPattern(Context& context) -> void { if (auto equals = context.ConsumeIf(Lex::TokenKind::Equal)) { context.AddLeafNode(NodeKind::LetInitializer, *equals); context.PushState(State::Expr); - } else { - if (!state.has_error) { - CARBON_DIAGNOSTIC( - ExpectedInitializerAfterLet, Error, - "Expected `=`; `let` declaration must have an initializer."); - context.emitter().Emit(*context.position(), ExpectedInitializerAfterLet); - } - context.ReturnErrorOnState(); } } diff --git a/toolchain/parse/node_kind.def b/toolchain/parse/node_kind.def index ba19b8943094..f4b2dd283b35 100644 --- a/toolchain/parse/node_kind.def +++ b/toolchain/parse/node_kind.def @@ -314,15 +314,19 @@ CARBON_PARSE_NODE_KIND_CHILD_COUNT(CompileTimeBindingPattern, 2, ColonExclaim) CARBON_PARSE_NODE_KIND_CHILD_COUNT(Addr, 1, Addr) CARBON_PARSE_NODE_KIND_CHILD_COUNT(Template, 1, Template) -// `let`: +// `let` declarations, including associated constant declarations: // LetIntroducer // _repeated_ _external_: modifier // _external_: BindingPattern or TuplePattern -// LetInitializer -// _external_: expression +// LetInitializer +// _external_: expression +// _optional_ // LetDecl // // Modifier keywords only appear for `let` declarations, not `let` statements. +// +// The LetInitializer and following expression are paired: either both will be +// present, or neither will. CARBON_PARSE_NODE_KIND_CHILD_COUNT(LetIntroducer, 0, Let) CARBON_PARSE_NODE_KIND_CHILD_COUNT(LetInitializer, 0, Equal) CARBON_PARSE_NODE_KIND_BRACKET(LetDecl, LetIntroducer, CARBON_IF_VALID(Semi)) diff --git a/toolchain/parse/state.def b/toolchain/parse/state.def index 7fad657404d7..afa9ebd3e002 100644 --- a/toolchain/parse/state.def +++ b/toolchain/parse/state.def @@ -1257,7 +1257,9 @@ CARBON_PARSE_STATE_VARIANTS2(VarFinish, Decl, For) // 3. LetFinish CARBON_PARSE_STATE(Let) -// Handles `let` after the pattern, followed by an initializer. +// Handles `let` after the pattern, optionally followed by an initializer. The +// initializer is required except in an associated constant declaration, but +// that is enforced by check. // // let ... = ... // ^ @@ -1265,6 +1267,8 @@ CARBON_PARSE_STATE(Let) // ^~~~~ // 1. Expr // +// let ... ; +// ^ // let ... ??? ; // ^~~ // (state done) diff --git a/toolchain/parse/testdata/let/fail_empty.carbon b/toolchain/parse/testdata/let/fail_empty.carbon index 4fade9f7ad75..8ed75545887f 100644 --- a/toolchain/parse/testdata/let/fail_empty.carbon +++ b/toolchain/parse/testdata/let/fail_empty.carbon @@ -16,6 +16,6 @@ let; // CHECK:STDOUT: {kind: 'IdentifierName', text: ';', has_error: yes}, // CHECK:STDOUT: {kind: 'InvalidParse', text: ';', has_error: yes}, // CHECK:STDOUT: {kind: 'BindingPattern', text: ';', has_error: yes, subtree_size: 3}, -// CHECK:STDOUT: {kind: 'LetDecl', text: ';', has_error: yes, subtree_size: 5}, +// CHECK:STDOUT: {kind: 'LetDecl', text: ';', subtree_size: 5}, // CHECK:STDOUT: {kind: 'FileEnd', text: ''}, // CHECK:STDOUT: ] diff --git a/toolchain/parse/testdata/let/fail_missing_value.carbon b/toolchain/parse/testdata/let/missing_value.carbon similarity index 61% rename from toolchain/parse/testdata/let/fail_missing_value.carbon rename to toolchain/parse/testdata/let/missing_value.carbon index e4403b58dae4..dd8916f3bce7 100644 --- a/toolchain/parse/testdata/let/fail_missing_value.carbon +++ b/toolchain/parse/testdata/let/missing_value.carbon @@ -4,26 +4,24 @@ // // AUTOUPDATE -// CHECK:STDERR: fail_missing_value.carbon:[[@LINE+3]]:11: ERROR: Expected `=`; `let` declaration must have an initializer. -// CHECK:STDERR: let a: i32; -// CHECK:STDERR: ^ let a: i32; fn F() { - // CHECK:STDERR: fail_missing_value.carbon:[[@LINE+3]]:13: ERROR: Expected `=`; `let` declaration must have an initializer. - // CHECK:STDERR: let b: i32; - // CHECK:STDERR: ^ let b: i32; } -// CHECK:STDOUT: - filename: fail_missing_value.carbon +interface I { + let T:! type; +} + +// CHECK:STDOUT: - filename: missing_value.carbon // CHECK:STDOUT: parse_tree: [ // CHECK:STDOUT: {kind: 'FileStart', text: ''}, // CHECK:STDOUT: {kind: 'LetIntroducer', text: 'let'}, // CHECK:STDOUT: {kind: 'IdentifierName', text: 'a'}, // CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'}, // CHECK:STDOUT: {kind: 'BindingPattern', text: ':', subtree_size: 3}, -// CHECK:STDOUT: {kind: 'LetDecl', text: ';', has_error: yes, subtree_size: 5}, +// CHECK:STDOUT: {kind: 'LetDecl', text: ';', subtree_size: 5}, // CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'}, // CHECK:STDOUT: {kind: 'IdentifierName', text: 'F'}, // CHECK:STDOUT: {kind: 'TuplePatternStart', text: '('}, @@ -33,7 +31,16 @@ fn F() { // CHECK:STDOUT: {kind: 'IdentifierName', text: 'b'}, // CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'}, // CHECK:STDOUT: {kind: 'BindingPattern', text: ':', subtree_size: 3}, -// CHECK:STDOUT: {kind: 'LetDecl', text: ';', has_error: yes, subtree_size: 5}, +// CHECK:STDOUT: {kind: 'LetDecl', text: ';', subtree_size: 5}, // CHECK:STDOUT: {kind: 'FunctionDefinition', text: '}', subtree_size: 11}, +// CHECK:STDOUT: {kind: 'InterfaceIntroducer', text: 'interface'}, +// CHECK:STDOUT: {kind: 'IdentifierName', text: 'I'}, +// CHECK:STDOUT: {kind: 'InterfaceDefinitionStart', text: '{', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'LetIntroducer', text: 'let'}, +// CHECK:STDOUT: {kind: 'IdentifierName', text: 'T'}, +// CHECK:STDOUT: {kind: 'TypeTypeLiteral', text: 'type'}, +// CHECK:STDOUT: {kind: 'CompileTimeBindingPattern', text: ':!', subtree_size: 3}, +// CHECK:STDOUT: {kind: 'LetDecl', text: ';', subtree_size: 5}, +// CHECK:STDOUT: {kind: 'InterfaceDefinition', text: '}', subtree_size: 9}, // CHECK:STDOUT: {kind: 'FileEnd', text: ''}, // CHECK:STDOUT: ] diff --git a/toolchain/parse/typed_nodes.h b/toolchain/parse/typed_nodes.h index c85f90fbf540..397bd1b3bd6d 100644 --- a/toolchain/parse/typed_nodes.h +++ b/toolchain/parse/typed_nodes.h @@ -345,8 +345,12 @@ struct LetDecl { LetIntroducerId introducer; llvm::SmallVector modifiers; AnyPatternId pattern; - LetInitializerId equals; - AnyExprId initializer; + + struct Initializer { + LetInitializerId equals; + AnyExprId initializer; + }; + std::optional initializer; }; // `var` nodes diff --git a/toolchain/sem_ir/file.cpp b/toolchain/sem_ir/file.cpp index 107c67615298..ebb87c690ac1 100644 --- a/toolchain/sem_ir/file.cpp +++ b/toolchain/sem_ir/file.cpp @@ -213,6 +213,7 @@ static auto GetTypePrecedence(InstKind kind) -> int { case ArrayIndex::Kind: case ArrayInit::Kind: case Assign::Kind: + case AssociatedConstantDecl::Kind: case AssociatedEntity::Kind: case BaseDecl::Kind: case BindName::Kind: @@ -453,6 +454,7 @@ static auto StringifyTypeExprImpl(const SemIR::File& outer_sem_ir, case ArrayIndex::Kind: case ArrayInit::Kind: case Assign::Kind: + case AssociatedConstantDecl::Kind: case AssociatedEntity::Kind: case BaseDecl::Kind: case BindName::Kind: @@ -569,6 +571,7 @@ auto GetExprCategory(const File& file, InstId inst_id) -> ExprCategory { case AddrOf::Kind: case AddrPattern::Kind: case ArrayType::Kind: + case AssociatedConstantDecl::Kind: case AssociatedEntity::Kind: case AssociatedEntityType::Kind: case BindSymbolicName::Kind: diff --git a/toolchain/sem_ir/formatter.cpp b/toolchain/sem_ir/formatter.cpp index 349ab7cd6fca..d176be21708e 100644 --- a/toolchain/sem_ir/formatter.cpp +++ b/toolchain/sem_ir/formatter.cpp @@ -469,9 +469,9 @@ class InstNamer { CollectNamesInBlock(scope_id, inst.As().inner_id); break; } - case SpliceBlock::Kind: { - CollectNamesInBlock(scope_id, inst.As().block_id); - break; + case AssociatedConstantDecl::Kind: { + add_inst_name_id(inst.As().name_id); + continue; } case BindAlias::Kind: case BindName::Kind: @@ -536,6 +536,10 @@ class InstNamer { add_inst_name_id(inst.As().name_id); continue; } + case SpliceBlock::Kind: { + CollectNamesInBlock(scope_id, inst.As().block_id); + break; + } case VarStorage::Kind: { add_inst_name_id(inst.As().name_id, ".var"); continue; @@ -1203,6 +1207,11 @@ class Formatter { auto FormatArg(InstId id) -> void { FormatInstName(id); } auto FormatArg(InstBlockId id) -> void { + if (!id.is_valid()) { + out_ << "invalid"; + return; + } + out_ << '('; llvm::ListSeparator sep; for (auto inst_id : sem_ir_.inst_blocks().Get(id)) { diff --git a/toolchain/sem_ir/inst_kind.def b/toolchain/sem_ir/inst_kind.def index be427faa6824..42c677a085e0 100644 --- a/toolchain/sem_ir/inst_kind.def +++ b/toolchain/sem_ir/inst_kind.def @@ -23,6 +23,7 @@ CARBON_SEM_IR_INST_KIND(ArrayIndex) CARBON_SEM_IR_INST_KIND(ArrayInit) CARBON_SEM_IR_INST_KIND(ArrayType) CARBON_SEM_IR_INST_KIND(Assign) +CARBON_SEM_IR_INST_KIND(AssociatedConstantDecl) CARBON_SEM_IR_INST_KIND(AssociatedEntity) CARBON_SEM_IR_INST_KIND(AssociatedEntityType) CARBON_SEM_IR_INST_KIND(BaseDecl) diff --git a/toolchain/sem_ir/typed_insts.h b/toolchain/sem_ir/typed_insts.h index 16ed2d87e77a..0b0ca3731fc9 100644 --- a/toolchain/sem_ir/typed_insts.h +++ b/toolchain/sem_ir/typed_insts.h @@ -154,6 +154,15 @@ struct Assign { InstId rhs_id; }; +struct AssociatedConstantDecl { + static constexpr auto Kind = + InstKind::AssociatedConstantDecl.Define( + "assoc_const_decl"); + + TypeId type_id; + NameId name_id; +}; + // An associated entity declared in an interface. This is either an associated // function or a non-function associated constant such as an associated type. // This represents the entity before impl lookup is performed, and identifies