Commit Graph

4105 Commits

Author SHA1 Message Date
Doug Gregor
2de9f4a8f5 [Strict safety] Stop complaining about unsafe signatures
Since we infer unsafety from a use of a declaration that involves unsafe types
in its signature, there isn't a reason to require @unsafe on declaration to
restate it. This matches recent revisions of SE-0458.
2025-02-15 22:02:22 -08:00
Becca Royal-Gordon
da07ff577c [PrintAsClang] Warn about unstable decl order
PrintAsClang is supposed to emit declarations in the same order regardless of the compiler’s internal state, but we have repeatedly found that our current criteria are inadequate, resulting in non-functionality-affecting changes to generated header content. Add a diagnostic that’s emitted when this happens soliciting a bug report.

Since there *should* be no cases where the compiler fails to order declarations, this diagnostic is never actually emitted. Instead, we test this change by enabling `-verify` on nearly all PrintAsClang tests to make sure they are unaffected.

This did demonstrate a missing criterion that only mattered in C++ mode: extensions that varied only in their generic signature were not sorted stably. Add a sort criterion for this.
2025-02-14 21:41:36 -08:00
Doug Gregor
654f8534bd Merge pull request #79399 from DougGregor/enable-span-everywhere
Enable usable of Span by default
2025-02-14 15:39:30 -08:00
Anthony Latsis
e8b393430f Merge pull request #78459 from AnthonyLatsis/tuber-magnatum-2
TypeCheckType: Unconditionally warn about missing existential `any` until Swift 7
2025-02-14 19:08:33 +00:00
Doug Gregor
3c8ef82963 Enable usable of Span by default
Usage of Span was temporarily behind an experimental feature flag. Now
that SE-0447 has been accepted, remove the experimental feature flag and
allow Span usage everywhere.

Implements rdar://144819992.
2025-02-14 10:45:47 -08:00
Doug Gregor
2989770cd6 Merge pull request #79352 from DougGregor/strict-sendable-metatypes
Add StrictSendableMetatypes to require Sendable requirements on metatypes
2025-02-14 03:40:36 -08:00
Doug Gregor
ed6dccf12c Diagnose captured of non-sendable metatypes crossing isolation boundaries
Keep track of all of the type parameters and archetypes that are captured
by a local function or closure. Use that information to diagnose cases
where a non-Sendable metatype crosses an isolation boundary.
2025-02-13 17:07:09 -08:00
Anthony Latsis
3222053810 AST: Add a diagnostic group for any syntax diagnostics
Allow users to escalate `any` syntax warnings to errors with
`-Werror ExistentialAny`.
2025-02-12 22:22:10 +00:00
Alejandro Alonso
e4fb1f6761 Rename Slab to InlineArray 2025-02-11 10:26:44 -08:00
Michael Gottesman
d33371a51a Merge pull request #79178 from xedin/execution-attr-in-type-context
[AST/Parse] Initial implementation of `@execution(concurrent | caller)` in type context
2025-02-06 18:44:00 -08:00
elsh
ee751835fc Package CMO: Skip deserialization error checks for same-module decls.
IterableDeclContext::checkDeserializeMemberErrorInPackage recursively checks if
decls and their member decls are deserialized correctly into another module.
This PR adds a check to make sure the inspected decls are from another module,
and provides an opt-in flag to fail fast on deserialization failure if found.

rdar://143830240
2025-02-05 14:27:00 -08:00
Pavel Yaskevich
aad858d66c [Sema] Implement validation of @execution(...) in type context 2025-02-05 10:11:38 -08:00
Doug Gregor
84ed66f3be Ensure that distributed functions with typed throws can be called from outside
When calling a distributed function for an actor that might not be local,
the call can throw due to the distributed actor system producing an
error. The function might, independently, also throw. When the
function uses typed throws, we incorrectly treated the call is if it
would always throw the error type specified by the function. This
leads to incorrectly accepting invalid code, and compiler crashes in
SILGen.

The change here is to always mark calls to distributed functions
outside the actor as "implicitly throwing", which makes sure that we
treat the call sites as throwing 'any Error'. The actual handling of
the typed throw (from the local function) and the untyped throw (from
the distributed actor system) occurs in thunk generation in SILGen,
and was already handled correctly.

