Commit Graph

1960 Commits

Author SHA1 Message Date
Michael Gottesman
763bbf971e Merge pull request #15114 from gottesmm/pr-ad4fc16a11b85ee79426be965870d165e866a298
[+0-all-args] Swift expects the returned object from bridgeErrorToNSE…
2018-03-10 10:19:25 -08:00
Joe Groff
98ee6a5d7d Runtime: Prefab metadata records for Any and AnyObject.
Metadata for these types gets demanded fairly frequently, and it's a decent code size savings not having to emit a runtime call to access them.
2018-03-10 10:15:42 -08: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
swift-ci
81624e22a8 Merge remote-tracking branch 'origin/master' into master-next 2018-03-10 09:09:03 -08:00
Arnold Schwaighofer
f01d84c4b9 Merge pull request #15132 from aschwaighofer/fix_linux_link_issue_attempt
Speculative fix for linux bot linker failure
2018-03-10 09:03:57 -08:00
swift-ci
4a343a43c2 Merge remote-tracking branch 'origin/master' into master-next 2018-03-10 03:29:07 -08:00
swift-ci
ca3acfd2b7 Merge pull request #15039 from gottesmm/pr-8840a7d3dda61ba61ad551cc6cece87b78fece99 2018-03-10 03:26:46 -08:00
swift-ci
b7b59e03e9 Merge remote-tracking branch 'origin/master' into master-next 2018-03-10 03:08:59 -08:00
Joe Groff
0d7c42ce66 Runtime: Do the bare minimum balancing for bridge casting at +0.
The logic here is causing leaks in some situations, and it's likely we'll want
bridging calls to go back to +1 again anyway, so do the minimum adaptation to
the +0 convention for now.

rdar://34222540
2018-03-10 02:17:24 -08:00
Joe Groff
7f9e322d98 [+0-all-args] Knock out some inappropriate "unreachable"s in the runtime.
Future Swifts may add new metadata kinds, so it isn't appropriate to crash when
we see one. In the case of reflection, we can fall back to opaque behavior.

rdar://34222540
2018-03-09 22:44:04 -08:00
Arnold Schwaighofer
e106161d8f Speculative fix for linux bot linker failure 2018-03-09 17:55:39 -08:00
Michael Gottesman
bb8a273386 [+0-all-args] Swift expects the returned object from bridgeErrorToNSError to be at +1 even if the bridge is a no-op.
rdar://34222540
2018-03-09 10:53:08 -08:00
swift-ci
ecd7a48bb2 Merge remote-tracking branch 'origin/master' into master-next 2018-03-09 09:49:07 -08:00
John McCall
9313aa04a1 Merge pull request #15071 from rjmccall/metadata-cache-entries
Rewrite MetadataCache to be a more natural extension of ConcurrentMap
2018-03-09 12:44:37 -05:00
Arnold Schwaighofer
1e4f55de8d Merge pull request #15046 from aschwaighofer/without_actually_escaping_verification
Implement withoutActuallyEscaping verification
2018-03-09 09:34:06 -08:00
swift-ci
164b94971a Merge remote-tracking branch 'origin/master' into master-next 2018-03-08 14:09:07 -08:00
swift-ci
4cef8ae59d Merge pull request #15082 from DougGregor/runtime-conformance-null-descriptor 2018-03-08 14:03:20 -08:00
Doug Gregor
2dd61a948a [Runtime] Don't use NULL as a conformance cache key.
The runtime hash table for protocol conformances is keyed by (type, protocol),
where the type can be either a type metadata pointer or a type context
descriptor. The latter is preferred for generic and resilient types, because
a single entry in the cache can work for any instantiation.

However, not all type metadata has a corresponding type context descriptor.
For example, a class that is dynamically subclassed by the Objective-C
runtime won't have a type context descriptor. In such cases, our key
into the hash table was (NULL, protocol) leading to mistaken
conformances for different dynamically-subclassed types.

Introduce a NULL check for the type of the hash table key, which
illustrates the problem in a number of existing tests that exercise
the runtime, and teach the runtime to use the type context descriptor
as the key only when it's non-NULL, falling back to the type metadata
pointer otherwise.

Fixes rdar://problem/38053213.
2018-03-08 13:31:57 -08:00
John McCall
f304c321f3 Rewrite MetadataCache to be a more natural extension of ConcurrentMap.
Change generic witness table instantiation to use a more lightweight
entry scheme that allocates the witness table as part of the entry.

In contrast, change generic metadata instantiation to use a more
straightforward allocation scheme where the metadata is a totally
independent allocation.

