Commit Graph

4105 Commits

Author SHA1 Message Date
Holly Borla
bd61b66754 Merge pull request #69974 from hborla/isolated-default-value-fixes
[SE-0411] Fixes for isolated default values.
2023-11-27 12:51:27 -08:00
Slava Pestov
1b1963e904 Sema: Remove 'inferred result type requires explicit coercion' diagnostic 2023-11-27 14:05:36 -05:00
Alejandro Alonso
2f8a0dd8bf Fix a static exclusive diagnostic 2023-11-27 09:12:16 -08:00
Alejandro Alonso
eca56da9bd Add note, check against feature 2023-11-27 09:11:15 -08:00
Alejandro Alonso
7da7c73c71 Introduce @_staticExclusiveOnly 2023-11-27 09:11:13 -08:00
Pavel Yaskevich
8a0d61faac [CSDiagnostics] Add a diagnostic for an invalid key path subscript index argument 2023-11-21 14:53:46 -08:00
Holly Borla
d6fce014a0 [Concurrency] When isolated default values are enabled, synthesized initializers
should be nonisolated if all initialized properties are Sendable with nonisolated
default values.
2023-11-17 16:19:14 -05:00
Holly Borla
e9750bc4e5 [Concurrency] Diagnose default values whose isolation differs from the corresponding
stored property.
2023-11-16 23:56:08 -05:00
Doug Gregor
628f5cbc2c [Typed throws] Support overrides that are contravariant in the thrown error 2023-11-16 10:42:55 -08:00
Doug Gregor
3baf6ac31a Revert "[Typed throws] Support overrides that are contravariant in the thrown error" 2023-11-16 10:40:23 -08:00
Doug Gregor
975519b7b4 Merge pull request #69839 from DougGregor/typed-throws-override
[Typed throws] Support overrides that are contravariant in the thrown error
2023-11-16 09:53:32 -08:00
Ellie Shin
e8d43434db Merge pull request #69733 from apple/es-pkg-intf
Introduce a package interface
2023-11-15 03:53:49 -08:00
Ellie Shin
fbdc16d69a Add a check for an empty package interface path
Update diags
2023-11-14 01:10:02 -08:00
Doug Gregor
33d694468c [Typed throws] Support overrides that are contravariant in the thrown error 2023-11-13 22:30:26 -08:00
Ellie Shin
e5ca8e5c0b Allow loading package interface if in same package.
Add a new flag to enable package interface loading.
Use the last value of package-name in case of dupes.
Rename PrintInterfaceContentMode as InterfaceMode.
Update diagnostics.
Test package interface loading with various scenarios.
Test duplicate package-name.
2023-11-09 18:44:06 -08:00
Pavel Yaskevich
9f21b95fcb [CSDiagnostics] A tailored diagnostic when passing key path as an argument to non-key path parameter
Produce a tailored diagnostic that omits a fully unresolved key path
type (`KeyPath<_, _>`) when key path without an explicit root type is
passed as an argument to non-keypath parameter type (i.e. `Int`).
2023-11-08 19:54:32 -08:00
Visckmart
b93273951f [Sema] Fix throwing super.init() diagnostics
The compiler now diagnoses appropriately the case where a super.init() is marked as throwing while a subclass' initializer isn't marked as throwing nor explicitly calls the super.init().
2023-11-08 12:42:03 -03:00
Meghana Gupta
5658deae27 Add initial support for _resultDependsOnSelf
This is used to establish lifetime dependence between self and the result.

Add under NonEscapableTypes experimental feature
2023-11-08 01:48:59 -08:00
Kavon Farvardin
ab6734aa04 Merge pull request #69590 from kavon/check-if-copyable-inferred
[NoncopyableGenerics] Synthesize conditional conformances
2023-11-07 18:19: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
a4e9919f29 [Sema] require value deinit absence for Copyable
A value type like a struct or enum cannot conform to Copyable if it has
a deinit. When NoncopyableGenerics is enabled, we make that part of what
 is required to verify that such a nominal type conforms to Copyable.

This change also does some refactoring to share common code to point out
 how to make a type noncopyable.
