Skip to content

Commit e3af684

Browse files
authored
Merge pull request swiftlang#41183 from DougGregor/implicitly-open-existentials
2 parents fee21bc + 4141e20 commit e3af684

17 files changed

+691
-149
lines changed

include/swift/AST/Decl.h

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2159,9 +2159,9 @@ class PoundDiagnosticDecl : public Decl {
21592159
class OpaqueTypeDecl;
21602160

21612161
/// Describes the least favorable positions at which a requirement refers
2162-
/// to 'Self' in terms of variance, for use in the is-inheritable and
2163-
/// is-available-existential checks.
2164-
class SelfReferenceInfo final {
2162+
/// to a given generic parameter in terms of variance, for use in the
2163+
/// is-inheritable and is-available-existential checks.
2164+
class GenericParameterReferenceInfo final {
21652165
using OptionalTypePosition = OptionalEnum<decltype(TypePosition::Covariant)>;
21662166

21672167
public:
@@ -2171,27 +2171,27 @@ class SelfReferenceInfo final {
21712171
OptionalTypePosition assocTypeRef;
21722172

21732173
/// A reference to 'Self'.
2174-
static SelfReferenceInfo forSelfRef(TypePosition position) {
2175-
return SelfReferenceInfo(false, position, llvm::None);
2174+
static GenericParameterReferenceInfo forSelfRef(TypePosition position) {
2175+
return GenericParameterReferenceInfo(false, position, llvm::None);
21762176
}
21772177

21782178
/// A reference to 'Self' through an associated type.
2179-
static SelfReferenceInfo forAssocTypeRef(TypePosition position) {
2180-
return SelfReferenceInfo(false, llvm::None, position);
2179+
static GenericParameterReferenceInfo forAssocTypeRef(TypePosition position) {
2180+
return GenericParameterReferenceInfo(false, llvm::None, position);
21812181
}
21822182

2183-
SelfReferenceInfo &operator|=(const SelfReferenceInfo &other);
2183+
GenericParameterReferenceInfo &operator|=(const GenericParameterReferenceInfo &other);
21842184

21852185
explicit operator bool() const {
21862186
return hasCovariantSelfResult || selfRef || assocTypeRef;
21872187
}
21882188

2189-
SelfReferenceInfo()
2189+
GenericParameterReferenceInfo()
21902190
: hasCovariantSelfResult(false), selfRef(llvm::None),
21912191
assocTypeRef(llvm::None) {}
21922192

21932193
private:
2194-
SelfReferenceInfo(bool hasCovariantSelfResult, OptionalTypePosition selfRef,
2194+
GenericParameterReferenceInfo(bool hasCovariantSelfResult, OptionalTypePosition selfRef,
21952195
OptionalTypePosition assocTypeRef)
21962196
: hasCovariantSelfResult(hasCovariantSelfResult), selfRef(selfRef),
21972197
assocTypeRef(assocTypeRef) {}
@@ -2682,7 +2682,7 @@ class ValueDecl : public Decl {
26822682
/// is considered covariant only when it appears as the immediate type of a
26832683
/// property, or the uncurried result type of a method/subscript, e.g.
26842684
/// '() -> () -> Self'.
2685-
SelfReferenceInfo findExistentialSelfReferences(
2685+
GenericParameterReferenceInfo findExistentialSelfReferences(
26862686
Type baseTy, bool treatNonResultCovariantSelfAsInvariant) const;
26872687
};
26882688

@@ -7800,6 +7800,14 @@ class MissingMemberDecl : public Decl {
78007800
}
78017801
};
78027802

7803+
/// Find references to the given generic paramaeter in the generic signature
7804+
/// and the type of the given value.
7805+
GenericParameterReferenceInfo findGenericParameterReferences(
7806+
const ValueDecl *value,
7807+
CanGenericSignature sig, GenericTypeParamType *genericParam,
7808+
bool treatNonResultCovarianceAsInvariant,
7809+
Optional<unsigned> skipParamIndex);
7810+
78037811
inline bool AbstractStorageDecl::isSettable(const DeclContext *UseDC,
78047812
const DeclRefExpr *base) const {
78057813
if (auto vd = dyn_cast<VarDecl>(this))

include/swift/Basic/LangOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,10 @@ namespace swift {
313313
/// `func f() -> <T> T`.
314314
bool EnableExperimentalNamedOpaqueTypes = false;
315315

316+
/// Enable support for implicitly opening existential argument types
317+
/// in calls to generic functions.
318+
bool EnableOpenedExistentialTypes = false;
319+
316320
/// Enable support for protocol types parameterized by primary
317321
/// associated type.
318322
bool EnableParameterizedProtocolTypes = false;

include/swift/Option/FrontendOptions.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,14 @@ def enable_parameterized_protocol_types :
514514
Flag<["-"], "enable-parameterized-protocol-types">,
515515
HelpText<"Enable experimental support for primary associated types and parameterized protocols">;
516516

517+
def enable_experimental_opened_existential_types :
518+
Flag<["-"], "enable-experimental-opened-existential-types">,
519+
HelpText<"Enable experimental support for implicitly opened existentials">;
520+
521+
def disable_experimental_opened_existential_types :
522+
Flag<["-"], "disble-experimental-opened-existential-types">,
523+
HelpText<"Disable experimental support for implicitly opened existentials">;
524+
517525
def enable_deserialization_recovery :
518526
Flag<["-"], "enable-deserialization-recovery">,
519527
HelpText<"Attempt to recover from missing xrefs (etc) in swiftmodules">;

include/swift/Sema/ConstraintSystem.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3353,6 +3353,11 @@ class ConstraintSystem {
33533353
ConstraintLocator *getOpenOpaqueLocator(
33543354
ConstraintLocatorBuilder locator, OpaqueTypeDecl *opaqueDecl);
33553355

3356+
/// Open the given existential type, recording the opened type in the
3357+
/// constraint system and returning both it and the root opened archetype.
3358+
std::pair<Type, OpenedArchetypeType *> openExistentialType(
3359+
Type type, ConstraintLocator *locator);
3360+
33563361
/// Retrive the constraint locator for the given anchor and
33573362
/// path, uniqued and automatically infer the summary flags
33583363
ConstraintLocator *
@@ -5506,20 +5511,16 @@ matchCallArguments(
55065511
MatchCallArgumentListener &listener,
55075512
Optional<TrailingClosureMatching> trailingClosureMatching);
55085513

5509-
ConstraintSystem::TypeMatchResult
5510-
matchCallArguments(ConstraintSystem &cs,
5511-
FunctionType *contextualType,
5512-
ArgumentList *argumentList,
5513-
ArrayRef<AnyFunctionType::Param> args,
5514-
ArrayRef<AnyFunctionType::Param> params,
5515-
ConstraintKind subKind,
5516-
ConstraintLocatorBuilder locator,
5517-
Optional<TrailingClosureMatching> trailingClosureMatching);
5518-
55195514
/// Given an expression that is the target of argument labels (for a call,
55205515
/// subscript, etc.), find the underlying target expression.
55215516
Expr *getArgumentLabelTargetExpr(Expr *fn);
55225517

5518+
/// Given a type that includes an existential type that has been opened to
5519+
/// the given type variable, type-erase occurences of that opened type
5520+
/// variable and anything that depends on it to their non-dependent bounds.
5521+
Type typeEraseOpenedExistentialReference(Type type, Type existentialBaseType,
5522+
TypeVariableType *openedTypeVar);
5523+
55235524
/// Returns true if a reference to a member on a given base type will apply
55245525
/// its curried self parameter, assuming it has one.
55255526
///

0 commit comments

Comments
 (0)