Commit Graph

2594 Commits

Author SHA1 Message Date
Slava Pestov
490edfa523 Merge pull request #81564 from slavapestov/fix-issue-78191
IRGen: Fix miscompile when a generic parameter is fixed to a tuple containing a pack
2025-05-21 00:06:59 -04:00
Anthony Latsis
eafc48fb1a [test] Fix REQUIRES line in test 2025-05-20 12:08:44 +01:00
Dario Rexin
b6e7f96c76 Disable layout_string_witnesses_dynamic.swift
rdar://151476435

The test is currently crashing on Amazon Linux 2, so until we have a solution, we are disabling it.
2025-05-19 18:39:34 -07:00
Slava Pestov
f17baefd7a IRGen: Fix miscompile when a generic parameter is fixed to a tuple containing a pack
If you had something like:

    struct G<T> {
      func f<each U>(_: repeat each U) where T == (repeat each U) {}
    }

We would fulfill 'each U' from the metadata for 'G<(repeat each U)>',
by taking apart the tuple metadata for `(repeat each U)` and forming
a pack.

However this code path was only intended to kick in for a tuple
conformance witness thunk. In the general case, this optimization
is not correct, because if 'each U' is substituted with a
one-element pack, the generic argument of `G<(repeat each U)>` is
just that one element's metadata, and not a tuple. In fact, we
cannot distinguish the one-element tuple case, because the wrapped
element may itself be a tuple.

The fix is to just split off FulfillmentMap::searchTupleTypeMetadata()
from searchTypeMetadata(), and only call the former when we're in
the specific situation that requires it.

- Fixes https://github.com/swiftlang/swift/issues/78191.
- Fixes rdar://problem/135325886.
2025-05-16 17:34:11 -04:00
Dario Rexin
ee9c0cc14c Merge pull request #81530 from drexin/wip-151176697
[IRGen] Don't set HasLayoutString flag on non-copyable generic types
2025-05-15 15:27:26 -07:00
Dario Rexin
a904fee7fe [IRGen] Don't set HasLayoutString flag on non-copyable generic types
rdar://151176697

While generic types generally have layout strings (when enabled), non-copyable types don't, so
we have to make sure the flag does not get set.
2025-05-15 10:21:22 -07:00
Alejandro Alonso
9e24563bb7 Merge pull request #81365 from Azoy/my-existentials
[AST & Runtime] Correctly mangle extended existentials with inverse requirements
2025-05-12 13:21:07 -07:00
Alejandro Alonso
0574c9d254 Fix test to use target cpu 2025-05-08 10:20:16 -07:00
Alejandro Alonso
d26bde798e Start building the runtime demangle tree for extended existentials 2025-05-07 13:56:25 -07:00
Alejandro Alonso
c165509147 Correctly emit inverse proto comps with extended shape symbolic refs 2025-04-30 13:43:01 -07:00
Erik Eckstein
7a5dbdc20b CastOptimizer: don't assume dynamic casts from ObjectiveC classes to unrelated classes will fail
In case of ObjectiveC classes, the runtime type can differ from its declared type.
Therefore a cast between (compile-time) unrelated classes may succeed at runtime.

rdar://149810124
2025-04-30 16:42:42 +02:00
Nate Chandler
bdcf27f583 [Test] Mark that test requires executable_test.
rdar://150103417
2025-04-28 07:36:50 -07:00
nate-chandler
fcebcd31fb Merge pull request #81058 from nate-chandler/rdar149782365
[SILGen] Make eagerMove class init's self lexical.
2025-04-24 06:51:49 -07:00
Nate Chandler
96eb85cc93 [SILGen] Make eagerMove class init's self lexical.
Change the representation for eagerMove classes so that the body of
their deinit runs after the body of their init.

rdar://149782365
2025-04-23 17:16:05 -07:00
Nate Chandler
40bcc74b47 [OSSACanOwned] Don't dead-end extend if consumed.
When the utility is used by the ConsumeOperatorCopyableValuesChecker,
the checker guarantees that the lifetime can end at the consumes, that
there are no uses after those consumes.  In that circumstance, the
utility maintains liveness to those consumes and as far as possible
without introducing a copy everywhere else.

The lack of complete lifetimes has forced the utility to extend liveness
of values to dead-ends.  That extension, however, is in tension with the
use that the checker is putting the utility to.  If there is a dead-end
after a consume, liveness must not be maintained to that dead-end.

rdar://147586673
2025-04-21 18:09:30 -07:00
nate-chandler
2e1494df9f Merge pull request #80701 from nate-chandler/rdar148941214
[CoroutineAccessors] Use yield_once_2 on Darwin and Linux.
2025-04-10 14:46:05 -07:00
Nate Chandler
b76a76bdf1 [CoroutineAccessors] Unwind based on feature.
Now that coroutine kind (and consequently ABI) for the accessors is
keyed off a SIL option, it's no longer possible to read whether a given
SILFunction arose from a read/modify coroutine just by checking its
coroutine kind.  Regardless of ABI, read/modify coroutines may only
unwind (i.e. are only permitted not to "run to completion") if the
relevant experimental (soon to be deleted) feature is enabled.
2025-04-10 07:41:37 -07:00
Nate Chandler
056fbc44c9 [CoroutineAccessors] Control ABI via flag. 2025-04-10 07:41:37 -07:00
Nate Chandler
3f356fa088 [Test] Disable this test for old runtimes.
The test verifies back compatibility of old binaries with new runtimes
and depends on new runtime support.

