Commit Graph

263 Commits

Author SHA1 Message Date
Konrad `ktoso` Malawski
9438cf6b2e [Distributed] Func metadata operations and implement executeDistributedTarget entry (#40605)
* [Distributed] Implement func metadata and executeDistributedTarget

dont expose new entrypoints

able to get all the way to calling _execute

* [Distributed] reimplement distributed get type info impls

* [Distributed] comment out distributed_actor_remoteCall for now

* [Distributed] disable test on linux for now
2022-01-09 23:55:06 +09:00
Jonathan Grynspan
099fdc2e41 Fix an issue on COFF/ELF targets where the runtime would register each loaded image twice (at least early on.) 2022-01-01 11:39:25 -05:00
Arnold Schwaighofer
cf3951394a Revert "Fix an issue on COFF/ELF targets where the runtime would register each loaded image twice (at least early on.)" 2021-12-21 07:15:08 -08:00
Jonathan Grynspan
7fe5ea7398 Fix an issue on COFF/ELF targets where the runtime would register each loaded image twice (at least early on.) 2021-12-20 15:15:02 -05:00
Kuba (Brecka) Mracek
c92f2a24ed When ptrauth-copying vtable/wtables, allow NULL entries (due to VFE) (#40578)
* When ptrauth-copying vtable/wtables, allow NULL entries (due to VFE)

* Mark virtual-function-elimination-generics-exec.swift UNSUPPORTED: arm64e until the rebranch

* Fix test expectations
2021-12-16 16:49:24 -08:00
Kuba Mracek
5bbf15053d Add #ifndef NDEBUG around assert() calls that use helper functions/variables that are also under #ifndef NDEBUG 2021-11-16 15:00:23 -08:00
Kuba (Brecka) Mracek
99a24d47be Introduce a CMake flag to disable fast-path context descriptor lookup based on short manglings (#39729) 2021-10-14 08:08:07 -07:00
Kuba (Brecka) Mracek
c2a92722c6 Split the NO_DYLD CMake flag into separate HAS_DLADDR and STATIC_IMAGE_INSPECTION flags (#39339) 2021-09-29 19:57:05 -07:00
Alastair Houghton
8be084f30a Merge pull request #39187 from al45tair/problem/79725187
[Demangler] Improve remangler error handling
2021-09-27 17:03:49 +01:00
Doug Gregor
7f2117690c Skip standard substitutions for _Concurrency types when back-deploying.
When back-deploying concurrency support, do not use the standard
substitutions for _Concurrency-defined types (such as `Task`) in type
metadata because older Swift runtimes will not be able to demangle
them. Instead, use the full mangled names so the runtime can still
demangle them appropriately.

Addresses rdar://82931890.
2021-09-09 13:23:19 -07:00
Alastair Houghton
fbf082b6cb [Demangling] Make Demangle::getUnspecialized() return errors too.
This lets us completely remove the unreachable() function from Remangler.cpp.

rdar://79725187
2021-09-06 17:49:09 +01:00
Alastair Houghton
3f01f853a6 [Demangling] Add error handling to the remangler.
Mangling can fail, usually because the Node structure has been built
incorrectly or because something isn't supported with the old remangler.
We shouldn't just terminate the program when that happens, particularly
if it happens because someone has passed bad data to the demangler.

rdar://79725187
2021-09-06 17:49:09 +01:00
Alastair Houghton
4b2e31654e [Demangler][Tests] Re-add getObjcClassByMangledName test.
This was reverted in ec3ccd72 because it broke the iOS simulator build.
2021-08-17 09:46:21 +01:00
Mishal Shah
34350e45cd Revert "[Demangler][Tests] Add an explicit test for getObjCClassByMangledName." 2021-08-16 14:00:39 -07:00
Alastair Houghton
fb351be64f [Demangler][Tests] Address Doug's comments.
Moved the test for the metadata kind to MetadataLookup.cpp.

Added an assertion (for debug builds) to Metadata.cpp to catch the case where
something manages to bypass that test.
2021-08-16 10:59:01 +01:00
Alastair Houghton
8db56f09a3 [Demangler][Tests] Add an explicit test for getObjCClassByMangledName.
Added a special test for getObjCClassByMangledName; this needs testing
separately as it uses the DecodedMetadataBuilder, which doesn't get exercised
by the normal demangling tests.

Added all the test cases from rdar://63485806, rdar://63488139, rdar://63496478,
rdar://63410196 and rdar://68449341.  The test cases from rdar://63485806 are
disabled for now because the problem there is the error handling mechanism (or
lack thereof), rather than us not handling errors.

Fixes the remaining cases from

rdar://63488139
rdar://63496478
2021-08-04 16:21:32 +01:00
Alastair Houghton
21ac407a21 <rdar://64939529> Convert unnecessary dlsym() calls into direct references.
Added SWIFT_RUNTIME_WEAK_IMPORT/CHECK/USE macros.

Everything supports fast dealloc except x86 iOS simulators, so we no longer need
to look up objc_has_weak_formation_callout.

Added direct references for

  objc_setHook_lazyClassNamer
	_objc_realizeClassFromSwift
	objc_setHook_getClass
	os_system_version_get_current_version
	_dyld_is_objc_constant
2021-06-18 10:16:30 +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
Doug Gregor
b57a73ab42 [Concurrency ABI] Add standard substitutions for _Concurrency types.
Introduce a second level of standard substitutions to the mangling,
all of the form `Sc<character>`, and use it to provide standard
substitutions for most of the _Concurrency types.

This is a precursor to rdar://78269642 and a good mangling-size
optimization in its own right.
2021-06-01 17:15:02 -07:00
Arnold Schwaighofer
eb60c7c66b Runtime: Fix async dynamic replacements
For async function async function pointers will be stored in dynamic
replacement records.

rdar://77072669
2021-04-23 09:01:34 -07:00
Nate Chandler
19d9ebd761 Revert "[AST] De/mangling for functions with generic sigs."
This reverts commit dbe689a3f2.
2021-04-06 15:41:43 -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
Mike Ash
6aab257c33 [Concurrency] Add compatibility overrides to Concurrency library.
Take the existing CompatibilityOverride mechanism and generalize it so it can be used in both the runtime and Concurrency libraries. The mechanism is preprocessor-heavy, so this requires some tricks. Use the SWIFT_TARGET_LIBRARY_NAME define to distinguish the libraries, and use a different .def file and mach-o section name accordingly.

We want the global/main executor functions to be a little more flexible. Instead of using the override mechanism, we expose function pointers that can be set by the compatibility library, or by any other code that wants to use a custom implementation.

rdar://73726764
2021-03-22 11:09:06 -04:00
Nate Chandler
dbe689a3f2 [AST] De/mangling for functions with generic sigs. 2021-03-15 13:37:40 -07:00
Mike Ash
7c1b968666 [Runtime] Silence warnings on NULL checks of ObjC function addresses.
Some ObjC runtime calls are weak or strong depending on the deployment target. When strong, we get warnings that the NULL checks always succeed; silence them.

Some of the adjacent code looked up functions using dlsym when they aren't provided by the SDK. Our current minimum SDK always has them, so remove the dlsym workaround.
2021-03-02 15:44:45 -05:00
Adrian Prantl
6fb61785c1 Support SILBoxWithLayout in TypeDecoder and factor out decodeRequirement() from
ASTBuilder.
2021-02-03 14:23:54 -08:00
Mike Ash
c8f1a538e9 [Runtime] Change ProtocolCache, NominalCache, and HashableConformances to ConcurrentReadableHashMap.
rdar://problem/70220804
2020-11-16 16:49:20 -05:00
John McCall
0fb407943f [NFC] Rename swift_runtime_unreachable to swift_unreachable and make it use LLVM's support when available. 2020-10-03 02:54:56 -04:00
Kuba (Brecka) Mracek
41f1285b99 Don't use lookupSymbol when SWIFT_RUNTIME_MACHO_NO_DYLD (#33792) 2020-09-03 18:43:52 -07:00
Mike Ash
fd6922f92d Add error reporting when looking up types by demangled name. 2020-08-28 14:43:51 -04: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
Suyash Srijan
42779d66c7 [NFC] Remove some dead variadic tuple code (#33059)
* [ASTDemangler] Remove 'isVariadic' parameter from 'createTupleType'

* [TypeDecoder] Remove 'variadic' argument from 'createTupleType' call

* [Reflection] Remove support for variadic from TupleTypeRef

* [Remote] Remove 'variadic' argument from 'createTupleType' call

* [Runtime] Remove 'variadic' parameter from createTupleType in MetadataLookup

* [Test] Remove variadic tuple typeref tests

* [Reflection] Restore accidentally deleted code from 'visitFunctionTypeRef'
2020-07-23 17:02:16 +01: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
f0413f6170 build: remove last llvm:: reference in stdlib
This removes the last reference to the `llvm::` namespace in the
standard library.  All uses of the LLVMSupport library now are
namespaced into the `__swift::__runtime` namespace.  This allows us to
incrementally vend the LLVMSupport library and make the separation
explicit.
2020-05-18 11:41:57 -07:00
Saleem Abdulrasool
e72b43f374 runtime: namespace SmallVectorImpl for inline namespace
This adjusts the use of `SmallVectorImpl` to allow the runtime to use
inline namespaces for its local copy of LLVMSupport.
2020-05-13 11:10:47 -07:00
Saleem Abdulrasool
96313ce3e1 runtime: explicitly namespace ArrayRef in shared headers
There are a set of headers shared between the Swift compiler and the
runtime.  Ensure that we explicitly use `llvm::ArrayRef` rather than
`ArrayRef` which is aliased to `::llvm::ArrayRef`.  Doing so enables us
to replace the `ArrayRef` with an inline namespaced version fixing ODR
violations when the swift runtime is loaded into an address space with
LLVM.
2020-05-13 08:42:06 -07:00
Saleem Abdulrasool
2ea11b5428 runtime: remove use of swift/LLVM.h (NFC)
Rather than using the forward declaration for the LLVMSupport types,
expect to be able to use the full declaration.  Because these are
references in the implementation, there is no reason to use a forward
declaration as the full types need to be declared for use.  The LLVM
headers will provide the declaration and definition for the types.  This
is motivated by the desire to ensure that the LLVMSupport symbols are
properly namespaced to avoid ODR violations in the runtime.
2020-05-07 13:37:31 -07:00
Kuba (Brecka) Mracek
ab6533a40f Merge branch 'master' into mracek/arm64e 2020-03-06 15:07:01 -08:00
Mike Ash
614f4becef [Runtime] Reject suffixes on ObjC mangled class names.
The demangler tolerates arbitrary suffixes on mangled names, and parses them as a Suffix node. When looking up a class by an ObjC mangled name, we don't want such demanglings to succeed, because this will result in false positives. It's expected that NSClassFromString(someClassName + "some suffix") will fail, unless something has actually created a class with that suffix.

rdar://problem/60012296
2020-03-04 12:05:35 -05:00
Kuba Mracek
84c4864911 [arm64e] Add Swift compiler support for arm64e pointer authentication 2020-02-27 16:10:31 -08:00
Ben Cohen
60b4f38660 Eliminate context descriptor cache (#29151) 2020-01-13 15:59:32 -08:00
Arnold Schwaighofer
cf20dd4cf3 Add swift_getTypeByMangledNameInEnvironmentInMetadataState runtime function 2019-11-19 09:18:04 -08:00
Arnold Schwaighofer
0d324d223f Add swift_getTypeByMangledNameInContextInMetadataState such that we can
use getTypeByMangledName when abstract metadata state is requested

This can significantly reduce the code size of apps constructing deeply
nested types with conditional conformances.

Requires a new runtime.

rdar://57157619
2019-11-18 14:41:35 -08:00
Joe Groff
8c4df3b4c2 Reflection: Traffic in RemoteRefs.
Instead of passing around raw local pointers and references, and spreading
tricky offset arithmetic around with the Local/RemoteAddress fields in
ReflectionInfo, have the TypeRefBuilder code use RemoteRefs everywhere,
which keep the remote/local mapping together in one unit and provide
centralized API for this logic.

This doesn't yet change how code uses the RemoteRef address data to
follow pointers across objects, for things like reading type refs, but
that should be much easier to do after this lands.
2019-09-25 20:28:03 -07:00
Saleem Abdulrasool
c4f448578e Revert "runtime: add a workaround for Windows build"
This reverts commit efaf1fbefa.
Add a much more palatable workaround for the unit tests.  Rather than
adding the dllimport for the symbols, locally define the required
symbols.  This list is sufficient to restore the ability to build tests
for Windows.
2019-09-16 15:31:01 -07:00
Saleem Abdulrasool
efaf1fbefa runtime: add a workaround for Windows build
The runtime tests will statically link the runtime and dynamically link
to the standard library.  This fails to build on Windows.  This is a
horrible workaround for the time being.
2019-09-16 09:20:49 -07:00
Joe Groff
4c3f044a46 Merge pull request #27185 from jckarter/fast-path-short-mangling-lookups
Runtime: Fast path lookup for short manglings.
2019-09-14 07:34:33 -07:00
Joe Groff
78ed70cbb8 Runtime: Fast path lookup for short manglings.
Mangling these common types takes only two bytes, which is shorter than a symbolic reference. We
know where their metadata is in the standard library, too, so we don't need to search the lookup
tables for them.
2019-09-13 18:40:25 -07:00
Joe Groff
413100be33 Merge pull request #27181 from jckarter/demangler-symbolic-reference-api-refactor
Demangler: Make symbolic reference resolver part of `demangle(Symbol|Type)` calls.
2019-09-13 18:12:04 -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