Commit Graph

1057 Commits

Author SHA1 Message Date
John McCall
d5142668f4 SIL and IRGen support for @isolated(any). SILGen to come. 2024-02-13 03:04:13 -05:00
Joe Groff
0365c6abba MoveOnlyAddressUtils: Fixes for borrowing switch over address-only types.
Relax some existing pattern matches and add some unhandled instructions to the
walkers so that borrowing switches over address-only enums are properly analyzed
for incorrect consumption. Add a `[strict]` flag to `mark_unresolved_move_only_value`
to indicate a borrow access that should remain a borrow access even if the subject
is later stack-promoted from a box.
2024-02-12 20:20:50 -08:00
Nate Chandler
b535725647 [NFC] SIL: Renamed SpecifyTestInst.
The instruction's spelling was changed to `specify_test` but the class
name wasn't updated from `TestSpecificationInst`.  Update it here.
2024-02-06 16:29:09 -08:00
Joe Groff
b847528c55 Merge pull request #71305 from jckarter/borrowing-switch-4
BorrowToDestructureUtils: handle borrowing switches.
2024-02-01 09:20:56 -08:00
Joe Groff
03e2e8f476 BorrowToDestructureUtils: handle borrowing switches.
Instead of trying to convert all switches into consumes, allow a switch of a borrow
to remain as such.
2024-01-31 20:38:22 -08:00
Erik Eckstein
3b239b25f3 swift SIL: add Function thunk APIs
* `var thunkKind`
* `set(thunkKind:)`
2024-01-31 17:16:13 +01:00
Nate Chandler
bb69df48f7 NFC: [MemAccessUtils] Tweaked API.
Previously, `visitProductLeafAccessPathNodes` required its caller to
provide both an `AccessPath` `path` and an `SILValue` `address` which
satisfied `path == AccessPath::compute(address)` to force the caller to
handle the case of an invalid `AccessPath`.  Now, instead, it computes
the value itself and returns false if it's invalid.

It could be tweaked to also return false if the provided lambda returned
false but that would make the only currently extant callers less
pleasant and also would not be sufficient in the case of caller who
wanted to distinguish between an invalid `AccessPath` and a particular
leaf visit returning false.
2024-01-25 14:18:44 -08:00
nate-chandler
fe39e69cae Merge pull request #71138 from nate-chandler/alias-analysis-builtin
[DestroyAddrHoisting] Don't fold for invalid paths.
2024-01-25 12:56:30 -08:00
Nate Chandler
7219914af3 [DestroyAddrHoisting] Don't fold for invalid paths
If the address for which hoisting is being performed doesn't have an
invalid access path don't attempt to fold its destroy_addrs.

rdar://121486203
2024-01-24 17:26:07 -08:00
Andrew Trick
37171e698a Handle mark_dependence [nonescaping] like a borrowing instruction. 2024-01-22 23:57:03 -08:00
Andrew Trick
e271973246 Fix FunctionTest memory corruption in SwiftCompilerSouces.
A FunctionTest created in Swift source has no persistent storage
address. This results in sporadic crashes when running unit tests.

Fix the FunctionTest registry to store the value of the test.

Eventually, we could probably rig something up with @_rawLayout, but
it makes more sense for FunctionTest to be a value type anyway.
2024-01-20 09:44:23 -08:00
Andrew Trick
5e9123978c Fix compiler Test Registry to use a StringMap.
We have no guarantee that the StringRef passed to the registry lives
in the static data segment.

This resulted in memory corruption during bootstrapping, which is
particularly difficult to diagnose and reproduce.
2024-01-20 07:51:06 -08:00
Nate Chandler
d538894203 [AddressLowering] Handle copyable_to_moveonly.
The _value version of the instruction lowers to the _address version.
2024-01-18 07:30:23 -08:00
Nate Chandler
99df40a6d1 [AddressLowering] Handle moveonly_to_copyable.
The _value version of the instruction lowers to the _address version.
2024-01-18 07:30:23 -08:00
Slava Pestov
14d1fcb51a AST: TypeChecker::conformsToProtocol() => ModuleDecl::checkConformance() 2024-01-16 17:08:00 -05:00
Allan Shortlidge
95a3bb8bbf NFC: Suppress a -Wimplicit-fallthrough warning in InstructionUtils.cpp. 2024-01-12 18:01:42 -08:00
Allan Shortlidge
42aab7451b SIL: Remove swift3ImplicitObjCEntrypoint built-in.
With the removal of `-enable-swift3-objc-inference`, no calls to the
`swift3ImplicitObjCEntrypoint` built-in should be generated anymore.
2024-01-11 15:40:04 -08:00
Zoe Carver
ae1fe78769 Merge pull request #70815 from zoecarver/perf-annotation-ns-direct-exception 2024-01-11 07:36:34 -07:00
zoecarver
0815ca8210 [perf diagnostics] objc_direct calls should not have objc runtime effects. 2024-01-10 10:58:48 -07:00
Yuta Saito
7cccbcc84f [DiscardingTG] Remove reabstraction thunk for () -> Void to () -> T (#70537)
Concurrency runtime expects discarding task operation entrypoint
function not to have result type, but the current SILGen
implementation generates reabstraction thunk to convert `() -> Void`
to `() -> T` for the operation function.

Since the `T` is always `Void` for DiscardingTG, the mismatch of result
type expectation does not cause any problem on most platforms, but the
signature mismatch causes a problem on WebAssembly.

This patch introduces new builtin operations for creating discarding
task, which always takes `() -> Void` as the operation function type.
2024-01-10 07:17:15 +09:00
nate-chandler
7365f9f36b Merge pull request #70774 from nate-chandler/nfc/20240108/1/deinit-barrier-component-predicates
[NFC] SIL: Clarified deinit barrier APIs.
2024-01-08 23:11:38 -08:00
nate-chandler
ecca144c39 Merge pull request #70773 from nate-chandler/rdar120656227
[SIL] Builtins that read or write memory may access pointers.
2024-01-08 19:24:38 -08:00
Nate Chandler
82b7495bb1 [NFC] SIL: Clarified deinit barrier APIs.
An instruction is a deinit barrier whenever one of three component
predicates is true for it.  In the case of applies, it is true whenever
one of those three predicates is true for any of the instructions in any
of its callees; that fact is cached in the side-effect analysis of every
function.

If side-effect analysis or callee analysis is unavailable, in order to
define each of those three component predicates on a
`FullApplySite`/`EndApplyInst`/`AbortApplyInst`, it would be necessary
to define them to conservatively return true: it isn't known whether any
of the instructions in any of the callees were deinit barriers.

Refactored the two versions of the deinit barrier predicate (namely
`Instruction.isDeinitBarrier(_:) and
`swift::mayBeDeinitBarrierNotConsideringSideEffects`) to handle
`FullApplySite`/`EndApplyInst`/`AbortApplyInst`s specially first (to
look up the callees' side-effect and to conservatively bail,
respectively).  Asserted that the three component predicates are not
called with `FullApplySite`/`EndApplyInst`/`AbortApplyInst`s.  Callers
should instead use the `isDeinitBarrier` APIs.

An alternative would be to conservatively return true from the three
components.  That seems more likely to result in direct calls to these
member predicates, however, and at the moment at least there is no
reason for such calls to exist.  If some other caller besides the
deinit-barrier predicates needs to call this function, side-effect
analysis should be updated to cache these three properties separately at
that point.
2024-01-08 15:25:24 -08:00
Nate Chandler
f765f557ed [NFC] SIL: Define deinit barrier preds on builtins
The three predicates are all now defined and defined correctly on
builtins to return true whenever mayReadOrWriteMemory is true.
2024-01-08 15:23:13 -08:00
Nate Chandler
77fd37be99 [NFC] SIL: Renamed maySynchronize.
Dropped the NotConsideringSideEffects suffix.
2024-01-08 13:35:20 -08:00
Nate Chandler
a00bb276d1 [SIL] Builtins that read/write mem may access ptr.
When an instruction `mayReadOrWriteMemory`, the `mayAccessPointer`
predicate relies on the `visitAccessedAddress` utility to determine
whether an instruction may access a pointer.  That utility doesn't (and
can't, without changing the representation of the builtin) visit
`RawPointer` operands as used by memmove/memcpy builtins.

Previously, this resulted `mayAccessPointer` returning `false` for such
builtins.  Here, this is fixed by making the predicate handle
`BuiltinInsts` separately.  Instead of just always returning `true` in
the face of a builtin, rely on the BuiltinInfo associated with a
BuiltinInst and use `mayReadOrWriteMemory`.

rdar://120656227
2024-01-08 12:56:53 -08:00
Michael Gottesman
8178eb0a6e Merge pull request #70514 from gottesmm/pr-763529d8ee9f4164b82d03087fec25439cc1d315
[region-isolation] Fix the dataflow and add support for project_block_storage
2023-12-19 10:21:59 -08:00
Michael Gottesman
7712639ab0 [region-isolation] Add support for project_block_storage.
rdar://119743743
2023-12-18 09:35:57 -08:00
Andrew Trick
b637f06acd [SIL] Bridge findPointerEscape() and fix OnoneSimplifyable
Do not bridge the hasPointerEscape flag until it is implemented.
2023-12-18 09:16:55 -08:00
Michael Gottesman
09151bd800 [region-isolation] Add lookthrough support for a bunch of instructions.
Specifically:

* MoveValueInst
* MarkUnresolvedNonCopyableValueInst
* MarkUnresolvedReferenceBindingInst
* CopyableToMoveOnlyWrapperValueInst
* MoveOnlyWrapperToCopyableValueInst
* MoveOnlyWrapperToCopyableBoxInst
* MoveOnlyWrapperToCopyableAddrInst
* CopyableToMoveOnlyWrapperAddrInst
* MarkUninitializedInst
2023-12-14 19:11:06 -08:00
Alejandro Alonso
f365316d74 Merge pull request #70327 from Azoy/inject-get-enum-tag-builtins
[IRGen] Add getEnumTag and injectEnumTag builtins
2023-12-12 16:07:56 -08:00
Konrad `ktoso` Malawski
828f589be4 Initial Task Executor implementation Task(on:), addTask(on:) etc. (#68793)
Co-authored-by: John McCall <rjmccall@gmail.com>
2023-12-12 17:14:24 +09:00
Alejandro Alonso
0ed4a19c73 Don't check inject enum tag's 2nd operand 2023-12-11 10:58:31 -08:00
Alejandro Alonso
49b0a23561 Add getEnumTag and injectEnumTag builtins 2023-12-11 10:58:29 -08:00
Erik Eckstein
dd9ce40ba1 add the allocVector builtin 2023-12-09 18:49:57 +01:00
Erik Eckstein
e652f2c92e SIL: add the alloc_vector and vector instructions
* `alloc_vector`: allocates an uninitialized vector of elements on the stack or in a statically initialized global
* `vector`: creates an initialized vector in a statically initialized global
2023-12-09 18:49:55 +01:00
eeckstein
10ff55b2b3 Merge pull request #70155 from eeckstein/refactoring
MemoryLifetimeVerifier: use CalleeCache instead of AliasAnalysis
2023-12-04 08:53:59 +01:00
Erik Eckstein
e80fedc52a move CalleeCache from SILOptimizer to SIL
Extract the CalleeCache from BasicCalleeAnalysis so that it can be used in SIL without BasicCalleeAnalysis
2023-12-01 19:20:18 +01:00
zoecarver
69498e2f2e [opt] Add three new perf annotations: @_noRuntime, @_noExistential, and @_noObjCBridging. 2023-12-01 09:13:24 -07:00
Erik Eckstein
6f6c0a5608 SwiftCompilerSources: add a few enum related APIs in Type and Builder
* `Type.getEnumCases`
* `Builder.createUncheckedTakeEnumDataAddr`
* `Builder.createSwitchEnumAddr`
2023-11-27 09:21:33 +01:00
Erik Eckstein
263f4d4cde SILBridging: remove writeCharToStderr
It's not needed
2023-11-27 09:21:33 +01:00
Nate Chandler
73d57c9012 [Test] Avoid LSAN report of leaked FunctionTest.
Avoid heap-allocating an immortal FunctionTest with `new` because it
results in LSAN reporting a leak.

In fact, the "leaked" value wasn't leaked: a reference to it was stored
in a global map when the type's constructor ran.  It was only a leak in
the sense that it was never freed, not that there was a dangling
allocation which couldn't be freed.

Work around this by storing the global instances themselves in a second
static structure.  Store pointers to the instances into the global map
as before.

rdar://118134637
2023-11-14 15:05:18 -08:00
Michael Gottesman
48b4ca0b24 Merge pull request #69686 from gottesmm/rdar117880194
[region-isolation] When assigning RValues into memory, use tuple_addr_constructor instead of doing it in pieces.
2023-11-07 20:15:58 -08:00
Michael Gottesman
b1f69030fc [region-isolation] When assigning RValues into memory, use tuple_addr_constructor instead of doing it in pieces.
I also included changes to the rest of the SIL optimizer pipeline to ensure that
the part of the optimizer pipeline before we lower tuple_addr_constructor (which
is right after we run TransferNonSendable) work as before.

The reason why I am doing this is that this ensures that diagnostic passes can
tell the difference in between:

```
x = (a, b, c)
```

and

```
x.0 = a
x.1 = b
x.2 = c
```

This is important for things like TransferNonSendable where assigning over the
entire tuple element is treated differently from if one were to initialize it in
pieces using projections.

rdar://117880194
2023-11-07 15:38:33 -08:00
Kuba Mracek
2936a33680 [embedded] Wrap SwiftCompilerSources initialization state into swiftModulesInitialized API 2023-11-07 10:00:53 -08:00
Kuba Mracek
f0dd174df3 [embedded] Require SwiftCompilerSources to use embedded Swift 2023-11-07 10:00:53 -08:00
Michael Gottesman
6a65c7829e [sil] Add tuple_addr_constructor an instruction that can be used to initial a tuple in memory from individual address and object components.
This commit just introduces the instruction. In a subsequent commit, I am going
to add support to SILGen to emit this. This ensures that when we assign into a
tuple var we initialize it with one instruction instead of doing it in pieces.
The problem with doing it in pieces is that when one is emitting diagnostics it
looks semantically like SILGen actually is emitting code for initializing in
pieces which could be an error.
2023-11-06 15:32:05 -08:00
Slava Pestov
05271d388d Merge pull request #69529 from slavapestov/sil-throw-addr
SILGen support for throwing indirect errors
2023-10-31 21:12:00 -04:00
Slava Pestov
05ccd9734c SIL: Introduce ThrowAddrInst 2023-10-31 16:58:54 -04:00
Hamish Knight
5d99fe63e9 Rename get() -> unbridged() on bridging wrappers 2023-10-31 11:06:39 +00:00