Commit Graph

105 Commits

Author SHA1 Message Date
Kavon Farvardin 21b2ebff12 Sema: infer inverses in opaque return types
Opaque return types are special type declarations that have it
own nested generic signature. Thus, given this:
```
  protocol P<A> { associatedtype A: ~Copyable }
  func f<T: ~Copyable>() -> some P<T> {}
```
The generic signature for f is <T where T Escapable>, and
for the opaque return type, its nested signature ends up as
```
  <X where X: P, X.A == T>
```
With SE-503, we will now also expand a default for the suppressed
primary associated type, so the signature after expansion becomes
```
  <X where X: P, X.A == T, X.A: Copyable>
```
It would be smarter to effectively have this rule
```
  X.A == T, T: ~Copyable
  ----------------------
     X.A: ~Copyable
```
where we infer the inverse on X.A to cancel-out the
expanded default X.A: Copyable. We already do this for
two in-scope type parameters, and it would be better if
we did it if one side was out-of-scope, but that would
be source-breaking to do in general.

In the case of opaque return types, the fact that
it has a nested generic signature seems more an
artifact of the implementation. There also is little
risk of source break, as the only kinds of same-type
requirements that can appear are from parameterized
protocol type.

The experimental suppressed associated types prior to
SE-503 wouldn't be broken by this change, as they do
not infer defaults that need suppression, and we only
filter-out requirements from defaults expansion, rather
than explicitly-written ones.

rdar://175500824
2026-05-04 14:49:34 -07:00
Kavon Farvardin 6651cb6389 NFC: refactor the applyInverses bool
There's a need for more control over how default requirements
for conformance to Copyable/Escapable are expanded, and
subsequently how inverses are applied or inferred to cancel-out
those defaults.

