Commit Graph

288 Commits

Author SHA1 Message Date
Doug Gregor
35222e1769 Use preprocessor metaprogramming for macro roles in the demangle node printer 2023-11-26 23:03:13 -08:00
Doug Gregor
4da1032f93 Add name mangling support for functions with a thrown error type 2023-10-29 09:12:32 -07:00
Arnold Schwaighofer
b0424759d7 Add support for objective c protocol symbolic references
Using symbolic references instead of a text based mangling avoids the
expensive type descriptor scan when objective c protocols are requested.

rdar://111536582
2023-10-05 13:11:32 -07:00
Kavon Farvardin
d0a9e78da0 [Mangling] Support function specializations that remove async 2023-09-21 12:20:24 -07:00
Pavel Yaskevich
0ab131c452 [Mangling] NFC: Remove mangling logic and Ha postfix used by @runtimeMetadata records 2023-08-15 12:17:31 -07:00
Slava Pestov
e7a8fdde22 Mangler: Fix de/remangling of Builtin.TheTupleType 2023-08-09 17:42:25 -04:00
Holly Borla
725374e0d8 [Macros] Implement attached extension macros. 2023-06-27 21:22:12 -07:00
Holly Borla
d065d821c5 [Demangler] Demangle init accessors. 2023-06-06 18:57:31 -07:00
Slava Pestov
15bd01b076 Mangler: Mangle PackElementType 2023-06-06 15:42:20 -04:00
Slava Pestov
b2bc2c72ec AST: Introduce PackElementType 2023-05-25 11:17:30 -04:00
Doug Gregor
a23d39bdfb [Macros] Mangle attached macro expansions based only on syntactic information
The mangling of attached macro expansions based on the declaration to
which they are attached requires semantic information (specifically,
the interface type of that declaration) that caused cyclic
dependencies during type checking. Replace the mangling with a
less-complete mangling that only requires syntactic information from
the declaration, i.e., the name of the declaration to which the macro
was attached.

This eliminates reference cycles that occur with attached macros that
produce arbitrary names.
2023-04-11 23:40:28 -04:00
Slava Pestov
07d08b65be Demangler: Fix printing of constrained existential types
We never updated the mangling tree to model existential types, and
NodePrinter still prints 'any P.Type' as 'P.Type' and '(any P).Type'
as 'P.Protocol'.

However, constrained existentials always printed as 'any P',
unfortunately isSimpleType() returned true and isExistentialType()
returned false, so 'any (P<Int>.Type)' and '(any P<Int>).Type' both
printed as 'any P<Int>.Type'.

Changing isSimpleType() to return false fixes this; now we print
'any (P<Int>.Type)' as 'any P<Int>.Type' and '(any P<Int>).Type'
as '(any P<Int>).Type'.
2023-03-23 00:53:13 -04:00
Mike Ash
91dcf8d298 [Runtime] Fix subscript key path printing when arguments can't be resolved.
If there's a mismatch between the arguments we match and the arguments we actually have, we can end up indexing off the end of the argumentTypeNames vector. This can happen when an argument has a dependent generic type. Add a bounds check and print <unknown> when we're out of bounds to avoid crashing.

For correctness, we should match generic dependent types and add them to the arguments array, but we'll fix the crashes first.

rdar://104438524
2023-03-02 13:46:44 -05:00
Slava Pestov
fee32cca3f ASTMangler: Mangle which generic parameters are packs 2023-02-25 16:19:07 -05:00
Slava Pestov
1e2daa2415 Demangler: Factor out NodePrinter::printGenericSignature() 2023-02-25 10:31:41 -05:00
Holly Borla
a3caacd309 [Macros] Initial implementation of conformance macros. 2023-02-23 20:43:11 -08:00
Slava Pestov
d15c592937 Demangler: Add support for SILPackType 2023-02-21 15:33:19 -05:00
Holly Borla
f04f512184 [Macros] Add a new macro role for attached peer macros. 2023-02-10 14:38:22 -08:00
swift-ci
07ad2b6ce4 Merge pull request #63396 from Azoy/fix-runtime-attrs-mangling
[Mangling] Fix Runtime Attribute mangling
2023-02-03 16:47:46 -08:00
Doug Gregor
b63fa566ec [Macros] Add mangling for attached macro expansion.
Extend the name mangling scheme for macro expansions to cover attached
macros, and use that scheme for the names of macro expansions buffers.

Finishes rdar://104038303, stabilizing file/buffer names for macro
expansion buffers.
2023-02-03 13:30:16 -08:00
Alejandro Alonso
1535f305a4 Fix Runtime Attribute mangling
use here

