Commit Graph

521 Commits

Author SHA1 Message Date
Robert Widmann
bdabeae98c Merge pull request #30609 from gribozavr/sil-rst
Removed a description of curried functions
2020-04-13 13:14:20 -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
Dmitri Gribenko
05cbd9702c Removed a description of curried functions
Curried functions were removed in 2016 in 983a674e0.
2020-03-24 14:42:18 +01: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
aab622e913 [AutoDiff upstream] Add derivative function SILDeclRefs. (#30564)
`@differentiable` attribute on protocol requirements and non-final class members
will produce derivative function entries in witness tables and vtables.

This patch adds an optional derivative function configuration
(`AutoDiffDerivativeFunctionIdentifier`) to `SILDeclRef` to represent these
derivative function entries.

Derivative function configurations consist of:
- A derivative function kind (JVP or VJP).
- Differentiability parameter indices.

Resolves TF-1209.
Enables TF-1212: upstream derivative function entries in witness tables/vtables.
2020-03-22 11:50:29 -07:00
Dmitri Gribenko
e715ebdfdd Fix documentation for alloc_existential_box
Remove the description of the second element of the return tuple: this
instruction has been returning only one value since b7ea3b9bb2.
2020-03-20 14:55:53 +01:00
Slava Pestov
9ec80df97e SIL: Remove curried SILDeclRefs 2020-03-19 02:20:21 -04:00
Erik Eckstein
ae93e60072 SIL: add a lazy_property_getter flag to SILFunction
It is set on getter-functions for lazy properties.
2020-03-13 09:49:55 +01:00
Erik Eckstein
cc0afcb838 docs: document SILFunction attributes in SIL.rst
Well, at least mention them. There could be more documentation about the attributes.
2020-03-12 14:00:05 +01:00
John McCall
ceff414820 Distinguish invocation and pattern substitutions on SILFunctionType.
In order to allow this, I've had to rework the syntax of substituted function types; what was previously spelled `<T> in () -> T for <X>` is now spelled `@substituted <T> () -> T for <X>`.  I think this is a nice improvement for readability, but it did require me to churn a lot of test cases.

Distinguishing the substitutions has two chief advantages over the existing representation.  First, the semantics seem quite a bit clearer at use points; the `implicit` bit was very subtle and not always obvious how to use.  More importantly, it allows the expression of generic function types that must satisfy a particular generic abstraction pattern, which was otherwise impossible to express.

As an example of the latter, consider the following protocol conformance:

```
protocol P { func foo() }
struct A<T> : P { func foo() {} }
```

The lowered signature of `P.foo` is `<Self: P> (@in_guaranteed Self) -> ()`.  Without this change, the lowered signature of `A.foo`'s witness would be `<T> (@in_guaranteed A<T>) -> ()`, which does not preserve information about the conformance substitution in any useful way.  With this change, the lowered signature of this witness could be `<T> @substituted <Self: P> (@in_guaranteed Self) -> () for <A<T>>`, which nicely preserves the exact substitutions which relate the witness to the requirement.

When we adopt this, it will both obviate the need for the special witness-table conformance field in SILFunctionType and make it far simpler for the SILOptimizer to devirtualize witness methods.  This patch does not actually take that step, however; it merely makes it possible to do so.

As another piece of unfinished business, while `SILFunctionType::substGenericArgs()` conceptually ought to simply set the given substitutions as the invocation substitutions, that would disturb a number of places that expect that method to produce an unsubstituted type.  This patch only set invocation arguments when the generic type is a substituted type, which we currently never produce in type-lowering.

My plan is to start by producing substituted function types for accessors.  Accessors are an important case because the coroutine continuation function is essentially an implicit component of the function type which the current substitution rules simply erase the intended abstraction of.  They're also used in narrower ways that should exercise less of the optimizer.
2020-03-07 16:25:59 -05:00
Erik Eckstein
a637b89c29 docs: add documentation for the [dynamic_lifetime] attribute of alloc_stack in SIL.rst 2020-03-05 13:12:08 +01:00
Dan Zheng
a49428ca7c [AutoDiff upstream] Add differentiability_witness_function instruction. (#29765)
The `differentiability_witness_function` instruction looks up a
differentiability witness function (JVP, VJP, or transpose) for a referenced
function via SIL differentiability witnesses.

Add round-trip parsing/serialization and IRGen tests.

Notes:
- Differentiability witnesses for linear functions require more support.
  `differentiability_witness_function [transpose]` instructions do not yet
  have IRGen.
- Nothing currently generates `differentiability_witness_function` instructions.
  The differentiation transform does, but it hasn't been upstreamed yet.

Resolves TF-1141.
2020-02-13 16:55:46 -08:00
Dan Zheng
849bd62a26 [AutoDiff upstream] Add SIL differentiability witnesses. (#29623)
SIL differentiability witnesses are a new top-level SIL construct mapping
"original" SIL functions to derivative SIL functions.

SIL differentiability witnesses have the following components:
- "Original" `SILFunction`.
- SIL linkage.
- Differentiability parameter indices (`IndexSubset`).
- Differentiability result indices (`IndexSubset`).
- Derivative `GenericSignature` representing differentiability generic
  requirements (optional).
- JVP derivative `SILFunction` (optional).
- VJP derivative `SILFunction` (optional).
- "Is serialized?" bit.

This patch adds the `SILDifferentiabilityWitness` data structure, with
documentation, parsing, and printing.

Resolves TF-911.

Todos:
- TF-1136: upstream `SILDifferentiabilityWitness` serialization.
- TF-1137: upstream `SILDifferentiabilityWitness` verification.
- TF-1138: upstream `SILDifferentiabilityWitness` SILGen from
  `@differentiable` and `@derivative` attributes.
- TF-20: robust mangling for `SILDifferentiabilityWitness` names.
2020-02-04 12:53:27 -08:00
Michael Gottesman
c97a0cf2d6 [sil.rst] Clarify documentation around partial_apply closure contexts/closed over parameters. 2020-01-24 12:25:44 -08:00
Robert Widmann
266f2c8912 Merge pull request #16589 from kitasuke/update_documentation_of_alloc_stack_for_sil
[Gardening] Update alloc_stack documentation in SIL.rst
2019-12-02 10:34:08 -08:00
Michael Gottesman
7ee5ad7318 [sil] Rename {,Strong}Copy{Unowned,Unmanaged}. 2019-10-26 17:03:47 -07:00
Michael Gottesman
a84497b834 [sil.rst] Try to make it clearer that copy_unmanaged_value performs a "strong copy" of the underlying value. 2019-09-25 18:59:07 -07:00
Varun Gandhi
2255e81ad0 [NFC] Replacing potentially confusing phrase "memory allocation promotion" 2019-09-18 10:30:36 -07:00
Andrew Trick
7b1b0a0077 Add comments to destroy_addr in SIL.rst.
`destroy_addr` is never semantically a "no-op". Just because an
instruction can be safely eliminated does not mean the instruction has
no semantics! That would be like saying we could move an unknown
memory read below an otherwise dead store!
2019-09-12 16:21:39 -07:00
Erik Eckstein
3d0b12e7bc MemoryLifetime: fix a problem where DestroyHoisting moved a destroy_addr before a use of a trivial type.
Even if a destroy_addr of a trivial type is a no-op, we must not end up with using such a value after a destroy_addr.
The fix is to also handle aggregate fields of trivial types in MemoryLifetime.

rdar://problem/55125020
2019-09-11 13:49:23 +02:00
Michael Gottesman
d05dc8ac31 [SIL.rst] Add docs for copy_unowned_value and copy_unmanaged_value.
This commit adds docs for copy_unmanaged_value to SIL.rst as requested by
@eeckstein in #26839. I noticed while doing the PR that copy_unowned_value was
also not documented, so I added docs for it as well as a bonus. = ).
2019-08-26 09:28:16 -07:00
Joe Groff
ca4c2211b9 Merge pull request #26523 from rxwei/clarify-partial-apply-inout-aliasable
[Docs] Clarify partial_apply's ownership of @inout_aliasable arguments.
2019-08-10 11:42:15 -07:00
Erik Eckstein
282907fc0a Fix property wrappers with tuples.
In case of a tuple as value type, the initializer and setter takes the tuple elements as separate arguments. This was just not handled in the assign_by_wrapper instruction lowering.

rdar://problem/53866473
2019-08-08 21:46:08 +02:00
Richard Wei
ffa9c40047 [Docs] Clarify partial_apply's ownership of @inout_aliasable arguments.
`partial_apply` does not own `@inout_aliasable` arguments, so the original description "the closure does however take ownership of the partially applied arguments" is not accurate. This patch makes things clear.
2019-08-06 15:50:00 -07:00
Richard Wei
642cc3c074 [Docs] Fix typo in SIL.rst.
"an `@noescape`" -> "a `@noescape`"
2019-08-03 11:38:57 +02:00
Erik Eckstein
237a3ef77f SIL: Extend cond_fail by a second operand, which is a static string literal, indicating the failure reason. 2019-07-16 12:31:10 +02:00
Brent Royal-Gordon
d5a2912a26 Revert "Better runtime failure messages (not yet enabled by default)" 2019-07-15 13:42:40 -07:00
Erik Eckstein
e2d313ef68 SIL: Extend cond_fail by a second operand, which is a static string literal, indicating the failure reason. 2019-07-12 14:03:13 +02:00
Doug Gregor
c02ecf9859 [SE-0258] Rename to Property Wrappers 2019-05-29 22:17:50 -07:00
Jonas Devlieghere
5fbab9ddaa [Docs] Fix headings in SIL.rst
Fixes "Title underline too short." warning which is treated as an error.
2019-05-22 17:04:18 -07:00
Arnold Schwaighofer
56924d4962 Document dynamic_function_ref and prev_dynamic_function_ref 2019-05-22 09:13:11 -07:00
Erik Eckstein
2e01b0edeb SIL: add assign_by_delegate instruction
Used for property delegates.
2019-04-23 11:32:28 -07:00
Slava Pestov
1159af50d9 Rename -enable-resilience to -enable-library-evolution and make it a driver flag
Fixes <rdar://problem/47679085>.
2019-03-14 22:24:26 -04:00
Manu Sridharan
244a1f2fd7 Fix types in open_existential_addr / value
Result type for `open_existential_addr` should be `$*@opened P`.  Similar change for `open_existential_value`
2019-03-05 16:51:25 -08:00
Richard Wei
976a9c7fe2 [SIL.rst] Fix is_escaping_closure code block. 2019-02-17 02:47:17 -08:00
Robert Widmann
441c85fe98 Merge pull request #22499 from rex4539/fix-typos
Fix typos
2019-02-14 14:11:27 -05:00
Andrew Trick
cd78226f84 Merge pull request #21867 from LucianoPAlmeida/gardening-link-sil-docs
[gardening] Adding some links to SIL files
2019-02-13 16:28:32 -08:00
Dimitris Apostolou
d84048e555 Fix typos 2019-02-11 08:33:47 +02:00
Richard Wei
dcbb26cc6d Fix typo in SIL.rst: [stack] -> [on_stack]. 2019-01-28 05:09:55 -05:00
swift-ci
10f84f0f9b Merge pull request #21985 from gottesmm/pr-44903c025f4dedd6fcf95759f6512365cd8eb662 2019-01-18 15:30:04 -08:00
Michael Gottesman
3585d7d36d Make text clearer. 2019-01-18 13:49:45 -08:00
Michael Gottesman
5701eb33bb Update given John's feedback. 2019-01-18 13:43:47 -08:00
Michael Gottesman
cbb3f11909 [sil] Add clarity to how load_weak [take] and store_weak effect an objects weak ref count. 2019-01-18 13:18:59 -08:00
Arnold Schwaighofer
ccbf25b0a2 Merge pull request #21933 from aschwaighofer/partial_apply_stack
Use stack allocation for Swift closures
2019-01-18 10:35:46 -08:00
Gwynne Raskind
664e5659c5 Merge pull request #21910 from gwynne/drop-litre-references
Remove all references to unused LitRe tool
2019-01-16 18:49:55 -06:00
Arnold Schwaighofer
f664b16010 SIL: Add an on stack version of partial_apply
It does not take ownership of its non-trivial arguments, is a trivial
function type and therefore must not be destroyed. The compiler must
make sure to extend the lifetime of non-trivial arguments beyond the
last use of the closure.

  %objc = copy_value %0 : $AnObject
  %closure = partial_apply [stack] [callee_guaranteed] %16(%obj) : $@convention(thin) (@guaranteed AnObject) -> ()
  %closure2 = mark_dependence %closure : $@noescape @callee_guaranteed () -> () on %obj : $AnObject
  %user = function_ref @useClosure : $@convention(thin) (@noescape @callee_guaranteed () -> ()) -> ()
  apply %user(%closure2) : $@convention(thin) (@noescape @callee_guaranteed () -> ()) -> ()
  dealloc_stack %closure : $() ->()
  destroy_value %obj : $AnObject // noescape closure does not take ownership

SR-904
rdar://35590578
2019-01-15 11:20:33 -08:00
Luciano Almeida
ff51f4d307 Fix broken ref of HighLevelSILOptimizations.rst on SIL.rst 2019-01-15 01:35:59 -02:00
Luciano Almeida
50d0118463 Adding some links on SIL docs. 2019-01-15 01:29:54 -02:00
Jordan Rose
425c190086 Restore initializing entry points for @objc convenience initializers (#21815)
This undoes some of Joe's work in 8665342 to add a guarantee: if an
@objc convenience initializer only calls other @objc initializers that
eventually call a designated initializer, it won't result in an extra
allocation. While Objective-C /allows/ returning a different object
from an initializer than the allocation you were given, doing so
doesn't play well with some very hairy implementation details of
compiled nib files (or NSCoding archives with cyclic references in
general).

This guarantee only applies to
(1) calling `self.init`
(2) where the delegated-to initializer is @objc
because convenience initializers must do dynamic dispatch when they
delegate, and Swift only stores allocating entry points for
initializers in a class's vtable. To dynamically find an initializing
entry point, ObjC dispatch must be used instead.

(It's worth noting that this patch does NOT check that the calling
initializer is a convenience initializer when deciding whether to use
ObjC dispatch for `self.init`. If we ever add peer delegation to
designated initializers, which is totally a valid feature, that should
use static dispatch and therefore should not go through objc_msgSend.)

This change doesn't /always/ result in fewer allocations; if the
delegated-to initializer ends up returning a different object after
all, the original allocation was wasted. Objective-C has the same
problem (one of the reasons why factory methods exist for things like
NSNumber and NSArray).

We do still get most of the benefits of Joe's original change. In
particular, vtables only ever contain allocating initializer entry
points, never the initializing ones, and never /both/ (which was a
thing that could happen with 'required' before).

rdar://problem/46823518
2019-01-14 13:06:50 -08:00
Gwynne Raskind
687585eafa Docs: Remove all references to long-unused LitRe tool. Also incidentally removes redundant/duplicate check for sphinx-build binary. 2019-01-13 21:15:56 -06:00