|
21 | 21 | using namespace swift;
|
22 | 22 | using namespace rewriting;
|
23 | 23 |
|
24 |
| -void RequirementMachine::verify(const MutableTerm &term) const { |
25 |
| -#ifndef NDEBUG |
26 |
| - // If the term is in the generic parameter domain, ensure we have a valid |
27 |
| - // generic parameter. |
28 |
| - if (term.begin()->getKind() == Symbol::Kind::GenericParam) { |
29 |
| - auto *genericParam = term.begin()->getGenericParam(); |
30 |
| - TypeArrayView<GenericTypeParamType> genericParams = getGenericParams(); |
31 |
| - auto found = std::find(genericParams.begin(), |
32 |
| - genericParams.end(), |
33 |
| - genericParam); |
34 |
| - if (found == genericParams.end()) { |
35 |
| - llvm::errs() << "Bad generic parameter in " << term << "\n"; |
36 |
| - dump(llvm::errs()); |
37 |
| - abort(); |
38 |
| - } |
39 |
| - } |
40 |
| - |
41 |
| - MutableTerm erased; |
42 |
| - |
43 |
| - // First, "erase" resolved associated types from the term, and try |
44 |
| - // to simplify it again. |
45 |
| - for (auto symbol : term) { |
46 |
| - if (erased.empty()) { |
47 |
| - switch (symbol.getKind()) { |
48 |
| - case Symbol::Kind::Protocol: |
49 |
| - case Symbol::Kind::GenericParam: |
50 |
| - erased.add(symbol); |
51 |
| - continue; |
52 |
| - |
53 |
| - case Symbol::Kind::AssociatedType: |
54 |
| - erased.add(Symbol::forProtocol(symbol.getProtocols()[0], Context)); |
55 |
| - break; |
56 |
| - |
57 |
| - case Symbol::Kind::Name: |
58 |
| - case Symbol::Kind::Layout: |
59 |
| - case Symbol::Kind::Superclass: |
60 |
| - case Symbol::Kind::ConcreteType: |
61 |
| - case Symbol::Kind::ConcreteConformance: |
62 |
| - llvm::errs() << "Bad initial symbol in " << term << "\n"; |
63 |
| - abort(); |
64 |
| - break; |
65 |
| - } |
66 |
| - } |
67 |
| - |
68 |
| - switch (symbol.getKind()) { |
69 |
| - case Symbol::Kind::Name: |
70 |
| - assert(!erased.empty()); |
71 |
| - erased.add(symbol); |
72 |
| - break; |
73 |
| - |
74 |
| - case Symbol::Kind::AssociatedType: |
75 |
| - erased.add(Symbol::forName(symbol.getName(), Context)); |
76 |
| - break; |
77 |
| - |
78 |
| - case Symbol::Kind::Protocol: |
79 |
| - case Symbol::Kind::GenericParam: |
80 |
| - case Symbol::Kind::Layout: |
81 |
| - case Symbol::Kind::Superclass: |
82 |
| - case Symbol::Kind::ConcreteType: |
83 |
| - case Symbol::Kind::ConcreteConformance: |
84 |
| - llvm::errs() << "Bad interior symbol " << symbol << " in " << term << "\n"; |
85 |
| - abort(); |
86 |
| - break; |
87 |
| - } |
88 |
| - } |
89 |
| - |
90 |
| - MutableTerm simplified = erased; |
91 |
| - System.simplify(simplified); |
92 |
| - |
93 |
| - // We should end up with the same term. |
94 |
| - if (simplified != term) { |
95 |
| - llvm::errs() << "Term verification failed\n"; |
96 |
| - llvm::errs() << "Initial term: " << term << "\n"; |
97 |
| - llvm::errs() << "Erased term: " << erased << "\n"; |
98 |
| - llvm::errs() << "Simplified term: " << simplified << "\n"; |
99 |
| - llvm::errs() << "\n"; |
100 |
| - dump(llvm::errs()); |
101 |
| - abort(); |
102 |
| - } |
103 |
| -#endif |
104 |
| -} |
105 |
| - |
106 |
| -void RequirementMachine::dump(llvm::raw_ostream &out) const { |
107 |
| - out << "Requirement machine for "; |
108 |
| - if (Sig) |
109 |
| - out << Sig; |
110 |
| - else if (!Params.empty()) { |
111 |
| - out << "fresh signature "; |
112 |
| - for (auto paramTy : Params) |
113 |
| - out << " " << Type(paramTy); |
114 |
| - } else { |
115 |
| - assert(!Protos.empty()); |
116 |
| - out << "protocols ["; |
117 |
| - for (auto *proto : Protos) { |
118 |
| - out << " " << proto->getName(); |
119 |
| - } |
120 |
| - out << " ]"; |
121 |
| - } |
122 |
| - out << "\n"; |
123 |
| - |
124 |
| - System.dump(out); |
125 |
| - Map.dump(out); |
126 |
| - |
127 |
| - out << "Conformance access paths: {\n"; |
128 |
| - for (auto pair : ConformanceAccessPaths) { |
129 |
| - out << "- " << pair.first.first << " : "; |
130 |
| - out << pair.first.second->getName() << " => "; |
131 |
| - pair.second.print(out); |
132 |
| - out << "\n"; |
133 |
| - } |
134 |
| - out << "}\n"; |
135 |
| -} |
136 |
| - |
137 | 24 | RequirementMachine::RequirementMachine(RewriteContext &ctx)
|
138 | 25 | : Context(ctx), System(ctx), Map(System) {
|
139 | 26 | auto &langOpts = ctx.getASTContext().LangOpts;
|
@@ -368,3 +255,34 @@ void RequirementMachine::computeCompletion(RewriteSystem::ValidityPolicy policy)
|
368 | 255 | bool RequirementMachine::isComplete() const {
|
369 | 256 | return Complete;
|
370 | 257 | }
|
| 258 | + |
| 259 | +void RequirementMachine::dump(llvm::raw_ostream &out) const { |
| 260 | + out << "Requirement machine for "; |
| 261 | + if (Sig) |
| 262 | + out << Sig; |
| 263 | + else if (!Params.empty()) { |
| 264 | + out << "fresh signature "; |
| 265 | + for (auto paramTy : Params) |
| 266 | + out << " " << Type(paramTy); |
| 267 | + } else { |
| 268 | + assert(!Protos.empty()); |
| 269 | + out << "protocols ["; |
| 270 | + for (auto *proto : Protos) { |
| 271 | + out << " " << proto->getName(); |
| 272 | + } |
| 273 | + out << " ]"; |
| 274 | + } |
| 275 | + out << "\n"; |
| 276 | + |
| 277 | + System.dump(out); |
| 278 | + Map.dump(out); |
| 279 | + |
| 280 | + out << "Conformance access paths: {\n"; |
| 281 | + for (auto pair : ConformanceAccessPaths) { |
| 282 | + out << "- " << pair.first.first << " : "; |
| 283 | + out << pair.first.second->getName() << " => "; |
| 284 | + pair.second.print(out); |
| 285 | + out << "\n"; |
| 286 | + } |
| 287 | + out << "}\n"; |
| 288 | +} |
0 commit comments