Commit Graph

28382 Commits

Author SHA1 Message Date
Pavel Yaskevich
00fe5632d7 [TypeChecker] Downgrade noasync availability to warnings on @preconcurrency declarations
This change helps to stage in new `async` overloads in Swift 6 language mode
if `@preconcurrency` declaration is not available from async contexts.
2025-01-17 14:01:34 -08:00
Allan Shortlidge
87308e37f1 AST: Avoid creating duplicate AvailabilityScopes under SequenceExprs.
Since availability scopes may be built at arbitrary times, the builder may
encounter ASTs where SequenceExprs still exist and have not been folded, or it
may encounter folded SequenceExprs that have not been removed from the AST.

To avoid a double visit, track whether a SequenceExpr is folded and then
customize how ASTVisitor handles folded sequences.

Resolves rdar://142824799 and https://github.com/swiftlang/swift/issues/78567.
2025-01-17 10:21:22 -08:00
Michael Gottesman
2adc68b36b Merge pull request #78665 from gottesmm/pr-054dfe289af455d0471eefd8e16ff4496a45c2f9
[concurrency] Inherit caller isolation inheriting when inferring isolation from a nominal type context for a method on the nominal type.
2025-01-16 10:41:02 -08:00
Saleem Abdulrasool
0e77477147 Merge pull request #78553 from compnerd/well-known-imports
IRGen: further generalise runtime function generation
2025-01-16 09:25:54 -08:00
Slava Pestov
d1d2411bf3 Merge pull request #78267 from slavapestov/incremental-bindings-part-0
Sema: Some small cleanups in CSBindings.cpp and related code
2025-01-16 09:03:32 -05:00
Anthony Latsis
99c3802e02 Merge pull request #78669 from AnthonyLatsis/andromeda
[NFC] Add some unit tests for diagnostic behaviors
2025-01-16 06:30:56 +00:00
Slava Pestov
9a48fed9c7 Sema: Add BindingSet::operator==
This will be used for debugging.
2025-01-15 22:30:34 -05:00
Slava Pestov
bed95dd1a4 Sema: Simplify PotentialBindings updates a little 2025-01-15 22:30:34 -05:00
Slava Pestov
340a60b0b9 Sema: Add PotentialBindings::dump() and improve BindingSet::dump() 2025-01-15 22:30:33 -05:00
Slava Pestov
cfcc73f164 Sema: Add -solver-disable-splitter flag for debugging
We're not planning on removing the splitter because it is a big win
in some cases, but we want to run it less often since it can also
be a source of overhead. This flag allows us to compare performance
to understand the tradeoffs better.
2025-01-15 22:30:33 -05:00
Slava Pestov
1aff26eaa6 Sema: Store BindingSet inside the ConstraintGraphNode
Building the DenseMap in determineBestBindings() is extremely
expensive.

Also rename getCurrentBindings() to getPotentialBindings().
2025-01-15 22:30:32 -05:00
Anthony Latsis
87cf1179ff [NFC] Sema: Add Solution::getCalleeOverloadChoice 2025-01-16 02:35:26 +00:00
Michael Gottesman
26512720db [concurrency] Inherit caller isolation inheriting when inferring isolation from a nominal type context for a method on the nominal type.
rdar://142790025
2025-01-15 14:41:26 -08:00
Saleem Abdulrasool
ec70054c93 IRGen: further generalise runtime function generation
This adjusts the runtime function declaration handling to track the
owning module for the well known functions. This allows us to ensure
that we are able to properly identify if the symbol should be imported
or not when building the shared libraries. This will require a
subsequent tweak to allow for checking for static library linkage to
ensure that we do not mark the symbol as DLLImport when doing static
linking.
2025-01-15 13:54:34 -08:00
Chris Miles
73b184df24 Merge pull request #78564 from swiftlang/eng/chrismiles/playground-transform-crash-parsing-nested-generic-func
Fixes crash instrumenting generic func body nested in another func.

The crash was caused by attempting to add logging expressions that capture generic variables while using the outer func decl context that was not the generic decl context of the inner (generic) func.

The fix "pushes" the current func decl context while instrumenting the body. Rather than always using the top-level func decl context for all nested func bodies.
2025-01-15 10:05:25 -08:00
Pavel Yaskevich
1932d07fe7 Merge pull request #78650 from xedin/rdar-142567811
[Sema] Emit dynamic actor isolation checks for derived protocol witnesses
2025-01-15 09:39:01 -08:00
Pavel Yaskevich
a30bcffcac [Sema] Emit dynamic actor isolation checks for derived Codable protocol witnesses 2025-01-14 17:05:37 -08:00
Pavel Yaskevich
04fd5a2c2a [Sema] Emit dynamic actor isolation checks for derived Equatable/Hashable protocol witnesses 2025-01-14 17:05:31 -08:00
Pavel Yaskevich
f10a4819fd [Sema] NFC: Add a variant of addNonIsolatedToSynthesized that checks for @preconcurrency conformances
If derived conformance is marked as `@preconcurrency` instead of
marking synthesized members as `nonisolated` the compiler should
insert dynamic checks.
2025-01-14 15:44:57 -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
Chris Miles
f2846ce2cb Fixes crash while instrumenting generic func body embedded in another func.
The crash was caused by attempting to add logging expressions that capture generic variables while using the outer func decl context that was not the generic decl context of the inner (generic) func.

The fix "pushes" the current func decl context while instrumenting the body. Rather than always using the top-level func decl context for all nested func bodies.
2025-01-14 11:19:27 -08:00
Anthony Latsis
fba8095144 Merge pull request #78602 from AnthonyLatsis/gyromitra-esculenta
ConformanceChecker: Make `actor_isolated_witness` call out the protocol
2025-01-14 19:08:06 +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
Alexis Laferrière
aa75341b20 Sema: Accessors's SPI are tied to the attributes on the storage
Recent changes started using SPIGroupRequest on accessors specifically
to verify access to the wrappedValue of PropertyWrappers within the
direct access logic on variables using the property wrapper. Update
SPIGroupRequest to support this request and the type-checking logic to
accept the @_spi attribute on internal usable from inline accessors.

rdar://141964200
2025-01-13 17:02:40 -08:00
Slava Pestov
5f79319c45 Merge pull request #78559 from slavapestov/fix-rdar141968103
Sema: Relax primary associated type matching in matchExistentialTypes()
2025-01-13 12:04:57 -05:00
Pavel Yaskevich
84c7188219 Merge pull request #78526 from xedin/issue-78371
[CSOptimizer] Literal arguments should cause score reset only for operators
2025-01-13 08:59:36 -08:00
Alejandro Alonso
09d122af7c Merge pull request #76438 from Azoy/vector
[stdlib] Slab
2025-01-12 10:36:25 -08:00
Anthony Latsis
75953d2b51 OpenedExistentials: Do not attempt to erase existential metatypes with invariant Self
The non-metatype case was never supported. The same should hold for the
existential metatype case, which used to miscompile and now crashes
because the invariant reference is deemed OK but the erasure expectedly
fails to handle it:

```swift
class C<T> {}
protocol P {
  associatedtype A

  func f() -> any P & C<A>
  func fMeta() -> any (P & C<A>).Type
}

do {
  let p: any P
  let _ = p.f() // error
  let _ = p.fMeta() // crash
}
```
2025-01-12 17:47:52 +00: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
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