Commit Graph

777 Commits

Author SHA1 Message Date
Greg Parker
e0656515b9 Revert "Metadata cache optimizations" 2016-08-29 19:03:40 -07:00
Greg Parker
b3566eace5 Fix shadow warnings of a local variable versus an instance variable. 2016-08-29 17:01:28 -07:00
Bryon Gloden, CISSP®
b07bc61b48 uninitialized variable: savedSize
[stdlib/public/runtime/Metadata.cpp:2560]: (error) Uninitialized variable: savedSize
2016-08-28 16:47:12 -04:00
John McCall
4fa5182c35 Merge pull request #4428 from rjmccall/structural-type-metadata-caches
Metadata cache optimizations
2016-08-26 12:54:39 -07:00
John McCall
b7bd752946 Simplify and optimize the structural type metadata caches to use ConcurrentMap directly.
Previously, these were all using MetadataCache.  MetadataCache is a
more heavyweight structure which acquires a lock before building the
metadata.  This is appropriate if building the metadata is very
expensive or might have semantic side-effects which cannot be rolled
back.  It's also useful when there's a risk of re-entrance, since it
can diagnose such things instead of simply dead-locking or infinitely
recursing.  However, it's necessary for structural cases like tuple
and function types, and instead we can just use ConcurrentMap, which
does a compare-and-swap to publish the constructed metadata and
potentially destroys it if another thread successfully won the race.

This is an optimization which we could not previously attempt.

