Commit Graph

10155 Commits

Author SHA1 Message Date
Valeriy Van
9821976c69 Removes redundant buffer zeroing in CGColorSpace.swift by using `init(unsafeUninitializedCapacity:initializingWith:) (#30134)
* Removes redundant buffer zeroing

* Fix compile error
2020-04-13 19:49:17 -07:00
Saleem Abdulrasool
d0048ccc61 stdlib: android does not support FP80
Correct the maximal floating point width.  Although technically, Android
could support FP128 on AArch64, Swift does not currently support FP128.
For now, ensure that we use FP64 on Android.
2020-04-13 12:23:26 -07:00
Saleem Abdulrasool
f069371083 Merge pull request #30988 from compnerd/constantly-improving
WinSDK: add some constants for the SDK overlay
2020-04-13 08:53:08 -07:00
Saleem Abdulrasool
fa4b7ead4e Merge pull request #30990 from compnerd/shellcore
Platform: add ShellCore to WinSDK modulemap
2020-04-13 08:52:23 -07:00
Saleem Abdulrasool
b9e3109fe8 Platform: add ShellCore to WinSDK modulemap
Add the ShellCore module to the Windows SDK modulemap.
2020-04-12 21:37:41 -07:00
Saleem Abdulrasool
24617651e5 WinSDK: add some constants for the SDK overlay
Unfortunately, the types are not imported through the clang importer.
Add them to the overlay for use in applications.
2020-04-12 16:08:47 -07:00
Robert Widmann
763875aea7 Merge pull request #15108 from darquro/fast-path-ad-hoc-printing-of-strings
[stdlib][SR-7136] Fast-path ad-hoc printing of Strings
2020-04-12 09:30:52 -07:00
Robert Widmann
22b0526917 Merge pull request #30082 from 3405691582/OpenBSD_Port_Build
Build system recognizes OpenBSD.
2020-04-12 09:30:17 -07:00
Saleem Abdulrasool
b7654f158b Merge pull request #30885 from compnerd/android-fp80
stdlib: android does not support fp80
2020-04-11 10:13:52 -07:00
Michael Ilseman
c1ab69e2db Merge pull request #30729 from milseman/merge_me_if_available
[string] String(decoding:as:) fast path for withContiguousStorageIfAvailable
2020-04-10 16:10:06 -07:00
Dan Zheng
a864a57c9a [AutoDiff upstream] Add Differentiable.withDerivative(_:). (#30945)
Add `Differentiable.withDerivative(_:)`, a "derivative surgery" API.

`Differentiable.withDerivative(_:)` is an identity function returning `self`.
It takes a closure and applies it to the derivative of the return value, in
contexts where the return value is differentiated with respect to.
2020-04-10 12:22:56 -07:00
Michael Ilseman
38fce16254 [string] Convert IR tests to SIL tests 2020-04-10 11:39:22 -07:00
Michael Ilseman
d02f5bc509 [string] Move wCSIA check higher than _HasContiguousBytes 2020-04-10 11:39:03 -07:00
Saleem Abdulrasool
29085464b2 Merge pull request #30940 from compnerd/magic-numbers-are-good
Platform: alias math constants on Windows
2020-04-10 07:29:46 -07:00
Dan Zheng
3ef8360f3e [AutoDiff] Add AnyDifferentiable. (#30928)
Add `AnyDifferentiable`, a type-erased wrapper for `Differentiable`-conforming types.
2020-04-09 22:49:55 -07:00
Saleem Abdulrasool
600d90dbed Platform: alias math constants on Windows
The non-C/C++ standard defined math constants require
`-Xcc -D_USE_MATH_DEFINES` when using the `ucrt` module.  Instead,
provide them through the wrapper `MSVCRT` module as aliases so that the
user does not need to be aware of this in practice.

Repairs the Windows build of `_Differentiation`.
2020-04-09 19:13:10 -07:00
Saleem Abdulrasool
e7ffea78b1 Merge pull request #30927 from compnerd/undefined-is-the-only-desired-behaviour
runtime: fix a UBSAN issue
2020-04-09 15:29:23 -07:00
Michael Ilseman
ae224cacdb [string] Restore _HasContiguousBytes for untyped storage
UnsafeRawBufferPointer cannot implement
withContiguousStorageIfAvailable because doing so would potentially
create a typed pointer from untyped data.
2020-04-09 13:38:28 -07:00
Michael Ilseman
e536ad2342 [string] Outline cold path from initializer
Outline the cold, non-contiguous UTF-8 path from String(decoding:as:),
saving ~40 bytes (33%) of code size (x86_64 and arm64) from every call
site where the contiguity check cannot be constant folded away.
2020-04-09 13:38:28 -07:00
Michael Ilseman
c2631004d7 [string] _HasContiguousBytes -> withContiguousStorageIfAvailable
Switch String(decoding:as) and other entry points to call
withContiguousStorageIfAvailable rather than use _HasContiguousBytes.
2020-04-09 13:38:28 -07:00
Michael Ilseman
19b332c8e2 [gardening] Delete Trailing Whitespace 2020-04-09 13:38:27 -07:00
Saleem Abdulrasool
c8e8b177fa runtime: fix a UBSAN issue
This was identified by UBSAN: signed-integer-overflow.  Explicitly mark
the value as unsigned to ensure that the value does not overflow.  There
is a second instance of a raw literal, however, because it is a `*=` the
value is implicitly understood to be unsigned.
2020-04-09 12:21:20 -07:00
Dan Zheng
d4ff5847d0 [AutoDiff upstream] Add AnyDerivative.
Add `AnyDerivative`, a type-erased wrapper for `Differentiable.TangentVector`
associated type implementations.
2020-04-09 11:52:59 -07:00
Dan Zheng
65ab642b1a [AutoDiff upstream] Add Differentiable.zeroTangentVector.
Add `Differentiable.zeroTangentVectorInitializer` protocol requirement and
`Differentiable.zeroTangentVector` default implementation.
2020-04-09 11:15:18 -07:00
tbkka
110e5136c1 Float16 optimal formatting (#30862)
Extend SwiftDtoa to provide optimal formatting for Float16 and use that for `Float16.description` and `Float16.debugDescription`.

Notes on signaling NaNs: LLVM's Float16 support passes Float16s on x86
by legalizing to Float32.  This works well for most purposes but incidentally
loses the signaling marker from any NaN (because it's a conversion as far
as the hardware is concerned), with a side effect that the print code never
actually sees a true sNaN.  This is similar to what happens with Float and
Double on i386 backends.  The earlier code here tried to detect sNaN in a
different way, but that approach isn't guaranteed to work so we decided to
make this code use the correct detection logic -- sNaN printing will just be
broken until we can get a better argument passing convention.

Resolves rdar://61414101
2020-04-09 09:37:38 -04:00
Dan Zheng
75548c30be Merge pull request #30875 from apple/autodiff-upstream-stdlib-differentiation
[AutoDiff upstream] Add stdlib `Differentiable` conformances and derivatives.
2020-04-08 22:31:47 -07:00
Saleem Abdulrasool
368d66af21 Merge pull request #30888 from compnerd/android-shims
runtime: provide AEABI shims for floating point conversion
2020-04-08 19:48:23 -07:00
Dan Zheng
01db90dd61 Merge branch 'master' of github.com:apple/swift into autodiff-upstream-stdlib-differentiation 2020-04-08 14:12:03 -07:00
Dan Zheng
2eb460de4d [AutoDiff upstream] Add forward-mode differentiation. (#30878)
JVP functions are forward-mode derivative functions. They take original
arguments and return original results and a differential function. Differential
functions take derivatives wrt arguments and return derivatives wrt results.

`JVPEmitter` is a cloner that emits JVP and differential functions at the same
time. In JVP functions, function applications are replaced with JVP function
applications. In differential functions, function applications are replaced
with differential function applications.

In JVP functions, each basic block takes a differential struct containing callee
differentials. These structs are consumed by differential functions.
2020-04-08 11:29:21 -07:00
Saleem Abdulrasool
dce9614bf4 runtime: provide AEABI shims for floating point conversion
Android NDK <r21 does not provide the AEABI mandated `__aeabi_d2h`
functions in the compiler runtime.  Add shims to ensure that the
functions are available for building the standard library.
2020-04-08 11:16:40 -07:00
Saleem Abdulrasool
3fe5b1531c stdlib: android does not support fp80
Like Windows, Android does not support FP80.  Ensure that we do not emit
these even on x86 and x86_64.
2020-04-08 10:07:50 -07:00
Dan Zheng
d599105715 [AutoDiff upstream] Fix stdlib differentiation tests.
Temporarily disable not-yet-supported differentiation tests:

- Forward-mode differentiation.
  - TF-1237: to be upstreamed.
- `Differentiable.zeroTangentVector`.
  - TF-1238: to be upstreamed.
- `SIMD.sum` differentiation.
  - TF-1103: `@_alwaysEmitIntoClient` derivative registration.
2020-04-08 02:50:43 -07:00
Dan Zheng
2c112141dd [AutoDiff upstream] Deduplicate floating-point Differentiable conformances.
Move `Differentiable` conformances out of Differentiable.swift.
All `Differentiable` conformances exist in separate files.
2020-04-08 02:49:21 -07:00
Dan Zheng
ece4fb75b0 [AutoDiff upstream] Add Float16 derivatives.
Add `@available` attributes for declarations using `Float16`.
2020-04-08 02:49:18 -07:00
Dan Zheng
e377436169 Merge branch 'master' of github.com:apple/swift into autodiff_upstream_conformances_derivatives_master 2020-04-08 02:49:17 -07:00
Dan Zheng
da36555aa5 [AutoDiff upstream] Gardening.
- Standardize filenames: `XXXDifferentiation.swift`.
  - Use Pascal or snake case consistently.
- Formatting changes.
2020-04-08 02:49:12 -07:00
Dario Rexin
999b93bfdb Merge pull request #30815 from ktoso/wip-mangledTypeName
Improve usability of _mangledTypeName with Any.Type arguments
2020-04-06 20:49:13 -07:00
Stephen Canon
248c554524 Add Float16 to stdlib (#30130)
Add Float16 (IEEE 754 binary16) to the standard library, plus assorted runtime support operations.

Swift Evolution thread: https://forums.swift.org/t/se-0277-float16/33546
2020-04-06 17:57:44 -04:00
Konrad `ktoso` Malawski
5faf82c553 Improve usability of _mangledTypeName with Any.Type arguments 2020-04-05 12:27:50 +09:00
nate-chandler
feba039217 Merge pull request #30785 from nate-chandler/rdar60790020
[Runtime] Handle incomplete class metadata in _checkGenericRequirements.
2020-04-03 15:32:53 -07:00
nate-chandler
afc963aa82 Merge pull request #30793 from nate-chandler/generic-metadata-prespecialization-components/prepare-for-classes
[prespecialized metadata] Note classes are complete.
2020-04-03 14:00:45 -07:00
Nate Chandler
2863f1964d [Runtime] Handle incomplete class metadata in _checkGenericRequirements.
When constructing the metadata for a type Gen<T : Super>
where Super is a superclass constraint, the generic argument K at which
the metadata for Gen is being instantiated is verified to be a subclass
of Super via _checkGenericRequirements.

Previously, that check was done using swift_dynamicCastMetatype.  That
worked for the most part but provided an incorrect answer if the
metadata for K was not yet complete.  These classes are incomplete more
often thanks to __swift_instantiateConcreteTypeFromMangledNameAbstract.

That issue occurred concretely in the following case:

  Framework with Library Evolution enabled:

    open class Super { ... }
    public struct Gen<T : Super> {
    }

  Target in a different resilience domain from that framework:

    class Sub : Super {
      var gen: Gen<Sub>?
    }

Here, the mechanism for checking whether the generic argument K at which
the metadata for Gen is being instantiated handles the case where K's
metadata is incomplete.  At worst, every superclass name from super(K)
up to Super are demangled to instantiate metadata.  A number of faster
paths are included as well.

rdar://problem/60790020
2020-04-03 13:28:54 -07:00
Ewa Matejska
36cf56651f fixing up some tests and turning off SIMD extension which uses @_alwaysEmitIntoClient since that's not supported yet. 2020-04-03 12:59:47 -07:00
Nate Chandler
a1e2fb019e [prespecialized metadata] Note classes are complete.
In preparation for the prespecialization of metadata for generic
classes, make checkMetadataState always return that the state of
prespecialized class metadata is complete, as is done for generic
structs and enums already.
2020-04-03 11:46:54 -07:00
Michael Ilseman
5815468ebb Merge pull request #30719 from milseman/tilde_equality
[String] Concrete String/Substring overloads for ~=
2020-04-03 11:12:32 -07:00
Ewa Matejska
b72aca9a5c Merge branch 'master' of https://github.com/apple/swift 2020-04-03 10:40:56 -07:00
3405691582
f8d0174b85 Build system recognizes OpenBSD.
Commit for CMake and build scripts to recognize OpenBSD. To keep this
commit relatively short, this just deals with the rather simple and
uncontroversial changes to the build system.

Note that OpenBSD calls "x86_64" as "amd64", Since the Swift stdlib will
be put in a subdirectory named after ARCH, to ensure the standard
library is properly found later, we use the native architecture name for
OpenBSD in the build system rather than trying to deal with the
difference the other way around.
2020-04-03 13:34:17 -04:00
Mike Ash
41cc3f3569 Merge pull request #30772 from mikeash/fix-mirror-enum-payload-extraction
[Mirror] Don't destroy and reconstitute enums when reflecting them.
2020-04-03 11:36:30 -04:00
Dan Zheng
e2014e3366 Merge pull request #30781 from dan-zheng/differentiation-transform-skeleton 2020-04-02 21:01:53 -07:00
Ewa Matejska
f07ae89636 First pass at upstreaming Differentiable conformances and derivatives 2020-04-02 19:55:26 -07:00