rdar://148852062
2025-04-08 14:17:23 -07:00
nate-chandler
785759ad6e Merge pull request #80603 from nate-chandler/rdar148641825
[Test] Codesign lib on same line as binary.
2025-04-07 18:27:01 -07:00
Nate Chandler
9e1536749c [Test] Codesign lib on same line as binary.
Maybe this helps with remote execution.

rdar://148641825
2025-04-07 10:56:41 -07:00
Mike Ash
9ad534bc4a [Runtime] Fix a false metadata cycle diagnostic when threads race to instantiate cyclical metadata.
The metadata creation system detects cycles where metadata depends on other metadata which depends on the first one again and raises a fatal error if the cycle can't be fulfilled.

Some cycles can be fulfilled. The cycle may involve a requirement for a metadata state less than full transitive completeness which can be reached without resolving the entire cycle. We only want to raise a fatal error when we detect a cycle that can't be fulfilled.

Normally this happens because the cycle checking in `blockOnMetadataDependency` only sees a cycle when it can't be fulfilled. Metadata initialization is advanced as far as it can be at each stage, so a cycle that can be fulfilled will see a fulfilling state and won't generate the dependency in the first place, since we only generate dependencies that haven't yet been met.

However, when two threads race to create types in a cycle, we can end up with such a dependency, because the dependency may be generated before another thread fulfilled yet. The cycle checker doesn't account for this and incorrectly raises a fatal error in that case.

Fix this by checking the cyclic dependency against the metadata's current state. If we have a dependency that's already been fulfilled, then there isn't really a dependency cycle. In that case, don't raise a fatal error.

rdar://135036243
2025-04-04 17:49:55 -04:00
Nate Chandler
5534eb4043 [DefaultOverides] Install in vtables at runtime. 2025-03-25 07:22:44 -07:00
Nate Chandler
fba93fc207 [Test] Reenable tbd validation.
This was fixed previously.
2025-03-25 07:22:13 -07:00
Amritpan Kaur
3c30d68d2e Merge pull request #78823 from amritpan/method-keypaths
[Sema/SILGen/IRGen] Implement method & initializer keypaths.
2025-03-19 18:59:17 -07:00
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
Mike Ash
2d06496197 [Test] Disable backtracing for dynamic_isolation_checks_for_closures.swift and preconcurrency_conformances.swift.
These tests verify that the program crashed by checking for the absence of an "OK" line. The backtracer's memory dumps can sometimes contain the string "OK" by chance, resulting in a spurious failure.

rdar://146577558
2025-03-18 10:43:01 -04:00
Alejandro Alonso
c1bb143648 Make ValueGenerics feature always available 2025-02-27 10:03:37 -08:00
Pavel Yaskevich
9cbd8e1f10 Merge pull request #79382 from xedin/more-Sendable-to-Any-problems
[Concurrency] Fix a few issues with `Senable` and `Any`
2025-02-15 08:23:28 -08:00
Pavel Yaskevich
484e0a7437 [ConstraintSystem] Sendable-to-Any: Allow conversion when in inout positions
It should be possible to pass values with `any Sendable` as arguments
to `inout` parameters that expect `Any`. This is pretty much the same
as an l-value conversion.

Resolves: https://github.com/swiftlang/swift/issues/79361
Resolves: rdar://144794132
2025-02-13 17:03:00 -08:00
Dario Rexin
401cd64a61 [IRGen] Apply correct type to conversion for direct values and erorrs with typed throws
rdar://144719032

When converting the combined result back to the actual types when directly returning typed errors, in case
the error or result value was a single value smaller then pointer size and the combined value was larger,
the value was converted to the combined type instead of the actual type, making it a no-op, which caused
undefined behavior when writing the value to the coerced alloca.
2025-02-13 12:53:12 -08:00
Amritpan Kaur
1c025f5b04 Add tests. 2025-02-09 10:19:44 -08:00
Dario Rexin
923cccf1ea [Runtime] Add specialized CVW entry points for multi payload enums
rdar://143852239

