Commit Graph

80 Commits

Author SHA1 Message Date
Amritpan Kaur
98cd675eb9 Guard feature behind experimental flag. 2025-03-19 10:54:09 -07:00
Amritpan Kaur
15c219cd70 [Tests] Add tests. 2025-03-19 10:54:09 -07:00
Amritpan Kaur
1c025f5b04 Add tests. 2025-02-09 10:19:44 -08:00
Michael Gottesman
6058b1d9bd [silgen] Change SILGen to emit ignored_user for emitIgnoredExpr and black hole initialization. 2025-01-22 21:12:36 -08:00
Erik Eckstein
7cceaff5f3 SIL: don't print operand types in textual SIL
Type annotations for instruction operands are omitted, e.g.

```
  %3 = struct $S(%1, %2)
```

Operand types are redundant anyway and were only used for sanity checking in the SIL parser.

But: operand types _are_ printed if the definition of the operand value was not printed yet.
This happens:

* if the block with the definition appears after the block where the operand's instruction is located

* if a block or instruction is printed in isolation, e.g. in a debugger

The old behavior can be restored with `-Xllvm -sil-print-types`.
This option is added to many existing test files which check for operand types in their check-lines.
2024-11-21 18:49:52 +01:00
Alex Hoppen
9a48cad432 Merge pull request #76939 from ahoppen/enable-parser-roundtrip
Enable experimental parser round-trip in test cases that no longer need it
2024-11-05 18:51:31 -08:00
Daniel Rodríguez Troitiño
5abb1ea6ac [test] Remove some REQUIRES: for features not longer used in those files
While doing #76740 I iteratively was adding new `REQUIRES:` as new
usages of the features were found, but I did not realize that at the
same time other people might be removing some of those usages. The tests
in this commit had some `REQUIRES:` line for a previous
`-enable-experimental/upcoming-feature`, but they not longer use those
features, so the `REQUIRES:` were effectively disabling the tests (at
least in the case of `KeyPathWithStaticMembers`. In other cases they
might still had executed).
2024-11-04 20:53:07 -08:00
Alex Hoppen
9bbdeaa8c0 Enable experimental parser round-trip in test cases that no longer need it
Also, track all remaining uses of `-disable-experimental-parser-round-trip` by issues.
2024-11-04 15:49:47 -08:00
Daniel Rodríguez Troitiño
ba68faaed5 [test] Mark tests that use experimental/upcoming features as such
Find all the usages of `--enable-experimental-feature` or
`--enable-upcoming-feature` in the tests and replace some of the
`REQUIRES: asserts` to use `REQUIRES: swift-feature-Foo` instead, which
should correctly apply to depending on the asserts/noasserts mode of the
toolchain for each feature.

Remove some comments that talked about enabling asserts since they don't
apply anymore (but I might had miss some).

All this was done with an automated script, so some formatting weirdness
might happen, but I hope I fixed most of those.

There might be some tests that were `REQUIRES: asserts` that might run
in `noasserts` toolchains now. This will normally be because their
feature went from experimental to upcoming/base and the tests were not
updated.
2024-11-02 11:46:46 -07:00
Pavel Yaskevich
5d77f3ca01 [Frontend] NFC: Remove KeyPathWithStaticMembers feature flag
This is a temporary way to land SE-0438 changes without disrupting
anything else.
2024-10-30 10:53:42 -07:00
Allan Shortlidge
6f55aa4170 Tests: Remove -disable-availability-checking in tests that use opaque types.
Use the `%target-swift-5.1-abi-triple` substitution to compile the tests for
deployment to the minimum OS versions required for use of opaque types, instead
of disabling availability checking.
2024-10-19 19:39:18 -07:00
Rintaro Ishizaki
761d013224 [Test] Disable new parser validation in 3 tests
These tests have syntax SwiftParser currently doesn't parse correctly.

* test/SILGen/keypaths.swift
```
\Foo.Type[0]
```
* test/SIL/lifetime_dependence_span_lifetime_attr.swift and
  test/Sema/lifetime_attr.swift
```
@lifetime(borrow x)
```
2024-10-03 11:26:52 -07:00
Amritpan Kaur
8ebc928649 Guard feature behind experimental flag. 2024-09-27 22:42:04 -07:00
Amritpan Kaur
605fe8f41c [Tests] Update SilGen tests. 2024-09-27 22:42:04 -07:00
Slava Pestov
74b2b03565 SILGen: Don't ask for context substitution map of existential 2024-09-19 14:18:31 -04:00
Freddy Kellison-Linn
8bf16493f9 Add additional SILGen test for keypath-function subtype conversion 2024-03-02 12:44:49 -05:00
Pavel Yaskevich
7ad80b8ce0 [CSApply] Optional chaining forces key path component to be r-value
Key path components with optional chaining unlike other places
don't propagate l-value through optionals.

