Commit Graph

777 Commits

Author SHA1 Message Date
Slava Pestov
4e4d281aa7 stdlib: Rework swift_typeName() to use _swift_buildDemanglingForMetadata()
Previously we had two separate mechanisms to turn a metatype
into a string. The swift_typeName() function was used to print
the metatype in a human-readable fashion, whereas the
_swift_buildDemanglingForMetadata() was used when naming
generated generic Objective-C classes.

Unify them, since what swift_typeName() does is redundant;
instead of going directly from the metatype to a human-readable
string, we can get the mangling, and print that using the
demangler.

This fixes some issues with unnecessary parenthesis when
printing function types, and also allows Objective-C classes
to be instantiated with nested generic types as parameters.
2016-11-18 00:39:14 -08:00
Joe Groff
e9ce682a75 Merge pull request #5846 from jckarter/refactor-section-registration
Runtime: Refactor platform-dependent image inspection code.
2016-11-17 18:33:22 -08:00
Joe Groff
87b27c6451 Runtime: Refactor platform-dependent image inspection code.
The code we use to interface with the platform dynamic linker is turning into a rat's nest of conditionals that's hard to maintain and extend. Since ELF, Mach-O, and PE platforms have pretty fundamentally different dynamic linker interfaces and capabilities, it makes sense to factor that code into a separate file per-platform, instead of trying to conditionalize the logic in-line. This patch factors out a much simpler portable interface for lazily kicking off the protocol conformance and type metadata lookup caches, and factors the guts out into separate MachO, ELF, and Win32 backends. This should also be a much cleaner interface to interface static binary behavior into, assisting #5349.
2016-11-17 16:50:04 -08:00
Slava Pestov
7c1adfe31d Runtime: Use metadata accessor functions in Reflection.mm and make sure they're public
Correct behavior with resilience requires calling accessors instead
of using the metadata symbols directly.

For some reason this file gets linked in with SwiftRuntimeTests too,
so make the types @_versioned in the stdlib.

Fixes <rdar://problem/29213794>.
2016-11-14 16:25:23 -08:00
practicalswift
f44686d825 [gardening] Fix trailing whitespace in *.cfg.in, *.html, *.mm and *.sil files 2016-10-29 14:06:43 +02:00
Joe Groff
2b4cba8499 Runtime: Call Set/Dictionary casting hooks in the stdlib with the correct calling convention.
We neglected to pass down the Hashable witness table parameters, leading to Heisenbugs because we would call into invalid witness pointers occasionally when loading the Hashable conformance from corrupted metadata. Fixes rdar://problem/28022201.
2016-10-12 12:16:40 -07:00
swift-ci
a989e998e5 Merge pull request #4949 from Concoction/master 2016-10-07 22:03:23 -07:00
Slava Pestov
53b3a69a9a Runtime: Fix dynamic casts to support resilient protocols
If a protocol witness table requires instantiation, the runtime
needs to call the witness table accessor when looking up the
conformance in swift_conformsToProtocol().

We had a bit of code for this already, but it wasn't fully
hooked up. Change IRGen to emit a reference to the witness table
accessor rather than the witness table itself if the witness
table needs instantiation, and add support to the runtime for
calling the accessor.
2016-09-30 18:28:11 -07:00
Michael Gottesman
581f1b0141 Merge pull request #5003 from modocache/stdlib-runtime-cmake-target-sdks
[runtime] Update CMake to use TARGET_SDKS (NFC)
2016-09-29 20:08:27 -07:00
Arnold Schwaighofer
d3ef6f70f2 Runtime: Make swift_getObjCClassMetadata resilient against weakly linked classes
rdar://28203571
2016-09-28 14:45:39 -07:00
Brian Gesiak
341d022ba7 [runtime] Update CMake to use TARGET_SDKS (NFC)
The `add_swift_library` CMake function takes an optional `TARGET_SDKS`
parameter. When used, only CMake targets for the specified SDKs are added.

