Commit Graph

384 Commits

Author SHA1 Message Date
Ben Barham
9779c18da3 Rename startswith to starts_with
LLVM is presumably moving towards `std::string_view` -
`StringRef::startswith` is deprecated on tip. `SmallString::startswith`
was just renamed there (maybe with some small deprecation inbetween, but
if so, we've missed it).

The `SmallString::startswith` references were moved to
`.str().starts_with()`, rather than adding the `starts_with` on
`stable/20230725` as we only had a few of them. Open to switching that
over if anyone feels strongly though.
2024-03-13 22:25:47 -07:00
Kavon Farvardin
e2d33ecd5f Merge pull request #71878 from kavon/ncgenerics-mangling-2
NCGenerics: New Inverse Mangling 3DS XL
2024-03-05 18:15:40 -08:00
Kavon Farvardin
215bd3cab4 Mangling: handle inverse requirements 2024-03-05 14:19:00 -08:00
Michael Gottesman
29db927ca9 [transferring] Fix mangling for reabstraction thunks with a transferring result.
rdar://124048418
2024-03-04 19:34:26 -08:00
Michael Gottesman
f4efcec55c [transferring] Add mangling support for transferring.
This includes runtime support for instantiating transferring param/result in
function types. This is especially important since that is how we instantiate
function types like: typealias Fn = (transferring X) -> ().

rdar://123118061
2024-02-19 12:11:57 -08:00
Meghana Gupta
0fd6ef3309 Add support for lifetime dependence mangling 2024-02-14 13:16:31 -08:00
John McCall
d5142668f4 SIL and IRGen support for @isolated(any). SILGen to come. 2024-02-13 03:04:13 -05:00
John McCall
2f8a33cf0a Experimental type-checking support for @isolated(any) function types. 2024-02-06 22:54:27 -05:00
Erik Eckstein
fcd5225f39 Mangling: add mangling for outlined value operations which must not use value witness functions 2024-02-05 12:33:18 +01:00
Arnold Schwaighofer
01df0ca1ff Merge pull request #71092 from aschwaighofer/outline_enum_addr_insts
IRGen: Outline by-address SIL enum instructions
2024-01-29 07:10:25 -08:00
Mike Ash
4341102c92 [Tools] Add a library to build specialized generic metadata out of process.
This library uses GenericMetadataBuilder with a ReaderWriter that can read data and resolve pointers from MachO files, and emit a JSON representation of a dylib containing the built metadata.

We use LLVM's binary file readers to parse the MachO files and resolve fixups so we can follow pointers. This code is somewhat MachO specific, but could be generalized to other formats that LLVM supports.

rdar://116592577
2024-01-24 20:45:50 -05:00
Arnold Schwaighofer
49e8ffb735 IRGen: Outline by-address SIL enum instructions
Use a heuristic to decide when to outline indirect enum operations.
2024-01-23 15:01:24 -08:00
Dario Rexin
36dd2c9450 [SilOpt] Add new layout type _TrivialStride and add pre-specialization suppport for it (#70308)
rdar://119329771

This layout allows adding pre-specializations for trivial types that have a different size, but the same stride. This is especially useful for collections, where the stride is the important factor.
2023-12-09 08:13:50 -08:00
Dario Rexin
df35f3327d [SilOpt] Add new layout _BridgeObject and add pre-specialization support for it (#70239)
rdar://119048001
2023-12-08 14:34:16 -08:00
Doug Gregor
6fa556b35d Preprocessor metaprogramming for mangling of macros
Yet more preprocessor metaprogramming to eliminate per-macro-role boilerplate
in the compiler. This time, focused on mangling, demangling, and remangling
of the accessor macro roles.
2023-11-25 10:20:33 -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
Tim Kientzle
fc0b08e7bc Fail cleanly for certain invalid manglings
There are certainly more such issues in this code, but this is
one that was recently reported.

While here, re-enable some disabled test cases that currently pass.

Resolves rdar://104671103
2023-08-01 18:19:38 -07: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
Ben Barham
515d22a486 [AST] Use a different operator for member attribute macros
Macro expansions are currently written to disk using the mangled name of
the macro. Do not use operators that only differ in case-sensitivity to
avoid issues on case-insensitive filesystems.

Resolves rdar://109371653.
2023-05-17 11:25:37 -07:00
Slava Pestov
1c924018d1 ASTMangler: Fix mangling of SILFunctionType with @pack conventions
Fixes rdar://problem/107151125.
2023-05-01 21:56:05 -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
Richard Wei
eb8e984b97 [Macros] Private discriminators for outermost-private MacroExpansionDecl (#64813)
Add a private discriminator to the mangling of an outermost-private `MacroExpansionDecl` so that declaration macros in different files won't have colliding macro expansion buffer names.

rdar://107462515
2023-03-31 20:36:29 -07:00
Mike Ash
fbc3f69ebf [RemoteMirror] Fix demangle node corruption caused by excessively eager clearing of the NodeFactory.
We clear the NodeFactory to prevent unbounded buildup of allocated memory, but this is done too eagerly. In particular, normalizeReflectionName can end up clearing the factory while the calling code is still using nodes that were allocated from it.

To keep peak memory usage low while avoiding this problem, we introduce a checkpoint mechanism in NodeFactory. A checkpoint can be pushed and then subsequently popped. When a checkpoint is popped, only the nodes allocated since the checkpoint was pushed are invalidated and the memory reclaimed. This allows us to quickly clear short-lived nodes like those created in normalizeReflectionName, while preserving longer-lived nodes used in code calling it. Uses of clearNodeFactory are replaced with this checkpoint mechanism.

rdar://106547092
2023-03-29 16:59:21 -04:00
Rintaro Ishizaki
c4b3edd6df [Macros] Add swift-plugin-server executable
This executable is intended to be installed in the toolchain and act as
an executable compiler plugin just like other 'macro' plugins.

This plugin server has an optional method 'loadPluginLibrary' that
dynamically loads dylib plugins.
The compiler has a newly added option '-external-plugin-path'. This
option receives a pair of the plugin library search path (just like
'-plugin-path') and the corresponding "plugin server" path, separated
by '#'. i.e.

  -external-plugin-path
    <plugin library search path>#<plugin server executable path>

For exmaple, when there's a macro decl:

  @freestanding(expression)
  macro stringify<T>(T) -> (T, String) =
      #externalMacro(module: "BasicMacro", type: "StringifyMacro")

The compiler look for 'libBasicMacro.dylib' in '-plugin-path' paths,
if not found, it falls back to '-external-plugin-path' and tries to find
'libBasicMacro.dylib' in them. If it's found, the "plugin server" path
is launched just like an executable plugin, then 'loadPluginLibrary'
method is invoked via IPC, which 'dlopen' the library path in the plugin
server. At the actual macro expansion, the mangled name for
'BasicMacro.StringifyMacro' is used to resolve the macro  just like
dylib plugins in the compiler.

This is useful for
 * Isolating the plugin process, so the plugin crashes doesn't result
   the compiler crash
 * Being able to use library plugins linked with other `swift-syntax`
   versions

rdar://105104850
2023-03-16 14:00:45 -07:00
Slava Pestov
151e1c55be Merge pull request #64337 from slavapestov/misc-variadic-generic-fixes
Miscellaneous variadic generics fixes
2023-03-15 14:53:25 -04:00
Konrad `ktoso` Malawski
41f99fc2ae [Executors][Distributed] custom executors for distributed actor (#64237)
* [Executors][Distributed] custom executors for distributed actor

* harden ordering guarantees of synthesised fields

* the issue was that a non-default actor must implement the is remote check differently

* NonDefaultDistributedActor to complete support and remote flag handling

* invoke nonDefaultDistributedActorInitialize when necessary in SILGen

* refactor inline assertion into method

* cleanup

* [Executors][Distributed] Update module version for NonDefaultDistributedActor

* Minor docs cleanup

* we solved those fixme's

* add mangling test for non-def-dist-actor
2023-03-15 23:42:55 +09:00
Slava Pestov
39a220e848 Demangler: Don't enter substitution for PackExpansionType 2023-03-14 16:41:25 -04:00
Slava Pestov
fee32cca3f ASTMangler: Mangle which generic parameters are packs 2023-02-25 16:19:07 -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
f8d78e2eb9 Handle demangling prefix @__swiftmacro_ used for filenames. 2023-02-01 09:20:46 -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
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
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