Commit Graph

604 Commits

Author SHA1 Message Date
Mike Ash
cd624bf380 [Runtime][Reflection][swift-inspect] Add facilities for tracking and examining backtraces for metadata allocations.
rdar://problem/63674755
2020-06-11 14:49:52 -04:00
Mike Ash
d80a405a46 [Runtime] Clean up verifyMangledNameRoundtrip comment. 2020-06-08 16:44:10 -04:00
Mike Ash
b25dab2925 Merge pull request #32137 from mikeash/debug-environment-variables
[Runtime] Unify debug variable parsing from the environment and avoid getenv when possible.
2020-06-04 16:39:18 -04:00
Saleem Abdulrasool
23bfee2078 runtime: silence -Wunused-variable warning (NFC)
`classMetadata` is only used in the ObjC path, resulting in a
`-Wunused-variable` warning.  Sink the variable into the ObjC path.
Because the conversion of the metadata does not rely on the type
metadata bits in the metadata, it is safe to delay the definition and
bit adjustment to the point where it is used unifying the two ObjC
paths.
2020-06-04 08:58:03 -07:00
Mike Ash
f2fb53967c [Runtime] Unify debug variable parsing from the environment and avoid getenv when possible.
There are a few environment variables used to enable debugging options in the
runtime, and we'll likely add more over time. These are implemented with
scattered getenv() calls at the point of use. This is inefficient, as most/all
OSes have to do a linear scan of the environment for each call. It's also not
discoverable, since the only way to find these variables is to inspect the
source.

This commit places all of these variables in a central location.
stdlib/public/runtime/EnvironmentVariables.def defines all of the debug
variables including their name, type, default value, and a help string. On OSes
which make an `environ` array available, the entire array is scanned in a single
pass the first time any debug variable is requested. By quickly rejecting
variables that do not start with `SWIFT_`, we optimize for the common case where
no debug variables are set. We also have a fallback to repeated `getenv()` calls
when a full scan is not possible.

Setting `SWIFT_HELP=YES` will print out all available debug variables along with
a brief description of what they do.
2020-06-04 10:00:06 -04:00
Anthony Latsis
9fd1aa5d59 [NFC] Pre- increment and decrement where possible 2020-06-01 15:39:29 +03:00
Mike Ash
ad0a8d3121 Merge pull request #31468 from mikeash/swiftdt
[Tools] Create swift-inspect, a debugging tool for dumping Swift runtime data from another process
2020-05-31 18:35:30 -04:00
Nate Chandler
bdef1cef23 [metadata prespecialization] Support for classes.
When generic metadata for a class is requested in the same module where
the class is defined, rather than a call to the generic metadata
accessor or to a variant of typeForMangledNode, a call to a new
accessor--a canonical specialized generic metadata accessor--is emitted.
The new function is defined schematically as follows:

    MetadataResponse `canonical specialized metadata accessor for C<K>`(MetadataRequest request) {
      (void)`canonical specialized metadata accessor for superclass(C<K>)`(::Complete)
      (void)`canonical specialized metadata accessor for generic_argument_class(C<K>, 1)`(::Complete)
      ...
      (void)`canonical specialized metadata accessor for generic_argument_class(C<K>, count)`(::Complete)
      auto *metadata = objc_opt_self(`canonical specialized metadata for C<K>`);
      return {metadata, MetadataState::Complete};
    }

where generic_argument_class(C<K>, N) denotes the Nth generic argument
which is both (1) itself a specialized generic type and is also (2) a
class.  These calls to the specialized metadata accessors for these
related types ensure that all generic class types are registered with
the Objective-C runtime.

To enable these new canonical specialized generic metadata accessors,
metadata for generic classes is prespecialized as needed. So are the
metaclasses and the corresponding rodata.

Previously, the lazy objc naming hook was registered during process
execution when the first generic class metadata was instantiated. Since
that instantiation may occur "before process launch" (i.e. if the
generic metadata is prespecialized), the lazy naming hook is now
installed at process launch.
2020-05-29 13:20:33 -07:00
Mike Ash
da5d2b49d7 [Runtime] Clean up metadata allocation tracking.
Keep the initial metadata pool to be all zeroes. Remove the hardcoded trailer at the end. Write a trailer into it when we check the environment variable the first time we allocate.
2020-05-29 08:31:03 -07:00
Mike Ash
b73b325e10 [Runtime] Only enable metadata allocation tracking when requested with an environment variable.
Expose _swift_debug variables for Remote Mirror to use for tracking metadata allocation, and adopt them in Remote Mirror.

