Commit Graph

2588 Commits

Author SHA1 Message Date
Dario Rexin
2f0726a9a1 [IRGen] Emit swift_enumSimple_destructiveInjectEnumTag 2023-07-06 15:25:11 -07:00
Slava Pestov
fb14aef32a Uncomment fixed FIXMEs in test/Interpreter/variadic_generic_conformances.swift 2023-07-05 16:35:16 -04:00
Slava Pestov
b7a404f86a Executable test for runtime demangling of pack expansions 2023-07-05 16:35:16 -04:00
Pavel Yaskevich
8a1107ea45 [Tests] InitAccessors: Test use of init accessor properties without setters 2023-07-04 00:05:25 -07:00
Michael Gottesman
268cd76ac6 [move-only] Add the moveonly_linkedlist.swift interpreter test.
Both of the previous fixes in this PR were found via this test.
2023-07-03 15:55:13 -07:00
Michael Gottesman
4f24a2f64b [move-only] Rename moveonly_fixedqueue.swift -> moveonly_fixedsizequeue.swift and add some more to the test.
The rename makes it more obvious what the file is testing and I added a bit more
to the test.
2023-06-30 12:26:47 -07:00
Dario Rexin
707330c8bd [IRGen] Emit swift_multiPayloadEnumGeneric_destructiveInjectEnumTag
Assign swift_multiPayloadEnumGeneric_destructiveInjectEnumTag as witness function on generic multi payload enums when using layout strings
2023-06-29 16:34:18 -07:00
Dario Rexin
622f7a26e9 Merge pull request #67022 from drexin/wip-sp-gen-destr-inject-tag
Support destructiveInjectEnumTag in generic single payload enums with layout strings
2023-06-29 16:33:30 -07:00
Ben Barham
844508dcbc [Test] Add executable test requirement to moveonly_fixedqueue.swift
Resolves rdar://111531602.
2023-06-29 14:09:59 -07:00
Dario Rexin
8ccaad1db5 [IRGen] Emit swift_singlePayloadEnumGeneric_destructiveInjectEnumTag
Assign swift_singlePayloadEnumGeneric_destructiveInjectEnumTag as witness function on generic single payload enums when using layout strings
2023-06-29 10:39:54 -07:00
Michael Gottesman
9b59588fc3 [move-only] If we have a guaranteed forwarding instruction with only trivial results, treat it as a liveness use.
The reason why we want to do this is that if we treat it as a true forwarding
use, we will visit the uses of the trivial value and treat those as liveness
uses. Since the trivial value is not tied to the lifetime of the underlying
noncopyable value, this can be outside of the lifetime of said value causing a
memory lifetime error. By just treating the guaranteed forwarding instruction
with all trivial values as a liveness use, we avoid this problem.

I added a SIL test, a Swift test, and an Interpreter test that validates this
behavior.

