Commit Graph

42290 Commits

Author SHA1 Message Date
Michael Gottesman
1160951585 Merge pull request #75069 from gottesmm/pr-6b7256344bb1a1ceb9d13dae6d52db0d356b46a3
[region-isolation] Treat async let as a isolation inference boundary closure and fix diagnostics due to change.
2024-07-08 14:48:27 -07:00
Michael Gottesman
03b26fd65b [region-isolation] Treat async let as a isolation inference boundary closure and fix diagnostics due to change.
Otherwise, we will assume that an async let autoclosure infers isolation from
its DeclContext... which we do not want. An async let autoclosure should always
be nonisolated + sending.

The diagnostic change that I mentioned in the header is that we were emitting
unfortunate "sending task or actor isolated could result in races" error. I
eliminated this by adding a new diagnostic for transfer non transferrable errors
happening in autoclosures. So now we emit this:

```swift
  func asyncLetInferAsNonIsolated<T : Actor>(
    isolation actor: isolated T
  ) async throws {
    async let subTask: Void = {
      await useValueAsyncNoReturnWithInstance(self, actor)
      // expected-warning @-1:47 {{sending 'self' risks causing data races}}
      // expected-note @-2 {{sending 'actor'-isolated 'self' into async let risks causing data races between nonisolated and 'actor'-isolated uses}}
    }()
    await subTask
```

I also noticed that we did not have enough test cases for autoclosures in
general so I also added a bunch of tests just so we can see what the current
behavior is. I think there are a few issues therein (I believe some may have
been reported due to '??').

rdar://130151318
2024-07-08 11:22:29 -07:00
Michael Gottesman
20acc503c2 Fix three typos in comments. NFC. 2024-07-08 11:01:44 -07:00
Hamish Knight
e630f66952 Merge pull request #75046 from hamishknight/out-of-placeholder
[CS] Improve placeholder diagnostics slightly
2024-07-08 18:13:10 +01:00
Kavon Farvardin
591891f7d4 Merge pull request #74918 from kavon/availability-ncgenerics
NCGenerics: add availability checking
2024-07-08 09:00:43 -07:00
Erik Eckstein
1a308ef2fe PerformanceDiagnostic: give an error if a generic non-copyable value with a deinit is captured by an escaping closure.
Otherwise IRGen would crash.
It needs a bit of work to support alloc_box of generic non-copyable structs/enums with deinit, because we need to specialize the deinit functions, though they are not explicitly referenced in SIL.
Until this is supported, give an error in such cases.

Fixes a compiler crash in IRGen
rdar://130283111
2024-07-08 10:05:19 +02:00
eeckstein
47baa9fb6c Merge pull request #74767 from eeckstein/demangle-type-error-handling
Demangler: handle errors in `demangleType`
2024-07-08 08:38:45 +02:00
Hamish Knight
4beaaf32ad [CS] Improve placeholder diagnostics slightly
Make sure `CouldNotInferPlaceholderType` can
produce a diagnostic for a `PlaceholderType`
locator element, and avoid emitting an extra
diagnostic for a placeholder type in an invalid
position.
2024-07-07 23:42:33 +01:00
Kavon Farvardin
04454054b7 NCGenerics: add availability checking
Not all runtimes can correctly operate with types that use noncopyable
generics. When the generic argument of a type is noncopyable, old
runtimes can't recognize that to correctly check conformances that may
be conditional on those arguments being Copyable, etc.

resolves rdar://126239335
2024-07-07 15:38:00 -07:00
Michael Gottesman
9f8e5e8998 Merge pull request #75016 from gottesmm/pr-d4640c7e2919faea7bc7eb96ebd8af643108e2d8
[region-isolation] When determining isolation from a class_method, check for global actor isolation first.
2024-07-07 09:58:24 -07:00
Slava Pestov
bd2fcf34af Merge pull request #75015 from slavapestov/split-caching
Request evaluator split caching
2024-07-07 12:41:55 -04:00
Hamish Knight
156aef5a91 Merge pull request #75010 from hamishknight/elemental
[AST] Simplify construction of EnumElementPattern
2024-07-07 10:20:33 +01:00
Michael Gottesman
13dccdeaa5 Merge pull request #75017 from gottesmm/pr-a26b718d5903a343e7c02a0a64befda7e3781f6e
[region-isolation] Improve pattern matching for isolated parameters in SILIsolationInfo by reusing infrastructure from other parts of RegionAnalysis
2024-07-07 01:54:53 -07:00
Michael Gottesman
62c6de7713 [region-isolation] Reuse ActorInstance::lookThroughInsts when computing the actor instance for SILIsolationInfo purposes.
We are already using this routine in other parts of TransferNonSendable to
ensure that we look through common insts that SILGen inserts that do not change
the actual underlying actor instance that we are using. In this case, I added
support for casts, optional formation, optional extraction, existential ref
initialization.

