Commit Graph

446 Commits

Author SHA1 Message Date
Nate Chandler
ec120e41e7 [Test] Ensourced canonicalize-borrow-scope.
Moved the test next to the code it calls.
2023-07-04 11:52:13 -07:00
Nate Chandler
c0783aa70f [Test] Ensourced canonicalize-ossa-lifetime.
Moved the test next to the code it calls.
2023-07-04 11:52:13 -07:00
Nate Chandler
fcec328c54 [Test] Ensourced multidefuse-liveness.
Moved the test next to the code it calls.
2023-07-04 11:52:13 -07:00
Nate Chandler
f99637156b [Test] Ensourced multidef-liveness.
Moved the test next to the code it calls.
2023-07-04 11:52:13 -07:00
Nate Chandler
303664c940 [Test] Ensourced scoped-address-liveness.
Moved the test next to the code it calls.
2023-07-04 11:52:13 -07:00
Nate Chandler
ef02dc2081 [Test] Ensourced ssa-liveness.
Moved the test next to the code it calls.
2023-07-04 11:52:13 -07:00
Nate Chandler
524c676318 [Test] Ensourced print-type-lowering.
Moved the test next to the code it calls.
2023-07-04 11:52:13 -07:00
Nate Chandler
3343ab926d [Test] Ensourced pruned-livenes-boundary...
-with-list-of-last-users-insertion-points.  Moved the test next to the
code it calls.
2023-07-04 11:52:13 -07:00
Nate Chandler
044625c31f [Test] Ensourced lexical-destroy-folding.
Moved the test next to the code it calls.
2023-07-04 11:52:13 -07:00
Nate Chandler
2e317907fd [Test] Ensourced has-pointer-escape.
Moved the test next to the code it calls.
2023-07-04 11:52:13 -07:00
Nate Chandler
e9ab3b4b53 [Test] Refactored SIL "unit" tests.
Renamed UnitTest to FunctionTest.

FunctionTests are now instantiated once as global objects--with their
names and the code they are to run--at which time they are stored by
name in a global registry.

Moved the types to the SIL library.

Together, these changes enable defining unit tests in the source file
containing the code to be tested.
2023-07-04 11:52:11 -07:00
Nate Chandler
4374b6b58f [Test] Moved test_spec parsing to SIL.
In preparation for moving unit test infrastructure there so that it can
be used anywhere the SIL library is used.
2023-07-04 11:51:36 -07:00
Evan Wilde
250082df25 [NFC] Reformat all the LLVMs
Reformatting everything now that we have `llvm` namespaces. I've
separated this from the main commit to help manage merge-conflicts and
for making it a bit easier to read the mega-patch.
2023-06-27 09:03:52 -07:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
swift-ci
995c41c008 Merge pull request #66826 from nate-chandler/rdar110862719
[FieldSensitivePL] NFC: Added unit tests.
2023-06-23 14:51:38 -07:00
Nate Chandler
7322ccb25b [FieldSensitivePL] NFC: Added unit tests.
Ported versions of the unit tests that Andy added to pruned liveness to
FieldSensitivePL.

rdar://110862719
2023-06-23 10:16:53 -07:00
Meghana Gupta
031255c2d8 Rename hasPointerEscape -> findPointerEscape 2023-06-20 21:13:55 -07:00
Nate Chandler
9b6904498e [TypeLowering] Move-only types are lexical.
Vars of such types should be given lexical `alloc_stack`s by
`AllocBoxToStack` which requires that the `alloc_box` insts formed for
them have an associated borrow scope which in turn requires that type
lowering for move only structs and enums have their lexical bits set.

