Commit Graph

11193 Commits

Author SHA1 Message Date
Joe Groff
dc4c874c49 Merge pull request #72452 from jckarter/pruned-liveness-try-apply-conditional-def
FieldSensitivePrunedLiveness: Handle conditionality of `try_apply` defs.
2024-03-20 07:43:42 -07:00
Joe Groff
1166f2e0d8 FieldSensitivePrunedLiveness: Handle conditionality of try_apply defs.
A `try_apply` with indirect out arguments is only a def for those arguments on
the success path. Model this by sinking the def-ness of the instruction into the
success branch of the try_apply, and introducing a new `DeadToLiveEdge` mode for
block liveness which stops propagation of use-before-def conditions into the
block that introduced the def. Fixes rdar://118567869.
2024-03-19 22:46:26 -07:00
Michael Gottesman
f02565719e Merge pull request #72435 from gottesmm/pr-89ce065b7f50a41a58d8fb358d0145913d8b53a3
[region-isolation] Convert more diagnostics from type isolation form to named variable form
2024-03-19 16:32:36 -07:00
Michael Gottesman
29e3069a50 [region-isolation] Teach variable name utils how to handle more tuple patterns.
Just slicing off from a larger patch.
2024-03-19 13:19:09 -07:00
Michael Gottesman
8b899b8f71 [region-isolation] Teach variable_name_inference how to infer through store_borrow initialized variables.
This eliminates a bunch of cases where we couldn't infer the name of a variable
and used the type based diagnostic.

It also eliminates an 'unknown' case for move checking.
2024-03-19 13:19:09 -07:00
Michael Gottesman
7368de2a20 [region-isolation] Remove variable_defined_here from named use after transfer error.
This is just a pseudo-why are these two things part of the same region error. I
am going to remove this for now and the proper form of this diagnostic will come
back when I land the region history functionality.
2024-03-19 13:19:08 -07:00
Andrew Trick
7da493498a Merge pull request #72407 from atrick/pointer-escape-bailout
Fix lifetime dependence in the presence of pointer escapes.
2024-03-19 11:40:38 -07:00
eeckstein
b9df9a7e4c Merge pull request #72415 from eeckstein/fix-eager-specializer
EagerSpecializer: fix a SIL verifier crash
2024-03-19 18:51:27 +01:00
Erik Eckstein
a5320a6fcd EagerSpecializer: fix a SIL verifier crash
When inserting type checks for pre-specialized functions, the existing return-block can only be re-used if it has no arguments.
Otherwise we are creating an argument-less branch to a block with arguments.

rdar://124638266
2024-03-19 12:28:33 +01:00
Erik Eckstein
308b5f9ff7 Swift Optimizer: add bridging for dynamic cast utilities
* `func canDynamicallyCast`
* `var CheckedCastAddrBranchInst.dynamicCastResult`
2024-03-19 10:54:38 +01:00
Andrew Trick
2e82db8e1b ClosureLifetimeFixup; emit mark_dependence [nonescaping].
It is safe to do so because the on_stack transformation already checks that the closure has a single known apply use.
2024-03-18 17:45:33 -07:00
Andrew Trick
aa208bbf91 Add SILType::containsNoEscapeFunction()
Add PartialApplyInst.hasNoescapeCapture
Add PartialApplyInst.mayEscape

Refactor DiagnoseInvalidEscapingCaptures. This may change functionality because tuples containing a noescape closure are now correctly recognized. Although I'm not sure such tupes can ever be captured directly.
2024-03-18 17:38:12 -07:00
Michael Gottesman
f796f11c97 [region-isolation] Rename ValueIsolationRegionInfo -> IsolationRegionInfo. 2024-03-18 12:24:34 -07:00
Michael Gottesman
afbcf85727 [region-isolation] Change named transfer non transferable error to use the dynamic merged IsolationRegionInfo found during dataflow.
I also eliminated the very basic "why is this task isolated" part of the warning
in favor of the larger, better, region history impl that I am going to land
soon. The diagnostic wasn't that good in the first place and also was fiddly. So
I removed it for now.

