Commit Graph

305 Commits

Author SHA1 Message Date
Slava Pestov
b6951932b4 ASTDemangler: Implement type alias types
Debug info uses a special mangling where type aliases can be
represented without being desugared; attempt to reconstruct
the TypeAliasType in this case.
2019-01-25 21:59:48 -05:00
Slava Pestov
bbe6a56e22 ASTDemangler: Implement builtin types 2019-01-25 21:44:02 -05:00
Doug Gregor
61d14ed3d7 [Remote AST] Use anonymous context descriptor mangled names for private types.
When an anonymous context descriptor provides a mangled name, use that
mangled name to provide the private declaration name for its child context.
This allows us to resolve private type names correctly when the corresponding
anonymous context has its mangled name.

Fixes rdar://problem/38231646.
2019-01-25 10:20:25 -08:00
rposts
808fe01ec6 Fix test case regressions on s390x arch 2019-01-14 10:24:50 -05:00
John McCall
ff6d031482 Allow TypeReference to refer to protocol descriptors.
We should also allow references via manglings just to cover the
general case if we need it, but this is useful on its own so that
we can emit a reference to any natively-declared Swift type.
2018-11-16 00:39:10 -05:00
Slava Pestov
1b37407227 Fix MetadataReader handling of @objc protocols in existentials 2018-11-02 00:47:11 -04:00
Slava Pestov
d093fcb4a4 Reflection: Decode imported Objective-C classes and protocols as their own TypeRef
Right now we expect that every class and protocol has a field
descriptor that tells us if the entity is @objc or not.

For imported types, the descriptor will not exist if we did not
directly emit a field whose concrete type contains the imported
type. For example, in lldb, we might have a generic type whose
runtime substituted type includes an imported type.

In this case, TypeLowering would fail to produce a layout because
it did not find a field descriptor for the imported type.

A better approach is to have the TypeDecoder call a different
factory method for imported types, and handle them specially in
TypeLowering, bypassing the field type metadata altogether.
2018-11-02 00:47:11 -04:00
Saleem Abdulrasool
de90109a24 Remote: explicitly qualify type
When building the remote mirror for Windows, the build would fail due to the
symbol resolution being slightly different on Windows.  Explicitly qualify the
name to resolve the ambiguity.  This reapirs the build of the remote mirror for
Windows.
2018-10-25 14:10:04 -07:00
Doug Gregor
5b41ac16db [ABI] Introduce indirect symbolic references to context descriptors.
Extending the mangling of symbolic references to also include indirect
symbolic references. This allows mangled names to refer to context
descriptors (both type and protocol) not in the current source file.

For now, only permit indirect symbolic references within the current module,
because remote mirrors (among other things) is unable to handle relocations.

Co-authored-by: Joe Groff <jgroff@apple.com>
2018-10-23 16:06:42 -07:00
Doug Gregor
a4778e1c0c [ABI] Only emit resilient superclass descriptor references in class metadata.
The superclass descriptor reference in class context descriptors is only used
for metadata bound computations when the superclass is resilient. Only
include the superclass descriptor reference when the class has a resilient
superclass, using a trailing record. It’s a tiny space savings for
classes that don’t have resilient superclasses.
2018-10-03 20:05:28 -07:00
Mike Ash
49c3547449 Merge remote-tracking branch 'origin/master' into rename-conflicting-classes-and-methods 2018-09-21 15:52:38 -04:00
Joe Groff
93d85997e8 Generalize extra inhabitants of tuples.
Like we did for structs, make it so that tuple types can also get extra inhabitants from whichever element with the most, not only the first. This lets us move all of the extra inhabitant handling functionality between structs and tuples in IRGen up to the common RecordTypeInfo CRTP base.
2018-09-20 15:39:44 -07:00
Mike Ash
798edb9d0e [Runtime][Stdlib][Overlays] Rename various Objective-C classes and methods that would conflict when loading old Swift libraries into a process alongside ABI-stable libraries.
rdar://problem/35768222
2018-09-13 16:55:10 -04:00
Davide Italiano
8d25db681b [MetadataReader] Rename pointed to pointer for consistency.
Pointed out by John McCall in a previous review (I just procrastinated
to do it, until today).
2018-09-05 16:27:49 -07:00
Slava Pestov
8be09fef74 IRGen/Runtime: Rename "InPlaceMetadata" to "SingletonMetadata"
It's not actually "in-place" for resilient classes, which have a
pattern with an allocation function.
2018-08-24 00:52:36 -07:00
Davide Italiano
8e43e0bca2 [MetadataReader] Remove the full llvm:: qualification.
It's not needed. Pointed out by John McCall during his code
reviews.
2018-08-22 17:23:07 +02:00
John McCall
05c9671902 Change the ABI for the type descriptors of imported declarations.
- Instead of keeping multiple flags in the type descriptor flags,
  just keep a single flag indicating the presence of additional
  import information after the name.

