Commit Graph

8065 Commits

Author SHA1 Message Date
Slava Pestov
1af01edbf0 Merge pull request #30965 from slavapestov/enable-dynamic-replacement-vs-library-evolution
Enable dynamic replacement with library evolution
2020-04-11 01:39:09 -04:00
Slava Pestov
23cac673ca IRGen: Enable dynamic replacement with library evolution
It looks like the only thing that fails is the linkage computation
for the dynamic replacement key of class methods. Even though
methods have hidden linkage to prevent them from being directly
referenced from outside a resilient module, we need to ensure
the dynamic replacement key is visible.

Fixes <rdar://problem/58457716>.
2020-04-10 22:53:36 -04:00
Slava Pestov
0724c47a8b IRGen: Fix simple_display(IRGenDescriptor) 2020-04-10 15:05:54 -04:00
Slava Pestov
f12b0d4977 IRGen: Type reconstruction supports opaque result types now 2020-04-10 15:05:54 -04:00
Nate Chandler
240fd09364 [metadata prespecialization] Not always on for stdlib.
Prespecializing metadata in the stdlib looks to be exposing a bug in its
implementation.  Disabling for now.
2020-04-08 08:07:49 -07: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
Dan Zheng
c834696bfa Add SynthesizedFileUnit.
`SynthesizedFileUnit` is a container for synthesized declarations. Currently, it
only supports module-level declarations.

