Commit Graph

6583 Commits

Author SHA1 Message Date
Michael Gottesman
29672c503a Merge pull request #66381 from gottesmm/noimplicitcopy-borrow-consuming
[borrowing/consuming] Make borrowing and consuming parameters no implicit copy.
2023-06-06 21:41:18 -04:00
Slava Pestov
c30f7dcdd8 Merge pull request #66096 from slavapestov/pack-element-type
Preliminary support for substitution with nested pack expansions
2023-06-06 19:11:52 -04:00
Michael Gottesman
59c8cff917 [borrowing] Add support for borrowing/consuming copyable types to be a noimplicitcopy type.
rdar://108383660
2023-06-06 18:12:29 -04: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
Slava Pestov
ec3aa5c9d7 SIL: Preliminary AbstractionPattern support for PackElementType 2023-06-06 14:18:37 -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
Andrew Trick
85317c6e8f [move-only] Fix dead code elimination to preserve value deinits. 2023-06-06 09:17:53 -07:00
Andrew Trick
521f0ffc9e [move-only] Verify drop_deinit
drop_deinit only exists in ownership SIL. Remove IRGen support.

A drop_deinit can only ever be destroyed or destructured.

A destructure of a struct-with-deinit requires a drop_deinit operand.
2023-06-06 09:17:53 -07:00
swift-ci
4ef135cc10 Merge pull request #66201 from nate-chandler/dealloc-on-stack-packs
[IRGen] Dealloc on-stack metadata/wtable packs on the dominance frontier.
2023-06-05 13:30:18 -07:00
Nate Chandler
27bc860cd9 [SILType] Added has[..]Pack conveniences. 2023-06-05 08:11:28 -07:00
Nate Chandler
fd45076a02 [SIL] Added no-stack-pack-metadata annotation. 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
Nate Chandler
ee3cbde8fe [SIL] computeDominatedBoundaryBlocks on non-OSSA.
The algorithm requires no critical edges, but that doesn't mean
require ownership.  Remove the assert to allow the utility to be called
from code where the caller has manually split edges.

In the fullness of time, there should no passes should introduce
critical edges.
2023-06-05 08:11:28 -07:00
Meghana Gupta
ed78fe06d7 Merge pull request #66304 from meg-gupta/fixcreateallocboxpr
Remove #ifndef on skipVarDeclAssert in SILBuilder::createAllocBox signature
2023-06-04 23:02:17 -07:00
Doug Gregor
2c98c7d13c [SIL Builder] Don't try to micro-optimize away a bool parameter with NDEBUG 2023-06-03 10:01:19 -07:00
swift-ci
b69004d25f Merge pull request #66300 from nate-chandler/nfc/20230602/1/type-lowering-nits
[TypeLowering] NFC: Two small cleanups.
2023-06-02 12:02:07 -07:00
Meghana Gupta
f08720b04e Remove #ifndef on skipVarDeclAssert in SILBuilder::createAllocBox signature 2023-06-02 11:57:17 -07:00
Nate Chandler
78d85336a5 [TypeLowering] NFC: Fixed type.
It happened not to matter because some other enum : bool was being
constructed/returned and it was only ever used when being converted to
bool.
2023-06-02 07:27:59 -07:00
Slava Pestov
fd81f8135d Merge pull request #66294 from slavapestov/pack-element-type-part-2
PackElementType changes, part 2
2023-06-02 07:32:54 -04:00
Meghana Gupta
1122050658 Merge pull request #66187 from meg-gupta/escapeflags
Add pointer_escape flag to move_value/begin_borrow/alloc_box
2023-06-01 16:59:21 -07:00
Andrew Trick
c4b6710822 Merge pull request #66279 from atrick/fix-dropdeinit-sideeffect
Fix drop_deinit side effects.
2023-06-01 16:24:23 -07:00
Slava Pestov
5e7a91d62a SIL: Generalize SILType::subst() to take SubstOptions 2023-06-01 19:20:11 -04:00
Andrew Trick
af49f62d63 Fix drop_deinit side effects.
rdar://109863801 ([move-only] DCE removes drop_deinit, so user-defined
deinitializers call themselves recursively at -O)
2023-06-01 09:46:59 -07:00
Adrian Prantl
958a1577b5 Ensure calls to getters have a source location.
Calls to getters are implicit because the compiler inserts them on a property
access, but the location is useful in backtraces so it should be preserved.

rdar://109123395
2023-05-31 17:41:26 -07:00
Meghana Gupta
73c962f190 Add pointer_escape flag to move_value/begin_borrow/alloc_box 2023-05-30 12:45:26 -07:00
Michael Gottesman
1d04df9155 [move-only] Teach deinit devirtualization how to handle devirtualizing a deinit of a resilient type.
Specifically, such a type has an @in convention for its deinit and the pass was
setup expecting self to always be @owned.