Fixes rdar://144093249, and undoes the ban introduced by rdar://136467528
2025-02-04 16:06:51 -08:00
Allan Shortlidge
1e76f19be9 Sema: Reject version specs in @available attributes for custom domains. 2025-01-31 17:31:13 -08:00
Allan Shortlidge
5c61a2d53e Sema: Require experimental feature to use custom availability domains. 2025-01-31 17:31:13 -08:00
Konrad `ktoso` Malawski
dee96d9516 Merge pull request #78978 from ktoso/wip-fix-error-type-distributed-throws 2025-01-30 11:36:23 +00:00
Ellie Shin
997eab4410 Merge pull request #79019 from swiftlang/elsh/downgrade-to-warning
Package CMO: downgrade error to warning when checking for deserialization errors.
2025-01-29 23:30:17 -08:00
Michael Gottesman
37720323d2 Merge pull request #78997 from gottesmm/wire-up-execution
[concurrency] Wire up execution(concurrent)/execution(caller)
2025-01-29 16:53:11 -08:00
Michael Gottesman
28826b107c Remove some dead code and remove an unneeded comment. 2025-01-29 12:22:57 -08:00
elsh
4b6e0bf8d9 Package CMO: downgrade error to warning when checking for deserialization errors.
Binary module built with Package CMO can be loaded for package-external client
modules which do not have direct access to decls that are serialized_for_package.
Downgrade build-time error to warning when a deserialization error is found for
a decl that should be allowed to access by package-external clients resiliently.

rdar://143800032
2025-01-29 10:46:02 -08:00
Konrad `ktoso` Malawski
a65a669bdb Update DiagnosticsSema.def
Co-authored-by: Holly Borla <hborla@apple.com>
2025-01-29 17:31:35 +00:00
Anthony Latsis
eeb991122a [NFC] Switch from backticks to quotes in several diagnostics 2025-01-29 07:49:27 +00:00
Michael Gottesman
6a9afa53f7 [concurrency] Add back support for checking if we have a global actor/execution together. 2025-01-28 13:44:23 -08:00
Konrad `ktoso` Malawski
a2b3c488a7 [Distributed] ban typed throws in distributed funcs
They don't yield a correct error type as we didn't implement it, so
rather allow it and risk crashes, ban it until we get the time to
implement it.

The real solution is to adjust typed throws error inference to do an
union of the thrown error of the func and the type thrown by the
distributed actor system remote call -- which today always would be (E |
Error) -> Error...

We could add a new associated type to DAS and then we could make it more
proper...

resolves rdar://136467528
2025-01-28 17:07:21 +00:00
Slava Pestov
0c2887db5b Sema: Simplify CSApply for Double<->CGFloat conversion 2025-01-27 16:42:03 -05:00
Allan Shortlidge
bd79424039 Sema: Move domain-specific @available attr diagnostics to type checking.
Since the domain is now resolved by SemanticAvailableAttrRequest, diagnosing
attributes with invalid combinations of fields for a specific domains needs to
be delayed.
2025-01-26 13:50:56 -08:00
Doug Gregor
b3f2f00588 Suggest both @unsafe and @safe Fix-Its for unsafe types in signature 2025-01-23 07:47:19 -08:00
Artem Chikin
ea2c501131 Merge pull request #78672 from artemcm/DepScanInvalidRejectedBinaryModulesWarn
[Dependency Scanning] Emit a warning when failing to load a binary module of a non-resilient dependency
2025-01-22 15:03:43 -08:00
Anthony Latsis
499146df88 Merge pull request #78739 from AnthonyLatsis/hatzegopteryx
TypeCheckType: Rework IUO diagnostics using behavior limitation
2025-01-22 19:12:02 +00:00
Joe Groff
5d0fe0a156 Merge pull request #78705 from jckarter/explicit-conditional-invertible-extension-requirements
Require explicit statement of all `Copyable`/`Escapable` requirements for conditional `Copyable`/`Escapable` conformances.
2025-01-22 09:52:26 -08:00
Anthony Latsis
35f1370f6e TypeCheckType: Rework IUO diagnostics using behavior limitation
Also stop suggesting a '?' fix-it for casts, where it is not likely to
be helpful because the common intention is either to force the optional
or declare an IUO.
2025-01-21 21:41:00 +00:00
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
Pavel Yaskevich
c89ba5f58c [Sema] Diagnose clash between inferred global actor isolation and @execution(concurrent) 2025-01-17 15:40:01 -08:00
Pavel Yaskevich
b1e30b22b9 [Sema] Impliment initial validation of @execution(concurrent) attribute 2025-01-17 15:40:01 -08:00
Artem Chikin
550538f3b5 [Dependency Scanning] Emit a warning when failing to load a binary module of a non-resilient dependency
This failure will most-likely result in the dependency query failure which will fail the scan. It will be helpful if the scanner emitted diagnostic for each such module it rejected to explain the reason why.

