Commit Graph

296 Commits

Author SHA1 Message Date
Slava Pestov
2c015164cf Stop passing NodePointer by reference 2019-02-13 21:51:28 -05:00
Slava Pestov
d0c7b1547e ASTMangler: Mangle sugared types for the debugger
Fixes <rdar://problem/48004306>.
2019-02-13 19:17:25 -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
36d3f47388 ASTDemangler: Preserve generic arguments for bound generic Objective-C classes
MetadataLookup gives special treatment to imported Objective-C classes,
since there's no nominal type descriptor and metadata is obtained
directly by calling into the Objective-C runtime.

Remote reflection also gives special treatment to imported Objective-C
classes; they don't have field descriptors.

However, the ASTDemangler needs to treat them like ordinary classes,
in particular it wants to preserve the generic arguments here so that
we can round-trip debug info.
2019-01-30 01:28:48 -05:00
Slava Pestov
4a74bf4ba1 ASTDemangler: Add support for lowered function types 2019-01-29 21:55:57 -05:00
Slava Pestov
13a50c2d2d ASTDemangler: Add support for lowered metatypes 2019-01-29 19:15:17 -05: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
55605ceab9 ASTDemangler: Implement DynamicSelfType 2019-01-25 21:44:02 -05:00
Slava Pestov
bbe6a56e22 ASTDemangler: Implement builtin types 2019-01-25 21:44:02 -05:00
Slava Pestov
2d21233378 ASTDemangler: Implement unresolved DependentMemberType
The debug mangling emits these when the type parameter only
conforms to one protocol having an associated type with this
name.
2019-01-25 21:44:02 -05:00
Davide Italiano
29a5605c13 [ReflectionContext] Save buffers and set the correct addresses. 2018-12-11 09:55:20 -08:00
Davide Italiano
32fc8f14d1 [ReflectionContext] Take slide in account. 2018-12-10 18:19:45 -08:00
Davide Italiano
fcc74e82de [Reflection] Try to read only the reflection sections.
(instead of the whole object).
2018-12-10 15:41:14 -08:00
Slava Pestov
00c1279dbb Reflection: Compute if types are bitwise takable
Bitwise takability is now part of the layout of a type, because
non-bitwise takable types are never stored inline in an
existential or resilient global's buffer, even if they would
fit.

The basic rule is that weak references, unknown-refcounted
unowned references, and aggregates that contain them, are not
bitwise takable, whereas everything else is bitwise takable.

Also, since the bitwise takable for an unowned reference
depends on the reference counting style, we have to record the
superclass of a protocol, if any, to correctly determine the
reference counting style of the protocol existential.
2018-11-07 00:32:12 -05: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
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
Mike Ash
8624325713 [RemoteMirrors] Fix the computation of the section start address in readMachOSections.
rdar://problem/45271231
2018-10-16 17:16:34 -04:00
Davide Italiano
fdf2ba19ac [ReflectionContext] Remove dead code. NFCI.
This is untested, and unused. I originally planned to use it
in the debugger, but I changed my mind.
2018-08-06 18:45:06 -07: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
Mike Ash
e8ccfa824f [Reflection] Make getSubstMap and visitDependentMemberTypeRef more robust against unexpected data.
Remote mirrors was hitting an assertion failure due to a generic parameter not being concrete. This check catches that case early and returns a clean failure from getSubstMap, which callers can then handle appropriately.

It also hit a casting failure in visitDependentMemberTypeRef, which assumed that SubstBase was either a NominalTypeRef or a BoundGenericTypeRef. This does a dynamic cast with a graceful failure.

In general there is a tension in this code between its use in the runtime, where we usually want to treat bad data as a horrible bug and fail loudly, and its use in remote mirrors, where we need to assume that the data we're examining might be horribly broken and we just want to do the best we can. Longer term we might want to make this code configurable so that we can have an "assert and die" mode for the runtime, and a "fail gracefully" mode for remote mirrors.

rdar://problem/40136609
2018-07-23 14:32:39 -04:00
Davide Italiano
e9d8e0a8ba [ELF] Remove a wrong comment and clarify another one.
<rdar://problem/41901725>
2018-07-19 15:23:58 -07:00
Davide Italiano
a907398872 [RemoteMirrors] Add support for reading ELF.
<rdar://problem/41901725>
2018-07-19 15:21:42 -07:00
Davide Italiano
78f23cc10f [Reflection] Locate __DATA and push into imageRanges.
This brings the current support to parity to the old one.
Thanks to Mike Ash for noticing this.

<rdar://problem/42306551>
2018-07-19 11:30:09 -07:00
Davide Italiano
382e099e60 [Reflection] Remove now dead code. NFCI.
<rdar://problem/42306551>
2018-07-18 15:24:31 -07:00
Davide Italiano
29f45b10cd [Reflection] Fix lifetime issues and out-of-process mapping.
This comes back to the older approach of mapping all __TEXT, as
taking in account the delta between sections seems a little too
complicated for now. Hopefully we'll be back optimizing this
once we're done with debugger integration.

