Commit Graph

2864 Commits

Author SHA1 Message Date
Michael Gottesman
083b10a879 Merge pull request #75963 from gottesmm/pr-fb279661a394bc36c6aea28f928d0c7e3adfdea4
[region-isolation] Tweak the logging to make it easier to quickly find the emitted error when triaging code.
2024-08-19 16:17:51 -07:00
Michael Gottesman
a36b3749dc [region-isolation] Tweak the logging to make it easier to quickly find the emitted error when triaging code.
Just trying to improve my triaging speed by making it easier to triage.
2024-08-19 12:25:54 -07:00
Michael Gottesman
03713498f7 Merge pull request #75873 from gottesmm/pr-6c64f2f0a43f93b59babd44b8bac2c396a039e2f
[region-isolation] Improve the error we emit for closure literals captured as a sending parameter.
2024-08-15 17:03:52 -07:00
Michael Gottesman
4bb2e4f3b1 [region-isolation] Improve the error we emit for closure literals captured as a sending parameter.
Specifically:

I changed the main error message to focus on the closure and that the closure
is being accessed concurrently.

If we find that we captured a value that is the actual isolation source, we
emit that the capture is actually actor isolated.

If the captured value is in the same region as the isolated value but is not
isolated, we instead say that the value is accessible from *-isolated code or
code within the current task.

If we find multiple captures and we do not which is the actual value that was
in the same region before we formed the partial apply, we just emit a note on
the captures saying that the closure captures the value.

I changed the diagnostics from using the phrase "task-isolated" to use some
variant of accessible to code in the current task.

The idea is that in all situations we provide a breadcrumb that the user can
start investigating rather than just saying that the closure is "task-isolated".

From a preconcurrency perspective, I made it so that we apply the preconcurrency
behavior of all of the captures. This means that if one of the captures is
preconcurrency, we apply the preconcurrency restriction to the closure. This is
one step towards making it so that preconcurrency applies at the region level...
we just are not completely there yet.

rdar://133798044
2024-08-14 10:37:31 -07:00
Kuba (Brecka) Mracek
2941f24da3 Merge pull request #75308 from kubamracek/embedded-indexing-non-wmo
[embedded] Don't produce PerfDiags when in non-WMO mode (e.g. when building during indexing)
2024-08-12 23:29:30 -07:00
Michael Gottesman
fd863f90e8 Merge pull request #75841 from gottesmm/pr-4c4ea8453f92202322e4254fa1156e77a0716bc3
[region-isolation] Improve debug logging
2024-08-12 15:04:39 -07:00
Michael Gottesman
8a20df1c44 [region-isolation] When dumping send never-sendable errors, dump the isolated value and its name if we can compute it.
This just makes it quicker/easier to diagnose inability to infer the appropriate
name of an isolated value and what the isolated value itself is.
2024-08-12 11:35:57 -07:00
Michael Gottesman
2535ef0c87 [region-isolation] When dumping info for send never sendable, dump the full one line logging of the isolation instead of just the diagnostics. 2024-08-12 11:35:57 -07:00
Kuba Mracek
80056c15cd [embedded] Explicitly disable PerfDiags from SourceKit instead of always disabling when WMO is off 2024-08-10 14:50:22 -07:00
Kuba Mracek
3ad777b942 [embedded] Don't produce PerfDiags when in non-WMO mode (e.g. when building during indexing) 2024-08-10 14:48:24 -07:00
Slava Pestov
375363a473 AST: Move global conformance lookup entry points to ConformanceLookup.h 2024-08-08 23:35:58 -04:00
Michael Gottesman
1fbc930cdd [region-isolation] Make logging and debug tooling appear in non-asserts builds.
This will just help me to more quickly triage without needing to compile an
asserts compiler.
2024-08-07 13:35:18 -07:00
Holly Borla
0ccbc7b4e6 Merge pull request #75705 from hborla/isolated-property-init-note
[Concurrency] Emit a better note when an isolated stored property initializer cannot be used.
2024-08-06 06:54:43 -07:00
Holly Borla
34cc7ea081 [Concurrency] Emit a better note when an isolated stored property initializer
cannot be used in an init with mismatching isolation.
2024-08-05 18:38:44 -07:00
Michael Gottesman
9c4da1ffb6 Merge pull request #75597 from gottesmm/incremental-diagnostics
[region-isolation] Incremental diagnostic updates
2024-08-02 15:10:34 -07:00
Michael Gottesman
7255281c1d [region-isolation] Use a hard to use API correctly.
Specifically, this API has some hard edges where instead of just returning an
invalid value to signal that we do not have self, we assert or return something
bogus. This commit just fixes our usage of that API to be correct.

