Commit Graph

306 Commits

Author SHA1 Message Date
Erik Eckstein
30cd3869b9 Mangling: add a new mangling for generic specialization
For performance annotations we need the generic specializer to trop non-generic metatype argumentrs
(which we don't do in general). For this we need a separate mangling.
2022-07-07 08:34:53 +02:00
John McCall
175f74d38f Implement symbolic demangling for extended existential metadata
Fixes rdar://96268090.
2022-07-01 11:21:53 -04:00
Robert Widmann
dde0d8f609 Generalize the Mangling of Constrained Existential Types
Upgrade the old mangling from a list of argument types to a
list of requiremnets. For now, only same-type requirements
may actually be mangled since those are all that are available
to the surface language.

Reconstruction of existential types now consists of demangling (a list of)
base protocol(s), decoding the constraints, and converting the same-type
constraints back into a list of arguments.

rdar://96088707
2022-06-30 15:32:37 -07:00
Erik Eckstein
718de937b7 Add a mangling for constant static arrays.
The layout of constant static arrays differs from non-constant static arrays.
Therefore use a different mangling to get symbol mismatches if for some reason two modules don't agree on which version a static array is.
2022-06-17 11:21:29 +02:00
Josh Soref
41ee0b9a4b spelling: important
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-05-01 04:32:23 -04:00
John McCall
bd77714537 Unique extended existential shapes using the generalized AST type.
I wrote out this whole analysis of why different existential types
might have the same logical content, and then I turned around and
immediately uniqued existential shapes purely by logical content
rather than the (generalized) formal type.  Oh well.  At least it's
not too late to make ABI changes like this.

We now store a reference to a mangling of the generalized formal
type directly in the shape.  This type alone is sufficient to unique
the shape:

- By the nature of the generalization algorithm, every type parameter
  in the generalization signature should be mentioned in the
  generalized formal type in a deterministic order.

- By the nature of the generalization algorithm, every other
  requirement in the generalization signature should be implied
  by the positions in which generalization type parameters appear
  (e.g. because the formal type is C<T> & P, where C constrains
  its type parameter for well-formedness).

- The requirement signature and type expression are extracted from
  the existential type.

As a result, we no longer rely on computing a unique hash at
compile time.

Storing this separately from the requirement signature potentially
allows runtimes with general shape support to work with future
extensions to existential types even if they cannot demangle the
generalized formal type.

Storing the generalized formal type also allows us to easily and
reliably extract the formal type of the existential.  Otherwise,
it's quite a heroic endeavor to match requirements back up with
primary associated types.  Doing so would also only allows us to
extract *some* matching formal type, not necessarily the *right*
formal type.  So there's some good synergy here.
2022-04-21 23:47:01 -04:00
John McCall
24616aed5c Mangling support for extended existential type shapes 2022-04-11 22:25:11 -04:00
Alastair Houghton
e857862f21 [Demangler] Add a couple of functions back to the minimal build.
Some of the functions inside the SWIFT_STDLIB_HAS_TYPE_PRINTING conditional
are now needed even in the minimal build as a result of #41452.

rdar://90839754
2022-03-25 17:34:23 +00:00
Konrad `ktoso` Malawski
5ab8e0834d [Distributed] Reimplement distributed call thunks completely in AST (#41616)
* [Distributed] dist actor always has default executor (currently)

* [Distributed] extra test for missing makeEncoder

* [DistributedDecl] Add DistributedActorSystem to known SDK types

* [DistributedActor] ok progress on getting the system via witness

* [Distributed] allow hop-to `let any: any X` where X is DistActor

* [Distributed] AST: Add an accessor to determine whether type is distributed actor

- Classes have specialized method on their declarations
- Archetypes and existentials check their conformances for
  presence of `DistributedActor` protocol.

* [Distributed] AST: Account for distributed members declared in class extensions

`getConcreteReplacementForProtocolActorSystemType` should use `getSelfClassDecl`
otherwise it wouldn't be able to find actor if the member is declared in an extension.

* [Distributed] fix ad-hoc requirement checks for 'mutating'

[PreChecker] LookupDC might be null, so account for that

* [Distributed] Completed AST synthesis for dist thunk

* [Distributed][ASTDumper] print pretty distributed in right color in AST dumps

* wip on making the local/remote calls

* using the _local to mark the localCall as known local

* [Distributed] fix passing Never when not throwing

* fix lifetime of mangled string

* [Distributed] Implement recordGenericSubstitution

* [Distributed] Dont add .

* [Distributed] dont emit thunk when func broken

* [Distributed] fix tests; cleanups

* [Distributed] cleanup, move is... funcs to DistributedDecl

* [Distributed] Remove SILGen for distributed thunks, it is in Sema now!

* [Distributed]  no need to check stored props in protocols

* remote not used flag

* fix mangling test

* [Distributed] Synthesis: Don't re-use AST nodes for `decodeArgument` references

* [Distributed] Synthesis: Make sure that each thunk parameter has an internal name

* [Distributed/Synthesis] NFC: Add a comment regarding empty internal parameter names

* [Distributed] NFC: Adjust distributed thunk manglings in the accessor section test-cases

* cleanup

* [Distributed] NFC: Adjust distributed thunk manglings in the accessor thunk test-cases

* review follow ups

* xfail some linux tests for now so we can land the AST thunk

* Update distributed_actor_remote_functions.swift

Co-authored-by: Pavel Yaskevich <xedin@apache.org>
2022-03-10 23:58:23 +09:00
Robert Widmann
f7b2a8ec9a Pretty-Print Bound Demangled Parameterized Protocols 2022-03-08 22:01:21 -08:00
Robert Widmann
3b3ff6a5db Define Mangling for ParameterizedProtocol 2022-03-08 22:01:19 -08:00
Allan Shortlidge
ed6d69fb15 Mangling: Add a mangling for back deployment fallback functions and update the back deployment thunk mangling to use the same prefix. 2022-02-18 16:30:27 -08:00
Allan Shortlidge
ff5abc4e2f Mangling: Use 'Tw' to mangle back deployment thunks. 2022-02-17 11:28:12 -08:00
Erik Eckstein
13d2b1fe15 mangling: add a mangling for constant propagating keypaths in capture propagation.
This is not ABI affecting.
2022-02-01 08:13:27 +01:00
Xi Ge
1667c5f643 mangling: take the constness of function parameters into mangling
Taking constness of parameters into mangling allows us to support overloads of
functions vary on the constness of specific parameters.

rdar://87954644
2022-01-24 11:51:01 -08:00
Michael Gottesman
5dc8b3879b [move-function] SILCloner/mangling changes to support converting inout_aliasable defer parameters to out parameters after move analysis. 2022-01-08 13:41:05 -08:00
Doug Gregor
61d35f07a4 Merge pull request #40766 from DougGregor/mangle-multiple-opaque-types
Introduce a mangling for multiple opaque types within the declaration.
2022-01-07 15:45:38 -08:00
Doug Gregor
f89ff0485f Introduce a mangling for multiple opaque types within the declaration.
The `Qr` mangling is used to refer to the opaque type within the
declaration that produces the opaque type. When there are multiple
opaque types, e.g., due to structural or named opaque result types, it
does not specify which of the opaque type parameters it refers to.

Introduce a new mangling `QR INDEX` for opaque type parameters after
the first, retaining the `Qr` mangling for the first opaque type
parameter. This way, existing (non-structural) uses of opaque result
types retain the same manglings, but uses of structural or named
opaque result types (new features) will have distinct manglings.

Note that this mangling within a declaration is only used for the
declaration itself, and not for references to the opaque type of the
declaration, so there is no impact on the runtime demangler.
2022-01-07 10:43:45 -08:00
Pavel Yaskevich
d516281da9 [Distributed] NFC: Remove Method from accessor APIs
The API is not constrained to methods only, it should support
computed properties as well.
2021-12-23 14:10:05 -08:00
Kuba (Brecka) Mracek
663a6fb771 Introduce SWIFT_STDLIB_HAS_TYPE_PRINTING flag to remove the ability to print types at runtime (to save codesize) (#40649) 2021-12-21 17:47:54 -08:00
Pavel Yaskevich
8e1aa19188 [Mangling] Define mangling for runtime accessible function records 2021-12-17 10:52:56 -08:00
Pavel Yaskevich
b8358b26fe [Mangling] Add mangling for distributed method accessors
`Distributed Method Accessor` is a global helper function
to get access to particular `distributed method` on an actor
from outside the process.
2021-12-17 10:52:55 -08:00
Saleem Abdulrasool
910fbee14e gardening: make c++98-compat-extra-semi an error
This cleans up 90 instances of this warning and reduces the build spew
when building on Linux.  This helps identify actual issues when
building which can get lost in the stream of warning messages.  It also
helps restore the ability to build the compiler with gcc.
2021-11-27 11:40:17 -08:00
Mike Ash
4440bd4977 Merge pull request #40055 from mikeash/swift-inspect-dump-arrays
[swift-inspect] Add a command to dump information about allocated arrays in the target process.
2021-11-18 20:50:12 -05:00
Mike Ash
9fa76e2f4f [swift-inspect] Add a command to dump information about allocated arrays in the target process. 2021-11-04 16:15:15 -04:00
Alastair Houghton
50c55ce4d9 [Tests][Demangling] Reduce maximum recursion depth for NodePrinter.
At MaxDepth 1024, NodePrinter will blow the stack on a debug build.
Reduce it to 768.

rdar://84615816
2021-10-26 17:12:14 +01:00
Doug Gregor
142973b653 Use a non-conflicting mangling for distributed thunks.
Distributed thunks were using the same mangling as direct method
reference thunks (i.e., for "super" calls). Although not technically
conflicting so long as actors never gain inheritance, it's confusing
and could cause problems in the future. So, introduce a distinct
mangling for distributed thunks and plumb them through the demangling
and remangler.
2021-10-15 23:15:43 -07:00
Kuba Mracek
d0e05003f5 For individual runtime records for types/protocols/conformances, add and use new mangling suffixes 2021-09-29 13:14:58 -07:00
Alastair Houghton
e6ced29908 [Demangler] Fix incorrect assertions in OldRemangler and NodePrinter.
There can be, currently, up to eight child nodes for a FunctionType.
OldRemangler seemed to think there could only be three, while NodePrinter
plumped for six.

rdar://82252704
2021-08-27 11:24:19 +01:00
Evan Wilde
191dc14c59 Merge pull request #38171 from etcwilde/ewilde/remove-extraneous-isSerialized
[NFC] Remove 'isSerialized' from NodePrinter
2021-07-07 11:20:03 -07:00
Alastair Houghton
8f717d2c50 [Demangler] Prevent stack overflow by limiting recursion depth.
It's trivially easy to drive the remanglers, the type decoder and the node
printer into a situation where they will overflow the process's stack.  For the
compiler, this is fine (though not great), but for the runtime it's a no-no.

This changeset imposes recursion depth limits to prevent uncontrolled stack
overruns.

rdar://68449341
2021-07-01 11:11:59 +01:00
Evan Wilde
353dba2635 [NFC] Remove 'isSerialized' from NodePrinter
'isSerialized' is tracked, but never actually used in
NodePrinter::print.

Was introduced in bc119d0d6d.
2021-06-29 14:38:44 -07:00
Doug Gregor
58f49692ed Add mangling, metadata, and reflection support for "isolated" parameters.
Isolated parameters are part of function types. Encode them in function
type manglings and metadata, and ensure that they round-trip through
the various mangling and metadata facilities. This nails down the ABI
for isolated parameters.
2021-06-08 00:00:11 -07:00
Alastair Houghton
3d11fb97ab [SR-13466]: Fix demangling of optionals containing function types.
ImplFunctionType nodes inside optionals are wrapped in Type nodes,
which means that isSimpleType() needs to look through the Type node
when we're printing them, or we fail to wrap them with parentheses.

<rdar://67915116>
2021-06-04 20:56:51 +01:00
Doug Gregor
b814e225dd Implement (de-)mangling and type metadata for global actor function types.
Implement name mangling, type metadata, runtime demangling, etc. for
global-actor qualified function types. Ensure that the manglings
round-trip through the various subsystems.

Implements rdar://78269642.
2021-06-02 23:34:22 -07:00
Joe Groff
92f56e7ec8 Allow conversions from actor-bound sync function type to unbound async function type.
For `async` function types, an actor constraint can be enforced by the callee by hopping executors,
unlike with `sync` functions, so doesn't need to influence the outward type of the function.

rdar://76248452
2021-05-21 14:17:50 -07:00
Dave Lee
07686979db Demangling: Add option for printing simplified async resume functions 2021-04-20 16:15:11 -07:00
Richard Wei
fb66de6126 Unify mangling operators for async, @Sendable, @differentiable and @noDerivative.
Repurpose mangling operator `Y` as an umbrella operator that covers new attributes on function types. Free up operators `J`, `j`, and `k`.

```
async ::= 'Ya'                             // 'async' annotation on function types
sendable ::= 'Yb'                          // @Sendable on function types
throws ::= 'K'                             // 'throws' annotation on function types
differentiable ::= 'Yjf'                   // @differentiable(_forward) on function type
differentiable ::= 'Yjr'                   // @differentiable(reverse) on function type
differentiable ::= 'Yjd'                   // @differentiable on function type
differentiable ::= 'Yjl'                   // @differentiable(_linear) on function type
```

Resolves rdar://76299796.
2021-04-07 17:49:10 -07:00
Richard Wei
82886bf77a [AutoDiff] Fix mangling of '@noDerivative' in function types.
`@noDerivative` was not mangled in function types, and was resolved incorrectly when there's an ownership specifier. It is fixed by this patch with the following changes:

* Add `NoDerivative` demangle node represented by a `k` operator.
    ```
    list-type ::= type identifier? 'k'? 'z'? 'h'? 'n'? 'd'?  // type with optional label, '@noDerivative', inout convention, shared convention, owned convention, and variadic specifier
    ```
* Fix `NoDerivative`'s overflown offset in `ParameterTypeFlags` (`7` -> `6`).
* In type decoder and type resolver where attributed type nodes are processed, add support for nested attributed nodes, e.g. `inout @noDerivative T`.
* Add `TypeResolverContext::InoutFunctionInput` so that when we resolve an `inout @noDerivative T` parameter, the `@noDerivative T` checking logic won't get a `TypeResolverContext::None` set by the caller.

Resolves rdar://75916833.
2021-04-07 15:42:12 -07:00
Nate Chandler
3243def046 Revert "[IRGen] Mangling for async, non-constant partial_apply thunks."
This reverts commit efaaee3656.
2021-04-06 15:51:33 -07:00
Richard Wei
d997526948 Fix function differentiability kind metadata and mangling. (#36601)
* Move differentiability kinds from target function type metadata to trailing objects so that we don't exhaust all remaining bits of function type metadata.
  * Differentiability kind is now stored in a tail-allocated word when function type flags say it's differentiable, located immediately after the normal function type metadata's contents (with proper alignment in between).
  * Add new runtime function `swift_getFunctionTypeMetadataDifferentiable` which handles differentiable function types.
* Fix mangling of different differentiability kinds in function types. Mangle it like `ConcurrentFunctionType` so that we can drop special cases for escaping functions.
    ```
    function-signature ::= params-type params-type async? sendable? throws? differentiable? // results and parameters
    ...
    differentiable ::= 'jf'                    // @differentiable(_forward) on function type
    differentiable ::= 'jr'                    // @differentiable(reverse) on function type
    differentiable ::= 'jd'                    // @differentiable on function type
    differentiable ::= 'jl'                    // @differentiable(_linear) on function type
    ```

Resolves rdar://75240064.
2021-03-30 09:59:06 -07:00
Doug Gregor
52096a640e SE-0302: Rename ConcurrentValue/@concurrent to Sendable/@Sendable. 2021-03-18 23:48:21 -07:00
Arnold Schwaighofer
00f495f48c Mangling for suspend/await resume partial functions
We use the suffix 'TQ'index and 'TP'index.
2021-03-15 11:13:22 -07:00
Nate Chandler
efaaee3656 [IRGen] Mangling for async, non-constant partial_apply thunks.
The scheme uses 'Tw' followed by the index--the number of non-constant
async partial applies that have been thunked in the function.
2021-03-14 17:30:43 -07:00
Holly Borla
648c5753df [SILGen] Teach SILGen to emit property wrapper generator functions that
take in a projected value.
2021-02-25 18:35:14 -08:00
Joe Groff
4bb49ba521 SILGen/ClangImporter: Handle async imports with a boolean error flag argument.
Import APIs with the `swift_async_error` attribute in `zero_argument` or `nonzero_argument`
modes by checking the corresponding boolean argument to indicate the error status, instead of
treating it as part of the result tuple. rdar://70594666
2021-02-19 17:31:09 -08:00
Richard Wei
e494df2ee6 [AutoDiff] Add differentiability kind to differentiability witnesses and mangle them.
Differentiability witnesses are now keyed by the original function name, the differentiability kind, and the autodiff config.

Updated SIL syntax:
```
differentiability-kind ::= 'forward' | 'reverse' | 'normal' | 'linear'
sil-differentiability-witness ::=
    'sil_differentiability_witness'
    sil-linkage?
    '[' differentiability-kind ']'
    '[' 'parameters' sil-differentiability-witness-function-index-list ']'
    '[' 'results' sil-differentiability-witness-function-index-list ']'
    generic-parameter-clause?
    sil-function-name ':' sil-type
    sil-differentiability-witness-body?
sil-instruction ::=
    'differentiability_witness_function'
    '[' sil-differentiability-witness-function-kind ']'
    '[' differentiability-kind ']'
    '[' 'parameters' sil-differentiability-witness-function-index-list ']'
    '[' 'results' sil-differentiability-witness-function-index-list ']'
    generic-parameter-clause?
    sil-function-name ':' sil-type
```
```console
sil_differentiability_witness [reverse] [parameters 0 1] [results 0] <T where T: Differentiable> @foo : <T> $(T) -> T
differentiability_witness_function [vjp] [reverse] [parameters 0] [results 0] <T where T: Differentiable> @foo : $(T) -> T
```

New mangling:
```swift
  global ::= global generic-signature? 'WJ' DIFFERENTIABILITY-KIND INDEX-SUBSET 'p' INDEX-SUBSET 'r' // differentiability witness
```
```console
$s13test_mangling3fooyS2f_S2ftFWJrSpSr ---> reverse differentiability witness for test_mangling.foo(Swift.Float, Swift.Float, Swift.Float) -> Swift.Float with respect to parameters {0} and results {0}
```

Resolves rdar://74380324.
2021-02-17 18:27:42 -05:00
Richard Wei
75088cde3e [AutoDiff] Mangle derivative vtable thunks.
Add the following mangling rule:
```
global ::= global generic-signature? 'TJV' AUTODIFF-FUNCTION-KIND INDEX-SUBSET 'p' INDEX-SUBSET 'r' // autodiff derivative vtable thunk
```

Resolves rdar://74340331.
2021-02-15 00:11:50 -08:00
Richard Wei
f9ddecf459 [AutoDiff] Mangle linear map self-reordering thunks and subset parameters thunks.
Add the following new mangling rules.
```
global ::= from-type to-type 'TJO' AUTODIFF-FUNCTION-KIND // autodiff self-reordering reabstraction thunk
global ::= from-type 'TJS' AUTODIFF-FUNCTION-KIND INDEX-SUBSET 'p' INDEX-SUBSET 'r' INDEX-SUBSET 'P' // autodiff linear map subset parameters thunk
global ::= global to-type 'TJS' AUTODIFF-FUNCTION-KIND INDEX-SUBSET 'p' INDEX-SUBSET 'r' INDEX-SUBSET 'P' // autodiff derivative function subset parameters thunk
```

Example:
```console
$s13TangentVector16_Differentiation14DifferentiablePQzAaDQy_SdAFIegnnnr_TJSdSSSpSrSUSP ---> autodiff subset parameters thunk for differential from @escaping @callee_guaranteed (@in_guaranteed A._Differentiation.Differentiable.TangentVector, @in_guaranteed B._Differentiation.Differentiable.TangentVector, @in_guaranteed Swift.Double) -> (@out B._Differentiation.Differentiable.TangentVector) with respect to parameters {0, 1, 2} and results {0} to parameters {0, 2}
$sS2f8mangling3FooV13TangentVectorVIegydd_SfAESfIegydd_TJOp ---> autodiff self-reordering reabstraction thunk for pullback from @escaping @callee_guaranteed (@unowned Swift.Float) -> (@unowned Swift.Float, @unowned mangling.Foo.TangentVector) to @escaping @callee_guaranteed (@unowned Swift.Float) -> (@unowned mangling.Foo.TangentVector, @unowned Swift.Float)
```

Resolves rdar://72666310 / SR-13508.

Also fix a bug in `AutoDiffFunction` mangling where the original may be a global that contains more than 1 node (rdar://74151229 / SR-14106).
2021-02-13 01:38:35 -08:00
Richard Wei
af8942d940 [AutoDiff] Rename '@differentiable' to '@differentiable(reverse)'.
Compiler:
- Add `Forward` and `Reverse` to `DifferentiabilityKind`.
- Expand `DifferentiabilityMask` in `ExtInfo` to 3 bits so that it now holds all 4 cases of `DifferentiabilityKind`.
- Parse `@differentiable(reverse)` and `@differentiable(_forward)` declaration attributes and type attributes.
- Emit a warning for `@differentiable` without `reverse`.
- Emit an error for `@differentiable(_forward)`.
- Rename `@differentiable(linear)` to `@differentiable(_linear)`.
- Make `@differentiable(reverse)` type lowering go through today's `@differentiable` code path. We will specialize it to reverse-mode in a follow-up patch.

ABI:
- Add `Forward` and `Reverse` to `FunctionMetadataDifferentiabilityKind`.
- Extend `TargetFunctionTypeFlags` by 1 bit to store the highest bit of differentiability kind (linear). Note that there is a 2-bit gap in `DifferentiabilityMask` which is reserved for `AsyncMask` and `ConcurrentMask`; `AsyncMask` is ABI-stable so we cannot change that.

_Differentiation module:
- Replace all occurrences of `@differentiable` with `@differentiable(reverse)`.
- Delete `_transpose(of:)`.

Resolves rdar://69980056.
2021-02-07 14:09:46 -08:00