Skip to content

Commit 74f54da

Browse files
authored
Merge pull request swiftlang#76263 from slavapestov/existential-signature-rework-part-4
Sema: Consolidate logic for opening existentials in OpenedExistentials.cpp
2 parents 60ba53c + b1e0e77 commit 74f54da

19 files changed

+1120
-1023
lines changed

include/swift/AST/Decl.h

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2753,54 +2753,6 @@ class PoundDiagnosticDecl : public Decl {
27532753

27542754
class OpaqueTypeDecl;
27552755

2756-
/// Describes the least favorable positions at which a requirement refers
2757-
/// to a given generic parameter in terms of variance, for use in the
2758-
/// is-inheritable and is-available-existential checks.
2759-
class GenericParameterReferenceInfo final {
2760-
using OptionalTypePosition = OptionalEnum<decltype(TypePosition::Covariant)>;
2761-
2762-
public:
2763-
/// Whether the uncurried interface type of the declaration, stripped of any
2764-
/// optionality, is a direct reference to the generic parameter at hand. For
2765-
/// example, "func foo(x: Int) -> () -> Self?" has a covariant 'Self' result.
2766-
bool hasCovariantSelfResult;
2767-
2768-
OptionalTypePosition selfRef;
2769-
OptionalTypePosition assocTypeRef;
2770-
2771-
/// A reference to 'Self'.
2772-
static GenericParameterReferenceInfo forSelfRef(TypePosition position) {
2773-
return GenericParameterReferenceInfo(false, position, std::nullopt);
2774-
}
2775-
2776-
/// A reference to the generic parameter in covariant result position.
2777-
static GenericParameterReferenceInfo forCovariantResult() {
2778-
return GenericParameterReferenceInfo(true, TypePosition::Covariant,
2779-
std::nullopt);
2780-
}
2781-
2782-
/// A reference to 'Self' through an associated type.
2783-
static GenericParameterReferenceInfo forAssocTypeRef(TypePosition position) {
2784-
return GenericParameterReferenceInfo(false, std::nullopt, position);
2785-
}
2786-
2787-
GenericParameterReferenceInfo &operator|=(const GenericParameterReferenceInfo &other);
2788-
2789-
explicit operator bool() const {
2790-
return hasCovariantSelfResult || selfRef || assocTypeRef;
2791-
}
2792-
2793-
GenericParameterReferenceInfo()
2794-
: hasCovariantSelfResult(false), selfRef(std::nullopt),
2795-
assocTypeRef(std::nullopt) {}
2796-
2797-
private:
2798-
GenericParameterReferenceInfo(bool hasCovariantSelfResult, OptionalTypePosition selfRef,
2799-
OptionalTypePosition assocTypeRef)
2800-
: hasCovariantSelfResult(hasCovariantSelfResult), selfRef(selfRef),
2801-
assocTypeRef(assocTypeRef) {}
2802-
};
2803-
28042756
/// ValueDecl - All named decls that are values in the language. These can
28052757
/// have a type, etc.
28062758
class ValueDecl : public Decl {
@@ -3334,9 +3286,6 @@ class ValueDecl : public Decl {
33343286
/// @_dynamicReplacement(for: ...), compute the original declaration
33353287
/// that this declaration dynamically replaces.
33363288
ValueDecl *getDynamicallyReplacedDecl() const;
3337-
3338-
/// Find references to 'Self' in the type signature of this declaration.
3339-
GenericParameterReferenceInfo findExistentialSelfReferences() const;
33403289
};
33413290

33423291
/// This is a common base class for declarations which declare a type.
@@ -9517,17 +9466,6 @@ class MacroExpansionDecl : public Decl, public FreestandingMacroExpansion {
95179466
}
95189467
};
95199468

9520-
/// Find references to the given generic parameter in the type signature of the
9521-
/// given declaration using the given generic signature.
9522-
///
9523-
/// \param skipParamIndex If the value is a function or subscript declaration,
9524-
/// specifies the index of the parameter that shall be skipped.
9525-
GenericParameterReferenceInfo
9526-
findGenericParameterReferences(const ValueDecl *value, CanGenericSignature sig,
9527-
GenericTypeParamType *origParam,
9528-
GenericTypeParamType *openedParam,
9529-
std::optional<unsigned> skipParamIndex);
9530-
95319469
inline void
95329470
AbstractStorageDecl::overwriteSetterAccess(AccessLevel accessLevel) {
95339471
Accessors.setInt(accessLevel);

include/swift/AST/SubstitutionMap.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ class SubstitutionMap {
104104
ArrayRef<Type> replacementTypes,
105105
LookupConformanceFn lookupConformance);
106106

107+
/// Build a substitution map from the substitutions represented by
108+
/// the given in-flight substitution.
109+
///
110+
/// This function should generally only be used by the substitution
111+
/// subsystem.
112+
static SubstitutionMap get(GenericSignature genericSig,
113+
ArrayRef<Type> replacementTypes,
114+
InFlightSubstitution &IFS);
115+
107116
/// Build a substitution map from the substitutions represented by
108117
/// the given in-flight substitution.
109118
///

include/swift/AST/TypeTransform.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -998,9 +998,7 @@ case TypeKind::Id:
998998
return subs;
999999

10001000
auto sig = subs.getGenericSignature();
1001-
return SubstitutionMap::get(sig,
1002-
QueryReplacementTypeArray{sig, newSubs},
1003-
LookUpConformanceInModule());
1001+
return SubstitutionMap::get(sig, newSubs, LookUpConformanceInModule());
10041002
}
10051003

10061004
CanType transformSILField(CanType fieldTy, TypePosition pos) {

include/swift/SIL/SILCloner.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ struct SubstitutionMapWithLocalArchetypes {
8585
ProtocolDecl *proto) {
8686
if (isa<LocalArchetypeType>(origType))
8787
return swift::lookupConformance(substType, proto);
88+
89+
if (isa<PrimaryArchetypeType>(origType) ||
90+
isa<PackArchetypeType>(origType))
91+
origType = origType->mapTypeOutOfContext()->getCanonicalType();
92+
8893
if (SubsMap)
8994
return SubsMap->lookupConformance(origType, proto);
9095

include/swift/Sema/ConstraintSystem.h

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5697,13 +5697,6 @@ class ConstraintSystem {
56975697
/// part of the constraint system.
56985698
void forEachExpr(Expr *expr, llvm::function_ref<Expr *(Expr *)> callback);
56995699

5700-
/// Determine whether referencing the given member on the
5701-
/// given existential base type is supported. This is the case only if the
5702-
/// type of the member, spelled in the context of \p baseTy, does not contain
5703-
/// 'Self' or 'Self'-rooted dependent member types in non-covariant position.
5704-
bool isMemberAvailableOnExistential(Type baseTy,
5705-
const ValueDecl *member) const;
5706-
57075700
/// Attempts to infer a capability of a key path (i.e. whether it
57085701
/// is read-only, writable, etc.) based on the referenced members.
57095702
///
@@ -5961,20 +5954,6 @@ std::optional<MatchCallArgumentResult> matchCallArguments(
59615954
/// subscript, etc.), find the underlying target expression.
59625955
Expr *getArgumentLabelTargetExpr(Expr *fn);
59635956

5964-
/// Given a type that includes an existential type that has been opened to
5965-
/// the given type variable, replace the opened type variable and its member
5966-
/// types with their upper bounds.
5967-
Type typeEraseOpenedExistentialReference(Type type, Type existentialBaseType,
5968-
TypeVariableType *openedTypeVar,
5969-
TypePosition outermostPosition);
5970-
5971-
5972-
/// Given a type that includes opened existential archetypes derived from
5973-
/// the given generic environment, replace the archetypes with their upper
5974-
/// bounds.
5975-
Type typeEraseOpenedArchetypesFromEnvironment(Type type,
5976-
GenericEnvironment *env);
5977-
59785957
/// Returns true if a reference to a member on a given base type will apply
59795958
/// its curried self parameter, assuming it has one.
59805959
///

0 commit comments

Comments
 (0)