Skip to content

Commit f902a9c

Browse files
authored
Merge pull request swiftlang#77788 from slavapestov/fix-rdar136106973-6.1
[6.1] Sema: Cache Solution::getTotalMemory()
2 parents 1fb4291 + 4147eb9 commit f902a9c

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,6 +1482,9 @@ class Solution {
14821482
/// The fixed score for this solution.
14831483
Score FixedScore;
14841484

1485+
/// The total memory used by this solution.
1486+
std::optional<size_t> TotalMemory;
1487+
14851488
public:
14861489
/// Create a solution for the given constraint system.
14871490
Solution(ConstraintSystem &cs, const Score &score)

lib/Sema/ConstraintSystem.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1863,7 +1863,11 @@ static inline size_t size_in_bytes(const T &x) {
18631863
}
18641864

18651865
size_t Solution::getTotalMemory() const {
1866-
return sizeof(*this) + typeBindings.getMemorySize() +
1866+
if (TotalMemory)
1867+
return *TotalMemory;
1868+
1869+
const_cast<Solution *>(this)->TotalMemory
1870+
= sizeof(*this) + typeBindings.getMemorySize() +
18671871
overloadChoices.getMemorySize() +
18681872
ConstraintRestrictions.getMemorySize() +
18691873
(Fixes.size() * sizeof(void *)) + DisjunctionChoices.getMemorySize() +
@@ -1887,6 +1891,8 @@ size_t Solution::getTotalMemory() const {
18871891
size_in_bytes(argumentLists) +
18881892
size_in_bytes(ImplicitCallAsFunctionRoots) +
18891893
size_in_bytes(SynthesizedConformances);
1894+
1895+
return *TotalMemory;
18901896
}
18911897

18921898
DeclContext *Solution::getDC() const { return constraintSystem->DC; }

0 commit comments

Comments
 (0)