Skip to content

Commit 0144fb6

Browse files
authored
Merge pull request #62830 from eeckstein/fix-compiletime-bugs
Fix two compile-time bugs
2 parents 497a8dc + 3ab94f1 commit 0144fb6

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

lib/SIL/IR/TypeLowering.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3047,9 +3047,12 @@ const TypeLowering &TypeConverter::getTypeLoweringForLoweredType(
30473047
AbstractionPattern origType, CanType loweredType,
30483048
TypeExpansionContext forExpansion,
30493049
IsTypeExpansionSensitive_t isTypeExpansionSensitive) {
3050-
assert(loweredType->isLegalSILType() && "type is not lowered!");
3051-
(void)loweredType;
3052-
3050+
3051+
// For very large types (e.g. tuples with many elements), this assertion is
3052+
// very expensive to execute, because the `isLegalSILType` status is not cached.
3053+
// Therefore the assert is commented out and only here for documentation purposes.
3054+
// assert(loweredType->isLegalSILType() && "type is not lowered!");
3055+
30533056
// Cache the lowered type record for a contextualized type independent of the
30543057
// abstraction pattern. Lowered type parameters can't be cached or looked up
30553058
// without context. (TODO: We could if they match the out-of-context

lib/SILOptimizer/LoopTransforms/LICM.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -937,14 +937,20 @@ void LoopTreeOptimization::analyzeCurrentLoop(
937937
}
938938
}
939939

940-
for (auto *AI : ReadOnlyApplies) {
941-
if (!mayWriteTo(AA, BCA, sideEffects, AI)) {
942-
HoistUp.insert(AI);
940+
// Avoid quadratic complexity in corner cases. Usually, this limit will not be exceeded.
941+
if (ReadOnlyApplies.size() * sideEffects.size() < 8000) {
942+
for (auto *AI : ReadOnlyApplies) {
943+
if (!mayWriteTo(AA, BCA, sideEffects, AI)) {
944+
HoistUp.insert(AI);
945+
}
943946
}
944947
}
945-
for (auto *LI : Loads) {
946-
if (!mayWriteTo(AA, sideEffects, LI)) {
947-
HoistUp.insert(LI);
948+
// Avoid quadratic complexity in corner cases. Usually, this limit will not be exceeded.
949+
if (Loads.size() * sideEffects.size() < 8000) {
950+
for (auto *LI : Loads) {
951+
if (!mayWriteTo(AA, sideEffects, LI)) {
952+
HoistUp.insert(LI);
953+
}
948954
}
949955
}
950956

0 commit comments

Comments
 (0)