Refactor `stdlib/public/runtime` to use this parameter. This also eliminates
logic that determines additional flags or source files to include based on
`SWIFT_HOST_VARIANT`, which makes it easier for hosts to add targets for
different platforms.
2016-09-24 22:40:57 -04:00
John Holdsworth
a430c40303 Bug in Windows swift_vasprintf() 2016-09-23 06:50:22 +01:00
Doug Gregor
f1a4dd7631 Merge pull request #4479 from gmilos/SR-755-linux-fatal-stacktrace-symbolication
[SR-755] Tool for re-symbolicating fatal stacktraces on Linux.
2016-09-21 10:13:21 -07:00
Doug Gregor
2942b850ad Merge pull request #4898 from DougGregor/tuple-casting
Runtime/standard library: fix tuple printing, reflection, and casting
2016-09-21 10:09:03 -07:00
Doug Gregor
c9ebcc592e [Runtime] Generalize dynamic casting between tuple types.
This allows dynamic casting to succeed between tuple types with
different element types, converting each element in turn. Fixes
rdar://problem/19892202.
2016-09-21 09:00:23 -07:00
Doug Gregor
fcacd089d6 [Mirrors] Use tuple labels when forming a mirror for a tuple type.
Fixes rdar://problem/22191852.
2016-09-21 09:00:22 -07:00
swift-ci
81ee414f7a Merge pull request #4894 from DougGregor/tuple-casting 2016-09-20 21:04:34 -07:00
Doug Gregor
87908c8a1b [Runtime] Handle tuple/tuple dynamic casts that add/remove labels.
Introduce narrow support for tuple/tuple dynamic casts that merely add
or remove labels, but require the element types to match exactly. This
gets us back to allowing the same correct dynamic casts as in Swift
3.0, when labels were completely ignored.
2016-09-20 17:05:07 -07:00
Joe Groff
2bfe9214ed Merge pull request #4869 from jckarter/optional-bridging
(take 2) SR-0140: Bridge Optionals to nonnull ObjC objects by bridging their payload, or using a sentinel.
2016-09-20 14:35:13 -07:00
Doug Gregor
1a8189814a [Runtime] Include tuple labels when printing the runtime name of a type.
When we started recording labels within the metadata for a tuple type,
we failed to print those labels when rendering the type name from
metadata.
2016-09-20 13:47:34 -07:00
Joe Groff
1a52e3f2c2 SR-0140: Bridge Optionals to nonnull ObjC objects by bridging their payload, or using a sentinel.
id-as-Any lets you pass Optional to an ObjC API that takes `nonnull id`, and also lets you bridge containers of `Optional` to `NSArray` etc. When this occurs, we can unwrap the value and bridge it so that inhabited optionals still pass into ObjC in the expected way, but we need something to represent `none` other than the `nil` pointer. Cocoa provides `NSNull` as the canonical "null for containers" object, which is the least bad of many possible answers. If we happen to have the rare nested optional `T??`, there is no precedented analog for these in Cocoa, so just generate a unique sentinel object to preserve the `nil`-ness depth so we at least don't lose information round-tripping across the ObjC-Swift bridge.

Making Optional conform to _ObjectiveCBridgeable is more or less enough to make this all work, though there are a few additional edge case things that need to be fixed up. We don't want to accept `AnyObject??` as an @objc-compatible type, so special-case Optional in `getForeignRepresentable`.

