Skip to content

Commit df554fd

Browse files
authored
Merge pull request #37801 from slavapestov/fix-perf-regressions-5.5
Fix some performance regressions [5.5]
2 parents 0a60a82 + 02aed9a commit df554fd

File tree

4 files changed

+47
-71
lines changed

4 files changed

+47
-71
lines changed

include/swift/AST/TypeCheckRequests.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ class PropertyWrapperTypeInfoRequest
606606

607607
public:
608608
// Caching
609-
bool isCached() const;
609+
bool isCached() const { return true; }
610610
};
611611

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

628628
public:
629629
// Caching
630-
bool isCached() const;
630+
bool isCached() const { return true; }
631631
};
632632

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

649649
public:
650650
// Caching
651-
bool isCached() const;
651+
bool isCached() const { return true; }
652652
};
653653

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

670670
public:
671671
// Caching
672-
bool isCached() const;
672+
bool isCached() const { return true; }
673673
};
674674

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

690690
public:
691691
// Caching
692-
bool isCached() const;
692+
bool isCached() const { return true; }
693693
};
694694

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

710710
public:
711711
// Caching
712-
bool isCached() const;
712+
bool isCached() const { return true; }
713713
};
714714

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

730730
public:
731731
// Caching
732-
bool isCached() const;
732+
bool isCached() const { return true; }
733733
};
734734

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

751751
public:
752752
// Caching
753-
bool isCached() const;
753+
bool isCached() const { return true; }
754754
};
755755

756756
/// Retrieve the structural type of an alias type.
@@ -833,7 +833,7 @@ class AttachedResultBuilderRequest :
833833

834834
public:
835835
// Caching
836-
bool isCached() const;
836+
bool isCached() const { return true; }
837837
};
838838

839839
/// Request the result builder type attached to the given declaration,

