Commit Graph

26323 Commits

Author SHA1 Message Date
Alejandro Alonso
52e301e798 Fix isProtocolContext condition 2024-07-02 13:39:16 -07:00
Alejandro Alonso
11a9b1463d Update TypeCheckDeclPrimary.cpp 2024-07-02 10:46:16 -07:00
Alejandro Alonso
2f0750a450 Let protocols define getter requirements for @_staticExclusiveOnly types 2024-07-02 10:35:11 -07:00
Allan Shortlidge
7cadb0b4e3 Sema: Downgrade actor convenience initializer diagnostic to a warning in interfaces.
The `convenience` keyword is not accepted on actor initializers because the
compiler infers this status automatically and actors cannot be subclassed.
However, internally the compiler still computes whether an actor init is a
convenience init and this implicit status has been leaking through accidentally
in printed `.swiftinterface` files. This was noticed because in Swift 6 the
presence of the keyword is diagnosed as an error, making `.swiftinterface`
files unparseable for modules containing actors with convenience inits.

For Swift 6, I'm just going to suppress the error in `.swiftinterface` files
regardless of language mode. In future releases of the compiler, though, it can
stop printing the `convenience` keyword on these inits altogether, though.

Resolves rdar://130857256.
2024-07-02 08:31:23 -07:00
Ellie Shin
8e914d72a4 Merge pull request #74827 from swiftlang/elsh/no-pkg-name-interfaces
Option to disable printing package-name in public or private interface.
2024-07-01 01:22:45 -07:00
Adrian Prantl
0350023bb0 Merge pull request #74848 from adrian-prantl/112122752
Skip macro-expanded code in the playground transform.
2024-06-30 08:40:01 -07:00
Adrian Prantl
388bd6e5f4 Skip macro-expanded code in the playground transform.
Playgrounds cannot display any macro expansions anyway and the @Observable macro
can generate instrumentations that don't typecheck and/or reference missing
functions.

rdar://112122752
2024-06-29 16:04:23 -07:00
Greg Titus
8a40393287 Merge pull request #74692 from gregomni/adding-member
[Sema] Raise impact of DefineMemberBasedOnUse to match RemoveInvalidCall
2024-06-28 15:33:36 -07:00
Ellie Shin
e5b4655108 Option to disable printing package-name in public or private interface.
Having package-name flag in non-package interfaces causes them to be built as if
belonging to a package, which causes an issue for a loading client outside of the
package as follows.

For example, when building X that depends on A with the following dependency chain:
  X --> A --> B --(package-only)--> C

1. X itself is not in the same package as A, B, and C.
2. When dependency scanning X, and opening up B, because the scan target is in a
   different package domain, the scanner decides that B's package-only dependency
   on C is to be ignored.
3. When then finally building A itself, it will load its dependencies, but because
   the .private.swiftinterface of A still specifies -package-name, when it loads
   B, it will then examine its dependencies and deem that this package-only dependency
   on C is required.

Because (2) and (3) disagree, we get an error now when building the private A textual interface.

rdar://130701866
2024-06-28 15:06:21 -07:00
Ben Barham
d8f381e660 Merge pull request #74804 from bnbarham/rename-equals
Update `StringRef::equals` references to `operator==`
2024-06-28 11:22:20 -07:00
Slava Pestov
a451523e00 Merge pull request #74800 from slavapestov/fix-rdar127575477
Sema: Fix incorrect use of STL iterator in associated type inference
2024-06-27 22:38:26 -04:00
Ben Barham
d72f5b12c4 Update StringRef::equals references to operator==
`equals` has been deprecated upstream, use `operator==` instead.
2024-06-27 19:14:06 -07:00
Allan Shortlidge
4457ad6263 Merge pull request #74793 from tshortli/subscript-setter-availability
Sema: Fix accessor availability checking in argument lists
2024-06-27 16:13:14 -07:00
Steven Wu
39cb996bb8 Merge pull request #73421 from cachemeifyoucan/eng/PR-127116512
[ScanDependencies] Get accurate macro dependency
2024-06-27 16:06:53 -07:00
Slava Pestov
005d83f8d2 Sema: Fix incorrect use of STL iterator in associated type inference
Fixes rdar://problem/127575477.
2024-06-27 18:21:14 -04:00
Allan Shortlidge
0dbbb68171 Sema: Fix accessor availability checking in argument lists.
The changes in https://github.com/apple/swift/pull/72410 caused a regression
when checking availability in the following example:

