microsoft / qsharp-compiler

Q# compiler, command line tool, and Q# language server
https://docs.microsoft.com/quantum
MIT License
684 stars 172 forks source link

Conditionally treat hardware capability errors as warnings #1588

Closed DmitryVasilevsky closed 1 year ago

DmitryVasilevsky commented 1 year ago

Adding option TreatCapabilityErrorsAsWarnings (command line argument treat-capability-errors-as-warnings). When set, it will instruct compiler to emit warnings instead of errors for target capabilities. Affected diagnostics:

UnsupportedResultComparison = 5023 ResultComparisonNotInOperationIf = 5024 ReturnInResultConditionedBlock = 5025 SetInResultConditionedBlock = 5026 UnsupportedCallableCapability = 5027 UnsupportedClassicalCapability = 5028

Current approach propagates this flag into F# type Target in module Analyzer. Then the flag is used to issue errors or warnings. (Alternative approach is to convert specific errors to warnings in C# code after they are collected).

swernli commented 1 year ago
  • There's a compiler option to turn any diagnostic code from a warning to an error. (Most compilers support this.)

To that end, see for example the WarningsAsErrors feature of the C# compiler or the Lint Levels feature of the Rust compiler. It's a common compiler pattern to allow someone to set all warnings, warnings of a specific class, or individual warnings identified by code to be treated as errors for a given compilation. I think that pattern is more standard and flexible than duplicating the codes among both the error and warning enum.

DmitryVasilevsky commented 1 year ago

An alternative approach has been implemented. https://github.com/microsoft/qsharp-compiler/pull/1594