<rdar://problem/42306551>
2018-07-18 14:53:36 -07:00
Davide Italiano
64a1e98634 [Reflection] Be less aggressive with unknown objects.
Instead of asserting, just return false.
2018-07-17 16:20:56 -07:00
Davide Italiano
da448fefc5 [ReflectionContext] Rewrite the Mach reader path.
There are several problems fixed by this commit.
-> It removes the dependency on a system header.
-> It works when the pointer size for host and target don't match
(i.e. 32-bits/64-bits and viceversa)
-> It reads the file lazily, mapping only the sections that are
needed. The old approach mapped the whole __TEXT segment, causing
significant slowdowns when trying to integrate this API in the
debugger. Now it's almost instant (10 seconds vs milliseconds).

<rdar://problem/42306551>
2018-07-17 15:35:40 -07:00
David Zarzycki
da506fc0f5 [Reflection] NFC: Adopt reference storage type meta-programming macros 2018-06-30 06:44:34 -04:00
Doug Gregor
d2a001af17 [ABI] Move the ABI parts of Runtime/Metadata.h into the ABI library.
Runtime/Metadata.h collected a large number of metadata data
structures that are actually part of the ABI. Move those data
structures into a new header, ABI/Metadata.h, and keep the in-process,
runtime-specific bits in Runtime/Metadata.h.
2018-06-12 09:55:39 -07:00
Mike Ash
4d37e2b945 Merge pull request #16996 from mikeash/faster-infoForMetadata
[RemoteMirrors] Put a cache in front of getFieldTypeInfo to avoid repetitive scanning of the target's reflection infos.
2018-06-05 09:26:59 -07:00
Mike Ash
e6a9198444 [RemoteMirrors] Put a cache in front of getFieldTypeInfo to avoid repetitive scanning of the target's reflection infos.
rdar://problem/40705238
2018-06-04 16:37:44 -07:00
Davide Italiano
52531eef00 [Reflection] Fix a member function so that it actually compiles.
Nobody's using it, so nobody noticed. I plan to use this in the
debugger.
2018-05-31 17:02:32 -07:00
Arnold Schwaighofer
cc7f207cec Rename swift sections from swift4 to swift5
rdar://38465220
2018-05-23 12:18:08 -07:00
Bob Wilson
62b9375690 [Reflection] Remove DEPENDENT_TEMPLATE2 macro
The Clang version checks introduced in #16212 and #16221 do not work well.
The __clang_major__ macro is defined differently for Apple builds of Clang,
and the __APPLE_CC__ macro is obsolete and not useful. The good news is that
those checks appear to be unnecessary. The version of Clang used with
Swift 4.2 (based on LLVM 6.0) accepts the code without the template keyword
in the places where the DEPENDENT_TEMPLATE2 macro was being used.

This also corrects a mistake in #16221 where the non-Clang/GCC definition
of DEPENDENT_TEMPLATE was changed to use the template keyword.
2018-05-03 22:02:37 -07:00
David Zarzycki
468b918eb3 Fix macOS build regression after #16212 (#16221) 2018-04-27 16:40:03 -04:00
David Zarzycki
4732be155a [Reflection] NFC: Enable building after clang r331013 (#16212) 2018-04-27 09:01:36 -04:00
Sho Ikeda
e71a065e97 [gardening][Reflection][Remote] Replace typedef with using 2018-04-02 13:43:39 +09:00
Mike Ash
979b75699a Merge branch 'master' into remotemirror-hide-reflection-sections 2018-03-16 16:24:57 -04:00
Arnold Schwaighofer
0c11e1a0a3 Mark swift sections as swift4 for Swift 4.2
rdar://36363251
2018-03-14 10:27:28 -07:00
Mike Ash
ac026128d1 [RemoteMirrors] Provide interop function for converting a raw metadata pointer into a swift_metadata_interop_t.
rdar://problem/37538580
2018-03-08 13:25:09 -05:00
Mike Ash
9a27add5f8 [RemoteMirrors] Fix ReflectionContext.h cast on 32-bit. 2018-03-02 13:53:44 -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
1434fce417 [RemoteMirrors] Switch #ifdef __APPLE__ to #if defined(__APPLE__) && defined(__MACH__) to be more specific about the fact that this code is for MachO. 2018-03-02 11:03:45 -05:00
Mike Ash
7a4ca828d8 [RemoteMirrors] Wrap MachO code in #ifdef __APPLE__. 2018-02-27 15:54:48 -05:00
Mike Ash
e4564087af [RemoteMirrors] Move ownsObject into ReflectionContext. 2018-02-27 10:32:32 -05:00
Davide Italiano
ec39bbb08c [RemoteMirrors] Move addImage from stdlib to Reflection. 2018-02-26 17:41:08 -08:00
Mike Ash
6f887475a3 [Reflection] Lots of smaller fixes and API changes due to testing the interop code.
* Remove getPointerSize and getSizeSize functions, replace with a single PointerSize value.
* Remove imageLength parameter from addImage, calculate it internally instead.
* Check remote mirrors libraries' metadata version and reject them if it's too old.
* Shim GetStringLength and GetSymbolAddress for the legacy library since we don't pass the caller's context pointer through directly.
* Actually set the IsLegacy flag in the Library struct.
* Implement ownsObject by tracking each added image's data segment and checking metadata pointers against them. The previous approach didn't work.
2018-02-26 16:56:54 -05:00
Mike Ash
7029967c99 Merge branch 'remotemirror-hide-reflection-sections' of https://github.com/mikeash/swift into remotemirror-hide-reflection-sections 2018-02-23 13:59:06 -05:00