fix tests
2023-02-03 13:26:42 -08:00
Doug Gregor
ac4aa41d0f [Macros] Use macro expansion mangling for unique names in macros
Use the name mangling scheme we've devised for macro expansions to
back the implementation of the macro expansion context's
`getUniqueName` operation. This way, we guarantee that the names
provided by macro expansions don't conflict, as well as making them
demangleable so we can determine what introduced the names.
2023-01-31 09:40:48 -08:00
Doug Gregor
1e6daae179 Rename mangling node for freestanding macro expansions 2023-01-31 09:40:48 -08:00
Doug Gregor
4ae434eaa1 [Macros] Add a mangling for macro expansions
These aren't ABI, but are useful to provide consistent names to refer
to macro expansions, e.g., in buffer names.
2023-01-25 22:45:14 -08:00
Joe Groff
6263956225 Mangler: Fix substitution ordering when mangling opaque return types.
When a declaration has a structural opaque return type like:

  func foo() -> Bar<some P>

then to mangle that return type `Bar<some P>`, we have to mangle the `some P`
part by referencing its defining declaration `foo()`, which in turn includes
its return type `Bar<some P>` again (this time using a special mangling for
`some P` that prevents infinite recursion). Since we mangle `Bar<some P>`
once as part of mangling the declaration, and we register substitutions for
bound generic types when they're complete, we end up registering the
substitution for `Bar<some P>` twice, once as the return type of the
declaration name, and again as the actual type. This would be fine, except
that the mangler doesn't check for key collisions, and it picks
substitution indexes based on the number of entries in its hash map, so
the duplicated substitution ends up corrupting the substitution sequence,
causing the mangler to produce an invalid mangled name.

Fixing that exposes us to another problem in the remangler: the AST
mangler keys substitutions by type identity, but the remangler
uses the value of the demangled nodes to recognize substitutions.
The mangling for `Bar<current declaration's opaque return type>` can
appear multiple times in a demangled tree, but referring to different
declarations' opaque return types, and the remangler would reconstruct
an incorrect mangled name when this happens. To avoid this, change the
way the demangler represents `OpaqueReturnType` nodes so that they
contain a backreference to the declaration they represent, so that
substitutions involving different declarations' opaque return types
don't get confused.
2023-01-03 09:33:07 -08:00
Pavel Yaskevich
6c1f37afda [AST] Add mangling for runtime attribute generators
'fa' is a new contextual prefix which is going to be
used to identify runtime discoverable attribute generator
functions.
2022-12-20 09:45:01 -08:00
Pavel Yaskevich
52cec67a6a [ABI/Mangling] RuntimeMetadata: Add mangling for runtime discoverable attr records 2022-12-20 09:45:01 -08:00
Doug Gregor
d9f5aa0bcd [Mangling] Add a mangling for macro declarations.
Although macro declarations never produce any symbols in the compiled
binary, they can be referenced via USR, so introduce a mangling for
them.
2022-11-28 18:33:10 -08:00
Slava Pestov
987552d53a Mangler: Add support for same-shape requirements 2022-11-12 02:13:54 -05:00
Slava Pestov
f2d1e8d2e9 AST: Invent mangling for PackType and PackExpansionType 2022-11-08 19:09:07 -05:00
Allan Shortlidge
6e07c8cfe1 Mangling: Add a mangling for #_hasSymbol query functions. 2022-10-13 21:00:24 -07:00
Ben Pious
57d82317c1 Add CustomDebugDescription conformance to AnyKeyPath (#60133)
* initial

* it works

demangling mostly works

fix dots

printing works

add tests

add conformance to AnyKeyPath

implement SPI

subscripts fully work

comments

use cross platform image inspection

remove unnecessary comment

fix

fix issues

add conditional conformance

add types

try to fix the api-digester test

cr feedback: move impls behind flag, remove addChain(), switch statement, fallthrough instead of if-elses, move import

cr feedback: refactor switch statement

fix #ifdef

reindent, cr feedback: removes manual memory management

fix missing whitespace

fix typo

fix indentation issues

switch to regexes

checks should test in on all platforms

print types in subscripts

add test for empty subscript

Update test/api-digester/stability-stdlib-abi-without-asserts.test

Co-authored-by: Xiaodi Wu <13952+xwu@users.noreply.github.com>

add commas

fix failing test

fix stdlib annotation

cr feedback: remove global, refactor ifdef

cr feedback: switch back to manual memory management

switch to 5.8 macro

add new weakly linked functions to the allowlist

fix one more failing test

more cr feedback

more cr feedback

* fix invisible unicode
2022-09-13 09:23:32 -07:00
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