Lint rule: operation
s that don't manipulate quantum state can be function
s instead
#1471
Labels
operation
s that don't manipulate quantum state can be function
s instead
#1471
We should add a rule to the linter that will emit a warning when an
operation
does not manipulate quantum state. The warning should suggest declaring the callable as afunction
instead.Context:
In Q#, callables declared as
operation
can manipulate quantum state (allocate qubits, apply gates, call otheroperation
s etc) while callables declared asfunction
must be pure functions and cannot manipulate state.Currently, a callable such as the one below can be declared as an
operation
orfunction
.Playground link
Since this is a pure function,
function
is a more appropriate designation for it.Declaring the proper callable type not only helps prevent mistakes, it may also allow runtime capability analysis to run faster since the compiler can rely on the knowledge that
function
s don't manipulate quantum state.CONTRIBUTORS PLEASE READ
Getting started
Welcome! Please take a look through our README to orient yourself in the repo and find instructions on how to build.
For this issue you'll want to have a working knowledge of Rust and compilers.
For documentation on how to add lints, see:
https://github.com/microsoft/qsharp/blob/main/compiler/qsc_linter/src/lib.rs
For examples of existing lints, see:
qsharp/compiler/qsc_linter/src/lints/ast.rs
Lines 10 to 12 in ed2a8fc
qsharp/compiler/qsc_linter/src/lints/hir.rs
Line 8 in ed2a8fc
Testing
You can demonstrate that the lint works by running the playground locally (see the code example in the issue description).
Please add unit tests verifying the functionality you implemented.
Before you submit a pull request please run
python ./build.py
to ensure the project builds cleanly. See README for details.Reviews
Once you have published your PR, the codeowners will automatically get tagged and we'll review shortly.
If you need clarification on an issue please tag @minestarks with your questions.
The text was updated successfully, but these errors were encountered: