Commit Graph

7754 Commits

Author SHA1 Message Date
Hamish Knight
6ae5f1c535 [test] Update test for placeholder revert 2023-05-05 19:43:10 +01:00
Daniel Rodríguez Troitiño
cfb76cc780 [test] Allow customizing swift-ide-test invocations during tests. (#65684)
In some Linux setups, one might need to provide extra arguments to setup
the environment for invocations done during the tests. The Swift
frontend and driver already had a mechanism to provide those arguments
in the shape of `SWIFT_FRONTEND_TEST_OPTIONS` and
`SWIFT_DRIVER_TEST_OPTIONS`. `swift-ide-test` was sadly missing the same
feature, which meant that many tests might fail or tests against the
incorrect environment.

The changes implement the `SWIFT_IDE_TEST_TEST_OPTIONS` mechanism to
cover that gap.
2023-05-05 09:35:45 -07:00
Allan Shortlidge
b12537faaf Merge pull request #65667 from tshortli/swiftinterface-missing-conformance-req-assert
Sema: Fix incorrect assert in TypeCheckProtocol.cpp.
2023-05-05 09:06:30 -07:00
Allan Shortlidge
ba422f96be Sema: Fix incorrect assert in TypeCheckProtocol.cpp.
We can't assume that we will always find a viable witness for a protocol
requirement when typechecking a `.swiftinterface` file. The assert that assumed
there would be a match could fail when building a broken interface or building
a valid interface with a broken SDK, causing crashes instead of emitting
diagnostics.

Resolves rdar://108688535
2023-05-04 16:24:31 -07:00
Hamish Knight
3087afc1f8 Merge pull request #65651 from hamishknight/placeholder
Resolves https://github.com/apple/swift/issues/65650
2023-05-04 19:50:12 +01:00
nate-chandler
74cbe264ca Merge pull request #65636 from nate-chandler/rdar108614878
[IRGen] Check for nil in final class cast opt.
2023-05-04 07:08:37 -07:00
Hamish Knight
b07f7b336e [CS] Improve handling of holes for Named/AnyPatterns
Rather than eagerly binding them to holes if the
sequence element type ends up being Any, let's
record the CollectionElementContextualMismatch fix,
and then if the patterns end up becoming holes,
skip penalizing them if we know the fix was
recorded. This avoids prematurely turning type
variables for ExprPatterns into holes, which
should be able to get better bindings from the
expression provided. Also this means we'll apply
the logic to non-Any sequence types, which
previously we would give a confusing diagnostic
to.
2023-05-04 14:53:58 +01:00
Nate Chandler
70cfa6a05c [IRGen] Check for nil in final class cast opt.
As an optimization, there is a fast-cast to non-final classes that just
compares isa pointers.  If the source of the cast is an Optional<class>,
though, it's not allowed to "directly compare the isa-pointer"; because
the source might be Optional.none, i.e. null.

Add a check for nil when emitting the fast class cast.

rdar://108614878
2023-05-03 18:39:08 -07:00
Arnold Schwaighofer
441b151ba3 Merge pull request #65549 from aschwaighofer/guard_using_clang_for_objc_protocols_by_deploy_target_2nd
IRGen: Only use clang protocol emission on newer deployment targets
2023-05-02 06:47:15 -07:00
swift-ci
7f60847231 Merge pull request #65548 from tbkka/tbkka-32bit-MPE-test
Fix this on 32 bit targets
2023-05-01 17:56:02 -07:00
Arnold Schwaighofer
086bc944f0 IRGen: Only use clang protocol emission on newer deployment targets
We started using clang to emit the _OBJC_PROTOCOL_ definition.

But we would use a different name for the proto_list definition than clang.

"OBJC_LABEL_PROTOCOL$" (objc)
|--> OBJC_PROTOCOL
"\01l_OBJC_LABEL_PROTOCOL$_" (swift)
|--> OBJC_PROTOCOL

If an Objective C object also emitted the same protocol definition you could
end up in a situation where both clang's and swift's proto_list definitions
point to the same protocol definition.

Older linkers don't like that.

rdar://108505376
2023-05-01 13:49:17 -07:00
Tim Kientzle
3f70b051a3 Fix this on 32 bit targets 2023-05-01 12:03:26 -07:00
Arnold Schwaighofer
f403e55a1d Revert "Merge pull request #65516 from aschwaighofer/guard_using_clang_for_objc_protocols_by_deploy_target"
This reverts commit 1a7f342a4e, reversing
changes made to 404b925d8b.
2023-05-01 07:43:56 -07:00
Arnold Schwaighofer
1a7f342a4e Merge pull request #65516 from aschwaighofer/guard_using_clang_for_objc_protocols_by_deploy_target
IRGen: only use clang protocol emission on newer deployment targets
2023-05-01 06:50:46 -07:00
Pavel Yaskevich
366213d90c Merge pull request #65479 from xedin/rdar-108534555
[CSDiagnostics] Teach `diagnoseConflictingGenericArguments` about holes
2023-04-28 17:18:25 -07:00
Arnold Schwaighofer
4416cb3f9b IRGen: only use clang protocol emission on newer deployment targets
Older linkers seemed to have a problem with clang emitted definitions.

rdar://108505376
2023-04-28 15:10:47 -07:00
Pavel Yaskevich
0b7aeed4b8 [CSDiagnostics] Teach diagnoseConflictingGenericArguments about holes
Only fully resolved substitutions are eligible to be considered
as conflicting, if holes are involved in any position that automatically
disqualifies a generic parameter.

Resolves: rdar://108534555
Resolves: https://github.com/apple/swift/issues/63450
2023-04-27 14:58:26 -07: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
Tim Kientzle
060d81f653 Merge pull request #64852 from tbkka/tbkka-RemoteMirror-MPE-zero-sized-plus-generics
[RemoteMirror] Fix handling of generic  and zero-sized cases in MPEs
2023-04-27 08:19:01 -07:00
Slava Pestov
dd0531e890 Merge pull request #65400 from slavapestov/generic-param-shadowing
Sema: Ban shadowing generic parameters from outer scopes
2023-04-26 12:08:51 -04:00
Tim Kientzle
5d67b814f5 Fix case calculation for SPE with zero-sized payload 2023-04-25 15:00:51 -07:00
Slava Pestov
290701cb4d Sema: Ban shadowing generic parameters from outer scopes
Code like that is usually indicative of programmer error, and does not
round-trip through module interface files since there is no source
syntax to refer to an outer generic parameter.

For source compatibility this is a warning, but becomes an error with
-swift-version 6.

Fixes rdar://problem/108385980 and https://github.com/apple/swift/issues/62767.
2023-04-25 17:41:23 -04:00
Tim Kientzle
8da561c8cb More tests! 2023-04-24 16:42:08 -07:00
Pavel Yaskevich
d6019ac466 Merge pull request #65366 from xedin/issue-65360
[CSSolver] Fix a crash in diagnostics related to pattern matching
2023-04-24 16:27:25 -07:00
Pavel Yaskevich
20d7642ca4 [CSGen] Allow expression pattern types to be holes 2023-04-24 10:02:00 -07:00
Tim Kientzle
9bfe1b1691 Merge branch 'main' into tbkka-RemoteMirror-MPE-zero-sized-plus-generics 2023-04-24 08:22:38 -07:00
Tim Kientzle
ed28d8e4eb Add a test case where the innermost type has no generic parameters 2023-04-22 11:52:31 -07:00
Pavel Yaskevich
b081bdbf57 [CSGen] Allow is pattern types to be holes 2023-04-21 12:14:41 -07:00
Tim Kientzle
16c0729492 Correct and simplify the test from PR #62854
The new logic no longer includes non-generic parent types as part
of the type reference.

This also combines the 32- and 64-bit tests validations, since they
were identical for this test anyway.
2023-04-20 14:31:06 -07:00
Tim Kientzle
02160e68a0 Recursively reconstruct nested generics, skipping non-generic
This is a more correct fix for the issue that inspired PR #62854.
In particular, this does not change the numbering of generic
argument levels, and so does not break generic type parameter
lookups.

Added a new test case to verify that nested types that mix
generics and non-generics in different ways consistently identify
the correct generic argument labels.
2023-04-20 14:31:06 -07:00
nate-chandler
0e8a6060ee Merge pull request #65306 from nate-chandler/rdar81421394
Address asserts raised when conforming pseudogeneric type to protocol with coroutine requirement.
2023-04-20 07:14:36 -07:00
Evan Wilde
37d2d692b3 Merge pull request #65303 from etcwilde/ewilde/disable-tsan-ignores-arc-locs
Unblock package bots: Disable tsan test
2023-04-19 22:45:16 -07:00
Nate Chandler
b9ccde3771 SILFunctionType: Loosened assert.
Allowed SILFunctionType instances for pseudogeneric coroutines without
signatures to be created.  Such instances are created by
SILTypeSubstituter::substSILFunctionType when SILGen'ing a conformance
of a pseudogeneric type to a protocol featuring a coroutine requirement.

rdar://81421394
2023-04-19 17:53:15 -07:00
Evan Wilde
5bad63bf1f Unblock package bots: Disable tsan test 2023-04-19 14:53:21 -07:00
nate-chandler
d20b8d26b8 Merge pull request #65274 from nate-chandler/rdar107275872
[Concurrency] Nest stack traffic in withValue.
2023-04-19 11:52:41 -07:00
Nate Chandler
4fe988b7c2 [Concurrency] Nest stack traffic in withValue.
Because `_taskLocalValuePush` and `_taskLocalValuePop` can result in calls
to `swift_task_alloc` and `swift_task_dealloc` respectively, and because
the compiler hasn't been taught about that (e.g.
`SILInstruction::isAllocatingStack`,
`SILInstruction::isDeallocatingStack`, etc), calling them (push and pop)
from a function which makes use the stack for dynamically sized
allocations can result in violations of stack discipline of the form

