Commit Graph

13406 Commits

Author SHA1 Message Date
nate-chandler
1430c04e68 Merge pull request #28610 from nate-chandler/generic-metadata-prespecialization
Generic metadata prespecialization, part 1
2020-01-10 15:08:05 -08:00
Michael Ilseman
70e6db81f1 Revert "[stdlib] Add withContiguousStorageIfAvailable to SubString.UTF8View" 2020-01-10 13:28:03 -08:00
swift-ci
4acddb3ab0 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-10 11:24:26 -08:00
eeckstein
3f71bb864c Merge pull request #29121 from eeckstein/fix-array-remove
stdlib: annotate Array's remove functions with semantic attributes.
2020-01-10 20:23:21 +01:00
Michael Ilseman
6209c97bf7 Merge pull request #29094 from Lukasa/cb-substring-fast-access
[stdlib] Add withContiguousStorageIfAvailable to SubString.UTF8View
2020-01-10 11:16:46 -08:00
Erik Eckstein
dfc5b06819 stdlib: annotate Array's remove functions with semantic attributes.
All mutating Array functions must be annotated with semantics, because otherwise some high level optimizations get confused.
The semantic attributes prevent inlining those functions in high-level-sil.
This is need so that the optimizer sees that the Array is taken as inout and can reason that it's modified.

This restriction is not needed anymore when we’ll have COW representation in SIL.

rdar://problem/58478089
2020-01-10 17:09:47 +01:00
Arnold Schwaighofer
0c99cd9734 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-10 08:00:41 -08:00
Cory Benfield
68f0816daa [stdlib] Add withContiguousStorageIfAvailable to SubString.UTF8View
Due to an oversight it seems that we never added a
withContigousStorageIfAvailable implementation to SubString.UTF8View,
which meant that if you sliced a String you lost the ability to get fast
access to the backing storage. There's no good reason for this
functionality to be missing, so this patch adds it in by delegating to
the Slice implementation.

Resolves SR-11999.
2020-01-10 09:10:09 +00:00
Nate Chandler
edab098067 [runtime] Metadata can be flagged static.
Added a new flag to the GenericMetadataPatternFlags flagset for whether
the metadata has a set of flags at its tail.  When that flag is set,
there will be an extra uint64_t flagset at the end of the metadata.  For
struct metadata, the type of that flagset will be
StructMetadataTrailingFlags.  The first flag in that trailing flagset
indicates whether the metadata was statically specialized.  The second
flag in that trailing flagset indicates whether the metadata is
statically canonical.

