Commit Graph

4105 Commits

Author SHA1 Message Date
Doug Gregor
54589e12f5 [Typed throws] Type-check thrown expressions against the thrown error type
Rather than always type-check the expression in a `throw` statement for
conformance to `Error`, check that it converts to the thrown error type.
2023-09-29 10:51:54 -07:00
Doug Gregor
51eed19d4b [Typed throws] Type system support for typed throws.
Add the thrown type into the AST representation of function types,
mapping from function type representations and declarations into the
appropriate thrown type. Add tests for serialization, printing, and
basic equivalence of function types that have thrown errors.
2023-09-29 10:51:53 -07:00
Alexis Laferrière
c15a576a1c [Sema] Introduce remarks about the source of each decl in API
Using `-Rmodule-api-import` the compiler prints a remark about the
import bringing in every decl used in public function signatures or
inlinable code. It also remarks on the source of conformances where they
are used and the source of typealias underlying types.
2023-09-28 13:00:04 -07:00
Alexis Laferrière
a0b848ea96 [Sema] Report imports marked as public that are not used in API 2023-09-28 13:00:04 -07:00
Yuta Saito
8cfcc245b5 Merge pull request #68524 from kateinoigakukun/katei/expose-wasm-sym
[wasm] Add `@_expose(wasm)` attribute for top-level functions
2023-09-28 09:17:48 -07:00
Alexis Laferrière
1bf368609e Merge pull request #68776 from xymus/access-level-import-indirect-checks
Sema: report conformances and typealias underlying types behind non-public imports
2023-09-27 12:54:35 -07:00
Alexis Laferrière
8f195b0a17 [Sema] Note which import restricts conformances and typealiases in API 2023-09-27 08:09:33 -07:00
Alexis Laferrière
2322164854 [Sema] Report typealiases desugaring to a non-public import in API
Typealiases with an underlying type from a non-public import cannot be
used in API or inlinable code. Report this as an error.
2023-09-26 14:24:10 -07:00
Alexis Laferrière
411ad875f5 [Sema] Ignore "exportability" check for non-public code
Exportability checking logic detects when decls are referenced from API
or inlinable code. This duplicates the check applied for the access
level. Skip the exportability reports about non-public imports and keep
the more familiar access-level check.
2023-09-26 14:23:37 -07:00
Alexis Laferrière
e90e2deb5d [Sema] Report use of conformances from non-public imports in inlinable code
Conformances imported as non-public cannot be used in API or inlinable
code, report it as an error.
2023-09-26 14:22:47 -07:00
Yuta Saito
6d378a3ec3 [wasm] add @_expose(wasm) attribute support
This attribute instructs the compiler that this function declaration
should be "export"ed from this .wasm module. It's equivalent of Clang's
`__attribute__((export_name("name")))`
2023-09-26 14:13:33 +00:00
Pavel Yaskevich
c5138a385a Merge pull request #68459 from mininny/error-on-inout-on-invalid-parameter
Fix inaccurate error on inout in wrong parameter type
2023-09-25 08:32:23 +01:00
Minhyuk Kim
c0eab4f551 Change error message to specify when inout usage is allowed 2023-09-24 23:18:27 +09:00
Kavon Farvardin
96d16b1a73 Merge pull request #68716 from kavon/inverse-parsing
permit parsing of `~` in general type syntaxes
2023-09-23 15:30:49 -07:00
Minhyuk Kim
d9a03dda17 [Sema] Produce better diagnostics when using inout on parameter types that cannot be 'inout'. Resolves #68417 2023-09-23 22:15:13 +09:00
Kavon Farvardin
0944d46e65 [nfc] fix spelling; invertable -> invertible 2023-09-22 17:04:57 -07:00
Holly Borla
d6483ae889 Merge pull request #68693 from hborla/non-sendable-local-captures
[Concurrency] Diagnose Sendable violations in captures of local functions.
2023-09-22 07:43:50 -07:00
Holly Borla
2159c0c58a [Concurrency] Diagnose Sendable violations in captures of local functions. 2023-09-21 21:11:34 -07:00
Kavon Farvardin
a69bcf8a61 Merge pull request #67930 from kavon/copyable-requirement
Copyable as a Requirement Against the Machine
2023-09-21 11:49:23 -07:00
Kavon Farvardin
80097bce0c [Generics] ~Copyable in inheritance clauses
Have `~Copyable` change the signatures of a generic type param,
protocol, or associated type if written in the inheritance clause
position.
2023-09-21 00:55:17 -07:00
Alexis Laferrière
4cd10483f4 [Sema] Name the decl in the error on package level without a package 2023-09-19 17:13:19 -07:00
Alexis Laferrière
1a4a47fee3 [Sema] Merge diagnostics about package modifier outside of a package
Show the same error for both decls and imports when using the package
access level and no package name is set. Also brings up this check to
run once on decls and avoid repeated diagnostics.
2023-09-19 15:01:16 -07:00
Kavon Farvardin
16af507d9e [Concurrency] tighten-up rules about isolated generic parameters
We were missing a check for conformance to `Actor` or `DistributedActor`
when an isolated parameter's type is a generic parameter.