rdar://110901430
2023-06-16 08:26:04 -07:00
Meghana Gupta
5d401fb70a Remove select_value SIL instruction 2023-06-13 14:13:43 -07:00
Holly Borla
ac66a06199 [SIL] Add a new AssignOrInit instruction for init accessors.
This instruction is similar to AssignByWrapperInst, but instead of having
a destination operand, the initialization is fully factored into the init
function operand. Like AssignByWrapper, AssignOrInit has partial application
operands of both the initializer and the setter, and DI will lower the
instruction to a call based on whether the assignment is initialization or
a setter call.
2023-06-06 18:59:10 -07:00
Michael Gottesman
70ab38d9da [move-only] Add a new instruction: moveonlywrapper_to_copyable_box.
I am going to use this to unwrap ${ @moveOnly T } so that I can pass it to
partial_apply that expect a ${ T }
2023-06-06 14:26:22 -04:00
Michael Gottesman
611e6760f5 [borrowing/consuming] Add a new instruction called copyable_to_moveonlywrapper_addr.
Just the $*T -> $*@moveOnly T variant for addresses. Unlike the object version
this acts like a cast rather than something that provides semantics from the
frontend to the optimizer.
2023-06-06 12:42:23 -04:00
Michael Gottesman
43f42e2c04 [borrowing/consuming] Add new instruction: moveonlywrapper_to_copyable_addr.
The reason why I am using a different instruction for addresses and objects here
is that the object checker doesnt have to deal with things like initialization.
2023-06-06 12:42:23 -04:00
Nate Chandler
e6f15b92c5 [UnitTestRunner] Gardening: Fixed typo. 2023-06-05 08:11:28 -07:00
Nate Chandler
efca4e57c8 [SIL] Added on-stack pack metadata marker insts.
The new alloc_pack_metadata and dealloc_pack_metadata are inserted as
part of IRGen lowering.  The former indicates that the next instruction
might result in on-stack pack metadata being emitted.  The latter
indicates that this is the position at which metadata emitted on behalf
of its operand should be cleaned up.
2023-06-05 08:11:28 -07:00
Michael Gottesman
8579c1924d [move-only] Make sure that we serialize deinits and if we are not able to see the value witness function, call it via the value witness function.
Some notes:

1. I put in both a swiftpm like test case and a library evolution test case. I
also updated the moveonly_deinit serialization swift test to show that we
actually serialize the deinit.

2. I changed when we emit the deinit table to only be when we have a type with
an actual value type destructor. Notably this doesn't include classes today so
as a side-effect, we no longer attempt to devirtualize moveonly class deinits.
This doesn't affect anything we are trying to actually do since we do not
support noncopyable classes today. With that in mind, I changed one test that
was showing that deinit devirtualization worked to use a struct with deinit
instead of a class.

rdar://109679168
2023-05-27 22:07:04 -07:00
Erik Eckstein
fa1ecff143 Swift Optimizer: rewrite the MemBehaviorDumper test pass in swift. 2023-05-09 08:25:09 +02:00
Erik Eckstein
8a8a895239 alias analysis: compute more precise memory effects of builtin "once"
* Check if the address in question is even visible from outside the function
* Return the memory effects of the called function

Also, add a new API `Instruction.memoryEffects`, which is internally used by `mayReadFromMemory` et al.
2023-05-08 21:23:36 +02: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
Nate Chandler
ec3f005f31 [CanonOSSALifetime] Run on lexical lifetimes.
Previously, the utility bailed out on lexical lifetimes because it
didn't respect deinit barriers.  Here, deinit barriers are found and
added to liveness if the value is lexical.  This enables copies to be
propagated without hoisting destroys over deinit barriers.

