Commit Graph

3316 Commits

Author SHA1 Message Date
Erik Eckstein
65a6d9a22a MemoryLifetimeVerifier: support verifying enum memory locations.
This is kind of complicated, because an enum can be trivial for one case and not trivial for another case. We need to check at which parts of the function we can prove that the enum does (or could) have a trivial case. In such a branch, it's not required in SIL to destroy the enum location.

Also, document the rules and requirements for enum memory locations in SIL.rst.

rdar://73770085
2021-02-23 08:08:34 +01:00
swift-ci
15da94f03b Merge pull request #36015 from rxwei/74380324-mangle-diff-witness-keys 2021-02-17 19:29:48 -08:00
Richard Wei
e494df2ee6 [AutoDiff] Add differentiability kind to differentiability witnesses and mangle them.
Differentiability witnesses are now keyed by the original function name, the differentiability kind, and the autodiff config.

Updated SIL syntax:
```
differentiability-kind ::= 'forward' | 'reverse' | 'normal' | 'linear'
sil-differentiability-witness ::=
    'sil_differentiability_witness'
    sil-linkage?
    '[' differentiability-kind ']'
    '[' 'parameters' sil-differentiability-witness-function-index-list ']'
    '[' 'results' sil-differentiability-witness-function-index-list ']'
    generic-parameter-clause?
    sil-function-name ':' sil-type
    sil-differentiability-witness-body?
sil-instruction ::=
    'differentiability_witness_function'
    '[' sil-differentiability-witness-function-kind ']'
    '[' differentiability-kind ']'
    '[' 'parameters' sil-differentiability-witness-function-index-list ']'
    '[' 'results' sil-differentiability-witness-function-index-list ']'
    generic-parameter-clause?
    sil-function-name ':' sil-type
```
```console
sil_differentiability_witness [reverse] [parameters 0 1] [results 0] <T where T: Differentiable> @foo : <T> $(T) -> T
differentiability_witness_function [vjp] [reverse] [parameters 0] [results 0] <T where T: Differentiable> @foo : $(T) -> T
```

New mangling:
```swift
  global ::= global generic-signature? 'WJ' DIFFERENTIABILITY-KIND INDEX-SUBSET 'p' INDEX-SUBSET 'r' // differentiability witness
```
```console
$s13test_mangling3fooyS2f_S2ftFWJrSpSr ---> reverse differentiability witness for test_mangling.foo(Swift.Float, Swift.Float, Swift.Float) -> Swift.Float with respect to parameters {0} and results {0}
```

Resolves rdar://74380324.
2021-02-17 18:27:42 -05:00
Joe Groff
eea3a6c27f SILGen: Handle pseudogeneric completion-handler-based async APIs.
Plumb generic signatures through the codegen for invoking foreign APIs as async, so that we
correctly handle APIs declared on ObjC lightweight generic classes. rdar://74361267
2021-02-16 16:05:04 -08:00
Richard Wei
75088cde3e [AutoDiff] Mangle derivative vtable thunks.
Add the following mangling rule:
```
global ::= global generic-signature? 'TJV' AUTODIFF-FUNCTION-KIND INDEX-SUBSET 'p' INDEX-SUBSET 'r' // autodiff derivative vtable thunk
```

Resolves rdar://74340331.
2021-02-15 00:11:50 -08:00
swift-ci
d33c79edaf Merge pull request #35847 from rxwei/72666310-mangle-ad-thunks 2021-02-13 05:07:32 -08:00
Richard Wei
f9ddecf459 [AutoDiff] Mangle linear map self-reordering thunks and subset parameters thunks.
Add the following new mangling rules.
```
global ::= from-type to-type 'TJO' AUTODIFF-FUNCTION-KIND // autodiff self-reordering reabstraction thunk
global ::= from-type 'TJS' AUTODIFF-FUNCTION-KIND INDEX-SUBSET 'p' INDEX-SUBSET 'r' INDEX-SUBSET 'P' // autodiff linear map subset parameters thunk
global ::= global to-type 'TJS' AUTODIFF-FUNCTION-KIND INDEX-SUBSET 'p' INDEX-SUBSET 'r' INDEX-SUBSET 'P' // autodiff derivative function subset parameters thunk
```

Example:
```console
$s13TangentVector16_Differentiation14DifferentiablePQzAaDQy_SdAFIegnnnr_TJSdSSSpSrSUSP ---> autodiff subset parameters thunk for differential from @escaping @callee_guaranteed (@in_guaranteed A._Differentiation.Differentiable.TangentVector, @in_guaranteed B._Differentiation.Differentiable.TangentVector, @in_guaranteed Swift.Double) -> (@out B._Differentiation.Differentiable.TangentVector) with respect to parameters {0, 1, 2} and results {0} to parameters {0, 2}
$sS2f8mangling3FooV13TangentVectorVIegydd_SfAESfIegydd_TJOp ---> autodiff self-reordering reabstraction thunk for pullback from @escaping @callee_guaranteed (@unowned Swift.Float) -> (@unowned Swift.Float, @unowned mangling.Foo.TangentVector) to @escaping @callee_guaranteed (@unowned Swift.Float) -> (@unowned mangling.Foo.TangentVector, @unowned Swift.Float)
```