2023-11-06 19:44:58 -08:00
Yuta Saito
79b3d2d626 Add underscore prefix to extern attribute
It's already guarded by a feature flag, but it would be nice to signal
users that it's not stable yet by adding an underscore prefix.
2023-11-07 02:01:02 +00:00
Kavon Farvardin
f8d688ce12 [Sema] overhaul NoncopyableAnnotationRequest
We need to know whether the noncopyable annotation is inferred from its
generic parameters. This allows us to synthesize the conditional
conformance.
2023-11-06 15:41:46 -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
swift-ci
62a24b51e1 Merge pull request #69595 from ktoso/wip-distributed-overloads
[Distributed] Allow overloads with different types; mangling can handle it
2023-11-06 03:31:44 -08:00
Konrad `ktoso` Malawski
8fde809a2c Remove ad-hoc ambiguity detection code; use conflicting() 2023-11-06 12:59:30 +09:00
Zhiyu Zhu/朱智语
6b88070bbe Merge pull request #68782 from ApolloZhu/ApolloZhu/macro/diagnose-default-argument
[Macros] Disallow expression macro as default argument
2023-11-03 13:39:05 -07:00
Pavel Yaskevich
8b4985054a [CSDiagnostics] Differentiate between key path type and value issues
Make sure that contextual mismatch uses a correct locator when
the issue is with key path value type instead of the key path
type.
2023-11-01 09:15:14 -07:00
Konrad `ktoso` Malawski
a3b4e90bb2 [Concurrency] Un-deprecate enqueue(UnownedJob) for easier adoption.
With this deprecation emitted by the compiler some codebases that
support many old Swift versions have been forced into warnings they
cannot avoid due to the compatibility promises they made.

This removes the warning but changes no functionality.
2023-10-31 17:59:57 +09:00
Pavel Yaskevich
9dcb921484 [TypeChecker] Reject @objc attribute on marker protocols 2023-10-30 10:21:04 -07:00
Kavon Farvardin
29acda5136 Merge pull request #69406 from kavon/noncopyable-generics-pt2
[NoncopyableGenerics] handle `~Copyable` in `where`, `some`, and compositions.
2023-10-28 22:36:22 -07: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
2e66b69953 [Sema] prevent inverse-constraints on outer params
Since there is no propagation of inverse constraints in the requirement
machine, we need to fully desugar these requirements at the point of
defining a generic parameter. That desugaring involves determining which
default conformance requirements need to be applied to a generic
parameter, accounting for inverses.

But, nested generic contexts in scope of those expanded generic
parameters can still write constraints on that outer parameter. For
example, this method's where clause can have its own constraints on `T`:

```
struct S<T> {
 func f() where T: ~Copyable {}
}
```

But, the generic signature of `S` already has a `T: Copyable` that was
expanded. The method `f` will always see a `T` that conforms to
`Copyable`, so it's impossible for `f` to claim that it applies for
`T`'s that lack Copyable.

Put another way, it's not valid for this method `f`, whose generic
signature is based on its parent's `S`, to weaken or remove requirements
 from parent's signature. Only positive requirements can be
 added to them.
2023-10-27 15:01:10 -07:00
Kavon Farvardin
bb341e7928 [NoncopyableGenerics] fix isNoncopyable for packs
We're not yet going to allow noncopyable types into packs, so this
change prevents the use of `~Copyable` on an `each T` generic parameter.
 It also fixes how we query for whether a `repeat X` parameter is
 copyable.
2023-10-27 15:01:10 -07:00
Apollo Zhu
35d5b68722 Disallow expression macro as default argument
Using as a sub expression in default argument still allowed as expression macros behave the same as built-in magic literals
2023-10-27 05:40:57 -07:00
Ben Barham
6ff69a000f Merge pull request #69417 from bnbarham/remark-to-warning
[Sema] Move predates concurrency remarks to warnings
2023-10-26 13:12:50 -07:00
Holly Borla
cbdb892fe5 Merge pull request #69391 from hborla/isolated-default-value-revision
[Concurrency] Allow isolated default arguments to be used from across isolation boundaries.
2023-10-26 09:33:25 -07:00
Becca Royal-Gordon
6b795a493e Diagnose lightweight generic classes with objcImpl
Extensions to lightweight generic classes are such a huge mess that we’re just removing these from the feature’s scope for now.