rdar://104630103
2023-03-25 21:17:26 -07:00
Nate Chandler
1e4086fd34 [Test] Unit test lexical destroy folding.
Adapt a preexisting test to be a unit test that runs the utility.
2023-03-25 12:27:57 -07:00
Andrew Trick
37ff9ad1a0 Add a MultiDefUseLivenessTest
This provides a way to test liveness based on non-SSA values. The move
checker is now using pruned liveness this way. So we need a way to
test that liveness no longer makes any assumptions about SSA
values. These test cases need to explicitly specify all the def and
use instructions.
2023-03-23 10:39:32 -07:00
Andrew Trick
aa469544c7 ParseTestSpecification: handle multi-line strings
We need this for specifications that involve multiple components and long instruction lists.
2023-03-23 01:56:19 -07:00
Andrew Trick
119e712c32 Merge pull request #64534 from atrick/liveblocks-bitfield
Cleanup PrunedLiveBlocks
2023-03-22 16:33:08 -07:00
Andrew Trick
15796e3ff9 PrunedLiveness: add a SILFunction argument
So that liveness can migrate to using a SILBitfield.
2023-03-22 01:36:48 -07:00
Erik Eckstein
ae7770d911 Swift Bridging: use C++ instead of C bridging for BridgedFunction 2023-03-21 15:33:09 +01:00
Nate Chandler
af1ac900f9 [SIL] Add hasPointerEscape(SILValue).
There is a preexisting function with this name that takes a
BorrowedValue.  The new function calls that preexisting function if a
BorrowedValue can be constructed from the SILValue.  Otherwise, it looks
for direct uses of the value which qualify as "pointer escapes".
2023-03-10 10:49:53 -08:00
Michael Gottesman
00d54ebaa8 [reference-binding] Add mark_unresolved_reference_binding to signal from SILGen to the pass to check.
Just the SIL part of this.
2023-03-03 17:14:41 -08:00
Andrew Trick
b0affc4931 Add unit test runner for OSSSLifetimeCompletion 2023-03-01 21:41:47 -08:00
nate-chandler
2d52058284 Merge pull request #63876 from nate-chandler/lexical-phis
[SIL] Phi with incoming lexical value is lexical.
2023-02-24 15:28:00 -08:00
Nate Chandler
7ea4523ee6 [SIL] Phi with incoming lexical value is lexical.
Added SILPhiArgument::isLexical.  It's true for phis which have an
incoming value that's lexical.  Dispatch to this member from
ValueBase::isLexical.
2023-02-23 16:26:44 -08:00
Allan Shortlidge
f1a8740ba5 AST: Only treat @backDeployed functions as fragile on platforms with an active attribute.
Previously, typechecking and SILGen would treat a function body as fragile as long as the declaration had a `@backDeployed` attribute, regardless of the platform specified by the attribute. This was overly conservative since back deployed functions are only emitted into the client on specific platforms. Now a `@backDeployed` function can reference non-`public` declarations on the platforms it is resilient on:

```
@backDeployed(before: iOS 15)
public func foo() {
  #if os(iOS)
  // Fragile; this code may be emitted into the client.
  #else
  // Resilient; this code won't ever be exposed to clients.
  #endif
}
```

Resolves rdar://105298520
2023-02-23 10:39:42 -08:00
John McCall
a38478724a Add a pack_length SIL instruction for measuring the length of a pack 2023-02-10 21:50:44 -05:00
Andrew Trick
13e1aa4467 Add OwnershipLiveness utilities
Encapsulate all the complexity of reborrows and guaranteed phi in 3
ownership liveness interfaces:

LinerLiveness, InteriorLiveness, and ExtendedLiveness.
2023-02-10 09:39:18 -08:00
Michael Gottesman
64ba69e3f8 Merge pull request #63556 from atrick/new-access-base-visitor
Add visitAccessPathBaseUses API
2023-02-09 21:38:54 -08:00
Andrew Trick
049d7856f4 Add visitAccessPathBaseUses API
For the move-only checker
2023-02-09 15:34:56 -08:00
Erik Eckstein
cef6ef9a84 SIL: add a debug_step instruction
This instruction can be inserted by Onone optimizations as a replacement for deleted instructions to
ensure that it's possible to single step on its location.
2023-02-09 06:50:05 +01:00
John McCall
dcf90ba3f3 Merge pull request #63512 from rjmccall/tuple_pack_element_addr
Add the tuple_pack_element_addr SIL instruction
2023-02-08 11:48:23 -05:00
John McCall
159c653780 Add the tuple_pack_element_addr SIL instruction.
This allows dynamically indexing into tuples.  IRGen not yet
implemented.

I think I'm going to need a type_refine_addr instruction in
order to handle substitutions into the operand type that
eliminate the outer layer of tuple-ness.  Gonna handle that
in a follow-up commit.
2023-02-07 23:22:35 -05:00
Andrew Trick
2d91316c06 Merge pull request #63485 from atrick/fix-inner-adjacent
Add visitInnerAdjacentPhis OSSA helper
2023-02-07 11:34:10 -08:00