rdar://111497657
2023-06-29 00:00:05 -07:00
Dario Rexin
3524945cd4 [IRGen+Runtime] Implement getEnumTag for singleton enums in layout strings (#66985) 2023-06-28 14:25:34 -07:00
swift-ci
746dd9823a Merge pull request #66976 from nate-chandler/test/20230627/1
[Test] Commented two tests and added one.
2023-06-28 02:04:07 -07:00
Michael Gottesman
bd90e310e1 Merge pull request #66952 from gottesmm/pr-87fcc78991b465d8a15454dc76b66d6f347ddff0
[move-only] Emit an error if we /ever/ partially consume a noncopyable type.
2023-06-28 01:00:40 -07:00
Doug Gregor
3064412703 Merge pull request #66972 from DougGregor/init-accessors-always-part-of-memberwise-init 2023-06-27 21:50:07 -07:00
Nate Chandler
bd52be8990 [Test] Add for MOAC reinit miscompile.
On recent main, this test case fails verification with

```
SIL memory lifetime failure in @$s4main4doityyF: memory is not initialized, but should be
memory location:   %21 = struct_element_addr %20 : $*M4, #M4.s2    // user: %23
at instruction:   %23 = apply %22(%19, %21) : $@convention(thin) (@inout S, @inout S) -> ()

[...]

4.      While running pass #173 SILFunctionTransform "MoveOnlyChecker" on SILFunction "@$s4main4doityyF".
 for 'doit()' (at test/Interpreter/moveonly_reinit_noncontiguous.swift:32:1)
```
2023-06-27 21:02:18 -07:00
Dario Rexin
ca664141cc [IRGen+Runtime] Add support for initializeBufferWithCopyOfBuffer to layout strings (#66965) 2023-06-27 18:05:30 -07:00
Doug Gregor
fe2dec5ee5 [SE-0400] All properties with init accessors become part of the memberwise init
Per the clarification during the review thread, all properties with
init accessors (including those that do not initialize any underlying
storage) are part of the memberwise initializer.
2023-06-27 17:28:53 -07:00
Michael Gottesman
3dde9df468 [move-only] Emit an error if we /ever/ partially consume a noncopyable type.
The reason why I am doing this is that this was not part of the original
evolution proposal (it was called an extension) and after some discussion it was
realized that partial consumption would benefit from discussion on the forums.

rdar://111353459
2023-06-27 13:52:49 -07:00
Dario Rexin
fc6834daf6 [IRGen+Runtime] Add getEnumTag for layout strings on simple single payload enums (#66941) 2023-06-26 19:32:51 -07:00
Dario Rexin
253d8fbf33 [IRGen+Runtime] Add getEnumTag for layout strings on generic single payload enum (#66911) 2023-06-23 20:43:28 -07:00
nate-chandler
98d895db52 Merge pull request #66892 from nate-chandler/rdar111221183
[MoveOnlyAddressChecker] Fixed two use-before-def handlings.
2023-06-23 19:13:56 -07:00
Dario Rexin
270089f297 [IRGen+Runtime] Layout string getEnumTag for fixed size enums subset (#66899)
* [IRGen+Runtime] Layout string getEnumTag for fixed size enums subset

getEnumTag impl for layout strings of fixed sized enums that use a function to fetch the enum tag

* Fix potential UB in IRGen
2023-06-23 18:10:55 -07:00
Nate Chandler
92fd8da3c3 [FieldSensitivePL] Fixed use-before-def handling.
rdar://111118843
2023-06-23 10:16:53 -07:00
Dario Rexin
36ddb77fcd [IRGen+Runtime] Layout string getEnumTag for generic multi payload enums (#66872)
We already store all necessary information to extract the tag in the layout string, so we should utilize it for the getEnumTag witness
2023-06-22 19:07:50 -07:00
Slava Pestov
3676379302 Merge pull request #66814 from slavapestov/variadic-type-conditional-conformance
Conditional conformances for variadic generic types
2023-06-21 17:52:28 -04:00
Slava Pestov
8742b1a1e2 Runtime: Fix shape requirement handling in _checkGenericRequirements()
We would say the shape requirement was always satisfied since we
incorrectly checked the left-hand side type twice.
2023-06-21 15:03:53 -04:00
Slava Pestov
3052e36f7e Runtime: Fix dynamic casts of variadic types that conditionally conform 2023-06-21 13:42:57 -04:00
Slava Pestov
d1cb9307c9 Runtime: Support for conditional conformances with pack conformance requirements 2023-06-21 13:42:57 -04:00
Joe Groff
26d8d84270 Merge pull request #66651 from jckarter/noncopyable-address-only-borrowed-capture
ClosureLifetimeFixup: Remove copy of borrowed move-only nonescaping captures when possible.
2023-06-21 09:36:18 -07:00
Dario Rexin
493a25faae [IRGen+Runtime] Add layout string support for generic single payload enums (#66791) 2023-06-20 20:46:54 -07:00
swift-ci
0845bc1373 Merge pull request #66789 from nate-chandler/rdar111066023
[Test] Marked execution test requires execution.
2023-06-20 20:19:14 -07:00
Nate Chandler
ac6ec58ada [Test] Marked execution test requires execution.
rdar://111066023
2023-06-20 17:16:43 -07:00
Joe Groff
ed2cbca04f ClosureLifetimeFixup: Remove copy of borrowed move-only nonescaping captures when possible.
SILGen introduces a copy of the capture, because the semantics of escaping partial_apply's
requires the closure to take ownership of the parameters. We don't know when a closure is
strictly nonescaping or its final lifetime until ClosureLifetimeFixup runs, but that replaces
the consume of the copy with a borrow of the copy normally, hoping later passes fix it up.
We can't wait that long for move-only types, which can't be copied, so try to remove the
copy up front when the copy lives long enough and has no interfering uses other than the
partial_apply. rdar://110137169
2023-06-20 12:10:31 -07:00
Andrew Trick
a8c45c55c4 Fix MoveOnlyAddressChecker to handle value deinits.
Track liveness of self so we don't accidentally think that such types
can be memberwise reinitialized.

Fixes rdar://110232973 ([move-only] Checker should distinguish in
between field of single field struct vs parent field itself (was:
mutation of field in noncopyable struct should not trigger deinit))
2023-06-19 18:38:03 -07:00
nate-chandler
d3125898ae Merge pull request #66585 from nate-chandler/rdar99681073
[MoveOnlyAddressChecker] Maximize lifetimes.
2023-06-17 14:00:38 -07:00
Nate Chandler
eaf4560cd7 [MoveOnlyAddressChecker] Maximize lifetimes.
Previously, the checker inserted destroys after each last use.  Here,
extend the lifetimes of fields as far as possible within their original
(unchecked) limits.

rdar://99681073
2023-06-16 21:13:09 -07:00
Dario Rexin
874b577280 [IRGen] Use EnumImplStrategy to generate getEnumTag function for layo… (#66707)
* [IRGen] Use EnumImplStrategy to generate getEnumTag function for layout strings

rdar://110794898

The implementation in TypeLayout seems to have a bug causing wrong tags to be returned on 32 bit systems.

* Don't use unsupported types in tests
2023-06-16 18:14:48 -07:00
Pavel Yaskevich
9d342f1dd0 Merge pull request #66681 from xedin/enable-inits-on-props-with-init-accessors
[Sema/SILGen] InitAccessors: Synthesize default arguments for init accessor properties
2023-06-16 11:24:35 -07:00
Pavel Yaskevich
f58d4077c4 [Sema/SILGen] Consider init exprs associated with init accessor properties for memberwise init 2023-06-15 13:12:16 -07:00
Arnold Schwaighofer
5d5dbd98a4 Merge pull request #66077 from aschwaighofer/wip_enable_opaque_pointers
Enable usage of LLVM's opaque pointer
2023-06-15 11:47:24 -07:00
Dario Rexin
d74c085fe8 [Runtime+IRGen] Add layout string support for generic singleton enums (#66647) 2023-06-14 20:13:15 -07:00
Arnold Schwaighofer
8f7e433c71 Fix LTO test to use just use libLTO.dylib
This is necessary until the Xcode toolchain's libLTO.dylib supports opaque pointers
2023-06-14 10:49:50 -07:00
Pavel Yaskevich
2b8a39724c Merge pull request #66513 from xedin/init-accessor-diagnostics
[Sema/SIL] Improve diagnostics related to init accessors
2023-06-14 09:57:08 -07:00
Dario Rexin
8b48a0d3e0 [Runtime+IRGen] Instantiate layout strings for generic multi payload enum (#66621)
Instantiating layout strings for generic types reduces code size and is expected to improve performance of generic value witnesses.
2023-06-14 09:31:11 -07:00
Pavel Yaskevich
34c8cf60f1 [Sema/SILGen] InitAccessors: Memberwise initializers with init accessors should follow field order
Skip stored properties that are initialized via init accessors and
emit parameters/initializations in field order which allows us to
cover more use-cases.
2023-06-13 13:56:33 -07:00
Pavel Yaskevich
cffc3fd73d [Sema/SILGen] InitAccessors: Don't synthesize memberwise init if initializes intersect
If some property is initializable by one than one init accessor
let's not sythesize a memberwise initializer in that case because
it's ambiguous what is the best init accessor to use.
2023-06-13 12:40:41 -07:00
Pavel Yaskevich
ddcfe01ba5 [Sema/SILGen] InitAccessors: Emit intersecting init accessor calls in memberwise init
If init accessor initialize the same properties, let's emit them
in sequence and emit `destroy_addr` in-between to make sure that
there is no double initialization.
2023-06-13 10:58:50 -07:00
Michael Gottesman
b2a52ff036 [move-only] Do not attempt to lazily deserialize the moveonly deinit table in IRGen.
SIL Functions are serialized in canonical SIL before they have their final ABI
adjusted for large function arguments. Large function argument ABI is adjusted
to be indirect as part of the transition from canonical SIL to lowered SIL. This
means that if we deserialize a function from another module in canonical SIL and
attempt to call it in IRGen we will call it with the wrong ABI implying if we
reference any fields of the type in the deinit we will most likely crash (among
other potential issues).

This patch fixes the issue by changing IRGen to not lazily deserialize the
moveonly deinit table and its associated functions. Instead if we do not have
our table already deserialized, we just call the function's deinit via the
destroy value deinit table.

rdar://110496872
2023-06-09 15:41:38 -04:00
Pavel Yaskevich
aaa72612bf [Tests] InitAccessors/NFC: add interpreter tests for different configurations of init accessors 2023-06-06 18:59:46 -07:00