rdar://132545626
2024-07-31 16:51:15 -07:00
Michael Gottesman
e7e035f60c [region-isolation] Convert the transfer non sendable typed error to be a new short-error, long-note form error.
I also messed with the text a little bit.

This eliminates the last of the old style diagnostics.
2024-07-31 13:10:02 -07:00
Michael Gottesman
359ae52cc3 [region-isolation] Move from old style to new style the typed error for passing never sendable types as a sending parameter. 2024-07-31 13:10:02 -07:00
Michael Gottesman
46b2224123 [region-isolation] Add .highlight to a few diagnostics that I missed.
Just trying to be standardized about this.
2024-07-31 13:10:02 -07:00
Michael Gottesman
c7d24e0003 [region-isolation] Convert the typed strongly transferred value diagnostic into a short error, longer note diagnostic.
Just finishing these diagnostics.
2024-07-31 13:10:02 -07:00
Michael Gottesman
2febd26861 [region-isolation] Convert emitTypedIsolationCrossingDueToCapture error to use a new form of error.
NOTE: To make testing these easier (since they are fallback paths), I
added an option that disables named errors only for use in asserts.
2024-07-31 13:10:02 -07:00
Michael Gottesman
bfdbc760cf [region-isolation] Convert UseAfterTransfer's typed isolation transfer error to the split small error/large note format we are standardizing on.
I also cleaned up the diagnostic a little bit.
2024-07-31 13:10:02 -07:00
Michael Gottesman
4713880ae8 [region-isolation] Add the ability to force the diagnostic emitter to emit typed diagnostics instead of named diagnostics.
We only use typed diagnostics if we are unable to pattern match a name for a
SILValue. Since we generally do this (in most of our tests we do for instance),
it is hard to test this. So I put in an option here that is enabled only in
asserts that forces the diagnostic emitter to emit the typed diagnostic by
forcing a name inference failure. This then allows me to write an asserts only
test that validates the behavior of the typed diagnostics since I can guarantee
the typed diagnostics will run.
2024-07-31 13:10:01 -07:00
Michael Gottesman
4e71e3248e [region-isolation] Delete an unused old form diagnostic. 2024-07-31 13:10:01 -07:00
Joe Groff
de687db20f Disallow consuming self in a noncopyable deinit again.
The changes to allow for partial consumption unintentionally also allowed for
`self` to be consumed as a whole during `deinit`, which we don't yet want to
allow because it could lead to accidental "resurrection" and/or accidental
infinite recursion if the consuming method lets `deinit` be implicitly run
again. This makes it an error again. The experimental feature
`ConsumeSelfInDeinit` will allow it for test coverage or experimentation
purposes. rdar://132761460
2024-07-29 21:20:14 -07:00
Nate Chandler
344ef3df37 [ClosureLifetimeFixup] Flag dead-end destroys. 2024-07-29 07:26:08 -07:00
Andrew Trick
030f2b8e90 Merge pull request #75050 from atrick/vardecl_lifetime
[SILGen] Create SIL variable declaration scopes for trivial values.
2024-07-26 16:23:07 -07:00
Andrew Trick
027684aab8 Teach MoveOnlyTypeWrapperEliminator to lower trivial moves/borrows. 2024-07-26 08:27:31 -07:00
Andrew Trick
9478d3488f Fix ConsumeOperatorCopyableValuesChecker to ignore trivial values. 2024-07-26 08:27:31 -07:00
Nate Chandler
a7c6538d4e Revert "Merge pull request #73275 from nate-chandler/lifetime-completion/enable"
This reverts commit 840198ec9b, reversing
changes made to b74303c214.
2024-07-26 07:12:45 -07:00
Nate Chandler
92e5dc84cd [ClosureLifetimeFixup] Flag dead-end destroys. 2024-07-24 17:56:31 -07:00
Nate Chandler
042241af55 [NFC] MoveOnlyAddressChecker: Use isWithinBoundary
Switch back to the API meant for a single instruction now that it
properly handles dead-end regions.
2024-07-23 13:38:35 -07:00
Nate Chandler
812891cf81 [NFC] PrunedLiveness: Clarified boundary API.
When checking whether an instruction is contained in a liveness
boundary, a pointer to a DeadEndBlocks instance must always be passed.
When the pointer is null, it is only checked that the instruction occurs
within the direct live region.  When the pointer is non-null, it is
checked whether the instruction occurs within the region obtained by
extending the live region up to the availability boundary within
dead-end regions that are adjacent to the non-lifetime-ending portion of
the liveness boundary.
2024-07-23 13:38:35 -07:00
Nate Chandler
4a397cc018 [NFC] OwnedLifetimeCan: Take DeadEndBlocksAnalysis
All clients of OwnedLifetimeCanonicalization pass an instance of the
analysis in.  For now, it's unused.
2024-07-22 21:51:28 -07:00
Nate Chandler
3eb288f92e [MoveOnlyAddressChecker] Exclusivity handles DEs.
Switch to the areUsesWithinBoundary API which takes dead-ends into
account.

