Commit Graph

10296 Commits

Author SHA1 Message Date
Michael Gottesman
e945c55c97 Merge pull request #75605 from gottesmm/pr-d4066f062c015e630d51fe05140fe756391079a9
[region-isolation] Use a hard to use API correctly.
2024-07-31 20:03:01 -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
541863dbc6 [region-isolation] Fix handling of coroutine apply results.
In this part of the code, we are attempting to merge all of the operands into
the same region and then assigning all non-Sendable results of the function to
that same region. The problem that was occuring here was a thinko due to the
control flow of the code here not separating nicely the case of whether or not
we had operands or not. Previously this did not matter, since we just used the
first result in such a case... but since we changed to assign to the first
operand element in some cases, it matters now. To fix this, I split the confused
logic into two different easy to follow control paths... one if we have operands
and one where we do not have an operand. In the case where we have a first
operand, we merge our elements into its region. If we do not have any operands,
then we just perform one large region assign fresh.

This was not exposed by code that used non-coroutines since in SIL only
coroutines today have multiple results.

rdar://132767643
2024-07-31 09:37:42 -07:00
eeckstein
d5f95c354e Merge pull request #75565 from eeckstein/fix-keypath-folding
Optimizer: fix a crash in keypath folding
2024-07-31 14:06:00 +02:00
Joe Groff
d37ff048aa Merge pull request #75560 from jckarter/disable-consuming-self-in-deinit
Disallow consuming `self` in a noncopyable `deinit` again.
2024-07-30 10:59:35 -07:00
Erik Eckstein
9d6643b07e Optimizer: fix a crash in keypath folding
The KeyPathProjector utility crashed for keypaths  to stored objectiveC properties.

rdar://132780588
2024-07-30 16:59:31 +02:00
eeckstein
8189840e95 Merge pull request #75505 from eeckstein/alias-analysis
AliasAnalysis: a complete overhaul of alias- and memory-behavior analysis
2024-07-30 07:32:22 +02: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
Michael Gottesman
72ad780578 Merge pull request #75541 from gottesmm/pr-7133549c90f98b7c9be71f80b74a97d088aa62f2
[region-isolation] Do not ignore non-trivial results that are Sendable to be more permissive in the face of lazy typechecker issues.
2024-07-29 13:00:24 -07:00
Michael Gottesman
8604480d12 [region-isolation] Do not ignore non-trivial results that are Sendable to be more permissive in the face of lazy typechecker issues.
We have found certain cases due to the requestified typechecker, a type is
initially Sendable and then is later non-Sendable. This can be seen by the
attached test case where the first time one calls isNonSendableType on the test
value, one would get that it is Sendable and then the second time one would get
it was non-Sendable. The result of this is that the pass gets into an
inconsistent state.

This patch is a small patch that makes the pass more permissive in the face of
such an error by making it so that we do not ignore Sendable results of
instructions (that is we make sure to track a value for them), so we do not
break invariants.

The longer term better fix is to make it so that we have a cache in the pass for
this query that way we just always use the first answer returned from the
typechecker and cache that. If the typechecker has such a bug, we may get bogus
results, but we at least do not break invariants.

As an example of this type of behavior, in the test case in this patch, we first
find the Sendable conformance of MySubClass and then the typechecker after doing
some more type checking while performing that query, the second time finds the
inherited non-Sendable conformance of MyParentClass causing MySubClass to be
considered to be non-Sendable.

rdar://132347404
2024-07-29 09:44:57 -07:00
Erik Eckstein
f9b524b1cb AliasAnalysis: a complete overhaul of alias- and memory-behavior analysis
The main changes are:

*) Rewrite everything in swift. So far, parts of memory-behavior analysis were already implemented in swift. Now everything is done in swift and lives in `AliasAnalysis.swift`. This is a big code simplification.

*) Support many more instructions in the memory-behavior analysis - especially OSSA instructions, like `begin_borrow`, `end_borrow`, `store_borrow`, `load_borrow`. The computation of end_borrow effects is now much more precise. Also, partial_apply is now handled more precisely.

