As specified by the SE-0446 acceptance, extensions that declare a type's
conditional `Copyable` or `Escapable` ability must reiterate explicitly all
of the `Copyable` and/or `Escapable` requirements, whether required or not
required (by e.g. `~Copyable`) that were suppressed in the original
type declaration.
Find all the usages of `--enable-experimental-feature` or
`--enable-upcoming-feature` in the tests and replace some of the
`REQUIRES: asserts` to use `REQUIRES: swift-feature-Foo` instead, which
should correctly apply to depending on the asserts/noasserts mode of the
toolchain for each feature.
Remove some comments that talked about enabling asserts since they don't
apply anymore (but I might had miss some).
All this was done with an automated script, so some formatting weirdness
might happen, but I hope I fixed most of those.
There might be some tests that were `REQUIRES: asserts` that might run
in `noasserts` toolchains now. This will normally be because their
feature went from experimental to upcoming/base and the tests were not
updated.
Add the machinery to support suppression of inference of conformance to
protocols that would otherwise be derived automatically.
This commit does not enable any conformances to be suppressed.
The model for associated types hasn't been fully worked-out for
noncopyable generics, but there is some support already that is being
used by the stdlib for an internal-only (and rather cursed) protocol
`_Pointer` to support `UnsafePointer`, etc.
This patch gates the existing experimental support for associated types
behind a feature flag. This flag doesn't emit feature-guards in
interfaces, since support for it is tied closely to NoncopyableGenerics
and has been there from its early days.
Ensure that we're properly parsing suppressed-conformance constraints
in expression contents and in metatypes. This allows types like `any
~Copyable` in expression context as well as types like `any
~Copyable.Type`.
While we're here, ensure that existentials that involve
suppressed-conformance constraints are spelled with `any`.
Fixes rdar://123728228.
Implement parser and type-expression folding semantics for invertible
protocols, so that one can write (e.g.) `[any ~Copyable]` as a type
within expression context.
Fixes rdar://125201146.
When a NoncopyableGenericsMismatch happens between the compiler and
stdlib, allow the compiler to rebuild the stdlib from its interface
instead of exiting with an error.
These tests were not updated in the transition to
`REQUIRES: noncopyable_generics` and thus running them with a
correctly-built stdlib that has the Copyable requirements.
We already need to track the inverses separate from the members in a
ProtocolCompositionType, since inverses aren't real types. Thus, the
only purpose being served by InverseType is to be eliminated by
RequirementLowering when it appears in a conformance requirement.
Instead, we introduce separate type InverseRequirement just to keep
track of which inverses we encounter to facilitate cancelling-out
defaults and ensuring that the inverses are respected after running
the RequirementMachine.
Much like when the type defines a deinit, if the nominal's declaration
is marked with ~Copyable, that prevents conformance to Copyable.
This meant that when trying to auto-derive Copyable conformance, we'll
skip types marked with ~Copyable. But now, we'll also reject
explicitly-requested conformances to Copyable because of that marking
too.
In reality right now, all marker protocols have conformances that are
always trivally checked and marked "complete", so when I refer to
rejecting a conformance here, I mean raising a diagnostic while checking
for validity.
Originally I tried to implement a fancy redundant-inverse error
diagnostic that identifies the "previous" requirement already seen. I
ended up removing this error diagnostic because it was tricky to
implement well and we weren't diagnosing other redundant requirements.
Turns out we do have a mode of the compiler to diagnose redundant
requirements, but as warnings, using `-warn-redundant-requirements`.
This warning is much simpler in that it just points to one requirement
that is redundant.
We already don't diagnose all redundant requirements. Because inverses
can be written in both inheritance and where clauses, but they're not
treated uniformly in the implementation, it's a bit annoying to try and
account for the redundancies in both places; `checkInheritanceClause`
will go over the same "requirements" that we'll also check again in
`swift::rewriting::expandDefaultRequirements`.
With `NoncopyableGenerics` enabled, we want to permit the syntax
`any ~Copyable`, and `~Copyable` generally anywhere a type can be
written. We also want to give proper error messages and deal with
typealiases of `Copyable` correctly when `~` precedes some token other
than `Copyable`.
This patch defines the `~` operator to attach rather tightly to simple
types like identifier-like types. The precedence order is roughly like
this within the syntax of types, from higher to lower:
1. `.` (member lookup)
2. postfix optionals: `?`, `!`
3. inverse `~`
4. postfix `...`, etc.
It's also invalid to write something like `~ any T`, as we'll treat
`any` as if it were a type identifier. You must parenthesize such types
to say `~(any T)`. Similarly, we parse `~T.Type` as `~(T.Type)` and not
`(~T).Type`. That might be controversial, but I don't think inverses
can ever support metatypes; they're not even "real" types.
rdar://115913356