- That import information consists of a sequence of null-terminated
  C strings, terminated by an empty string (i.e. by a double null
  terminator), each prefixed with a character describing its purpose.

- In addition to the symbol namespace and related entity name,
  include the ABI name if it differs from the user-facing name of the
  type, and make the name the user-facing Swift name.

There's a remaining issue here that isn't great: we don't correctly
represent the parent relationship between error types and their codes,
and instead we just use the Clang module as the parent.  But I'll
leave that for a later commit.
2018-08-01 18:37:08 -04:00
Davide Italiano
a7f36075ff Merge pull request #17571 from dcci/existentialremoteast
[RemoteAST] Initial support for projecting the type out of an existen…
2018-07-31 14:27:50 -07:00
John McCall
873c02e317 Remove the need to set CTag on all imported tag declarations.
NFC; I'll change the schema to remove CTag in a separate patch.
2018-07-30 22:29:07 -04:00
John McCall
aa88f861df Recursify the type-descriptor-to-demangle-tree algorithm; NFC.
Having the parent nodes available when building children is
sometimes useful, as I'll show soon.  It also naturally avoids the
weird re-use of local variables in this function that made it so
delightfully difficult to read.
2018-07-30 21:27:12 -04:00
Davide Italiano
4b5c2295d1 [RemoteAST] Support for extracting the type/valuea out of an existential.
This will be used in lldb.
<rdar://problem/41546568>
2018-07-30 17:00:23 -07:00
John McCall
db8f23df74 Update the ABI for uniquing foreign type metadata.
- `swift_getForeignTypeMetadata` is now a request/response function.

- The initialization function is now a completion function, and the
  pointer to it has moved into the type descriptor.

- The cache variable is no longer part of the ABI; it's an
  implementation detail of the access function.

- The two points above mean that there is no special header on foreign
  type metadata and therefore that they can be marked constant when
  there isn't something about them that needs to be initialized.

The only foreign-metadata initialization we actually do right now is
of the superclass field of a foreign class, and since that relationship
is a proper DAG, it's not actually possible to have recursive
initialization problems.  But this is the right long-term thing to do,
and it removes one of the last two clients of once-based initialization.
2018-07-29 03:16:35 -04:00
John McCall
d10239313f Reference runtime-only ObjC classes with bare strings.
As part of this, rename TypeMetadataRecordKind to TypeReferenceKind
and consistently give it three bits of storage.

The better modelling of these type references appears to have been
sufficient to make dynamic conformance checks succeed, which is good
but unexpected.
2018-07-27 22:55:22 -04:00
Davide Italiano
5dc41566fb [Reflection] Hoist computation of error existentials to the reader.
<rdar://problem/41546568>
2018-07-26 10:23:31 -07:00
Davide Italiano
055c789915 [Reflection] Hoist computation of metadata/value for opaque existential to the reader.
This will allow re-use of this code in RemoteAST (and, transitively,
in lldb).