Previously, if you used a generic parameter constrained to just `AnyActor`,
you'd crash the compiler in LowerHopToExecutor because it doesn't know
how to obtain the executor for such a value. Since `AnyActor` has no
`unownedExecutor` requirement, there's no way to get the executor without
emitting code to do dynamic casts down to `Actor` or `DistributedActor`.

Rather than have the compiler silently emit dynamic casting, I figured
it's best to ban it. This forces people to either do the dynamic casts
themselves, or use one of the more specific types to constrain their
parameter.

For other generic parameters, we would silently treat the function
as though it is nonisolated (i.e., as if the `isolated` wasn't written
on the parameter at all).

resolves rdar://109059544
2023-09-18 20:27:46 -07:00
Alexis Laferrière
377ecf46f9 [Sema] Pass ModuleDecl directly to notes on imports with access-levels 2023-09-13 15:40:33 -07:00
Slava Pestov
973a5065e2 Merge pull request #68282 from slavapestov/sema-tuple-conformances
(More) Declaration checker support for tuple conformances
2023-09-07 11:57:05 -04:00
Slava Pestov
1a72ca133b Sema: Enforce coherence condition on type witnesses of tuple conformance
We want that (repeat each Element).[P]A == (repeat (each Element).[P]A),
where on the left is type witness projection from the tuple conformance,
and on the right is a tuple with a pack expansion.
2023-09-07 00:47:00 -04:00
Kuba Mracek
25eb997a28 [embedded] Add basics of module serialization, importing and validation in embedded Swift.
- Add a flag to the serialized module (IsEmbeddedSwiftModule)
- Check on import that the mode matches (don't allow importing non-embedded module in embedded mode and vice versa)
- Drop TBD support, it's not expected to work in embedded Swift for now
- Drop auto-linking backdeploy libraries, it's not expected to backdeploy embedded Swift for now
- Drop prespecializations, not expected to work in embedded Swift for now
- Use CMO to serialize everything when emitting an embedded Swift module
- Change SILLinker to deserialize/import everything when importing an embedded Swift module
- Add an IR test for importing modules
- Add a deserialization validation test
2023-09-06 20:06:36 -07:00
Alexis Laferrière
125962cf0e Merge pull request #68336 from xymus/package-import-require-package
[Sema] Report uses of `package import` without defining a package name
2023-09-06 14:35:58 -07:00
Slava Pestov
e773f6881f Sema: Diagnose nested type in tuple extension 2023-09-05 23:21:27 -04:00
Slava Pestov
653c00ca07 Sema: More tuple conformance diagnostics 2023-09-05 23:21:27 -04:00
Slava Pestov
d5cdfb2cf2 AST: Clone generic parameter list of tuple extension from extended typealias 2023-09-05 23:21:27 -04:00
Alexis Laferrière
ea2465dea6 [Sema] Report uses of package import without a package name 2023-09-05 17:33:49 -07:00
Hamish Knight
6ee44f09b4 Introduce then statements
These allow multi-statement `if`/`switch` expression
branches that can produce a value at the end by
saying `then <expr>`. This is gated behind
`-enable-experimental-feature ThenStatements`
pending evolution discussion.
2023-09-01 14:32:14 +01:00
Doug Gregor
1c5dcb51fa Merge pull request #68154 from DougGregor/remark-macro-loading 2023-08-25 19:19:20 -07:00
Doug Gregor
339d31fabb [Macros] Add a frontend flag -Rmacro-loading to remark on macro resolution
Macro implementations can come from various locations associated with
different search paths. Add a frontend flag `-Rmacro-loading` to emit
a remark when each macro implementation module is resolved, providing
the kind of macro (shared library, executable, shared library loaded
via the plugin server) and appropriate paths. This allows one to tell
from the build load which macros are used.

Addresses rdar://110780311.
2023-08-25 15:09:49 -07:00
Doug Gregor
8ed1853b61 Ban the use of accessor macros on bindings with multiple variables
As with property wrappers, we can't properly desugar the application of
accessor macros to bindings with multiple variables. Prohibit them up
front.

Fixes rdar://112783811.
2023-08-23 06:24:48 -07:00
Luciano Almeida
76becb4cd0 [AST] Remove initializes and accesses attr reference 2023-08-22 20:54:37 -03:00
Alex Hoppen
baa20aec52 Merge pull request #67909 from nishithshah2211/imperative-fixits
[Diagnostics] Use imperative msg for protocol conformance & switch-case fixits
2023-08-21 14:40:21 -07:00
Sophia Poirier
aec59f2f9c Merge pull request #67974 from sophiapoirier/global-static-data-race-safety
enforce under strict concurrency that globals and statics be either…
2023-08-19 08:28:02 -07:00
Sophia Poirier
936ab20e5d enforce under strict concurrency that globals and statics be either isolated to a global actor or Sendable plus immutable
rdar://81629027 Global and static variable data-race safety
2023-08-18 15:08:42 -07:00
Mustafa Uzun
49fe1b870b fix: init_accessor_initializes_attribute_on_other_declaration error message typo 2023-08-18 14:36:57 +03:00
Doug Gregor
1d246629a4 Merge pull request #67998 from DougGregor/observer-macros-on-computed-properties
Improve checking of macro-generated accessors against documented names
2023-08-17 20:46:35 -07:00
Doug Gregor
5d6746d974 Improve checking of macro-generated accessors against documented names
The checking of the accessors generated by a macro against the
documented set of accessors for the macro is slightly too strict and
produces misleading error messages. Make the check slightly looser in
the case where an observer-producing macro (such as
`@ObservationIgnored`) is applied to a computed property. Here, we
would diagnose that the observer did not in fact produce any
observers, even though it couldn't have: computed properties don't get
observers. Remove the diagnostic in this case.

While here, add some tests and improve the wording of diagnostics a
bit.

Fixes rdar://113710199.
2023-08-17 16:59:42 -07:00
Pavel Yaskevich
c38b9b1e08 Merge pull request #67945 from xedin/remove-runtimeMetadata
[Frontend] NFC: Remove code and tests related to rejected @runtimeMetadata feature
2023-08-16 17:16:46 -07:00
Doug Gregor
b2f46ba26f Merge pull request #67957 from ktoso/wip-dont-use-loc-validness-in-diagnostics-determination-113913291
[Executors] Do not consider Loc validity in determining to emit error/warning about enqueue(_:)
2023-08-16 12:04:35 -07:00
Konrad `ktoso` Malawski
5e43ba9895 Don't trigger warnings about stdlib itself when user code might trigger them
The standard library's enqueue() does not play by the same rules -- we
provide "deprecated" implementations in  order to remain source/binary
compatible, and showing warnings about this when users make mistake will
only be misleading.
2023-08-16 22:22:37 +09:00
Becca Royal-Gordon
fa0e6285fc Merge pull request #67925 from beccadax/objcimpl-warning-main
Temporarily soften @objcImpl errors into warnings
2023-08-16 01:34:39 -07:00
Pavel Yaskevich
b21e8426a0 [AST] NFC: Remove @runtimeMetadata related code 2023-08-15 12:16:40 -07:00
Becca Royal-Gordon
ad960a1e2d Temporarily soften @objcImpl errors into warnings
Temporarily cherry-pick Swift 5.9’s behavior of turning @objcImplementation errors into warnings to 5.10 until we fix the last few bugs in these diagnostics.
2023-08-14 16:49:51 -07:00
Nishith Shah
8e2e625543 [Diagnostics] Use imperative msg for protocol conformance & switch-case fixits
This commit changes fixit messages from a question/suggestion to an
imperative message for protocol conformances and switch-case. Addresses
https://github.com/apple/swift/issues/67510.
2023-08-13 22:34:26 -07:00