Adding these specialized entry points reduces the overhead of the witness functions by removing the first indirection.
2025-01-30 14:44:49 -08:00
Stefan Gränitz
76243a25db [windows][toolchain] Build sanitizers and builtins standalone for all SDKs (#78861)
Unified builds of compiler-rt together with LLVM failed for the Android SDKs. It got too complicated to redirect the way LLVM would configure the nested build-trees. Standalone builds slightly increase build time, but they turned out much simpler and we end up with less duplication of definitions.
2025-01-28 22:08:07 +01:00
Erik Eckstein
66e801b0e8 tests: fix lifetimes of objects in two tests
Those tests rely on lexical object lifetimes. But lifetimes are only guaranteed for "variables" but not for temporary objects.
Storing those objects in variables fixes the issue.

This fixes the tests when running them in optimize mode and when OSSA modules are enabled.

This is part of rdar://140229560.
2025-01-27 10:38:30 +01:00
Erik Eckstein
42fef1fb68 SILGen: let withoutActuallyEscaping also catch an escaping closure in the throwing case
withoutActuallyEscaping checks that the passed closure has not beed escaped by ensuring that its reference count is exactly 1 at the end of the code block.
So far this was only done in the regular return case. But if the code block throws, the check was not done.

Fixes an undetected undefined behavior.
2025-01-24 18:57:40 +01:00
Dario Rexin
30e7ba13b2 [IRGen] Add indirect typed error slot when async function has indirect result
rdar://142918657

Erorrs have to be passed indirectly whenever the result type is indirect.
2025-01-16 15:29:13 -08:00
Alexis Laferrière
f4f61d23ff Merge pull request #78530 from xymus/local-cache-for-appkit
Tests: Use a local cache for many tests importing AppKit
2025-01-10 12:43:33 -08:00
Alexis Laferrière
11c448d954 Tests: Use a local cache for many tests importing AppKit
Tests importing AppKit have a tendency to be flaky if they share a
module cache with other builds using a different set of framework search
flags. Make sure they use a local cache to avoid picking incompatible
cached modules.

Alternatively, we could align all builds using the same cache to have
exactly the same framework search paths or enable explicit module
builds. I picked the module cache as it's the most reliable solution in
the short and long term.

The 5 tests below import AppKit and have been known to be flaky.
Adapting them to use a custom cache with require more care. For now,
let's use them as control group to validate that the fix works. If these
5 fail without the fixed ones, we should extend the same corresponding
fix to them.

- Interpreter/SDK/GLKit.swift
- Interpreter/SDK/cf_extensions.swift
- Interpreter/SDK/cf_type_bridging.swift
- Interpreter/SDK/mapkit_header_static.swift
- Interpreter/SDK/objc_ns_enum.swift

rdar://142296731
2025-01-09 12:22:02 -08:00
Pavel Yaskevich
0a0a34c853 [CSApply] Add support for l-value to l-value and inout unsafe casts
`any Sendable` -> `Any` in generic argument positions should be
supported for l-value and inout types as well otherwise it won't
be possible to call setters and mutating methods.
2025-01-07 17:21:33 -08:00
Pavel Yaskevich
636525ebd9 Merge pull request #78171 from xedin/rdar-140300022
[TypeChecker/SILGen] Allow `any Sendable` to match `Any` while matching generic arguments
2024-12-17 20:24:34 -08:00
Hamish Knight
a1b56fbb29 [test] Disable variadic_generic_opaque_type.swift for back deployment
rdar://139913681
2024-12-16 14:02:25 +00:00
Pavel Yaskevich
0de9e9cd1d [CSSimplify] Extend any Sendable -> Any conversion support to function argument/result positions in generic argument context 2024-12-13 17:27:06 -08:00
Pavel Yaskevich
5e08f7e257 [CSApply/SILGen] Implement any Sendable to Any erasure for generic arguments
In non-strict concurrency mode when `@preconcurrency` declarations
are involved `any Sendable` should be treated as `Any` in generic
argument positions to support passing types that (partially) adopted
concurrency annotations to types that haven't yet done so.
2024-12-11 17:19:14 -08:00
Hiroshi Yamauchi
32832dd1e1 Revert "[windows][toolchain] Enable builtins and sanitizers"
Revert https://github.com/swiftlang/swift/pull/77770

To fix CI https://ci-external.swift.org/job/swift-main-windows-toolchain-arm64/785/consoleText
2024-12-06 14:22:30 -08:00
Saleem Abdulrasool
3ab2a3ee4c Merge pull request #77770 from weliveindetail/windows-toolchain-sanitizers
[windows][toolchain] Enable builtins and sanitizers
2024-12-05 15:46:46 -08:00
Saleem Abdulrasool
03eeffdbb7 test: disable failing test
Disable the test until someone can look into why the path is getting
corrupted.
2024-12-05 15:17:30 -08:00
Saleem Abdulrasool
499e4227c6 test: fix the broken test
swiftlang/swift-driver#1741 fixed a bug in the swift-driver which
exposed a bug in this test. The use of `%FileCheck` is a problem as that
sanitises the output substituting `BUILD_DIR` for the build directory
that is now properly computed. Because `PATH` is being configured to an
invalid path the actual driver is not found and the test fails.
2024-12-04 11:24:27 -08:00
Stefan Gränitz
2f7116a36f Disable tests newly included with asan_runtime available, but not supported on Windows yet 2024-12-03 18:41:49 +01:00