We don't want to pass in the outer generic signature here.
The base type's constraint type is written in terms of archetypes,
and we run generic signature queries against it with types appearing
in the protocol member. Since the protocol member has Self at
depth 0, index 0, prepending the outer generic signature to the
opened existential signature would produce incorrect results.
We used to concatenate the DeclContext's generic signature with the
protocol requirement's signature, then look for occurrences of the
first generic parameter from the DeclContext's signature in the
requirement's type.
This almost worked, except when the first generic parameter from the
DeclContext's signature didn't conform to a protocol referenced by
an associated type. In that case, we would falsely report that there
are no 'Self' references.
Note that the CHECK lines in test/SILGen/witnesses_class.swift change
to what they were before 01d9d61cc8.
This ensures that opened archetypes always inherit any outer generic parameters from the context in which they reside. This matters because class bounds may bind generic parameters from these outer contexts, and without the outer context you can wind up with ill-formed generic environments like
<τ_0_0, where τ_0_0 : C<T>, τ_0_0 : P>
Where T is otherwise unbound because there is no entry for it among the generic parameters of the environment's associated generic signature.
It's a convenient way to use existing logic for default argument inference
because suhc inference cannot open whole signature but only conformance
and layout constraints associated generic parameters used in a particular
parameter position.
If an overload locator couldn't be simplified to its anchor, fallback to
the anchor of the locator instead. Also add an assert so that we can
track down whether this is actually valid or not.
Resolves rdar://89097800.
An opaque type is only invariant with respect to the existential Self
when the constraints on the opaque type involve Self. Such constraints
are not expressible in the type-erased value, so treat them as
invariant. This loosens the restriction on using members of protocol
type that return an opaque type, such that (e.g.) the following is
still well-formed:
protocol P { }
protocol Q { }
extension P {
func getQ() -> some Q { ... }
}
func test(p: any P) {
let q = p.getQ() // formerly an error, now returns an "any Q"
}
However, this does not permit uses of members such as:
extension P {
func getCollection() -> some Collection<Self> { ... } // error
}
because the type system cannot express the corresponding existential
type `any Collection<Self>`.
When calling a generic function with an argument of existential type,
implicitly "open" the existential type into a concrete archetype, which
can then be bound to the generic type. This extends the implicit
opening that is performed when accessing a member of an existential
type from the "self" parameter to all parameters. For example:
func unsafeFirst<C: Collection>(_ c: C) -> C.Element { c.first! }
func g(c: any Collection) {
unsafeFirst(c) // currently an error
// with this change, succeeds and produces an 'Any'
}
This avoids many common sources of errors of the form
protocol 'P' as a type cannot conform to the protocol itself
which come from calling generic functions with an existential, and
allows another way "out" if one has an existention and needs to treat
it generically.
This feature is behind a frontend flag
`-enable-experimental-opened-existential-types`.
When we are within a closure that is not required to be asynchronous
(i.e., it has no `await` in it), make sure that we prefer synchronous
functions to asynchronous ones, even if this closure will later be
converted to `async` and the constraint system knows that.
Fixes rdar://88692889.
Instead of asking callers of `isExpired` to provide the threshold,
let's ask for that upfront. This change also allows us to check how
much time remains in the timer and build timers with different
thresholds without having to safe that information somewhere else.
Some implicit calls to `.callAsFunction` require that a new root
expression to be created for them in order to record argument list
and resolved overload choice.
I need to determine when top-level code contains an `await` to determine
whether to make the source file an async context. This logic is
perfectly encapsulated in the `FindInnerAsync` AST walker.
Unfortunately, that is pushed down in Sema/ConstraintSystem and isn't
available at the AST level. I've pulled it up into the brace statement
so that I can use that as part of determining whether the source file is
async in `DeclContext::isAsyncContext`.
Unfortunately, statements don't have an AST context or evaluator or I
would make this a request.
Opened archetypes can be created in the constraint system, and the
existential type it wraps can contain type variables. This can happen
when the existential type is inferred through a typealias inside a
generic type, and a member reference whose base is the opened existential
gets bound before binding the generic arguments of the parent type.
However, simplifying opened archetypes to replace type variables is
not yet supported, which leads to type variables escaping the constraint
system. We can support cases where the underlying existential type doesn't
depend on the type variables by canonicalizing it when opening the
existential. Cases where the underlying type requires resolved generic
arguments are still unsupported for now.