Skip to content

Commit 8f84429

Browse files
committed
Add a scale-test for VarDecl::getStoredProperties.
Adds a NumStoredPropertiesQueries stat. Adds a test case for an increasing number of lazy stored class properties. Each property requires a formal access within the initializer. This would manifest as cubic behavior in AccessEnforcementOpts, which scales as O(1.5) in the above stat.
1 parent c7b4e7c commit 8f84429

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

include/swift/Basic/Statistics.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ FRONTEND_STATISTIC(AST, NumPrefixOperators)
141141
/// Number of precedence groups in the AST context.
142142
FRONTEND_STATISTIC(AST, NumPrecedenceGroups)
143143

144+
/// Number of precedence groups in the AST context.
145+
FRONTEND_STATISTIC(AST, NumStoredPropertiesQueries)
146+
144147
/// Number of full function bodies parsed.
145148
FRONTEND_STATISTIC(Parse, NumFunctionsParsed)
146149

lib/AST/Decl.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3370,6 +3370,14 @@ void NominalTypeDecl::addExtension(ExtensionDecl *extension) {
33703370

33713371
auto NominalTypeDecl::getStoredProperties(bool skipInaccessible) const
33723372
-> StoredPropertyRange {
3373+
// This should be called at most once per SIL instruction that accesses a
3374+
// VarDecl.
3375+
//
3376+
// FIXME: Once VarDecl itself caches its field index, it should be called at
3377+
// most once per finalized VarDecl.
3378+
if (getASTContext().Stats)
3379+
getASTContext().Stats->getFrontendCounters().NumStoredPropertiesQueries++;
3380+
33733381
// Clang-imported classes never have stored properties.
33743382
if (hasClangNode() && isa<ClassDecl>(this))
33753383
return StoredPropertyRange(DeclRange(nullptr, nullptr),
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %scale-test -O --begin 5 --end 21 --step 5 --select NumStoredPropertiesQueries %s
2+
// REQUIRES: OS=macosx
3+
// REQUIRES: asserts
4+
//
5+
// Single file with many stored properties.
6+
//
7+
// Check that SIL passes don't exhibit cubic behavior by repeatedly
8+
// asking for all the stored properties (if the
9+
// NumStoredPropertiesQueries stat scales quadratically, then the
10+
// behavior is cubic).
11+
12+
public class LazyProperties {
13+
%for i in range(N):
14+
public lazy var prop${i}: String = { return "${i}" }()
15+
%end
16+
}

0 commit comments

Comments
 (0)