Commit Graph

89 Commits

Author SHA1 Message Date
Anton Korobeynikov
03334a8f92 [AutoDiff] Generalize handling of semantic result parameters (#67230)
Introduce the notion of "semantic result parameter". Handle differentiation of inouts via semantic result parameter abstraction. Do not consider non-wrt semantic result parameters as semantic results

Fixes #67174
2023-08-03 09:33:11 -07:00
Arnold Schwaighofer
0b6db0afc4 Fix test/AutoDiff directory 2023-06-20 12:47:56 -07:00
Arnold Schwaighofer
c1a93e0bde Move tests over to use the %use_no_opaque_pointers option 2023-06-14 10:49:48 -07:00
Anton Korobeynikov
0b235a7aac [AutoDiff[ Preserve substitutions maps while calculating derivative types (#65451)
The substituon map might contain proper specialization (e.g. t_0_0 -> Double) that is required to fully specify a derivate type (e.g. during reabstraction conversion from fully specified function type to a substituted one)

Fixes #65073
2023-04-26 23:11:15 -07:00
Erik Eckstein
e356b122f6 tests: disable AutoDiff/compiler_crashers_fixed/issue-55852-tangent-value-category-mismatch.swift on linux
Sometimes the linker crashes on linux
2023-04-18 14:38:25 +02:00
Erik Eckstein
0794eb3c57 tests: don't run AutoDiff/compiler_crashers_fixed/58660-conflicting-debug-info-inlining.swift on linux 2023-04-18 10:17:51 +02:00
Slava Pestov
a8cec8e268 Disable AutoDiff/compiler_crashers_fixed/58660-conflicting-debug-info-inlining.swift on Linux 2023-03-15 00:56:29 -04:00
Anton Korobeynikov
869fc1792e [AutoDiff] Ensure autodiff code does not ignore getSingleTerminatorOperands return value (#64200)
Also extend activity analysis to handle `try_apply` normal result properly. Add testcase from #63728
2023-03-08 10:10:22 -08:00
swift-ci
ee20e6066f Merge remote-tracking branch 'origin/main' into rebranch 2023-02-19 18:54:26 -08:00
Anton Korobeynikov
11de73639c [AutoDiff] Unwrap the top level of linear map tuple when it is possible (#63770)
This essentially passes the members of a linear map tuple as individual arguments. It yields few nice simplifications:

 * No linear map tuples at all for getters / setters
 * No tuple formation / deconstruction around pullbacks
 * Pullbacks with loops still use heap-allocated tuples
2023-02-19 18:46:49 -08:00
swift-ci
d542b741b6 Merge remote-tracking branch 'origin/main' into rebranch 2023-02-08 07:54:19 -08:00
Anton Korobeynikov
d2e022d5b4 Remove linear map structs and use plain tuples instead. (#63444)
The changes are intentionally were made close to the original implementation w/o possible simplifications to ease the review

Fixes #63207, supersedes #63379 (and fixes #63234)
2023-02-08 07:42:54 -08:00
swift-ci
73883dd0b3 Merge remote-tracking branch 'origin/main' into rebranch 2023-01-20 10:48:41 -08:00
Alex Hoppen
069f382023 Disable rdar74087329-debug-scope-trampoline-blocks.swift
This is failing on the Linux bots. Let’s disable the test for now. #63107 tracks the actual failure.
2023-01-20 19:40:24 +01:00
Erik Eckstein
712fd7922b Merge remote-tracking branch 'origin/main' into rebranch 2023-01-09 08:48:47 +01:00
Anton Korobeynikov
6d657c90af [AutoDiff] Refine debug info emitted for adjoint buffers (#62779)
Single input variable might yield multiple adjoint buffers if control flow is involved. Therefore we cannot simply transfer debug info  from the input variable: it will be invalid as we will end with multiple locations for a single "source" variable, and, even worse, might end with conflicting debug info as different buffers might be optimized
differently.

We do:
  - Drop input argument number. This must be unique and we're not
  - Correct variable name
2023-01-06 14:34:16 -08:00
swift-ci
84236ec390 Merge remote-tracking branch 'origin/main' into rebranch 2022-12-04 01:13:44 -08:00
Anthony Latsis
4cb63c8a0f [NFC] Migrate remnant Jira issue references to GitHub issues 2022-12-04 08:20:34 +03:00
Erik Eckstein
53fa067256 tests: don't match alignment in an AutoDiff test 2022-12-01 15:26:27 +01:00
Anthony Latsis
7d40b283f9 Gardening: Migrate test suite to GH issues: AutoDiff/compiler_crashers_fixed (2/2) 2022-09-22 20:27:52 +03:00
Anthony Latsis
8872fe6b30 Gardening: Migrate test suite to GH issues: AutoDiff/compiler_crashers_fixed (1/2) 2022-09-19 02:36:02 +03:00
Anton Korobeynikov
8fa3d2f863 Add regression test for #59467 (#60158)
* Add S4TF crasher test
* Unbreak the test

Co-authored-by: Philip Turner <philipturner.AR@gmail.com>

Resolves #59467
2022-07-20 15:05:16 -07:00
Ben Barham
c163e0fe5e [Tests] Make OS features consistent
lit.py currently allows any substring of `target_triple` to be used as a
feature in REQUIRES/UNSUPPORTED/XFAIL. This results in various forms of
the OS spread across the tests and is also somewhat confusing since they
aren't actually listed in the available features.

Modify all OS-related features to use the `OS=` version that Swift adds
instead. We can later remove `config.target_triple` so that these don't
the non-OS versions don't work in the first place.
2022-05-20 19:51:23 -07:00
Anton Korobeynikov
4f05096594 Propagate location from destination alloca in salvageDebugInfo(). (#58763)
`salvageDebugInfo` is called during SIL Mem2Reg and could produce misleading debug info in the following case:

```
%a = alloc_stack $MyModel.TangentVector, var, name "self", argno 1, implicit, loc "debug2.swift":37:17 ...
...
store %b to %a : $*MyModel.TangentVector
```

Such SIL could be created as a result of inlining (where store comes from the inlined function).
Before this patch we'd end with `debug_value` instruction with variable information, but without or incorrect location.

This caused LLVM IR debug info verifier assertions when there might be another instruction with complete debug info (including location) for the same argument.

After this patch we always reuse it from destination alloca

Fixes #58660
2022-05-11 13:28:23 -07:00
Philip Turner
61a352486e Create sr15884-generic-signature-builder-keypath-iterable.swift 2022-04-29 16:07:37 -04:00
Josh Soref
e8b5204bd0 Spelling autodiff (#42546)
* spelling: differentiated

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: initialization

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: multiplication

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: occasionally

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: overriding

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* Rename test

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-25 09:01:37 -07:00
Anton Korobeynikov
c4ebb3249f Properly transfer location info from debug_value into alloc_stack: we need to drop op_deref expression (#42245)
In order to transfer debug info from `debug_value` to `alloc_stack` we need to drop `op_ref` debug expression, as the latter instruction represents the location and not the value itself. Also, fix the debug info verifier as variable type was deduced from `alloc_stack` / `alloc_box` improperly: pointer type of instruction itself was used instead of underlying object type.

The issue is only exposed when both optimizations (SIL mem2reg at least) and debug info are enabled

Resolves SR-15849
2022-04-21 08:03:21 -07:00
Philip Turner
2af1460ce6 [AutoDiff] Introduce regression test for SR-15849 (#41717) 2022-03-08 13:13:00 -08:00
Anton Korobeynikov
4b7baf000c [AutoDiff] Properly collect inout parameter adjoints (#41559)
Apparently, the parameter index calculation in #37861 was not always correct in presence of other pullback parameters (e.g. captures and non-differentiated args). Collect all inout parameters and collect inout parameter adjoints correctly.

Resolves SR-15891
2022-02-25 14:09:59 -08:00
Richard Wei
b0a038bd66 Merge pull request #41401 from asl/sr15205-fix
[AutoDiff] Fix several issues related to captured arguments
2022-02-16 16:45:10 -08:00
Richard Wei
7151608e21 Disable an autodiff test on Linux to unblock CI.
AutoDiff/compiler_crashers_fixed/rdar71191415-nested-differentiation-of-extension-method-optimized.swift is starting to fail recently. Tracked by rdar://89055298.
2022-02-16 16:34:10 -08:00
Anton Korobeynikov
91458b4890 Fix several issues related to captured arguments:
- Introduce a workaround while dealing with getLoweredParameterIndices() results:
    it operates on AST and therefore does not take into account captured arguments
    which are "on side" on AST and explicit in SIL
  - Ensure captured arguments (@inout_aliased) are handled in a same way as ordinary
    @inout arguments while generating a pullback type

Fixes SR-15205
2022-02-17 00:04:12 +03:00
Robert Widmann
3511314952 Disable Flaky Test
Disable an autodiff test that's causing the linker on Ubuntu 20.04 to crash every so often

rdar://87254800
2022-01-07 09:08:07 -08:00
Robert Widmann
e5885871e0 Disable Flaky Compiler Crasher Test
This test appears to cause the linker to crash every so often.

rdar://86041709
2022-01-05 13:31:32 -08:00
Richard Wei
cf2ccf1072 [AutoDiff] Use auto-generated locations for temporary allocations.
In `TangentBuilder` temporary allocations are emitted in order to make generic calls to `AdditiveArithmetic.zero` and `AdditiveArithmetic.+`. When we perform accumulation of two adjoint values that correspond to a lexical value in the original function, the stack allocations require a debug variable, as we use the original instruction's location. However such a debug variable wouldn't really make sense as these temporary allocations do not represent the original variable's adjoint. With lexical borrow scopes, we hit a crasher when creating temporary allocations when accumulating adjoints for lexical `begin_borrow` instructions.

This PR makes `TangentBuilder`'s temporary allocations use an auto-generated location. The existing debug info emission behavior is not changed, as we still emit `debug_value` when materializing an `AdjointValue` after any necessary adjoint accumulation.
2021-12-10 12:32:16 -08:00
Erik Eckstein
7caf9902e8 tests: disable a flaky AutoDiff test 2021-12-05 13:45:48 +01:00
Richard Wei
9bcba98213 Revert "Revert "[AutoDiff] Fix two derivative type calculation bugs caught by RequirementMachine""
This reverts commit 262965418f.
2021-11-05 10:29:08 -07:00
Richard Wei
1a4ea67e2c [AutoDiff] Plumb witness derivative generic signatures through SILGen.
When SILGenWitnessTable creates a decl ref for the witness of a derivative function requirement, it is using the requirement's derivative generic signature in the resulting witness decl ref. This is wrong because the witness may have a different derivative generic signature than the requirement, leading to a crash. This bug was never discovered because GSB's dark magic made it "just work", until requirement machine.

The fix is to store the matched witness derivative generic signature in `Witness` during type checking, and during witness table generation, use the witness' generic signature to create a witness decl ref.

Resolves rdar://84716758, rdar://84213107 and rdar://84987079.
2021-11-05 10:28:33 -07:00
Doug Gregor
262965418f Revert "[AutoDiff] Fix two derivative type calculation bugs caught by RequirementMachine" 2021-11-04 15:56:48 -07:00
Richard Wei
90ec31a068 [AutoDiff] Compute derivative types using requirements from archetypes.
Resolves rdar://84213107 and partially resolves rdar://82549134.
2021-10-13 21:23:17 -07:00
Richard Wei
808c7ec783 [AutoDiff] Fix two derivative type calculation bugs caught by RequirementMachine.
1. When calculating the differential type of an original function with an inout parameter and when the inout parameter has a type parameter, the inout parameter should get a generic parameter in the subst generic signature of the differential but it currently doesn't. This causes SILGen to attempt to reabstract the differential value in the JVP protocol witness thunk, whilst the generic signature is lacking requirements, leading to a requirement machine error. This patch fixes the calculation so that the JVP's result type (the differential type) always matches the witness thunk's result type.

    Wrong type:
    ```swift
             sil private [transparent] [thunk] [ossa] @... <τ_0_0 where τ_0_0 : Differentiable> (...) -> @owned @callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <τ_0_0.TangentVector, τ_0_0.TangentVector> {
               %6 = differentiable_function_extract [jvp] %5 : $@differentiable(reverse) @convention(method) <τ_0_0 where τ_0_0 : Differentiable> (@in_guaranteed τ_0_0, @noDerivative @inout τ_0_0, @noDerivative SR_13305_Struct) -> () // user: %7
    HERE ====> %7 = apply %6<τ_0_0>(%0, %1, %3) : $@convention(method) <τ_0_0 where τ_0_0 : Differentiable> (@in_guaranteed τ_0_0, @inout τ_0_0, SR_13305_Struct) -> @owned @callee_guaranteed @substituted <τ_0_0> (@in_guaranteed τ_0_0) -> @out τ_0_0 for <τ_0_0.TangentVector>
    ```

    Should be:
    ```swift
      %7 = apply %6<τ_0_0>(%0, %1, %3) : $@convention(method) <τ_0_0 where τ_0_0 : Differentiable> (@in_guaranteed τ_0_0, @inout τ_0_0, SR_13305_Struct) -> @owned @callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <τ_0_0.TangentVector, τ_0_0.TangentVector>
    ```

2. `TypeConverter::makeConstantInterfaceType` is not passing down the derivative generic signature to `SILFunctionType::getAutoDiffDerivativeFunctionType` for class methods, and this was caught by RequirementMachine during vtable emission. This patch fixes that.

Partially resolves rdar://82549134. The only remaining tests that require `-requirement-machine=off` are SILOptimizer/semantic_member_accessors_sil.swift and SILOptimizer/differentiation_diagnostics.swift which I will fix next. Then I'll do a proper fix for workaround #39416.
2021-09-30 20:51:36 -07:00
Slava Pestov
bbb71962f0 AutoDiff: Workaround for performing generic signature queries on the wrong signature 2021-09-23 13:24:40 -04:00
Slava Pestov
b57be6dbf1 Revert "AutoDiff: Disable requirement machine when building or testing Differentiation library"
This reverts commit 4f6ba29715.
2021-09-23 13:24:40 -04:00
Hamish Knight
7fd5d461fa Revert "[test] Disable a couple of AutoDiff tests" 2021-08-24 21:41:15 +01:00
Hamish Knight
9bec7c258f [test] Disable a couple of AutoDiff tests
Temporarily disable on non-macOS platforms until
the CI is fixed.

rdar://82240971
2021-08-23 13:52:51 +01:00
Holly Borla
71cbd24750 [Test] Mark sr14240-symbol-in-ir-file-not-tbd-file.swift to require
an executable test.
2021-08-13 09:11:20 -07:00
Brad Larson
4a86174868 [AutoDiff] [SR-14240] Align name mangling for Clang-imported declarations (#38850)
* Adding fix for handling Clang-imported names, along with test case.

* Correct EOL.
2021-08-12 17:09:37 -06:00
Slava Pestov
4f6ba29715 AutoDiff: Disable requirement machine when building or testing Differentiation library
The SIL type lowering logic for AutoDiff gets the substituted generic signature
mixed up with the invocation generic signature, so it tries to ask questions
about DependentMemberTypes in a signature with no requirements. This triggers
assertions when the requirement machine is enabled.

Disable the requirement machine until this is fixed.
2021-07-30 19:42:31 -04:00
Robert Widmann
e87a583cfd Disable Flaky AutoDiff Test
This test fails to link every once in a while.

See https://bugs.swift.org/browse/SR-14775
2021-06-14 13:01:13 -07:00
Brad Larson
2e73e708b5 Proposed fix, with test, for SR-14625's over-consume. 2021-06-03 21:12:30 -05:00