rdar://131960619
2024-07-22 14:03:49 -07:00
Michael Gottesman
bcbf5c515e [region-isolation] Emit an error when we assign a non-disconnected value into a sending result.
rdar://127318392
2024-07-18 21:29:08 -07:00
Michael Gottesman
ace94b00ba [region-isolation] Move RepresentativeValue from RegionAnalysis.h -> PartitionUtils.h and add APIs for mapping an ElementID -> Representative.
This is just moving up the declaration in the chain of dependencies so that I
can write logic in PartitionUtils.h using it. I also added entrypoints to lookup
the ReprensetativeValue for our various emitters.
2024-07-18 21:28:22 -07:00
Michael Gottesman
219073be97 Revert "[region-isolation] Make "unknown pattern error" always an error."
This reverts commit b63781f7ba.

We found some cases where due to malformed IR that we allow through due to
either us compiling for strict-concurrency=complete+swift-5 or swift-6 +
preconcurrency, that we can actually have actor isolation mismatch. I am going
to in a subsequent commit add a better phrasing here. But for now, just undo the
conversion from error -> warning.

rdar://131757602
2024-07-17 16:09:55 -07:00
Slava Pestov
d1847ffde7 Merge pull request #75068 from slavapestov/simplify-sub-map
Simplify and optimize SubstitutionMap
2024-07-10 20:45:56 -04:00
Michael Gottesman
b63781f7ba [region-isolation] Make "unknown pattern error" always an error.
This shows an actual issue with the compiler where semantically we should crash.
Rather than crashing (due to the broken invariants), we emit this error so that
the user gets a nice error message at the problem place and can work around it
instead of just getting a mysterious crash.

Previously, we were making this a warning in swift 5 mode... but given the
issues, it makes sense to emit an error diagnostic so we get the feedback and
the user cannot ship the code.

rdar://131482934
2024-07-10 12:48:09 -07:00
Slava Pestov
977b444eb3 AST: Add a new overload of getContextSubstitutionMap() 2024-07-10 13:28:26 -04:00
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
57392b1031 [region-isolation] Fix a nullptr error.
This is triggered by the test case in the next commit. The problem is anonymous
closures can be passed here and they do not have a ValueDecl so there isn't a
decl for us to use.
2024-07-08 11:19:20 -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
Slava Pestov
86d567f95a AST: ModuleDecl::lookupConformance() is a static method 2024-07-06 12:05:47 -04:00
Slava Pestov
fae01d9776 AST: Remove ModuleDecl parameter from more places 2024-07-06 12:05:46 -04: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
Nate Chandler
1d47d3ca0d [OME] Erase dead_end lifetime ends.
Such instructions are inserted to ensure complete OSSA lifetimes and
should be removed when lowering out of OSSA.
2024-07-03 16:44:35 -07:00
Nate Chandler
dd730b849c [LifetimeCompletion] Flag instructions dead_end. 2024-07-03 16:44:35 -07:00