Commit Graph

4105 Commits

Author SHA1 Message Date
nate-chandler
5e92df0014 Merge pull request #71470 from nate-chandler/bitwise-copyable/same-file
[BitwiseCopyable] Require conformance in same module as declaration.
2024-02-08 16:19:56 -08:00
Kavon Farvardin
5e51773718 NCGenerics: find conflicts in PCT's
We weren't diagnosing conflicts in PCT's like `Copyable & ~Copyable`,
instead deferring until that PCT was constrained to something like the
existential Self or a generic parameter, which then we'd diagnose.

But we should canonicalize PCT's such as `Copyable & Copyable` into
`Any`, which represents the empty composition. That's what the assert in
 PCT::build is about.
2024-02-08 15:56:50 -08:00
Nate Chandler
e0487b6ce0 [BitwiseCopyable] Ban non-trivial C++ types.
Such types can't be copied bit-by-bit.
2024-02-08 12:47:30 -08:00
Nate Chandler
ce6c25977b [BitwiseCopyable] Req conformance in decl module.
Don't allow conformances to `BitwiseCopyable` to be declared in other
modules.
2024-02-08 10:51:13 -08:00
Nate Chandler
0bc38128d8 [BitwiseCopyable] Ban indirect enums and cases.
Enums which are entirely indirect or which have indirect cases are never
trivial and hence cannot conform to BitwiseCopyable.
2024-02-08 06:47:32 -08:00
Kavon Farvardin
aaf2f7e565 Merge pull request #71438 from kavon/ncgenerics-test-fixes-kavon-v4
Ncgenerics test fixes kavon v4
2024-02-07 19:28:11 -08:00
Kavon Farvardin
3ab4c7548c Sema: ban extensions of known marker protocols
There's no good reason to permit them. Conformances like Copyable and
Sendable are pervasive, so it's as though we are permitting extensions
of `Any`. Until there's a good argument in favor of such extensions,
remove the capability now.
2024-02-07 14:54:36 -08:00
John McCall
60807a76a4 Merge pull request #71433 from rjmccall/isolated-any-typechecking
Experimental type-checking support for `@isolated(any)` function types.
2024-02-07 14:07:53 -05:00
John McCall
2f8a33cf0a Experimental type-checking support for @isolated(any) function types. 2024-02-06 22:54:27 -05:00
Doug Gregor
0b01b55e73 Remove an old restriction on _ObjectiveCBridgeable conformances.
Historically, we checked against a specific allowlist for a certain set
of types that were allowed to introduce an `_ObjectiveCBridgeable`
conformance in a different module that where the type was defined.
This rigid allow-list isn't really buying us much, but it's getting in
the way of some refactoring for swift-foundation that's changing
the layering. Remove this diagnostic, since it really isn't buying us
much nowadays, and we have the more general warnings about retroactive
conformances to make folks think twice.
2024-02-06 16:09:17 -08:00
nate-chandler
f98b211f18 Merge pull request #71403 from nate-chandler/delete-flag
[Frontend] Removed enable-lexical-borrow-scopes flag.
2024-02-06 07:00:25 -08:00
Slava Pestov
d46bd335de Merge pull request #71371 from slavapestov/ncgenerics-fixes-3
Non-copyable generics fixes, part 3
2024-02-06 08:35:07 -05:00
Nate Chandler
ddccaa7d9c [Frontend] Removed lexical-borrow-scope flag.
Adding `move_value [lexical]` and `begin_borrow [lexical]` should happen
all the time at this point.  Remove the ability to omit these
instructions and update the corresponding tests.
2024-02-05 17:34:10 -08:00
Slava Pestov
d9c82b1b04 Sema: Clean up printing of generic signatures in missing witness diagnostics
Instead of stripping out requirements, let's pass the right PrintOptions.
2024-02-05 17:13:02 -05:00
Pavel Yaskevich
55af87f8e0 Merge pull request #71372 from apple/function-keypath-follow-ups
Follow ups for keypath function conversion PR
2024-02-05 09:47:45 -08:00
Andrew Trick
e738b8a77e Merge pull request #71353 from meg-gupta/initlifetimedep
Support for lifetime dependence specifiers on initializers
2024-02-05 08:55:54 -08:00
Freddy Kellison-Linn
aedf854e33 Follow ups for keypath function conversion PR 2024-02-03 13:41:22 -05:00
Frederick Kellison-Linn
0735629c8d Merge pull request #39612 from Jumhyn/keypath-function-conversion
[ConstraintSystem] Allow function-function conversions for keypath literals
2024-02-03 10:26:13 -08:00
Slava Pestov
387156ae11 Merge pull request #71354 from slavapestov/check-type-witness-fix
Sema: Fix problems with checkTypeWitness()
2024-02-03 08:28:14 -05: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
1867b38a5f Sema: Fix problems with checkTypeWitness()
Our tentative witness might have weird concrete DependentMemberTypes
in it. In that case, perform a more relaxed check that can succeed
as long as the witness is not completely invalid.