*) Simplify and reduce type-based alias analysis (TBAA). The complexity of the old TBAA comes from old days where the language and SIL didn't have strict aliasing and exclusivity rules (e.g. for inout arguments). Now TBAA is only needed for code using unsafe pointers. The new TBAA handles this - and not more. Note that TBAA for classes is already done in `AccessBase.isDistinct`.

*) Handle aliasing in `begin_access [modify]` scopes. We already supported truly immutable scopes like `begin_access [read]` or `ref_element_addr [immutable]`. For `begin_access [modify]` we know that there are no other reads or writes to the access-address within the scope.

*) Don't cache memory-behavior results. It turned out that the hit-miss rate was pretty bad (~ 1:7). The overhead of the cache lookup took as long as recomputing the memory behavior.
2024-07-29 17:33:46 +02:00
Erik Eckstein
8f2531348d LICM: make sure that getMemoryBehavior is only called for address values
It was called for non-address operands of fix_lifetime.
Just exclude such fix_lifetime instructions from moving. It's not important anyway.
2024-07-29 17:33:44 +02:00
Erik Eckstein
4c49e0039b Verifier: in the swift verifier call the bridged C++ verificationFailure function in case of a failure
This brings all the nice verifier features to the swift verifier, like printing the surrounding instructions in case of a failure, etc.
2024-07-29 17:33:43 +02:00
Erik Eckstein
04e0907ab0 SIL: rename Type.instanceTypeOfMetatype -> Type.loweredInstanceTypeOfMetatype
The same for SILType

It needs to be made clear that this is not the "original", but the lowered SIL type.

