-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is the dev branch for the inout argument feature (tracked by #282). The idea is to allow explicit `@inout` annotations on function arguments that "give back" the passed value after the function returns: ```python @guppy def foo(q: qubit @inout) -> None: ... @guppy def bar(q1: qubit @inout, q2: qubit @inout) -> bool: ... @guppy def main() -> None: q1, q2 = qubit(), qubit() foo(q1) # Desugars to `q1 = foo(q1)` x = bar(q1, q2) # Desugars to `q1, q2, x = bar(q1, q2)` y = bar(q1, q1) # Error: Linearity violation, q1 used twice ``` To enable this, we need to enforce that `@inout` arguments are not moved in the body of the function (apart from passing them in another `@inout` position). This means that the argument will always be bound to the same name and never aliased which allows us to desugar `@inout` functions like ```python @guppy def bar(q1: qubit, q2: qubit) -> bool: [body] return [expr] ``` into ```python @guppy def bar(q1: qubit, q2: qubit) -> tuple[qubit, qubit, bool]: [body] return q1, q2, [expr] # Linearity checker needs to ensure that q1, q2 are unused ``` Note that we only allow `@inout` annotations on linear types, since they would be useless for classical ones (unless we also implement an ownership system for classical values). Supporting them would make the checking logic more complicated without providing any meaningful benefit. Tracked PRs: * #315 * #316 * #349 * #344 * #321 * #331 * #350 * #339 * #340 * #351
- Loading branch information
Showing
69 changed files
with
1,457 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
fle = "fle" | ||
ine = "ine" | ||
inot = "inot" | ||
inout = "inout" | ||
inouts = "inouts" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.