Skip to content

Commit ed31a6d

Browse files
authored
Import NamedConstraintDecl instruction names (#6305)
For now, they are imported as their constant value, so there's little to do, we just need to support getting their NameId. In the future we will need to import the full named constraint in order to ["identify"](https://github.com/carbon-language/carbon-lang/blob/656150593c1e3fc2b6ccd83c7256a61e4bd04030/proposals/p5168.md#proposed-rules) them. But we need FacetTypeInfo to hold named constraints first.
1 parent bf72c43 commit ed31a6d

File tree

4 files changed

+107
-54
lines changed

4 files changed

+107
-54
lines changed

toolchain/check/import.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ static auto GetImportName(const SemIR::File& import_sem_ir,
7474
import_sem_ir.name_scopes().Get(ns.name_scope_id));
7575
}
7676

77+
case CARBON_KIND(SemIR::NamedConstraintDecl named_constraint_decl): {
78+
return GetImportNameForEntity(import_sem_ir.named_constraints().Get(
79+
named_constraint_decl.named_constraint_id));
80+
}
81+
7782
default:
7883
CARBON_FATAL("Unsupported export kind: {0}", import_inst);
7984
}

toolchain/check/import_ref.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3187,6 +3187,8 @@ static auto TryResolveInstCanonical(ImportRefResolver& resolver,
31873187
case CARBON_KIND(SemIR::InterfaceDecl inst): {
31883188
return TryResolveTypedInst(resolver, inst, const_id);
31893189
}
3190+
// TODO: Import NamedConstraintDecl once its FacetType constant value
3191+
// contains the NamedConstraintId.
31903192
default:
31913193
break;
31923194
}

toolchain/check/testdata/interface/import_interface_decl.carbon

Lines changed: 6 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44
//
55
// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/none.carbon
6-
// TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
7-
// EXTRA-ARGS: --dump-sem-ir-ranges=if-present
86
//
97
// AUTOUPDATE
108
// TIP: To test this file alone, run:
@@ -17,6 +15,7 @@ library "[[@TEST_NAME]]";
1715
interface A;
1816

1917
// --- a.impl.carbon
18+
//@include-in-dumps
2019
impl library "[[@TEST_NAME]]";
2120

2221
// --- fail_b.carbon
@@ -29,23 +28,9 @@ interface B {}
2928
impl () as B;
3029

3130
// --- b.impl.carbon
31+
//@include-in-dumps
3232
impl library "[[@TEST_NAME]]";
3333

