@@ -72,124 +72,45 @@ static auto NoteIncompleteNamedConstraint(
7272 }
7373}
7474
75- // Makes a copy of a Specific from one generic to apply to another given
76- // `generic_id`, with a given `Self` argument appended to the end.
77- static auto MakeCopyOfSpecificAndAppendSelf (
78- Context& context, SemIR::LocId loc_id, SemIR::SpecificId specific_id,
79- SemIR::GenericId generic_id, SemIR::InstId self_id) -> SemIR::SpecificId {
80- auto source_specific_args_id =
81- context.specifics ().GetArgsOrEmpty (specific_id);
82- auto source_specific_args =
83- context.inst_blocks ().Get (source_specific_args_id);
84-
85- llvm::SmallVector<SemIR::InstId> arg_ids;
86- arg_ids.reserve (source_specific_args.size () + 1 );
87- // Start with the enclosing arguments from the source Specific.
88- llvm::append_range (arg_ids, source_specific_args);
89- // Add the new `Self` argument.
90- arg_ids.push_back (self_id);
91-
92- return MakeSpecific (context, loc_id, generic_id, arg_ids);
93- }
94-
95- static auto GetRequireImplsSpecificSelf (Context& context,
96- const SemIR::RequireImpls& require)
97- -> SemIR::InstId {
98- const auto & require_generic = context.generics ().Get (require.generic_id );
99- const auto & require_self_specific =
100- context.specifics ().Get (require_generic.self_specific_id );
101- auto require_self_specific_args =
102- context.inst_blocks ().Get (require_self_specific.args_id );
103- // The last argument of a `require` generic is always `Self`, as require can
104- // not have any parameters of its own, only enclosing parameters.
105- return require_self_specific_args.back ();
106- }
107-
108- static auto GetFacetTypeInSpecific (Context& context, SemIR::InstId facet_type,
109- SemIR::SpecificId specific_id)
110- -> SemIR::FacetTypeId {
111- auto const_facet_type = SemIR::GetConstantValueInSpecific (
112- context.sem_ir (), specific_id, facet_type);
113- auto facet_type_in_specific = context.insts ().TryGetAs <SemIR::FacetType>(
114- context.constant_values ().GetInstId (const_facet_type));
115- if (!facet_type_in_specific.has_value ()) {
116- return SemIR::FacetTypeId::None;
117- }
118- return facet_type_in_specific->facet_type_id ;
119- }
120-
12175static auto RequireCompleteFacetType (Context& context, SemIR::LocId loc_id,
12276 const SemIR::FacetType& facet_type,
12377 MakeDiagnosticBuilderFn diagnoser)
12478 -> bool {
125- llvm::SmallVector<SemIR::FacetTypeId> work = {facet_type.facet_type_id };
126- while (!work.empty ()) {
127- auto next_facet_type_id = work.pop_back_val ();
128- const auto & facet_type_info = context.facet_types ().Get (next_facet_type_id);
129-
130- for (auto extends : facet_type_info.extend_constraints ) {
131- auto interface_id = extends.interface_id ;
132- const auto & interface = context.interfaces ().Get (interface_id);
133- if (!interface.is_complete ()) {
134- if (diagnoser) {
135- auto builder = diagnoser ();
136- NoteIncompleteInterface (context, interface_id, builder);
137- builder.Emit ();
138- }
139- return false ;
140- }
141-
142- for (auto require_impls_id : context.require_impls_blocks ().Get (
143- interface.require_impls_block_id )) {
144- const auto & require = context.require_impls ().Get (require_impls_id);
145- if (require.extend_self ) {
146- auto require_specific_id = MakeCopyOfSpecificAndAppendSelf (
147- context, loc_id, extends.specific_id , require.generic_id ,
148- GetRequireImplsSpecificSelf (context, require));
149- auto facet_type_id = GetFacetTypeInSpecific (
150- context, require.facet_type_inst_id , require_specific_id);
151- if (facet_type_id.has_value ()) {
152- work.push_back (facet_type_id);
153- }
154- }
155- }
79+ const auto & facet_type_info =
80+ context.facet_types ().Get (facet_type.facet_type_id );
15681
157- if (extends.specific_id .has_value ()) {
158- ResolveSpecificDefinition (context, loc_id, extends.specific_id );
82+ for (auto extends : facet_type_info.extend_constraints ) {
83+ auto interface_id = extends.interface_id ;
84+ const auto & interface = context.interfaces ().Get (interface_id);
85+ if (!interface.is_complete ()) {
86+ if (diagnoser) {
87+ auto builder = diagnoser ();
88+ NoteIncompleteInterface (context, interface_id, builder);
89+ builder.Emit ();
15990 }
91+ return false ;
16092 }
16193
162- for (auto extends : facet_type_info.extend_named_constraints ) {
163- auto named_constraint_id = extends.named_constraint_id ;
164- const auto & constraint =
165- context.named_constraints ().Get (named_constraint_id);
166- if (!constraint.is_complete ()) {
167- if (diagnoser) {
168- auto builder = diagnoser ();
169- NoteIncompleteNamedConstraint (context, named_constraint_id, builder);
170- builder.Emit ();
171- }
172- return false ;
173- }
94+ if (extends.specific_id .has_value ()) {
95+ ResolveSpecificDefinition (context, loc_id, extends.specific_id );
96+ }
97+ }
17498
175- for (auto require_impls_id : context.require_impls_blocks ().Get (
176- constraint.require_impls_block_id )) {
177- const auto & require = context.require_impls ().Get (require_impls_id);
178- if (require.extend_self ) {
179- auto require_specific_id = MakeCopyOfSpecificAndAppendSelf (
180- context, loc_id, extends.specific_id , require.generic_id ,
181- GetRequireImplsSpecificSelf (context, require));
182- auto facet_type_id = GetFacetTypeInSpecific (
183- context, require.facet_type_inst_id , require_specific_id);
184- if (facet_type_id.has_value ()) {
185- work.push_back (facet_type_id);
186- }
187- }
99+ for (auto extends : facet_type_info.extend_named_constraints ) {
100+ auto named_constraint_id = extends.named_constraint_id ;
101+ const auto & constraint =
102+ context.named_constraints ().Get (named_constraint_id);
103+ if (!constraint.is_complete ()) {
104+ if (diagnoser) {
105+ auto builder = diagnoser ();
106+ NoteIncompleteNamedConstraint (context, named_constraint_id, builder);
107+ builder.Emit ();
188108 }
109+ return false ;
110+ }
189111
190- if (extends.specific_id .has_value ()) {
191- ResolveSpecificDefinition (context, loc_id, extends.specific_id );
192- }
112+ if (extends.specific_id .has_value ()) {
113+ ResolveSpecificDefinition (context, loc_id, extends.specific_id );
193114 }
194115 }
195116
0 commit comments