rdar://124960994
2024-03-18 12:13:36 -07:00
Michael Gottesman
f7d1f2acb9 [region-isolation] Define getIsolationRegionInfo(Element elt) on PartitionOpEvaluator.
This will let me look up the dynamic isolation region associated with \p elt
while performing dataflow.
2024-03-18 12:13:30 -07:00
Michael Gottesman
465bb230c4 [region-isolation] Rename callback handleFailure -> handleLocalUseAfterTransfer.
Now that we have other forms of error callbacks, having such a general name for
any specific failure is misleading and hinds intent.
2024-03-18 12:13:30 -07:00
Kuba (Brecka) Mracek
8a660a0902 Merge pull request #72371 from kubamracek/embedded-specialize-more-superclass-vtables
[embedded] Specialize superclasses in VTableSpecializer as part of MandatoryPerformanceOptimizations
2024-03-18 08:50:56 -07:00
nate-chandler
05473239b8 Merge pull request #72360 from nate-chandler/noncopyable-bugs/20240315/1
[MoveChecker] Fix visitor return.
2024-03-16 09:32:34 -07:00
Kuba Mracek
f5797941b7 [embedded] Specialize superclasses in VTableSpecializer as part of MandatoryPerformanceOptimizations 2024-03-15 21:30:08 -07:00
Michael Gottesman
683e94f30d Merge pull request #72368 from gottesmm/pr-14b84426e480f5b5049c09df01c9445308dd19c5
[region-isolation] Change semantics of function_extract_isolation from AssertingIfNonSendable -> Require.
2024-03-15 20:13:53 -07:00
Michael Gottesman
dd156f36d0 Merge pull request #72366 from gottesmm/pr-12358c24eb38a655a2275f9b947625a9c72ab016
[region-isolation] Fix assert.
2024-03-15 19:02:10 -07:00
Michael Gottesman
e2ddb088cb [region-isolation] Change semantics of function_extract_isolation from AssertingIfNonSendable -> Require.
The reason why I am doing this is that:

1. function_extract_isolation can take as a parameter a non-Sendable function
today in SIL so in such a case, we crash.
2. It returns an Optional<any Actor> which always must be Sendable.

