Skip to content

Commit 3e280b8

Browse files
Merge pull request #32107 from LucianoPAlmeida/nfc-move-to-cpp
[NFC][ConstraintSystem] Move some inlined header methods to implementation file
2 parents 62b2570 + c91211c commit 3e280b8

File tree

2 files changed

+69
-47
lines changed

2 files changed

+69
-47
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,72 @@ TypeVariableType *ConstraintSystem::isRepresentativeFor(
955955
return *member;
956956
}
957957

958+
static Optional<std::pair<VarDecl *, Type>>
959+
getPropertyWrapperInformationFromOverload(
960+
SelectedOverload resolvedOverload, DeclContext *DC,
961+
llvm::function_ref<Optional<std::pair<VarDecl *, Type>>(VarDecl *)>
962+
getInformation) {
963+
if (auto *decl =
964+
dyn_cast_or_null<VarDecl>(resolvedOverload.choice.getDeclOrNull())) {
965+
if (auto declInformation = getInformation(decl)) {
966+
Type type;
967+
VarDecl *memberDecl;
968+
std::tie(memberDecl, type) = *declInformation;
969+
if (Type baseType = resolvedOverload.choice.getBaseType()) {
970+
type =
971+
baseType->getTypeOfMember(DC->getParentModule(), memberDecl, type);
972+
}
973+
return std::make_pair(decl, type);
974+
}
975+
}
976+
return None;
977+
}
978+
979+
Optional<std::pair<VarDecl *, Type>>
980+
ConstraintSystem::getStorageWrapperInformation(
981+
SelectedOverload resolvedOverload) {
982+
return getPropertyWrapperInformationFromOverload(
983+
resolvedOverload, DC,
984+
[](VarDecl *decl) -> Optional<std::pair<VarDecl *, Type>> {
985+
if (!decl->hasAttachedPropertyWrapper())
986+
return None;
987+
988+
auto storageWrapper = decl->getPropertyWrapperStorageWrapper();
989+
if (!storageWrapper)
990+
return None;
991+
992+
return std::make_pair(storageWrapper,
993+
storageWrapper->getInterfaceType());
994+
});
995+
}
996+
997+
Optional<std::pair<VarDecl *, Type>>
998+
ConstraintSystem::getPropertyWrapperInformation(
999+
SelectedOverload resolvedOverload) {
1000+
return getPropertyWrapperInformationFromOverload(
1001+
resolvedOverload, DC,
1002+
[](VarDecl *decl) -> Optional<std::pair<VarDecl *, Type>> {
1003+
if (!decl->hasAttachedPropertyWrapper())
1004+
return None;
1005+
1006+
return std::make_pair(decl,
1007+
decl->getPropertyWrapperBackingPropertyType());
1008+
});
1009+
}
1010+
1011+
Optional<std::pair<VarDecl *, Type>>
1012+
ConstraintSystem::getWrappedPropertyInformation(
1013+
SelectedOverload resolvedOverload) {
1014+
return getPropertyWrapperInformationFromOverload(
1015+
resolvedOverload, DC,
1016+
[](VarDecl *decl) -> Optional<std::pair<VarDecl *, Type>> {
1017+
if (auto wrapped = decl->getOriginalWrappedProperty())
1018+
return std::make_pair(decl, wrapped->getInterfaceType());
1019+
1020+
return None;
1021+
});
1022+
}
1023+
9581024
/// Does a var or subscript produce an l-value?
9591025
///
9601026
/// \param baseType - the type of the base on which this object

lib/Sema/ConstraintSystem.h

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3237,62 +3237,18 @@ class ConstraintSystem {
32373237
/// Gets the VarDecl associateed with resolvedOverload, and the type of the
32383238
/// storage wrapper if the decl has an associated storage wrapper.
32393239
Optional<std::pair<VarDecl *, Type>>
3240-
getStorageWrapperInformation(SelectedOverload resolvedOverload) {
3241-
if (resolvedOverload.choice.isDecl()) {
3242-
if (auto *decl = dyn_cast<VarDecl>(resolvedOverload.choice.getDecl())) {
3243-
if (decl->hasAttachedPropertyWrapper()) {
3244-
if (auto storageWrapper = decl->getPropertyWrapperStorageWrapper()) {
3245-
Type type = storageWrapper->getInterfaceType();
3246-
if (Type baseType = resolvedOverload.choice.getBaseType()) {
3247-
type = baseType->getTypeOfMember(DC->getParentModule(),
3248-
storageWrapper, type);
3249-
}
3250-
return std::make_pair(decl, type);
3251-
}
3252-
}
3253-
}
3254-
}
3255-
return None;
3256-
}
3240+
getStorageWrapperInformation(SelectedOverload resolvedOverload);
32573241

32583242
/// Gets the VarDecl associateed with resolvedOverload, and the type of the
32593243
/// backing storage if the decl has an associated property wrapper.
32603244
Optional<std::pair<VarDecl *, Type>>
3261-
getPropertyWrapperInformation(SelectedOverload resolvedOverload) {
3262-
if (resolvedOverload.choice.isDecl()) {
3263-
if (auto *decl = dyn_cast<VarDecl>(resolvedOverload.choice.getDecl())) {
3264-
if (decl->hasAttachedPropertyWrapper()) {
3265-
auto wrapperTy = decl->getPropertyWrapperBackingPropertyType();
3266-
if (Type baseType = resolvedOverload.choice.getBaseType()) {
3267-
wrapperTy = baseType->getTypeOfMember(DC->getParentModule(),
3268-
decl, wrapperTy);
3269-
}
3270-
return std::make_pair(decl, wrapperTy);
3271-
}
3272-
}
3273-
}
3274-
return None;
3275-
}
3245+
getPropertyWrapperInformation(SelectedOverload resolvedOverload);
32763246

32773247
/// Gets the VarDecl, and the type of the type property that it wraps if
32783248
/// resolved overload has a decl which is the backing storage for a
32793249
/// property wrapper.
32803250
Optional<std::pair<VarDecl *, Type>>
3281-
getWrappedPropertyInformation(SelectedOverload resolvedOverload) {
3282-
if (resolvedOverload.choice.isDecl()) {
3283-
if (auto *decl = dyn_cast<VarDecl>(resolvedOverload.choice.getDecl())) {
3284-
if (auto wrapped = decl->getOriginalWrappedProperty()) {
3285-
Type type = wrapped->getInterfaceType();
3286-
if (Type baseType = resolvedOverload.choice.getBaseType()) {
3287-
type = baseType->getTypeOfMember(DC->getParentModule(),
3288-
wrapped, type);
3289-
}
3290-
return std::make_pair(decl, type);
3291-
}
3292-
}
3293-
}
3294-
return None;
3295-
}
3251+
getWrappedPropertyInformation(SelectedOverload resolvedOverload);
32963252

32973253
/// Merge the equivalence sets of the two type variables.
32983254
///

0 commit comments

Comments
 (0)