Commit Graph

28352 Commits

Author SHA1 Message Date
Doug Gregor
ff2ef7a2e2 Ensure that the effects checker understands what declaration references are evaluated 2025-01-11 22:38:26 -08: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
a0ebd87731 Remove unused tracking of unsafe uses in the effects checker
We track this information via anchor, so we don't need to manage a
separate list that doesn't have an anchor.
2025-01-11 12:43:48 -08:00
Doug Gregor
2fc9ac08ca Handle autoclosures for 'unsafe' effects checking 2025-01-11 12:43:43 -08:00
Doug Gregor
fc632b2c53 Check 'unsafe' within keypaths 2025-01-11 12:43:43 -08:00
Doug Gregor
d6c020d843 Diagnose 'unsafe' within explicit references to types in expressions 2025-01-11 12:43:43 -08:00
Doug Gregor
446474499a Diagnose unsafe sequences in the for..in loop
The `unsafe` goes on the sequence expression, e.g.,

    for x in unsafe mySequence { ... }
2025-01-11 12:43:42 -08:00
Doug Gregor
d787c0fab3 Extend effects checking to the various expressions that reference declarations
Only "unsafe" checking is affected here.
2025-01-11 12:43:42 -08:00
Doug Gregor
16b0538f47 Generalize declaration-reference checking in the effects checker 2025-01-11 12:43:41 -08:00
Doug Gregor
37bfa1998e Tighten up checking for uses of unsafe conformances
Check for unsafe conformances for type erasure and opaque type
erasure.

This also uncovered an issue where we were making every conformance of
an unsafe type to an unsafe protocol @unsafe implicitly, even though
that's not really what we want.
2025-01-11 12:43:41 -08:00
Hamish Knight
ee6652dd3c Merge pull request #78545 from hamishknight/warn-misc-macro-arg
[Sema] Downgrade implicit self diag to warning for macro args
2025-01-11 10:56:38 +00:00
Allan Shortlidge
393ad9872a Merge pull request #78541 from tshortli/available-attr-remodel
AST: Refactor `AvailableAttr` representation to use `AvailabilityDomain`
2025-01-11 02:39:27 -08:00
Doug Gregor
ede7bfe1e8 Merge pull request #78554 from DougGregor/unsafe-effect 2025-01-10 23:51:29 -08:00
Allan Shortlidge
86ea1ae775 AST: Introduce a Kind enum and new constructor for AvailableAttr.
AvailableAttr::Kind and AvailabilityDomain are designed to replace
PlatformAgnosticAvailabilityKind, allowing AvailableAttr to more flexibly model
availability for arbitrary domains. For now, the new constructor just
translates its inputs into inputs for the existing constructor. Once all of the
callers of the existing AvailableAttr constructor have been updated to use the
new constructor, the representation of AvailableAttr will be updated to store
the new properties.
2025-01-10 18:43:12 -08:00
Pavel Yaskevich
092018674c Merge pull request #78535 from xedin/rdar-142562250
[Sema] Look through `ActorIsolationErasureExpr` when finding function…
2025-01-10 15:06:12 -08:00
Slava Pestov
c257cdbc7c Sema: Relax primary associated type matching in matchExistentialTypes()
Recently I found a soundness hole here, where we would allow conversion
between `any P<T>` and `any Q<T>` even if P and Q have different primary
associated types.

However, the fix was too strict, because we still want to allow the
conversion when the associated types have the same name.

Fixes rdar://141968103.
2025-01-10 15:37:10 -05:00
Doug Gregor
1b7707d2cc Remove the now-unused @safe(unchecked) 2025-01-10 10:39:16 -08:00
Doug Gregor
c043f1138b Drop the "allows unsafe" modeling as availability
With the move to unsafe effects, we no longer model `unsafe` as an
availability problem. Remove all of that supporting code.
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
Pavel Yaskevich
f9d34984c6 [Sema] Look through ActorIsolationErasureExpr when finding function DeclRefs for rethrows checking.
This conversion has no effect on `rethrows` checking and should
be ignored.

Resolves: rdar://142562250
2025-01-10 09:04:50 -08:00
Hamish Knight
34f809055a [Sema] Downgrade implicit self diag to warning for macro args
We previously missed diagnosing this for macro
args, fixing it turned out to be a bit more source
breaking than initially thought though, so downgrade
to a warning until Swift 7.

rdar://141963700
2025-01-10 14:36:29 +00:00
Hamish Knight
fd4c86f8f5 [Sema] NFC: Move walker out of diagnoseImplicitSelfUseInClosure
I need to add a method with a template, and C++
doesn't support that in local classes.
2025-01-10 14:36:29 +00:00
Pavel Yaskevich
e3987beffb [CSOptimizer] Literal arguments should cause score reset only for operators
Resetting score to `0.1` is intended to make sure that the
solver picks the outermost disjunction in literal chains like
`1 + 2 + 3 ...` because that would provide context to the
inner choices.