The pattern of `/*applyInverses*/BOOL` is insufficient, so this
is a refactoring to grow that into a proper type that carries
an option that can be used in some future scenario about inferring
inverses for opaque return types.
2026-04-29 16:56:00 -07:00
Konrad `ktoso` Malawski 4c1e2c55cc [Distributed] distributed accessor fixes against optimization (#87453)
WIP, still not enough

resolves rdar://168881945
2026-03-02 13:46:11 +09:00
Slava Pestov d09c773536 IRGen: Fix yet another typed throws crash
- Fixes https://github.com/swiftlang/swift/issues/86347.
2026-01-08 14:20:42 -05:00
Anthony Latsis fec049e5e4 Address llvm::PointerUnion::{is,get} deprecations
These were deprecated in
https://github.com/llvm/llvm-project/pull/122623.
2025-07-29 18:37:48 +01:00
Anthony Latsis f8577a2731 IRGen: Address llvm::Type::getPointerTo deprecation
See https://github.com/llvm/llvm-project/pull/113331.
2025-07-21 12:37:15 +01:00
Konrad `ktoso` Malawski e4c0c79d65 Apply suggestions from code review 2025-05-09 06:24:14 +09:00
Konrad 'ktoso' Malawski d7152c789d [Distributed] pointer auth protocol pointers as we use conformsToProtocol 2025-05-08 13:05:53 +09:00
Slava Pestov cf1572c65b AST: Add ASTContext::TheSelfType for convenience 2025-04-28 11:49:50 -04:00
Konrad `ktoso` Malawski ed5007f6b1 Merge pull request #77584 from ktoso/wip-check-array-calls 2024-12-04 21:01:36 +09:00
Konrad `ktoso` Malawski 7189aded61 [Distributed] minor cleanups, remove dump=always from tests 2024-12-03 14:59:16 +09:00
Kuba Mracek 6f4ae28520 [ASTMangler] Pass ASTContext to all instantiations of ASTMangler 2024-12-02 15:01:04 -08:00
Alejandro Alonso f4f60f4344 Remove Value requirement Add GenericTypeParamKind 2024-09-04 15:13:43 -07:00
Alejandro Alonso 75c2cbf593 Implement value generics
Some requirement machine work

Rename requirement to Value

Rename more things to Value

Fix integer checking for requirement

some docs and parser changes

Minor fixes
2024-09-04 15:13:25 -07:00
Akira Hatanaka 42bc49d3fe Add a new parameter convention @in_cxx for non-trivial C++ classes that are passed indirectly and destructed by the caller (#73019)
This corresponds to the parameter-passing convention of the Itanium C++
ABI, in which the argument is passed indirectly and possibly modified,
but not destroyed, by the callee.

@in_cxx is handled the same way as @in in callers and @in_guaranteed in
callees. OwnershipModelEliminator emits the call to destroy_addr that is
needed to destroy the argument in the caller.

rdar://122707697
2024-06-27 09:44:04 -07:00
Tim Kientzle 1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Pavel Yaskevich 53c9049b99 [AST] NFC: Move distributed actor methods from ASTContext into swift namespace 2024-03-06 13:51:14 -08:00
Pavel Yaskevich c00c692c96 [IRGen] Distributed: Fix distributed actor metadata referencing when ObjC interop is disabled 2024-03-04 17:46:49 -08:00
Pavel Yaskevich 1e06448da7 [IRGen] Distributed: Remove a requirement that accessible function should be backed by SILFunction
Distributed protocol requirements don't have associated SILFunction,
let's introduce a more flexible way to define it that collects only
the information necessary for the function to become accessible.
2024-03-04 15:59:57 -08:00
Pavel Yaskevich c6820a539b [IRGen] Distributed: Expand distributed actor accessor to support protocol requirements
Given the following protocol:

```
protocol Greeter : DistributedActor {
  distributed func greet()
}
```

The changes make it possible to synthesize a distributed accessor
thunk for the requirement `greet` which would be dispatched to the
underlying concrete actor implementation at runtime.
2024-03-04 15:59:23 -08:00
Pavel Yaskevich 548f2f63ff [IRGen] Distributed/NFC: Collect all target handling logic into AccessorTarget 2024-03-01 15:47:36 -08:00
Pavel Yaskevich 89231745c8 [IRGen] Distributed: Drop unused parameter from getAccessorType 2024-03-01 14:32:56 -08:00
Konrad `ktoso` Malawski c56a1e8be7 [Distributed] Handle mangling thunks in extensions with generic AS and $Stubs (#71914) 2024-02-29 04:22:00 -08:00
Pavel Yaskevich 6789506474 [IRGen] Distributed: Skip protocols that don't require witness tables for decodeNextArgument call 2024-02-21 13:29:47 -08:00
Pavel Yaskevich 738ac14489 [IRGen] Distributed: Dispatch decodeNextArgument via witness thunk if concrete decoder is not available
Since distributed actors can now be generic over actor system
it's no longer guaranteed for concrete decoder to be present,
we need to handle that case specifically during accessor emission.
2024-02-21 13:29:47 -08:00
Pavel Yaskevich c0dc88878c Revert "[IRGen] Distributed: Always invoke decodeNextArgument through witness thunk"
This reverts commit 4d4c80b8ec.
2024-02-21 13:29:47 -08:00
Konrad `ktoso` Malawski 551b07ba80 [Distributed] Fix _executeDistributedTarget ABI (#71725) 2024-02-19 21:23:11 -08:00
Konrad `ktoso` Malawski e9c7f3c382 [Distributed] Target identifiers for protocol calls (#70928) 2024-02-16 07:19:20 -08:00
Pavel Yaskevich 4d4c80b8ec [IRGen] Distributed: Always invoke decodeNextArgument through witness thunk
`decodeNextArgument` is now a requirement, so thunks should be
always calling that instead of trying to dispatch directly.
2024-02-12 14:26:30 -08:00
Slava Pestov af50d7e6b8 AST: Add allowInverses flag to AbstractGenericSignatureRequest 2024-02-05 18:43:06 -05:00
Konrad `ktoso` Malawski 4d5324560f Fix some warnings in GenDistributed.cpp (#71235) 2024-01-29 22:41:52 -08:00
Konrad `ktoso` Malawski dfdbe457bf [Distributed] Support complex generic distributed actors in thunk gen (#70842) 2024-01-28 01:26:52 -08:00
Arnold Schwaighofer 2f94890e5f IRGen: Remove supportsTypedPointers, getNonOpaquePointerElementType, isOpaqueOrPointeeTypeMatches
Typed pointers are no longer supported by llvm.

rdar://121083958
2024-01-17 07:33:30 -08:00
Konrad `ktoso` Malawski 396ecdf5ed [Distributed] Destroy decoded parameters after executeDistributedTarget (#70806) 2024-01-11 11:56:14 +09:00
Mishal Shah aa6a588f45 Merge pull request #69163 from apple/rebranch
Merge `rebranch` into `main` to support `stable/20230725` llvm-project branch
2023-10-23 09:26:37 -07:00
Konrad `ktoso` Malawski b542a5dc19 Simplify branching logic 2023-10-20 13:43:46 +09:00
Konrad `ktoso` Malawski 2bda332738 Remove dumpContext 2023-10-20 13:15:47 +09:00
Konrad `ktoso` Malawski 137dddba17 handle detecting generic code better 2023-10-20 10:40:33 +09:00
Konrad `ktoso` Malawski 8159b239d1 [Distributed] Handle dispach thunks of decodeNextArgument in Distributed IRGen
correct way to detect dispatch thunk presence in GenDistributed
2023-10-20 10:30:46 +09:00
Evan Wilde f4946e9718 Updating more alignment APIs
Adding a few more updates to places where the ABI Alignment functions
changed. `getABITypeAlignment` was replaced with `getABITypeAlign`,
which returns an `llvm::Align` instead of an unsigned int.
2023-07-25 12:28:28 -07:00
Evan Wilde 26a974e772 [NFC] Headers headers headers!
Including headers that were being transitively included from LLVM
before. Also pointing them at the new locations for some of them.
2023-07-17 10:55:55 -07:00
Evan Wilde 8ce6ee8dd1 Updating API usages
LLVM deprecated, renamed, and removed a bunch of APIs. This patch
contains a lot of the changes needed to deal with that.

The SetVector type changed the template parameters.

APInt updated multiple names, countPopulation became popcount,
getAllOnesValue became getAllOnes, getNullValue became getZero, etc...

Clang type nullability check stopped taking a clang AST context.

The LLVM IRGen Function type stopped exposing basic block list directly,
but gained enough API surface that the translation isn't too bad.
(GenControl.cpp, LLVMMergeFunctions.cpp)

llvm::Optional had a transform function. That was being used in a couple
of places, so I've added a new implementation under STLExtras that
transforms valid optionals, otherwise it returns nullopt.
2023-07-17 10:53:42 -07:00
Konrad `ktoso` Malawski 1b74ea62b4 Add test to exercise Indirect_In codepaths in DistributedAccessor emit 2023-07-12 13:22:49 +09:00
Konrad `ktoso` Malawski 5abfc91291 [Distributed] Fix handling indirect @in convention params in distributed funcs
rdar://111887706
2023-07-12 10:24:38 +09:00
Konrad `ktoso` Malawski b54f409763 [Distributed] Handle composite type in generic bound in distributed accessor
rdar://111664985
2023-07-05 10:36:59 +09:00
Konrad `ktoso` Malawski 0104f2b324 formatting 2023-05-19 23:41:58 +02:00
Konrad `ktoso` Malawski cd3e243ff8 [Distributed] Ensure decoded classes get refcounted down to 0 from decoding 2023-05-19 23:29:49 +02:00
Pavel Yaskevich 8569c9d081 [IRGen] Distributed: Destroy loaded arguments after the call
Arguments that have been loaded due to underlying method conversion
have to be destroyed after the call otherwise they are going to leak.

Resolves: https://github.com/apple/swift/issues/65853
Resolves: rdar://109207043
2023-05-15 14:46:19 -07:00
John McCall d25a8aec8b Add explicit lowering for value packs and pack expansions.
- SILPackType carries whether the elements are stored directly
  in the pack, which we're not currently using in the lowering,
  but it's probably something we'll want in the final ABI.
  Having this also makes it clear that we're doing the right
  thing with substitution and element lowering.  I also toyed
  with making this a scalar type, which made it necessary in
  various places, although eventually I pulled back to the
  design where we always use packs as addresses.

- Pack boundaries are a core ABI concept, so the lowering has
  to wrap parameter pack expansions up as packs.  There are huge
  unimplemented holes here where the abstraction pattern will
  need to tell us how many elements to gather into the pack,
  but a naive approach is good enough to get things off the
  ground.

- Pack conventions are related to the existing parameter and
  result conventions, but they're different on enough grounds
  that they deserve to be separated.
2023-01-29 03:29:06 -05:00
Slava Pestov aae03550b4 IRGen: Basic support for computing function signatures with shape parameters 2022-12-13 11:56:33 -05:00