Fixes rdar://116066409.
2023-10-25 16:20:16 -07:00
Becca Royal-Gordon
81b5d59363 Diagnose root classes with @objcImpl
@objcImpl, like @objc, cannot be used to implement root classes. Diagnose an attempt to do so.

Fixes rdar://109130979.
2023-10-25 16:20:16 -07:00
Ben Barham
36686d720d [Sema] Move predates concurrency remarks to warnings
Remarks are intended to be enabled via eg. `-R...`, where as
`(add|remove)_predates_concurrency_import` is a diagnostic that's always
output without any `-R` flag. Move it to a warning instead.

Resolves rdar://114207080.
2023-10-25 14:37:25 -07:00
Holly Borla
49d6399a88 [Concurrency] Allow isolated default arguments to be used from across isolation
boundaries.
2023-10-24 22:54:22 -07:00
Becca Royal-Gordon
1b7adbe6fd Diagnose invalid Swift-only @objcImpl inits
Required and designated inits have to be overridable—the former so that uses of the initializer on `any T.Type` will call the subclass initializer, the latter so that inherited convenience inits will call the subclass initializer. However, Swift-only members use vtables to dispatch to subclasses, and @objcImpl classes don’t have vtables, so their Swift-only inits cannot be made overridable. Upshot: Swift-only inits on @objcImpl classes must be `convenience`, not `required` or designated.

Enforce this rule in the ObjCImplementationChecker.

Fixes rdar://109121293.
2023-10-24 12:33:56 -07:00
Becca Royal-Gordon
9bb71ff91f Add @objcImpl vtable fallback diagnostic
Nothing in an `@_objcImplementation` block—including Swift-only declarations—should ever require a vtable entry. Diagnose any such members.

The diagnostic emitted here is intended to be a fallback that will be used when a vtable entry is needed but we don’t know the specific reason. A future commit will add a more specific diagnostic for Swift-only non-convenience inits.
2023-10-24 12:32:42 -07:00
Becca Royal-Gordon
231de1a666 Add ObjCReason for @objcImpl
Besides improving diagnostics, this also allows us to track whether there were any @objc failures using the invalid bit on the @_objcImplementation attribute.
2023-10-24 10:21:37 -07:00
Pavel Yaskevich
3bb86f3808 Merge pull request #69219 from xedin/rdar-99281333
[TypeChecker] Disallow use of global actor attributes of setters, add…
2023-10-24 09:40:50 -07:00
Pavel Yaskevich
a71d62c6a5 [TypeChecker] Disallow use of global actor attributes of setters, addressors, and observers
No other accessor besides a getter could be marked as async and
adding @MainActor global accessor on setters and other accessor
kinds would mean disconnecting them from a getter in terms of
isolation, so let's keep things simple and allow global actor
attribute on getters and/or enclosing declaration only.

Resolves: rdar://99281333
2023-10-23 16:29:56 -07:00
Yuta Saito
4f0e3bf3ea Merge pull request #69207 from kateinoigakukun/yt/cdecl-without-body
Introduce `@extern(c)` to declare C function without Clang module
2023-10-23 12:48:12 -07:00
Kavon Farvardin
e75c45102f [Sema] redo parameter ownership checking
We really should be checking for the presence of the ownership
annotation from the top of the parameter's TypeRepr hierarchy, instead
of the bottom.

This fixes some missed edge cases that are now relevant, like
`some ~Copyable`. parameters
2023-10-23 10:37:22 -07:00
Kuba (Brecka) Mracek
5fed4798d2 Merge pull request #69192 from kubamracek/attr-section-on-static-vars
Allow attributes @_used and @_section on static variables and member functions
2023-10-22 08:10:11 -07:00
Harlan Haskins
4ac34a40ea @retroactive conformance syntax and checking (#36068) 2023-10-20 14:27:03 -07:00