<rdar://problem/41546568>
2018-07-25 16:02:46 -07:00
John McCall
dadb51e708 Support in-place value metadata initialization in the runtime. 2018-07-25 03:00:36 -04:00
Doug Gregor
e7998f1846 [ABI] Record unmangled names in Swift protocol descriptors.
Rather than storing a mangled name in a Swift protocol descriptor,
which encodes information that is redundant with the context of the
protocol, store an unmangled name as in nominal type descriptors. Update
the various places where this name is used to extract the demangle
tree from the context descriptors.
2018-07-24 04:25:13 -07:00
Doug Gregor
a54a6d8d7f [ABI] Rework protocol descriptor metadata.
Reimplement protocol descriptors for Swift protocols as a kind of
context descriptor, dropping the Objective-C protocol compatibility
layout. The new protocol descriptors have several advantages over the
current implementation:

* They drop all of the unused fields required for layout-compatibility
  with Objective-C protocols.
* They encode the full requirement signature of the protocol. This
  maintains more information about the protocol itself, including
  (e.g.) correctly encoding superclass requirements.
* They fit within the general scheme of context descriptors, rather than
  being their own thing, which allows us to share more code with
  nominal type descriptors.
* They only use relative pointers, so they’re smaller and can be placed
  in read-only memory

 Implements rdar://problem/38815359.
2018-07-23 22:12:42 -07:00
Doug Gregor
a777c5c6a9 [Metadata reader] Separate ObjC and Swift protocol descriptor reading.
When reading the protocol metadata from existential type metadata,
check the “isObjC” bit and handle the reading of the Objective-C
protocol name (using TargetObjCProtocolPrefix) separately from the reading the name of a Swift protocol (using TargetProtocolDescriptor).
More preparation for separating the layout of these two entities.
2018-07-23 17:08:59 -07:00
Doug Gregor
3464929638 [ABI] Rework existential type metadata to use ProtocolDescriptorRef.
Use ProtocolDescriptorRefs within the runtime representation of
existential type metadata (TargetExistentialTypeMetadata) instead of
bare protocol descriptor pointers. Start rolling out the use of
ProtocolDescriptorRef in a few places in the runtime that touch this
code. Note that we’re not yet establishing any strong invariants on
the TargetProtocolDescriptorRef instances.