As an example of where this came up is the following test case where we fail to
look through an init_existential_ref.

```swift
public actor MyActor {
  private var intDict: [Int: Int] = [:]

  public func test() async {
    await withTaskGroup(of: Void.self) { taskGroup in
      for (_, _) in intDict {}
      await taskGroup.waitForAll() // Isolation merge failure happens here
    }
  }
}
```

I also added the ability to at the SIL level actual test out this merge
condition using the analysis test runner. I used this to validate that this
functionality works as expected in a precise way.

rdar://130113744
2024-07-06 23:02:11 -07:00
Michael Gottesman
6129f4e833 [region-isolation] Print out SILIsolationInfo's options on all printing routines for SILIsolationInfo.
Before we wouldn't print them in all situations and even more so a few of the
printing routines did not have it at all. This just adds a centralized
SILIsolationInfo::dumpOptions() method and then goes through all of the printing
helpers and changes them to use them as appropriate.
2024-07-06 23:02:11 -07:00
Michael Gottesman
0c254807bf [region-isolation] Allow for unapplied isolated parameter ownership.
Given a function or a partial_apply with an isolated parameter, we do not know
immediately what the actual isolation is of the function or partial_apply since
we do not know which instance will be applied to the function or partial_apply.

In this commit, I introduce a new bit into SILIsolationInfo that tracks this
information upon construction and allows for it to merge with ownership that has
the appropriate type and a specific instance. Since the values that created the
two isolations, will be in the same region this should ensure that the value is
only ever in a flow sensitive manner in a region with only one actor instance
(since regions with isolations with differing actor instances are illegal).
2024-07-06 23:02:11 -07:00
Michael Gottesman
0a06c00f47 [region-isolation] When determining isolation from a class_method, check for global actor isolation first.
Before this change in the following code, we would say that message is isolated to the actor instead of the global actor isolation of the actor's method:

```swift
class Message { ... }

actor MessageHolder {
  @MainActor func hold(_ message: Message) { ... }
}

@MainActor
func sendMessage() async {
    let messageHolder = MessageHolder()
    let message = Message()
    // We identified messageHolder.hold as being MessageHolder isolated
    // instead of main actor isolated.
    messageHolder.hold(message)
    Task { @MainActor in print(message) }
}
```

I also used this as an opportunity to simplify the logic in this part of the
code. Specifically, I had made it so that multiple interesting cases were
handled in the same conditional statement in a manner that it made it hard to
know which cases were actually being handled and why it was correct. Now I split
that into two separate if statements with comments that make it clear what we
are actually trying to pattern match against.

rdar://130980933
2024-07-06 23:01:21 -07:00
Slava Pestov
4c7ca3ea72 Convert ApplyAccessNoteRequest to use separate caching 2024-07-06 23:36:00 -04:00
Slava Pestov
ec28d62d61 Convert AttachedPropertyWrappersRequest to use split caching 2024-07-06 23:36:00 -04:00
Slava Pestov
6489b60f8a Convert DynamicallyReplacedDeclRequest to use split caching 2024-07-06 23:36:00 -04:00
Slava Pestov
010ddfc816 Convert LifetimeDependenceInfoRequest to use split caching 2024-07-06 23:36:00 -04:00
Slava Pestov
0097ef68a6 Convert ActorIsolationRequest to use split caching 2024-07-06 23:36:00 -04:00
Slava Pestov
6b9267aaac Convert ExpandPeerMacroRequest to use split caching 2024-07-06 23:35:59 -04:00
Slava Pestov
edf8237df2 Convert SPIGroupsRequest to use split caching 2024-07-06 23:35:59 -04:00
Slava Pestov
80ddc3275f Convert PropertyWrapperAuxiliaryVariablesRequest to use split caching 2024-07-06 23:35:59 -04:00
Slava Pestov
9d163c4139 Convert GlobalActorAttributeRequest to use split caching 2024-07-06 23:35:59 -04:00
Slava Pestov
8a92c9cfc5 Convert ExpandMemberAttributeMacros to use split caching 2024-07-06 23:35:59 -04:00
Slava Pestov
7dc1328fad Basic: Introduce 'split caching' for requests 2024-07-06 23:35:46 -04:00
Slava Pestov
7ba2b76966 Basic: Add -analyze-request-evaluator flag to dump request cache statistics 2024-07-06 23:35:39 -04:00
Hamish Knight
fe68fab1e2 [AST] Simplify construction of EnumElementPattern
Add `EnumElementPattern::create` and
`EnumElementPattern::createImplicit`, and replace
existing constructions with them.
2024-07-06 22:56:30 +01:00
Slava Pestov
ab0ffe395b Merge pull request #74998 from slavapestov/global-conformance-lookup
AST: Stop pretending that conformance lookup takes the module into account
2024-07-06 17:26:46 -04:00
Hamish Knight
b9149e9ae0 Merge pull request #75009 from hamishknight/remove-disable-avail
[Sema] NFC: Remove `DisableExprAvailabilityChecking`
2024-07-06 20:16:42 +01:00
Slava Pestov
86d567f95a AST: ModuleDecl::lookupConformance() is a static method 2024-07-06 12:05:47 -04:00
Slava Pestov
e8d717bcd6 AST: Remove ModuleDecl parameter from checkRequirements() 2024-07-06 12:05:46 -04:00
Slava Pestov
1901862afc AST: Remove LookUpConformanceInSignature 2024-07-06 12:05:46 -04:00
Slava Pestov
fae01d9776 AST: Remove ModuleDecl parameter from more places 2024-07-06 12:05:46 -04:00
Slava Pestov
b7117aa877 AST: Start untangling ModuleDecl from conformance lookup 2024-07-06 12:05:45 -04:00
Hamish Knight
ee5df0041a [Sema] Remove DisableExprAvailabilityChecking 2024-07-06 16:20:21 +01:00
Andrew Trick
32ca35cb64 Fix SILBridging for GlobalAddr_getDecl
and RefElementAddr_getDecl.

