Skip to content

Fix some performance regressions [5.5] #37801

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
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
18 changes: 9 additions & 9 deletions include/swift/AST/TypeCheckRequests.h
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ class PropertyWrapperTypeInfoRequest

public:
// Caching
bool isCached() const;
bool isCached() const { return true; }
};

/// Request the nominal type declaration to which the given custom attribute
Expand All @@ -627,7 +627,7 @@ class AttachedPropertyWrappersRequest :

public:
// Caching
bool isCached() const;
bool isCached() const { return true; }
};

/// Request the raw (possibly unbound generic) type of the property wrapper
Expand All @@ -648,7 +648,7 @@ class AttachedPropertyWrapperTypeRequest :

public:
// Caching
bool isCached() const;
bool isCached() const { return true; }
};

/// Request the nominal type declaration to which the given custom attribute
Expand All @@ -669,7 +669,7 @@ class PropertyWrapperBackingPropertyTypeRequest :

public:
// Caching
bool isCached() const;
bool isCached() const { return true; }
};

/// Request information about the mutability of composed property wrappers.
Expand All @@ -689,7 +689,7 @@ class PropertyWrapperMutabilityRequest :

public:
// Caching
bool isCached() const;
bool isCached() const { return true; }
};

/// Request information about the l-valueness of composed property wrappers.
Expand All @@ -709,7 +709,7 @@ class PropertyWrapperLValuenessRequest :

public:
// Caching
bool isCached() const;
bool isCached() const { return true; }
};

/// Request the synthesized auxiliary declarations for a wrapped property.
Expand All @@ -729,7 +729,7 @@ class PropertyWrapperAuxiliaryVariablesRequest :

public:
// Caching
bool isCached() const;
bool isCached() const { return true; }
};

/// Request information about initialization of the backing property
Expand All @@ -750,7 +750,7 @@ class PropertyWrapperInitializerInfoRequest :

public:
// Caching
bool isCached() const;
bool isCached() const { return true; }
};

/// Retrieve the structural type of an alias type.
Expand Down Expand Up @@ -833,7 +833,7 @@ class AttachedResultBuilderRequest :

public:
// Caching
bool isCached() const;
bool isCached() const { return true; }
};

/// Request the result builder type attached to the given declaration,
Expand Down
28 changes: 22 additions & 6 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5937,17 +5937,33 @@ llvm::TinyPtrVector<CustomAttr *> VarDecl::getAttachedPropertyWrappers() const {

/// Whether this property has any attached property wrappers.
bool VarDecl::hasAttachedPropertyWrapper() const {
return !getAttachedPropertyWrappers().empty() || hasImplicitPropertyWrapper();
if (getAttrs().hasAttribute<CustomAttr>()) {
if (!getAttachedPropertyWrappers().empty())
return true;
}

if (hasImplicitPropertyWrapper())
return true;

return false;
}

bool VarDecl::hasImplicitPropertyWrapper() const {
if (!getAttachedPropertyWrappers().empty())
if (getAttrs().hasAttribute<CustomAttr>()) {
if (!getAttachedPropertyWrappers().empty())
return false;
}

if (isImplicit())
return false;

auto *dc = getDeclContext();
bool isClosureParam = isa<ParamDecl>(this) &&
dc->getContextKind() == DeclContextKind::AbstractClosureExpr;
return !isImplicit() && getName().hasDollarPrefix() && isClosureParam;
if (!isa<ParamDecl>(this))
return false;

if (!isa<AbstractClosureExpr>(getDeclContext()))
return false;

return getName().hasDollarPrefix();
}

bool VarDecl::hasExternalPropertyWrapper() const {
Expand Down
21 changes: 16 additions & 5 deletions lib/AST/DeclContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1038,11 +1038,22 @@ IterableDeclContext::castDeclToIterableDeclContext(const Decl *D) {
}

Optional<Fingerprint> IterableDeclContext::getBodyFingerprint() const {
auto mutableThis = const_cast<IterableDeclContext *>(this);
return evaluateOrDefault(getASTContext().evaluator,
ParseMembersRequest{mutableThis},
FingerprintAndMembers())
.fingerprint;
auto fileUnit = dyn_cast<FileUnit>(getAsGenericContext()->getModuleScopeContext());
if (!fileUnit)
return None;

if (isa<SourceFile>(fileUnit)) {
auto mutableThis = const_cast<IterableDeclContext *>(this);
return evaluateOrDefault(getASTContext().evaluator,
ParseMembersRequest{mutableThis},
FingerprintAndMembers())
.fingerprint;
}

if (getDecl()->isImplicit())
return None;

return fileUnit->loadFingerprint(this);
}

/// Return the DeclContext to compare when checking private access in
Expand Down
51 changes: 0 additions & 51 deletions lib/AST/TypeCheckRequests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,47 +468,6 @@ void DefaultTypeRequest::cacheResult(Type value) const {
cacheEntry = value;
}

bool PropertyWrapperTypeInfoRequest::isCached() const {
auto nominal = std::get<0>(getStorage());
return nominal->getAttrs().hasAttribute<PropertyWrapperAttr>();;
}

bool AttachedPropertyWrappersRequest::isCached() const {
auto var = std::get<0>(getStorage());
return !var->getAttrs().isEmpty();
}

bool AttachedPropertyWrapperTypeRequest::isCached() const {
auto var = std::get<0>(getStorage());
return !var->getAttrs().isEmpty();
}

bool PropertyWrapperBackingPropertyTypeRequest::isCached() const {
auto var = std::get<0>(getStorage());
return !var->getAttrs().isEmpty() &&
!(isa<ParamDecl>(var) && isa<ClosureExpr>(var->getDeclContext()));
}

bool PropertyWrapperAuxiliaryVariablesRequest::isCached() const {
auto var = std::get<0>(getStorage());
return !var->getAttrs().isEmpty() || var->hasImplicitPropertyWrapper();
}

bool PropertyWrapperInitializerInfoRequest::isCached() const {
auto var = std::get<0>(getStorage());
return !var->getAttrs().isEmpty() || var->hasImplicitPropertyWrapper();
}

bool PropertyWrapperMutabilityRequest::isCached() const {
auto var = std::get<0>(getStorage());
return !var->getAttrs().isEmpty() || var->hasImplicitPropertyWrapper();
}

bool PropertyWrapperLValuenessRequest::isCached() const {
auto var = std::get<0>(getStorage());
return !var->getAttrs().isEmpty() || var->hasImplicitPropertyWrapper();
}

void swift::simple_display(
llvm::raw_ostream &out, const PropertyWrapperTypeInfo &propertyWrapper) {
out << "{ ";
Expand Down Expand Up @@ -609,16 +568,6 @@ void swift::simple_display(llvm::raw_ostream &out,
<< (value.allowUsableFromInline ? "true" : "false");
}

//----------------------------------------------------------------------------//
// ResultBuilder-related requests.
//----------------------------------------------------------------------------//

bool AttachedResultBuilderRequest::isCached() const {
// Only needs to be cached if there are any custom attributes.
auto var = std::get<0>(getStorage());
return var->getAttrs().hasAttribute<CustomAttr>();
}

//----------------------------------------------------------------------------//
// SelfAccessKindRequest computation.
//----------------------------------------------------------------------------//
Expand Down