@@ -159,16 +159,18 @@ class MinimalConformances {
159
159
160
160
DebugOptions Debug;
161
161
162
- // All conformance rules, sorted by (isExplicit(), getLHS()), with non-explicit
163
- // rules with longer left hand sides coming first.
162
+ // All conformance rules in the current minimization domain, sorted by
163
+ // (isExplicit(), getLHS()), with non-explicit rules with longer left hand
164
+ // sides coming first.
164
165
//
165
166
// The idea here is that we want less canonical rules to be eliminated first,
166
167
// but we prefer to eliminate non-explicit rules, in an attempt to keep protocol
167
168
// conformance rules in the same protocol as they were originally defined in.
168
169
SmallVector<unsigned , 4 > ConformanceRules;
169
170
170
- // Maps a conformance rule to a conformance path deriving the subject type's
171
- // base type. For example, consider the following conformance rule:
171
+ // Maps a conformance rule in the current minimization domain to a conformance
172
+ // path deriving the subject type's base type. For example, consider the
173
+ // following conformance rule:
172
174
//
173
175
// T.[P:A].[Q:B].[R] => T.[P:A].[Q:B]
174
176
//
@@ -177,15 +179,17 @@ class MinimalConformances {
177
179
// path for the term T.[P:A].[Q], known as the 'parent path'.
178
180
llvm::MapVector<unsigned , SmallVector<unsigned , 2 >> ParentPaths;
179
181
180
- // Maps a conformance rule to a list of paths. Each path in the list is a unique
181
- // derivation of the conformance in terms of other conformance rules.
182
+ // Maps a conformance rule in the current minimization domain to a list of paths.
183
+ // Each path in the list is a unique derivation of the conformance in terms of
184
+ // other conformance rules.
182
185
llvm::MapVector<unsigned , std::vector<SmallVector<unsigned , 2 >>> ConformancePaths;
183
186
184
- // The set of conformance rules which are protocol refinements, that is rules of
185
- // the form [P].[Q] => [P].
187
+ // The set of conformance rules (from all minimization domains) which are protocol
188
+ // refinements, that is rules of the form [P].[Q] => [P].
186
189
llvm::DenseSet<unsigned > ProtocolRefinements;
187
190
188
- // This is the result.
191
+ // This is the computed result set of redundant conformance rules in the current
192
+ // minimization domain.
189
193
llvm::DenseSet<unsigned > &RedundantConformances;
190
194
191
195
void decomposeTermIntoConformanceRuleLeftHandSides (
@@ -391,17 +395,15 @@ void MinimalConformances::collectConformanceRules() {
391
395
if (!rule.isAnyConformanceRule ())
392
396
continue ;
393
397
398
+ // Save protocol refinement relations in a side table.
399
+ if (rule.isProtocolRefinementRule (Context))
400
+ ProtocolRefinements.insert (ruleID);
401
+
394
402
if (!System.isInMinimizationDomain (rule.getLHS ().getRootProtocol ()))
395
403
continue ;
396
404
397
405
ConformanceRules.push_back (ruleID);
398
406
399
- // Save protocol refinement relations in a side table.
400
- if (rule.isProtocolRefinementRule ()) {
401
- ProtocolRefinements.insert (ruleID);
402
- continue ;
403
- }
404
-
405
407
auto lhs = rule.getLHS ();
406
408
407
409
// Record a parent path if the subject type itself requires a non-trivial
@@ -698,7 +700,7 @@ bool MinimalConformances::isValidConformancePath(
698
700
bool MinimalConformances::isValidRefinementPath (
699
701
const llvm::SmallVectorImpl<unsigned > &path) const {
700
702
for (unsigned ruleID : path) {
701
- if (!System. getRule (ruleID). isProtocolRefinementRule () )
703
+ if (ProtocolRefinements. count (ruleID) == 0 )
702
704
return false ;
703
705
}
704
706
@@ -867,8 +869,14 @@ void MinimalConformances::computeMinimalConformances() {
867
869
for (const auto &path : paths) {
868
870
// Only consider a protocol refinement rule to be redundant if it is
869
871
// witnessed by a composition of other protocol refinement rules.
870
- if (isProtocolRefinement && !isValidRefinementPath (path))
872
+ if (isProtocolRefinement && !isValidRefinementPath (path)) {
873
+ if (Debug.contains (DebugFlags::MinimalConformances)) {
874
+ llvm::dbgs () << " Not a refinement path: " ;
875
+ dumpConformancePath (llvm::errs (), path);
876
+ llvm::dbgs () << " \n " ;
877
+ }
871
878
continue ;
879
+ }
872
880
873
881
llvm::SmallDenseSet<unsigned , 4 > visited;
874
882
visited.insert (ruleID);
0 commit comments