This problem was exposed by existing test cases starting to fail
once implicit Copyable requirements were introduced, because these
concrete DependentMemberTypes do not conform to protocols. This now
postpones the check until all witnesses have been fully substituted.

This also fixes a long-standing bug with superclass requirements on
associated types.

Fixes https://github.com/apple/swift/issues/48770,
https://github.com/apple/swift/issues/51772,
rdar://95729075.
2024-02-02 23:30:44 -05:00
Slava Pestov
dcca5ced0f RequirementMachine: Remove -warn-redundant-requirements flag 2024-02-02 14:57:19 -05:00
Meghana Gupta
c8ece100ba Handle explicit lifetime dependence specifiers in initializers 2024-02-02 11:50:10 -08:00
Pavel Yaskevich
db7959668e [Frontend] NFC: Rename PreconcurrencyConformances to DynamicActorIsolation 2024-02-01 13:28:25 -08:00
Holly Borla
11cb94faa5 [Concurrency] Use .limitBehaviorUntilSwiftVersion for concurrency diagnostics
that are suppressed or downgraded until Swift 6.

There are a few benefits to using a `UntilSwiftVersion` diagnostic engine API,
including the diagnostic wrapping to communicate that the mistake will be an
error in Swift 6, and to include the mistake in the frontend statistic for
Swift 6 errors.
2024-01-31 17:08:01 -08:00
Holly Borla
09432a9993 [Concurrency] Sendable diagnostics are errors in Swift 6. 2024-01-30 18:50:00 -08:00
Meghana Gupta
4dcda843e2 Infer lifetime dependence info for functions that return ~Escapable type 2024-01-29 15:45:19 -08:00
Meghana Gupta
f716c097ac Diagnose if lifetime dependence specifier is present on Escapable type 2024-01-29 14:55:47 -08:00
John McCall
41cdfb04ad Introduce a proper TypeAttribute class hierarchy.
The old TypeAttributes reprsentation wasn't too bad for a small number of
simple attributes.  Unfortunately, the number of attributes has grown over
the years by quite a bit, which makes TypeAttributes fairly bulky even at
just a single SourceLoc per attribute.  The bigger problem is that we want
to carry more information than that on some of these attributes, which is
all super ad hoc and awkward.  And given that we want to do some things
for each attribute we see, like diagnosing unapplied attributes, the linear
data structure does require a fair amount of extra work.

I switched around the checking logic quite a bit in order to try to fit in
with the new representation better.  The most significant change here is the
change to how we handle implicit noescape, where now we're passing the
escaping attribute's presence down in the context instead of resetting the
context anytime we see any attributes at all.  This should be cleaner overall.

The source range changes around some of the @escaping checking is really a
sort of bugfix --- the existing code was really jumping from the @ sign
all the way past the autoclosure keyword in a way that I'm not sure always
works and is definitely a little unintentional-feeling.

