Commit Graph

2588 Commits

Author SHA1 Message Date
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
Dario Rexin
5cbf9f9641 [IRGen] Handle complex single payload enum cases (#66289)
* [IRGen] Handle complex single payload enum cases

rdar://110138498

Handles single payload enum cases with more complex bit patterns (e.g. >64 bits or scattered) by storing a relative pointer to a function that reads the tag.

* Use proper symbol for enum tag helper
2023-06-02 11:49:57 -07:00
Dario Rexin
e6fe6befe7 [IRGen] Include extra tag bytes in offset in layout strings (#66259)
rdar://110088270

When extra tag bytes are used in single payload enums, the generated layout string does not include the tag bytes in its offset after the enum payload. This causes subsequent ref count operations to use the wrong memory location.
2023-05-31 20:54:47 -07:00
Dario Rexin
5db2b28420 [Runtime] Handle single payload enums in swift_resolve_resilientAccessors (#66218)
rdar://109803119

It is sufficient to skip the header, because everything after that are regular ref counts
2023-05-30 18:27:00 -07:00
Allan Shortlidge
0e7ad1e9a4 Frontend: Don't append -target-min-inlining-target target to implicit module builds.
When performing an implicit module build, the frontend was prepending
`-target-min-inlining-target target` to the command line. This was overriding
the implicit `-target-min-inlining-target min` argument that is implied when
`-library-level api` is specified. As a result, the wrong overload could be
picked when compiling the body of an inlinable function to SIL for emission
into the client, potentially resulting in crashes when the client of the module
is back deployed to an older OS.

Resolves rdar://109336472
2023-05-30 13:33:26 -07:00
Sophia Poirier
0594efc0ce Merge pull request #66214 from sophiapoirier/tuple-expansion-without-dot-element
[Variadic Generics] drop requirement of .element for tuple expansion
2023-05-30 16:29:55 -04:00
Sophia Poirier
93864f6c15 [Variadic Generics] drop requirement of .element for tuple expansion rdar://107160966 2023-05-30 11:37:55 -04:00
Michael Gottesman
c0ce58c9a3 [move-only] Make sure to run the moveonly interpreter test also at -Onone so we can make sure it works even without opts. 2023-05-28 19:42:55 -07:00
Michael Gottesman
a52302d384 Some misc fixes for tests. 2023-05-27 23:29:56 -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
Daniel Rodríguez Troitiño
8f0382c109 [test] Replace swift_obj_root for alternates that work in LLVM unified builds (#66167)
In LLVM unified builds `%swift_obj_root` points to `<LLVM build dir>/tools/swift`,
and folders like `bin`, `lib` and `share` are not under `swift_obj_root`, which
makes some tests fail.

For the cases in which `%swift_obj_root/lib` was used, replace it by
using `%swift-lib-dir` instead. Replicate `%swift-lib-dir` to create
`%swift-bin-dir` and `%swift-share-dir`, and use those instead of
`%swift_obj_root/bin` and `%swift_obj_root/share`.

This alternates work both in Swift build-script builds and also in LLVM
unified builds.
2023-05-26 08:39:31 -07: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
Dario Rexin
97381e6411 [IRGen] Support additional single payload enum cases in layout strings (#66042)
* [IRGen] Support additional single payload enum cases in layout strings

rdar://105837101

Adds layout string support for single payload enums with simple (non-scattered) extra inhabitant patterns

* Add more test cases
2023-05-23 13:17:51 -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
Kavon Farvardin
7ad1683ac9 Merge pull request #66005 from kavon/optimize-noncopyables
add optimizations-on variants directly in the noncopyable tests
2023-05-22 21:40:33 -07:00
Kavon Farvardin
37cc8cb174 add optimizations-on variants directly in noncopyable tests 2023-05-22 17:17:52 -07:00
Slava Pestov
31bfa4b78c Merge pull request #65936 from slavapestov/se-0398-accepted
Unconditionally enable variadic generic types now that SE-0398 has been accepted
2023-05-16 07:34:31 -04:00
Kavon Farvardin
7816138cf4 Merge pull request #65931 from kavon/discard-generics-v2
more `discard` fixes in Sema
2023-05-15 21:17:07 -07:00
Slava Pestov
e9e6a51c82 Unconditionally enable variadic generic types now that SE-0398 has been accepted 2023-05-15 23:32:52 -04:00
Kavon Farvardin
da9847a841 fix typechecking for discard in generics
Don't use `getDeclaredTypeInContext` it gives
the wrong types for generic params.

rdar://108975216
2023-05-15 15:37:23 -07:00
Slava Pestov
b6a2791de9 Merge pull request #65899 from slavapestov/variadic-type-availability
Variadic type availability
2023-05-15 17:09:21 -04:00
Slava Pestov
541c5d396d Merge pull request #65884 from slavapestov/parameter-packs-backward-deployment
Backward deployment shim for swift_allocate{Metadata,WitnessTable}Pack()
2023-05-13 09:17:49 -04:00
Slava Pestov
4318a36be6 Sema: Availability checking for variadic generic types 2023-05-12 22:50:25 -04:00
swift-ci
bc9acf98d8 Merge pull request #65840 from kavon/async-requirement-matching
Witness selection should pick exact matches for effect overloads
2023-05-12 14:14:42 -07:00
Slava Pestov
c2338aa0f6 Backward deployment shim for swift_allocate{Metadata,WitnessTable}Pack() 2023-05-12 15:44:12 -04:00
Kavon Farvardin
3ae2ce5a7f Witness selection should pick exact matches for effect overloads
You can overload a function based on its `async`-ness, and
resolution is carried out based on async-ness of calling
context.

But during protocol conformance checking, for an `async`
requirement we were accidentally choosing the non-`async
overload instead of the `async` one. The `async` one is
the choice people would expect, since the `async` requirement
is in essence the "context" that forwards to the underlying
witness. This intended behavior is also inferred from:

https://github.com/apple/swift/pull/40088

The problem boiled down to a bad check when categorizing the
witness matches prior to ranking them.

Resolves rdar://109135488 / https://github.com/apple/swift/issues/60318
2023-05-12 11:03:48 -07:00
Kavon Farvardin
3e4bc82aa8 rename _forget to discard; deprecate _forget
SE-390 concluded with choosing the keyword discard rather than forget for
the statement that disables the deinit of a noncopyable type. This commit
adds parsing support for `discard self` and adds a deprecation warning for
`_forget self`.

rdar://108859077
2023-05-08 21:42:19 -07:00
Kavon Farvardin
c260792e73 Merge pull request #65690 from kavon/forget-usage-fixes
`_forget` usage fixes to match SE-390
2023-05-06 11:50:10 -07:00
Slava Pestov
ebb99e5e84 SILGen: Wrap captures of parameter packs inside tuples
Fixes rdar://problem/108481933.
2023-05-05 22:45:03 -04:00
Kavon Farvardin
7ac3ea02a6 make it illegal to use _forget in an initializer
we decided against allowing it for now.

rdar://108877261
2023-05-05 14:50:48 -07:00
Dario Rexin
6d031cbada [IRGen] Respect optionality of unowned(unsafe) reference properties (#65663)
* [IRGen] Respect optionality of unowned(unsafe) reference properties

rdar://108705703

When generating the type info for fields marked unowned(unsafe) of an optional reference (e.g. AnyObject?), we dropped the fact that it was optional along the way. This caused incorrect tags to be returned when on object of the type was stored in an optional itself and the unowned property contained `nil`. In those cases the outer optional appeared to be `nil` as well, even if it in fact contained a value.

* Fix additional case
2023-05-05 09:37:46 -07: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
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
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
Michael Gottesman
a0a3aecd4d [move-only] Add some execution tests that use generics. 2023-05-02 16:30:33 -07:00
Slava Pestov
9c68aaac2d Merge pull request #65466 from slavapestov/irgen-vanishing-tuple
IRGen: Unwrap one-element tuple metadata in emitDynamicTupleTypeMetadataRef()
2023-05-01 18:15:12 -04:00
Slava Pestov
75cea742a5 IRGen: Unwrap one-element tuple metadata in emitDynamicTupleTypeMetadataRef()
This matches the static behavior of Type::subst() and the SIL optimizer.
2023-05-01 14:46:04 -04:00
Karoy Lorentey
b82ce9c3be [stdlib] Adopt _pointerBitWidth conditional 2023-04-27 13:33:24 -07:00
Julian Lettner
0ce8bfaaec [Sanitizers] Remove obsolete LIT substitution (#65420)
Co-authored-by: Julian Lettner <julian.lettner@apple.com>
2023-04-27 10:41:10 -07:00
Michael Gottesman
739417ff09 [move-only] Convert __shared to borrowing in move only tests.
These are the same semantically, just the mangling is slightly different. The
benefit of doing this is that we are actually testing what we expect our users
to do.

rdar://108511703
2023-04-25 10:51:04 -07:00
Michael Gottesman
9a0b9665f1 [move-only] When emitting accesses to let boxes containing a noncopyable type, always emit mark_must_check.
The reason to do this is that:

1. Otherwise, we do not emit markers when someone attempts to consume the let.
We need the no_consume_or_assign to be there.
2. We need to insert assign_but_not_consuming so that DI can properly check lets
that are conditionally initialized and convert them to
initable_but_not_consuming.

I included a full definite_init SIL test that validates that we get the correct
codegen after DI in this case and emit the appropriate error as well.

rdar://108511534
2023-04-25 10:51:04 -07:00
Michael Gottesman
438974a2b9 [move-only] When emitting borrows for move only types, use a load [copy] instead of a load_borrow.
The reason why I am doing this is that otherwise if one has a function that
takes both a guaranteed and an owned parameter, we will break OSSA invariants
since the load [take] will invalidate the load_borrow. So instead, we put in a
load_borrow knowing that the move checker will convert it to a load_borrow
assuming that the two pass exclusivity checking.

NOTE: Because of some missing functionality in subsequent tests, I had to
disable one test (moveonly_escaping_definite_initialization.swift) and also add
some checks for copy of noncopyable object errors. They will go away in the next
2 commits.

rdar://108510987
2023-04-25 10:51:03 -07:00
Dario Rexin
022311e438 [IRGen] Fix layout string generation for pre-specialized metadata (#65162)
* [IRGen] Fix layout string generation for pre-specialized metadata

rdar://108012057

Pre-specialized metadata has to be specifically handled by using the bound generic type instead of the unbound one. All the necessary information is already being passed down as BoundGenericTypeCharacteristics, we just need to apply them when present.

* Add tests and a few fixes

* Fixes after rebase

* Attempt to fix Windows linker issue in test
2023-04-20 13:26:41 -07:00
Joe Groff
f045829068 Merge pull request #65302 from jckarter/borrow-moveonly-lvalue-base
SILGen: Emit move-only bases for lvalues in a borrow scope.
2023-04-20 09:28:56 -07:00
Joe Groff
cb23187209 SILGen: Emit move-only bases for lvalues in a borrow scope.
Normally, if we project from a mutable class ivar or global variable, we'll
load a copy in a tight access scope and then project from the copy, in order to
minimize the potential for exclusivity violations while working with classes and
copyable values. However, this is undesirable when a value is move-only, since
copying is not allowed; borrowing the value in place is the expected and only possible
behavior. rdar://105794506
2023-04-19 14:50:34 -07:00
Joe Groff
8ea5ab84d3 Merge pull request #65173 from jckarter/noncopyable-tuples-not-supported
Diagnose attempts to use tuples with noncopyable elements.
2023-04-17 10:49:53 -07:00
Holly Borla
e48a9b5aeb [NFC] Remove the VariadicGenerics flag from tests that don't use generic types
with parameter packs.
2023-04-15 17:48:08 -07:00
Joe Groff
52e97d6544 Diagnose attempts to use tuples with noncopyable elements.
These aren't fully supported yet. rdar://108024586
2023-04-14 16:49:30 -07:00
Dario Rexin
883750e908 [IRGen] Reject enums with inaccessible tpye metadata in layout string… (#65016)
* [IRGen] Reject enums with inaccessible tpye metadata in layout string generation

rdar://107679697

Because we are currently handling most enums in layout strings by going through the metadata, we have to ensure that the metadata is accessible from the current module and reject the enum otherwise.

* Use proper mechanism to create and reference dylib in test

* Fix linking

* Add rpath to test dylib
2023-04-13 17:19:31 -07:00
Holly Borla
35fcc37136 Merge pull request #65134 from hborla/parameter-pack-revision
[SE-0393] Require the `repeat` keyword for generic requirement expansions.
2023-04-13 08:33:25 -07:00