Commit Graph

122 Commits

Author SHA1 Message Date
Arnold Schwaighofer
958b9ad2f1 Tests for OpaqueBoxedExistentials initWithXXX value witnesses
rdar://31958059
2017-05-03 15:04:33 -07:00
Arnold Schwaighofer
3564733d1a Add more unit tests for the assignWith value witnesses of opaque existential boxes
rdar://31958059
2017-05-03 11:04:28 -07:00
Arnold Schwaighofer
bf91dc989f Add unit tests for the assignWith value witnesses of opaque existential boxes
More tests for the failure from rdar://31955457
2017-05-03 09:33:01 -07:00
Slava Pestov
58f2f35313 Runtime: Add superclass constraint to existential type metadata 2017-04-25 01:32:44 -07:00
Slava Pestov
3fa712d4d1 Revert "disabled flaky test" 2017-04-21 14:02:00 -07:00
Erik Eckstein
a99e380e8d disabled flaky test 2017-04-21 10:05:10 -07:00
Slava Pestov
a8360095c1 Try to fix race in getExistentialMetadata() unit tests 2017-04-19 00:52:14 -07:00
Slava Pestov
a5a40c7fc7 Runtime/IRGen: Preliminary plumbing for subclass existentials 2017-04-13 21:29:57 -07:00
Arnold Schwaighofer
39fa2f0228 Use the swift calling convention for swift functions
Use the generic type lowering algorithm described in
"docs/CallingConvention.rst#physical-lowering" to map from IRGen's explosion
type to the type expected by the ABI.

Change IRGen to use the swift calling convention (swiftcc) for native swift
functions.

Use the 'swiftself' attribute on self parameters and for closures contexts.

Use the 'swifterror' parameter for swift error parameters.

Change functions in the runtime that are called as native swift functions to use
the swift calling convention.

rdar://19978563
2017-02-14 12:17:57 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
practicalswift
38be6125e5 [gardening] C++ gardening: Terminate namespaces, fix argument names, ...
Changes:
* Terminate all namespaces with the correct closing comment.
* Make sure argument names in comments match the corresponding parameter name.
* Remove redundant get() calls on smart pointers.
* Prefer using "override" or "final" instead of "virtual". Remove "virtual" where appropriate.
2016-12-17 00:32:42 +01:00
Erik Eckstein
9f8b68ae11 Mangling: use macros instead of hard-coded swift symbol names.
This makes it easier to switch between the old and new mangling scheme.
2016-12-02 15:55:30 -08:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01: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
Greg Parker
5817ca7381 [stdlib] Fix assertion failures in SwiftRuntimeTests (aka unittests/runtime). 2016-08-31 18:55:31 -07:00
Doug Gregor
823c24b355 [SE-0112] Rename ErrorProtocol to Error.
This is bullet (5) of the proposed solution in SE-0112, and the last
major piece to be implemented.
2016-07-12 10:53:52 -07:00
John McCall
0ffb7278bc Only use metadata patterns for generic types; perform other
initialization in-place on demand.  Initialize parent metadata
references correctly on struct and enum metadata.

Also includes several minor improvements related to relative
pointers that I was using before deciding to simply switch the
parent reference to an absolute reference to get better access
patterns.

Includes a fix since the earlier commit to make enum metadata
writable if they have an unfilled payload size.  This didn't show
up on Darwin because "constant" is currently unenforced there in
global data containing relocations.

This patch requires an associated LLDB change which is being
submitted in parallel.
2016-03-24 15:10:31 -07:00
John McCall
abba7f0c8b Revert "Only use metadata patterns for generic types; perform other"
This reverts commit 41efb3d4d3.
LLDB has too many tendrils into our metadata.
2016-03-23 20:26:43 -07:00
John McCall
41efb3d4d3 Only use metadata patterns for generic types; perform other
initialization in-place on demand.  Initialize parent metadata
references correctly on struct and enum metadata.

Also includes several minor improvements related to relative
pointers that I was using before deciding to simply switch the
parent reference to an absolute reference to get better access
patterns.
2016-03-23 17:04:04 -07:00
Max Moiseev
488b464f10 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-25 12:21:56 -08:00
John McCall
fc261045a5 Optimize the number of accesses performed on ConcurrentMap
and MetadataCache and fix a re-entrancy bug in metadata
instantiation.