```
swift_task_alloc // allocates %ptr_1
copy_value_witness // copies into %ptr_1
swift_task_localValuePush // calls swift_task_alloc and allocates %ptr_2
swift_task_dealloc // deallocates %ptr_1
swift_task_localValuePop // calls swift_task_dealloc and deallocates %ptr_2
```

Avoid the problem by not allocating dynamically sized stack space in the
function which calls `_taskLocalValuePush` and `_taskLocalValuePop`.
Split the calls to those functions into `withValueImpl` function which
takes its argument `__owned`.  Call that function from `withValue`,
ensuring that the necessary copy (to account for the fact that withValue
takes its argument `__guaranteed` but `_taskLocalValuePush` takes its
`__owned`) and associated stack traffic occur in `withValue`.

Still, allow `withValueImpl` to be inlined.  The stack nesting will be
preserved across it.

rdar://107275872
2023-04-18 19:51:34 -07:00
Tim Kientzle
894f116189 Remove a test that is not actually ready; it was just an experiment 2023-04-12 17:24:12 -07:00
Tim Kientzle
a6ff81345a Make some tests work better on varying platforms.
In particular, the exactly internal layout of Array<> is quite
different between macOS and Linux, which makes it impractical
for use in tests like this.  An empty class is still a reference
and doesn't introduce so many complications.
2023-04-12 16:40:44 -07:00
Tim Kientzle
ef0eafc84f Generalize a test to work correctly on Linux aarch64 2023-04-11 17:40:07 -07:00
Pavel Yaskevich
976c0b17c3 [CSSyntaticElement] Canonicalize type before collecting "in scope" variables
Follow-up to https://github.com/apple/swift/pull/65048

