Commit Graph

120 Commits

Author SHA1 Message Date
Pavel Yaskevich
1067ead82c [Mangling] Mangle presence of @execution(caller) in a function type
If `@execution(caller)` attribute is present on a function type,
mark its presence in the mangling with `YC` suffix.
2025-02-19 16:48:41 -08:00
John McCall
623d063ad7 Fix remangling isolated(any) function types from type metadata. 2025-01-22 21:41:14 -05:00
John McCall
11ff5b4348 Merge pull request #78576 from rjmccall/demangle-sending-result-with-function-isolation
Fix the demangling of sending result types when combined with isolation
2025-01-11 12:35:55 -05:00
John McCall
fa932e736c Fix the demangling of sending result types when combined with isolation
Fixes the immediate problem, but the presence of demangling code in the
runtime means that we'll need a follow-up to fix the compiler so that it
doesn't try to use the demangler to materialize metadata for function types
that have both isolation and a sending result.

rdar://142443925
2025-01-10 21:11:45 -05:00
Saleem Abdulrasool
627e79556e runtime: use the preferred spelling on Windows (NFCI)
This changes the windows path to use the preferred `_strdup` over
`strdup` to avoid the deprecation warning.
2025-01-10 09:31:09 -08:00
Alejandro Alonso
9903d71f91 More changes to get off of ssize_t 2024-09-04 15:13:49 -07:00
Alejandro Alonso
7c85261a77 Add runtime support 2024-09-04 15:13:27 -07:00
Michael Gottesman
e3e78ad6bb [sending] Change the internals of sending to be based around 'sending' instead of 'transferring'.
We still only parse transferring... but this sets us up for adding the new
'sending' syntax by first validating that this internal change does not mess up
the current transferring impl since we want both to keep working for now.

rdar://128216574
2024-05-16 12:20:45 -07:00
Joe Groff
b9f91144d1 Fix ABI breakage caused by ValueOwnership order change.
The `ABI` headers had accidentally grown an `#include` into compiler headers,
allowing the enum constant values of the `ValueOwnership` enum to leak into
the runtime ABI. Sever this inappropriate relationship by declaring a separate
`ParameterOwnership` enum with ABI-stable values in the ABI headers, and
explicitly converting between the AST and ABI representation where needed.
Fixes rdar://122435628.
2024-02-20 07:55:16 -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
Mike Ash
8dc4bc13b1 [Runtime] Add some missing NULL checks to _swift_buildDemanglingForMetadata calls.
The call can fail but many callers assumed it always succeeds.
2024-02-15 16:30:09 -05:00
Mike Ash
edb292dda5 [Runtime] Do a proper hash table lookup in the prespecializations library.
We were doing a linear scan of the table contents as a stopgap. Stop doing that, and compute the proper key for the lookup, matching the one used in the builder.
2024-01-26 12:04:02 -05: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
Alejandro Alonso
8ac7f0b10f Merge pull request #69138 from Azoy/generics-are-hard
[Runtime] Refactor _gatherWrittenGenericParameters
2023-11-06 19:27:54 -08:00
Alejandro Alonso
3503ab35d8 Update assert to fix packs 2023-11-06 10:31:21 -08:00
Alejandro Alonso
a0c8465f0c Refactor _gatherWrittenGenericParameters
Fix some bugs
2023-11-06 10:31:20 -08:00
Doug Gregor
40e07cf900 [Typed throws] IR generation and runtime support for function type metadata
Extend function type metadata with an entry for the thrown error type,
so that thrown error types are represented at runtime as well. Note
that this required the introduction of "extended" function type
flags into function type metadata, because we would have used the last
bit. Do so, and define one extended flag bit as representing typed
throws.

Add `swift_getExtendedFunctionTypeMetadata` to the runtime to build
function types that have the extended flags and a thrown error type.
Teach IR generation to call this function to form the metadata, when
appropriate.

Introduce all of the runtime mangling/demangling support needed for
thrown error types.
2023-10-29 09:12:32 -07:00
Doug Gregor
4da1032f93 Add name mangling support for functions with a thrown error type 2023-10-29 09:12:32 -07:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
Mike Ash
110f428780 [Runtime] Add tracing for section scans.
Section scans (for metadata, protocols, etc.) can be costly. This change adds tracing calls to those scans so we can more easily see how much time is spent in these scans and where they're initiated.

This adds an os_signpost implementation controlled by SWIFT_STDLIB_TRACING, and a default empty implementation for when that's disabled.

rdar://110266743
2023-06-14 12:07:44 -04:00
Slava Pestov
d776f71b4f Runtime: Teach checkGenericRequirements() to check same-shape and conformance pack requirements 2023-03-09 09:42:00 -05:00
Slava Pestov
b3cb845ea3 Runtime: support metadata packs in _buildDemanglingForNominalType()
This adds a bunch of new code but once I finish refactoring the other
demangling stuff, I should be able to remove

