Skip to content

[NFC][ConstraintSystem] Move some inlined header methods to implementation file #32107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions lib/Sema/ConstraintSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,72 @@ TypeVariableType *ConstraintSystem::isRepresentativeFor(
return *member;
}

static Optional<std::pair<VarDecl *, Type>>
getPropertyWrapperInformationFromOverload(
SelectedOverload resolvedOverload, DeclContext *DC,
llvm::function_ref<Optional<std::pair<VarDecl *, Type>>(VarDecl *)>
getInformation) {
if (auto *decl =
dyn_cast_or_null<VarDecl>(resolvedOverload.choice.getDeclOrNull())) {
if (auto declInformation = getInformation(decl)) {
Type type;
VarDecl *memberDecl;
std::tie(memberDecl, type) = *declInformation;
if (Type baseType = resolvedOverload.choice.getBaseType()) {
type =
baseType->getTypeOfMember(DC->getParentModule(), memberDecl, type);
}
return std::make_pair(decl, type);
}
}
return None;
}

Optional<std::pair<VarDecl *, Type>>
ConstraintSystem::getStorageWrapperInformation(
SelectedOverload resolvedOverload) {
return getPropertyWrapperInformationFromOverload(
resolvedOverload, DC,
[](VarDecl *decl) -> Optional<std::pair<VarDecl *, Type>> {
if (!decl->hasAttachedPropertyWrapper())
return None;

auto storageWrapper = decl->getPropertyWrapperStorageWrapper();
if (!storageWrapper)
return None;

return std::make_pair(storageWrapper,
storageWrapper->getInterfaceType());
});
}

Optional<std::pair<VarDecl *, Type>>
ConstraintSystem::getPropertyWrapperInformation(
SelectedOverload resolvedOverload) {
return getPropertyWrapperInformationFromOverload(
resolvedOverload, DC,
[](VarDecl *decl) -> Optional<std::pair<VarDecl *, Type>> {
if (!decl->hasAttachedPropertyWrapper())
return None;

return std::make_pair(decl,
decl->getPropertyWrapperBackingPropertyType());
});
}

Optional<std::pair<VarDecl *, Type>>
ConstraintSystem::getWrappedPropertyInformation(
SelectedOverload resolvedOverload) {
return getPropertyWrapperInformationFromOverload(
resolvedOverload, DC,
[](VarDecl *decl) -> Optional<std::pair<VarDecl *, Type>> {
if (auto wrapped = decl->getOriginalWrappedProperty())
return std::make_pair(decl, wrapped->getInterfaceType());

return None;
});
}

/// Does a var or subscript produce an l-value?
///
/// \param baseType - the type of the base on which this object
Expand Down
50 changes: 3 additions & 47 deletions lib/Sema/ConstraintSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -3080,62 +3080,18 @@ class ConstraintSystem {
/// Gets the VarDecl associateed with resolvedOverload, and the type of the
/// storage wrapper if the decl has an associated storage wrapper.
Optional<std::pair<VarDecl *, Type>>
getStorageWrapperInformation(SelectedOverload resolvedOverload) {
if (resolvedOverload.choice.isDecl()) {
if (auto *decl = dyn_cast<VarDecl>(resolvedOverload.choice.getDecl())) {
if (decl->hasAttachedPropertyWrapper()) {
if (auto storageWrapper = decl->getPropertyWrapperStorageWrapper()) {
Type type = storageWrapper->getInterfaceType();
if (Type baseType = resolvedOverload.choice.getBaseType()) {
type = baseType->getTypeOfMember(DC->getParentModule(),
storageWrapper, type);
}
return std::make_pair(decl, type);
}
}
}
}
return None;
}
getStorageWrapperInformation(SelectedOverload resolvedOverload);

/// Gets the VarDecl associateed with resolvedOverload, and the type of the
/// backing storage if the decl has an associated property wrapper.
Optional<std::pair<VarDecl *, Type>>
getPropertyWrapperInformation(SelectedOverload resolvedOverload) {
if (resolvedOverload.choice.isDecl()) {
if (auto *decl = dyn_cast<VarDecl>(resolvedOverload.choice.getDecl())) {
if (decl->hasAttachedPropertyWrapper()) {
auto wrapperTy = decl->getPropertyWrapperBackingPropertyType();
if (Type baseType = resolvedOverload.choice.getBaseType()) {
wrapperTy = baseType->getTypeOfMember(DC->getParentModule(),
decl, wrapperTy);
}
return std::make_pair(decl, wrapperTy);
}
}
}
return None;
}
getPropertyWrapperInformation(SelectedOverload resolvedOverload);

/// Gets the VarDecl, and the type of the type property that it wraps if
/// resolved overload has a decl which is the backing storage for a
/// property wrapper.
Optional<std::pair<VarDecl *, Type>>
getWrappedPropertyInformation(SelectedOverload resolvedOverload) {
if (resolvedOverload.choice.isDecl()) {
if (auto *decl = dyn_cast<VarDecl>(resolvedOverload.choice.getDecl())) {
if (auto wrapped = decl->getOriginalWrappedProperty()) {
Type type = wrapped->getInterfaceType();
if (Type baseType = resolvedOverload.choice.getBaseType()) {
type = baseType->getTypeOfMember(DC->getParentModule(),
wrapped, type);
}
return std::make_pair(decl, type);
}
}
}
return None;
}
getWrappedPropertyInformation(SelectedOverload resolvedOverload);

/// Merge the equivalence sets of the two type variables.
///
Expand Down