Commit Graph

580 Commits

Author SHA1 Message Date
Konrad `ktoso` Malawski
8b4740f0cc Merge pull request #81797 from ktoso/wip-handle-public-import-distributed-awareness
[Distributed] account Distributed module use from DA declarations
2025-05-29 08:04:24 +09:00
Konrad `ktoso` Malawski
ff8b9f1453 [Distributed] fix typo in CHECK assertions (#81795)
... in distributed_actor_accessor_thunks_32bit.swift

Spotted a typo while skimming through the test so let's fix it. it
should be CHECK-SAME and not CHECK_SAME which would just do nothing
2025-05-28 00:24:11 -07:00
Konrad 'ktoso' Malawski
3b94f009d6 [Distributed] account Distributed module use from DA declarations
When issuing warnings about an import not needing to be public, we did
not account for the Distributed module MUST be imported when a
distributed actor is declared. This also actually means that a public
distributed actor effectively is a public use of the DistributedActor
protocol

resolves rdar://152129980
2025-05-28 12:54:07 +09:00
Pavel Yaskevich
9e562881fe [TypeChecker] Improve diagnostics for access to actor-isolated values outside of the actor
Replaces generic `expression is 'async' but is not marked with 'await`
diagnostic with a tailed one for cases where there is an access to an
actor-isolated value outside of its actor without `await` keyword.

This makes the diagnostics for async and sync contexts consistent
and actually identifies a problem instead of simply pointing out
the solution.

Resolves: rdar://151720646
2025-05-23 00:20:18 -07:00
Anthony Latsis
55e5618eab [test] Match nocapture to succeed both on main and rebranch
Both the syntax and relative order of the LLVM `nocapture` parameter
attribute changed upstream in 29441e4f5fa5f5c7709f7cf180815ba97f611297.
To reduce conflicts with rebranch, adjust FileCheck patterns to expect
both syntaxes and orders anywhere the presence of the attribute is not
critical to the test. These changes are temporary and will be cleaned
up once rebranch is merged into main.
2025-05-08 23:52:43 +01:00
Anthony Latsis
17fc00f8a7 [test] IRGen: Adjust FileCheck patterns for new nuw attribute in upstream LLVM
This attribute was introduced in
7eca38ce76d5d1915f4ab7e665964062c0b37697 (llvm-project).

Match it using a wildcard regex, since it is not relevant to these
tests.

This is intended to reduce future conflicts with rebranch.
2025-05-04 03:28:56 +01:00
Konrad 'ktoso' Malawski
284c060d0a [Distributed] thread-safety also for parameter type metadata
We had fixed this bug in https://github.com/swiftlang/swift/pull/79381
but missed to realize the same problem existed for parameters as well.

This corrects the swift_func_getParameterTypeInfo impl, and also removes
the entire "unsafe" method, we no longer use it anywhere.

Resolves rdar://146679254
2025-04-26 21:30:13 +09:00
Konrad 'ktoso' Malawski
1732834d41 [Distributed] Add another test for SPI Actor System 2025-04-25 14:13:50 +09:00
Konrad 'ktoso' Malawski
9f0f4777c3 Review followup, cleanup test 2025-04-21 12:02:49 +09:00
Konrad 'ktoso' Malawski
957a95be63 [Distributed] Distributed actor usage through protocol with lib-evo must work
This corrects how we were dealing with dispatch thunks -- mostly be
removing a lot of special casing we did but doesn't seem necessary and
instead we correct and emit all the necessary information int TBD.

This builds on  https://github.com/swiftlang/swift/pull/74935 by further refining how we fixed that issue, and adds more regression tests. It also removes a load of special casing of distributed thunks in library evolution mode, which is great.

Resolves and adds regression test for for rdar://145292018

This is also a more proper fix to the previously resolved but in a not-great-way which caused other issues:
- resolves rdar://128284016
- resolves rdar://128310903
2025-04-18 11:21:01 +09:00
Arnold Schwaighofer
5762912af5 Merge pull request #80639 from aschwaighofer/store_once_async_context_addr
IRGen: Don't stored the current async frame to llvm.swift.async.context.addr twice
2025-04-17 08:23:22 -07:00
Konrad 'ktoso' Malawski
af04c84c2d [Distributed] Minor test cleanup 2025-04-09 10:39:24 +09:00
Arnold Schwaighofer
50ebb3f579 IRGen: Don't stored the current async frame to llvm.swift.async.context.addr twice
rdar://148826951
2025-04-08 08:12:07 -07:00
Konrad `ktoso` Malawski
97be02d5b2 [Distributed] Dont emit TBD also for distributed thunks (#80526)
* [Distributed] Accessor must be available cross module in resilient mode

This is an important fix for libraries using @Resolvable in resilient
libraries. Without the fix we're missing an accessor and this will fail
some remote calls which make use of remote calls on resolvable
protocols. This would manifest as missing accessor error thrown by the
executeDistributedTarget function.

resolves rdar://148224780

* Disable test on windows since %env not supported

* [Distributed] Dont emit TBD also for distributed thunks

This resolves pedantic "all" TBD validation issues, i.e. we dont emit
unexpected records anymore - we would before as we only checked for
is_distributed but we also want to skip those for is_distributed_thunk

resolves rdar://128284016
2025-04-07 06:55:19 -07:00
Konrad `ktoso` Malawski
f21d029b82 [Distributed] Accessor must be available cross module in resilient mode (#80523)
* [Distributed] Accessor must be available cross module in resilient mode

This is an important fix for libraries using @Resolvable in resilient
libraries. Without the fix we're missing an accessor and this will fail
some remote calls which make use of remote calls on resolvable
protocols. This would manifest as missing accessor error thrown by the
executeDistributedTarget function.

resolves rdar://148224780

* Disable test on windows since %env not supported
2025-04-07 02:09:23 -07:00
Pavel Yaskevich
ffe25be16f [Tests] Distributed: Use %target-swift-6.0-abi-triple to avoid availability issues 2025-04-04 14:45:10 -07:00
Konrad 'ktoso' Malawski
6ca5ace32d [Distributed] Harden detecting adhoc req methods, don't crash when missing protocol decls
This issue manifested in crashing when in Xcode one would do the Archive
workflow, and we would be missing the Distributed module types and
proceed to run into a nullpointer when faced with code like this:

```
public class TestViewModel {
    public init() {}

    public func onReturn() {
        print("on return executed!")
    }
}
```

where the name matched one of the ad hoc requirements, but we'd get null
for the protocol lookup since this does not import the distributed
module.

resolves rdar://148327936
2025-04-02 18:44:31 +09:00
Pavel Yaskevich
585b687103 [SILOptimizer] Prevent devirtualization of call to distributed witness requirements
This is a narrow fix, we are going to work on fixing this properly
and allowing both devirtualization and specialization for distributed
requirement witnesses.

Anything that uses an ad-hoc serialization requirement scheme cannot
be devirtualized because that would result in loss of ad-hoc conformance
in new substitution map.

Resolves: https://github.com/swiftlang/swift/issues/79318
Resolves: rdar://146101172
2025-03-29 19:27:46 -07:00
Konrad `ktoso` Malawski
8430749e81 [Distributed] Allow @Resolvable to work with available on specific func (#80296)
resolves rdar://147892011
2025-03-26 05:30:51 -07:00
Doug Gregor
8fd02d7ccd Merge pull request #80190 from DougGregor/conformance-isolation-diagnostics
Rework diagnostics for conformance isolation failures
2025-03-21 02:54:53 -07:00
Doug Gregor
1b1f28decb Tighten up diagnostics wording a bit 2025-03-20 22:13:19 -07:00
Doug Gregor
9ea735b9ed Rework diagnostics for conformance isolation failures
A protocol conformance can be ill-formed due to isolation mismatches
between witnesses and requirements, or with associated conformances.
Previously, such failures would be emitted as a number of separate
errors (downgraded to warnings in Swift 5), one for each witness and
potentially an extra for associated conformances. The rest was a
potential flood of diagnostics that was hard to sort through.

Collect all of the isolation-related problems for a given conformance
together and produce a single error (downgraded to a warning when
appropriate) that describes the overall issue. That error will have up
to three notes suggesting specific courses of action:
* Isolating the conformance (when the experimental feature is enabled)
* Marking the witnesses as 'nonisolated' where needed
*

The diagnostic also has notes to point out the witnesses/associated
conformances that have isolation problems. There is a new educational
note that also describes these options.

We give the same treatment to missing 'distributed' on witnesses to a
distributed protocol.
2025-03-20 21:23:16 -07:00
Doug Gregor
cd99fb57fd [Diagnostics] Remove unhelpful notes from witness-isolation diagnostics
When diagnosing an isolation mismatch between a requirement and witness,
we would produce notes on the requirement itself suggesting the addition of
`async`. This is almost never what you want to do, and is often so far
away from the actual conforming type as to be useless. Remove this note,
and the non-function fallback that just points at the requirement, because
they are unhelpful.

This is staging for a rework of the way we deal with conformance-level
actor isolation problems.
2025-03-19 17:18:52 -07:00
Konrad `ktoso` Malawski
39687f1e83 [Distributed] Carry SPI attribute to stub types (#79987)
* [Distributed] Carry SPI attribute to stub types

* Cleaner identifier checking
2025-03-18 04:39:04 -07:00
Konrad `ktoso` Malawski
7d15ce0dcc [Distributed] make sure resolvable works with package level access (#80080) 2025-03-18 01:24:20 -07:00
Mike Ash
1de24cce80 [Test] Clean up leftover comments in distributed_actor_func_calls_without_touching_returnType_metadata_first.swift. 2025-02-17 10:18:01 -05:00
Konrad `ktoso` Malawski
d8f89bd948 [Distributed] improved return type metadata test and dont allow partial metadata 2025-02-15 18:15:10 +09:00
Konrad `ktoso` Malawski
62155f380d [Distributed] Improve getting return type metadata for distributed invocations
rdar://141313340
2025-02-15 11:27:06 +09:00
Erik Eckstein
ba4081ee76 Optimizer: replace PredictableMemoryAccessOptimizations with MandatoryRedundantLoadElimination in the pass pipeline
PredictableMemoryAccessOptimizations has become unmaintainable as-is.
RedundantLoadElimination does (almost) the same thing as PredictableMemoryAccessOptimizations.
It's not as powerful but good enough because PredictableMemoryAccessOptimizations is actually only needed for promoting integer values for mandatory constant propagation.
And most importantly: RedundantLoadElimination does not insert additional copies which was a big problem in PredictableMemoryAccessOptimizations.

Fixes rdar://142814676
2025-02-07 11:30:35 +01:00
Doug Gregor
80278a4a48 Reinstate distributed actor typed throws test with proper availability
This test was failing in some configurations due to missing availability.
Address it in the same manner as other distributed tests do, by setting
a target triple with Swift 5.7.

Fixes rdar://144229403.
2025-02-05 08:56:56 -08:00
Arnold Schwaighofer
f98c5ed4c0 Disable test Distributed/distributed_actor_typed_throws.swift
Until folks can take a look.

It fails on some bots including apparently a pr test bot. For example:

https://ci.swift.org/job/oss-swift_tools-RA_stdlib-DA_test-device-non_executable/8369/
https://ci.swift.org/job/oss-swift_tools-RA_stdlib-DA_test-simulators/5629
 https://ci.swift.org/job/oss-swift-pr-test-macoss/4725

Introduced in https://github.com/swiftlang/swift/pull/79144

rdar://144229403
2025-02-05 07:33:10 -08:00
Doug Gregor
84ed66f3be Ensure that distributed functions with typed throws can be called from outside
When calling a distributed function for an actor that might not be local,
the call can throw due to the distributed actor system producing an
error. The function might, independently, also throw. When the
function uses typed throws, we incorrectly treated the call is if it
would always throw the error type specified by the function. This
leads to incorrectly accepting invalid code, and compiler crashes in
SILGen.

The change here is to always mark calls to distributed functions
outside the actor as "implicitly throwing", which makes sure that we
treat the call sites as throwing 'any Error'. The actual handling of
the typed throw (from the local function) and the untyped throw (from
the distributed actor system) occurs in thunk generation in SILGen,
and was already handled correctly.

Fixes rdar://144093249, and undoes the ban introduced by rdar://136467528
2025-02-04 16:06:51 -08:00
Tony Allevato
c5f0200680 Merge pull request #79059 from allevato/json-ast-followups
[ASTDumper] Some followups from the initial JSON PR and macro dumping improvements.
2025-02-04 01:13:46 -05:00
Konrad `ktoso` Malawski
866848c87b Update test/Distributed/distributed_actor_unsupported_typed_throws.swift 2025-01-29 22:58:44 +00:00
Tony Allevato
5fe10ce86a ASTDumper: Label "interface type" -> "interface_type". 2025-01-29 13:55:00 -05:00
Konrad `ktoso` Malawski
a2b3c488a7 [Distributed] ban typed throws in distributed funcs
They don't yield a correct error type as we didn't implement it, so
rather allow it and risk crashes, ban it until we get the time to
implement it.

The real solution is to adjust typed throws error inference to do an
union of the thrown error of the func and the type thrown by the
distributed actor system remote call -- which today always would be (E |
Error) -> Error...

We could add a new associated type to DAS and then we could make it more
proper...

resolves rdar://136467528
2025-01-28 17:07:21 +00:00
Anthony Latsis
f85eb97337 ConformanceChecker: Make actor_isolated_witness call out the protocol 2025-01-14 14:49:22 +00:00
Mykola Pokhylets
5ac1cba8d1 Handle versioning of the IsolatedDeinit feature 2024-12-12 16:41:02 +09:00
Mykola Pokhylets
bc80529d02 Revert "Merge pull request #77438 from swiftlang/revert-77364-mpokhylets/non-experimental-isolated-deinit"
This reverts commit 11781a5fd1, reversing
changes made to 2ee2f1eb2c.
2024-12-12 16:41:02 +09:00
Konrad `ktoso` Malawski
746720c67b [Distributed] additional test coverage 2024-12-04 15:18:49 +09:00
Konrad `ktoso` Malawski
7189aded61 [Distributed] minor cleanups, remove dump=always from tests 2024-12-03 14:59:16 +09:00
Konrad `ktoso` Malawski
f48384bc7e [Distributed] Correct distributed accessor mangling for protocol calls
This is a crucial fix without which we can crash on some distributed
protocol declarations with @Resolvable. We cannot "just" use a String to
represent the "fake base" of the thunks, and must instead find the
$Target macro generated type and use it as the base of the thunk's
mangling.

Calls are made in such way that record for the protocol requirement:
`$s4main28GreeterDefinedSystemProtocolP5greetSSyYaKFTEHF` points at
`$$s4main29$GreeterDefinedSystemProtocolC5greetSSyYaKFTE` which makes a
dispatch through the _apropriate_ witness table.
And the record for the $witness named e.g.
`$s4main29$GreeterDefinedSystemProtocolC5greetSSyYaKFTEHF` points to
`$s4main28GreeterDefinedSystemProtocolPAA11Distributed01_F9ActorStubRzrlE5greetSSyYaKFTE`
which is an extension method: `distributed thunk (extension in main):main.GreeterDefinedSystemProtocol< where A: Distributed._DistributedActorStub>.greet() async throws -> Swift.String`,
this very specific design allows us to call the "right method" on the
recieving end of a remote call where we do not know the recipient type.
2024-12-03 14:59:15 +09:00
Konrad `ktoso` Malawski
a98a30d404 [Distributed] More tests for primary associated types in protocols 2024-12-03 14:59:15 +09:00
Konrad `ktoso` Malawski
138f145ab9 [Distributed] @Resolvable now handles primary associated types in protocols
Previously we would not propagate those into the generated distributed
actor, making a lot of generic distributed actor protocols impossible to
express.

We indeed cannot handle protocols WITHOUT primary associated types, but
we certainly can handle them with!

This resolves rdar://139332556
2024-12-03 14:59:15 +09: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
Konrad `ktoso` Malawski
aadc67ec0e Revert "Make IsolatedDeinit non-experimental" 2024-11-07 09:59:00 +09:00
Mykola Pokhylets
c139d1b1a7 Make IsolatedDeinit non-experimental 2024-11-05 12:19:01 +01: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
Allan Shortlidge
75bad99f78 Tests: Remove -disable-availability-checking in Distributed tests.
Use the `%target-swift-5.X-abi-triple` substitutions to compile the tests for
deployment to the minimum OS versions required for the APIs used in the tests,
instead of disabling availability checking.
2024-10-20 09:07:13 -07:00
Allan Shortlidge
cb578172ea Tests: Remove -disable-availability-checking in more tests that use concurrency.
Use the `%target-swift-5.1-abi-triple` substitution to compile the tests for
deployment to the minimum OS versions required for use of _Concurrency APIs,
instead of disabling availability checking.
2024-10-19 12:35:20 -07:00