I tried to make the parser logic more consistent around recognizing these
parameter specifiers; it seems better now, at least.
2024-01-28 22:30:26 -05:00
Holly Borla
c98d93d75f Merge pull request #70909 from hborla/nonisolated-nonsendable 2024-01-28 13:10:23 -08:00
Holly Borla
009d7d0c70 [Concurrency] nonisolated can only be applied to actor properties with
`Sendable` type.
2024-01-26 08:54:28 -08:00
Nate Chandler
898737db0d [BitwiseCopyable] Require Copyable, Escapable.
In order to conform to _BitwiseCopyable, require that a type not be
~Copyable or ~Escapable.  Once the stdlib is built with the relevant
feature flags, that checking will occur automatically.  Until then, have
these bespoke diagnostics.
2024-01-25 07:22:12 -08:00
Kavon Farvardin
b8cd7effeb Merge pull request #70866 from kavon/ncgenerics-stdlib-building-v4
Build Stdlib with Noncopyable Generics (Part 4)
2024-01-25 07:09:38 -08:00
Meghana Gupta
28f27c3da1 Merge pull request #71069 from meg-gupta/lifetimedependencelangattr
Initial language support for lifetime dependence
2024-01-25 00:39:13 -08:00
Meghana Gupta
1894b11017 Add additional lifetime dependence diagnostics 2024-01-24 15:01:15 -08:00
Meghana Gupta
79248a5866 Diagnose if lifetime dependence specifiers are not in the function result position 2024-01-24 15:01:15 -08:00
Meghana Gupta
0cb805bccf Add Sema support for LifetimeDependence 2024-01-24 15:01:15 -08:00
Sophia Poirier
74d2127583 Merge pull request #71067 from sophiapoirier/nonisolated-mutable-stored-property-diagnostic
[Concurrency] clarify diagnostic for 'nonisolated' stored properties being due to mutability
2024-01-24 11:43:43 -08:00
Kavon Farvardin
483b569bc8 [NCGenerics] trigger module mismatch
A swiftmodule can only be correctly ingested by a compiler
that has a matching state of using or not-using
NoncopyableGenerics.

The reason for this is fundamental: the absence of a Copyable
conformance in the swiftmodule indicates that a type is
noncopyable. Thus, if a compiler with NoncopyableGenerics
reads a swiftmodule that was not compiled with that feature,
it will think every type in that module is noncopyable.

Similarly, if a compiler with NoncopyableGenerics produces a
swiftmodule, there will be Copyable requirements on each
generic parameter that the compiler without the feature will
become confused about.

The solution here is to trigger a module mismatch, so that
the compiler re-generates the swiftmodule file using the
swiftinterface, which has been kept compatible with the compiler
regardless of whether the feature is enabled.
2024-01-23 22:42:37 -08:00
Sophia Poirier
27b57c6ce3 [Concurrency] clarify diagnostic for 'nonisolated' stored properties being due to mutability 2024-01-23 15:15:29 -08:00
Frederick Kellison-Linn
0d79f4523a Allow function-function conversions for keypath literals
Remove keypath subtype asserts; always use cached root type

Add tests for keypaths converted to funcs with inout param

Add unit test for overload selection
2024-01-23 08:51:44 -05:00
Holly Borla
d60a06760b Merge pull request #71050 from hborla/global-actor-unsafe
[Concurrency] Deprecate `@GlobalActor(unsafe)` in favor of `@preconcurrency @GlobalActor`
2024-01-22 16:52:56 -08:00
Holly Borla
ecd94e4908 [Concurrency] Diagnose @GlobalActor(unsafe) attributes with a fix-it to use
`@preconcurrency` instead.

This diagnosic is a warning until Swift 6, and it's ignored in swiftinterfaces.
2024-01-21 21:05:33 -08:00
Slava Pestov
0bc2e3f8e8 Sema: Diagnostic strings should not end with a full stop 2024-01-21 08:34:41 -05:00
Hamish Knight
72cbea678a [Sema] Avoid mentioning then in a diagnostic
This is still an experimental feature, so avoid
mentioning it in this diagnostic.
2024-01-18 14:52:20 +00:00
Anthony Latsis
96ee57b00b Merge pull request #70623 from AnthonyLatsis/init-sema
Move unqualified `init` diagnosis from Parse to Sema
2024-01-18 03:53:33 +03:00
Pavel Yaskevich
6cdab78028 Merge pull request #70867 from xedin/dynamic-enforcement-of-witness-isolation-with-preconcurrency
[TypeChecker/SILGen] Dynamic enforcement of witness/objc isolation with @preconcurrency attribute
2024-01-17 10:01:37 -08:00
Doug Gregor
8b514ec029 Merge pull request #70902 from DougGregor/isolation-macro
Implement `#isolation` macro to produce the isolation of the current context
2024-01-16 14:27:00 -08:00
Doug Gregor
255009dddb Implement #isolation macro to produce the isolation of the current context
Introduce a new expression macro that produces an value of type
`(any AnyActor)?` that describes the current actor isolation. This
isolation will be `nil` in non-isolated code, and refer to either the
actor instance of shared global actor in other cases.

This is currently behind the experimental feature flag
OptionalIsolatedParameters.
2024-01-16 14:25:51 -08:00
Pavel Yaskevich
1caafee3cf [Sema] Diagnose places where @preconcurrency attribute on conformance has no effect 2024-01-16 11:51:49 -08:00