While here, replace TargetExistentialTypeMetadata’s hand-rolled pointer 
arithmetic with swift::ABI::TrailingObjects and centralize knowledge of
its layout better.
2018-07-20 20:54:49 -07:00
Joe Groff
e2dd2ff11f Runtime: Handle synthesized decl "related entity" tags.
Clang-importer-synthesized declarations get an extra tag character included in their mangling, which was not being preserved in type context descriptors. This caused runtime lookup for these synthesized types to fail. Fix this by adding the tag information to type context descriptors and teaching the runtime to match it up when fetching metadata by mangled name. Fixes rdar://problem/40878715.
2018-06-28 12:11:12 -07:00
Joe Groff
681a96b45c Runtime: Tolerate unknown metadata kinds.
We want to be able to potentially introduce new metadata kinds in future Swift compilers, so a runtime ought to be able to degrade gracefully in the face of metadata kinds it doesn't know about. Remove attempts to exhaustively switch over metadata kinds and instead treat unknown metadata kinds as opaque.
2018-05-17 15:35:06 -07:00
Sho Ikeda
e71a065e97 [gardening][Reflection][Remote] Replace typedef with using 2018-04-02 13:43:39 +09:00
Kuba (Brecka) Mracek
84e71b8d7a Change the RemoteMirror API to have extensible data layout callback (#15291)
* Change the RemoteMirror API to have extensible data layout callback

* Use DLQ_Get prefix on DataLayoutQueryType enum values

* Simplify MemoryReaderImpl and synthesize minimalDataLayoutQueryFunction
2018-03-16 14:54:04 -07:00
Joe Groff
57d6772d48 Runtime: Use type context descriptors to unique foreign metadata.
Now that every foreign type has a type context descriptor, we can use that for a uniquing key instead of a dedicated mangled string, saving some code size especially in code that makes heavy use of imported types. rdar://problem/37537241
2018-03-10 10:15:38 -08:00
Mike Ash
a2d973dbbd Merge branch 'master' into remotemirror-hide-reflection-sections 2018-03-05 09:48:58 -05:00
John McCall
a7c5c80799 Compute class metadata bounds solely from class-descriptor chain information.
Change the "metadata base offset" variable into a "class metadata bounds"
variable that contains the base offset and the +/- bounds on the class.
Link this variable from the class descriptor when the class has a resilient
superclass; otherwise, store the +/- bounds there.  Use this variable to
compute the immediate-members offset for various runtime queries.  Teach the
runtime to fill it in lazily and remove the code to compute it from the
generated code for instantiation.  Identify generic arguments with the start
of the immediate class metadata members / end of the {struct,enum} metadata
header and remove the generic-arguments offset from generic type descriptors.
2018-03-04 02:14:32 -05:00
John McCall
f2bb319bdb Change the pattern of generic class metadata instantiation.
Minimize the generic class metadata template by removing the
class header and base-class members.  Add back the set of
information that's really required for instantiation.
Teach swift_allocateGenericClass how to allocate classes without
superclass metadata.  Reorder generic initialization to establish
a stronger phase-ordering between allocation (the part that doesn't
really care about the generic arguments) and initialization (the
part that really does care about the generic arguments and therefore
might need to be delayed to handle metadata cycles).

A similar thing needs to happen for resilient class relocation.
2018-03-04 00:01:56 -05:00
Mike Ash
6d10ac9e92 [RemoteMirrors] #include <cstring> in MemoryReader.h for memcpy. 2018-03-02 15:57:28 -05:00
Mike Ash
553ef86a4b [RemoteMirrors] Change MemoryReader::readBytes to return a unique_ptr instead of a tuple so that the destructor handles freeing the memory. 2018-03-02 12:05:36 -05:00
Mike Ash
7e9e476b58 Merge branch 'master' into remotemirror-hide-reflection-sections 2018-03-01 10:47:07 -05:00
John McCall
8d93cee012 Add a superclass reference to class descriptors. 2018-02-28 00:38:00 -05:00
Mike Ash
6324c3dbe9 [RemoteMirrors] Fix the pointer-returning readBytes wrapper to actually work. 2018-02-27 16:53:01 -05:00
John McCall
a53f82449c Clarify which type-descriptor-specific flags apply to which types; NFC. 2018-02-27 16:00:21 -05:00
Mike Ash
d775f72d19 [RemoteMirrors] Support passing NULL for the FreeBytesFunction. 2018-02-27 15:16:15 -05:00
Mike Ash
71f1c391ab [RemoteMirrors] Move FreeBytesFunction from an out-parameter on ReadBytesFunction to a function pointer passed in when creating a reflection context. 2018-02-27 12:51:04 -05:00
John McCall
dd99536d31 Move the metadata-pattern header into the type context descriptor.
This is yet another waypoint on the path towards the final
generic-metadata design.  The immediate goal is to make the
pattern a private implementation detail and to give the runtime
more visibility into the allocation and caching of generic types.
2018-02-26 12:10:24 -05:00
Mike Ash
ad0f8f5415 Merge branch 'master' into remotemirror-hide-reflection-sections 2018-02-23 11:48:21 -05:00
Mike Ash
9aa24e8be7 [Reflection] Make both MemoryReader::readBytes methods virtual and provide a default implementation for both to allow subclasses to smoothly transition from overriding the old one to overriding the new one.
rdar://problem/37538580
2018-02-22 17:17:00 -05:00
Mike Ash
bf58357e54 [Reflection] Change ReadBytesFunction to return a pointer rather than copying data, and adjust its users accordingly.
rdar://problem/37538580
2018-02-21 12:17:28 -05:00