Skip to content

Commit 04b8712

Browse files
authored
Merge pull request #12327 from slavapestov/more-trivial-cleanups
More trivial cleanups
2 parents d0232e5 + 5e5b626 commit 04b8712

File tree

5 files changed

+25
-48
lines changed

5 files changed

+25
-48
lines changed

include/swift/AST/Witness.h

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

153-
/// Implicit conversion to the \c ConcreteDeclRef, which is used by a
154-
/// number of clients.
155-
///
156-
/// FIXME: We probably want this to go away eventually, because clients using
157-
/// it will all need to be cognizant of the synthetic environment.
158-
operator ConcreteDeclRef() const { return getDeclRef(); }
159-
160153
/// Determine whether this witness requires any substitutions.
161154
bool requiresSubstitution() const { return storage.is<StoredWitness *>(); }
162155

lib/AST/ConformanceLookupTable.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,7 @@ ConformanceLookupTable::getSatisfiedProtocolRequirementsForMember(
11311131

11321132
auto normal = conf->getRootNormalConformance();
11331133
normal->forEachValueWitness(resolver, [&](ValueDecl *req,
1134-
ConcreteDeclRef witness) {
1134+
Witness witness) {
11351135
if (witness.getDecl() == member)
11361136
reqs.push_back(req);
11371137
});

lib/SILGen/SILGenType.cpp

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -604,50 +604,30 @@ SILGenModule::emitProtocolWitness(ProtocolConformance *conformance,
604604
Witness witness) {
605605
auto requirementInfo = Types.getConstantInfo(requirement);
606606

607+
// Work out the lowered function type of the SIL witness thunk.
608+
auto reqtOrigTy = cast<GenericFunctionType>(requirementInfo.LoweredType);
609+
607610
// Mapping from the requirement's generic signature to the witness
608611
// thunk's generic signature.
609-
SubstitutionMap reqtSubMap;
612+
auto reqtSubs = witness.getRequirementToSyntheticSubs();
613+
auto reqtSubMap = reqtOrigTy->getGenericSignature()->getSubstitutionMap(reqtSubs);
610614

611615
// The generic environment for the witness thunk.
612-
GenericEnvironment *genericEnv = nullptr;
616+
auto *genericEnv = witness.getSyntheticEnvironment();
617+
618+
// The type of the witness thunk.
619+
auto input = reqtOrigTy->getInput().subst(reqtSubMap)->getCanonicalType();
620+
auto result = reqtOrigTy->getResult().subst(reqtSubMap)->getCanonicalType();
613621

614-
// Work out the lowered function type of the SIL witness thunk.
615-
auto reqtOrigTy = cast<GenericFunctionType>(requirementInfo.LoweredType);
616622
CanAnyFunctionType reqtSubstTy;
617-
SubstitutionList witnessSubs;
618-
if (witness.requiresSubstitution()) {
619-
genericEnv = witness.getSyntheticEnvironment();
620-
witnessSubs = witness.getSubstitutions();
621-
622-
auto reqtSubs = witness.getRequirementToSyntheticSubs();
623-
reqtSubMap = reqtOrigTy->getGenericSignature()
624-
->getSubstitutionMap(reqtSubs);
625-
626-
auto input = reqtOrigTy->getInput().subst(reqtSubMap);
627-
auto result = reqtOrigTy->getResult().subst(reqtSubMap);
628-
629-
if (genericEnv) {
630-
auto *genericSig = genericEnv->getGenericSignature();
631-
reqtSubstTy = cast<GenericFunctionType>(
632-
GenericFunctionType::get(genericSig, input, result,
633-
reqtOrigTy->getExtInfo())
634-
->getCanonicalType());
635-
} else {
636-
reqtSubstTy = cast<FunctionType>(
637-
FunctionType::get(input, result,
638-
reqtOrigTy->getExtInfo())
639-
->getCanonicalType());
640-
}
623+
if (genericEnv) {
624+
auto *genericSig = genericEnv->getGenericSignature();
625+
reqtSubstTy = CanGenericFunctionType::get(
626+
genericSig->getCanonicalSignature(),
627+
input, result, reqtOrigTy->getExtInfo());
641628
} else {
642-
reqtSubMap = SubstitutionMap::getProtocolSubstitutions(
643-
conformance->getProtocol(),
644-
conformance->getType(),
645-
ProtocolConformanceRef(conformance));
646-
647-
auto input = reqtOrigTy->getInput().subst(reqtSubMap)->getCanonicalType();
648-
auto result = reqtOrigTy->getResult().subst(reqtSubMap)->getCanonicalType();
649-
650-
reqtSubstTy = CanFunctionType::get(input, result, reqtOrigTy->getExtInfo());
629+
reqtSubstTy = CanFunctionType::get(
630+
input, result, reqtOrigTy->getExtInfo());
651631
}
652632

653633
// Lower the witness thunk type with the requirement's abstraction level.
@@ -659,7 +639,7 @@ SILGenModule::emitProtocolWitness(ProtocolConformance *conformance,
659639
Mangle::ASTMangler NewMangler;
660640
std::string nameBuffer = NewMangler.mangleWitnessThunk(conformance,
661641
requirement.getDecl());
662-
642+
663643
// If the thunked-to function is set to be always inlined, do the
664644
// same with the witness, on the theory that the user wants all
665645
// calls removed if possible, e.g. when we're able to devirtualize
@@ -694,6 +674,10 @@ SILGenModule::emitProtocolWitness(ProtocolConformance *conformance,
694674

695675
SILGenFunction SGF(*this, *f);
696676

677+
// Substitutions mapping the generic parameters of the witness to
678+
// archetypes of the witness thunk generic environment.
679+
auto witnessSubs = witness.getSubstitutions();
680+
697681
// Open-code certain protocol witness "thunks".
698682
if (maybeOpenCodeProtocolWitness(SGF, conformance, linkage,
699683
selfInterfaceType, selfType, genericEnv,

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,7 @@ matchWitness(TypeChecker &tc,
12131213
if (reqGenericEnv)
12141214
selfTy = reqGenericEnv->mapTypeIntoContext(selfTy);
12151215

1216-
// Open up the type of the requirement.
1216+
// Open up the type of the requirement.
12171217
reqLocator = cs->getConstraintLocator(
12181218
static_cast<Expr *>(nullptr),
12191219
LocatorPathElt(ConstraintLocator::Requirement, req));

lib/Serialization/Serialization.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1642,7 +1642,7 @@ void Serializer::writeDefaultWitnessTable(const ProtocolDecl *proto,
16421642
unsigned abbrCode = abbrCodes[DefaultWitnessTableLayout::Code];
16431643
for (auto member : proto->getMembers()) {
16441644
if (auto *value = dyn_cast<ValueDecl>(member)) {
1645-
ConcreteDeclRef witness = proto->getDefaultWitness(value);
1645+
auto witness = proto->getDefaultWitness(value);
16461646
if (!witness)
16471647
continue;
16481648

0 commit comments

Comments
 (0)