Implements SR-0140 (rdar://problem/27905315).
2016-09-20 13:04:09 -07:00
Grzegorz Miłoś
f96b655a89 Merge remote-tracking branch 'upstream/master' into SR-755-linux-fatal-stacktrace-symbolication 2016-09-20 18:24:04 +01:00
Maxim Moiseev
46b860b5f8 [stdlib] returning false in case where comparison cannot succeed in SwiftValue (#4813) 2016-09-20 10:01:00 -07:00
Erik Eckstein
bd0d2bfed4 Remove the LLVM stack promotion pass and related SIL optimization logic.
It's not needed anymore because array buffers are now allocated with alloc_ref instead of a swift_bufferAllocate runtime call.
2016-09-16 11:02:19 -07:00
practicalswift
b19481f887 [gardening] Fix 67 recently introduced typos 2016-09-16 11:16:07 +02:00
Greg Parker
cd9a8afd5d Revert "SR-0140: Bridge Optionals to nonnull ObjC objects by bridging their payload, or using a sentinel." (#4820) 2016-09-15 18:18:07 -07:00
Joe Groff
3441fe8ca4 Merge pull request #4782 from jckarter/bridging-enhancements
SR-0140: Bridge Optionals to nonnull ObjC objects by bridging their payload, or using a sentinel.
2016-09-15 13:06:01 -07:00
swift-ci
40483d470a Merge pull request #4767 from practicalswift/inconsistent-headers 2016-09-15 12:14:44 -07:00
Grzegorz Miłoś
74ff4dad81 Merge remote-tracking branch 'upstream/master' into SR-755-linux-fatal-stacktrace-symbolication 2016-09-15 14:17:15 +01:00
Dmitri Gribenko
fbb3cf35a5 Revert "New SIL instructions to support tail-allocated arrays in SIL." 2016-09-15 00:25:25 -07:00
Joe Groff
cfa9cd9a08 SR-0140: Bridge Optionals to nonnull ObjC objects by bridging their payload, or using a sentinel.
id-as-Any lets you pass Optional to an ObjC API that takes `nonnull id`, and also lets you bridge containers of `Optional` to `NSArray` etc. When this occurs, we can unwrap the value and bridge it so that inhabited optionals still pass into ObjC in the expected way, but we need something to represent `none` other than the `nil` pointer. Cocoa provides `NSNull` as the canonical "null for containers" object, which is the least bad of many possible answers. If we happen to have the rare nested optional `T??`, there is no precedented analog for these in Cocoa, so just generate a unique sentinel object to preserve the `nil`-ness depth so we at least don't lose information round-tripping across the ObjC-Swift bridge.

Making Optional conform to _ObjectiveCBridgeable is more or less enough to make this all work, though there are a few additional edge case things that need to be fixed up. We don't want to accept `AnyObject??` as an @objc-compatible type, so special-case Optional in `getForeignRepresentable`.

Implements SR-0140 (rdar://problem/27905315).
2016-09-14 15:50:13 -07:00
Erik Eckstein
6ae818c9d1 Remove the LLVM stack promotion pass and related SIL optimization logic.
It's not needed anymore because array buffers are now allocated with alloc_ref instead of a swift_bufferAllocate runtime call.
2016-09-14 14:54:18 -07:00
Erik Eckstein
c710b04dbf IRGen: Let the stride of a type be at least one, even for zero-sized types like the empty tuple.
This affects the computed stride for fixed-sized types in IRGen as well as the stored stride in value witness tables.
The reason is to let comparisons and difference operations work for pointers to zero-sized types.
(Currently this is achieved by using Builtin.strideof_nonzero in MemoryLayout.stride, but this requires a std::max(1, stride) operation after loading the stride)
2016-09-14 13:24:19 -07:00
practicalswift
9185c052a9 [gardening] Fix inconsistent headers 2016-09-14 20:48:28 +02:00
Grzegorz Miłoś
201c19dc98 Review comments, round 3. 2016-09-07 12:14:48 +01:00
Grzegorz Miłoś
dc3369dffe Review comments. Mostly python improvements in symbolicate-linux-fatal(.py). 2016-09-07 12:14:48 +01:00
Grzegorz Miłoś
f068b1eb33 [SR-755] Tool for re-symbolicating fatal stacktraces on Linux. 2016-09-07 12:14:48 +01:00
Ryan Mansfield
75084a7868 Fix build error when SWIFT_DEBUG_RUNTIME is defined. 2016-09-04 14:59:51 -04:00
Doug Gregor
73e2143213 [SE-0112] Provide default implementations for CustomNSError requirements.
Provide default implementations for all of the CustomNSError requirements:
  * errorDomain: default to the name of the enum type
  * errorCode: default to the same thing "_code" gets, e.g., the enum tag or
    raw value
  * errorUserInfo: default to empty

This makes it significantly easier to customize just one aspect of the
NSError view of an error type, e.g., just the user-info dictionary,
without having to write boilerplate for the others. This was actually
part of SE-0112, but I missed it in the original implementation and we
thought it was an amendment.

Fixes rdar://problem/23511842.
2016-09-02 10:33:15 -07:00
John McCall
4b22a29a7c Change MetadataCache to just use malloc/free.
IIRC we never had any evidence that the performance impact of a
separate allocator here was actually measurable, and it does come
at a significant fragmentation cost because every single cache
allocates at least a page of memory.  Sharing that with the system
allocator makes more sense, even if these allocations are typically
permanent.

This also means that standard memory-debugging tools will actually
find problems with out-of-bounds accesses to metadata.
2016-09-01 14:19:14 -07:00
John McCall
28bbc54bb2 Switch the generic heap box metadata cache over to use ConcurrentMap directly. 2016-09-01 14:09:44 -07:00
John McCall
81b27c210b Permit ConcurrentMap to be templated over an allocator and move
MetadataCache's allocator into it.

The major functional change here is that MetadataCache will now use
the slab allocator for tree nodes, but I also switched the Hashable
conformances cache to use ConcurrentMap directly instead of a
Lazy<ConcurrentMap<>>.
2016-09-01 14:09:43 -07:00
swift-ci
65f6d9dda5 Merge pull request #4582 from rjmccall/metadata-caching-redux 2016-08-31 19:39:30 -07:00
John McCall
17d72f558b 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-31 18:53:54 -07:00
John McCall
99c52e89ad Remove the linked list through metadata caches, since LLDB is
no longer using it even in fallback code.
2016-08-31 18:53:54 -07:00
John McCall
e958dd0663 Type metadata for a class isn't necessarily ClassMetadata; it could
be an ObjC class wrapper.

Fixes a longstanding bug that was exposed by my metadata cache improvements;
previously it was hidden due to a chain of coincidences around the
allocation of ObjCClassWrapper metadata.
2016-08-31 18:53:54 -07:00
Dmitri Gribenko
e9d451ba55 Merge pull request #4572 from apple/runtime-better-name-for-hashable-protocol-descriptor
runtime: rename _TMps8Hashable to HashableProtocolDescriptor
2016-08-31 14:28:06 -07:00
swift-ci
ab59308c54 Merge pull request #4535 from bryongloden/patch-1 2016-08-31 12:08:05 -07:00
Dmitri Gribenko
dfb4f56e55 runtime: rename _TMps8Hashable to HashableProtocolDescriptor 2016-08-31 09:53:39 -07:00
Greg Parker
e5a6b2240e Merge pull request #4548 from gparker42/fix-isa-warning
Fix shadow warnings of a local variable versus an instance variable.
2016-08-30 00:38:36 -07:00