Skip to content

[move-only] Add copyable_to_moveonlywrapper and moveonlywrapper_to_copyable instructions. #59355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

gottesmm
Copy link
Contributor

These instructions have the following attributes:

  1. copyably_to_moveonlywrapper takes in a 'T' and maps it to a '@moveOnly
    T'. This is semantically used when initializing a new moveOnly binding from a
    copyable value. It semantically destroys its input @owned value and returns a
    brand new independent @owned @moveOnly value. It also is used to convert a
    trivial copyable value with type 'Trivial' into an owned non-trivial value of
    type '@moveOnly Trivial'. If one thinks of '@moveOnly' as a monad, this is how
    one injects a copyable value into the move only space.

  2. moveonlywrapper_to_copyable takes in a '@moveOnly T' and produces a new 'T'
    value. This is a 'forwarding' instruction where at parse time, we only allow for
    one to choose it to be [owned] or [guaranteed].

  • moveonlywrapper_to_copyable [owned] is used to signal the end of lifetime of
    the '@moveOnly' wrapper. SILGen inserts these when ever a move only value has
    its ownership passed to a situation where a copyable value is needed. Since it
    is consuming, we know that the no implicit copy checker will ensure that if we
    need a copy for it, the program will emit a diagnostic.

  • moveonlywrapper_to_copyable [guaranteed] is used to pass a @moveOnly T value
    as a copyable guaranteed parameter with type 'T' to a function. In the case of
    using no-implicit-copy checking this is always fine since no-implicit-copy is a
    local pattern. This would be an error when performing no escape
    checking. Importantly, this instruction also is where in the case of an
    @moveOnly trivial type, we convert from the non-trivial representation to the
    trivial representation.

Some important notes:

  1. In a forthcoming commit, I am going to rebase the no implicit copy checker on
    top of these instructions. By using '@moveOnly' in the type system, we can
    ensure that later in the SIL pipeline, we can have optimizations easily ignore
    the code.

  2. Be aware of is that due to SILGen only emitting '@moveOnly T' along immediate
    accesses to the variable and always converts to a copyable representation when
    calling other code, we can simply eliminate from the IR all moveonly-ness from
    the IR using a lowering pass (that I am going to upstream). In the evil scheme
    we are accomplishing here, we perform lowering of trivial values right after
    ownership lowering and before diagnostics to simplify the pipeline.

On another note, I also fixed a few things in SILParsing around getASTType() vs
getRawASTType().

Replace this paragraph with a description of your changes and rationale. Provide links to external references/discussions if appropriate.

Resolves SR-NNNN.

@gottesmm gottesmm requested a review from jckarter June 10, 2022 00:38
@gottesmm
Copy link
Contributor Author

@swift-ci test

@gottesmm gottesmm force-pushed the pr-20b996075d28e099e1c791eb80e78022f940f91e branch from 7e202d4 to a3c6f8f Compare June 10, 2022 02:00
@gottesmm
Copy link
Contributor Author

@swift-ci test

…pyable instructions.

These instructions have the following attributes:

1. copyably_to_moveonlywrapper takes in a 'T' and maps it to a '@moveOnly
T'. This is semantically used when initializing a new moveOnly binding from a
copyable value. It semantically destroys its input @owned value and returns a
brand new independent @owned @moveOnly value. It also is used to convert a
trivial copyable value with type 'Trivial' into an owned non-trivial value of
type '@moveOnly Trivial'. If one thinks of '@moveOnly' as a monad, this is how
one injects a copyable value into the move only space.

2. moveonlywrapper_to_copyable takes in a '@moveOnly T' and produces a new 'T'
value. This is a 'forwarding' instruction where at parse time, we only allow for
one to choose it to be [owned] or [guaranteed].

* moveonlywrapper_to_copyable [owned] is used to signal the end of lifetime of
the '@moveOnly' wrapper. SILGen inserts these when ever a move only value has
its ownership passed to a situation where a copyable value is needed. Since it
is consuming, we know that the no implicit copy checker will ensure that if we
need a copy for it, the program will emit a diagnostic.

* moveonlywrapper_to_copyable [guaranteed] is used to pass a @moveOnly T value
as a copyable guaranteed parameter with type 'T' to a function. In the case of
using no-implicit-copy checking this is always fine since no-implicit-copy is a
local pattern. This would be an error when performing no escape
checking. Importantly, this instruction also is where in the case of an
@moveOnly trivial type, we convert from the non-trivial representation to the
trivial representation.

Some important notes:

1. In a forthcoming commit, I am going to rebase the no implicit copy checker on
top of these instructions. By using '@moveOnly' in the type system, we can
ensure that later in the SIL pipeline, we can have optimizations easily ignore
the code.

2. Be aware of is that due to SILGen only emitting '@moveOnly T' along immediate
accesses to the variable and always converts to a copyable representation when
calling other code, we can simply eliminate from the IR all moveonly-ness from
the IR using a lowering pass (that I am going to upstream). In the evil scheme
we are accomplishing here, we perform lowering of trivial values right after
ownership lowering and before diagnostics to simplify the pipeline.

On another note, I also fixed a few things in SILParsing around getASTType() vs
getRawASTType().
@gottesmm gottesmm force-pushed the pr-20b996075d28e099e1c791eb80e78022f940f91e branch from a3c6f8f to e1006c6 Compare June 10, 2022 02:53
@gottesmm
Copy link
Contributor Author

@swift-ci test

@gottesmm
Copy link
Contributor Author

I talked with JoeG. We are going to do post-commit review on this since it is just scaffolding infrastructure (the big PR is coming next).

@gottesmm gottesmm merged commit 7c7fb47 into swiftlang:main Jun 10, 2022
@gottesmm gottesmm deleted the pr-20b996075d28e099e1c791eb80e78022f940f91e branch June 10, 2022 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant