Commit Graph

6583 Commits

Author SHA1 Message Date
Erik Eckstein
5e2e7e3884 SIL Bridging: use bool for boolean properties
This was a leftover from the time we didn't use C++ interop
2023-05-11 08:03:19 +02:00
Erik Eckstein
e95c6425f2 Swift SIL: add some APIs for global variables 2023-05-08 21:23:36 +02:00
Allan Shortlidge
0366c42293 Merge pull request #65557 from tshortli/unavailable-decl-optimization-stub
Introduce `stub` mode for `-unavailable-decl-optimization`
2023-05-05 09:11:41 -07:00
eeckstein
3bad9069a6 Merge pull request #65622 from eeckstein/improve-escape-utils
EscapeUtils: better handling of noescape closures and convert_function instructions
2023-05-04 07:54:23 +02:00
eeckstein
ddc0219928 Merge pull request #65592 from eeckstein/fix-sil-verifier
MemoryLifetimeVerifier: be more precise with indirect function arguments.
2023-05-04 07:52:34 +02:00
Michael Gottesman
e1f2a207bd Merge pull request #65604 from gottesmm/address-only-stuff
[move-only] Address Only Patches
2023-05-03 18:39:25 -07:00
Allan Shortlidge
2f5b61ebe0 SILOptimizer: Suppress unreachable code diagnostics for unavailable stubs.
User code should not be diagnosed as "unreachable" by the SIL optimizer when
the no-return function that made the code unreachable is a compiler inserted
call to `_diagnoseUnavailableCodeReached()`.

Part of rdar://107388493
2023-05-03 15:19:31 -07:00
Allan Shortlidge
d1416ddd56 SILGen: Stub unavailable functions.
When `-unavailable-decl-optimization=stub` is specified, insert a call to
`_diagnoseUnavailableCodeReached()` at the beginning of the function to cause
it to trap if executed at run time.

Part of rdar://107388493
2023-05-03 15:19:31 -07:00
Erik Eckstein
5992e68d23 EscapeUtils: better handling of noescape closures and convert_function instructions
* Assume that a noescape closure argument cannot escape a called function
* Handle convert_function instructions

rdar://108837480
2023-05-03 19:53:19 +02:00
Erik Eckstein
4b33b99ee2 MemoryLifetimeVerifier: be more precise with indirect function arguments.
Optimizations can rely on alias analysis to know that an in-argument (or parts of it) is not actually read.
We have to do the same in the verifier: if alias analysis says that an in-argument is not read, there is no need that the memory location is initialized.

Fixes a false verifier error.
rdar://106806899
2023-05-03 14:33:45 +02:00
Michael Gottesman
92116ba4b8 [sil] Add a small helper API called SILUndef::get(SILValue).
This just creates a new SILUndef with the same type as the SILValue. This just
prevents one from having to write
SILUndef::get(value->getType(), *value->getModule()).
2023-05-02 16:30:38 -07:00
Nate Chandler
3e6ac9301e [SIL] BitfieldRef forwards arbitrary args.
Previously, when constructing a container within a StackState, a
SILFunction that was passed to the StackState's constructor was passed
along.  Here, arbitrary arguments are forwarded along.
2023-05-02 11:51:53 -07:00
Nate Chandler
f952b0cc7e [PrunedLiveness] Removed invalidate.
The method doesn't do what clients expect.
2023-05-02 11:51:53 -07:00
Nate Chandler
dfe2c00155 [SIL] Added operator bool to ref. 2023-05-02 11:51:52 -07:00
nate-chandler
2984f0a236 Merge pull request #65417 from nate-chandler/rdar108514447
[SemanticARCOpts] Promote moved load [copy]s to load_borrows.
2023-04-27 06:59:02 -07:00
Nate Chandler
b686e81085 [OwnershipUtils] Add move as OwnedValueIntroducer. 2023-04-25 11:37:30 -07:00
Michael Gottesman
c577055100 [move-only] Instead of using AccessUseVisitor to visit addresses use TransitiveAddressVisitor.
This makes it so that the move address checker is not dependent on starting the
traversal at a base object. I also included verifier checks that the API can
visit all address uses for:

1. project_box.
2. alloc_stack.
3. ref_element_addr.
4. ref_tail_addr.
5. global_addr_inst.

this is because this visitor is now apart of the SIL API definition as being
able to enumerate /all/ addresses derived from a specific chosen address value.

This is a refactoring NFCI change.

