Commit Graph

216 Commits

Author SHA1 Message Date
Nate Chandler
a68fcb155b [prespecialized metadata] Add token for caching.
Emit a once token when adding canonical prespecialized metadata records
to a nominal type descriptor and add the token itself as a trailing
object to the type descriptor.  The new token will, in subsequent
commits, enable the canonical prespecialized metadata records attached
to the type descriptor to be added to the metadata cache exactly once.
2020-11-01 13:34:22 -08:00
Alejandro Alonso
424802fb34 Revert SE-0283 (#34492)
Reverted despite build failures.
2020-10-29 17:32:06 -07:00
Azoy
746837548b [ABI] Split TypeReferenceKind from TypeMetadataRecord 2020-10-22 18:28:37 -04:00
Azoy
4b71d6776e [ABI] Introduce MetadataKind TypeRef 2020-10-22 18:24:28 -04: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
Nate Chandler
00e143c0aa [Runtime] Add trailing prespecializations to type descriptor.
The attachment of the canonical prespecializations to the generic type
will enable runtime functions to look through the canonical
prespecializations in order to return them (getGenericMetadata) and
register them with the runtime (getSpecializedGenericMetadata).
2020-08-13 17:38:02 -07: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
Nate Chandler
b0fc8daa83 [Runtime] Add entry point to canonicalize metadata.
The new function swift_getCanonicalSpecializedMetadata takes a metadata
request, a prespecialized non-canonical metadata, and a cache as its
arguments.  The idea of the function is either to bless the provided
prespecialized metadata as canonical if there is not currently a
canonical metadata record for the type it describes or else to return
the actual canonical metadata.

When called, the metadata cache checks for a preexisting entry for this
metadata.  If none is found, the passed-in prespecialized metadata is
added to the cache.  Otherwise, the metadata record found in the cache
is returned.

rdar://problem/56995359
2020-07-15 15:27:36 -07:00
Saleem Abdulrasool
41095aaa5c ABI: qualify use of StringRef and Optional (NFC)
This simply uses the qualified names for `StringRef` and `Optional` to
help with use of regular expressions to identify the usage to help
migrate the references away from `LLVMSupport` to enable explicitly
vending a custom `LLVMSupport` in the runtime.
2020-06-03 15:37:15 -07: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
David Zarzycki
97c89d8d3a Remove three ObjC fields from non-ObjC runtime 2020-05-22 09:21:21 -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
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
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
Joe Groff
bc8ff75d3a Remove dead typedef 2020-03-18 12:45:04 -07:00
Slava Pestov
4bc1d03283 Runtime: Use accessor method to get TargetWitnessTable::Description 2020-03-11 19:34:10 -04:00
Slava Pestov
c61ead1aa0 ABI: Fix return type of TargetGenericRequirementDescriptor::getConformance() 2020-03-11 00:33:46 -04:00
Kuba Mracek
84c4864911 [arm64e] Add Swift compiler support for arm64e pointer authentication 2020-02-27 16:10:31 -08:00
Slava Pestov
b1c69bd115 ABI: Introduce TargetRelativeProtocolRequirementPointer 2020-02-20 22:23:52 -05:00
Slava Pestov
a98f446f5f ABI: Clean up context and method descriptor pointers 2020-02-20 17:20:19 -05: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
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
Nate Chandler
9d019ed300 [gardening] Corrected comment.
The comment said that a function was defined in a file where in fact it
was no longer defined.  The comment now refers to the correct file.
2020-01-09 17:25:30 -08:00
Saleem Abdulrasool
7d8aac60ca disambiguate some type shadowing (NFCI)
Adjust the type shadowing identified by GCC 7.  The declaration shadows
a type which changes the meaning of the identifier subsequently.
2019-12-23 15:34:55 -08: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
Varun Gandhi
affa1b49bf [Runtime] Memset Extradata fully before copy from pattern. (#28478)
The third argument of memset needs a size in *bytes* not words.
2019-12-04 08:48:01 -08:00
Joe Groff
67ff818215 Remove unused imaginary 'friend' declaration 2019-10-03 10:03:04 -07:00
Mike Ash
ce26e7f3fd [Runtime] Fix protocol conformances on NULL types when back deploying.
Add code to the 5.0 compatibility library that scans for conformances pointing to a NULL type and rewrites them to point to a dummy type that the 5.0 protocol conformance checking code will safely ignore.
2019-08-14 11:07:31 -04:00
Jordan Rose
284b674900 [Runtime] Improve dump() for Metadata and (Type)ContextDescriptor
No functionality change.
2019-07-08 17:46:08 -07:00
Michael Munday
a8ea69e757 Merge pull request #25467 from linux-on-ibm-z/s390x-keypath-tuple-fix
Fix KeyPath failure on s390x
2019-07-01 12:36:12 +01:00
Lei Zhang
e08359c201 Fix KeyPath failure on s390x 2019-06-28 15:01:12 -04:00
Jordan Rose
57a0c9f5f8 [Runtime] Fix some type mismatch errors (#25790)
Harmless in practice, but still good hygiene.
2019-06-26 15:17:50 -07:00
Mike Ash
62cb20ec69 Merge pull request #25705 from mikeash/more-dump-methods
[Runtime] Add dump() methods to TypeContextDescriptor and EnumDescriptor.
2019-06-24 11:15:02 -07:00
Mike Ash
d05a8cab34 [Runtime] Add dump() methods to TypeContextDescriptor and EnumDescriptor. 2019-06-24 11:24:53 -04:00
moatom
2e95a0d265 Fix include guards 2019-06-02 12:10:43 +09:00
David Zarzycki
80896cdd21 [ABI headerdoc] Fix -Wdocumentation warning
'\return' is only allowed on functions/methods.
2019-05-27 05:44:22 -04:00
Joe Groff
fc8be62895 RemoteAST: Add a request to get the underlying type from an opaque type descriptor. 2019-05-01 15:42:57 -07:00
Joe Groff
9c6bc9ccd7 Runtime: Generalize TypeMetadataRecords to non-type contexts.
We could introduce non-nominal-type context descriptors, such as those for opaque declarations,
which are also interesting to be able to look up for reflection or remote purposes. This should be
a backward compatible change with old runtimes, which always ignore any context descriptor kind
they don't know about.
2019-04-29 11:30:11 -07:00
Joe Groff
95c43f4e18 Decode opaque types in the runtime demangler. 2019-04-17 14:44:40 -07:00
Joe Groff
a3c17bd080 Runtime: Implement entry points for opaque type support 2019-04-17 14:44:40 -07:00
Slava Pestov
68c07620cd IRGen: Emit Objective-C resilient class stubs if experimental flag is on
Non-generic classes with resilient ancestry do not have statically-emitted
metadata, so we can now emit an Objective-C resilient class stub instead.

Also, when emitting an Objective-C category, reference the class stub if
the class has resilient ancestry; previously this case would hit an assert.

Note that class stubs always start with a zero word, with the address point
pointing immediately after. This works around a linker issue, where the
linker tries to coalesce categories and gets confused upon encountering a
class stub.
2019-03-26 18:53:09 -04:00
Slava Pestov
9ceb3faee9 Runtime: Add support for Objective-C resilient class stubs
This adds a new tail-allocated field to class context descriptors storing
a pointer to an Objective-C class stub.

When the stub is present, we use the new _objc_realizeClassFromSwift()
entry point to realize the class instead of calling objc_readClassPair().

This should attach categories to the realized class, if they were emitted
to reference the stub.
2019-03-26 18:42:59 -04:00
David Zarzycki
b032d0b38f [Runtime] NFC: Move LLVM_ATTRIBUTE_USED from declaration to definition
This is both more correct and now required to keep building with
top-of-tree clang.
2019-03-08 12:35:53 -05:00
Mike Ash
fbe990481b [Runtime] Dynamically select the is-Swift bit at runtime on Apple platforms.
Recent Swift uses 2 as the is-Swift bit when running on newer versions, and 1 on older versions. Since it's difficult or impossible to know what we'll be running on at build time, make the selection at runtime.
2019-03-07 10:12:27 -05:00
Saleem Abdulrasool
650ebeb14b ABI: use a c-style cast in the header (NFC)
Use a C-style cast to appease cl depending on the template type
parameters used.  It does not like a reinterpret_cast between integral
types.
2019-02-24 16:47:30 -08:00
Slava Pestov
6ebd9929ea Runtime: Clarify meaning of a flag bit in GenericWitnessTable 2019-02-21 00:02:25 -05:00
Saleem Abdulrasool
6f121148d2 Merge pull request #22376 from compnerd/null-is-not-0
ABI: use `nullptr` instead of `0` for NULL comparision
2019-02-07 08:34:48 -08:00