The re-entrancy bug is that we were holding the instantiation
lock of a metadata cache while instantiating metadata.  Doing
so prevents us from creating a different instantiation if
it's needed by the outer instantiation.  This is already
possible, but it's much more likely in a patch I'm working on
to only store the minimal metadata for generic parameters
in generic types.

The same bug could also show up as a deadlock between threads,
so a recursive lock would not be a good fix.  Instead, we add
a condition variable to the metadata cache.  When fetching
metadata, we look for a node in the concurrent map, eagerly
creating an empty one if none currently exists.  If lookup
finds an empty node, we wait on the condition variable for
the node to become populated.  If lookup succeeds in creating
an empty node, we instantiate the metadata, grab the lock,
populate the node, and notify the condition variable.

Safely creating an empty node without any metadata present
requires us to move the key data into the map entry.  That,
plus a few other invariant shifts, makes it sensible to
give the user of ConcurrentMap more control over the
allocation of map nodes and the layout of keys.  That, in
turn, allows us to change the contract so that keys can be
more complex than just a hash code.  Instead of incrementing
hash codes and re-performing the lookup, we just insist
that lookup keys be totally ordered.

For now, I've kept the uniform use of hash codes as a
component of the key for MetadataCaches.  However, hash
codes aren't really profitable for small keys, and we should
probably use direct comparisons instead.

We should also switch the safer metadata caches (i.e. the
ones that don't involve calling an arbitrary instantiation
function, like MetatypeMetadataCache) over to directly use
ConcurrentMap.

LLDB's requirement that we maintain a linked list of metadata
cache instantiations with a known layout means we can't yet
remove the CacheEntry's redundant copy of the generic
arguments.
2016-02-25 01:11:57 -08:00
Max Moiseev
3a3984877a Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-15 15:43:34 -08:00
Joe Groff
32872cb74a IRGen/Runtime: Relative-reference the nominal type descriptor and parent type from metadata.
Save a couple relocations per concrete value type, leaving only the value witness table as an absolute symbol.
2016-02-09 15:17:03 -08:00
Nadav Rotem
978e02412f [UnitTest] Add another unit tests to the data structures that contain the metadata.
I am adding this test mainly to check that the code that removed the sentinal
value and replaced it with a nullable pointer and some logic for initializing
the pointer works.
2016-02-08 22:57:51 -08:00
Slava Pestov
3624b1fc6b Runtime: Support for resiliently adding protocol requirements with default implementations
This is the first patch in a series that will allow new protocol
requirements to be added resiliently, with the runtime filling in
default implementations in witness tables.

First, this adds a new flag to the protocol descriptor indicating
that the protocol is resilient. In this case, there are two
additional fields, MinimumWitnessTableSizeInWords and
DefaultWitnessTableSizeInWords, followed by tail-allocated
default witnesses.

The swift_getGenericWitnessTable() entry point now fills in the
default witnesses from the protocol if the given witness table
template is smaller than the expected witness table size.

This also changes the layout of instantiated witness tables to move
the address point to the end of private data. Previously the private
data came after the requirements, but this meant that adding new
requirements would require sliding the private data at runtime and
accessing it indirectly. It is much simpler to access it from
negative offsets instead.

I updated IRGen to emit the new metadata, but currently all protocols
are flagged as not resilient, and default witnesses are not emitted;
this will come in a subsequent patch once some more plumbing is
in place.

To avoid generating GOT entries for references to protocols defined
in the current module, I had to add some hacks to the existing hack
for this. I'll hopefully clean this up in a principled manner later.
2016-02-04 17:34:55 -08:00
Max Moiseev
f51e708a8f Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-01-04 12:25:25 -08:00
practicalswift
1339b5403b Consistent use of header comment format.
Correct format:
//===--- Name of file - Description ----------------------------*- Lang -*-===//
2016-01-04 13:26:31 +01:00
practicalswift
022efe94c4 Reference file names (and not paths) in file headers. 2016-01-04 09:56:23 +01:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Dmitri Gribenko
feacbc4433 Rename ErrorType to ErrorProtocol 2015-12-09 17:12:19 -08:00
Slava Pestov
54dd7892e8 SIL: Emit native ivar destroyer and store it in class metadata
Swift SVN r32644
2015-10-13 00:27:57 +00:00
Joe Groff
42c71b7972 Don't mangle directness into type metadata symbols.
Anywhere we can't directly address type metadata in Swift, we've found we need a function call. Directness isn't useful here.

Swift SVN r32626
2015-10-12 17:22:40 +00:00
Jordan Rose
a1cd5b5d07 [test] Squash warnings in r30462.
No functionality change.