As part of this, fix tuple metadata uniquing to consider the label
string correctly.  This exposes a bug where the runtime demangling
of tuple metadata nodes doesn't preserve labels; fix this as well.
2016-08-25 22:27:17 -07:00
John McCall
f2080cb1a2 Remove the linked list through metadata caches, since LLDB is
no longer using it even in fallback code.
2016-08-25 20:11:56 -07:00
Doug Gregor
e1545a7d5a [Type checker/runtime] Move default implementation of Error._code into the runtime.
Rather than having Sema provide a default implementation of
Error._code when needed, introduce a runtime function to extract the
default code, so that we can provide a default implementation via a
protocol extension in the standard library.
2016-08-25 16:00:19 -07:00
Greg Parker
deb562dccf [stdlib] Remove struct SwiftObject_s. (#4501)
[stdlib] Remove struct SwiftObject_s.

SWIFT_HEAPOBJECT_NON_OBJC_MEMBERS works just as well with less redundancy.
2016-08-25 00:33:43 -07:00
Gary Liu
9fab7cb15f Fix s390x Enum load/storeMultiPayloadValue (#4461) 2016-08-24 15:33:29 -07:00
John McCall
219d093ef4 Fix the cast optimizer to handle CF/NS bridging correctly,
and fix the dynamic cast runtime to handle class + enum casts
to AnyHashable correctly.
2016-08-23 07:22:28 -07:00
Ted Kremenek
f5f690567e Merge pull request #4452 from jckarter/crash-on-empty-field-in-nested-class
Runtime: Don't clobber the compiler-emitted layout of empty fields.
2016-08-22 14:32:54 -07:00
Joe Groff
4f65ef92c2 Runtime: Don't clobber the compiler-emitted layout of empty fields.
Otherwise, we try to dirty constant memory for classes emitted as constant-layout by the compiler. Fixes rdar://problem/27951346.
2016-08-22 13:37:13 -07:00
David Farler
985e32b3b0 Merge pull request #4397 from bitjammer/stack-overflow-class-existential-mirror-27348445
Make a temporary existential when reflecting weak properties
2016-08-19 18:00:35 -07:00
David Farler
f0609a612b Make a temporary existential when reflecting weak properties
When getting a mirror child that is a class existential, there
may be witness tables for the protocol composition to copy. Don't
just take the address of a class instance pointer from the stack -
make a temporary existential-like before calling into the Mirror
constructor.

This now correctly covers reflecting weak optional class types, and weak
optional class existential types, along with fixing a stack buffer
overflow reported by the Address Sanitizer (thanks, ASan!).

Tests were also updated to check for the validity of the child's data.

rdar://problem/27348445
2016-08-19 15:30:35 -07:00
John McCall
b937bdf717 Dynamic casts to AnyObject should succeed for an arbitrary source
type because we can always make a SwiftValue.

rdar://26268575
2016-08-19 10:36:18 -07:00
David Farler
47d618cb5b Don't leak boxes when releasing Mirror owners
Heap boxes don't have a "class" metadata kind, so make
sure to release them when creating a new owner for loading
weak references in the runtime mirrors.

rdar://problem/27348445
2016-08-17 12:42:26 -07:00
David Farler
a420279a70 Merge pull request #4060 from bitjammer/weak-reference-in-mirror-existential
Always, no, never... forget to check your references
2016-08-16 12:47:27 -07:00
David Farler
10c44e1a3a Always, no, never... forget to check your references
for weak semantics, that is!

94a9c512b9 made some changes to loading
weak references by adding some information in the lower bits with
respect to locking. These bits need to be masked out when performing a
load, such as when we want to get the metadata pointer for a class
instance. This normally works fine when going through the normal weak
loading functions in the runtime.

When the runtime function swift_ClassMirror_subscript gets the offset of
one of its stored properties, it immediately packages it into the the
ad-hoc existential container, known as just `Mirror` in the runtime.
However, the weak reference isn't aligned! It has bit 1 set.  We weren't
loading the weak reference here as we would during normal SILGen, such
as with a weak_load instruction. Simulate that here and make the
reference strong before putting it into the Mirror container, which also
clears those lower bits.

rdar://problem/27475034

There are still a couple of other cases to handle, namely the
unowned(safe) and unowned(unsafe) reference kinds. There may be other
places where an unaligned pointer is problematic in the runtime, which
we should audit for correctness.

rdar://problem/27809991
2016-08-16 11:43:58 -07:00
Joe Groff
f998c624e6 Runtime: Add a convenient -[_SwiftValue _swiftTypeName] method for debugging.
This makes it a bit easier to diagnose unexpected boxing problems in the debugger, by allowing `po [value _swiftTypeName]` to work, instead of forcing users to know how to call `swift_getTypeName` from lldb themselves.
2016-08-15 13:53:59 -07:00
Dmitri Gribenko
42a4537ea4 Merge pull request #4204 from apple/runtime-expose-SwiftError-layout
runtime: expose the layout of SwiftError to LLDB
2016-08-10 22:07:38 -07:00
Dmitri Gribenko
3709e1ffba runtime: remove unused variables from the non-ObjC SwiftError 2016-08-10 16:10:52 -07:00
Dmitri Gribenko
990350e068 runtime: expose the layout of SwiftError to LLDB through global constants 2016-08-10 16:10:52 -07:00
Dmitri Gribenko
783fafa36a runtime: rename SwiftValue to _SwiftValue (it is a private class) 2016-08-10 15:45:16 -07:00
Dmitri Gribenko
f1ec334fe5 stdlib: make AnyHashable(SwiftValue) unbox the value
Previously AnyHashable would consider SwiftValue to be a subclass of
NSObject (which it is in practice) and return false when trying to
compare an AnyHashable of a SwiftValue box to an AnyHashable of the
unboxed value.
2016-08-09 01:38:53 -07:00
Dmitri Gribenko
e6f23fb7d3 runtime: move two AnyHashable-related entrypoints to SwiftHashableSupport.h 2016-08-09 00:49:20 -07:00
Dmitri Gribenko
45ab914bb1 runtime: make SwiftValue use the Hashable conformance, if available
If a value error wrapped in a SwiftValue box conforms to Hashable, the box now
uses the Swift's conformance to Hashable.

Part of rdar://problem/27574348.
2016-08-09 00:49:20 -07:00
Dmitri Gribenko
813b556ad2 runtime: hide contents of SwiftValue.h from non-objc runtime build 2016-08-09 00:49:20 -07:00
Dmitri Gribenko
b162f60070 runtime: make _SwiftNativeNSError use the Hashable conformance, if available
If the Swift error wrapped in a _SwiftNativeNSError box conforms to
Hashable, the box now uses the Swift's conformance to Hashable.

Part of rdar://problem/27574348.
2016-08-09 00:49:20 -07:00
Joe Groff
50af58b62a Merge pull request #4030 from jckarter/27671131
Runtime: Fix undersized allocation for out-of-line optional cast result.
2016-08-05 09:44:11 -07:00
John McCall
a6e1e87585 Add implicit conversions and casts from T:Hashable <-> AnyHashable.
rdar://27615802
2016-08-04 23:13:27 -07:00
Joe Groff
2508c46051 Runtime: Fix undersized allocation for out-of-line optional cast result.
We accounted for the size difference between T and T? in the inline case, but not the out-of-line case. rdar://problem/27671131
2016-08-04 16:59:51 -07:00
Joe Groff
b8c66b218a Merge pull request #4020 from jckarter/metatype-universal-bridging
Runtime: Handle universal bridging of class metatypes.
2016-08-04 15:18:29 -07:00
Joe Groff
c3fed97431 Runtime: Handle Protocol objects through universal bridging too. 2016-08-04 15:03:14 -07:00
Joe Groff
f6ea4fe766 Runtime: Handle universal bridging of class metatypes.
Class metatypes bridge to their `Class` objects in Objective-C.
2016-08-04 14:17:11 -07:00
Doug Gregor
360ed82872 Reinstate cod epart of "Eliminate race in swift_bridgeErrorToNSError.""
This partially reverts commit
47f01ee98d. In other words, I'm bring
back the changes to the Swift runtime that should eliminate the data
race in swift_bridgeErrorToNSError, but leaving the actual test
disabled while we do more investigation.
2016-08-03 23:53:31 -07:00
Doug Gregor
47f01ee98d Revert "Eliminate race in swift_bridgeErrorToNSError."
This reverts commit e07e88706d. The
crash came back, so there's obviously more I need to investigate here:

  https://ci.swift.org/job/swift-PR-osx-smoke-test/881/testReport/junit/Swift(macosx-x86_64)/stdlib/ErrorProtocol_swift/
2016-08-03 23:48:33 -07:00
Doug Gregor
e83fb64917 [Runtime] Extract an embedded NSError when dynamic casting to an Error existential.
SILGen already attempts to extract an embedded NSError when
type-erasing to an Error existential; make the runtime do the same
thing dynamically.

Huge thanks to Joe Groff who noticed that I missed this path.
2016-08-03 23:22:30 -07:00
Michael Gottesman
a0fca3a8f0 Merge pull request #3965 from gottesmm/support_per_host_cmake_and_tsan_of_runtime_via_buildscript
Support per host cmake and tsan of runtime via buildscript
2016-08-03 21:48:24 -07:00
Michael Gottesman
06a70d3942 [cmake] Add cmake support for only applying tsan to the swift stdlib/runtime. 2016-08-03 17:53:57 -07:00
Doug Gregor
4b8b7bb878 [NSError bridging] Rename runtime entry points for _getErrorEmbeddedNSError.
This clarifies the 'Indirect' case. Thanks, Dmitri!
2016-08-03 15:59:01 -07:00
Doug Gregor
e07e88706d Eliminate race in swift_bridgeErrorToNSError.
Huge thanks to John for noting that 'consume' didn't provide the
guarantees we wanted, and to Michael G. for getting a TSan build up
and running to identify/verify this race.

It's possible that this is overlay strict, and that we only need to
look at the domain to ensure that the code and userInfo are
visible. However, TSan seems to prefix the form in this patch, so
we'll be more conservative for now.

Fixes rdar://problem/27541751.
2016-08-03 15:21:15 -07:00
Doug Gregor
d2195318d2 [NSError bridging] Use embedded NSError when erasing types to Error existentials.
Imported Cocoa error types are represented by structs wrapping an
NSError. The conversion from these structs to Error would end up
boxing the structs in _SwiftNativeNSError, losing identity and leading
to a wrapping loop.

Instead, extract the embedded NSError if there is one. In the Swift
runtime, do this as part of the dynamic cast to NSError, using a (new,
defaulted) requirement in the Error type so we can avoid an extra
runtime lookup of the protocol. In SILGEn, do this by looking for the
_BridgedStoredNSError protocol conformance when erasing to an Error
type. Fixes SR-1562 / rdar://problem/26370984.
2016-08-03 09:20:04 -07:00
Joe Groff
77df2865e9 Merge pull request #3829 from jckarter/cast-structural-type-from-boxed-anyobject
Runtime: Let structural types be cast out of boxed AnyObjects too.
2016-07-28 14:04:45 -07:00
Joe Groff
d206bb5aa1 Runtime: Let structural types be cast out of boxed AnyObjects too. 2016-07-28 12:52:46 -07:00
Dmitri Gribenko
561ac46679 stdlib: move a function from runtime to stubs
This function is not needed in the runtime.
2016-07-28 01:19:31 -07:00
Roman Levenstein
880be3be4f Remove unsafeAddress(of:)
rdar://problem/18589289
2016-07-26 19:57:26 -07:00
Dmitri Gribenko
53c424409d stdlib: add AnyHashable
Implements SE-0131 "Add AnyHashable to the standard library".
2016-07-26 03:10:52 -07:00
Joe Groff
b1fb1fa3ea Runtime: Handle bridging from ObjC objects to Any or boxed types. 2016-07-25 06:01:21 -07:00
Joe Groff
32b50c624d stdlib: Remove _isBridgedToObjectiveC from _ObjectiveCBridgeable.
All generic bridgeable types can bridge for all their instantiations now. Removing this ferrets out some now-unnecessary traps that check for unbridgeable parameter types.
2016-07-25 06:01:21 -07:00
practicalswift
a87d170b81 [gardening] Improve consistency in header formatting. 2016-07-24 21:36:25 +02:00