Resolves: rdar://123638701
2024-02-26 13:10:46 -08:00
Freddy Kellison-Linn
2b2f780a21 Fix solution application for keypath function subtype conversions
In #39612 we added subtyping for keypaths-as-functions, but during application
the implementation naively coerced the keypath expression itself to the
inferred supertype, resulting in erroneous results. This patch updates the
solution application logic to build the keypath-function conversion expression
based entirely on the 'natural' keypath type, only converting to the inferred
supertype at the end via the usual coerceToType machinery for function
conversions.
2024-02-19 15:41:15 -08:00
Yuta Saito
c5314bd3af Centralize KeyPath accessor calling convention logic to IRGen
KeyPath's getter/setter/hash/equals functions have their own calling
convention, which receives generic arguments and embedded indices from a
given KeyPath argument buffer.
The convention was previously implemented by:
1. Accepting an argument buffer as an UnsafeRawPointer and casting it to
   indices tuple pointer in SIL.
2. Bind generic arguments info from the given argument buffer while emitting
   prologue in IRGen by creating a new forwarding thunk.

This 2-phase lowering approach was not ideal, as it blocked KeyPath
projection optimization [^1], and also required having a target arch
specific signature lowering logic in SIL-level [^2].

This patch centralizes the KeyPath accessor calling convention logic to
IRGen, by introducing `@convention(keypath_accessor_XXX)` convention in
SIL and lowering it in IRGen. This change unblocks the KeyPath projection
optimization while capturing subscript indices, and also makes it easier
to support WebAssembly target.

