@@ -36,38 +36,46 @@ RequirementMachine::RequirementMachine(RewriteContext &ctx)
36
36
37
37
RequirementMachine::~RequirementMachine () {}
38
38
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 {
41
45
switch (result) {
42
46
case CompletionResult::Success:
43
47
break ;
44
48
45
49
case CompletionResult::MaxRuleCount:
46
50
llvm::errs () << " Rewrite system exceeded maximum rule count\n " ;
47
- machine. dump (llvm::errs ());
51
+ dump (llvm::errs ());
48
52
abort ();
49
53
50
54
case CompletionResult::MaxRuleLength:
51
55
llvm::errs () << " Rewrite system exceeded rule length limit\n " ;
52
- machine. dump (llvm::errs ());
56
+ dump (llvm::errs ());
53
57
abort ();
54
58
55
59
case CompletionResult::MaxConcreteNesting:
56
60
llvm::errs () << " Rewrite system exceeded concrete type nesting depth limit\n " ;
57
- machine. dump (llvm::errs ());
61
+ dump (llvm::errs ());
58
62
abort ();
59
63
}
60
64
}
61
65
62
66
// / Build a requirement machine for the requirements of a generic signature.
63
67
// /
68
+ // / In this mode, minimization is not going to be performed, so rewrite loops
69
+ // / are not recorded.
70
+ // /
64
71
// / This must only be called exactly once, before any other operations are
65
72
// / performed on this requirement machine.
66
73
// /
67
74
// / Used by ASTContext::getOrCreateRequirementMachine().
68
75
// /
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) {
71
79
Sig = sig;
72
80
Params.append (sig.getGenericParams ().begin (),
73
81
sig.getGenericParams ().end ());
@@ -92,17 +100,21 @@ void RequirementMachine::initWithGenericSignature(CanGenericSignature sig) {
92
100
std::move (builder.RequirementRules ));
93
101
94
102
auto result = computeCompletion (RewriteSystem::DisallowInvalidRequirements);
95
- checkCompletionResult (*this , result.first );
96
103
97
104
if (Dump) {
98
105
llvm::dbgs () << " }\n " ;
99
106
}
107
+
108
+ return result;
100
109
}
101
110
102
111
// / Build a requirement machine for the structural requirements of a set
103
112
// / of protocols, which are understood to form a strongly-connected component
104
113
// / (SCC) of the protocol dependency graph.
105
114
// /
115
+ // / In this mode, minimization will be performed, so rewrite loops are recorded
116
+ // / during completion.
117
+ // /
106
118
// / This must only be called exactly once, before any other operations are
107
119
// / performed on this requirement machine.
108
120
// /
@@ -138,55 +150,16 @@ RequirementMachine::initWithProtocols(ArrayRef<const ProtocolDecl *> protos) {
138
150
return result;
139
151
}
140
152
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
-
183
153
// / Build a requirement machine from a set of generic parameters and
184
154
// / structural requirements.
185
155
// /
156
+ // / In this mode, minimization will be performed, so rewrite loops are recorded
157
+ // / during completion.
158
+ // /
186
159
// / This must only be called exactly once, before any other operations are
187
160
// / performed on this requirement machine.
188
161
// /
189
- // / Used by InferredGenericSignatureRequest.
162
+ // / Used by AbstractGenericSignatureRequest and InferredGenericSignatureRequest.
190
163
// /
191
164
// / Returns failure if completion fails within the configured number of steps.
192
165
std::pair<CompletionResult, unsigned >
0 commit comments