Commit Graph

10155 Commits

Author SHA1 Message Date
Dan Zheng
aa66cce808 [AutoDiff upstream] Add differentiation transform.
The differentiation transform does the following:
- Canonicalizes differentiability witnesses by filling in missing derivative
  function entries.
- Canonicalizes `differentiable_function` instructions by filling in missing
  derivative function operands.
- If necessary, performs automatic differentiation: generating derivative
  functions for original functions.
  - When encountering non-differentiability code, produces a diagnostic and
    errors out.

Partially resolves TF-1211: add the main canonicalization loop.

To incrementally stage changes, derivative functions are currently created
with empty bodies that fatal error with a nice message.

Derivative emitters will be upstreamed separately.
2020-04-02 15:43:57 -07:00
Mike Ash
f4e635320a [Mirror] Don't destroy and reconstitute enums when reflecting them.
It's possible to get multiple threads reading from the same enum at the same time, and the result can be bad data extracted or even permanent corruption of the value in memory. Instead, copy the enum value, then project the data from the copy.

rdar://problem/59493486
2020-04-02 13:44:19 -04:00
Michael Ilseman
30c92574ed [String] Concrete String/Substring overloads for ~=
Add concrete overloads for ~= for String/Substring
combinations. SR-12457 tracks making this generic after we understand
the expression type checker impact.
2020-04-02 10:37:30 -07:00
swift-ci
b1b725ac83 Merge pull request #30761 from benrimmington/de-gybbed-file-headers 2020-04-02 04:14:50 -07:00
Dan Zheng
1308fc69c5 [AutoDiff] Simplify conditions enabling differentiable programming. (#30765)
Previously, two conditions were necessary to enable differentiable programming:
- Using the `-enable-experimental-differentiable-programming` frontend flag.
- Importing the `_Differentiation` module.

Importing the `_Differentiation` module is the true condition because it
contains the required compiler-known `Differentiable` protocol. The frontend
flag is redundant and cumbersome.

Now, the frontend flag is removed.
Importing `_Differentiation` is the only condition.
2020-04-02 03:24:03 -07:00
Ben Rimmington
682c1672b6 [stdlib] Update file headers of de-gybbed files 2020-04-01 22:14:03 +01:00
marcrasi
77fd034a0b Merge pull request #30711 from rxwei/differential-operators
[AutoDiff upstream] Add differential operators and some utilities.
2020-04-01 10:11:35 -07:00
Karoy Lorentey
0344f0830e Merge branch 'master' into foundation-no-inlinable-shim-calls 2020-03-31 18:24:59 -07:00
tbkka
3c8fde7885 Implement MultiPayloadEnum support for projectEnumValue (#30635)
This code rearchitects and simplifies the projectEnumValue support by
introducing a new `TypeInfo` subclass for each kind of enum, including trivial,
no-payload, single-payload, and three different classes for multi-payload enums:

* "UnsupportedEnum" that we don't understand.  This returns "don't know" answers for all requests in cases where the runtime lacks enough information to accurately handle a particular enum.

* MP Enums that only use a separate tag value.  This includes generic enums and other dynamic layouts, as well as enums whose payloads have no spare bits.

* MP Enums that use spare bits, possibly in addition to a separate tag.  This logic can only be used, of course, if we can in fact compute a spare bit mask that agrees with the compiler.

The final challenge is to choose one of the above three handlings for every MPE.  Currently, we do not have an accurate source of information for the spare bit mask, so we never choose the third option above.  We use the second option for dynamic MPE layouts (including generics) and the first for everything else.

TODO: Once we can arrange for the compiler to expose spare bit mask data, we'll be able to use that to drive more MPE cases.
2020-03-31 15:12:44 -07:00
Joe Groff
026b8b31c9 Merge pull request #30318 from ktoso/wip-mangledTypeName
Add _mangledTypeName to allow round trips T->mangledName->T
2020-03-30 18:13:56 -07:00
Marc Rasi
64d0e76dd9 improve differential operator tests 2020-03-30 14:57:59 -07:00
Richard Wei
57d228b39e [AutoDiff upstream] Add differential operators and some utilities.
* Add all [differential operators](https://github.com/apple/swift/blob/master/docs/DifferentiableProgramming.md#list-of-differential-operators).
* Add `withoutDerivative(at:)`, used for efficiently stopping the derivative propagation at a value and causing the derivative at the value to be zero.
* Add utility `differentiableFunction(from:)`, used for creating a `@differentiable` function from an original function and a derivative function.

Mostly work done by @marcrasi and @dan-zheng.
Partially resolves TF-843.

TODO:
* Add `AnyDerivative`.
* Add `Array.differentiableMap(_:)` and `differentiableReduce(_:_:)`.
2020-03-30 14:15:35 -07:00
swift-ci
e5110d7953 Merge pull request #30146 from benrimmington/static-string-documentation 2020-03-27 16:36:13 -07:00
swift-ci
047438711f Merge pull request #30355 from mikeash/remote-mirror-type-name-api 2020-03-27 10:51:24 -07:00
swift-ci
216bff5213 Merge pull request #30668 from lorentey/mark-xctest-overlay-obsolete 2020-03-26 19:10:21 -07:00
Karoy Lorentey
3e8509df08 [XCTest] Add a note explaining that this is not the real XCTest overlay 2020-03-26 16:30:45 -07:00
Joe Groff
4981da4a4d Merge pull request #30632 from Azoy/swift-5-3-hacks
Bump backward compatibility to 5.3
2020-03-26 11:16:01 -07:00
David Smith
40e67b53c9 Merge pull request #30034 from Catfish-Man/what-i-tell-you-three-times-is-true
Avoid mishandling retain_n of immortal objects where n >= 3
2020-03-26 11:00:46 -07:00
David Smith
78c693ba2d Avoid mishandling retain_n of immortal objects where n >= 3 2020-03-25 15:53:31 -07:00
Mike Ash
1c1d57574c [Reflection] Make sure DemanglingForTypeRef consistently wraps all nodes in a Type node.
rdar://problem/59909982
2020-03-25 17:23:22 -04:00
Mike Ash
3a9e7a6611 [Reflection] Implement TypeRef demangling for foreign classes.
rdar://problem/59909982
2020-03-25 17:22:45 -04:00
Azoy
d8ea42adfb Bump backward compatibility to 5.3 2020-03-25 11:41:15 -04:00
Mishal Shah
e7cd5ab17f Update master to build with Xcode 11.4 2020-03-24 11:30:45 -07:00
Mike Ash
e05720cd09 [RemoteMirror] Add a call to get the demangled name for a typeref.
rdar://problem/59909982
2020-03-23 13:53:35 -04:00
Martin Boehme
3ccecc6819 Remove [extern_c] attribute from WinSDK module.
I've verified that all of the header files in this module already
contain their own `extern "C"` blocks that are activated if compiling as
C++.

The additional [extern_c] attribute causes problems for some headers,
like PathCch.h, that define additional overloads of functions when
compiled as C++. The "global" [extern_c] essentially switches off name
mangling with these overloads, which causes them to conflict with the
functions they are overloading.

See here for more context:
https://github.com/apple/swift/pull/30233#issuecomment-601594221

See here for an example of failures caused by the [extern_c]:
https://ci-external.swift.org/job/swift-PR-windows/869/console

(Search for "PathCch.h".)
2020-03-20 10:45:38 +01:00
Konrad `ktoso` Malawski
34b6e4fe58 Add precondition that no repairs were made to _mangledTypeName string 2020-03-18 11:51:28 +09:00
Dmitri Gribenko
841eeb05b0 Merge pull request #30403 from MForster/forster/string-fixes
Cherry-pick StringRef->std::string conversion fixes into `master`
2020-03-17 12:09:36 +01:00
Xiaodi Wu
90c6c491d9 [gardening] Silence a warning about unused value 2020-03-14 10:33:45 -04:00
swift-ci
cc4bfe82da Merge pull request #30398 from milseman/palloc_size 2020-03-13 17:57:59 -07:00
Michael Ilseman
d98a022924 [stdlib] Re-enable assertions on malloc size
Round up our malloc requests and assert that breadcrumbs are aligned
and where we think they should be. This is necessary because ASAN
doesn't give us pointer-rounded sizes.
2020-03-13 15:50:40 -07:00
Fred Riss
259d78a350 Adapt to llvm.org StringRef API change 2020-03-13 19:08:22 +01:00
Luciano Almeida
d0af9eee96 [NFC] Fixing redundant discard assign void type warn on stdlib (#30397) 2020-03-13 09:51:41 +00:00
Slava Pestov
afa2440f85 Merge pull request #30370 from slavapestov/encapsulate-conformance-descriptor
Runtime: Use accessor method to get TargetWitnessTable::Description
2020-03-12 00:19:24 -04:00
Kuba (Brecka) Mracek
1a3c582490 Fix typos in declarations of swift_ptrauth_key_associated_type and swift_ptrauth_key_associated_conformance (#30363) 2020-03-11 19:24:30 -07:00
tbkka
ee36c1cc3e RemoteMirror: Project some multi-payload enums (#30357)
* First part of multi-payload enum support

This handles multi-payload enums with fixed
layouts that don't use spare payload bits.
It includes XI calculations that allow us to
handle single-payload enums where the payload
ultimately includes a multi-payload enum
(For example, on 32-bit platforms, String uses
a multi-payload enum, so this now supports single-payload
enums carrying Strings.)
2020-03-11 18:48:39 -07:00
Slava Pestov
4bc1d03283 Runtime: Use accessor method to get TargetWitnessTable::Description 2020-03-11 19:34:10 -04:00
tbkka
46bba7aa58 Memoize the ObjCBridgeable conformance for Swift.String (#30329)
This seems to be the single most common bridge cast,
and repeated lookup seems to be a performance issue
for the common operation of bridging a string-valued
NSDictionary into Swift.  Spending a couple of static
words of memory to memoize it should be a nice perf win.

Resolves rdar://55237013
2020-03-10 20:03:57 -07:00
Mike Ash
faa2bf2698 [Reflection] Fix a dangling reference in EnumTypeInfoBuilder when creating a case with an empty TypeInfo.
While we're in there, fix a couple of DEBUG_LOG calls that didn't compile when logging is enabled.

rdar://problem/59921829
2020-03-10 15:10:08 -04:00
Konrad `ktoso` Malawski
ea6b69eabc Add missing @available marker on _getMangledTypeName 2020-03-10 14:04:47 +09:00
Konrad `ktoso` Malawski
33444489e5 Add _mangledTypeName to allow round trips T->mangledName->T 2020-03-10 12:20:08 +09:00
swift-ci
28f343df51 Merge pull request #30301 from tbkka/tbkka-remoteMirror-projectEnum 2020-03-09 15:55:01 -07:00
Michael Ilseman
4715d68890 Merge pull request #30237 from valeriyvan/RemoveRedundantZeroingStringGuts
Changes implementation of _persistCString from _StringGuts
2020-03-09 14:36:05 -07:00
Mike Ash
b80e33b514 Fix reuse of the payload area when the discriminator != 0 2020-03-09 11:58:54 -07:00
Saleem Abdulrasool
559dc2a516 WinSDK: further extend the WinSock module
Add the new `afunix.h` header to the WinSock module which was introduced
in the 10.0.17134 release.
2020-03-09 09:54:59 -07:00
swift-ci
57f54dd1a3 Merge pull request #30294 from CodaFi/order-up 2020-03-09 09:50:31 -07:00
Robert Widmann
4c74c07a01 [NFC] Squash an initialization ordering warning 2020-03-09 08:07:04 -07:00
Saleem Abdulrasool
4fcd65a411 WinSDK: extend the WinSock module further
This enables the use of `TransmitFile` more fully by adding the
Microsoft extensions to the WinSock module.
2020-03-08 13:14:24 -07:00
Kuba (Brecka) Mracek
ab6533a40f Merge branch 'master' into mracek/arm64e 2020-03-06 15:07:01 -08:00
tbkka
0d361bd3ea Teach RemoteMirror how to project enum values (#30161)
Teach RemoteMirror how to project enum values

This adds two new functions to the SwiftRemoteMirror
facility that support inspecting enum values.

Currently, these support non-payload enums and
single-payload enums, including nested enums and
payloads with struct, tuple, and reference payloads.
In particular, it handles nested `Optional` types.

TODO: Multi-payload enums use different strategies for
encoding the cases that aren't yet supported by this
code.

Note: This relies on information from dataLayoutQuery
to correctly decode invalid pointer values that are used
to encode enums.  Existing clients will need to augment
their DLQ functions before using these new APIs.

Resolves rdar://59961527

```
/// Projects the value of an enum.
///
/// Takes the address and typeref for an enum and determines the
/// index of the currently-selected case within the enum.
///
/// Returns true iff the enum case could be successfully determined.
/// In particular, note that this code may fail for valid in-memory data
/// if the compiler is using a strategy we do not yet understand.
SWIFT_REMOTE_MIRROR_LINKAGE
int swift_reflection_projectEnumValue(SwiftReflectionContextRef ContextRef,
                                      swift_addr_t EnumAddress,
                                      swift_typeref_t EnumTypeRef,
                                      uint64_t *CaseIndex);

/// Finds information about a particular enum case.
///
/// Given an enum typeref and index of a case, returns:
/// * Typeref of the associated payload or zero if there is no payload
/// * Name of the case if known.
///
/// The Name points to a freshly-allocated C string on the heap.  You
/// are responsible for freeing the string (via `free()`) when you are finished.
SWIFT_REMOTE_MIRROR_LINKAGE
int swift_reflection_getEnumCaseTypeRef(SwiftReflectionContextRef ContextRef,
                                        swift_typeref_t EnumTypeRef,
                                        unsigned CaseIndex,
                                        char **CaseName,
                                        swift_typeref_t *PayloadTypeRef);
```


Co-authored-by: Mike Ash <mikeash@apple.com>
2020-03-06 13:17:40 -08:00
Rintaro Ishizaki
3f69d6b9dd Merge pull request #30260 from milseman/assert_san
[stdlib] Disable assertion tripping up ASAN
2020-03-06 09:32:31 -08:00