NFC
2024-07-29 17:33:36 +02:00
Nate Chandler
344ef3df37 [ClosureLifetimeFixup] Flag dead-end destroys. 2024-07-29 07:26:08 -07:00
Nate Chandler
45f3cf9150 [OwnedLifetimeCan] Persist [dead_end].
When creating `destroy_value`s, create them with the `dead_end` flag if
all subsequent destroys (those from which it is notionally being
hoisted) have the flag.
2024-07-29 07:26:08 -07:00
Anton Korobeynikov
a751b076b6 Fixes inject_enum_addr handling: (#75459)
- Ensure it really accumulates the adjoint buffer
- Handle Optional.none case when there is no value to propagate to

Fixes #75280
2024-07-26 17:04:26 -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
4915bfa9cb Fix ConstExpr evaluation to handle extend_lifetime. 2024-07-26 08:27:31 -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
2e2a81b766 [Test] Underscored dump_function.
Use underscores rather than hyphens so that text editors understand the
name as a single word.
2024-07-25 13:52:21 -07:00
Nate Chandler
acab991197 [Test] Underscored canonicalize_ossa_lifetime.
Use underscores rather than hyphens so that text editors understand the
name as a single word.
2024-07-25 13:52:21 -07:00
Nate Chandler
06bdd79936 [Test] Underscored deleter_delete_if_dead.
Use underscores rather than hyphens so that text editors understand the
name as a single word.
2024-07-25 13:52:21 -07:00
Nate Chandler
fb56178481 [Test] Underscored canonicalize_borrow_scope.
Use underscores rather than hyphens so that text editors understand the
name as a single word.
2024-07-25 13:52:21 -07:00
Nate Chandler
0cad62521e [Test] Underscored sil_isolation_info_inference.
Use underscores rather than hyphens so that text editors understand the
name as a single word.
2024-07-25 13:52:21 -07:00
Nate Chandler
3e5d0039e9 [Test] Underscored lexical_destroy_folding.
Use underscores rather than hyphens so that text editors understand the
name as a single word.
2024-07-25 13:52:21 -07:00
Nate Chandler
a75bd893b9 [Test] Underscored variable_name_inference.
Use underscores rather than hyphens so that text editors understand the
name as a single word.
2024-07-25 13:52:21 -07:00
Nate Chandler
074036982c [Test] Underscored simplify_cfg_simplify_argument.
Use underscores rather than hyphens so that text editors understand the
name as a single word.
2024-07-25 13:50:17 -07:00
Nate Chandler
9825b26e3a [Test] Underscored simplify_cfg_simplify_argument.
Use underscores rather than hyphens so that text editors understand the
name as a single word.
2024-07-25 13:50:17 -07:00
Nate Chandler
2878b053ec [Test] Underscored simplify_cfg_simplify_block_args.
Use underscores rather than hyphens so that text editors understand the
name as a single word.
2024-07-25 13:50:17 -07:00
Nate Chandler
dd19acdf68 [Test] Underscored simplify_cfg_canonicalize_switch_enum.
Use underscores rather than hyphens so that text editors understand the
name as a single word.
2024-07-25 13:50:17 -07:00
Nate Chandler
4329512fb0 [Test] Underscored simplify_cfg_simplify_term_with_identical_dest_blocks.
Use underscores rather than hyphens so that text editors understand the
name as a single word.
2024-07-25 13:50:17 -07:00
Nate Chandler
b0bb97467f [Test] Underscored simplify_cfg_simplify_switch_enum_block.
Use underscores rather than hyphens so that text editors understand the
name as a single word.
2024-07-25 13:50:17 -07:00
Nate Chandler
c0d95c121b [Test] Underscored simplify_cfg_simplify_switch_enum_on_objc_class_optional.
Use underscores rather than hyphens so that text editors understand the
name as a single word.
2024-07-25 13:50:14 -07:00
Nate Chandler
7470c29cfe [Test] Underscored simplify_cfg_simplify_switch_enum_unreachable_blocks.
Use underscores rather than hyphens so that text editors understand the
name as a single word.
2024-07-25 13:48:22 -07:00
Nate Chandler
8d3a5a17d9 [Test] Underscored simplify_cfg_try_jump_threading.
Use underscores rather than hyphens so that text editors understand the
name as a single word.
2024-07-25 13:47:45 -07:00
nate-chandler
840198ec9b Merge pull request #73275 from nate-chandler/lifetime-completion/enable
[LifetimeCompletion] Enable.
2024-07-25 12:29:44 -07:00
Nate Chandler
92e5dc84cd [ClosureLifetimeFixup] Flag dead-end destroys. 2024-07-24 17:56:31 -07:00
Nate Chandler
c726366f88 [OwnedLifetimeCan] Persist [dead_end].
When creating `destroy_value`s, create them with the `dead_end` flag if
all subsequent destroys (those from which it is notionally being
hoisted) have the flag.
2024-07-24 17:56:31 -07:00
Nate Chandler
95b8eef292 [NFC] OwnedLifetimeCan: Use isWithinBoundary.
Now that `isWithinBoundary` and `areUsesWithinBoundary` are "the same"
(up to the fact that one takes an instruction and the other an array of
operands), there's no reason to use the latter when looking at a single
instruction.
2024-07-24 11:28:00 -07:00
Allan Shortlidge
66e2f972ab Merge pull request #75432 from tshortli/maccatalyst-upstream
Upstream missing macCatalyst support
2024-07-24 09:58:04 -07:00
Allan Shortlidge
e4331af916 IRGen: Introduce macCatalyst target variant version check builtins. 2024-07-23 17:00:10 -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
aa8ccafd20 [OwnedLifetimeCan] Prune fewer debug_values.
Use the more precise areUsesWithinBoundary API (which takes dead-end
blocks into account).  This requires first updating liveness with the
newly created destroys.
2024-07-22 21:51:33 -07:00
Nate Chandler
001c41741a [NFC] OwnedLifetimeCan: Record new destroys.
Add them to a small vector.  For now, do nothing with them.
2024-07-22 21:51:33 -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
11abefee60 [NFC] SILCombine: Use DeadEndBlocksAnalysis.
Instead of having a separately calculated version.
2024-07-22 20:35:30 -07:00