Skip to content

Commit 01e8cbd

Browse files
committed
[AST] Remove requiresSubstitution invariant from Witness
1 parent f5db1df commit 01e8cbd

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

include/swift/AST/Witness.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,6 @@ class Witness {
150150
/// Determines whether there is a witness at all.
151151
explicit operator bool() const { return !storage.isNull(); }
152152

153-
/// Determine whether this witness requires any substitutions.
154-
bool requiresSubstitution() const { return storage.is<StoredWitness *>(); }
155-
156153
/// Retrieve the substitutions required to use this witness from the
157154
/// synthetic environment.
158155
///
@@ -164,15 +161,17 @@ class Witness {
164161

165162
/// Retrieve the synthetic generic environment.
166163
GenericEnvironment *getSyntheticEnvironment() const {
167-
assert(requiresSubstitution() && "No substitutions required for witness");
168-
return storage.get<StoredWitness *>()->syntheticEnvironment;
164+
if (auto *storedWitness = storage.dyn_cast<StoredWitness *>())
165+
return storedWitness->syntheticEnvironment;
166+
return nullptr;
169167
}
170168

171169
/// Retrieve the substitution map that maps the interface types of the
172170
/// requirement to the interface types of the synthetic environment.
173171
SubstitutionList getRequirementToSyntheticSubs() const {
174-
assert(requiresSubstitution() && "No substitutions required for witness");
175-
return storage.get<StoredWitness *>()->reqToSyntheticEnvSubs;
172+
if (auto *storedWitness = storage.dyn_cast<StoredWitness *>())
173+
return storedWitness->reqToSyntheticEnvSubs;
174+
return {};
176175
}
177176

178177
LLVM_ATTRIBUTE_DEPRECATED(

lib/AST/ASTVerifier.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2507,13 +2507,18 @@ class Verifier : public ASTWalker {
25072507
// Check the witness substitutions.
25082508
const auto &witness = normal->getWitness(req, nullptr);
25092509

2510-
if (witness.requiresSubstitution()) {
2511-
GenericEnv.push_back({witness.getSyntheticEnvironment()});
2512-
for (const auto &sub : witness.getSubstitutions()) {
2513-
verifyChecked(sub.getReplacement());
2514-
}
2510+
if (auto *genericEnv = witness.getSyntheticEnvironment())
2511+
GenericEnv.push_back({genericEnv});
2512+
2513+
for (const auto &sub : witness.getRequirementToSyntheticSubs())
2514+
verifyChecked(sub.getReplacement());
2515+
2516+
for (const auto &sub : witness.getSubstitutions())
2517+
verifyChecked(sub.getReplacement());
2518+
2519+
if (auto *genericEnv = witness.getSyntheticEnvironment()) {
25152520
assert(GenericEnv.back().storage.dyn_cast<GenericEnvironment *>()
2516-
== witness.getSyntheticEnvironment());
2521+
== genericEnv);
25172522
GenericEnv.pop_back();
25182523
}
25192524

lib/Serialization/Serialization.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,9 +1573,7 @@ void Serializer::writeNormalConformance(
15731573
// Write the witness substitutions.
15741574
writeSubstitutions(witness.getSubstitutions(),
15751575
DeclTypeAbbrCodes,
1576-
witness.requiresSubstitution()
1577-
? witness.getSyntheticEnvironment()
1578-
: nullptr);
1576+
witness.getSyntheticEnvironment());
15791577
});
15801578
}
15811579

0 commit comments

Comments
 (0)