@@ -36,38 +36,46 @@ RequirementMachine::RequirementMachine(RewriteContext &ctx)
3636
3737RequirementMachine::~RequirementMachine () {}
3838
39- static void checkCompletionResult (const RequirementMachine &machine,
40- CompletionResult result) {
39+ // / Checks the result of a completion in a context where we can't diagnose
40+ // / failure, either when building a rewrite system from an existing
41+ // / minimal signature (which should have been checked when it was
42+ // / minimized) or from AbstractGenericSignatureRequest (where failure
43+ // / is fatal).
44+ void RequirementMachine::checkCompletionResult (CompletionResult result) const {
4145 switch (result) {
4246 case CompletionResult::Success:
4347 break ;
4448
4549 case CompletionResult::MaxRuleCount:
4650 llvm::errs () << " Rewrite system exceeded maximum rule count\n " ;
47- machine. dump (llvm::errs ());
51+ dump (llvm::errs ());
4852 abort ();
4953
5054 case CompletionResult::MaxRuleLength:
5155 llvm::errs () << " Rewrite system exceeded rule length limit\n " ;
52- machine. dump (llvm::errs ());
56+ dump (llvm::errs ());
5357 abort ();
5458
5559 case CompletionResult::MaxConcreteNesting:
5660 llvm::errs () << " Rewrite system exceeded concrete type nesting depth limit\n " ;
57- machine. dump (llvm::errs ());
61+ dump (llvm::errs ());
5862 abort ();
5963 }
6064}
6165
6266// / Build a requirement machine for the requirements of a generic signature.
6367// /
68+ // / In this mode, minimization is not going to be performed, so rewrite loops
69+ // / are not recorded.
70+ // /
6471// / This must only be called exactly once, before any other operations are
6572// / performed on this requirement machine.
6673// /
6774// / Used by ASTContext::getOrCreateRequirementMachine().
6875// /
69- // / Asserts if completion fails within the configured number of steps.
70- void RequirementMachine::initWithGenericSignature (CanGenericSignature sig) {
76+ // / Returns failure if completion fails within the configured number of steps.
77+ std::pair<CompletionResult, unsigned >
78+ RequirementMachine::initWithGenericSignature (CanGenericSignature sig) {
7179 Sig = sig;
7280 Params.append (sig.getGenericParams ().begin (),
7381 sig.getGenericParams ().end ());
@@ -92,17 +100,21 @@ void RequirementMachine::initWithGenericSignature(CanGenericSignature sig) {
92100 std::move (builder.RequirementRules ));
93101
94102 auto result = computeCompletion (RewriteSystem::DisallowInvalidRequirements);
95- checkCompletionResult (*this , result.first );
96103
97104 if (Dump) {
98105 llvm::dbgs () << " }\n " ;
99106 }
107+
108+ return result;
100109}
101110
102111// / Build a requirement machine for the structural requirements of a set
103112// / of protocols, which are understood to form a strongly-connected component
104113// / (SCC) of the protocol dependency graph.
105114// /
115+ // / In this mode, minimization will be performed, so rewrite loops are recorded
116+ // / during completion.
117+ // /
106118// / This must only be called exactly once, before any other operations are
107119// / performed on this requirement machine.
108120// /
@@ -138,55 +150,16 @@ RequirementMachine::initWithProtocols(ArrayRef<const ProtocolDecl *> protos) {
138150 return result;
139151}
140152
141- // / Build a requirement machine from a set of generic parameters and
142- // / (possibly non-canonical or non-minimal) abstract requirements.
143- // /
144- // / This must only be called exactly once, before any other operations are
145- // / performed on this requirement machine.
146- // /
147- // / Used by AbstractGenericSignatureRequest.
148- // /
149- // / Asserts if completion fails within the configured number of steps.
150- void RequirementMachine::initWithAbstractRequirements (
151- ArrayRef<GenericTypeParamType *> genericParams,
152- ArrayRef<Requirement> requirements) {
153- Params.append (genericParams.begin (), genericParams.end ());
154-
155- FrontendStatsTracer tracer (Stats, " build-rewrite-system" );
156-
157- if (Dump) {
158- llvm::dbgs () << " Adding generic parameters:" ;
159- for (auto *paramTy : genericParams)
160- llvm::dbgs () << " " << Type (paramTy);
161- llvm::dbgs () << " \n " ;
162- }
163-
164- // Collect the top-level requirements, and all transtively-referenced
165- // protocol requirement signatures.
166- RuleBuilder builder (Context, System.getProtocolMap ());
167- builder.addRequirements (requirements);
168-
169- // Add the initial set of rewrite rules to the rewrite system.
170- System.initialize (/* recordLoops=*/ true ,
171- /* protos=*/ ArrayRef<const ProtocolDecl *>(),
172- std::move (builder.PermanentRules ),
173- std::move (builder.RequirementRules ));
174-
175- auto result = computeCompletion (RewriteSystem::AllowInvalidRequirements);
176- checkCompletionResult (*this , result.first );
177-
178- if (Dump) {
179- llvm::dbgs () << " }\n " ;
180- }
181- }
182-
183153// / Build a requirement machine from a set of generic parameters and
184154// / structural requirements.
185155// /
156+ // / In this mode, minimization will be performed, so rewrite loops are recorded
157+ // / during completion.
158+ // /
186159// / This must only be called exactly once, before any other operations are
187160// / performed on this requirement machine.
188161// /
189- // / Used by InferredGenericSignatureRequest.
162+ // / Used by AbstractGenericSignatureRequest and InferredGenericSignatureRequest.
190163// /
191164// / Returns failure if completion fails within the configured number of steps.
192165std::pair<CompletionResult, unsigned >
0 commit comments