Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
c5112ac
Experimental support for implicitly opening existential arguments.
DougGregor Feb 2, 2022
69cac7d
Erase opaque types involving opened existential types to their upper …
DougGregor Feb 3, 2022
8a41c4c
Opaque types are only invariant when they involve same-type constraints.
DougGregor Feb 4, 2022
5a4af8d
Fix flag name
DougGregor Feb 4, 2022
4fed119
Fix test availability for opaque result types
DougGregor Feb 4, 2022
98e096f
Prevent opening existentials when the corresponding parameter is variant
DougGregor Feb 7, 2022
79ddd70
Support opening of arguments of existential metatype type.
DougGregor Feb 7, 2022
54687e0
Don't open existential arguments to `type(of:)`.
DougGregor Feb 8, 2022
277282a
Ensure that we only open existential arguments to functions/subscripts.
DougGregor Feb 8, 2022
7c03643
Don't open existentials when calling C++ function templates
DougGregor Feb 8, 2022
b3d7e8a
SwiftOnoneSupport creates different specializations with opened exist…
DougGregor Feb 10, 2022
3476eb8
Opened existential types aren't always `ExistentialType`.
DougGregor Feb 10, 2022
9035806
Only open existentials for generic arguments on the called declaration
DougGregor Feb 10, 2022
eb73e81
Cannot open existentials passed to variadic parameters.
DougGregor Feb 10, 2022
9b80a01
Allow opening existentials for inout parameters.
DougGregor Feb 10, 2022
5e50d0f
Allow existential opening for parameters of optional type.
DougGregor Feb 11, 2022
2641f2d
[DNM] Force-enable implicit opening of existentials
DougGregor Feb 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2161,9 +2161,9 @@ class PoundDiagnosticDecl : public Decl {
class OpaqueTypeDecl;

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

public:
Expand All @@ -2173,27 +2173,27 @@ class SelfReferenceInfo final {
OptionalTypePosition assocTypeRef;

/// A reference to 'Self'.
static SelfReferenceInfo forSelfRef(TypePosition position) {
return SelfReferenceInfo(false, position, llvm::None);
static GenericParameterReferenceInfo forSelfRef(TypePosition position) {
return GenericParameterReferenceInfo(false, position, llvm::None);
}

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

SelfReferenceInfo &operator|=(const SelfReferenceInfo &other);
GenericParameterReferenceInfo &operator|=(const GenericParameterReferenceInfo &other);

explicit operator bool() const {
return hasCovariantSelfResult || selfRef || assocTypeRef;
}

SelfReferenceInfo()
GenericParameterReferenceInfo()
: hasCovariantSelfResult(false), selfRef(llvm::None),
assocTypeRef(llvm::None) {}

private:
SelfReferenceInfo(bool hasCovariantSelfResult, OptionalTypePosition selfRef,
GenericParameterReferenceInfo(bool hasCovariantSelfResult, OptionalTypePosition selfRef,
OptionalTypePosition assocTypeRef)
: hasCovariantSelfResult(hasCovariantSelfResult), selfRef(selfRef),
assocTypeRef(assocTypeRef) {}
Expand Down Expand Up @@ -2684,7 +2684,7 @@ class ValueDecl : public Decl {
/// is considered covariant only when it appears as the immediate type of a
/// property, or the uncurried result type of a method/subscript, e.g.
/// '() -> () -> Self'.
SelfReferenceInfo findExistentialSelfReferences(
GenericParameterReferenceInfo findExistentialSelfReferences(
Type baseTy, bool treatNonResultCovariantSelfAsInvariant) const;
};

Expand Down Expand Up @@ -7785,6 +7785,14 @@ class MissingMemberDecl : public Decl {
}
};

/// Find references to the given generic paramaeter in the generic signature
/// and the type of the given value.
GenericParameterReferenceInfo findGenericParameterReferences(
const ValueDecl *value,
CanGenericSignature sig, GenericTypeParamType *genericParam,
bool treatNonResultCovarianceAsInvariant,
Optional<unsigned> skipParamIndex);

inline bool AbstractStorageDecl::isSettable(const DeclContext *UseDC,
const DeclRefExpr *base) const {
if (auto vd = dyn_cast<VarDecl>(this))
Expand Down
4 changes: 4 additions & 0 deletions include/swift/Basic/LangOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,10 @@ namespace swift {
/// keyword.
bool EnableExplicitExistentialTypes = true;

/// Enable support for implicitly opening existential argument types
/// in calls to generic functions.
bool EnableOpenedExistentialTypes = false;

/// Enable support for protocol types parameterized by primary
/// associated type.
bool EnableParameterizedProtocolTypes = false;
Expand Down
4 changes: 4 additions & 0 deletions include/swift/Option/FrontendOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,10 @@ def enable_parameterized_protocol_types :
Flag<["-"], "enable-parameterized-protocol-types">,
HelpText<"Enable experimental support for primary associated types and parameterized protocols">;

def enable_experimental_opened_existential_types :
Flag<["-"], "enable-experimental-opened-existential-types">,
HelpText<"Enable experimental support for implicitly opened existentials">;

def enable_deserialization_recovery :
Flag<["-"], "enable-deserialization-recovery">,
HelpText<"Attempt to recover from missing xrefs (etc) in swiftmodules">;
Expand Down
21 changes: 11 additions & 10 deletions include/swift/Sema/ConstraintSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -3334,6 +3334,11 @@ class ConstraintSystem {
ConstraintLocator *getOpenOpaqueLocator(
ConstraintLocatorBuilder locator, OpaqueTypeDecl *opaqueDecl);

/// Open the given existential type, recording the opened type in the
/// constraint system and returning both it and the root opened archetype.
std::pair<Type, OpenedArchetypeType *> openExistentialType(
Type type, ConstraintLocator *locator);

/// Retrive the constraint locator for the given anchor and
/// path, uniqued and automatically infer the summary flags
ConstraintLocator *
Expand Down Expand Up @@ -5489,20 +5494,16 @@ matchCallArguments(
MatchCallArgumentListener &listener,
Optional<TrailingClosureMatching> trailingClosureMatching);

ConstraintSystem::TypeMatchResult
matchCallArguments(ConstraintSystem &cs,
FunctionType *contextualType,
ArgumentList *argumentList,
ArrayRef<AnyFunctionType::Param> args,
ArrayRef<AnyFunctionType::Param> params,
ConstraintKind subKind,
ConstraintLocatorBuilder locator,
Optional<TrailingClosureMatching> trailingClosureMatching);

/// Given an expression that is the target of argument labels (for a call,
/// subscript, etc.), find the underlying target expression.
Expr *getArgumentLabelTargetExpr(Expr *fn);

/// Given a type that includes an existential type that has been opened to
/// the given type variable, type-erase occurences of that opened type
/// variable and anything that depends on it to their non-dependent bounds.
Type typeEraseOpenedExistentialReference(Type type, Type existentialBaseType,
TypeVariableType *openedTypeVar);

/// Returns true if a reference to a member on a given base type will apply
/// its curried self parameter, assuming it has one.
///
Expand Down
Loading