34-
// CHECK:STDOUT: --- a.carbon
35-
// CHECK:STDOUT:
36-
// CHECK:STDOUT: constants {
37-
// CHECK:STDOUT: %A.type: type = facet_type <@A> [concrete]
38-
// CHECK:STDOUT: }
39-
// CHECK:STDOUT:
40-
// CHECK:STDOUT: file {
41-
// CHECK:STDOUT: package: <namespace> = namespace [concrete] {
42-
// CHECK:STDOUT: .A = %A.decl
43-
// CHECK:STDOUT: }
44-
// CHECK:STDOUT: %A.decl: type = interface_decl @A [concrete = constants.%A.type] {} {}
45-
// CHECK:STDOUT: }
46-
// CHECK:STDOUT:
47-
// CHECK:STDOUT: interface @A;
48-
// CHECK:STDOUT:
4934
// CHECK:STDOUT: --- a.impl.carbon
5035
// CHECK:STDOUT:
5136
// CHECK:STDOUT: imports {
@@ -56,43 +41,10 @@ impl library "[[@TEST_NAME]]";
5641
// CHECK:STDOUT: package: <namespace> = namespace [concrete] {
5742
// CHECK:STDOUT: .A = imports.%Main.A
5843
// CHECK:STDOUT: }
59-
// CHECK:STDOUT: %default.import.loc1_17.1 = import <none>
60-
// CHECK:STDOUT: %default.import.loc1_17.2 = import <none>
61-
// CHECK:STDOUT: }
62-
// CHECK:STDOUT:
63-
// CHECK:STDOUT: --- fail_b.carbon
64-
// CHECK:STDOUT:
65-
// CHECK:STDOUT: constants {
66-
// CHECK:STDOUT: %B.type: type = facet_type <@B> [concrete]
67-
// CHECK:STDOUT: %Self: %B.type = symbolic_binding Self, 0 [symbolic]
68-
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
69-
// CHECK:STDOUT: %B.impl_witness: <witness> = impl_witness file.%B.impl_witness_table [concrete]
70-
// CHECK:STDOUT: }
71-
// CHECK:STDOUT:
72-
// CHECK:STDOUT: file {
73-
// CHECK:STDOUT: package: <namespace> = namespace [concrete] {
74-
// CHECK:STDOUT: .B = %B.decl
75-
// CHECK:STDOUT: }
76-
// CHECK:STDOUT: %B.decl: type = interface_decl @B [concrete = constants.%B.type] {} {}
77-
// CHECK:STDOUT: impl_decl @empty_tuple.type.as.B.impl [concrete] {} {
78-
// CHECK:STDOUT: %.loc7_7.1: %empty_tuple.type = tuple_literal ()
79-
// CHECK:STDOUT: %.loc7_7.2: type = converted %.loc7_7.1, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
80-
// CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [concrete = constants.%B.type]
81-
// CHECK:STDOUT: }
82-
// CHECK:STDOUT: %B.impl_witness_table = impl_witness_table (), @empty_tuple.type.as.B.impl [concrete]
83-
// CHECK:STDOUT: %B.impl_witness: <witness> = impl_witness %B.impl_witness_table [concrete = constants.%B.impl_witness]
44+
// CHECK:STDOUT: %default.import.loc2_17.1 = import <none>
45+
// CHECK:STDOUT: %default.import.loc2_17.2 = import <none>
8446
// CHECK:STDOUT: }
8547
// CHECK:STDOUT:
86-
// CHECK:STDOUT: interface @B {
87-
// CHECK:STDOUT: %Self: %B.type = symbolic_binding Self, 0 [symbolic = constants.%Self]
88-
// CHECK:STDOUT:
89-
// CHECK:STDOUT: !members:
90-
// CHECK:STDOUT: .Self = %Self
91-
// CHECK:STDOUT: witness = ()
92-
// CHECK:STDOUT: }
93-
// CHECK:STDOUT:
94-
// CHECK:STDOUT: impl @empty_tuple.type.as.B.impl: %.loc7_7.2 as %B.ref;
95-
// CHECK:STDOUT:
9648
// CHECK:STDOUT: --- b.impl.carbon
9749
// CHECK:STDOUT:
9850
// CHECK:STDOUT: constants {
@@ -111,8 +63,8 @@ impl library "[[@TEST_NAME]]";
11163
// CHECK:STDOUT: package: <namespace> = namespace [concrete] {
11264
// CHECK:STDOUT: .B = imports.%Main.B
11365
// CHECK:STDOUT: }
114-
// CHECK:STDOUT: %default.import.loc1_17.1 = import <none>
115-
// CHECK:STDOUT: %default.import.loc1_17.2 = import <none>
66+
// CHECK:STDOUT: %default.import.loc2_17.1 = import <none>
67+
// CHECK:STDOUT: %default.import.loc2_17.2 = import <none>
11668
// CHECK:STDOUT: }
11769
// CHECK:STDOUT:
11870
// CHECK:STDOUT: interface @B [from "fail_b.carbon"] {
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
2+
// Exceptions. See /LICENSE for license information.
3+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
//
5+
// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/none.carbon
6+
//
7+
// AUTOUPDATE
8+
// TIP: To test this file alone, run:
9+
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/named_constraint/import_constraint_decl.carbon
10+
// TIP: To dump output, run:
11+
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/named_constraint/import_constraint_decl.carbon
12+
13+
// --- a.carbon
14+
library "[[@TEST_NAME]]";
15+
16+
constraint A;
17+
18+
// --- a.impl.carbon
19+
//@include-in-dumps
20+
impl library "[[@TEST_NAME]]";
21+
22+
// --- b.carbon
23+
library "[[@TEST_NAME]]";
24+
25+
constraint B {}
26+
27+
// --- b.impl.carbon
28+
//@include-in-dumps
29+
impl library "[[@TEST_NAME]]";
30+
31+
fn F(T:! B) {}
32+
33+
// CHECK:STDOUT: --- a.impl.carbon
34+
// CHECK:STDOUT:
35+
// CHECK:STDOUT: imports {
36+
// CHECK:STDOUT: %Main.A = import_ref Main//a, A, unloaded
37+
// CHECK:STDOUT: }
38+
// CHECK:STDOUT:
39+
// CHECK:STDOUT: file {
40+
// CHECK:STDOUT: package: <namespace> = namespace [concrete] {
41+
// CHECK:STDOUT: .A = imports.%Main.A
42+
// CHECK:STDOUT: }
43+
// CHECK:STDOUT: %default.import.loc2_17.1 = import <none>
44+
// CHECK:STDOUT: %default.import.loc2_17.2 = import <none>
45+
// CHECK:STDOUT: }
46+
// CHECK:STDOUT:
47+
// CHECK:STDOUT: --- b.impl.carbon
48+
// CHECK:STDOUT:
49+
// CHECK:STDOUT: constants {
50+
// CHECK:STDOUT: %type: type = facet_type <type> [concrete]
51+
// CHECK:STDOUT: %.Self: %type = symbolic_binding .Self [symbolic_self]
52+
// CHECK:STDOUT: %T: %type = symbolic_binding T, 0 [symbolic]
53+
// CHECK:STDOUT: %pattern_type: type = pattern_type %type [concrete]
54+
// CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
55+
// CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
56+
// CHECK:STDOUT: }
57+
// CHECK:STDOUT:
58+
// CHECK:STDOUT: imports {
59+
// CHECK:STDOUT: %Main.B: type = import_ref Main//b, B, loaded [concrete = constants.%type]
60+
// CHECK:STDOUT: }
61+
// CHECK:STDOUT:
62+
// CHECK:STDOUT: file {
63+
// CHECK:STDOUT: package: <namespace> = namespace [concrete] {
64+
// CHECK:STDOUT: .B = imports.%Main.B
65+
// CHECK:STDOUT: .F = %F.decl
66+
// CHECK:STDOUT: }
67+
// CHECK:STDOUT: %default.import.loc2_17.1 = import <none>
68+
// CHECK:STDOUT: %default.import.loc2_17.2 = import <none>
69+
// CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {
70+
// CHECK:STDOUT: %T.patt: %pattern_type = symbolic_binding_pattern T, 0 [concrete]
71+
// CHECK:STDOUT: } {
72+
// CHECK:STDOUT: %.loc4: type = splice_block %B.ref [concrete = constants.%type] {
73+
// CHECK:STDOUT: %.Self: %type = symbolic_binding .Self [symbolic_self = constants.%.Self]
74+
// CHECK:STDOUT: %B.ref: type = name_ref B, imports.%Main.B [concrete = constants.%type]
75+
// CHECK:STDOUT: }
76+
// CHECK:STDOUT: %T.loc4_6.2: %type = symbolic_binding T, 0 [symbolic = %T.loc4_6.1 (constants.%T)]
77+
// CHECK:STDOUT: }
78+
// CHECK:STDOUT: }
79+
// CHECK:STDOUT:
80+
// CHECK:STDOUT: generic fn @F(%T.loc4_6.2: %type) {
81+
// CHECK:STDOUT: %T.loc4_6.1: %type = symbolic_binding T, 0 [symbolic = %T.loc4_6.1 (constants.%T)]
82+
// CHECK:STDOUT:
83+
// CHECK:STDOUT: !definition:
84+
// CHECK:STDOUT:
85+
// CHECK:STDOUT: fn() {
86+
// CHECK:STDOUT: !entry:
87+
// CHECK:STDOUT: return
88+
// CHECK:STDOUT: }
89+
// CHECK:STDOUT: }
90+
// CHECK:STDOUT:
91+
// CHECK:STDOUT: specific @F(constants.%T) {
92+
// CHECK:STDOUT: %T.loc4_6.1 => constants.%T
93+
// CHECK:STDOUT: }
94+
// CHECK:STDOUT:

0 commit comments

Comments
 (0)