lib/AST/Decl.cpp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5937,17 +5937,33 @@ llvm::TinyPtrVector<CustomAttr *> VarDecl::getAttachedPropertyWrappers() const {
59375937

59385938
/// Whether this property has any attached property wrappers.
59395939
bool VarDecl::hasAttachedPropertyWrapper() const {
5940-
return !getAttachedPropertyWrappers().empty() || hasImplicitPropertyWrapper();
5940+
if (getAttrs().hasAttribute<CustomAttr>()) {
5941+
if (!getAttachedPropertyWrappers().empty())
5942+
return true;
5943+
}
5944+
5945+
if (hasImplicitPropertyWrapper())
5946+
return true;
5947+
5948+
return false;
59415949
}
59425950

59435951
bool VarDecl::hasImplicitPropertyWrapper() const {
5944-
if (!getAttachedPropertyWrappers().empty())
5952+
if (getAttrs().hasAttribute<CustomAttr>()) {
5953+
if (!getAttachedPropertyWrappers().empty())
5954+
return false;
5955+
}
5956+
5957+
if (isImplicit())
59455958
return false;
59465959

5947-
auto *dc = getDeclContext();
5948-
bool isClosureParam = isa<ParamDecl>(this) &&
5949-
dc->getContextKind() == DeclContextKind::AbstractClosureExpr;
5950-
return !isImplicit() && getName().hasDollarPrefix() && isClosureParam;
5960+
if (!isa<ParamDecl>(this))
5961+
return false;
5962+
5963+
if (!isa<AbstractClosureExpr>(getDeclContext()))
5964+
return false;
5965+
5966+
return getName().hasDollarPrefix();
59515967
}
59525968

59535969
bool VarDecl::hasExternalPropertyWrapper() const {

lib/AST/DeclContext.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,11 +1038,22 @@ IterableDeclContext::castDeclToIterableDeclContext(const Decl *D) {
10381038
}
10391039

10401040
Optional<Fingerprint> IterableDeclContext::getBodyFingerprint() const {
1041-
auto mutableThis = const_cast<IterableDeclContext *>(this);
1042-
return evaluateOrDefault(getASTContext().evaluator,
1043-
ParseMembersRequest{mutableThis},
1044-
FingerprintAndMembers())
1045-
.fingerprint;
1041+
auto fileUnit = dyn_cast<FileUnit>(getAsGenericContext()->getModuleScopeContext());
1042+
if (!fileUnit)
1043+
return None;
1044+
1045+
if (isa<SourceFile>(fileUnit)) {
1046+
auto mutableThis = const_cast<IterableDeclContext *>(this);
1047+
return evaluateOrDefault(getASTContext().evaluator,
1048+
ParseMembersRequest{mutableThis},
1049+
FingerprintAndMembers())
1050+
.fingerprint;
1051+
}
1052+
1053+
if (getDecl()->isImplicit())
1054+
return None;
1055+
1056+
return fileUnit->loadFingerprint(this);
10461057
}
10471058

10481059
/// Return the DeclContext to compare when checking private access in

lib/AST/TypeCheckRequests.cpp

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -468,47 +468,6 @@ void DefaultTypeRequest::cacheResult(Type value) const {
468468
cacheEntry = value;
469469
}
470470

471-
bool PropertyWrapperTypeInfoRequest::isCached() const {
472-
auto nominal = std::get<0>(getStorage());
473-
return nominal->getAttrs().hasAttribute<PropertyWrapperAttr>();;
474-
}
475-
476-
bool AttachedPropertyWrappersRequest::isCached() const {
477-
auto var = std::get<0>(getStorage());
478-
return !var->getAttrs().isEmpty();
479-
}
480-
481-
bool AttachedPropertyWrapperTypeRequest::isCached() const {
482-
auto var = std::get<0>(getStorage());
483-
return !var->getAttrs().isEmpty();
484-
}
485-
486-
bool PropertyWrapperBackingPropertyTypeRequest::isCached() const {
487-
auto var = std::get<0>(getStorage());
488-
return !var->getAttrs().isEmpty() &&
489-
!(isa<ParamDecl>(var) && isa<ClosureExpr>(var->getDeclContext()));
490-
}
491-
492-
bool PropertyWrapperAuxiliaryVariablesRequest::isCached() const {
493-
auto var = std::get<0>(getStorage());
494-
return !var->getAttrs().isEmpty() || var->hasImplicitPropertyWrapper();
495-
}
496-
497-
bool PropertyWrapperInitializerInfoRequest::isCached() const {
498-
auto var = std::get<0>(getStorage());
499-
return !var->getAttrs().isEmpty() || var->hasImplicitPropertyWrapper();
500-
}
501-
502-
bool PropertyWrapperMutabilityRequest::isCached() const {
503-
auto var = std::get<0>(getStorage());
504-
return !var->getAttrs().isEmpty() || var->hasImplicitPropertyWrapper();
505-
}
506-
507-
bool PropertyWrapperLValuenessRequest::isCached() const {
508-
auto var = std::get<0>(getStorage());
509-
return !var->getAttrs().isEmpty() || var->hasImplicitPropertyWrapper();
510-
}
511-
512471
void swift::simple_display(
513472
llvm::raw_ostream &out, const PropertyWrapperTypeInfo &propertyWrapper) {
514473
out << "{ ";
@@ -609,16 +568,6 @@ void swift::simple_display(llvm::raw_ostream &out,
609568
<< (value.allowUsableFromInline ? "true" : "false");
610569
}
611570

612-
//----------------------------------------------------------------------------//
613-
// ResultBuilder-related requests.
614-
//----------------------------------------------------------------------------//
615-
616-
bool AttachedResultBuilderRequest::isCached() const {
617-
// Only needs to be cached if there are any custom attributes.
618-
auto var = std::get<0>(getStorage());
619-
return var->getAttrs().hasAttribute<CustomAttr>();
620-
}
621-
622571
//----------------------------------------------------------------------------//
623572
// SelfAccessKindRequest computation.
624573
//----------------------------------------------------------------------------//

0 commit comments

Comments
 (0)