rdar://108510644
2023-04-25 10:51:03 -07:00
nate-chandler
28bbbd5614 Merge pull request #65114 from nate-chandler/nfc/20230412/2/delete-duplicate-api
[SIL] NFC: Removed visitBorrowIntroducingUserResults.
2023-04-24 15:20:16 -07:00
Nate Chandler
6ad9581bd6 [SIL] NFC: Clarified doc comment. 2023-04-24 10:38:11 -07:00
Meghana Gupta
3d75abc570 Add an option to force boundary completion of lexical values 2023-04-21 22:41:22 -07:00
Slava Pestov
ce5bef8f4d Merge pull request #65361 from slavapestov/sil-type-subst-cloner-sillyness
SIL: TypeSubstCloner::remapASTType() should not call getLoweredRValueType()
2023-04-21 18:52:32 -04:00
Slava Pestov
8bb3248ab3 SIL: TypeSubstCloner::remapASTType() should not call getLoweredRValueType()
SILCloner::visitScalarPackIndexInst() was calling remapASTType() on
a PackType. This was becoming a SILPackType, which would then crash
in a cast<>.
2023-04-21 14:17:08 -04:00
Nate Chandler
5b6c1d6660 [SIL] Accesses to globals are deinit barriers.
Accesses to globals can't be reordered with deinits since deinits could
read such globals.

rdar://98542123
2023-04-20 18:02:41 -07:00
Slava Pestov
7fa676e53d SIL: Introduce SILType::hasParameterizedExistential() 2023-04-18 12:54:49 -04:00
Meghana Gupta
fa4f3a5642 Update assertion for partial_apply [on_stack] lifetime ends in lifetime completion
Since partial_apply [on_stack] is considered as a BorrowingOperand now,
and BorrowingOperand::visitScopeEndingUses can be called on the its forwarded values
lifetime ends, update the assertion to reflect this.
2023-04-14 16:00:24 -07:00
John McCall
9bf4e8c4a3 Remove a couple of over-eager assertions.
The best substitutions we can easily find in nested functions for
captured local variables are the forwarding substitutions of the
current environment.  These should be fine for type-substitution
purposes but do not necessarily match the generic signature of the
original variable's environment, which can trip these assertions.
Unfortunately, I can't think of an easy way to weaken these
assertions sufficiently to cover this case.

This should fix the source-compat suite regression reported in
rdar://107642925.
2023-04-14 02:04:47 -04:00
Meghana Gupta
264d86d26c Implement InteriorLivenessVisitor::handleInnerBorrow for all BorrowingOperand kinds
Not all BorrowingOperand introduce a BorrowedValue. Add a new api to get the defining value
for use in InteriorLivenessVisitor::handleInnerBorrow.
2023-04-12 14:42:23 -07:00
Nate Chandler
b1ccb59f01 [SIL] NFC: Removed visitBorrowIntroUserResults.
It's equivalent to getBorrowIntroducingUserResult except that it's less
convenient to use.  There's only ever one result, so there's no need for
a visitor.  Updated all users to call getBorrowIntroducingUserResult
instead.
2023-04-12 13:41:42 -07:00
Nate Chandler
0fceb33905 [SIL] NFC: Marked function const.
Make it available on const instances.
2023-04-12 13:29:05 -07:00
Meghana Gupta
6cefbb303a Handle partial_apply [on_stack] lifetime ends in the visitor 2023-04-11 13:56:42 -07:00
Erik Eckstein
7d70a70acf SIL: add the drop_deinit instruction
his instruction is a marker for a following destroy instruction to suppress the call of the move-only type's deinitializer.
2023-04-11 10:25:48 +02:00
Meghana Gupta
6854bbef1f Merge pull request #64975 from meg-gupta/fixborrowcompletion
Fix ossa borrow completion
2023-04-06 18:28:49 -04:00
nate-chandler
417bc5a7f5 Merge pull request #64964 from nate-chandler/lexical-lifetime-elim-lexical-move
[LexicalLifetimeEliminator] Removed flag from move_values.
2023-04-06 13:57:28 -07:00
Meghana Gupta
85a580a96e Fix ossa borrow completion
end_borrow was not considered as a lifetime ending use,
leading to insertion of redundant end_borrows at boundaries.
2023-04-06 11:15:37 -07:00
Nate Chandler
b682d54ddc [LexLifetimeElim] Removed flag from moves.
When eliminating lexical lifetimes, also eliminate the lifetimes
introduced by move_values in addition to those introduced by
begin_borrow and communicated via alloc_stack.
2023-04-05 18:38:08 -07:00
John McCall
c11cbfa6ce [NFC] Convert this code to use canonical types 2023-04-05 16:58:49 -04:00
Andrew Trick
4bc9671e44 Merge pull request #64926 from atrick/fix-liveblocks
MultiDefPrunedLiveness: add support for arbitrary uses/defs.
2023-04-05 10:03:27 -07:00
Adrian Prantl
829491b230 Merge pull request #64551 from adrian-prantl/88274783
Rebase SILScope generation on top of ASTScope
2023-04-05 08:30:13 -07:00
Adrian Prantl
158772c2ab Rebase SILScope generation on top of ASTScope.
This patch replaces the stateful generation of SILScope information in
SILGenFunction with data derived from the ASTScope hierarchy, which should be
100% in sync with the scopes needed for local variables. The goal is to
eliminate the surprising effects that the stack of cleanup operations can have
on the current state of SILBuilder leading to a fully deterministic (in the
sense of: predictible by a human) association of SILDebugScopes with
SILInstructions. The patch also eliminates the need to many workarounds. There
are still some accomodations for several Sema transformation passes such as
ResultBuilders, which don't correctly update the source locations when moving
around nodes. If these were implemented as macros, this problem would disappear.