Resolves rdar://72666310 / SR-13508.

Also fix a bug in `AutoDiffFunction` mangling where the original may be a global that contains more than 1 node (rdar://74151229 / SR-14106).
2021-02-13 01:38:35 -08:00
Varun Gandhi
fb4718234b Merge pull request #35777 from ahoppen/sccache-not-working
[docs] Add warning that sccache isn't caching any commands since version 0.13.4
2021-02-09 15:08:09 -08:00
Erik Eckstein
ee5491a7c9 PassManager: simplify the options to print intermediate SIL.
* rename -sil-print-only-function to -sil-print-function and -sil-print-only-functions to -sil-print-functions
* to print single functions, don't require -Xllvm -sil-print-all. It's now sufficient to use e.g. -Xllvm -sil-print-function=<f>
But it's still possible to select functions with -sil-print-function(s) for other print options, -sil-print-after.
2021-02-09 09:12:06 +01:00
swift-ci
bc04881206 Merge pull request #35815 from 3405691582/DocUpdate 2021-02-08 14:17:28 -08:00
Richard Wei
18fe723543 Merge pull request #35811 from rxwei/69980056-differentiable-reverse
[AutoDiff] Add '@differentiable(reverse)'.
2021-02-08 04:32:27 -08:00
Alex Hoppen
987415283f [docs] Add warning that sccache isn't caching any commands since version 0.2.14 2021-02-08 09:33:09 +01:00
Richard Wei
af8942d940 [AutoDiff] Rename '@differentiable' to '@differentiable(reverse)'.
Compiler:
- Add `Forward` and `Reverse` to `DifferentiabilityKind`.
- Expand `DifferentiabilityMask` in `ExtInfo` to 3 bits so that it now holds all 4 cases of `DifferentiabilityKind`.
- Parse `@differentiable(reverse)` and `@differentiable(_forward)` declaration attributes and type attributes.
- Emit a warning for `@differentiable` without `reverse`.
- Emit an error for `@differentiable(_forward)`.
- Rename `@differentiable(linear)` to `@differentiable(_linear)`.
- Make `@differentiable(reverse)` type lowering go through today's `@differentiable` code path. We will specialize it to reverse-mode in a follow-up patch.

ABI:
- Add `Forward` and `Reverse` to `FunctionMetadataDifferentiabilityKind`.
- Extend `TargetFunctionTypeFlags` by 1 bit to store the highest bit of differentiability kind (linear). Note that there is a 2-bit gap in `DifferentiabilityMask` which is reserved for `AsyncMask` and `ConcurrentMask`; `AsyncMask` is ABI-stable so we cannot change that.

_Differentiation module:
- Replace all occurrences of `@differentiable` with `@differentiable(reverse)`.
- Delete `_transpose(of:)`.

Resolves rdar://69980056.
2021-02-07 14:09:46 -08:00
buttaface
e6f5913772 [android] Move to the NDK's unified sysroot (#34491)
Since the NDK removes the platforms/ and sysroot/ directories in the latest NDK
22, switch to the unified sysroot in toolchains/llvm/ and take advantage of a
bunch of simplification that's now possible.
2021-02-07 09:19:18 -08:00
3405691582
c5be034008 [docs] Minor doc update for OpenBSD.
Swift uses `ar s`, but LLVM does an `ar` and `ranlib` pass separately. To
work around the platform binutils bug, you should use the LLVM version of
both these tools, not just `ar`.
2021-02-07 11:21:02 -05:00
Ben Rimmington
d9a3dcd3bd [Docs] Remove UnicodeScalar from ABI/Mangling.rst (#35785)
Follow-up to: apple/swift@9e7dfad384
2021-02-05 21:36:21 +00:00
David Zarzycki
acfdbc94df [Docs] Fix testing target suffixes
The underlying change happened almost five years ago: 457f2b901c.
2021-02-02 08:46:00 -05:00
Varun Gandhi
36b589d623 Merge pull request #35538 from mininny/disable-dead-stripping-option
[build-script] Add swift-disable-dead-stripping option for disabling dead stripping
2021-01-31 16:31:48 -08:00
Doug Gregor
c97637cb96 Merge pull request #35655 from DougGregor/concurrent-function-types-sil
[SIL] Add `@concurrent` function types to SIL
2021-01-29 15:43:45 -08:00
Doug Gregor
99f8d7a5e8 [SIL] Add @concurrent function types to SIL
Add @concurrent to SIL function types, mirroring what's available on
AST function types. @concurrent function types will have by-value
capture semantics.
2021-01-29 11:16:17 -08:00
Doug Gregor
f13167d9d1 Merge pull request #35628 from DougGregor/concurrent-function-types
[Concurrency] Add @concurrent function types
2021-01-29 08:34:59 -08:00
swift-ci
19c55a63fc Merge pull request #35616 from teameh/patch-2 2021-01-27 20:00:58 -08:00
Doug Gregor
ba8819eb58 [Concurrent] Introduce concurrent function types.
Introduce `@concurrent` attribute on function types, including:
* Parsing as a type attribute
* (De-/re-/)mangling for concurrent function types
* Implicit conversion from @concurrent to non-@concurrent
- (De-)serialization for concurrent function types
- AST printing and dumping support
2021-01-27 14:22:32 -08:00
Teameh
dd8d95a680 Fix typo in OptimizationTips.rst
d is assigned to d, not the other way around
2021-01-27 16:52:12 +01:00
Brentley Jones
bf6c753a81 Update guide to mention correct subdirectory
The guide as written results in lots of repositories being placed as siblings to `swift-project`, instead of inside of it. This also results in the `build` directory being a sibling. Changing the clone to the `swift` directory fixes this.
2021-01-22 11:08:51 -06:00
Minhyuk Kim
b0426829fe Add swift_disable_dead_stripping option for disabling dead stripping in Swift build 2021-01-22 23:56:02 +09:00
Varun Gandhi
72105d59b0 Merge pull request #35284 from apple/remove-needless-directory
Stop creating swift-project/swift/swift
2021-01-20 17:12:06 -08:00
Varun Gandhi
d9cd7e73cd Merge pull request #35457 from varungandhi-apple/vg-cleanup-rep-matching
[docs] Tidy and document permissible conversions based on calling conventions
2021-01-20 13:28:54 -08:00
Richard Wei
e3db926e0c [AutoDiff] Remove '_Differentiable.zeroTangentVectorInitializer'. (#35329)
Remove `_Differentiable.zeroTangentVectorInitializer` to address the feedback on the [proposal thread](https://forums.swift.org/t/differentiable-programming-for-gradient-based-machine-learning/42147). The corresponding change has already been made in the [proposal](https://github.com/rxwei/swift-evolution/blob/autodiff/proposals/0000-differentiable-programming.md).

Removed components:
- `zeroTangentVectorInitializer` and `zeroTangentVector` in `Differentiable`, `Array`, `Optional`, `Float`, `Double`, `Float80`, and SIMD types.
- `zeroTangentVectorInitializer` synthesis logic in `Differentiable` derived conformances.
2021-01-20 10:45:03 -08:00
Varun Gandhi
29430d643d [doc] Dynamic cast of function types needs matching conventions. 2021-01-19 10:48:13 -08:00
3405691582
36728d73d5 [docs] Update docs for OpenBSD.
When making debug builds, `Decl.cpp` compiles with a large number of ELF
section headers; including randomdata sections as normally included by
the platform for security purposes, this may in reality exceed the ELF
limit of `SHN_LORESERVE`.

In this case, the ELF header field containing the number of section
headers, `e_shnum`, is set to 0 and the real number of section headers
is stored elsewhere. However, when an object file has no section
headers, this field is also set to 0.

OpenBSD uses the GNU binutils by default. These binutils do not handle
the case when `e_shnum` is 0, and assume that the object file has no
section headers.  But the only tool that counts is the static archive
tool `ar`. When creating the archive index, `ar` encounters `Decl.cpp.o`
as part of `libswiftAST.a`, notes that `e_shnum` is 0, and skips the
object file entirely, presumably because it thinks the object file has
no section headers and therefore no symbols. This leads the linker to
assume that symbols in `Decl.cpp.o` are not part of `libswiftAST.a`,
when in fact they are.

The LLVM version of `ar` does not appear to have this bug.

Since this is only a problem that is more likely to occur on debug
builds and workarounds like enabling LTO can alleviate the problem, do
not recommend that the `llvm` package be added as part of the standard
package dependency set, but merely note that using `llvm-ar` can work
around the problem. Indeed, future OpenBSD versions may include updated
binutils which may have this bug fixed.

While we are here, the new concurrency features require libdispatch, and
since some of the necessary patches to libdispatch have not yet been
reviewed or accepted upstream yet to make it work on OpenBSD, recommend
that prospective builders for this platform still disable features that
depend on libdispatch for now.

Additionally, update the platform version number which has been tested.
2021-01-18 20:19:16 -05:00
Alex Hoppen
bfe0a00551 Merge pull request #35429 from ahoppen/remove-bytetree
Remove ByteTree serialization format
2021-01-15 09:28:19 +01:00
Alex Hoppen
8ec8516893 Remove ByteTree serialization format
It was originally designed for faster trasmission of syntax trees from
C++ to SwiftSyntax, but superceded by the CLibParseActions. There's no
deserializer for it anymore, so let's just remove it.
2021-01-14 20:37:49 +01:00
Robert Widmann
843b25bbc7 Merge pull request #34423 from valeriyvan/patch-2
Fix snippet in OptimizationTips.rst
2021-01-13 18:00:14 -08:00
Slava Pestov
c997016bc6 Update some docs to talk about 'main' instead of 'master'
Fixes https://bugs.swift.org/browse/SR-14015 / rdar://problem/72819056
2021-01-11 22:57:51 -05:00
Robert Widmann
e27c862c20 Merge pull request #35279 from apple/clarify-use-sccache-env-var
Clarify SWIFT_USE_SCCACHE meaning
2021-01-09 08:05:54 -08:00
Dave Abrahams
94f2c0d020 Further clarification 2021-01-07 14:13:17 -08:00
Dave Abrahams
1ca367d4a0 sccache will start itself 2021-01-07 14:09:27 -08:00
Richard Wei
5e5f48471b Merge pull request #35259 from rxwei/autodiff-mangling
[AutoDiff] Mangle derivative functions and linear maps
2021-01-07 08:46:42 -08:00
Richard Wei
ffe6064101 Mangle derivative functions and linear maps.
- `Mangle::ASTMangler::mangleAutoDiffDerivativeFunction()` and `Mangle::ASTMangler::mangleAutoDiffLinearMap()` accept original function declarations and return a mangled name for a derivative function or linear map. This is called during SILGen and TBDGen.
- `Mangle::DifferentiationMangler` handles differentiation function mangling in the differentiation transform. This part is necessary because we need to perform demangling on the original function and remangle it as part of a differentiation function mangling tree in order to get the correct substitutions in the mangled derivative generic signature.

A mangled differentiation function name includes:
- The original function.
- The differentiation function kind.
- The parameter indices for differentiation.
- The result indices for differentiation.
- The derivative generic signature.
2021-01-07 02:21:10 -08:00
Dave Abrahams
565385b6b0 Stop creating swift-project/swift/swift
The instructions as written will create an unnecessary swift/swift directory, it looks like.
2021-01-06 14:49:46 -08:00
swift-ci
8da6fbf2bf Merge pull request #35272 from tbkka/tbkka/dynamicCast-existentialMetatypeClarification 2021-01-06 12:54:59 -08:00
Dave Abrahams
fcd054f448 Clarify SWIFT_USE_SCCACHE meaning 2021-01-06 11:38:11 -08:00
Max Desiatov
52d9398c30 Merge pull request #34998 from apple/maxd/fix-apple-silicon
CMake: fix build for Apple Silicon hosts

When building with `build-script` using these arguments

```
utils/build-script --skip-build-benchmarks
  --skip-ios --skip-watchos --skip-tvos
  --swift-darwin-supported-archs "arm64"
  --sccache --release-debuginfo --test
```

the build fails with

```
ninja: error: 'stdlib/swift-test-stdlib-macosx-x86_64',
needed by 'stdlib/CMakeFiles/swift-test-stdlib', missing and no known rule to make it
```

I think that the "Getting Started" guide should avoid hardcoding `x86_64` arguments, and suggest using `$(uname -m)` instead. `SWIFT_PRIMARY_VARIANT_ARCH_default` could also get its value from `CMAKE_HOST_SYSTEM_PROCESSOR` in the root `CMakeLists.txt`.

Resolves SR-13943.
2021-01-06 18:05:28 +00:00
Mishal Shah
6a61d119e8 Update the CI doc with new trigger info
OS X -> macOS
2021-01-06 09:32:16 -08:00
Tim Kientzle
0630981e2c Clarify existential metatype discussion, add a caveat about function casting 2021-01-05 18:28:39 -08:00
Michael Gottesman
0171e753d8 Merge pull request #35257 from apple/gottesmm-patch-1-sil.rst
[sil.rst] Fix some formatting
2021-01-05 12:08:10 -08:00
Michael Gottesman
ed2e1f63a2 [sil.rst] Fix another formatting error
Another case where spacing was off so the rendering on GitHub looks bad.
2021-01-04 18:22:07 -08:00
Michael Gottesman
f5e34b3d30 [sil.rst] Fix some formatting
Just a mistake I noticed.
2021-01-04 18:13:08 -08:00
Michael Gottesman
a7422b7aac [sil.rst] Add a discussion of "Dead End Blocks" and its implications upon OSSA.
The main implication being that we allow for values to be leaked along dead end
blocks.

NOTE: For those who are unaware, a dead end block in SIL is a block that is
post-dominated in the same function by program terminating blocks (which we
model using unreachables).
2020-12-29 13:32:17 -08:00