Skip to content

Commit af1706e

Browse files
authored
Merge pull request swiftlang#38606 from CodaFi/fly-by-require
2 parents 2d546b0 + e545d7f commit af1706e

20 files changed

+118
-173
lines changed

include/swift/AST/GenericSignature.h

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,18 @@ class GenericSignature {
201201
/// signature.
202202
GenericEnvironment *getGenericEnvironment() const;
203203

204+
/// Return the requirements of this generic signature that are not also
205+
/// satisfied by \c otherSig.
206+
///
207+
/// \param otherSig Another generic signature whose generic parameters are
208+
/// equivalent to or a subset of the generic parameters in this signature.
209+
SmallVector<Requirement, 4>
210+
requirementsNotSatisfiedBy(GenericSignature otherSig) const;
211+
212+
/// Return the canonical version of the given type under this generic
213+
/// signature.
214+
CanType getCanonicalTypeInContext(Type type) const;
215+
204216
/// Check invariants.
205217
void verify() const;
206218
};
@@ -373,18 +385,6 @@ class alignas(1 << TypeAlignInBits) GenericSignatureImpl final
373385
bool isRequirementSatisfied(
374386
Requirement requirement, bool allowMissing = false) const;
375387

376-
/// Return the requirements of this generic signature that are not also
377-
/// satisfied by \c otherSig.
378-
///
379-
/// \param otherSig Another generic signature whose generic parameters are
380-
/// equivalent to or a subset of the generic parameters in this signature.
381-
SmallVector<Requirement, 4> requirementsNotSatisfiedBy(
382-
GenericSignature otherSig) const;
383-
384-
/// Return the canonical version of the given type under this generic
385-
/// signature.
386-
CanType getCanonicalTypeInContext(Type type) const;
387-
388388
bool isCanonicalTypeInContext(Type type) const;
389389
bool isCanonicalTypeInContext(Type type,
390390
GenericSignatureBuilder &builder) const;
@@ -462,6 +462,18 @@ class alignas(1 << TypeAlignInBits) GenericSignatureImpl final
462462
/// (archetypes) that correspond to the interface types in this generic
463463
/// signature.
464464
GenericEnvironment *getGenericEnvironment() const;
465+
466+
/// Return the requirements of this generic signature that are not also
467+
/// satisfied by \c otherSig.
468+
///
469+
/// \param otherSig Another generic signature whose generic parameters are
470+
/// equivalent to or a subset of the generic parameters in this signature.
471+
SmallVector<Requirement, 4>
472+
requirementsNotSatisfiedBy(GenericSignature otherSig) const;
473+
474+
/// Return the canonical version of the given type under this generic
475+
/// signature.
476+
CanType getCanonicalTypeInContext(Type type) const;
465477
};
466478

467479
void simple_display(raw_ostream &out, GenericSignature sig);

include/swift/SIL/AbstractionPattern.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ class AbstractionPattern {
530530
OrigType = origType;
531531
GenericSig = CanGenericSignature();
532532
if (OrigType->hasTypeParameter()) {
533-
assert(OrigType == signature->getCanonicalTypeInContext(origType));
533+
assert(OrigType == signature.getCanonicalTypeInContext(origType));
534534
GenericSig = signature;
535535
}
536536
}