rdar://109904633
2023-05-27 22:07:04 -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
Meghana Gupta
2c6139dce4 Rename SILArgument::isEscaping -> SILArgument::hasPointerEscape 2023-05-26 15:58:30 -07:00
Kuba (Brecka) Mracek
2d5f33e2e3 Add @_used and @_section attributes for global variables and top-level functions (#65901)
* Add @_used and @_section attributes for global variables and top-level functions

This adds:
- @_used attribute that flags as a global variable or a top-level function as
  "do not dead-strip" via llvm.used, roughly the equivalent of
  __attribute__((used)) in C/C++.
- @_section("...") attribute that places a global variable or a top-level
  function into a section with that name, roughly the equivalent of
  __attribute__((section("..."))) in C/C++.
2023-05-26 14:02:32 -07:00
eeckstein
1a84fc72b0 Merge pull request #66118 from eeckstein/global-enums
Optimizer/IRGen: allow enums in static initializers of globals
2023-05-26 07:23:29 +02:00
Joe Groff
ba67156608 Merge pull request #66091 from jckarter/debug-info-inout-move-only
Emit updated debug info when inout parameters are consumed and reinitialized.
2023-05-25 11:32:03 -07:00
Erik Eckstein
d02765fd54 Swift SIL: some new APIs and some refactoring 2023-05-25 16:28:41 +02:00
Allan Shortlidge
a59f5257b3 Merge pull request #66069 from tshortli/unavailable-enum-payloads
IRGen: Exclude unavailable enum cases from runtime layout calculations
2023-05-24 17:22:08 -07:00
Joe Groff
9db359985d Emit updated debug info when inout parameters are consumed and reinitialized.
Change SILGen to emit the `debug_value` instruction using the original inout
parameter address, instead of the `mark_must_check` inserted for move-only
parameters, because code in the MoveOnlyAddressChecker did not expect to
find the debug_value anywhere but on the original address. Update move-only
diagnostics so that they pick up the declaration name for a memory location
from any debug_value instruction if there are more than one. rdar://109740281
2023-05-24 12:15:53 -07:00
Allan Shortlidge
ce97377218 IRGen: Exclude unavailable enum cases from runtime layout calculations.
When `-unavailable-decl-optimization=complete` is specified, exclude
unavailable enum cases from the runtime layout of enums with payloads. Without
this, the type metadata for unavailable types may be referenced by enum cases
with unavailable payloads and cause linker failures.

Resolves rdar://107483852
2023-05-22 21:49:41 -07:00
Erik Eckstein
a80d0cb8a7 remove now unused utilities
* StaticInitCloner
* some APIs in SILGlobalVariable
2023-05-22 15:34:26 +02:00
Erik Eckstein
38de5b1ab5 Swift SIL/Optimizer: implement cloning of static init values of globals in Swift
* add the StaticInitCloner utility
* remove bridging of `copyStaticInitializer` and `createStaticInitializer`
* add `Context.mangleOutlinedVariable` and `Context.createGlobalVariable`
2023-05-22 15:34:26 +02:00
Erik Eckstein
ee1c52bc77 Swift SIL: add some APIs 2023-05-22 15:34:26 +02:00
Erik Eckstein
b707b5a595 Swift SIL: improve the Builder
* add new create-functions for instructions
* allow the Builder to build static initializer instructions for global variables
* some refactoring to simplify the implementation
2023-05-22 15:34:26 +02:00
Erik Eckstein
a4225a9088 Swift SIL: add a few SIL instructions and instruction APIs 2023-05-22 15:34:26 +02:00
Erik Eckstein
54aacf64e1 SIL: don't allow upcast to be done on address types
It's not needed and just complicates the SIL
2023-05-22 15:34:26 +02:00
eeckstein
570c364cc4 Merge pull request #66021 from eeckstein/fix-read-only-var-pass
ReadOnlyGlobalVariables: don't convert external global vars to lets
2023-05-20 18:57:49 +02:00
Joe Groff
31032b9cae Merge pull request #65992 from jckarter/debug-info-for-move-only-reinitialization
MoveOnlyAddressChecker: Reintroduce debug info for variables after reassignment.
2023-05-19 09:51:42 -07:00
Erik Eckstein
7bbf66ab5b ReadOnlyGlobalVariables: don't convert external global vars to lets
Because we don't know if external variables will be written

Fixes a miscompile
rdar://109476745
2023-05-19 18:28:22 +02:00
Joe Groff
51f75c99a4 MoveOnlyAddressChecker: Reintroduce debug info for variables after reassignment.
After a value is consumed, we emit a `debug_value undef` to indicate that the
variable value is no longer valid to the debugger. However, once a value is
reassigned, it becomes valid again, so emit a `debug_value %original_address` to
reassociate the variable with the valid memory location. rdar://109218404
2023-05-18 15:08:59 -07:00
Andrew Trick
91c4efea95 Move the LoadOperation abstraction to InstructionUtils.h
This is a fundamental abstraction over loads. It was in
OwnershipOptUtils because load_borrow happens to be restricted by
OSSA. Passes should not include OwnershipOptUtils just because they
work with loads.
2023-05-15 15:20:57 -07:00
swift-ci
cd06759029 Merge pull request #65835 from meg-gupta/newflags
Add new flags "reborrow" and "escaping" to SILArgument.
2023-05-11 17:27:36 -07:00
Meghana Gupta
1dc713e2f7 Add new flags "reborrow" and "escaping" to SILArgument.
"reborrow" flag on the SILArgument avoids transitive walk over the phi operandsi
to determine if it is a reborrow in multiple utilities.
SIL transforms must keep the flag up-to-date by calling SILArgument::setReborrow.
SILVerifier checks to ensure the flag is not invalidated.

Currently "escaping" is not used anywhere.
2023-05-11 12:31:37 -07:00
Erik Eckstein
b9169064c6 Swift SIL: add some APIs
* `Options.assertConfiguration`
* `Argument.isIndirectResult`
* in `Function`: `selfArgument`, `isTransparent`, `performanceConstraints` and `inlineStrategy`
* `BuiltinInst.substitutionMap`
* `SubstitutionMap.replacementTypes`
* `Type.canBeClass`
2023-05-11 08:11:44 +02:00