rdar://problem/55481578
2020-05-29 08:31:03 -07:00
Mike Ash
2c7f09cef7 [Tools] Add some metadata printing to swiftdt.
rdar://problem/55481578
2020-05-29 08:31:03 -07:00
Mike Ash
22cfe461ec [Tools] Super rough draft of swiftdt dumping MetadataAllocator contents.
rdar://problem/55481578
2020-05-29 08:31:03 -07:00
David Zarzycki
97c89d8d3a Remove three ObjC fields from non-ObjC runtime 2020-05-22 09:21:21 -07:00
John McCall
677f42db5d Merge pull request #31820 from rjmccall/unused-associated-type-elimination
[NFC] initAssociatedTypeWitness is now unused in non-ptrauth builds
2020-05-15 17:27:34 -04:00
John McCall
0a41ac9a7c [NFC] initAssociatedTypeWitness is now unused in non-ptrauth builds 2020-05-15 13:22:35 -04:00
Saleem Abdulrasool
3fa1d1fe3f runtime: ingest LLVMSupport into the runtime
This adds a new copy of LLVMSupport into the runtime.  This is the final
step before changing the inline namespace for the runtime support.  This
will allow us to avoid the ODR violations from the header definitions of
LLVMSupport.

LLVMSupport forked at: 22492eead218ec91d349c8c50439880fbeacf2b7
Changes made to LLVMSupport from that revision:
  process.inc forward declares `_beginthreadex` due to compilation issues due to custom flag handling

API changes required that we alter the `Deallocate` routine to account
for the alignment.

This is a temporary state, meant to simplify the process.  We do not use
the entire LLVMSupport library and there is no value in keeping the
entire library.  Subsequent commits will prune the library to the needs
for the runtime.
2020-05-15 09:55:36 -07:00
John McCall
6200df1d88 Make the lazy assignment of an assoociated type/wtable atomic.
Should fix SR-12760.
2020-05-13 20:37:41 -04: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
c721cf12f5 Merge pull request #31635 from compnerd/completely-impartial
runtime: remove use of `swift/LLVM.h` (NFC)
2020-05-09 11:28:04 -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
Saleem Abdulrasool
04eeff5b8d runtime: remove llvm/Support header usage
This reduces the dependency on `LLVMSupport`.  This is the first step
towards helping move towards a local fork of the LLVM ADT to ensure that
static linking of the Swift runtime and core library does not result in
ODR violations.
2020-05-07 13:36:13 -07:00
Saleem Abdulrasool
e0b0d20cd8 runtime: add and switch to SWIFT_NORETURN (NFC)
Remove the use of the `LLVM_ATTRIBUTE_NORETURN` to trim dependencies on
LLVMSupport.
2020-05-07 09:22:39 -07:00
Saleem Abdulrasool
fe9751f988 Merge pull request #31585 from compnerd/likely
runtime: replace `LLVM_LIKELY` with `SWIFT_LIKELY` (NFC)
2020-05-07 09:21:58 -07:00
Saleem Abdulrasool
b74f42602a runtime: add and switch to SWIFT_USED (NFC)
This further trims dependencies to LLVMSupport by introducing the
equivalent `SWIFT_USED` macro.
2020-05-06 21:19:14 -07:00
Saleem Abdulrasool
e7996a770a runtime: replace LLVM_LIKELY with SWIFT_LIKELY (NFC)
Use the Swift namespaced version of the macro and reduce the dependency
on LLVMSupport.
2020-05-06 09:11:32 -07:00
Nate Chandler
d87a734a50 [Runtime] In debug builds, dirty metadata records.
To facilitate debugging metadata records which are not properly
initialized, upon allocation fill them with a regular byte pattern
(0xAA) so that on subsequent inspection it is obvious if part of the
record is not initialized.
2020-04-23 18:18:40 -07:00
Nate Chandler
47943f8304 [Runtime] Fixed zeroing of extra data padding for values.
See also bcc309efa1 .
2020-04-15 17:22:26 -07:00
Nate Chandler
82b668f1f3 [Runtime] Assert dynamic metadata is not static.
Added an assertion that a generic metadata record that is instantiated
at runtime is not a prespecialized metadata record.
2020-04-15 17:22:23 -07:00
nate-chandler
feba039217 Merge pull request #30785 from nate-chandler/rdar60790020
[Runtime] Handle incomplete class metadata in _checkGenericRequirements.
2020-04-03 15:32:53 -07:00
Nate Chandler
2863f1964d [Runtime] Handle incomplete class metadata in _checkGenericRequirements.
When constructing the metadata for a type Gen<T : Super>
where Super is a superclass constraint, the generic argument K at which
the metadata for Gen is being instantiated is verified to be a subclass
of Super via _checkGenericRequirements.