So it makes sense for it to just require that its non-Sendable parameter not be
transferred at that point.
2024-03-15 17:30:29 -07:00
Michael Gottesman
9fe64cd319 [region-isolation] Fix assert.
This assert validates that look through parameters only have a single operand
(the one we are going to lookthrough). It did not take into account though that
some of these lookthrough instructions /do/ have type dependent operands (which
we should ignore for the assert). I changed the assert to ignore those.
2024-03-15 16:18:56 -07:00
Meghana Gupta
4fb2c59cf9 Merge pull request #72334 from meg-gupta/fixsilcombine
Fix silcombine of inject_enum_addr when we have an empty struct with unreferenceable storage
2024-03-15 15:58:37 -07:00
Nate Chandler
73531d475a [MoveChecker] Fix visitor return.
The visitor returns false to indicate an unknown/unhandled instruction.
Previously it returned true as a fallback.  This resulted in aberrant
behavior: e.g., in the test case committed here, the try_apply was
deleted.
2024-03-15 14:03:30 -07:00
Meghana Gupta
18c24a18b3 Fix silcombine of inject_enum_addr when we have an empty struct with unreferenceable storage 2024-03-15 13:12:36 -07:00
Michael Gottesman
c2c4f13392 [region-isolation] Fix crasher.
The specific problem is that instead of just using the parent type of the
ref_element_addr (which is guaranteed to be a class), we used the base of the
storage... the base doesn't have to be the ref_element_addr's operand. The
crasher occured when that base was a class existential that we cast to a super
class whose field we access.
2024-03-15 12:51:29 -07:00
Ben Barham
cbcfc85777 Merge pull request #72323 from bnbarham/rename-startswith
Rename startswith to starts_with
2024-03-14 09:06:54 -07:00
nate-chandler
e1c04c9d33 Merge pull request #72318 from nate-chandler/noncopyable-bugs/20240313/1
[CanonicalizeInstruction] Process instruction "at" load after rewriting.
2024-03-14 07:05:52 -07:00
Ben Barham
9779c18da3 Rename startswith to starts_with
LLVM is presumably moving towards `std::string_view` -
`StringRef::startswith` is deprecated on tip. `SmallString::startswith`
was just renamed there (maybe with some small deprecation inbetween, but
if so, we've missed it).

The `SmallString::startswith` references were moved to
`.str().starts_with()`, rather than adding the `starts_with` on
`stable/20230725` as we only had a few of them. Open to switching that
over if anyone feels strongly though.
2024-03-13 22:25:47 -07:00
Michael Gottesman
e156289cea Merge pull request #72126 from gottesmm/async-let-fixes
[region-isolation] Make async let closures non-Sendable and require actor isolation crossing function into an async let use a transferring result.
2024-03-13 21:54:04 -07:00
Nate Chandler
2cbc13aca6 [CanonInst] Process "at" load after rewriting.
When a load/load_borrow is canonicalized, canonicalization should
continue from where the load was before rather than the first
instruction that was after it.  Enables narrowing the load through
a sequence of projections.
2024-03-13 17:42:33 -07:00
Nate Chandler
9c3d941a4a [Gardening] Deleted stale comment. 2024-03-13 17:42:33 -07:00
Michael Gottesman
acca7353db [transferring] Make async let take a transferring result if its result is non-Sendable.
Some notes:

1. If the result is non-Sendable and we didn't infer something that is
transferring, we still emit the current sema error that says that one cannot
assign a non-Sendable value to an async let.

2. When region isolation is enabled, but transferring args and results are
disabled, we leave the async let semantics alone. This means that the async let
closure is still @Sendable and one cannot pass in non-Sendable values to it.
2024-03-13 15:30:54 -07:00
Nate Chandler
edf71f49d6 [Gardening] Test: Dropped spurious imports.
Now that tests of various utilities have been moved next to the
utilities themselves, the TestRunner file doesn't need to import the
corresponding headers.
2024-03-13 13:50:27 -07:00
eeckstein
a24539171c Merge pull request #72265 from eeckstein/fix-mandatory-inlining
MandatoryInlining and ConstExpr: look through sendable function conversions
2024-03-13 18:52:43 +01:00
Ellie Shin
56d337d322 Merge pull request #72249 from apple/es/pkg-cmo 2024-03-13 09:26:35 -07:00
Joe Groff
b0655407c6 Merge pull request #72281 from jckarter/moveonly-optional-chain-3
SIL: Optimizer fixes for noncopyable optional chains.
2024-03-13 08:11:39 -07:00
nate-chandler
197b1648fa Merge pull request #72272 from nate-chandler/noncopyable-bugs/20240312/2
[ConsumeAddrChecker] Check inout_aliasable arguments.
2024-03-13 07:00:00 -07:00
Erik Eckstein
4316a7cf05 ConstExpr: look through sendable function conversions 2024-03-13 09:58:31 +01:00
Erik Eckstein
4e61c5620c MandatoryInlining: look through sendable function conversions
Allows inlining of sendable transparent functions

rdar://124401627
2024-03-13 09:58:30 +01:00
Meghana Gupta
2d27ec581c Merge pull request #72267 from meg-gupta/enablesilcombineempty
Enable SILCombine of inject_enum_addr for empty types
2024-03-12 20:34:09 -07:00
Meghana Gupta
a312225f17 Merge pull request #72274 from meg-gupta/debugbreak
Add an option -sil-break-before-pass-count
2024-03-12 19:50:28 -07:00
Michael Gottesman
d72f267538 Merge pull request #72271 from gottesmm/pr-e9ccc43526e04bf00a21d49893c15ef4031898e8
[region-isolation] When inferring AST arg nums from SIL operand numbers, ignoring indirect operands.
2024-03-12 18:26:12 -07:00
Joe Groff
8a65c9be94 SIL: Optimizer fixes for noncopyable optional chains.
Don't attempt a SILCombine transform on `select_enum` that inserts a copy when an
enum is noncopyable. Adjust the cleanup handling for a consuming optional chain to
ensure a `destroy_value` still gets emitted on the `none` path; this shouldn't
actually matter since `none` is a trivial case, but the memory verifier isn't
that fancy during OSSA, and we can optimize it later. Fixes rdar://124426918.
2024-03-12 18:11:21 -07:00
Michael Gottesman
c6e24a7a46 Merge pull request #72264 from gottesmm/eliminate-rest-of-task-or-actor-isolated
[region-isolation] Eliminate most of the rest of the "task or actor" isolated error
2024-03-12 17:54:26 -07:00
Nate Chandler
862ee47c6b [ConsumeAddrChecker] Check inout_aliasable args.
Such values can be referenced in a `ConsumeExpr`, so the checker must
check them.  Furthermore it's legal to consume such values some of the
time.
2024-03-12 16:17:53 -07:00
Meghana Gupta
dacf5b47e3 Add an option -sil-break-before-pass-count to break before running a pass when in the debugger
We often look at the SIL output of -sil-print-function and may want to debug a specific pass
after looking at the output.

-sil-break-before-pass-count=<pass_number> will allow to automatically break in the debugger
after <pass_count> of passes are run.

Example:
From -sil-print-function dump:
"SIL function after  #6680, stage MidLevel,Function, pass 38: RedundantLoadElimination"

-Xllvm -sil-break-before-pass-count=6680 will break before running this pass in the debugger
2024-03-12 15:16:01 -07:00
Ellie Shin
a3250e426d Support Package CMO
* Add a new flag -experimental-package-cmo that requires -experimental-allow-non-resilient-access.
* Support serializing package decls for CMO in package if enabled.
* Only applies to default mode CMO.
* Unlike the existing CMO, package CMO can be built with -enable-library-evolution as package
modules are required to be built together in the same project.
* Create hasPublicOrPackageVisibility to opt in for package decls; needed for CMO, SILVerifier,
and other call sites that verify or determine codegen.

Resolves rdar://121976014
2024-03-12 15:00:24 -07:00
nate-chandler
aac2051e68 Merge pull request #72257 from nate-chandler/noncopyable-bugs/20240312/1
[ConsumeAddrChecker] Check in_guaranteed arguments.
2024-03-12 14:49:00 -07:00