When verifying the metadata cache, a check is done for whether the
metadata was statically specialized and whether it was known to be
canonical statically.  If so, verification is skipped.  Skipping it is
necessary because the known-canonical statically specialized metadata
will not be in the cache.  In that case, the canonical statically
specialized metadata will be returned from the metadata accessor and
never be cached.
2020-01-09 17:25:31 -08:00
Erik Eckstein
60a0718922 stdlib: simplify Array/ContiguousArray's withUnsafeMutableBufferPointer and withUnsafeMutableBufferPointer
Again, to reduce code size
2020-01-09 16:17:38 +01:00
Erik Eckstein
bda8af0958 stdlib: simplify Array/ContiguousArray's append(contentsOf:)
Instead of calling ArrayBuffer's _arrayAppendSequence, inline the code. This saves some code size.
2020-01-09 16:17:38 +01:00
Erik Eckstein
88a9ebb9f8 stdlib: Don't request additional capacity in Array/ContiguousArray's remove.
Just copy the buffer if it's not unique.
This also implies that if there is a copy-on-write in remove, "shrink" the capacity of the new buffer to the required amount of elements (instead of copying the capacity of the original buffer).
2020-01-09 16:17:38 +01:00
Erik Eckstein
ea3b6a02af stdlib: rewrite Array/ContiguousArray logic for reserving capacity and creating a new buffer.
Share more code and avoid the large generic functions of ArrayProtocol.
The result is a significant code size win.
2020-01-09 16:17:38 +01:00
Karoy Lorentey
cdd99564e3 [Foundation] Fix potential backdeployment regression in append
Data.append now calls Data.count’s setter, which used to have a bug in previously shipped versions of the Foundation overlay (#28918).

To prevent working code from breaking when recompiled with the current version, avoid calling Data.count’s setter directly. Instead, extract its implementation (conveniently already packaged into a nested function) into a named method, marking it @_alwaysEmitIntoClient.
2020-01-08 18:39:40 -08:00
Karoy Lorentey
5c2095e93d Merge pull request #28919 from lorentey/fix-Data.count-setter
[Foundation] Fix Data.count’s setter
2020-01-08 17:48:58 -08:00
swift_jenkins
9ce6844ff8 Merge remote-tracking branch 'origin/master' into master-next 2020-01-08 10:38:32 -08:00
Mike Ash
222b9deeab Merge pull request #28753 from mikeash/lazy-objc-class-names
[Runtime] When the ObjC runtime supports lazy class names, lazily create the ObjC names for generic classes.
2020-01-08 13:27:20 -05:00
Arnold Schwaighofer
43c24be5cd Merge remote-tracking branch 'upstream/master' into master-next 2020-01-08 06:41:34 -08:00
Saleem Abdulrasool
4e797662e8 swiftMSVCRT: build with -Xcc -D_USE_MATH_DEFINES
This enables the use of the math defines when building tgmath.swift.
Although not used in the normal branch, this define is necessary to
build the swiftMSVCRT module for TensorFlow which uses the math
constants.
2020-01-07 14:31:55 -08:00
Xi Ge
7a1ac6b5a4 cmake: add SDK library search path for overlays unavailable in the source
When force linking auto-linked libraries, an overlay will fail to link if the dependence
libraries are missing from the source. This change provides linker flags
to search overlay libraries from the SDK.
2020-01-06 21:17:02 -08:00
swift_jenkins
3ad5fa6c7f Merge remote-tracking branch 'origin/master' into master-next 2020-01-06 10:38:53 -08:00
tbkka
93d07c6c30 _isOptional(type(of: value)) Does Not Do What You Think It Does (#28994)
In particular, if value is `Any` in a generic context, then `type(of: value)` is
`Any.Protocol` which is never considered optional.  As a result, the first
clause here was never actually being used for `print()` or other similar paths.
(Curiously, it _was_ used for string interpolation.)

This changes how we test for an optional type so that the first clause is consistently used for all optionals, even when they are wrapped in `Any` containers.

Fortunately? `print()` was producing the right results for
optionals because of a dynamic cast bug that failed to
unwrap optionals in these same contexts. <sigh>
2020-01-06 10:29:36 -08:00
swift_jenkins
ebbfaa4614 Merge remote-tracking branch 'origin/master' into master-next 2020-01-06 09:58:57 -08:00
tbkka
246d52defe Simplify the floating-point parsing initializers (#28992)
The original version scanned the entire input string for whitespace and
non-ASCII characters.  Both are unnecessary: the C routines we're building on
already stop at non-ASCII characters or non-leading whitespace.  So we need only
check the first character for whitespace and verify that all characters are
consumed.

This both improves performance and reduces the amount of code that gets inlined into consumers.
2020-01-06 09:52:21 -08:00
swift_jenkins
7e3149ac8f Merge remote-tracking branch 'origin/master' into master-next 2020-01-06 09:39:07 -08:00
Karoy Lorentey
b7e08accb1 [stdlib] Slice: customize withContiguous[Mutable]StorageIfAvailable (#28883)
* [stdlib] Slice: customize withContiguous[Mutable]StorageIfAvailable

We can easily make an UnsafeBufferPointer that slices another UnsafeBufferPointer, so let’s allow Slice to vend a slice of the base collection’s contiguous storage, if it provides access to one.

We need to do some index distance calculations to implement this, but those will be constant-time in the usual case where the base collection is a RAC.

https://bugs.swift.org/browse/SR-11957
rdar://58090587

* [test] UnsafeBufferPointer: fix some warnings

* [stdlib] Slice: don’t calculate index distances unless the base provides contiguous mutable storage
2020-01-06 12:32:30 -05:00
kelvin13
ed2552a694 fix merge conflict and update caseless stdlib enums to use synthesized Comparable 2020-01-02 18:40:50 -06:00
swift_jenkins
81c0ed297a Merge remote-tracking branch 'origin/master' into master-next 2020-01-02 10:19:08 -08:00
Saleem Abdulrasool
beafad9651 SwiftShims: unify assertion paths (NFC)
Use the C++ spelling for the static assertions.  This is a C11
extension, but GCC and MSVC both object to the reserved spelling
(`_Static_assert`).  Use the compatibility spelling of `static_assert`
on all targets instead.
2019-12-27 10:17:43 -08:00
Karoy Lorentey
a6d7ee5eba Merge branch 'fix-Data.count-setter' into foundation-no-inlinable-shim-calls 2019-12-20 23:48:34 -08:00
Karoy Lorentey
1a9f7afdec [Foundation] Fix Data.count’s setter
Data provides a settable `count` property. Its expected behavior is undocumented, but based on the implementation, it is intended to zero-extend (or truncate) the collection to the specified length.

This does not work correctly if we start with an empty Data and we try to increase the count by a small integer:

```
import Foundation

var d = Data()
d.count = 2
print(d.count) // ⟹ 0 ⁉️

d.count = 100
print(d.count) // ⟹ 100 ✓
```

It looks like this bug was introduced with the Data overhaul that shipped in Swift 5.

(This issue was uncovered by https://github.com/apple/swift/pull/28918.)

rdar://58134026
2019-12-20 23:35:05 -08:00
Karoy Lorentey
c9058f0946 [Foundation] Switch to private imports of Foundation shims 2019-12-20 20:50:18 -08:00
Karoy Lorentey
15e865f0b5 [Foundation] Remove inlinable shim calls
We want to enable overlays to import their shims as @_implementationOnly, so that the shims disappear from the public interface.

However, this isn’t possible when a shim is called from an @inlinable func, because then the existence (and definition) of the shim needs to be available to all callers of it.

Unfortunately Foundation’s Data has three instances where it calls  _SwiftFoundationOverlayShims._withStackOrHeapBuffer within @inlinable code:

- Data.init<S: Sequence>(_: S)
- Data.append<S: Sequence>(contentsOf: S)
- Data.replaceSubrange<C: Collection>(_: Range<Int>, with: C)

Rewrite the first two to write sequence contents directly into the target Data instance (saving a memcpy and possibly a memory allocation).

In replaceSubrange, add fast paths for contiguous collection cases, falling back to a Swift version of _withStackOrHeapBuffer with a 32-byte inline buffer.

The expectation is that this will be an overall speedup in most cases, with the possible exception of replaceSubrange invocations with a large non-contiguous collection.

rdar://58132561
2019-12-20 20:45:02 -08:00
Mike Ash
f32af9b047 [Runtime] Adjust lazy name API to a hook-based call that can have multiple hooks. Use the API from the headers if present.
rdar://problem/57674583
2019-12-18 17:15:51 -05:00
swift_jenkins
a812971ee5 Merge remote-tracking branch 'origin/master' into master-next 2019-12-17 15:00:16 -08:00
tbkka
2b5ada11cb Correctly calculate extra inhabitants for no-payload enums (#28830)
In particular, this fixes the size calculation for nested enums,
specifically enums within Optionals.  Without this, the
reflection library computes `v` below as requiring two bytes
instead of one.

```
enum E {
case a
case b
}

let v = Optional<E>
```

This also adds a number of test cases for enums alone and
wrapped in optionals, including:
* Zero-case enums are allocated zero size and have zero extra inhabitants
* Zero-case enums in optionals also get zero size
* One-case no-payload enums are allocated zero size and have zero extra inhabitants
* One-case no-payload enums in optionals get one byte allocated and have zero extra inhabitants
* 254-case enums have only two extra inhabitants, so putting them in thrice-nested optionals requires an extra byte
* Various cases where each nested optional gets an extra byte

Resolves rdar://31154770
2019-12-17 14:52:35 -08:00
Mike Ash
fbcef9a9ec [Runtime] Use the new NonMetaClass ObjC field to have generic metaclasses point to their classes. Remove metaclass handling from the lazy class namer since it's not necessary.
rdar://problem/57674583
2019-12-17 16:41:47 -05:00
swift_jenkins
dcc7626bd9 Merge remote-tracking branch 'origin/master' into master-next 2019-12-17 09:59:53 -08:00
tbkka
fdb1926421 [SR-5289] Teach Mirror how to handle unowned/unmanaged references (#28823)
SR-5289: Teach Mirror how to inspect weak, unowned, and unmanaged refs

Correctly reflect weak, unowned, and unmanaged references
to both Swift and Obj-C types (including existential references to
such types) that occur in both Swift class objects and in Swift
structs.

This includes the specific reported case (unowned reference to an
Obj-C object) and several related ones.

Related changes in this PR:

* Tweak internal bitmap used for tracking ownership modifiers
  to reject unsupported combinations.

* Move FieldType into ReflectionMirror.mm
  FieldType is really just an internal implementation detail
	of this one source file, so it does not belong in an ABI header.

* Use TypeReferenceOwnership directly to track field ownership
  This avoids bitwise copying of properties and localizes some
	of the knowledge about reference ownership

* Generate a top-level "copyFieldContents" from ReferenceStorage.def
  Adding new ownership types to ReferenceStorage.def will now
	automatically produce calls to `copy*FieldContents` - failure
	to provide a suitable implementation will fail the build.

* Add `deallocateBoxForExistentialIn` to match `allocateBoxForExistentialIn`

Caveat:  The unit tests are not as strict as I'd like.  Attempting to make them
so ran afoul of otherwise-unrelated bugs in dynamic casting.
2019-12-17 09:42:52 -08:00
swift_jenkins
d07ae02c6c Merge remote-tracking branch 'origin/master' into master-next 2019-12-16 21:19:58 -08:00
Doug Gregor
a8f2f95c4e Merge pull request #28804 from DougGregor/error-cast-overrelease
[Dynamic casting] Fix overrelease on unsuccessful cast to an Error type.
2019-12-16 21:09:57 -08:00
swift_jenkins
130bff9a5c Merge remote-tracking branch 'origin/master' into master-next 2019-12-16 18:00:02 -08:00
David Smith
a46ea4bd8e Merge pull request #28817 from Catfish-Man/ducking-types
Use -[NSSet getObjects:] instead of -[NSSet getObjects:count:] to maintain compatibility with existing code passing NSArrays into this function
2019-12-16 17:53:19 -08:00
swift_jenkins
c9d8f24ebf Merge remote-tracking branch 'origin/master' into master-next 2019-12-16 17:40:20 -08:00
Mishal Shah
ca693eeca3 Revert "SR-5289: Teach Mirror how to handle unowned/unmanaged references (#28368)"
This reverts commit 9c638ae60d.
2019-12-16 17:24:30 -08:00
David Smith
257c93a183 Use -[NSSet getObjects:] instead of -[NSSet getObjects:count:] to maintain compatibility with existing code passing NSArrays into this function 2019-12-16 15:43:16 -08:00
swift_jenkins
1aac8a4d89 Merge remote-tracking branch 'origin/master' into master-next 2019-12-16 12:40:01 -08:00
tbkka
9c638ae60d SR-5289: Teach Mirror how to handle unowned/unmanaged references (#28368)
* SR-5289: Support reflecting weak, unowned, and unmanaged refs

This refactors how we handle reference ownership
when reflecting fields of struct and class objects.
There are now explicit paths for each type of reference
and some simple exhaustiveness checks to fail the build
if a new reference type is added in the future without
updating this logic.
2019-12-16 12:26:22 -08:00
Doug Gregor
23cc0790a7 [Dynamic casting] Fix overrelease on unsuccessful cast to an Error type.
Fixes SR-9207 / rdar://problem/45961622, SR-10478 / rdar://problem/49906841,
and rdar://problem/50665156.
2019-12-16 08:46:33 -08:00
swift_jenkins
ec584fd607 Merge remote-tracking branch 'origin/master' into master-next 2019-12-14 17:20:50 -08:00