[^1]: https://github.com/apple/swift/pull/28799
[^2]: https://forums.swift.org/t/wasm-support/16087/21
2023-09-20 11:25:39 -07:00
Alejandro Alonso
315ee2a167 Fix tuple keypath verifier (#60737) 2022-08-26 15:28:59 -07:00
Arnold Schwaighofer
1d4497a599 SILVerifier: Fix keypath verification involving opaque return types
The SIL type of the keypath instruction is lowered in the function's
type expansion context, the various types involved in patterns are
unlowered AST types.

When verifying that the types matchup apply the type expansion to both
sides.

rdar://72134937
2020-12-10 13:52:08 -08:00
Erik Eckstein
79913b9595 Don't "finalize" the empty-array singleton.
Array literals only need to be finalized, if the array is really allocated.
In case of zero elements, no allocation is done, but the empty-array singleton is used.
"Finalization" means to emit an end_cow_mutation instruction on the array.
As the empty-array singleton is a read-only and shared object, it's not legal to do a end_cow_mutation on it.
2020-07-03 15:56:50 +02:00
Erik Eckstein
1559fe333f SIL: a new library intrinsic to "finalize" array literals
For COW support in SIL it's required to "finalize" array literals.
_finalizeUninitializedArray is a compiler known stdlib function which is called after all elements of an array literal are stored.
This runtime function marks the array literal as finished.

  %uninitialized_result_tuple = apply %_allocateUninitializedArray(%count)
  %mutable_array = tuple_extract %uninitialized_result_tuple, 0
  %elem_base_address = tuple_extract %uninitialized_result_tuple, 1
  ...
  store %elem_0 to %elem_addr_0
  store %elem_1 to %elem_addr_1
  ...
  %final_array = apply %_finalizeUninitializedArray(%mutable_array)

In this commit _finalizeUninitializedArray is still a no-op because the COW support is not used in the Array implementation yet.
2020-06-08 10:24:29 +02:00
Slava Pestov
9ec80df97e SIL: Remove curried SILDeclRefs 2020-03-19 02:20:21 -04:00
John McCall
ceff414820 Distinguish invocation and pattern substitutions on SILFunctionType.
In order to allow this, I've had to rework the syntax of substituted function types; what was previously spelled `<T> in () -> T for <X>` is now spelled `@substituted <T> () -> T for <X>`.  I think this is a nice improvement for readability, but it did require me to churn a lot of test cases.

Distinguishing the substitutions has two chief advantages over the existing representation.  First, the semantics seem quite a bit clearer at use points; the `implicit` bit was very subtle and not always obvious how to use.  More importantly, it allows the expression of generic function types that must satisfy a particular generic abstraction pattern, which was otherwise impossible to express.

As an example of the latter, consider the following protocol conformance:

```
protocol P { func foo() }
struct A<T> : P { func foo() {} }
```

The lowered signature of `P.foo` is `<Self: P> (@in_guaranteed Self) -> ()`.  Without this change, the lowered signature of `A.foo`'s witness would be `<T> (@in_guaranteed A<T>) -> ()`, which does not preserve information about the conformance substitution in any useful way.  With this change, the lowered signature of this witness could be `<T> @substituted <Self: P> (@in_guaranteed Self) -> () for <A<T>>`, which nicely preserves the exact substitutions which relate the witness to the requirement.

When we adopt this, it will both obviate the need for the special witness-table conformance field in SILFunctionType and make it far simpler for the SILOptimizer to devirtualize witness methods.  This patch does not actually take that step, however; it merely makes it possible to do so.

As another piece of unfinished business, while `SILFunctionType::substGenericArgs()` conceptually ought to simply set the given substitutions as the invocation substitutions, that would disturb a number of places that expect that method to produce an unsubstituted type.  This patch only set invocation arguments when the generic type is a substituted type, which we currently never produce in type-lowering.

My plan is to start by producing substituted function types for accessors.  Accessors are an important case because the coroutine continuation function is essentially an implicit component of the function type which the current substitution rules simply erase the intended abstraction of.  They're also used in narrower ways that should exercise less of the optimizer.
2020-03-07 16:25:59 -05:00
Joe Groff
dcd432a1bc Turn on substituted SILFunctionTypes by default 2020-02-24 12:14:21 -08:00
zoecarver
88f9c674db Add FileCheck tests 2019-11-26 00:38:39 -08:00
zoecarver
0f6ff75c57 Add tests and isVariadic 2019-11-24 12:09:19 -08:00
zoecarver
b8947c4e16 Add more FileCheck tests 2019-11-18 09:19:18 -08:00
zoecarver
976c8c9310 Add tests 2019-11-17 13:44:15 -08:00
zoecarver
3a98452295 Add FileCheck tests 2019-11-12 18:12:43 -08:00
zoecarver
b0877fb4d1 Re-enable tests (oops) 2019-11-10 15:59:38 -08:00
zoecarver
8c3bfc598b Move default arg generation into SILGen 2019-11-10 15:47:34 -08:00
zoecarver
00ebbee341 Fix based on review comments 2019-11-06 11:02:57 -08:00
zoecarver
327c08a983 Add edgecases to tests 2019-11-06 09:30:01 -08:00
zoecarver
e87d243d70 Fix support for subscript default arguments in KeyPath 2019-10-30 17:31:00 -07:00
technicated
e7eb743d1b Fixed some tests after rebase 2019-02-18 14:45:24 +01:00
technicated
1577afee80 Added more tests (related to generic tuples) 2019-02-18 10:19:43 +01:00
technicated
d7324b977e Added more tests
Testing SILGen & IRGen tuple keypath generation
Added tuple element type check in SILVerifier
2019-02-18 10:19:42 +01:00
Michael Gottesman
40a09c9c21 Fixup tests for -assume-parsing-unqualified-ownership-sil => [ossa] transition. 2018-12-18 00:49:32 -08:00
Karoy Lorentey
666a22feff [test] Modernize hashing throughout the test suite 2018-11-29 17:38:29 +00:00
Slava Pestov
ebe769a58c SIL: Stop imploding parameter list into a single value with opaque abstraction pattern
The constraint solver support for the Swift 3 function type behavior
has been removed, so it's no longer possible to pun the same value as
both a function taking multiple parameters and a function taking a
single tuple argument.

This means the entire parameter list is no longer a target for
substitution as a single value, so the most general form of a function
value passes each parameter indirectly instead of passing a single
tuple parameter indirectly.
2018-09-26 23:20:54 -07:00
eeckstein
814e656cf9 Merge pull request #19388 from eeckstein/mangling-prefix
change mangling prefix from $S to $s
2018-09-20 09:16:30 -07:00
Erik Eckstein
39bb14b094 change mangling prefix from $S to $s
This is the final ABI mangling prefix

rdar://problem/38471478
2018-09-19 13:55:11 -07:00
Joe Groff
93b5de61e7 Implement the final approved syntax for SE-227 identity key paths.
`\.self` is the final chosen syntax. Implement support for this syntax, and remove the stopgap builtin and `WritableKeyPath._identity` property that were in place before.
2018-09-19 11:45:13 -07:00
Joe Groff
44b55ae197 Runtime support for identity key paths.
Make sure the implementation can handle a key path with zero components by removing inappropriate assumptions that the number of components is always non-empty. Identity key paths also need some special behavior:

- Appending an identity key path should be an identity operation for the other operand
- Identity key paths have a `MemoryLayout.offset(of:)` zero
- Identity key paths interop with KVC as key paths to `@"self"`

To be able to exercise and test this behavior, add a `Builtin.identityKeyPath()` function and `WritableKeyPath._identity` accessor in lieu of finalized syntax.
2018-08-20 14:00:46 -07:00
Joe Groff
c0b785a027 Remove stale -enable-sil-ownership flag from test 2018-07-25 10:49:29 -07:00
Alex Hoppen
560c22b18e [tests] Verify the libSyntax tree on SILGen tests
The SILGen testsuite consists of valid Swift code covering most language
features. We use these tests to verify that no unknown nodes are in the
file's libSyntax tree. That way we will (hopefully) catch any future
changes or additions to the language which are not implemented in
libSyntax.
2018-04-27 09:33:03 -07:00
Michael Gottesman
cb80f65f1e Remove plus_zero_test,plus_one_test from lit tests since they are no longer needed.
I am going to leave in the infrastructure around this just in case. But there is
no reason to keep this in the tests themselves. I can always just revert this
and I don't think merge conflicts are likely due to previous work I did around
the tooling for this.
2018-03-21 20:49:52 -07:00
Michael Gottesman
e567bc9028 [+0-all-args] Enable +0 normal arguments.
rdar://34222540
2018-03-19 20:25:31 -07:00