Skip to content

Commit c5741e3

Browse files
committed
Sema: Stash the existential archetype in PreparedOverload
1 parent 426c7a3 commit c5741e3

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3413,7 +3413,8 @@ class ConstraintSystem {
34133413

34143414
/// Update OpenedExistentials and record a change in the trail.
34153415
void recordOpenedExistentialType(ConstraintLocator *locator,
3416-
ExistentialArchetypeType *opened);
3416+
ExistentialArchetypeType *opened,
3417+
PreparedOverload *preparedOverload = nullptr);
34173418

34183419
/// Retrieve the generic environment for the opened element of a given pack
34193420
/// expansion, or \c nullptr if no environment was recorded yet.

include/swift/Sema/PreparedOverload.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
namespace swift {
1919

20+
class ExistentialArchetypeType;
2021
class GenericTypeParamType;
2122
class TypeVariableType;
2223

@@ -33,6 +34,7 @@ struct PreparedOverload {
3334
SmallVector<TypeVariableType *, 2> TypeVariables;
3435
SmallVector<Constraint *, 2> Constraints;
3536
SmallVector<OpenedType, 2> Replacements;
37+
ExistentialArchetypeType *OpenedExistential = nullptr;
3638

3739
void discharge(ConstraintSystem &cs, ConstraintLocatorBuilder locator) const;
3840
};

lib/Sema/ConstraintSystem.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "swift/Sema/CSFix.h"
3939
#include "swift/Sema/ConstraintGraph.h"
4040
#include "swift/Sema/IDETypeChecking.h"
41+
#include "swift/Sema/PreparedOverload.h"
4142
#include "swift/Sema/SolutionResult.h"
4243
#include "llvm/ADT/SetVector.h"
4344
#include "llvm/ADT/SmallSet.h"
@@ -899,7 +900,15 @@ ConstraintSystem::openAnyExistentialType(Type type,
899900
}
900901

901902
void ConstraintSystem::recordOpenedExistentialType(
902-
ConstraintLocator *locator, ExistentialArchetypeType *opened) {
903+
ConstraintLocator *locator,
904+
ExistentialArchetypeType *opened,
905+
PreparedOverload *preparedOverload) {
906+
if (preparedOverload) {
907+
ASSERT(!preparedOverload->OpenedExistential);
908+
preparedOverload->OpenedExistential = opened;
909+
return;
910+
}
911+
903912
bool inserted = OpenedExistentialTypes.insert({locator, opened}).second;
904913
ASSERT(inserted);
905914

lib/Sema/TypeOfReference.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1753,7 +1753,8 @@ DeclReferenceType ConstraintSystem::getTypeOfMemberReference(
17531753
} else if (baseObjTy->isExistentialType()) {
17541754
auto openedArchetype =
17551755
ExistentialArchetypeType::get(baseObjTy->getCanonicalType());
1756-
recordOpenedExistentialType(getConstraintLocator(locator), openedArchetype);
1756+
recordOpenedExistentialType(getConstraintLocator(locator), openedArchetype,
1757+
preparedOverload);
17571758
baseOpenedTy = openedArchetype;
17581759
}
17591760

@@ -2471,6 +2472,10 @@ void PreparedOverload::discharge(ConstraintSystem &cs,
24712472
cs.activateConstraint(c);
24722473
}
24732474
cs.recordOpenedTypes(locator, Replacements);
2475+
if (OpenedExistential) {
2476+
cs.recordOpenedExistentialType(cs.getConstraintLocator(locator),
2477+
OpenedExistential);
2478+
}
24742479
}
24752480

24762481
void ConstraintSystem::resolveOverload(ConstraintLocator *locator,

0 commit comments

Comments
 (0)