Commit Graph

548 Commits

Author SHA1 Message Date
Michael Gottesman
a0679a40a6 [sil.rst] Use consistent white space margin around boxes in ascii figure. 2020-12-19 00:09:49 -08:00
Michael Gottesman
414b82eb89 [sil.rst] Update Ownership SSA section given further feedback/small rst fixes. 2020-12-18 17:48:11 -08:00
Raphael Isemann
60f8efe393 [sil.rst] Fix invalid reStructuredText syntax
* 'Any' isn't defined anywhere, so the references to that are invalid.
* Starting a literal block but not having any leading whitespace in the next line
   causes "Literal block expected; none found."

This breaks the build when sphinx is installed.
2020-12-18 17:48:11 -08:00
Michael Gottesman
c80856c737 [sil.rst] Update OSSA section for the introduction of an explicit "Ownership Kind Lattice". 2020-12-17 11:58:42 -08:00
Andrew Trick
257b7e60b8 Specify the unchecked_ownership_conversion instruction.
All SIL instructions need their semantics specified in SIL.rst and their
constraints specified in SILVerifier.
2020-11-13 16:33:30 -08:00
Michael Gottesman
9712e453b6 [ownership] Add a section to SIL.rst that describes the semantics of safe interior pointers in Ownership SIL.
This is just part of my ongoing effort to document more explicitly Ownership SSA
in SIL.rst.

NOTE: I realized while writing this, we might be able toalso do this form of
verification with owned values. I don't know how easy/hard it would be
though. Its nice to have that owned values do not need to look for these when
optimizing. So that would need to be balanced against expanding this.
2020-11-08 15:19:45 -08:00
Erik Eckstein
f18a9b8ee8 [Concurrency] SIL: add hop_to_executor instruction
This instructions ensures that all instructions, which need to run on the specified executor actually run on that executor.
For details see the description in SIL.rst.
2020-10-28 18:17:43 +01:00
Michael Gottesman
a37e7b95dc Add an Ownership SSA sub-section about forwarding uses. 2020-10-26 18:03:43 -07:00
Joe Groff
e4b6f8bcca More feedback: ownership of bbargs, begin -> get_async_continuation 2020-09-22 15:22:58 -07:00
Joe Groff
e2dfe3a334 Add example of withUnsafeContinuation lowering to SIL 2020-09-21 15:29:28 -07:00
Joe Groff
29587ac766 Revise with feedback from John and Andy 2020-09-21 14:21:47 -07:00
Joe Groff
57215cb17f SIL.rst: Add documentation for async function representation.
Unlike our existing coroutines, async functions run independently within an async coroutine context, and don't
directly yield values back and forth. They therefore mostly behave like normal functions with only an `@async` annotation
to indicate the presence of async suspend points. The `withUnsafeContinuation` primitive requires some instructions
to represent the operation that prepares the continuation to be resumed, which will be represented by
`begin_async_continuation`...`await_async_continuation` regions.
2020-09-18 16:57:07 -07:00
Michael Gottesman
8ea966319b [SIL.rst] Small bit of copy editing. 2020-07-16 13:12:20 -07:00
Erik Eckstein
5e21e46961 docs: add a dummy section for "begin_borrow" in SIL.rst
It fixes a doc build error
2020-07-16 18:51:19 +02:00
Michael Gottesman
8da561692b [docs] Begin adding section describing OSSA.
This just introduces ValueOwnershipKind and the partitioning of value users into
consuming and non-consuming users. I have more to add, but this I think is a
good start.
2020-07-15 15:30:27 -07:00
Michael Gottesman
6f101b88b4 Merge pull request #32830 from gottesmm/pr-3b0bbc9394dcb9de08d4961ea09ff4f7d918e6dd
[SIL.rst] Convert a bunch of bolded instruction names to inline links to the instructions docs.
2020-07-15 12:26:15 -07:00
Michael Gottesman
3c95a19bd4 [SIL.rst] Convert a bunch of bolded instruction names to inline links to the instructions docs.
Seems useful to allow for quick navigation. I did not get all of them, but did a
bunch of them.
2020-07-10 15:01:33 -07:00
Michael Gottesman
5e36ae1c7c [sil] Add a forwarding cast called unchecked_value_cast.
Today unchecked_bitwise_cast returns a value with ObjCUnowned ownership. This is
important to do since the instruction can truncate memory meaning we want to
treat it as a new object that must be copied before use.

This means that in OSSA we do not have a purely ossa forwarding unchecked
layout-compatible assuming cast. This role is filled by unchecked_value_cast.
2020-07-09 21:14:32 -07:00
Erik Eckstein
67605553df SIL: a new instruction 'base_addr_for_offset' for field offset calculations.
The ``base_addr_for_offset`` instruction creates a base address for offset calculations.
The result can be used by address projections, like ``struct_element_addr``, which themselves return the offset of the projected fields.
IR generation simply creates a null pointer for ``base_addr_for_offset``.
2020-07-01 15:10:08 +02:00
freddi(Yuki Aki)
e3259c4ef8 Fixed desc of unconditional_checked_cast_addr 2020-05-17 13:23:58 +09:00
Erik Eckstein
d57ee1316b docs: add a SIL COW support section in SIL.rst 2020-05-14 08:39:54 +02:00
Erik Eckstein
f5a8f600ea SIL: new instructions for copy-on-write support
* a new [immutable] attribute on ref_element_addr and ref_tail_addr
* new instructions: begin_cow_mutation and end_cow_mutation

These new instructions are intended to be used for the stdlib's COW containers, e.g. Array.
They allow more aggressive optimizations, especially for Array.
2020-05-14 08:39:54 +02:00
Dmitri Gribenko
b384bf9ac9 Addressed code review comments 2020-05-08 10:13:57 +02:00
Dmitri Gribenko
6972e38b29 Improved the description of loadable and address-only types
Added a missing requirement that loadable types must be loaded and
stored in terms of their parts. Added some examples of loadable and
address-only types that are not expressible in Swift today but help
illustrate the concepts.
2020-05-08 10:04:49 +02:00
Dmitri Gribenko
683c27140c SIL.rst: use terms 'object type' and 'address type'
Use the terms used in compiler source when introducing these concepts in
the documentation.
2020-05-05 15:56:34 +02:00
Robert Widmann
4b8db7cc15 Merge pull request #30637 from gribozavr/sil-rst-2
Fixed the description of init_existential_value to match the implementation
2020-04-23 19:13:56 -07:00
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
72931eaf64 Fixed the description of init_existential_value to match the implementation 2020-03-25 18:21:50 +01: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