Previously, that check was done using swift_dynamicCastMetatype.  That
worked for the most part but provided an incorrect answer if the
metadata for K was not yet complete.  These classes are incomplete more
often thanks to __swift_instantiateConcreteTypeFromMangledNameAbstract.

That issue occurred concretely in the following case:

  Framework with Library Evolution enabled:

    open class Super { ... }
    public struct Gen<T : Super> {
    }

  Target in a different resilience domain from that framework:

    class Sub : Super {
      var gen: Gen<Sub>?
    }

Here, the mechanism for checking whether the generic argument K at which
the metadata for Gen is being instantiated handles the case where K's
metadata is incomplete.  At worst, every superclass name from super(K)
up to Super are demangled to instantiate metadata.  A number of faster
paths are included as well.

rdar://problem/60790020
2020-04-03 13:28:54 -07:00
Nate Chandler
a1e2fb019e [prespecialized metadata] Note classes are complete.
In preparation for the prespecialization of metadata for generic
classes, make checkMetadataState always return that the state of
prespecialized class metadata is complete, as is done for generic
structs and enums already.
2020-04-03 11:46:54 -07:00
Slava Pestov
afa2440f85 Merge pull request #30370 from slavapestov/encapsulate-conformance-descriptor
Runtime: Use accessor method to get TargetWitnessTable::Description
2020-03-12 00:19:24 -04:00
Kuba (Brecka) Mracek
1a3c582490 Fix typos in declarations of swift_ptrauth_key_associated_type and swift_ptrauth_key_associated_conformance (#30363) 2020-03-11 19:24:30 -07:00
Slava Pestov
4bc1d03283 Runtime: Use accessor method to get TargetWitnessTable::Description 2020-03-11 19:34:10 -04:00
Kuba Mracek
84c4864911 [arm64e] Add Swift compiler support for arm64e pointer authentication 2020-02-27 16:10:31 -08:00
Slava Pestov
20048bdc0d Runtime: Bounds check method override descriptors 2020-02-21 02:05:47 -05:00
Slava Pestov
a98f446f5f ABI: Clean up context and method descriptor pointers 2020-02-20 17:20:19 -05:00
Dmitri Gribenko
3566e6ed7a Merge pull request #29530 from swiftwasm/swiftwasm-ifdefs
[WebAssembly] Add ifdefs for the WASI target
2020-02-13 17:40:45 +01:00
nate-chandler
b62871047d Merge pull request #29345 from nate-chandler/generic-metadata-prespecialization-components/enums
Generic metadata prespecialization: enums
2020-02-12 13:09:59 -08:00
Nate Chandler
949029a788 [metadata prespecialization] Create enum records.
Extracted implementation of SpecializedGenericStructMetadataBuilder into
SpecializedGenericNominalMetadataBuilderBase, a CRTP with a template
template argument for the CRTP superclass and a template argument for
the implementation.  That new type is now subclassed by
SpecializedGenericStructMetadataBuilder.  Additionally, this new type is
also subclassed by the newly added SpecializedGenericEnumMetadataBuilder
which is responsible for build the prespecialization of generic enum
metadata.

rdar://problem/56960887
2020-02-11 09:57:22 -08:00
Max Desiatov
67297904ac [WebAssembly] Add ifdefs for the WASI target 2020-02-08 07:37:10 +00:00
Dario Rexin
d913eefcc9 Remove dependency on libatomic on Linux
Due to some unfortunate interplay between clang and libstdc++, clang was
not able to correctly identify to alignment of PoolRange and
SideTableRefCountBits, causing it to emit library calls instead of
inlining atomic operations. This was fixed by adding the appropriate
alignment to those types. In addition to that the march for the Linux
target was set to 'core2', which is the earliest architecture to support
cx16, which is necessary for the atomic operations on PoolRange.
2020-01-31 15:59:54 -08:00
Nate Chandler
edab098067 [runtime] Metadata can be flagged static.
Added a new flag to the GenericMetadataPatternFlags flagset for whether
the metadata has a set of flags at its tail.  When that flag is set,
there will be an extra uint64_t flagset at the end of the metadata.  For
struct metadata, the type of that flagset will be
StructMetadataTrailingFlags.  The first flag in that trailing flagset
indicates whether the metadata was statically specialized.  The second
flag in that trailing flagset indicates whether the metadata is
statically canonical.

When verifying the metadata cache, a check is done for whether the
metadata was statically specialized and whether it was known to be
canonical statically.  If so, verification is skipped.  Skipping it is
necessary because the known-canonical statically specialized metadata
will not be in the cache.  In that case, the canonical statically
specialized metadata will be returned from the metadata accessor and
never be cached.
2020-01-09 17:25:31 -08:00
Mike Ash
222b9deeab Merge pull request #28753 from mikeash/lazy-objc-class-names
[Runtime] When the ObjC runtime supports lazy class names, lazily create the ObjC names for generic classes.
2020-01-08 13:27:20 -05:00
Mike Ash
f32af9b047 [Runtime] Adjust lazy name API to a hook-based call that can have multiple hooks. Use the API from the headers if present.
rdar://problem/57674583
2019-12-18 17:15:51 -05:00
Mike Ash
fbcef9a9ec [Runtime] Use the new NonMetaClass ObjC field to have generic metaclasses point to their classes. Remove metaclass handling from the lazy class namer since it's not necessary.
rdar://problem/57674583
2019-12-17 16:41:47 -05:00
tbkka
fdb1926421 [SR-5289] Teach Mirror how to handle unowned/unmanaged references (#28823)
SR-5289: Teach Mirror how to inspect weak, unowned, and unmanaged refs

Correctly reflect weak, unowned, and unmanaged references
to both Swift and Obj-C types (including existential references to
such types) that occur in both Swift class objects and in Swift
structs.

This includes the specific reported case (unowned reference to an
Obj-C object) and several related ones.

Related changes in this PR:

* Tweak internal bitmap used for tracking ownership modifiers
  to reject unsupported combinations.

* Move FieldType into ReflectionMirror.mm
  FieldType is really just an internal implementation detail
	of this one source file, so it does not belong in an ABI header.

* Use TypeReferenceOwnership directly to track field ownership
  This avoids bitwise copying of properties and localizes some
	of the knowledge about reference ownership

* Generate a top-level "copyFieldContents" from ReferenceStorage.def
  Adding new ownership types to ReferenceStorage.def will now
	automatically produce calls to `copy*FieldContents` - failure
	to provide a suitable implementation will fail the build.

* Add `deallocateBoxForExistentialIn` to match `allocateBoxForExistentialIn`

Caveat:  The unit tests are not as strict as I'd like.  Attempting to make them
so ran afoul of otherwise-unrelated bugs in dynamic casting.
2019-12-17 09:42:52 -08:00
Mishal Shah
ca693eeca3 Revert "SR-5289: Teach Mirror how to handle unowned/unmanaged references (#28368)"
This reverts commit 9c638ae60d.
2019-12-16 17:24:30 -08:00
tbkka
9c638ae60d SR-5289: Teach Mirror how to handle unowned/unmanaged references (#28368)
* SR-5289: Support reflecting weak, unowned, and unmanaged refs

This refactors how we handle reference ownership
when reflecting fields of struct and class objects.
There are now explicit paths for each type of reference
and some simple exhaustiveness checks to fail the build
if a new reference type is added in the future without
updating this logic.
2019-12-16 12:26:22 -08:00
Mike Ash
1da182555a [Runtime] When the ObjC runtime supports lazy class names, lazily create the ObjC names for generic classes.
rdar://problem/57674583
2019-12-12 15:25:22 -05:00