This necessary rewrite of the macro scope handling included in this patch also
adds proper support nested macro expansions.

This fixes

rdar://88274783

and either fixes or at least partially addresses the following:

rdar://89252827
rdar://105186946
rdar://105757810
rdar://105997826
rdar://105102288
2023-04-04 15:20:11 -07:00
Andrew Trick
c9eb1aea91 MultiDefPrunedLiveness: add support for arbitrary uses/defs.
This now supports liveness holes within blocks where previously we
expected a phi def.

PrunedLiveness is streamlined for SSA liveness where we expect the
defs and uses to be related in the SSA def-use graph.
MultiDefPrunedLiveness was added on top of SSAPrunedLivenes to handle
extended SSA liveness that occurs with phis, but are still connected
in the def-use graph. Recently MultiDefPrunedLiveness was repurposed
for liveness of addressible storage. This means that we can now have
uses before defs in the same block without a corresponding phi.

Fortunately, handling this case is a straightforward extension of
MultiDefPrunedLiveness that does not complicate or penalize the
streamlined SSA case.
2023-04-04 10:22:32 -07:00
Andrew Trick
d44c7f3b99 [NFC] Move the updateForUse API into PrunedliveRange
PrunedLiveness only knows about the live blocks and uses.

The PrunedLiveRange subclass is now responsible for updating liveness
based on both the defs and uses. This is in preparation for handling
non-SSA liveness when uses occur before the first def.
2023-04-04 10:22:32 -07:00
Andrew Trick
20604ab234 PrunedLiveness: remove a useless flag.
This was recently introduced as a result of rebasing commits. It never
did anything useful on the main branch.
2023-04-04 10:22:32 -07:00
John McCall
9c9671b349 Merge pull request #64887 from rjmccall/vanishing-tuple-silgen
SILGen and SIL type lowering support for vanishing tuples
2023-04-04 12:41:29 -04:00
John McCall
30817b11dd Support vanishing tuples in the the general abstraction pattern routines. 2023-04-03 23:14:47 -04:00
Slava Pestov
3d9a79e4b1 Merge pull request #64777 from slavapestov/sil-optimizer-variadic-generics
SIL optimizer fixes for variadic generics
2023-04-03 11:30:03 -04:00
Slava Pestov
894b57eaf3 AST: Introduce TupleType::getNumScalarElements() 2023-04-02 23:04:00 -04:00
Michael Gottesman
43d8ab24f4 [move-only] Add a new type of mark_must_check initable_but_not_consumable.
This is used to teach the checker that the thing being checked is supposed to be
uninitialized at the mark_must_check point so that we don't put a destroy_addr
there.

The way this is implemented is that we always initially add
assignable_but_not_consumable but in DI once we discover that the assign we are
guarding is an init, we convert the assignable to its initable variant.

rdar://106525988
2023-03-31 17:32:58 -07:00
Adrian Prantl
af3b73a8ac Merge pull request #64590 from adrian-prantl/implicit-sillocation
Preserve the Implicit attribute in SILLocation. (NFC)
2023-03-30 13:46:51 -07:00
Andrew Trick
0c8ecb54bf Revert "MultiDefPrunedLiveness: add support for arbitrary uses/defs." 2023-03-28 17:43:42 -07:00
Andrew Trick
95a92fda30 Merge pull request #64625 from atrick/fix-liveblocks
MultiDefPrunedLiveness: add support for arbitrary uses/defs.
2023-03-28 14:19:42 -07:00