Commit Graph

16 Commits

Author SHA1 Message Date
swift-ci
44ab03a90b Merge pull request #66871 from kavon/generics-error-noncopyable
Be more specific than "noncopyable type T can't be used with generics yet"
2023-06-26 18:32:26 -07:00
Kavon Farvardin
ada0d335b1 have TypeCheckType be specific about the generic type a noncopyable was used with.
This change causes explicit types written in the
source language that substitute a noncopyable type
for a type variable in a generic type to state
that's what's wrong. For example:

```
// NEW: noncopyable type 'MO' cannot be used with generic type 'Dictionary<Key, Value>' yet
// OLD: noncopyable type 'MO' cannot be used with generics yet
let _: [MO : T]
```
2023-06-22 15:12:30 -07:00
Kavon Farvardin
79332c19b0 emit error when a noncopyable enum has a raw type
previously I was allowing these because I thought there was
some representational difference if the enum is raw. it
turns out that a raw enum is only useful if you synthesize
conformance to RawRepresentable. since I disabled that
synthesis it's kind of silly to still allow the raw type
to be written at all.

rdar://110539937
2023-06-21 11:21:49 -07:00
Kavon Farvardin
31aa2f77e3 polish noncopyable types diagnostic wordings
- replaces "move-only" terminology with "noncopyable"
- replaces compiler jargon like "guaranteed parameters"
  and "lvalue" with corresponding language-level notions
- simplifies diagnostics about closures.

and probably more.

rdar://109281444
2023-05-24 20:56:36 -07:00
Michael Gottesman
739417ff09 [move-only] Convert __shared to borrowing in move only tests.
These are the same semantically, just the mangling is slightly different. The
benefit of doing this is that we are actually testing what we expect our users
to do.

rdar://108511703
2023-04-25 10:51:04 -07:00
Kavon Farvardin
2c7d9a5047 update tests given move-only types are enabled
the main things still left behind the experimental flag(s) are
- move-only classes (guarded by MoveOnlyClasses feature)
- noimplicitcopy
- the _borrow operator
2023-03-14 18:35:13 -07:00
swift-ci
788f52bd1a Merge pull request #64124 from kavon/moveonly-no-effectful-accessor
disallow effectful getters for borrowed reads
2023-03-05 19:12:01 -08:00
Kavon Farvardin
2bf37b49cf disallow effectful getters for borrowed reads
This means properties returning noncopyable types or those
marked with `@_borrowed` can't have effects. The compiler
never accepted the latter correctly before.

The synthesized coroutine `read` calls the user-defined `get`,
but coroutines don't support `async` or `throws`.

resolves rdar://106260787
2023-03-05 16:40:49 -08:00
Kavon Farvardin
971ce817be disallow failable initializers for noncopyable types
These initializers implicitly return an optional of the
nominal type, but we can't wrap move-only / noncopyable
types inside of optionals at the moment, because that
would permit copying.

resolves rdar://106120881
2023-03-05 10:49:45 -08:00
Kavon Farvardin
60d9e614f2 prevent more synthesized conformances for move-only types
enums with only cases that have no associated values
automatically get Equatable and Hashable synthesized.

That's not valid for move-only enums, so we were
just getting errors about broken conformances when
we hadn't specified any explicitly.

This PR just prevents the synthesis from the start
so we don't get any errors.

fixes rdar://104986597
2023-02-10 10:02:43 -08:00
Kavon Farvardin
5b7eada4dd permit conformances in extensions of move-only types
previously we were blindly rejecting anything
that such extensions conformed to, but Sendable
is now allowed for move-only types.
2023-02-10 10:02:43 -08:00
Kavon Farvardin
d2da71a58c update existing tests after banning move-only types in generics
A number of our existing tests put move-only types in optionals and
used them as arguments to generic type parameters. It turns out that
many of these appearances in the tests were not crucial for the test's
functionality itself.

The little coverage for force-unwrapping an Optional<moveOnly>
that was lost will be regained once we make these types sound.

I also tried to tidy up some of the tests with consistent naming for
operations on values, i.e., `consumeVal` and `borrowVal` functions.
2023-02-01 23:38:28 -08:00
Kavon Farvardin
1356694043 experimentally allow move-only classes
A lot of existing regression tests rely on there
being some form of move-only classes, despite
them being something that will not be available
to users (and not complete).

This change introduces a `MoveOnlyClasses`
experimental feature so that those tests don't
need to be fully rewritten just yet. You need to
include `-enable-experimental-feature MoveOnlyClasses` along with
`-enable-experimental-move-only` to get move-only classes.
2023-01-23 22:33:27 -08:00
Slava Pestov
0f66cb6925 Sema: Use getLocalProtocols() instead of getAllProtocols() in move-only diagnostics 2022-11-12 02:13:54 -05:00
Michael Gottesman
51e90ee52c [move-only] Ban creating protocol conformances on move only nominal types.
I added code to the type checker that both bans this when one adds the
conformance on the nominal type declaration as well as on extensions. I was
careful to ensure we can still add extensions without an inherited clause.

Doing this until we get the full generics model.

rdar://101874019
2022-11-04 12:48:44 -07:00
Michael Gottesman
b95b19be44 [move-only] Ban move only types being stored properties of copyable types.
rdar://101650982
2022-11-04 11:56:31 -07:00