include/swift/SILOptimizer/Analysis/DifferentiableActivityAnalysis.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ class DifferentiableActivityInfo {
135135
bool hasTangentSpace(SILValue value) {
136136
auto type = value->getType().getASTType();
137137
// Remap archetypes in the derivative generic signature, if it exists.
138-
if (derivativeGenericSignature && type->hasArchetype()) {
139-
type = derivativeGenericSignature->getCanonicalTypeInContext(
138+
if (type->hasArchetype()) {
139+
type = derivativeGenericSignature.getCanonicalTypeInContext(
140140
type->mapTypeOutOfContext());
141141
}
142142
// Look up conformance in the current module.

lib/AST/ASTContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5159,9 +5159,9 @@ bool ASTContext::overrideGenericSignatureReqsSatisfied(
51595159

51605160
switch (direction) {
51615161
case OverrideGenericSignatureReqCheck::BaseReqSatisfiedByDerived:
5162-
return sig->requirementsNotSatisfiedBy(derivedSig).empty();
5162+
return sig.requirementsNotSatisfiedBy(derivedSig).empty();
51635163
case OverrideGenericSignatureReqCheck::DerivedReqSatisfiedByBase:
5164-
return derivedSig->requirementsNotSatisfiedBy(sig).empty();
5164+
return derivedSig.requirementsNotSatisfiedBy(sig).empty();
51655165
}
51665166
llvm_unreachable("Unhandled OverrideGenericSignatureReqCheck in switch");
51675167
}

lib/AST/ASTMangler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2645,7 +2645,7 @@ bool ASTMangler::appendGenericSignature(GenericSignature sig,
26452645
genericParams = canSig.getGenericParams();
26462646
requirements = canSig.getRequirements();
26472647
} else {
2648-
requirementsBuffer = canSig->requirementsNotSatisfiedBy(contextSig);
2648+
requirementsBuffer = canSig.requirementsNotSatisfiedBy(contextSig);
26492649
requirements = requirementsBuffer;
26502650
}
26512651
} else {

lib/AST/Attr.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -991,8 +991,7 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
991991
auto genericSig = FnDecl->getGenericSignature();
992992

993993
if (auto sig = attr->getSpecializedSignature()) {
994-
requirementsScratch = sig->requirementsNotSatisfiedBy(
995-
genericSig);
994+
requirementsScratch = sig.requirementsNotSatisfiedBy(genericSig);
996995
requirements = requirementsScratch;
997996
}
998997
}

lib/AST/GenericSignature.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,16 @@ bool GenericSignatureImpl::isRequirementSatisfied(
967967
return requirement.isSatisfied(conditionalRequirements, allowMissing);
968968
}
969969

970+
SmallVector<Requirement, 4>
971+
GenericSignature::requirementsNotSatisfiedBy(GenericSignature otherSig) const {
972+
// The null generic signature has no requirements, therefore all requirements
973+
// are satisfied by any signature.
974+
if (isNull()) {
975+
return {};
976+
}
977+
return getPointer()->requirementsNotSatisfiedBy(otherSig);
978+
}
979+
970980
SmallVector<Requirement, 4> GenericSignatureImpl::requirementsNotSatisfiedBy(
971981
GenericSignature otherSig) const {
972982
SmallVector<Requirement, 4> result;
@@ -1071,6 +1081,15 @@ bool GenericSignatureImpl::isCanonicalTypeInContext(
10711081
});
10721082
}
10731083

1084+
CanType GenericSignature::getCanonicalTypeInContext(Type type) const {
1085+
// The null generic signature has no requirements so cannot influence the
1086+
// structure of the can type computed here.
1087+
if (isNull()) {
1088+
return type->getCanonicalType();
1089+
}
1090+
return getPointer()->getCanonicalTypeInContext(type);
1091+
}
1092+
10741093
CanType GenericSignatureImpl::getCanonicalTypeInContext(Type type) const {
10751094
type = type->getCanonicalType();
10761095

lib/AST/ProtocolConformance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ ConditionalRequirementsRequest::evaluate(Evaluator &evaluator,
543543

544544
// Find the requirements in the extension that aren't proved by the original
545545
// type, these are the ones that make the conformance conditional.
546-
const auto unsatReqs = extensionSig->requirementsNotSatisfiedBy(typeSig);
546+
const auto unsatReqs = extensionSig.requirementsNotSatisfiedBy(typeSig);
547547
if (unsatReqs.empty())
548548
return {};
549549

lib/AST/SubstitutionMap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ Type SubstitutionMap::lookupSubstitution(CanSubstitutableType type) const {
295295

296296
// The generic parameter may not be canonical. Retrieve the canonical
297297
// type, which will be dependent.
298-
CanType canonicalType = genericSig->getCanonicalTypeInContext(genericParam);
298+
CanType canonicalType = genericSig.getCanonicalTypeInContext(genericParam);
299299

300300
// If nothing changed, we don't have a replacement.
301301
if (canonicalType == type) return Type();

lib/AST/Type.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,10 +1450,7 @@ CanType TypeBase::computeCanonicalType() {
14501450
}
14511451

14521452
CanType TypeBase::getCanonicalType(GenericSignature sig) {
1453-
if (!sig)
1454-
return getCanonicalType();
1455-
1456-
return sig->getCanonicalTypeInContext(this);
1453+
return sig.getCanonicalTypeInContext(this);
14571454
}
14581455

14591456
TypeBase *TypeBase::reconstituteSugar(bool Recursive) {
@@ -1904,7 +1901,7 @@ class IsBindableVisitor
19041901

19051902
// Collect requirements from the conformance not satisfied by the
19061903
// original declaration.
1907-
for (auto reqt : conformanceSig->requirementsNotSatisfiedBy(genericSig)) {
1904+
for (auto reqt : conformanceSig.requirementsNotSatisfiedBy(genericSig)) {
19081905
LLVM_DEBUG(llvm::dbgs() << "\n- adds requirement\n";
19091906
reqt.dump(llvm::dbgs()));
19101907

0 commit comments

Comments
 (0)