Fixes:
Assertion failed: (isa<To>(Val) && "cast<Ty>() argument of incompatible type!"), function cast, file Casting.h

While running pass #224 SILFunctionTransform "LifetimeDependenceDiagnostics"
 #7 0x0000000102d3efcc decltype(auto) llvm::cast<swift::DebugValueInst, swift::SILInstruction>(swift::SILInstruction*)
 #8 0x0000000102d01e24 swift::DebugValueInst* BridgedInstruction::getAs<swift::DebugValueInst>() const
 #9 0x0000000102d01ee4 BridgedInstruction::GlobalAddr_getDecl() const
2024-07-05 12:00:07 -07:00
Erik Eckstein
7fe2befd31 Demangler: handle errors in demangleType
Makes sure that invalid runtime type strings result in errors and not fail silently.
In worst case this could lead to wrong reconstructed metatypes which can result in all kind of memory corruption.

relates to rdar://129861211
2024-07-05 11:37:15 +02:00
Hamish Knight
63e7c9380d Merge pull request #74890 from hamishknight/attr-etc
[Completion] Update type attribute completions
2024-07-04 17:57:15 +01:00
nate-chandler
04debd3536 Merge pull request #74922 from nate-chandler/lifetime-completion/20240701/1
[LifetimeCompletion] Flag ends synthesized in dead-ends.
2024-07-04 00:23:57 -07:00
Doug Gregor
e50beb0a46 Merge pull request #74962 from DougGregor/typed-throws-backdeploy-fixes
Typed throws backdeploy fixes
2024-07-04 00:12:52 -07:00
eeckstein
46256f5cd7 Merge pull request #74897 from eeckstein/fix-vtable-specializer
Fix a SourceKitCrash in the VTableSpecializer pass
2024-07-04 08:16:30 +02:00
Doug Gregor
21e5066249 Diagnose deployment constraints on type metadata involving typed throws
Fixes the rest of rdar://121530587.
2024-07-03 21:08:54 -07:00
Doug Gregor
9604019c87 Drop typed throws from the mangling in closure and field reflection metadata
This follows what we just did for `@isolated(any)` function types.

Part of rdar://130858222.
2024-07-03 20:14:01 -07:00
Pavel Yaskevich
17deda69eb [AST] NFC: Add a flag that allows matching to skip any Sendable and `& Sendable compositions 2024-07-03 20:02:11 -07:00
Artem Chikin
15dda6c9a7 Merge pull request #74945 from artemcm/FixCrossImportOnScannerValidatedBinaryModules
[Dependency Scanning] Resolve cross-import overlays relative to defining interface for prebuilt binary Swift dependencies
2024-07-03 18:03:23 -07:00
Nate Chandler
dd730b849c [LifetimeCompletion] Flag instructions dead_end. 2024-07-03 16:44:35 -07:00
Nate Chandler
d641dc65bf [UnreachableLifetimeCompletion] Keep ctor arg.
Don't drop the argument, use it to initialize the member.
2024-07-03 15:27:00 -07:00