Commit Graph

269 Commits

Author SHA1 Message Date
Joe Groff
02b5e56327 Merge pull request #27369 from jckarter/type-ref-builder-remote-ref
Reflection: Traffic in RemoteRefs.
2019-09-26 09:22:57 -07: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
Joe Groff
bacbdb8164 Merge pull request #27368 from jckarter/metadata-reader-anonymous-context-size
MetadataReader: Correct size measurement reading AnonymousContextDescriptors.
2019-09-25 17:09:01 -07:00
Joe Groff
a37f81880e MetadataReader: Correct size measurement reading AnonymousContextDescriptors.
By including the trailing mangled name reference in the baseSize, we computed the wrong offset for
the generic parameter header, and then miscomputed the size of the trailing generic context info.
This would lead to accesses into the context sometimes reading from uninitialized memory.
Fixes rdar://problem/55711107
2019-09-25 14:29:47 -07:00
Joe Groff
31212b8b25 Fix handling of null relative references in RemoteRef. 2019-09-23 20:08:48 -07:00
Joe Groff
88a833f19c Reflection: Move resolveRelativeField functionality onto RemoteRef
Resolving a direct relative reference given a RemoteRef doesn't need the MetadataReader,
since the offset should already be in the local buffer; we can add it to RemoteRef's
saved remote address and get a new remote address. Refactor the API to make as much as
possible of it available directly on RemoteRef.
2019-09-20 15:01:57 -07:00
Joe Groff
f1cb0d11ef Reflection: Make RemoteRef template not depend on Runtime.
The only thing the Runtime affects is the width of the StoredPointer for the remote address, for
which storing a uint64_t ought to be enough for anyone we care about so far. This will make it
easier to store and use RemoteRefs in code that isn't or shouldn't ideally be templatized on
Runtime (such as TypeRefBuilder, and ultimately ReflectionContext, from the Reflection library.)
2019-09-20 12:43:51 -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
Joe Groff
4e493b0051 Reflection: Look through opaque type descriptors.
Turn an opaque type reference in a mangled name into its underlying type, if we can.
rdar://problem/46140707
2019-06-26 17:58:52 -07:00
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