Resolves: https://github.com/swiftlang/swift/issues/78371
Resolves: rdar://142105691
2025-01-09 11:28:24 -08:00
Alejandro Alonso
f76d841540 Rename to Slab 2025-01-09 10:39:45 -08:00
Pavel Yaskevich
6c82892c3c [CSOptimizer] NFC: check whether a choice is of operator instead of whole disjunction 2025-01-09 10:39:18 -08:00
Allan Shortlidge
70a2363b97 AST: Introduce new conveniences for synthesizing AvailabilityAttrs.
This makes intent clearer at the call site and removes a lot of explicit uses
of PlatformAgnosticAvailabilityKind, which is going away.
2025-01-08 19:59:47 -08:00
Slava Pestov
c12e0a1e8f Merge pull request #78470 from slavapestov/fix-rdar141961300
Sema: Fix local property wrappers on constructor
2025-01-08 21:33:12 -05:00
Slava Pestov
df8a4c84a8 Merge pull request #78468 from slavapestov/fix-141967932
Sema: Don't remove nonisolated attribute when we diagnose it as invalid on 'lazy'
2025-01-08 18:27:40 -05:00
Doug Gregor
9bd48e0177 Merge pull request #78491 from DougGregor/strict-safety-more-cases
Strict safety more cases
2025-01-08 13:49:46 -08:00
Allan Shortlidge
9df531a1bd Merge pull request #78485 from tshortli/adopt-semantic-available-attr-part-3
AST: Remove most platform queries from `AvailableAttr`
2025-01-08 12:34:17 -08:00
Slava Pestov
c17044381e Sema: Fix local property wrappers on constructor
Fixes rdar://problem/142443421.
2025-01-08 14:31:12 -05:00
Slava Pestov
cc2048764a Sema: Clean up local property wrapper bookkeeping 2025-01-08 14:31:12 -05:00
Alejandro Alonso
61702fb813 Implement Vector literals 2025-01-08 10:35:55 -08:00
Pavel Yaskevich
8f7e71aa97 Merge pull request #78487 from xedin/Sendable-to-Any-for-lvalues
[CSApply] Sendable-to-Any: Add support for l-value to l-value and inout unsafe casts
2025-01-08 09:57:02 -08:00
Allan Shortlidge
9edd9eed9e AST: Finish adopting SemanticAvailableAttr in AvailabilityInference utilities. 2025-01-08 08:17:27 -08:00
Allan Shortlidge
05d342eb98 AST: Remove AvailableAttr::hasPlatform().
Use SemanticAvailableAttr::isPlatformSpecific() instead.
2025-01-08 08:17:27 -08:00
Allan Shortlidge
5058534805 AST: Remove AvailableAttr::prettyPlatformString(). 2025-01-08 08:17:27 -08:00
Allan Shortlidge
c2e8e3060e AST: Remove AvailableAttr::isActivePlatform(). 2025-01-08 08:17:26 -08:00
Doug Gregor
6855dc474f Uses of @exclusivity(unsafe) variables are unsafe 2025-01-08 07:03:04 -08:00
Slava Pestov
e663ad0cbd Sema: Don't remove nonisolated attribute when we diagnose it as invalid on 'lazy'
Otherwise, we'll in turn complain if the nonisolated lazy property was
@objc. This is also invalid, but the goal here is to avoid the source
break until -swift-version 6.

Fixes rdar://141967932.
2025-01-07 23:33:47 -05:00
Pavel Yaskevich
0a0a34c853 [CSApply] Add support for l-value to l-value and inout unsafe casts
`any Sendable` -> `Any` in generic argument positions should be
supported for l-value and inout types as well otherwise it won't
be possible to call setters and mutating methods.
2025-01-07 17:21:33 -08:00
Pavel Yaskevich
79f6b07961 [CSApply] Mark self parameter as inout when base/self match on deep equality
If type equality check fails we need to check whether the types
are the same with deep equality restriction since `any Sendable`
to `Any` conversion is now supported in generic argument positions
of @preconcurrency declarations. i.e. referencing a member on
`[any Sendable]` if member declared in an extension that expects
`Element` to be equal to `Any`.
2025-01-07 10:55:04 -08:00
Allan Shortlidge
f58a269512 Sema: Adopt SemanticAvailableAttr more thoroughly in TypeCheckConcurrency.cpp. 2025-01-07 07:31:29 -08:00
Allan Shortlidge
e719d71439 Sema: Adopt SemanticAvailableAttr more thoroughly in unavailability diagnostics. 2025-01-07 07:31:29 -08:00
Allan Shortlidge
c76c63712c Sema: Adopt SemanticAvailableAttr in ExprAvailabilityWalker. 2025-01-07 07:31:13 -08:00
Allan Shortlidge
a4203ed508 Sema: Adopt SemanticAvailableAttr in override availability checking. 2025-01-07 07:31:13 -08:00
Allan Shortlidge
7eb5323a31 Sema: Adopt SemanticAvailableAttr in deprecation diagnostics. 2025-01-07 07:31:13 -08:00
Allan Shortlidge
dcfe563294 AST: Remove AvailabilityInference::availableRangeAndAttr() 2025-01-07 07:31:13 -08:00
Allan Shortlidge
efa1afff11 AST: Introduce SemanticAvailableAttr::getIntroducedRange().
It replaces the overload of AvailabilityInference::availableRange() that takes
an AvailableAttr.
2025-01-07 07:31:12 -08:00
Allan Shortlidge
f1d0885458 AST: Adopt SemanticAvailableAttr in AvailabilityConstraint. 2025-01-07 07:31:12 -08:00