`getDesugaredType` unwraps sugar types that appear in sequence,
to remove sugar from nested positions we need to get a canonical type.

Thanks to @slavapestov for pointing it out.
2023-04-11 11:53:31 -07:00
Pavel Yaskevich
6b3a17bad9 Merge pull request #65048 from xedin/rdar-107835060
[CSSyntaticElement] Desugar types before collecting "in scope" type v…
2023-04-11 10:47:38 -07:00
Pavel Yaskevich
ca14ab7157 [CSSyntaticElement] Desugar types before collecting "in scope" type variables
Generic type aliases, unless desugared, could bring unrelated type variables
into the scope i.e. `TypeAlias<$T, $U>.Context` is actually `_Context<$U>`.
These variables could be inferrable only after the the body the closure is
solved. To avoid that, let's adjust `TypeVariableRefFinder` to desugar types
before collecting referenced type variables.

Resolves: rdar://107835060
2023-04-10 15:33:03 -07:00
Tim Kientzle
a76c925b49 Merge remote-tracking branch 'github-apple/main' into tbkka-RemoteMirror-MPE-zero-sized-plus-generics 2023-04-10 12:42:12 -07:00
Dario Rexin
021d524056 [IRGen] Pass component generic sig when emitting key path component f… (#64871)
* [IRGen] Pass component generic sig when emitting key path component for external property

rdar://101179225

When no generic environment was present, we passed nullptr, which is not correct when the property uses an external associated type, causing crashes in IRGen. In those cases, we have to pass the component generic sig instead.

* Fix test
2023-04-07 13:58:47 -07:00
Tim Kientzle
2f27e06591 Generalize tests that already work for 32 bits 2023-04-06 13:27:06 -07:00
Tim Kientzle
3bb9285d45 Accurately distinguish generic and non-generic cases.
A "generic" case is any case whose payload type depends
on generic type parameters for the enum or any enclosing type.
Some examples:

```
struct S<T> {
  enum E {
    case a        // Non-generic case
    case b(Int)   // Non-generic case
    case c(T)     // Generic case
    case d([U])   // Generic case
    case e([Int]) // Non-generic case
  }
}
```

This is important for correctly distinguishing MPE versus
SPE layouts.  A case is considered "empty" only if it
is either a non-payload case (`case a`) or if the payload
is zero-sized and non-generic.  Generic cases are always
treated as non-zero-sized for purposes of determining
the layout strategy.

Correctly testing this is tricky, since some of the
layout strategies differ only in whether they export
extra tag values as XIs.  The easiest way to verify is
to check whether wrapping the result in an `Optional<>`
adds another byte to the overall size.
2023-04-03 17:17:59 -07:00
Tim Kientzle
e573366a53 Fix handling of generic MPEs
This exercises a number of cases that the previous logic got
wrong, including cases where MPEs are laid out like SPEs,
and cases where we use the SPE or MPE layout strategies for enums
that have no non-empty payloads.  (These cases are superficially
similar but differ in how they handle XIs.)

These new tests allowed me to correct a number logical flaws
about how layouts are selected.  In particular, cases with
generic payloads are always considered to be non-empty for
purposes of selecting a layout strategy.  Only cases that
are statically known to be empty are considered empty for
layout purposes.
2023-04-02 21:09:24 -07:00
Rintaro Ishizaki
9dc7ee8222 Merge pull request #64796 from rintaro/test-hosttriple-rdar107398734
[Test] Add %host_triple and %host_sdk substitutions
2023-03-31 10:43:31 -07:00
Rintaro Ishizaki
1d2fd4223f [Test] Add %host_triple and %host_sdkroot substitutions
Macro tests need to build host libraries/tools. We can't use %target-*
substitutions for that.

rdar://107398734
2023-03-31 07:41:41 -07:00