```
// warning: Setter for 'hasDeprecatedSetter' is deprecated: ...
x[y.hasDeprecatedSetter] = ...
```

The result of `y.hasDeprecatedSetter` is being passed as an argument to the
subscript and its setter will not be called. To fix this,
`ExprAvailabilityWalker` now consistently creates a new default
`MemberAccessContext` when descending into any `Argument`, since the access
context for the expressions surrounding the call should not affect the
arguments to the call.

Additionally, `MemberAccessContext` has been refactored to better model context
state transitions. Instead of only modeling which accessors will be called, the
enumeration's members now reflect the possible states that
`ExprAvailabilityWalker` can be in during its traversal. This should hopefully
make it easier to follow the logic for traversal of `LoadExpr`s and arguments.

Resolves rdar://130487998.
2024-06-27 11:13:52 -07:00
Steven Wu
4125e8c3cd [ScanDependencies] Get accurate macro dependency
Build an accurate macro dependency for swift caching. Specifically, do
not include not used macro plugins into the dependency, which might
cause false negatives for cache hits.

This also builds the foundation for future improvement when dependency
scanning will determine the macro plugin to load and swift-frontend do
not need to redo the work.

rdar://127116512
2024-06-27 10:45:14 -07:00
Akira Hatanaka
42bc49d3fe Add a new parameter convention @in_cxx for non-trivial C++ classes that are passed indirectly and destructed by the caller (#73019)
This corresponds to the parameter-passing convention of the Itanium C++
ABI, in which the argument is passed indirectly and possibly modified,
but not destroyed, by the callee.

@in_cxx is handled the same way as @in in callers and @in_guaranteed in
callees. OwnershipModelEliminator emits the call to destroy_addr that is
needed to destroy the argument in the caller.

rdar://122707697
2024-06-27 09:44:04 -07:00
Kavon Farvardin
e3a5d13a75 Merge pull request #74743 from kavon/perform-inference-in-interfaces
NCGenerics: add workaround for rev. condfail
2024-06-26 20:36:14 -07:00
Kavon Farvardin
1e2111afca NCGenerics: add flag to opt-out SE-427 strictness
This is mainly for tests to avoid the reverse condfail.
2024-06-26 17:10:33 -07:00
Becca Royal-Gordon
e701223556 Merge pull request #74719 from beccadax/objcimpl-is-incomplete
Support nil completions in @objcImpl async methods
2024-06-26 14:23:04 -07:00
Hamish Knight
3c6b0bde9a Merge pull request #74680 from hamishknight/confirmance
[Sema] Pass down ProtocolConformance to DerivedConformance
2024-06-26 20:12:57 +01:00
Kavon Farvardin
baabaa022f NCGenerics: add workaround for rev. condfail
resolves rdar://130424971
2024-06-26 11:43:52 -07:00
Allan Shortlidge
8dbcd11344 Merge pull request #74690 from tshortli/accessor-availability-reference-types
Sema: Suppress set accessor availability diagnostics in `LoadExpr`s
2024-06-26 07:53:13 -07:00
Rintaro Ishizaki
5ebd715a2a Merge pull request #73725 from rintaro/macros-inproc-plugin
[Macros] In-process plugin server
2024-06-26 06:33:38 -07:00
Becca Royal-Gordon
01a90cc99b Support nil completions in @objcImpl async methods
An async @objc method only checks if its completion handler parameter is null if ClangImporter forces it to. This is fine for @objc with a generated header, because the generated header always declares the parameter _Nonnull, but clients ignore that annotation and pass nil anyway often enough that for @objc @implementation, we ought to be defensive.

We can achieve this by simply making the completion handler’s type Optional—SILGen already looks for this and knows what to do when it sees it.

Fixes rdar://130527373.
2024-06-25 20:36:41 -07:00
Kavon Farvardin
4b98498bf2 Merge pull request #74672 from kavon/post-vacation-misc-cleanups
Handful of small NoncopyableGenerics fixes / cleanups.
2024-06-25 18:35:40 -07:00
Kavon Farvardin
05f5e511fc Diags: say "actors" cannot be ~Copyable
rdar://130450351
2024-06-25 12:06:22 -07:00
Greg Titus
50333b6104 Raise impact of DefineMemberBasedOnUse to 4, lower RemoveInvalidCall to 3. 2024-06-25 11:29:24 -07:00
Allan Shortlidge
31df22f5ec Sema: A LoadExpr enclosing a call does not affect the arguments.
Fixes missing setter availability diagnostics in some edge cases.
2024-06-25 11:08:20 -07:00
Michael Gottesman
56cb980540 Merge pull request #74564 from gottesmm/pr-9be87019f95149167c2e03043b7a86b82f9d282c
Follow up fixes with feedback from #74129
2024-06-25 10:24:26 -07:00
Allan Shortlidge
6e16075692 Sema: Suppress set accessor availability diagnostics in LoadExprs.
This fixes a regression from https://github.com/swiftlang/swift/pull/72369.
The compiler now incorrectly diagnoses use of an unavailable setter in this
example:

```
func increaseBrightness(in window: UIWindow) {
  // warning: setter for 'screen' was deprecated in iOS 13.0
  window.screen.brightness = 1.0
}
```

While the setter is deprecated, it would not be called in the generated code
since `screen` is a reference type and there is no writeback through the setter
for `screen` after setting `brightness`.

Resolves rdar://129679658
2024-06-25 09:20:34 -07:00
Hamish Knight
742922296e [Sema] Remove an isInvalid check
This check was added in 38e305cfdc,
and was used to detect whether there may be
something invalid about the members that were
necessary for conformance derivation. However this
is no longer the case, a nominal should only ever
be marked invalid these days if it is either in an
unsupported DeclContext, or it's a redeclaration.
The synthesis logic ought to be resilient against
invalid members.

Additionally, this check wasn't even necessarily
looking at the nominal, it could have been
looking at an ExtensionDecl. In that case, we could
have still attempted to synthesize with invalid
members. As such, it seems unlikely this check is
providing any real benefit, let's remove it.
2024-06-25 11:36:22 +01:00
Hamish Knight
5e95ae6867 [Sema] Pass down ProtocolConformance to DerivedConformance
Previously `getHashableConformance` was attempting
to find the conformance itself, which could fail
(rdar://129620291). Instead, pass down the
known protocol conformance that we're deriving
a witness for. No test case unfortunately as I
haven't been able to come up with a reproducer.

rdar://129620291
2024-06-25 11:36:22 +01:00
Hamish Knight
9b313488fa [Sema] NFC: Remove unused declaration
`deriveProtocolRequirement` is no longer a
member on `TypeChecker`, it's static.
2024-06-25 11:36:21 +01:00
Hamish Knight
c9f1707be9 [Sema] NFC: Remove a redundant call to getASTContext
We already have the ASTContext on this type.
2024-06-25 11:36:21 +01:00
Kavon Farvardin
80c99973d7 NFC: introduce isAddingConformanceToInvertible
Removes duplicated code between Sema and the ASTPrinter.
2024-06-24 15:34:58 -07:00
Michael Gottesman
112071e57d [sending] Remove transferring.
Out of an abundance of caution, we:

1. Left in parsing support for transferring but internally made it rely on the
internals of sending.

2. Added a warning to tell people that transferring was going to
be removed very soon.

Now that we have given people some time, remove support for parsing
transferring.

rdar://130253724
2024-06-21 16:03:21 -07:00
Michael Gottesman
74944a69bd Merge pull request #74239 from gottesmm/taskinit-sending
[sending] Mark Task.init, Task.detached and friends as taking a sending closure instead of a __owned @Sendable
2024-06-21 10:36:29 -07:00
Mishal Shah
4afac731d9 Merge pull request #74614 from xedin/concurrency-incorrect-placement-of-static-property-error
[Concurrency] Don't attempt to diagnose `GlobalConcurrency` issues wi…
2024-06-21 10:07:15 -07:00
Holly Borla
678d41a6d9 Merge pull request #74607 from hborla/isolation-from-superclass-requirement
[Concurrency] Infer protocol isolation from superclass requirements.
2024-06-21 08:30:11 -07:00
Michael Gottesman
d54e6ba25d [sending] Just like @Sendable, sending stops isolation inference along DeclContexts.
Without this, we were hitting weird behaviors in flow_isolation.swift only when
compiling in Swift 5 mode.

Consider the following example:

```
func fakeTask(@_inheritActorContext _ x: sending @escaping () async -> ()) {}

actor MyActor {
    var x: Int = 5
    var y: Int = 6
    var hax: MyActor? = nil

    init() {
        fakeTask {
            // Warning! You can remove await
            // Error! Cannot access actor state in nonisolated closure.
            _ = await self.hax
        }
    }
}
```

The reason why this was happening is that we were not understanding that the
closure passed to fakeTask is not part of the init and has different isolation
from the init (it is nonisolated but does not have access to the init's state).
This then caused us to exit early and not properly process the isolation
crossing point there.

Now, we properly understand that a sending inheritActorContext closure (just
like an @Sendable closure) has this property in actor initializers.
2024-06-21 02:24:03 -07:00
Michael Gottesman
ca6cde65c4 Remove an unneeded function parameter by inlining its body.
There is only one call site of this helper function, so we are not gaining any
flexibility by doing this. It only makes it harder to reason about what the
function actually does without providing any benefit.

I am doing this before I make in the next commit an actual semantic changing
commit to ease review.
2024-06-21 02:24:03 -07:00
Michael Gottesman
5e27999b09 [sending] Rename Sema level APIs from isSendingParameter -> isPassedToSendingParameter.
This came up while I was talking with @xedin. This name makes
it really clear what we are trying to communicate to the author.
2024-06-21 02:24:03 -07:00
Michael Gottesman
3f39bdc1ed [sending] closure literals that are passed as sending parameters are now inferred to be nonisolated.
Consider the following piece of code and what the isolation is of the closure
literal passed to doSomething():

```swift
func doSomething(_ f: sending () -> ()) { ... }

@MyCustomActor
func foo() async {
  doSomething {
    // What is the isolation here?
  }
}
```

In this case, the isolation of the closure is @MyCustomActor. This is because
non-Sendable closures are by default isolated to their current context (in this
case @MyCustomActor since foo is @MyCustomActor isolated). This is a problem
since

1. Our closure is a synchronous function that does not have the ability to hop
to MyCustomActor to run said code. This could result in a concurrency hole
caused by running the closure in doSomething() without hopping to
MyCustomActor's executor.

2. In Region Based Isolation, a closure that is actor isolated cannot be sent,
so we would immediately hit a region isolation error.

To fix this issue, by default, if a closure literal is passed as a sending
parameter, we make its isolation nonisolated. This ensures that it is
disconnected and can be transferred safely.

In the case of an async closure literal, we follow the same semantics, but we
add an additional wrinkle: we keep support of inheritActorIsolation. If one
marks an async closure literal with inheritActorIsolation, we allow for it to be
passed as a sendable parameter since it is actually Sendable under the hood.
2024-06-21 02:24:03 -07:00
Michael Gottesman
4d7af7be25 [sending] Make sending a no escape closure a default rather than consuming parameter
The reason why I am doing this is that:

1. We don't support no escaping closure parameters today and would like
   to leave the design space open.

2. These closures are bitwise copyable/trivial so marking them as
   specifically consuming doesn't really make sense.
2024-06-21 02:24:03 -07:00
Pavel Yaskevich
aae15c33d4 [Concurrency] Don't attempt to diagnose GlobalConcurrency issues with deserialized variable/properties
If the property comes from a different module the compiler shouldn't
attempt to diagnose `GlobalIsolation` problems based in the current
module flags otherwise it would create issues when i.e. a variable/property
from a module built with `-swift-version 5` that gets referenced
by a module that is built with `-swift-version 6` that has stricter
local concurrency requirements.

See https://forums.swift.org/t/swift-6-language-mode-being-passed-to-dependencies/72622
for further discussion.

A better solution would be to move the check to `ActorIsolationChecker`
or `DeclChecker` but that would be too risky for 6.0.
2024-06-21 00:23:09 -07:00
Holly Borla
13f0c0c953 [Concurrency] Infer protocol isolation from superclass requirements.
Actor isolation on protocols was already inferred from inherited protocols,
but we were missing inference from a required superclass.
2024-06-20 21:24:52 -07:00
Slava Pestov
3a91280f08 Sema: Diagnose 'lazy' variable initializer with effect
This used to crash in SILGen.

Fixes https://github.com/apple/swift/issues/60128
Fixes https://github.com/apple/swift/issues/60129
2024-06-20 21:34:54 -04:00
Hamish Knight
23a85d19ed Merge pull request #74387 from hamishknight/pattern-resolution
[Sema] Requestify pattern resolution
2024-06-20 21:07:07 +01:00