Swift SVN r30479
2015-07-22 00:14:03 +00:00
Joe Groff
6f47a4a51b Fix bug in runtime test for installCommonValueWitnesses_pod_indirect.
It didn't properly set "withInlineStorage(false)" on the test value witness table, causing it to pick direct-storage value witnesses that overflow a fixed-size buffer and crash on the ASan bot. Fix the test, and add a check for a canary that fails even without ASan.

Swift SVN r30462
2015-07-21 21:52:26 +00:00
Joe Groff
a1a00e7a24 Runtime: Fix incorrect implementation of pod_indirect_initializeBufferWithTakeOfBuffer.
Fixes rdar://problem/21375421.

Swift SVN r30073
2015-07-10 17:23:30 +00:00
Joe Groff
16c8a3b6c0 Runtime: Fix crash when first allocation for a metadata cache is page-sized or greater.
We incorrectly tested the uninitialized "next" pointer against MAP_FAILED, instead of the real result of mmap. Fixes rdar://problem/21659505.

Swift SVN r30030
2015-07-09 18:19:59 +00:00
Joe Groff
6d1a623b68 Runtime tests: Fix compile error for non-ObjC build.
Swift SVN r27417
2015-04-17 05:57:35 +00:00
Joe Groff
1b2fcd1852 IRGen/Runtime: AnyObject never has a witness table, even if it isn't @objc.
@objc protocols aren't supported with an ObjC runtime, but we still want values of AnyObject type to be word-sized. Handle this by turning the binary "needsWitnessTable" condition into a "dispatch strategy" enum, so we can recognize the condition "has no methods, so neither swift nor objc dispatch" as distinct from either swift or ObjC protocol representations. Assign this dispatch strategy when we lower AnyObject. Should be NFC for the ObjC-enabled build.

(It would also be beneficial for the ObjC-runtime-enabled version of Swift if AnyObject weren't an @objc protocol; that would mean we could give it a canonical protocol descriptor in the standard library, among other things. There are fairly deep assumptions in Sema that AnyObject is @objc, though, and it's not worth disturbing those assumptions right now.)

Reapplying with updates to the runtime unit tests.

Swift SVN r27341
2015-04-16 00:24:51 +00:00
Joe Groff
feb5371e27 Runtime: Use ObjC pointer value witness for ErrorType.
Swift SVN r26497
2015-03-24 19:42:08 +00:00
Joe Groff
ef8cc448d0 Runtime: Instantiate existential metadata with special protocol set.
If an existential type for a special protocol (not a composition) is instantiated, carry the special protocol identifier from that protocol to the existential, allowing us to easily recognize existentials with unique runtime characteristics.

Swift SVN r26436
2015-03-23 17:06:22 +00:00
Nadav Rotem
d214e367d0 Remove the custom memory allocator. It was not effective in accelerating the metadata lookups and Greg and Dave have suggested other solutions for accelerating this call.
Swift SVN r24869
2015-01-31 00:44:17 +00:00
Nadav Rotem
bdadc015b7 Add a generic parameter to control the number of threads. NFC.
Swift SVN r24868
2015-01-31 00:44:16 +00:00
Nadav Rotem
278bc16f43 Rename the method. NFC.
Swift SVN r24866
2015-01-31 00:44:15 +00:00
Nadav Rotem
26261cd1fe Allow the allocator to free memory.
Swift SVN r24865
2015-01-31 00:44:14 +00:00
Nadav Rotem
2236ff8153 Use std::distance and add the missing typedefs needed for stl
Swift SVN r24863
2015-01-31 00:44:10 +00:00
Nadav Rotem
0b9a79b38b Add a concurrent bump-ptr memory allocator.
Swift SVN r24702
2015-01-24 01:08:04 +00:00
Nadav Rotem
1e02da9465 Add a concurrent memory bank
Swift SVN r24701
2015-01-24 01:08:04 +00:00
Nadav Rotem
1d3a373cbf Add a unit test for the concurrent list.
Swift SVN r24700
2015-01-24 01:08:03 +00:00
Graham Batty
913a76526d Use pthreads in the metadata runtime unit test.
Swift SVN r23381
2014-11-17 21:23:18 +00:00
Graham Batty
b46474ff61 Revert "Use pthreads in the metadata runtime unit test."
This reverts commit r23369.

Swift SVN r23372
2014-11-17 17:54:30 +00:00