Resolves rdar://142906530
2025-01-17 10:52:10 -08:00
Anthony Latsis
8dd7669816 Merge pull request #78592 from AnthonyLatsis/meganeura-monyi
Sema: Specify compatibility margin for `access_control_non_objc_open_member`
2025-01-14 20:52:08 +00:00
Anthony Latsis
e626887dcc Sema: Improve requirement indicator note for actor_isolated_witness
`x declared here` is not helpful and clear enough, especially when there
are other notes attached. Swap it for a new note that says
`requirement x declared here`.
2025-01-14 14:52:41 +00:00
Anthony Latsis
f85eb97337 ConformanceChecker: Make actor_isolated_witness call out the protocol 2025-01-14 14:49:22 +00:00
Alejandro Alonso
09d122af7c Merge pull request #76438 from Azoy/vector
[stdlib] Slab
2025-01-12 10:36:25 -08:00
Anthony Latsis
6a0834f2fc Sema: Minor improvements to access_control_non_objc_open_member message
* Use the '%kindonly' specifier.
* Make the object and its modifier agree on grammatical number.
* 'in extension' → 'declared in extension'.
2025-01-12 15:28:00 +00:00
Anthony Latsis
531ad28996 Sema: Specify compatibility margin for access_control_non_objc_open_member
This diagnostic was staged in
https://github.com/swiftlang/swift/pull/38991 as a warning to not break
source. Give it a reasonable margin and, in turn, convey that it is in
fact a compatibility warning and will become an error.
2025-01-12 03:03:49 +00:00
Doug Gregor
d6c020d843 Diagnose 'unsafe' within explicit references to types in expressions 2025-01-11 12:43:43 -08:00
Ellie Shin
727fb8c32d Merge pull request #78258 from swiftlang/elsh/disallow-bypass-deser-check
Package CMO: add deserialization checks to ensure correct memory layout
2025-01-11 05:40:49 -08:00
Doug Gregor
ede7bfe1e8 Merge pull request #78554 from DougGregor/unsafe-effect 2025-01-10 23:51:29 -08:00
Doug Gregor
1b7707d2cc Remove the now-unused @safe(unchecked) 2025-01-10 10:39:16 -08:00
Doug Gregor
8bb5bbedbc Implement an unsafe expression to cover uses of unsafe constructs
Introduce an `unsafe` expression akin to `try` and `await` that notes
that there are unsafe constructs in the expression to the right-hand
side. Extend the effects checker to also check for unsafety along with
throwing and async operations. This will result in diagnostics like
the following:

    10 |   func sum() -> Int {
    11 |     withUnsafeBufferPointer { buffer in
    12 |       let value = buffer[0]
       |                   |     `- note: reference to unsafe subscript 'subscript(_:)'
       |                   |- warning: expression uses unsafe constructs but is not marked with 'unsafe'
       |                   `- note: reference to parameter 'buffer' involves unsafe type 'UnsafeBufferPointer<Int>'
    13 |       tryWithP(X())
    14 |       return fastAdd(buffer.baseAddress, buffer.count)

These will come with a Fix-It that inserts `unsafe` into the proper
place. There's also a warning that appears when `unsafe` doesn't cover
any unsafe code, making it easier to clean up extraneous `unsafe`.

This approach requires that `@unsafe` be present on any declaration
that involves unsafe constructs within its signature. Outside of the
signature, the `unsafe` expression is used to identify unsafe code.
2025-01-10 10:39:14 -08:00
Doug Gregor
63c9882852 Introduce the notion of a warning that is ignored by default, but enabled by -Wwarning/-Werror
As an example, use this for the "`@preconcurrency` on import has no
effect" warning, which is not yet working correctly. This disables it
by default but leaves it in place for our testing.
2025-01-10 09:10:56 -08:00
Alejandro Alonso
f76d841540 Rename to Slab 2025-01-09 10:39:45 -08:00
Anthony Latsis
eb428bea31 Merge pull request #78398 from AnthonyLatsis/micronecta-scholtzi
DiagnosticEngine: Fix diagnostic groups behavior for wrapped diagnostics
2025-01-09 11:46:24 +00:00
Alejandro Alonso
61702fb813 Implement Vector literals 2025-01-08 10:35:55 -08:00