Commit Graph

30 Commits

Author SHA1 Message Date
Joe Groff
a0a26b8330 Require explicit statement of all Copyable/Escapable requirements for conditional Copyable/Escapable conformances.
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.
2025-01-21 09:36:39 -08:00
Daniel Rodríguez Troitiño
ba68faaed5 [test] Mark tests that use experimental/upcoming features as such
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.
2024-11-02 11:46:46 -07:00
Holly Borla
1527139393 Merge pull request #75425 from hborla/redundant-copyable
[Conformance] Always downgrade redundant conformances to marker protocols to a warning.
2024-07-23 20:55:22 -07:00
Holly Borla
286bdeb481 [NFC][Copyable] Update an expected error to a warning. 2024-07-23 16:50:35 -07:00
Kavon Farvardin
653e224711 Sema: handle ~<<error type>> gracefully 2024-07-23 11:05:33 -07:00
Kavon Farvardin
a1e14ae0c7 Sema: ext's must add solo invertible conformances
This helps prevent confusion after not inferring requirements if the
extension adds a Copyable conformance.
2024-06-12 14:44:22 -07:00
Kavon Farvardin
2893e3dd8d Sema: reword inverse-on-extension message
We should be saying "can't suppress Copyable" instead, since you can't
"suppress" ~Copyable.
2024-06-12 14:44:22 -07:00
Anthony Latsis
1b6efc12ea [NFC] Reorganize and extend any syntax enforcement tests 2024-06-04 02:13:04 +03:00
Kavon Farvardin
0420310623 NCGenerics: it's no longer "experimental"
resolves rdar://127701059
2024-05-08 10:49:12 -07:00
Nate Chandler
ba467d2bd2 [Sema] Enable suppression of inferred conformances.
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.
2024-04-15 16:46:22 -07:00
Kavon Farvardin
30983530b6 NCGenerics: introduce SuppressedAssociatedTypes
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.
2024-04-02 16:53:36 -07:00
Doug Gregor
533a744623 Parse suppressed-conformance constraints in expressions and validate them
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.
2024-04-01 14:32:40 -07:00
Doug Gregor
7eb964c147 Parse inverse requirements like ~Copyable in expression position.
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.
2024-04-01 10:58:01 -07:00
Slava Pestov
3a4d831e52 AST: Fix crash-on-invalid when writing ~ followed by a non-protocol
Also reword some diagnostics. We don't want to talk about 'invert' or
'inverse'.
2024-03-11 14:36:21 -04:00
Slava Pestov
512a15939d Sema: Fix handling of inverse requirements in checkProtocolRefinementRequirements() 2024-02-24 07:25:59 -05:00
Kavon Farvardin
08b71e0136 NCGenerics: rebuild stdlib from its interface
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.
2024-02-15 18:08:54 -08:00
Kavon Farvardin
6d3e7e0818 test: add missing composition conflict error 2024-02-08 22:46:01 -08:00
Slava Pestov
8db0af48bd Merge pull request #71352 from slavapestov/remove-redundant-requirements
Remove -warn-redundant-requirements flag
2024-02-03 08:28:02 -05:00
Slava Pestov
ea15d9f9b2 Stop passing -warn-redundant-requirements in tests 2024-02-02 14:57:19 -05:00
Kavon Farvardin
7612682621 NCGenerics: update a number of tests
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.
2024-02-02 11:11:17 -08:00
Kavon Farvardin
5f977ca763 NCGenerics: force module mismatches 2024-01-31 14:00:08 -08:00
Kavon Farvardin
e99ce1cc5d [NCGenerics] add ~Escapable
Basic implementation of `~Escapable` in the type system.

rdar://119216918
2023-12-10 01:25:43 -08:00
Kavon Farvardin
63b3e7624d [NCGenerics] fold InverseType into PCT
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.
2023-12-07 22:14:23 -08:00
Kavon Farvardin
28890ba580 [Sema] no Copyable conformance if marked ~Copyable
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.
2023-11-07 13:09:15 -08:00
Kavon Farvardin
455fcdc5e0 [Sema] add redundant ~Copyable requirement warning
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.
2023-11-06 15:38:10 -08:00
Kavon Farvardin
bbbf4e7d43 [Sema] drop half-baked redundancy checking for now
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`.
2023-10-28 15:31:44 -07:00
Kavon Farvardin
dcd465ee00 [NoncopyableGenerics] additional test coverage 2023-10-27 15:01:10 -07:00
Kavon Farvardin
85340ea148 [HasNoncopyableAnnotationRequest] handle where
Adds rudiementary support for searching `where` clauses for `~Copyable`
constraints, but the implementation is known to have flaws.
2023-10-18 13:52:14 -07:00
Kavon Farvardin
0944d46e65 [nfc] fix spelling; invertable -> invertible 2023-09-22 17:04:57 -07:00
Kavon Farvardin
54643c1c1d [Parser] allow ~Copyable to appear in more places
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
2023-09-22 17:04:57 -07:00