Commit Graph

381 Commits

Author SHA1 Message Date
swift-ci
c522b6e487 Merge remote-tracking branch 'origin/master' into master-next 2018-08-01 19:09:02 -07: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
swift-ci
c076416f04 Merge remote-tracking branch 'origin/master' into master-next 2018-07-30 21:29:25 -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
swift-ci
9fd7492fa6 Merge remote-tracking branch 'origin/master' into master-next 2018-07-24 15:09:02 -07: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
swift-ci
fe35287c42 Merge remote-tracking branch 'origin/master' into master-next 2018-07-23 09:29:56 -07:00
Doug Gregor
bec722df57 [Runtime/IRGen] Switch swift_getExistentialTypeMetadata() to ProtocolDescriptorRef.
Switch one entry point in the runtime (swift_getExistentialTypeMetadata)
to use ProtocolDescriptorRef rather than a protocol descriptor. Update
IRGen to produce ProtocolDescriptorRef instances for its calls, setting
the discriminator bit appropriately.

Within the runtime, verify that all instances of ProtocolDescriptorRef have
the right layout, i.e., the discriminator bit is set for @objc protocols
but not Swift protocols.
2018-07-21 07:48:34 -07:00
swift-ci
decf2b1130 Merge remote-tracking branch 'origin/master' into master-next 2018-07-05 11:49:26 -07:00
David Zarzycki
efce6fca1e [Runtime] NFC: Adopt reference storage type meta-programming macros 2018-06-30 06:44:34 -04:00
Bob Wilson
b254041121 Merge remote-tracking branch 'origin/master' into master-next 2018-06-28 23:23:29 -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
9ef3377d28 Runtime: Fallback when _swift_getFieldAt fails to find field metadata.
Better to log the failure than fall off the edge of this function, which is expected to always invoke its callback once.
2018-06-27 14:04:14 -07:00
swift-ci
d3e605a74a Merge remote-tracking branch 'origin/master' into master-next 2018-06-25 16:50:12 -07:00
Joe Groff
663904766e Revert "Runtime: Only demangle symbolic references in constant memory."
This reverts commit 99842f9919.
2018-06-25 15:47:14 -07:00
swift-ci
b70a1cd998 Merge remote-tracking branch 'origin/master' into master-next 2018-06-25 12:49:31 -07:00
Joe Groff
99842f9919 Runtime: Only demangle symbolic references in constant memory.
This provides a slight amount of defense against attackers constructing mangled names with offsets crafted to JOP the runtime into attacker-controlled code. (Someone could still find some random code or constant data artifact in a binary that *looks* like a mangled string with symbolic references and theoretically attack that way, but they at least wouldn't be able to construct their own string entirely.)
2018-06-25 10:22:20 -07:00
Bob Wilson
740c4d0782 [master-next] Avoid use of StringRef::split and rsplit
LLVM r334283 changed StringRef::split(char) to be implemented using
StringRef::split(StringRef), which is not defined inline. Because Swift
uses StringRef without linking LLVM's libSupport.a, we can only use
functions that are defined inline in the headers. Swift currently only
builds LLVM for the host, so we cannot link libSupport.a without building
it for every target, which would be a big change. Instead, this changes
a few places in Swift to avoid using those split and rsplit functions.

rdar://problem/41029268
2018-06-18 12:57:59 -07:00
Joe Groff
5887165582 Merge pull request #15565 from tanner0101/get-field-c-callable
[runtime] make `swift_getFieldAt` callable from C / Swift
2018-06-13 09:39:32 -07:00
Mike Ash
00ef29c322 Merge branch 'fix-ConcurrentReadableArray-double-free' into fix-metadatalookup-deadlocks 2018-05-23 11:33:10 -04:00
Mike Ash
b3d1030b65 [Runtime] Change MetadataLookup's various section vectors to use ConcurrentReadableArray rather than std::vector. This avoids the need to hold a lock while iterating, removing potential deadlocks.
rdar://problem/40230581
2018-05-21 12:35:15 -04:00
Joe Groff
d91fe6bcca Mirror: Treat fields with type names we fail to demangle as empty.
And log a warning message that we're doing so.
2018-05-18 13:12:22 -07:00
Joe Groff
0d438c91c4 [Demangle to metadata] Support simple extension contexts.
Support demangling for types nested within some simple extension contexts.
Still does not support nested types within constrained extensions that
involve same-type constraints among generic parameters, nor
deeply-nested types in extensions. However, it fixes
rdar://problem/40071688.
2018-05-10 23:36:01 -07:00
Slava Pestov
902c0d3586 Runtime: Handle symbolic references inside other mangling nodes
Previously we could only handle symbolic references at the
top level, but this is insufficient; for example, you can
have a nested type X.Y where X is defined in the current
translation unit and Y is defined in an extension of X in
a different translation unit. In this case, X.Y mangles as
a tree where the child contains a symbolic reference to X.

Handle this by adding a new form of Demangle::mangleNode()
which takes a callback for resolving symbolic references.

Fixes <rdar://problem/39613190>.
2018-04-20 21:55:45 -07:00
Joe Groff
b8426862c1 Runtime: Quell a warning about useless const on a function typedef. 2018-04-17 10:46:01 -07:00
Joe Groff
b51d43377e Runtime: Properly handle demangling nested generic typerefs with symbolic manglings.
The demangling tree for a symbolic reference doesn't indicate the generic context depth of the referenced type, so we have to form the type metadata from whole cloth without incrementally building up nested types as we do for concrete mangled types. Notice when DecodedMetadataBuilder is passed a context descriptor ref without a parent and directly form the entire type in this case. Fixes rdar://problem/38891999.
2018-04-05 16:23:16 -07:00
John McCall
6c31586128 Add cyclic-metadata support to tuples.
I was going to put this off for awhile, but it turns out that a lot of
my testcases are enums with multi-payload cases, which we currently
compile as tuples, so they were all still hanging until this patch.
2018-04-01 19:23:57 -04:00
Mike Ash
34be7f6f15 Merge branch 'master' into casting-hooks 2018-03-28 14:45:48 -04:00
Mike Ash
f4224b092e [Runtime] Redo compatibility overrides boilerplate using a .def file.
rdar://problem/36997475
2018-03-28 13:39:55 -04:00
tanner0101
56713f7630 add context pointer to swift_getFieldAt function 2018-03-28 01:09:36 -04:00
tanner0101
1af7c118ab make swift_getFieldAt runtime method c-callable 2018-03-27 02:21:05 -04:00
John McCall
ba17f320c6 Extract MetadataRequest::BasicKind as MetadataState. NFC.
I de-templated MetadataState and MetadataRequest because we weren't
relying on the template and because using the template was causing
conversion problems due to the inability to directly template an enum
in C++.
2018-03-26 01:13:45 -04:00
Mike Ash
6ed2628883 [Runtime] Clean up the compatibility hooking mechanism a bit. Add a hook to swift_conformsToProtocol.
rdar://problem/36997475
2018-03-21 14:16:41 -07:00
Mike Ash
9e8d4da76f [Runtime] Add a hooking mechanism to allow future apps to extend dynamic casting and type lookup. Make swift_dynamicCast and swift_getTypeByMangledName use these hooks.
rdar://problem/36997475
2018-03-20 16:33:37 -07:00
John McCall
31f2eec044 Change type metadata accessors to support incomplete metadata.
This includes global generic and non-generic global access
functions, protocol associated type access functions,
swift_getGenericMetadata, and generic type completion functions.

The main part of this change is that the functions now need to take
a MetadataRequest and return a MetadataResponse, which is capable
of expressing that the request can fail.  The state of the returned
metadata is reported as an second, independent return value; this
allows the caller to easily check the possibility of failure without
having to mask it out from the returned metadata pointer, as well
as allowing it to be easily ignored.

Also, change metadata access functions to use swiftcc to ensure that
this return value is indeed returned in two separate registers.

Also, change protocol associated conformance access functions to use
swiftcc.  This isn't really related, but for some reason it snuck in.
Since it's clearly the right thing to do, and since I really didn't
want to retroactively tease that back out from all the rest of the
test changes, I've left it in.

Also, change generic metadata access functions to either pass all
the generic arguments directly or pass them all indirectly.  I don't
know how we ended up with the hybrid approach.  I needed to change all
the code-generation and calls here anyway in order to pass the request
parameter, and I figured I might as well change the ABI to something
sensible.
2018-03-18 21:38:08 -04:00
Huon Wilson
78bdc95ce3 Merge pull request #14874 from huonw/at-owned-cleanup
Various refactorings for __owned.
2018-03-02 14:20:21 -08:00
Huon Wilson
b94c5364f5 [NFC] Rename 'Ownership' to 'ReferenceOwnership'.
There's really two forms of ownership: references and values. Renaming
to make way for better distinguishing of the two.
2018-03-02 11:38:28 -08:00
John McCall
8d93cee012 Add a superclass reference to class descriptors. 2018-02-28 00:38:00 -05:00
Pavel Yaskevich
9288b71b60 [MetadataLookup] Enable field descriptor cache 2018-02-21 15:26:19 -08:00
Pavel Yaskevich
94017f7ee7 [IRGen] Remove 'FieldNames' field from type context descriptor
All of the information contained by this field (list of property names)
is already encoded as part of the field reflection metadata and
is accessible via `swift_getFieldAt` runtime method.
2018-02-20 18:49:00 -08:00
Joe Groff
eb316818c5 Demangler: Fill in places we need to handle symbolic references and OtherNominalTypes when demangling bound generic types. 2018-02-20 18:20:09 -08:00
Pavel Yaskevich
194c84e0a4 [MetadataLookup] Properly setup Demangler symbolic ref resolver 2018-02-20 18:20:09 -08:00
Pavel Yaskevich
3323ae36bf [Metadata] Use ownership info from _typeByMangledName 2018-02-20 18:20:09 -08:00
Pavel Yaskevich
7bcd7306c0 [Runtime/Metadata] Move swift_getFieldAt to new generic context framework 2018-02-20 18:20:09 -08:00
Pavel Yaskevich
877c70bae9 [Runtime/Metadata] Add support for dynamic field descriptor registration 2018-02-20 18:20:09 -08:00
Pavel Yaskevich
c44ad571c8 [Runtime/ABI] Add ownership info to the name-to-type metadata builder 2018-02-20 18:20:09 -08:00
Pavel Yaskevich
0da5e48a0e [Runtime/Reflection] Add swift_getFieldAt runtime accessor
Use information from reflection section of the binary to lookup
type field info such as name and it's type and return it using
new `swift_getFieldAt` method based on nominal type and field index.
2018-02-20 18:20:09 -08:00
Pavel Yaskevich
bc1c170a45 [Runtime] Register type field metadata section 2018-02-20 18:18:48 -08:00
Pavel Yaskevich
855e2286cd [Metadata/TypeByName] Don't try to check for dot syntax in presence of symbolic references
If symbolic references are present in the mangled name don't try
to check for convenience dot syntax as well since they can't appear
together.
2018-02-19 14:54:34 -08:00