This is preparation for proper cyclic-dependency handling.
2018-03-08 02:29:20 -05:00
swift-ci
97b732d8cc Merge remote-tracking branch 'origin/master' into master-next 2018-03-07 18:29:16 -08:00
Huon Wilson
e307e54098 [AST] Explicitly track things marked __owned. 2018-03-08 12:36:24 +11:00
Arnold Schwaighofer
b9602754cd Untangle the dependency on swiftStdlibStubs from swiftRuntime that I introduced
rdar://35525730
2018-03-07 11:17:19 -08:00
Arnold Schwaighofer
89e972f5a8 SILGen: Implement withoutActuallyEscaping verification
Check that an ``withoutActuallyEscaping(noescape_closure) { // scope}`` closure
has not escaped in the scope using the ``is_escaping_closure %closure``
instruction.

rdar://35525730
2018-03-07 09:00:12 -08:00
Arnold Schwaighofer
5940796cc1 SIL: Add an is_escaping_closure instruction
Will be used to verify that withoutActuallyEscaping's block does not
escape the closure.

``%escaping = is_escaping_closure %closure`` tests the reference count. If the
closure is not uniquely referenced it prints out and error message and
returns true. Otherwise, it returns false. The returned result can be
used with a ``cond_fail %escaping`` instruction to abort the program.

rdar://35525730
2018-03-07 08:56:00 -08:00
swift-ci
d92f84478b Merge remote-tracking branch 'origin/master' into master-next 2018-03-07 00:29:23 -08:00
John McCall
9c8bdf24a7 Fill in the field-offset vector and payload size for fixed-layout value metadata.
This regression wasn't caught by normal testing because the emission
pattern substantially changed anyway, breaking tests that were looking for
the field-offset vector, and because normal execution testing doesn't
actually use the field-offset vector and enum payload size fields.
Reflection, which does use these fields, was skating by for common types
because metadata is typically allocated out of freshly zeroed pages and
most such types have only one field.

Also, don't emit a completion function for value metadata with fixed layout.

We really shouldn't have to emit field-offset vectors for fixed-layout types;
the layout should just go in the type descriptor.  But for now, this is what
we have to do.
2018-03-07 01:18:44 -05:00
swift-ci
632dce19ce Merge remote-tracking branch 'origin/master' into master-next 2018-03-06 02:49:18 -08:00
swift-ci
9bd1ac9b60 Merge pull request #15016 from rjmccall/split-metadata-instantiation 2018-03-06 02:38:02 -08:00
swift-ci
5dead4ad96 Merge remote-tracking branch 'origin/master' into master-next 2018-03-06 02:09:22 -08:00
Michael Gottesman
eb96da521f [+0-all-args] Update tryDynamicCastNSErrorToValue for +0 all arguments. 2018-03-06 02:05:43 -08:00
John McCall
9a4540e84d Split the instantiation function into two phases.
The allocation phase is guaranteed to succeed and just puts enough
of the structure together to make things work.

The completion phase does any component metadata lookups that are
necessary (for the superclass, fields, etc.) and performs layout;
it can fail and require restart.

Next up is to support this in the runtime; then we can start the
process of making metadata accessors actually allow incomplete
metadata to be fetched.
2018-03-06 03:07:55 -05:00
swift-ci
a0cd030c07 Merge remote-tracking branch 'origin/master' into master-next 2018-03-05 19:49:23 -08:00
John McCall
11e3d16c93 Merge pull request #14998 from rjmccall/generic-metadata-patterns
Apply generic metadata patterns to all types and change their layout.
2018-03-05 22:45:23 -05:00
swift-ci
d9c2e4b593 Merge remote-tracking branch 'origin/master' into master-next 2018-03-05 16:09:21 -08:00
Huon Wilson
216e69e810 Merge pull request #14973 from huonw/no-dynamic-count
[IRGen] Cond. conformance witness table count isn't needed dynamically.
2018-03-05 16:07:14 -08:00
John McCall
dff0031b02 Apply generic metadata patterns to all types and change their layout.
The layout changes to become relative-address based.  For this to be
truly immutable (at least on Darwin), things like the RO data patterns
must be moved out of the pattern header.  Additionally, compress the
pattern header so that we do not include metadata about patterns that
are not needed for the type.

Value metadata patterns just include the metadata kind and VWT.

The design here is meant to accomodate non-default instantiation
patterns should that become an interesting thing to support in the
future, e.g. for v-table specialization.
2018-03-05 19:05:41 -05:00
swift-ci
8c50a53066 Merge remote-tracking branch 'origin/master' into master-next 2018-03-05 12:29:07 -08:00
Michael Gottesman
e66fd1ad0c [+0-all-args] When casting a value to NSError, release the value passed to _swift_stdlib_bridgeErrorToNSError since it is at +0 now.
rdar://34222540
2018-03-05 12:22:09 -08:00
Michael Gottesman
f98fc84957 [+0-all-args] Add a missing +1 guard so this release doesn't happen with a +0 calling convention.
rdar://34222540
2018-03-05 12:21:47 -08:00
swift-ci
6fa54bc0bf Merge remote-tracking branch 'origin/master' into master-next 2018-03-05 11:49:22 -08:00
Joe Groff
f213671327 Runtime: Handle getDescription correctly in +0 mode.
This can eventually be made more efficient by avoiding copies in all the
callees, but this is the minimal fix. Remove an unnecessary bit of
reverse-dependency on the Foundation overlay while we're here.

rdar://34222540
2018-03-05 11:48:40 -08:00
Huon Wilson
43196c27ac [IRGen] 'void **' -> 'void ***' in swift_getGenericWitnessTable.
This is simpler, because the native form of that last argument is: a
pointer to a buffer (*) of pointers (*) to witness tables, which is
modelled as a buffer of void *s. Thus, void ***.
2018-03-06 00:22:05 +11:00
swift-ci
5477029dd0 Merge remote-tracking branch 'origin/master' into master-next 2018-03-04 15:08:58 -08:00
Davide Italiano
a59d82188f [Metadata] Define _objc_empty_cache under SWIF_OBJC_INTEROP.
Later code uses the variable under this macro, so defining it
under NDEBUG breaks debug builds of stdlib.
2018-03-04 12:29:09 -08:00
swift-ci
9dbb5effd5 Merge remote-tracking branch 'origin/master' into master-next 2018-03-04 01:29:35 -08: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
swift-ci
dcee1f4d47 Merge remote-tracking branch 'origin/master' into master-next 2018-03-02 14:31:02 -08: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