Commit Graph

260 Commits

Author SHA1 Message Date
Joe Groff
17511c06bd MetadataReader: Build demanglings for opaque type contexts.
When building for debug, the opaque return type context is nested under an anonymous context for
the defining function. Demangle the anonymous context name to reconstruct the mangling for the
opaque type.
2019-05-02 17:27:59 -07: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
swift-ci
3aa9158940 Merge pull request #24130 from mikeash/readMetadataAndValueErrorExistential-null-check 2019-04-18 16:35:28 -07:00
Mike Ash
55cf559adc [RemoteMirror] Add a missing NULL check when reading metadata in readMetadataAndValueErrorExistential.
rdar://problem/49246601
2019-04-18 16:44:45 -04:00
Joe Groff
05dfec0cda Push the conformance accessor hack down into getTypeByMangledName. 2019-04-17 14:44:40 -07:00
Mike Ash
78e7106c57 [Reflection] Gracefully handle the absence of objc_debug_taggedpointer_ext_* variables.
rdar://problem/48483373
2019-02-28 17:51:54 -05:00
Slava Pestov
c8343525c9 Merge pull request #22975 from slavapestov/remoteast-error-existential-linux
RemoteAST: Fix Error existential introspection on Linux
2019-02-28 15:04:55 -05:00
Slava Pestov
31992143ee RemoteAST: Fix Error existential introspection on Linux
We don't have tests that look at the instance address
on the Swift side, but lldb is going to use this API
shortly.
2019-02-28 00:00:36 -05:00
Mike Ash
f85d87f764 [Reflection] Fail gracefully when objc_debug_taggedpointer_obfuscator isn't present.
Older OSes don't have this variable. We can treat it as 0 when it's not present.

rdar://problem/48411483
2019-02-27 14:37:18 -05:00
Saleem Abdulrasool
40c3655838 Remote: loosen a cast
cl objects to the use of the reinterpret_cast for the casting between
integral types.  Loosen to a static_cast.
2019-02-25 11:19:47 -08:00
Slava Pestov
86fe7fde77 RemoteAST: Fix error existential introspection on Linux 2019-02-18 18:44:02 -05:00
Erik Eckstein
58f2d373d4 Demangler: Reduce sizeof(Node) from 48 bytes to 24 bytes
This is done by disallowing nodes with children to also have index or text payloads.
In some cases those payloads were not needed anyway, because the information can be derived later.
In other cases the fix was to insert an additional child node with the index/text payload.

Also, implement single or double children as "inline" children, which avoids needing a separate node vector for children.

All this reduces the needed size for node trees by over 2x.
2019-02-15 09:29:49 -08:00
Slava Pestov
2c015164cf Stop passing NodePointer by reference 2019-02-13 21:51:28 -05:00
Slava Pestov
905a6def79 RemoteAST: Clean up use of std::pair and std::tuple for opened existentials with named structs 2019-02-12 15:18:03 -05:00
Slava Pestov
76ebaee078 MetadataReader: Add support for NSError toll-free bridging
An Error existential value can directly store a
reference to an NSError instance without wrapping
it in an Error container.

When "projecting" such an existential, the dynamic type
is the NSError's isa pointer, and the payload is the
address of the instance itself.
2019-02-12 14:59:57 -05:00
Slava Pestov
5824b0f475 MetadataReader: Factor out readNominalTypeFromClassMetadata() to clean up the code flow 2019-02-12 14:59:57 -05:00
Slava Pestov
94a6ca3094 MetadataReader: Fix reading obfuscated tagged pointers
Turns out the tags are shuffled around by XORing with a
per-process hash, and we have to deobfuscate the tag
before checking if its an extended tag.

There's no test for this; just running the existing tests
several times in a row is sufficient to trigger the problem.
2019-02-11 19:12:02 -05:00
Slava Pestov
28f305bf75 MetadataReader: Fix caching of Objective C class metadata
If resolving the type of an instance produces a class metadata for
which we cannot build a type (for example, a special class like
__NSCFNumber, which the ClangImporter does not produce a ClassDecl
for), we try the superclass.

The caching logic was broken in this case, so subsequent calls
would return an empty type.
2019-02-11 19:12:02 -05:00
Slava Pestov
dc3abd14c3 MetadataReader: Add support for Objective-C tagged pointers (#22498)
This allows Remote Mirrors and RemoteAST to inspect existentials
containing instances of imported classes.
2019-02-10 12:23:37 -05:00
Saleem Abdulrasool
9bd31f9d04 Remote: fully qualify NodePointer for Win32
This adjusts the uses of `NodePointer` to an elaborated type to resolve
ambiguity when building for Windows.
2019-01-28 19:55:27 -08:00
Saleem Abdulrasool
b422fdcaf7 Merge pull request #22155 from compnerd/NodePointer
Remote: use the qualified name for `NodePointer`
2019-01-28 10:56:56 -08:00
Doug Gregor
21e5a7e8a2 [Metadata reader] Save/restore symbolic reference resolver
… rather than clearing it out completely. This is better hygiene, although it
doesn’t matter right now.
2019-01-27 21:58:09 -08:00
Doug Gregor
23886ba579 [Metadata reader] Form demangle trees for generic extension contexts.
Translate the metadata for the generic requirements of an extension context
into a demangle tree that is associated with the demangling of an extension.

Teach the ASTDemangler how to handle class layout constraints as well.

With this, RemoteAST can resolve types nested within most constrained
extensions.
2019-01-26 23:25:51 -08:00
Doug Gregor
ff687967cc [Metadata reader] Handle symbolic references in mangled names.
When reading a mangled name, make sure to cope with embedded null bytes that
show up in symbolic references. When demangling such a name, handle symbolic
references.
2019-01-26 23:23:37 -08:00
Doug Gregor
850a2a753d [Metadata reader] Factor out reading metadata for a protocol reference.
Protocol references are interesting because we have to deal with the
low bit indicating whether we have a reference to an Objective-C protocol.
Factor out this logic for later re-use.
2019-01-26 23:08:38 -08:00
Saleem Abdulrasool
e8c6e842ce Remote: use the qualified name for NodePointer
Use the qualified name for the `NodePointer`.  The unqualified name
causes ambiguity when building on Windows.  This repairs the Windows
build.
2019-01-26 11:30:00 -08:00
Doug Gregor
cc360908cc [Remote AST] Resolve extension context descriptors to demangle trees.
Read the extended context mangled name from an extension context descriptor
so we can form a proper demangle tree for extensions. For example, this allows
types nested within extensions of types from different modules to be found.
2019-01-25 21:18:43 -08:00
Doug Gregor
9e7826b29f [Remote AST] Resolve local types using anonymous context descriptor mangling.
When the mangled name is available within an anonymous context descriptor
for a local type, use that mangled name to help RemoteAST resolve lookups
based on local type metadata.
2019-01-25 20:17:50 -08:00
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