- gatherWrittenGenericArgs()
- _gatherGenericParameters()
- SubstGenericParametersFromWrittenArgs
2023-03-03 14:16:53 -05:00
Alejandro Alonso
382510fa50 Rename Reflection library to RemoteInspection (#62846) 2023-01-06 13:21:32 -05:00
John McCall
175f74d38f Implement symbolic demangling for extended existential metadata
Fixes rdar://96268090.
2022-07-01 11:21:53 -04:00
Zoe Carver
fd52592451 Merge pull request #59439 from zoecarver/frt-metatdata-runtime
[cxx-interop] Runtime support for foreign reference types.
2022-06-17 10:01:29 -07:00
Robert Widmann
115acc2b78 Failing Casts Should Not Crash
Return a NULL demangle tree instead of crashing. When an unconditional
runtime cast fails, it's going to crash anyways, but this way it prints
a better description (though not great) than the unreachable's message here.
2022-06-16 15:00:30 -06:00
Robert Widmann
9e4670a605 Implement Casting For Extended Existentials
Implement casting to and from extended existentials. This is done by slightly generalizing the conditional conformances checking infrastructure.

Unfortunately, casts for reference types and metatypes are unsound because IRGen is peepholing all non-opaque existential conversions with a helper. I’ll disable that in a follow-up.

rdar://92197049
2022-06-15 21:35:15 -06:00
Robert Widmann
d4952d53b9 Add Runtime Demangling for Extended Existentials 2022-06-15 18:19:33 -06:00
zoecarver
f972f664d3 [cxx-interop] Runtime support for foreign reference types. 2022-06-14 12:18:05 -07:00
Kuba (Brecka) Mracek
4511c474ea Avoid depending on missing nodeToString and genericParameterName symbols in the freestanding stdlib (#42174) 2022-04-06 08:37:28 -07:00
Kuba (Brecka) Mracek
e6a1e23a9f Add SWIFT_STDLIB_ENABLE_VECTOR_TYPES to take away support for SIMD (#41149) 2022-02-02 12:06:45 -08:00
Kuba Mracek
c10c1bbe5e When SWIFT_ENABLE_REFLECTION is Off, don't build the reflection runtime code (stdlib/public/Reflection/*.cpp) 2021-12-15 09:13:06 -08:00
Argyrios Kyrtzidis
325d8b3c21 [Demangle.h] Remove the swift_demangle declaration from Demangle.h since it's not needed there
Also allows removing the "swift/Runtime/Config.h" include from that header.
2021-09-03 18:19:10 -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
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
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
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
Doug Gregor
ba8819eb58 [Concurrent] Introduce concurrent function types.
Introduce `@concurrent` attribute on function types, including:
* Parsing as a type attribute
* (De-/re-/)mangling for concurrent function types
* Implicit conversion from @concurrent to non-@concurrent
- (De-)serialization for concurrent function types
- AST printing and dumping support
2021-01-27 14:22:32 -08:00
Varun Gandhi
3882beb85d [NFC] Use consistent naming scheme for predicate methods. (#33265)
bool throws() -> isThrowing(), bool async() -> isAsync()
2020-08-03 16:37:29 -07:00
Doug Gregor
f6e9f352f0 [Concurrency] Add async to the Swift type system.
Add `async` to the type system. `async` can be written as part of a
function type or function declaration, following the parameter list, e.g.,

  func doSomeWork() async { ... }

`async` functions are distinct from non-`async` functions and there
are no conversions amongst them. At present, `async` functions do not
*do* anything, but this commit fully supports them as a distinct kind
of function throughout:

* Parsing of `async`
* AST representation of `async` in declarations and types
* Syntactic type representation of `async`
* (De-/re-)mangling of function types involving 'async'
* Runtime type representation and reconstruction of function types
involving `async`.
* Dynamic casting restrictions for `async` function types
* (De-)serialization of `async` function types
* Disabling overriding, witness matching, and conversions with
differing `async`
2020-07-27 18:18:03 -07:00
Saleem Abdulrasool
158332c088 runtime: remove llvm/DataTypes.h, llvm-c/DataTypes.h
Inline the standard headers that they included and remove the extra
include path.
2020-06-04 21:00:39 +00:00
Saleem Abdulrasool
c050a26aeb runtime: further isolate runtime from LLVMSupport
This cleans up some more `llvm::` leakage in the runtime when built into
a static library.  With this change we are down to 3 leaking symbols in
the static library related to a missed ADT (`StringSwitch`).
2020-05-28 12:42:11 -07:00
Saleem Abdulrasool
a7415423e6 runtime: add and switch to SWIFT_FALLTHROUGH (NFC)
This duplicates and switches the uses of `LLVM_FALLTHROUGH` to a local
macro for the same annotation.
2020-05-07 11:50:22 -07:00
Adrian Prantl
ea2b5eced9 Reflection: Implement a TypeRef -> Demangle tree adapter.
To allow more pervasive use of TypeRefs in LLDB, we need a way to build mangled
names from TypeRef pointers to allow round-tripping between TypeRefs and AST
types. The goal is to experiment with making lldb::CompilerType backed by
TypeRefs instead of AST types.

<rdar://problem/55412775>
2020-01-14 17:50:01 -08:00
Jordan Rose
171ff440fc Remove swift::reversed in favor of llvm::reverse (#27610)
The former predates the latter, but we don't need it anymore! The
latter has more features anyway.

No functionality change.
2019-10-10 17:16:09 -07:00
Joe Groff
f1e84994ed Demangler: Make symbolic reference resolver part of demangle(Symbol|Type) calls.
This makes for a cleaner and less implicit-context-heavy API, and makes it easier for symbolic
reference resolvers to do context-dependent things (like map the in-memory base address back to a
remote address in MetadataReader).
2019-09-13 15:47:08 -07:00
Azoy
f79eb3b8d0 swift_demangle: update buffer size after copying 2019-06-07 18:06:32 -05:00
Erik Eckstein
3bd7f027f8 Runtime: use SmallVector instead of std::vector to avoid memory allocations in most cases.
This dramatically reduces the number of needed malloc calls.
Unfortunately I had to add the implementation of SmallVectorBase::grow_pod to the runtime, as we don't link LLVM. This is a bad hack, but better than re-inventing a new SmallVector implementation.

SR-10028
rdar://problem/48575729
2019-03-06 14:37:03 -08:00