It is used by the SIL differentiation transform, which generates implicit struct
and enum declarations.
2020-04-07 18:29:26 -07:00
Arnold Schwaighofer
66ea6e6f38 Merge pull request #30839 from aschwaighofer/irgen_fix_partial_apply_on_stack_indirect
IRGen: Fix capture of indirect values in ``[onstack]`` closures
2020-04-07 06:09:00 -07:00
Dan Zheng
fccfa29240 [AutoDiff upstream] Update LoadableByAddress. (#30825)
Update LoadableByAddress to handle AutoDiff-related instructions:
- `differentiable_function`
- `differentiable_function_extract`
- `linear_function`
- `linear_function_extract`
- `differentiability_witness_function`
2020-04-06 16:47:38 -07:00
Arnold Schwaighofer
5ab6df8f94 IRGen: Fix capture of indirect values in `[onstack]` closures
A [onstack] closure does not take ownership of its arguments. It is
therefore not correct to use an initWithTake copy of indirect arguments.

Instead we just capture the address of the indirect argument.

rdar://61261982
2020-04-06 13:23:34 -07:00
nate-chandler
9c1a70358c Merge pull request #30796 from nate-chandler/generic-metadata-prespecialization-components/require-same-file
[prespecialized metadata] Require same file without wmo.
2020-04-03 18:31:09 -07:00
Nate Chandler
6c178c7c62 [prespecialized metadata] Require same file without wmo.
Without whole module optimization, the metadata accessors are emitted on
a per-file basis.  The result is that if the file containing a generic
type is processed before the file containing a usage of that type that
would result in that prespecialization, the metadata accessor would have
already been emitted by the time that the usage is noted, making it
impossible for the newly created prespecialization to be returned from
the already-emitted metadata accessor.

Here, require that either whole module optimization is enabled so that
the metadata accessors are all emitted at once at the end, or else that
the usage of the prespecialization is in the same file as the type is
declared.
2020-04-03 15:37:36 -07:00
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
Robert Widmann
630d0f631a Merge pull request #30606 from AnthonyLatsis/rename-getfullname
[NFC] Preparations to address the «Rename to getName?» TODO on ValueDecl::getFullName
2020-04-01 09:00:04 -07:00
Robert Widmann
aa0bf50323 Merge pull request #30723 from CodaFi/dependendable-dependencies
[Evaluator] Online Request-Based Incremental Dependency Tracking
2020-03-31 18:13:05 -07:00
Robert Widmann
9b4e014cf2 Define high-level dependency sources
Plug high-level requests that define dependency sources into the evaluator's incremental infrastructure.
2020-03-31 16:16:53 -07:00
Artem Chikin
1b11e8798c [IRGen] Skip witness table query for protocols that do not require one
Some protocols, such as protocols marked with 'objc', do not have a Witness Table.
The code before this patch assumes all protocols do have a Witness Table when generating the layout of an OpaqueTypeDescriptor, causing an assert to be triggered for opaque return types that conform to an 'objc' protocol.

Fixes SR-12257 / rdar://problem/59740179
2020-03-31 10:56:20 -07:00
Anthony Latsis
c63b737e92 Collapse all indirect equivalents to ValueDecl::getBaseIdentifier 2020-03-29 00:36:01 +03:00
Anthony Latsis
d0ae3ee580 [AST] Replace FuncDecl::getName & EnumElementDecl::getName with ValueDecl::getBaseIdentifier 2020-03-29 00:35:51 +03:00
marcrasi
d067e7e18c [AutoDiff upstream] more IRGen for @differentiable functions (#30688) 2020-03-28 12:27:08 -07:00
Dan Zheng
c1fe0e37ba [AutoDiff upstream] Add differentiable function type mangling. (#30675)
Add mangling scheme for `@differentiable` and `@differentiable(linear)` function
types. Mangling support is important for debug information, among other things.

Update docs and add tests.

Resolves TF-948.
2020-03-27 12:02:55 -07:00
Robert Widmann
1f904ca86d Merge pull request #30669 from CodaFi/consteval
[NFC] A Handful of Sweeping Evaluator Cleanups
2020-03-27 09:43:28 -07:00
Arnold Schwaighofer
94e9aeb1a2 Merge pull request #30667 from aschwaighofer/revert_objc_protocol_method_uniquing
Revert "Merge pull request #30612 from aschwaighofer/irgen_also_uniqu…
2020-03-27 08:36:53 -07:00
Robert Widmann
987cd55f50 [NFC] Drop llvm::Expected from Evaluation Points
A request is intended to be a pure function of its inputs. That function could, in theory, fail. In practice, there were basically no requests taking advantage of this ability - the few that were using it to explicitly detect cycles can just return reasonable defaults instead of forwarding the error on up the stack.

This is because cycles are checked by *the Evaluator*, and are unwound by the Evaluator.

Therefore, restore the idea that the evaluate functions are themselves pure, but keep the idea that *evaluation* of those requests may fail. This model enables the best of both worlds: we not only keep the evaluator flexible enough to handle future use cases like cancellation and diagnostic invalidation, but also request-based dependencies using the values computed at the evaluation points. These aforementioned use cases would use the llvm::Expected interface and the regular evaluation-point interface respectively.
2020-03-26 23:08:02 -07:00
Robert Widmann
4accf59a3b Merge pull request #30618 from CodaFi/protocol-adoption-program
[NFC] Add LookupConformancesInContextRequest
2020-03-26 17:18:55 -07:00
Arnold Schwaighofer
c9d490c5a9 Revert "Merge pull request #30612 from aschwaighofer/irgen_also_unique_ext_method_types_list"
This reverts commit f0cdd76f18, reversing
changes made to 703fe0f1a1.

Revert "IRGen: Refactor getObjCEncodingForMethod and getObjectEncodingFromClangNode into one"

This reverts commit 0082682b0d.

Revert "Merge pull request #30438 from aschwaighofer/irgen_prefer_clang_type_encoding"

This reverts commit eeb7fa52b2, reversing
changes made to 77af77fa8a.

Revert "Merge pull request #30433 from aschwaighofer/irgen_no_duplicate_objc_method_descriptor_entries"

This reverts commit 77af77fa8a, reversing
changes made to 841eeb05b0.

This reverts the changes for

rdar://60461850, rdar://60474785, rdar://60778637

There is still at least an issue that we address with PR#30654.

Revert until we have confidence that this is the right fix set.
2020-03-26 15:00:15 -07:00
ematejska
75691d641e [AutoDiff upstream] Add linear function SIL instructions (#30638)
Add `linear_function` and `linear_function_extract` instructions.

`linear_function` creates a `@differentiable(linear)` function-typed value from
an original function operand and a transpose function operand (optional).

`linear_function_extract` extracts either the original or transpose function
value from a `@differentiable(linear)` function.

Resolves TF-1142 and TF-1143.
2020-03-26 09:41:14 -07:00
Dan Zheng
e5cb871428 [AutoDiff upstream] Add flag-gated AdditiveArithmetic derivation. (#30628)
Add `AdditiveArithmetic` derived conformances for structs, gated by the
`-enable-experimential-additive-arithmetic-derivation` flag.

Structs whose stored properties all conform to `AdditiveArithmetic` can derive
`AdditiveArithmetic`:
- `static var zero: Self`
- `static func +(lhs: Self, rhs: Self) -> Self`
- `static func -(lhs: Self, rhs: Self) -> Self`
- An "effective memberwise initializer":
  - Either a synthesized memberwise initializer or a user-defined initializer
    with the same type.

Effective memberwise initializers are used only by derived conformances for
`Self`-returning protocol requirements like `AdditiveArithmetic.+`, which
require memberwise initialization.

Resolves TF-844.
Unblocks TF-845: upstream `Differentiable` derived conformances.
2020-03-25 10:31:50 -07:00
marcrasi
025cb9a501 autodiff builtins (#30624)
Define type signatures and SILGen for the following builtins:

```
/// Applies the {jvp|vjp} of `f` to `arg1`, ..., `argN`.
func applyDerivative_arityN_{jvp|vjp}(f, arg1, ..., argN) -> jvp/vjp return type

/// Applies the transpose of `f` to `arg`.
func applyTranspose_arityN(f, arg) -> transpose return type

/// Makes a differentiable function from the given `original`, `jvp`, and
/// `vjp` functions.
func differentiableFunction_arityN(original, jvp, vjp)

/// Makes a linear function from the given `original` and `transpose` functions.
func linearFunction_arityN(original, transpose)
```

Add SILGen FileCheck tests for all builtins.
2020-03-25 02:36:42 -07:00
Mishal Shah
88b093e9d7 Merge pull request #30615 from apple/post-back-master-xcode-11.4
Update master to build with Xcode 11.4
2020-03-24 17:19:37 -07:00
Arnold Schwaighofer
f0cdd76f18 Merge pull request #30612 from aschwaighofer/irgen_also_unique_ext_method_types_list
IRGen: Also unique selectors in extended method types list
2020-03-24 12:42:59 -07:00
Robert Widmann
a9e11e3130 [NFC] Separate Taking Redundant Conformance Diagnostics From The Lookup Table 2020-03-24 12:40:11 -07:00
Mishal Shah
e7cd5ab17f Update master to build with Xcode 11.4 2020-03-24 11:30:45 -07:00
Arnold Schwaighofer
e344971de7 IRGen: Also unique selectors in extended method types list
rdar://60778637
2020-03-24 09:39:44 -07:00
Slava Pestov
ac4ca6dffa IRGen: Don't call getConditionalRequirementsIfAvailable()
We should not fail silently here if the conditional requirements
could not be computed due to a cycle.
2020-03-23 18:59:43 -04:00
Dan Zheng
62f6686da4 Merge pull request #30579 from dan-zheng/autodiff-upstream-sil
[AutoDiff upstream] [SIL] Add differentiable function instructions.
2020-03-23 12:18:19 -07:00
Joe Groff
b0ca53fcf3 Merge pull request #30546 from jckarter/mangle-any-protocol-conformance
Factor `appendAnyProtocolConformance` out of the conformance mangling.
2020-03-23 11:47:34 -07:00
Dan Zheng
cc7e9fc39e [AutoDiff upstream] [SIL] Add differentiable function instructions.
Add `differentiable_function` and `differentiable_function_extract`
instructions.

`differentiable_function` creates a `@differentiable` function-typed
value from an original function operand and derivative function operands
(optional).

`differentiable_function_extract` extracts either the original or
derivative function value from a `@differentiable` function.

The differentiation transform canonicalizes `differentiable_function`
instructions, filling in derivative function operands if missing.

Resolves TF-1139 and TF-1140.
2020-03-22 23:53:43 -07:00
Dan Zheng
603db8c954 [AutoDiff upstream] Add @differentiable function IRGen.
Lower `@differentiable` and `@differentiable(linear)` functions as structs of
function pointers.
2020-03-22 23:52:28 -07:00
Dan Zheng
723b2d2cbe [AutoDiff upstream] Add derivative function witness/vtable entry SILGen. (#30569)
`@differentiable` attribute on protocol requirements and non-final class
members now produces derivative function entries in witness tables and vtables.

This enables `witness_method` and `class_method` differentiation.

Existing type-checking rules:

- Witness declarations of `@differentiable` protocol requirements must have a
  `@differentiable` attribute with the same configuration (or a configuration
  with superset parameter indices).
  - Witness table derivative function entries are SILGen'd for `@differentiable`
    witness declarations.

- Class vtable derivative function entries are SILGen'd for non-final
  `@differentiable` class members.
  - These derivative entries can be overridden or inherited, just like other
    vtable entries.

Resolves TF-1212.
2020-03-22 16:59:01 -07:00
Joe Groff
ee08197010 Factor appendAnyProtocolConformance out of the conformance mangling.
We want to be able to use mangled names to refer to protocol conformances in addition to type
metadata. Provide an ASTMangler method that can render an arbitrary abstract or concrete
`ProtocolConformanceRef`, factoring it out of the code used to emit conditional conformance arguments
in `appendProtocolConformance`.
2020-03-20 15:06:42 -07:00
Arnold Schwaighofer
4dec4abcd0 Merge pull request #30472 from aschwaighofer/irgen_typelayout_use_heuristic
IRGen: Only use type layouts when we expect the generated IR to be faster
2020-03-19 17:44:04 -07:00
Joe Groff
faec5866a4 Merge pull request #30489 from jckarter/swift-52-opaque-type-mangling
IRGen: Use mangled names to access opaque type associated types in Swift >=5.2.
2020-03-19 12:01:49 -07:00
Joe Groff
b4abd44e03 Merge pull request #30479 from jckarter/disable-mangled-name-metadata
IRGen: Add a flag to disable mangled name type metadata accessors.
2020-03-19 12:01:38 -07:00
Slava Pestov
9ec80df97e SIL: Remove curried SILDeclRefs 2020-03-19 02:20:21 -04:00
Joe Groff
b636a07070 IRGen: Use mangled names to access opaque type associated types in Swift >=5.2. 2020-03-18 16:43:09 -07:00
Arnold Schwaighofer
71599b711c IRGen: Only use type layouts when we expect the generated IR to be faster
If there the layout is not dependent on archetypes and but has resilient types
using the new type layout based approach is not going to be faster.

rdar://59960653
2020-03-18 14:54:04 -07:00
Arnold Schwaighofer
13cd05cfb1 TypeLayout: Add containsResilient and containsArchetype
We'll use that in a follow-up commit.
2020-03-18 14:54:04 -07:00
Joe Groff
72b13e8c65 IRGen: Add a flag to disable mangled name type metadata accessors.
Useful as a workaround for runtime demangler bugs, or in rare cases where there are
performance problems with the demangler.
2020-03-18 13:55:01 -07:00
swift-ci
270f734403 Merge pull request #30435 from zoecarver/fix/builtin-is-dead 2020-03-17 20:48:59 -07:00