Commit Graph

117 Commits

Author SHA1 Message Date
Dan Zheng
56c8ebabbd [SIL] Fix alloc_stack [dynamic_lifetime] attribute cloning.
Make `SILCloner:visitAllocStack` correctly propagate the `[dynamic_lifetime]`
attribute.

Resolves SR-12886: differentiation transform error related to the `VJPEmitter`
subclass of `SILCloner`.
2020-05-29 01:56:42 -07:00
Suyash Srijan
d53cd535ba [Typechecker] Emit a specialised diagnostic for redeclaration errors when the declaration is synthesised (#31915)
* [Typechecker] Emit a specialized diagnostic for redeclaration errors when the declaration is synthesized

* [Test] Update existing tests

* [Typechecker] Diagnose the original wrapped property instead of the nearest non-implicit decl context

* [Test] Update existing tests

* [Typechecker] Do not diagnose redeclarations when both declarations are implicit

* [Test] Update a AutoDiff test
2020-05-21 17:37:55 +01:00
Dan Zheng
ffca352daf [AutoDiff] Remove flaky SR-12650 negative test. (#31919)
`@noDerivative` parameter mangling was added, so the test is not meaningful.
The test occasionally flaked during CI, so it is better to remove it.
2020-05-20 14:55:39 -07:00
Slava Pestov
653fa07260 GSB: Fix maybeResolveEquivalenceClass() with member type of superclass-constrained type
Name lookup might find an associated type whose protocol is not in our
conforms-to list, if we have a superclass constraint and the superclass
conforms to the associated type's protocol.

We used to return an unresolved type in this case, which would result in
the constraint getting delayed forever and dropped.

While playing wack-a-mole with regressing crashers, I had to do some
refactoring to get all the tests to pass. Unfortuanately these refactorings
don't lend themselves well to being peeled off into their own commits:

- maybeAddSameTypeRequirementForNestedType() was almost identical to
  concretizeNestedTypeFromConcreteParent(), except for superclasses
  instead of concrete same-type constraints. I merged them together.

- We used to drop same-type constraints where the subject type was an
  ErrorType, because maybeResolveEquivalenceClass() would return an
  unresolved type in this case.

  This violated some invariants around nested types of ArchetypeTypes,
  because now it was possible for a nested type of a concrete type to
  be non-concrete, if the type witness in the conformance was missing
  due to an error.

  Fix this by removing the ErrorType hack, and adjusting a couple of
  other places to handle ErrorTypes in order to avoid regressing with
  invalid code.

Fixes <rdar://problem/45216921>, <https://bugs.swift.org/browse/SR-8945>,
<https://bugs.swift.org/browse/SR-12744>.
2020-05-19 20:28:51 -04:00
Dan Zheng
7fbfbc5dda [AutoDiff] Fix derivative forwarding thunk linkage. (#31726)
Make derivative forwarding thunks use original function's linkage instead of the
derivative function's, stripping external.

This is consistent with the linkage of differentiability witnesses.

Clarify AutoDiff linkage-related comments.

Resolves TF-1160: TBDGen error due to incorrect derivative thunk linkage.
2020-05-12 06:07:06 -07:00
Dan Zheng
96f3f6fbcb [AutoDiff] Finish wrapped property differentiation support.
Add special-case VJP generation support for "semantic member accessors".
This is necessary to avoid activity analysis related diagnostics and simplifies
generated code.

Fix "wrapped property mutability" check in `Differentiable` derived conformnances.
This resolves SR-12642.

Add e2e test using real world property wrappers (`@Lazy` and `@Clamping`).
2020-05-10 15:55:29 -07:00
marcrasi
ce5e0e774c [AutoDiff] Fix SR-12641: Handle address-only types in derivative fn types (#31496)
* The update in `SILFunctionType.cpp` fixes SR-12641 by making address-only parameters/results in differentials have indirect convention.
* I updated the crasher test to use a resilient struct defined in the test, instead of `Tracked<Float>`, so that the test does not need to depend on `DifferentiationUnittest`.
* The update in `VJPEmitter.cpp` fixes a similar issue with pullbacks that I discovered while investigating.
* I added code that exposes this new issue to the SR-12641 crasher test.
2020-05-05 12:29:10 -07:00
Dan Zheng
bab23d8298 SILOptimizer: fix partial_apply optimization. (#31552)
`partial_apply` can be rewritten to `thin_to_thick_function` only if the
specialized callee is `@convention(thin)`.

This condition is newly exercised by the differentiation transform:
`{JVP,VJP}Emitter::visitApplyInst` generates argument-less `partial_apply`
with `@convention(method)` callees.

Resolves SR-12732.
2020-05-05 09:09:42 -07:00
Varun Gandhi
a1716fe2a6 [Diagnostics] Update compiler diagnostics to use less jargon. (#31315)
Fixes rdar://problem/62375243.
2020-04-28 14:11:39 -07:00
Dan Zheng
8357c188eb [AutoDiff] Mangle @noDerivative parameters. (#31201)
Mangle `@noDerivative` parameters to fix type reconstruction errors.
Resolves SR-12650. The new mangling is non-breaking.

When differentiation supports multiple result indices and `@noDerivative`
results are added, we can reuse some of this mangling support.
2020-04-22 12:38:21 -07:00
Dan Zheng
e9ed2d50cf [AutoDiff] Fix @derivative attribute type-checking crash. (#30936)
Fix `@derivative` attribute type-checking crash, so far reproducible only via
`-parse-stdlib`.

The crash occurs because it is not sufficient for type-checking to check for
`Differentiable` conformances. We must also check for invalid `TangentVector`
associated types.

Resolves SR-12559.
2020-04-10 02:14:02 -07:00
Dan Zheng
c142fcf6e2 [AutoDiff] Add SynthesizedFileUnit TBDGen/serialization tests.
Upstream `SynthesizedFileUnit` failing tests from TF-1239.
2020-04-08 21:22:06 -07:00
Dan Zheng
606c070e11 [SILOptimizer] Disable SILCombiner::visitPartialApplyInst for method callees.
Disable `SILCombiner::visitPartialApplyInst` from rewriting `partial_apply` with
with `@convention(method)` callee to `thin_to_thick_function`.

This fixes SIL verification errors: `thin_to_thick_function` only supports
`@convention(thin)` operands.

Resolves SR-12548.
2020-04-08 12:40:44 +00:00
Dan Zheng
f7a9eed4de [AutoDiff] Add generated implicit declarations to SynthesizedFileUnit.
Add implicit declarations generated by the differentiation transform to a
`SynthesizedFileUnit` instead of an ad-hoc pre-existing `SourceFile`.

Resolves TF-1232: type reconstruction for AutoDiff-generated declarations.

Previously, type reconstruction failed because retroactively adding declarations
to a `SourceFile` did not update name lookup caches.
2020-04-07 18:29:34 -07:00
marcrasi
15f512b81b [AutoDiff] fix SR-12493 (#30817)
We simply needed to upstream `TypeSubstCloner::visitDifferentiableFunctionExtractInst`.
The code has a detailed comment explaining what it does.
2020-04-05 19:36:10 -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
Dan Zheng
1cefebe227 [AutoDiff] Fix @differentiable-related override matching crash. (#29985)
Remove meaningless `assert(false)` assertion from
`hasOverridingDifferentiableAttribute` in `TypeCheckDeclOverride.cpp`.

The assertion served no purpose and can safely be removed.

Resolves TF-1167. Add test.
2020-02-21 09:29:29 -08:00