From 9d99a364fafe4e8592ea7a17facb006adb716a1b Mon Sep 17 00:00:00 2001 From: Sarah Marshall Date: Tue, 5 Jan 2021 15:26:07 -0800 Subject: [PATCH 1/7] Add use and borrow keywords --- src/QsCompiler/DataStructures/Diagnostics.fs | 2 ++ src/QsCompiler/DataStructures/ReservedKeywords.fs | 9 +++++++++ src/QsCompiler/TextProcessor/QsFragmentParsing.fs | 15 +++++++++++++-- src/QsCompiler/TextProcessor/QsKeywords.fs | 10 ++++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/QsCompiler/DataStructures/Diagnostics.fs b/src/QsCompiler/DataStructures/Diagnostics.fs index 5445582ba3..99b64c2d5b 100644 --- a/src/QsCompiler/DataStructures/Diagnostics.fs +++ b/src/QsCompiler/DataStructures/Diagnostics.fs @@ -334,6 +334,7 @@ type WarningCode = | UseOfFutureReservedKeyword = 3304 | [] UseOfUnderscorePattern = 3305 | DeprecatedTupleBrackets = 3306 + | DeprecatedKeyword = 3307 | DeprecatedRUSloopInFunction = 4001 | DiscardingItemInAssignment = 5001 @@ -891,6 +892,7 @@ type DiagnosticItem = "Double underscores as well as underscores before a dot or at the end of a namespace name will be reserved for internal use in the future." | WarningCode.DeprecatedTupleBrackets -> "Deprecated syntax. Parentheses here are no longer required and will not be supported in the future." + | WarningCode.DeprecatedKeyword -> "The \"{0}\" keyword is deprecated. Use the keyword \"{1}\" instead." | WarningCode.DeprecatedRUSloopInFunction -> "The use of repeat-until-success-loops within functions may not be supported in the future. Please use a while-loop instead." diff --git a/src/QsCompiler/DataStructures/ReservedKeywords.fs b/src/QsCompiler/DataStructures/ReservedKeywords.fs index cb43ddf15a..5262764dcb 100644 --- a/src/QsCompiler/DataStructures/ReservedKeywords.fs +++ b/src/QsCompiler/DataStructures/ReservedKeywords.fs @@ -119,8 +119,17 @@ module Statements = let Apply = "apply" /// keyword for a Q# allocation statement + let Use = "use" + + /// keyword for a Q# allocation statement + [] let Using = "using" + + /// keyword for a Q# allocation statement + let Borrow = "borrow" + /// keyword for a Q# allocation statement + [] let Borrowing = "borrowing" diff --git a/src/QsCompiler/TextProcessor/QsFragmentParsing.fs b/src/QsCompiler/TextProcessor/QsFragmentParsing.fs index 19b71020d1..0f743dd564 100644 --- a/src/QsCompiler/TextProcessor/QsFragmentParsing.fs +++ b/src/QsCompiler/TextProcessor/QsFragmentParsing.fs @@ -39,6 +39,15 @@ let private invalidInitializer = (InvalidInitializer, Null) |> QsInitializer.New /// returns a QsFunctorGenerator representing an invalid functor generator (i.e. syntax error on parsing) let private unknownGenerator = (FunctorGenerationDirective InvalidGenerator, Null) |> QsSpecializationGenerator.New +/// Parses a Q# keyword or an equivalent deprecated keyword. If the deprecated keyword is parsed, a deprecation warning +/// is emitted. +let private deprecatedKeyword keyword deprecated = + let pushWarning = + QsCompilerDiagnostic.Warning(WarningCode.DeprecatedKeyword, [ deprecated.id; keyword.id ]) + >> pushDiagnostic + + keyword.parse >>% () <|> (deprecated.parse >>= pushWarning) + /// Given an array of QsSymbols and a tuple with start and end position, builds a Q# SymbolTuple as QsSymbol. let private buildSymbolTuple (items, range: Range) = (SymbolTuple items, range) |> QsSymbol.New @@ -588,12 +597,12 @@ let private applyHeader = buildFragment qsApply.parse (preturn "") ApplyBlockInt /// Uses buildFragment to parse a Q# using block intro as QsFragment. let private usingHeader = let invalid = UsingBlockIntro(invalidSymbol, invalidInitializer) - buildFragment qsUsing.parse allocationScope invalid (fun _ -> UsingBlockIntro) eof + buildFragment (deprecatedKeyword qsUse qsUsing) allocationScope invalid (fun _ -> UsingBlockIntro) eof /// Uses buildFragment to parse a Q# borrowing block intro as QsFragment. let private borrowingHeader = let invalid = BorrowingBlockIntro(invalidSymbol, invalidInitializer) - buildFragment qsBorrowing.parse allocationScope invalid (fun _ -> BorrowingBlockIntro) eof + buildFragment (deprecatedKeyword qsBorrow qsBorrowing) allocationScope invalid (fun _ -> BorrowingBlockIntro) eof /// Always builds an invalid fragment after parsing the given fragment header. let private buildInvalidFragment header = @@ -616,7 +625,9 @@ let private fragments = (qsUntil, untilSuccess) (qsWithin, withinHeader) (qsApply, applyHeader) + (qsUse, usingHeader) (qsUsing, usingHeader) + (qsBorrow, borrowingHeader) (qsBorrowing, borrowingHeader) (namespaceDeclHeader, namespaceDeclaration) (typeDeclHeader, udtDeclaration) diff --git a/src/QsCompiler/TextProcessor/QsKeywords.fs b/src/QsCompiler/TextProcessor/QsKeywords.fs index 2f2c6676b2..812493e9b1 100644 --- a/src/QsCompiler/TextProcessor/QsKeywords.fs +++ b/src/QsCompiler/TextProcessor/QsKeywords.fs @@ -4,6 +4,7 @@ /// The purpose of this module is to aggregate all keywords used throughout Qs such that they only need to adapted here when changed module Microsoft.Quantum.QsCompiler.TextProcessing.Keywords +open System open System.Collections.Generic open System.Collections.Immutable open FParsec @@ -157,8 +158,17 @@ let qsWithin = addFragmentHeader Statements.Within let qsApply = addFragmentHeader Statements.Apply /// keyword for a Q# allocation statement (QsFragmentHeader) +let qsUse = addFragmentHeader Statements.Use + +/// keyword for a Q# allocation statement (QsFragmentHeader) +[] let qsUsing = addFragmentHeader Statements.Using + +/// keyword for a Q# allocation statement (QsFragmentHeader) +let qsBorrow = addFragmentHeader Statements.Borrow + /// keyword for a Q# allocation statement (QsFragmentHeader) +[] let qsBorrowing = addFragmentHeader Statements.Borrowing // expression related keywords From e65352780341200e133a75fd583f16ad3c44ec56 Mon Sep 17 00:00:00 2001 From: Sarah Marshall Date: Tue, 5 Jan 2021 15:50:02 -0800 Subject: [PATCH 2/7] Update syntax highlighting --- src/VSCodeExtension/syntaxes/qsharp.tmLanguage.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/VSCodeExtension/syntaxes/qsharp.tmLanguage.json b/src/VSCodeExtension/syntaxes/qsharp.tmLanguage.json index 4556bcaec3..632f1d85a6 100644 --- a/src/VSCodeExtension/syntaxes/qsharp.tmLanguage.json +++ b/src/VSCodeExtension/syntaxes/qsharp.tmLanguage.json @@ -44,7 +44,7 @@ "patterns": [ { "name": "keyword.control.qsharp", - "match": "\\b(using|borrowing|mutable|let|set|if|elif|else|repeat|until|fixup|for|in|while|return|fail|within|apply)\\b" + "match": "\\b(use|using|borrow|borrowing|mutable|let|set|if|elif|else|repeat|until|fixup|for|in|while|return|fail|within|apply)\\b" }, { "name": "keyword.other.qsharp", From 88904f0f66d3879608dd3e91ba9ea5ab4c2d206b Mon Sep 17 00:00:00 2001 From: Sarah Marshall Date: Wed, 6 Jan 2021 11:06:57 -0800 Subject: [PATCH 3/7] Update tests --- .../Tests.Compiler/LocalVerificationTests.fs | 70 ++--- .../TestCases/FunctorGeneration.qs | 28 +- .../TestCases/GlobalVerification.qs | 252 +++++++++--------- .../TestCases/LocalVerification.qs | 50 ++-- 4 files changed, 196 insertions(+), 204 deletions(-) diff --git a/src/QsCompiler/Tests.Compiler/LocalVerificationTests.fs b/src/QsCompiler/Tests.Compiler/LocalVerificationTests.fs index 45f492806c..bbb18b8705 100644 --- a/src/QsCompiler/Tests.Compiler/LocalVerificationTests.fs +++ b/src/QsCompiler/Tests.Compiler/LocalVerificationTests.fs @@ -5,7 +5,6 @@ namespace Microsoft.Quantum.QsCompiler.Testing open System.Collections.Generic open System.IO -open Microsoft.Quantum.QsCompiler.DataTypes open Microsoft.Quantum.QsCompiler.Diagnostics open Microsoft.Quantum.QsCompiler.SyntaxExtensions open Microsoft.Quantum.QsCompiler.SyntaxTree @@ -31,45 +30,38 @@ type LocalVerificationTests() = member this.``Type argument inference``() = this.Expect "TypeArgumentsInference1" [ Error ErrorCode.UnresolvedTypeParameterForRecursiveCall ] this.Expect "TypeArgumentsInference2" [ Error ErrorCode.UnresolvedTypeParameterForRecursiveCall ] - this.Expect "TypeArgumentsInference3" [ Error ErrorCode.UnresolvedTypeParameterForRecursiveCall Error ErrorCode.MultipleTypesInArray ] - this.Expect "TypeArgumentsInference4" [ Error ErrorCode.UnresolvedTypeParameterForRecursiveCall Error ErrorCode.MultipleTypesInArray ] - this.Expect "TypeArgumentsInference5" [ Error ErrorCode.UnresolvedTypeParameterForRecursiveCall Error ErrorCode.UnresolvedTypeParameterForRecursiveCall ] - this.Expect "TypeArgumentsInference6" [ Error ErrorCode.UnresolvedTypeParameterForRecursiveCall ] this.Expect "TypeArgumentsInference7" [ Error ErrorCode.UnresolvedTypeParameterForRecursiveCall ] - this.Expect "TypeArgumentsInference8" [ Error ErrorCode.UnresolvedTypeParameterForRecursiveCall Error ErrorCode.UnresolvedTypeParameterForRecursiveCall ] - this.Expect "TypeArgumentsInference9" [ Error ErrorCode.UnresolvedTypeParameterForRecursiveCall Error ErrorCode.UnresolvedTypeParameterForRecursiveCall ] - this.Expect "TypeArgumentsInference10" [] this.Expect "TypeArgumentsInference11" [] this.Expect "TypeArgumentsInference12" [] @@ -90,21 +82,18 @@ type LocalVerificationTests() = this.Expect "TypeArgumentsInference27" [ Error ErrorCode.ConstrainsTypeParameter ] this.Expect "TypeArgumentsInference28" [ Error ErrorCode.ArgumentTypeMismatch ] this.Expect "TypeArgumentsInference29" [ Error ErrorCode.InvalidCyclicTypeParameterResolution ] - this.Expect "TypeArgumentsInference30" [ Error ErrorCode.TypeParameterResConflictWithTypeArgument Error ErrorCode.InvalidCyclicTypeParameterResolution ] - this.Expect "TypeArgumentsInference31" [ Error ErrorCode.TypeParameterResConflictWithTypeArgument Error ErrorCode.InvalidCyclicTypeParameterResolution ] - this.Expect "TypeArgumentsInference32" [ Error ErrorCode.ConstrainsTypeParameter ] this.Expect "TypeArgumentsInference33" [ Error ErrorCode.ArgumentTypeMismatch ] this.Expect "TypeArgumentsInference34" [] @@ -133,25 +122,21 @@ type LocalVerificationTests() = this.Expect "VariableDeclaration11" [ Error ErrorCode.InvalidUseOfTypeParameterizedObject ] this.Expect "VariableDeclaration12" [ Error ErrorCode.InvalidUseOfTypeParameterizedObject ] this.Expect "VariableDeclaration13" [ Error ErrorCode.ConstrainsTypeParameter ] - this.Expect "VariableDeclaration14" [ Error ErrorCode.InvalidUseOfTypeParameterizedObject Error ErrorCode.InvalidUseOfTypeParameterizedObject ] - this.Expect "VariableDeclaration15" [ Error ErrorCode.InvalidUseOfTypeParameterizedObject ] this.Expect "VariableDeclaration16" [ Error ErrorCode.InvalidUseOfTypeParameterizedObject ] this.Expect "VariableDeclaration17" [ Error ErrorCode.InvalidUseOfTypeParameterizedObject ] - this.Expect "VariableDeclaration18" [ Error ErrorCode.InvalidUseOfTypeParameterizedObject Error ErrorCode.MultipleTypesInArray ] - this.Expect "VariableDeclaration19" [ Error ErrorCode.InvalidUseOfTypeParameterizedObject ] this.Expect "VariableDeclaration20" [ Error ErrorCode.ConstrainsTypeParameter ] this.Expect "VariableDeclaration21" [] @@ -199,14 +184,12 @@ type LocalVerificationTests() = this.Expect "ApplyAndReassign4" [] this.Expect "ApplyAndReassign5" [] this.Expect "ApplyAndReassign6" [ Error ErrorCode.ExpectingBoolExpr ] - this.Expect "ApplyAndReassign7" [ Error ErrorCode.ArgumentMismatchInBinaryOp Error ErrorCode.ArgumentMismatchInBinaryOp ] - this.Expect "ApplyAndReassign8" [ Error ErrorCode.UpdateOfImmutableIdentifier ] this.Expect "ApplyAndReassign9" [ Error ErrorCode.UpdateOfArrayItemExpr ] this.Expect "ApplyAndReassign10" [ Error ErrorCode.UpdateOfArrayItemExpr ] @@ -216,39 +199,33 @@ type LocalVerificationTests() = [] member this.``Named type item access``() = this.Expect "ItemAccess1" [ Error ErrorCode.ExpectingUserDefinedType ] - this.Expect "ItemAccess2" [ Error ErrorCode.UnknownItemName ] this.Expect "ItemAccess3" [] this.Expect "ItemAccess4" [] - this.Expect "ItemAccess5" [ Error ErrorCode.ArgumentMismatchInBinaryOp Error ErrorCode.ArgumentMismatchInBinaryOp ] - this.Expect "ItemAccess6" [] this.Expect "ItemAccess7" [] this.Expect "ItemAccess8" [] this.Expect "ItemAccess9" [] this.Expect "ItemAccess10" [] this.Expect "ItemAccess11" [] - this.Expect "ItemAccess12" [ Error ErrorCode.OperationCallOutsideOfOperation Error ErrorCode.OperationCallOutsideOfOperation ] - this.Expect "ItemAccess13" [ Error ErrorCode.MissingFunctorForAutoGeneration Error ErrorCode.MissingFunctorForAutoGeneration ] - this.Expect "ItemAccess14" [] this.Expect "ItemAccess15" [] this.Expect "ItemAccess16" [] @@ -267,50 +244,41 @@ type LocalVerificationTests() = this.Expect "ItemUpdate5" [ Error ErrorCode.UpdateOfImmutableIdentifier ] this.Expect "ItemUpdate6" [ Error ErrorCode.TypeMismatchInCopyAndUpdateExpr ] this.Expect "ItemUpdate7" [ Error ErrorCode.TypeMismatchInCopyAndUpdateExpr ] - this.Expect "ItemUpdate8" [ Error ErrorCode.TypeMismatchInCopyAndUpdateExpr Error ErrorCode.TypeMismatchInCopyAndUpdateExpr ] - this.Expect "ItemUpdate9" [] - this.Expect "ItemUpdate10" [ Error ErrorCode.InvalidIdentifierExprInUpdate Error ErrorCode.ExcessContinuation ] - this.Expect "ItemUpdate11" [ Error ErrorCode.UpdateOfArrayItemExpr ] - this.Expect "ItemUpdate12" [ Error ErrorCode.TypeMismatchInCopyAndUpdateExpr Error ErrorCode.TypeMismatchInCopyAndUpdateExpr ] - this.Expect "ItemUpdate13" [] this.Expect "ItemUpdate14" [ Error ErrorCode.TypeMismatchInCopyAndUpdateExpr ] this.Expect "ItemUpdate15" [ Error ErrorCode.TypeMismatchInCopyAndUpdateExpr ] - this.Expect "ItemUpdate16" [ Error ErrorCode.MissingFunctorForAutoGeneration Error ErrorCode.MissingFunctorForAutoGeneration ] - this.Expect "ItemUpdate17" [ Error ErrorCode.MissingFunctorForAutoGeneration Error ErrorCode.ValueUpdateWithinAutoInversion ] - this.Expect "ItemUpdate18" [ Error ErrorCode.MissingFunctorForAutoGeneration ] this.Expect "ItemUpdate19" [ Error ErrorCode.MissingFunctorForAutoGeneration ] this.Expect "ItemUpdate20" [] @@ -397,14 +365,12 @@ type LocalVerificationTests() = this.Expect "UsingDeprecatedType1" [ Warning WarningCode.DeprecationWithoutRedirect ] this.Expect "UsingDeprecatedType2" [ Warning WarningCode.DeprecationWithoutRedirect ] this.Expect "UsingDeprecatedType3" [ Warning WarningCode.DeprecationWithoutRedirect ] - this.Expect "UsingDeprecatedType4" [ Warning WarningCode.DeprecationWithoutRedirect Warning WarningCode.DeprecationWithoutRedirect ] - this.Expect "UsingDeprecatedType5" [ @@ -415,14 +381,12 @@ type LocalVerificationTests() = this.Expect "UsingRenamedType1" [ Warning WarningCode.DeprecationWithRedirect ] this.Expect "UsingRenamedType2" [ Warning WarningCode.DeprecationWithRedirect ] this.Expect "UsingRenamedType3" [ Warning WarningCode.DeprecationWithRedirect ] - this.Expect "UsingRenamedType4" [ Warning WarningCode.DeprecationWithRedirect Warning WarningCode.DeprecationWithRedirect ] - this.Expect "UsingRenamedType5" [ @@ -458,21 +422,18 @@ type LocalVerificationTests() = this.Expect "InvalidTestAttribute2" [ Error ErrorCode.MisplacedDeclarationAttribute ] this.Expect "InvalidTestAttribute3" [ Error ErrorCode.MisplacedDeclarationAttribute ] this.Expect "InvalidTestAttribute4" [ Error ErrorCode.MisplacedDeclarationAttribute ] - this.Expect "InvalidTestAttribute5" [ Error ErrorCode.InvalidTestAttributePlacement Warning WarningCode.TypeParameterNotResolvedByArgument ] - this.Expect "InvalidTestAttribute6" [ Error ErrorCode.InvalidTestAttributePlacement Warning WarningCode.TypeParameterNotResolvedByArgument ] - this.Expect "InvalidTestAttribute7" [ Error ErrorCode.InvalidTestAttributePlacement ] this.Expect "InvalidTestAttribute8" [ Error ErrorCode.InvalidTestAttributePlacement ] this.Expect "InvalidTestAttribute9" [ Error ErrorCode.InvalidTestAttributePlacement ] @@ -481,32 +442,27 @@ type LocalVerificationTests() = this.Expect "InvalidTestAttribute12" [ Error ErrorCode.InvalidExecutionTargetForTest ] this.Expect "InvalidTestAttribute13" [ Error ErrorCode.InvalidExecutionTargetForTest ] this.Expect "InvalidTestAttribute14" [ Error ErrorCode.InvalidExecutionTargetForTest ] - this.Expect "InvalidTestAttribute15" [ Error ErrorCode.InvalidExecutionTargetForTest Warning WarningCode.DuplicateAttribute ] - this.Expect "InvalidTestAttribute16" [ Error ErrorCode.InvalidTestAttributePlacement; Error ErrorCode.UnknownType ] - this.Expect "InvalidTestAttribute17" [ Error ErrorCode.InvalidExecutionTargetForTest Error ErrorCode.AttributeArgumentTypeMismatch ] - this.Expect "InvalidTestAttribute18" [ Error ErrorCode.InvalidExecutionTargetForTest Error ErrorCode.MissingAttributeArgument ] - this.Expect "InvalidTestAttribute19" [ Error ErrorCode.InvalidExecutionTargetForTest ] this.Expect "InvalidTestAttribute20" [ Error ErrorCode.InvalidExecutionTargetForTest ] this.Expect "InvalidTestAttribute21" [ Error ErrorCode.InvalidExecutionTargetForTest ] @@ -527,7 +483,25 @@ type LocalVerificationTests() = this.Expect "NoParensUntil" [] this.Expect "ParensUntilFixup" [] this.Expect "NoParensUntilFixup" [] - this.Expect "ParensUsing" [ Warning WarningCode.DeprecatedTupleBrackets ] - this.Expect "NoParensUsing" [] - this.Expect "ParensBorrowing" [ Warning WarningCode.DeprecatedTupleBrackets ] - this.Expect "NoParensBorrowing" [] + this.Expect "ParensUse" [ Warning WarningCode.DeprecatedTupleBrackets ] + this.Expect "NoParensUse" [] + this.Expect "ParensBorrow" [ Warning WarningCode.DeprecatedTupleBrackets ] + this.Expect "NoParensBorrow" [] + + + [] + member this.``Deprecated qubit allocation keywords``() = + this.Expect "DeprecatedUsingKeyword" [ Warning WarningCode.DeprecatedKeyword ] + this.Expect + "DeprecatedUsingKeywordParens" + [ + Warning WarningCode.DeprecatedKeyword + Warning WarningCode.DeprecatedTupleBrackets + ] + this.Expect "DeprecatedBorrowingKeyword" [ Warning WarningCode.DeprecatedKeyword ] + this.Expect + "DeprecatedBorrowingKeywordParens" + [ + Warning WarningCode.DeprecatedKeyword + Warning WarningCode.DeprecatedTupleBrackets + ] diff --git a/src/QsCompiler/Tests.Compiler/TestCases/FunctorGeneration.qs b/src/QsCompiler/Tests.Compiler/TestCases/FunctorGeneration.qs index 2b66254642..ea5f174b11 100644 --- a/src/QsCompiler/Tests.Compiler/TestCases/FunctorGeneration.qs +++ b/src/QsCompiler/Tests.Compiler/TestCases/FunctorGeneration.qs @@ -687,14 +687,14 @@ namespace Microsoft.Quantum.Testing.FunctorGeneration { operation InvalidAutoInversion10(q : Qubit) : Unit { body (...) { - using c = Qubit() { return (); } + use c = Qubit() { return (); } } adjoint auto; } operation InvalidAutoInversion11(q : Qubit) : Unit { body (...) { - using c = Qubit() { + use c = Qubit() { repeat {} until (true) fixup {} @@ -705,21 +705,21 @@ namespace Microsoft.Quantum.Testing.FunctorGeneration { operation InvalidAutoInversion12(q : Qubit) : Unit { body (...) { - using c = Qubit() { set _ = 1; } + use c = Qubit() { set _ = 1; } } adjoint auto; } operation InvalidAutoInversion13(q : Qubit) : Unit { body (...) { - borrowing c = Qubit() { return (); } + borrow c = Qubit() { return (); } } adjoint auto; } operation InvalidAutoInversion14(q : Qubit) : Unit { body (...) { - borrowing c = Qubit() { + borrow c = Qubit() { repeat {} until (true) fixup {} @@ -730,7 +730,7 @@ namespace Microsoft.Quantum.Testing.FunctorGeneration { operation InvalidAutoInversion15(q : Qubit) : Unit { body (...) { - borrowing c = Qubit() { set _ = 1; } + borrow c = Qubit() { set _ = 1; } } adjoint auto; } @@ -855,14 +855,14 @@ namespace Microsoft.Quantum.Testing.FunctorGeneration { operation WithInvalidQuantumDependency6 (q : Qubit) : Unit { body (...) { - using qs = Qubit[CoinFlip() ? 1 | 0] {} + use qs = Qubit[CoinFlip() ? 1 | 0] {} } adjoint auto; } operation WithInvalidQuantumDependency7 (q : Qubit) : Unit { body (...) { - borrowing qs = Qubit[CoinFlip() ? 1 | 0] {} + borrow qs = Qubit[CoinFlip() ? 1 | 0] {} } adjoint auto; } @@ -905,14 +905,14 @@ namespace Microsoft.Quantum.Testing.FunctorGeneration { operation WithoutInvalidQuantumDependency6 (q : Qubit) : Unit { body (...) { - using c = Qubit() { Adjointable(q); } + use c = Qubit() { Adjointable(q); } } adjoint auto; } operation WithoutInvalidQuantumDependency7 (q : Qubit) : Unit { body (...) { - borrowing c = Qubit() { Adjointable(q); } + borrow c = Qubit() { Adjointable(q); } } adjoint auto; } @@ -936,14 +936,14 @@ namespace Microsoft.Quantum.Testing.FunctorGeneration { operation InvalidControlled3 (q : Qubit) : Unit { body (...) { - using cs = Qubit[CoinFlip() ? 1 | 0] {} + use cs = Qubit[CoinFlip() ? 1 | 0] {} } controlled auto; } operation InvalidControlled4 (q : Qubit) : Unit { body (...) { - borrowing cs = Qubit[CoinFlip() ? 1 | 0] {} + borrow cs = Qubit[CoinFlip() ? 1 | 0] {} } controlled auto; } @@ -1000,14 +1000,14 @@ namespace Microsoft.Quantum.Testing.FunctorGeneration { operation ValidControlled8 (q : Qubit) : Unit { body (...) { - using c = Qubit() { Controllable(q); } + use c = Qubit() { Controllable(q); } } controlled auto; } operation ValidControlled9 (q : Qubit) : Unit { body (...) { - borrowing c = Qubit() { Controllable(q); } + borrow c = Qubit() { Controllable(q); } } controlled auto; } diff --git a/src/QsCompiler/Tests.Compiler/TestCases/GlobalVerification.qs b/src/QsCompiler/Tests.Compiler/TestCases/GlobalVerification.qs index 1f9da9ea9e..51e4f9c9e4 100644 --- a/src/QsCompiler/Tests.Compiler/TestCases/GlobalVerification.qs +++ b/src/QsCompiler/Tests.Compiler/TestCases/GlobalVerification.qs @@ -351,26 +351,26 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation AllPathsReturnValue8 () : Int { - using q = Qubit() { + use q = Qubit() { return 1; } } operation AllPathsReturnValue9 () : Int { - borrowing q = Qubit() { + borrow q = Qubit() { return 1; } } operation AllPathsReturnValue10 () : Int { - using q = Qubit() { + use q = Qubit() { repeat { return 1; } until (true); } } operation AllPathsReturnValue11 () : Int { - borrowing q = Qubit() { + borrow q = Qubit() { repeat { return 1; } until (true); } @@ -378,13 +378,13 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { operation AllPathsReturnValue12 (cond : Bool) : Int { if (cond) { - borrowing q = Qubit() { + borrow q = Qubit() { repeat { return 1; } until (true); } } else { - using q = Qubit() { + use q = Qubit() { repeat { return 1; } until (true) fixup {} @@ -453,19 +453,19 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation AllPathsFail8 () : Int { - using q = Qubit() { + use q = Qubit() { fail ""; } } operation AllPathsFail9 () : Int { - borrowing q = Qubit() { + borrow q = Qubit() { fail ""; } } operation AllPathsFail10 () : Int { - using q = Qubit() { + use q = Qubit() { repeat { fail ""; } until (true) fixup {} @@ -473,7 +473,7 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation AllPathsFail11 () : Int { - borrowing q = Qubit() { + borrow q = Qubit() { repeat { fail ""; } until (true) fixup {} @@ -482,13 +482,13 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { operation AllPathsFail12 (cond : Bool) : Int { if (cond) { - borrowing q = Qubit() { + borrow q = Qubit() { repeat { fail ""; } until (true); } } else { - using q = Qubit() { + use q = Qubit() { repeat { fail ""; } until (true); } @@ -583,7 +583,7 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation NotAllPathsReturnValue11 () : Int { - using q = Qubit() { + use q = Qubit() { repeat {} until (true) fixup { return 1; } @@ -591,7 +591,7 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation NotAllPathsReturnValue12 () : Int { - borrowing q = Qubit() { + borrow q = Qubit() { repeat {} until (true) fixup { return 1; } @@ -682,7 +682,7 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation NotAllPathsReturnOrFail11 () : Int { - using q = Qubit() { + use q = Qubit() { repeat {} until (true) fixup { fail ""; } @@ -690,7 +690,7 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation NotAllPathsReturnOrFail12 () : Int { - borrowing q = Qubit() { + borrow q = Qubit() { repeat {} until (true) fixup { fail ""; } @@ -713,20 +713,20 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { // valid uses of return within using operation ReturnFromWithinUsing1 () : Unit { - using q = Qubit() { + use q = Qubit() { return (); } } operation ReturnFromWithinUsing2 () : Unit { - using q = Qubit() { + use q = Qubit() { if (true) { return (); } else {} } } operation ReturnFromWithinUsing3 () : Unit { - using q = Qubit() { + use q = Qubit() { if (true) {} elif (true) { return (); } else {} @@ -734,7 +734,7 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation ReturnFromWithinUsing4 () : Unit { - using q = Qubit() { + use q = Qubit() { if (true) {} elif (true) {} else { return (); } @@ -742,7 +742,7 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation ReturnFromWithinUsing5 () : Unit { - using q = Qubit() { + use q = Qubit() { if (true) { return (); } elif (true) { return (); } else { return (); } @@ -750,7 +750,7 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation ReturnFromWithinUsing6 () : Unit { - using q = Qubit() { + use q = Qubit() { repeat { return (); } until(true) fixup { DoNothing(); } @@ -758,7 +758,7 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation ReturnFromWithinUsing7 () : Unit { - using q = Qubit() { + use q = Qubit() { repeat { DoNothing(); return (); @@ -771,7 +771,7 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation ReturnFromWithinUsing8 () : Unit { - using q = Qubit() { + use q = Qubit() { for i in 1..10 { DoNothing(); return (); @@ -783,28 +783,28 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { // invalid uses of return within using operation InvalidReturnFromWithinUsing1 () : Unit { - using q = Qubit() { + use q = Qubit() { return (); DoNothing(); } } operation InvalidReturnFromWithinUsing2 () : Unit { - using q = Qubit() { + use q = Qubit() { return (); fail "unreachable"; } } operation InvalidReturnFromWithinUsing3 () : Unit { - using q = Qubit() { + use q = Qubit() { return (); if (true) { return (); } } } operation InvalidReturnFromWithinUsing4 () : Unit { - using q = Qubit() { + use q = Qubit() { return (); repeat {} until(true) @@ -813,7 +813,7 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation InvalidReturnFromWithinUsing5 () : Unit { - using q = Qubit() { + use q = Qubit() { repeat {} until(false) fixup { return (); } @@ -821,35 +821,35 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation InvalidReturnFromWithinUsing6 () : Unit { - using q = Qubit() { + use q = Qubit() { within { return(); } apply {} } } operation InvalidReturnFromWithinUsing7 () : Unit { - using q = Qubit() { + use q = Qubit() { within {} apply { return(); } } } operation InvalidReturnFromWithinUsing8 () : Unit { - using q = Qubit() { + use q = Qubit() { return (); for i in 1..10 {} } } operation InvalidReturnFromWithinUsing9 () : Unit { - using q = Qubit() { + use q = Qubit() { if (true) { return (); } DoNothing(); } } operation InvalidReturnFromWithinUsing10 () : Unit { - using q = Qubit() { + use q = Qubit() { if (true) { DoNothing(); } elif (true) { return (); } elif (true) { return (); } @@ -859,7 +859,7 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation InvalidReturnFromWithinUsing11 () : Unit { - using q = Qubit() { + use q = Qubit() { if (true) { DoNothing(); } elif (true) { DoNothing(); } else { return (); } @@ -868,7 +868,7 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation InvalidReturnFromWithinUsing12 () : Unit { - using q = Qubit() { + use q = Qubit() { if (true) { return (); } elif (true) { return (); } else { return (); } @@ -877,7 +877,7 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation InvalidReturnFromWithinUsing13 () : Unit { - using q = Qubit() { + use q = Qubit() { if (true) { if (true) { DoNothing(); } @@ -893,7 +893,7 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation InvalidReturnFromWithinUsing14 () : Unit { - using q = Qubit() { + use q = Qubit() { if (true) { DoNothing(); } elif (true) { if (true) { @@ -908,7 +908,7 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation InvalidReturnFromWithinUsing15 () : Unit { - using q = Qubit() { + use q = Qubit() { if (true) { DoNothing(); } elif (true) { DoNothing(); } else { @@ -926,20 +926,20 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { // valid uses of return within borrowing operation ReturnFromWithinBorrowing1 () : Unit { - borrowing q = Qubit() { + borrow q = Qubit() { return (); } } operation ReturnFromWithinBorrowing2 () : Unit { - borrowing q = Qubit() { + borrow q = Qubit() { if (true) { return (); } else { DoNothing(); } } } operation ReturnFromWithinBorrowing3 () : Unit { - borrowing q = Qubit() { + borrow q = Qubit() { if (true) { DoNothing(); } elif (true) { return (); } else { DoNothing(); } @@ -947,7 +947,7 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation ReturnFromWithinBorrowing4 () : Unit { - borrowing q = Qubit() { + borrow q = Qubit() { if (true) { DoNothing(); } elif (true) { DoNothing(); } else { return (); } @@ -955,7 +955,7 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation ReturnFromWithinBorrowing5 () : Unit { - borrowing q = Qubit() { + borrow q = Qubit() { if (true) { return (); } elif (true) { return (); } else { return (); } @@ -963,7 +963,7 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation ReturnFromWithinBorrowing6 () : Unit { - borrowing q = Qubit() { + borrow q = Qubit() { repeat { return (); } until(true) fixup { DoNothing(); } @@ -971,7 +971,7 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation ReturnFromWithinBorrowing7 () : Unit { - borrowing q = Qubit() { + borrow q = Qubit() { repeat { DoNothing(); return (); @@ -984,7 +984,7 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation ReturnFromWithinBorrowing8 () : Unit { - borrowing q = Qubit() { + borrow q = Qubit() { for i in 1..10 { DoNothing(); return (); @@ -995,28 +995,28 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { // invalid uses of return within borrowing operation InvalidReturnFromWithinBorrowing1 () : Unit { - borrowing q = Qubit() { + borrow q = Qubit() { return (); DoNothing(); } } operation InvalidReturnFromWithinBorrowing2 () : Unit { - borrowing q = Qubit() { + borrow q = Qubit() { return (); fail "unreachable"; } } operation InvalidReturnFromWithinBorrowing3 () : Unit { - borrowing q = Qubit() { + borrow q = Qubit() { return (); if (true) { return (); } } } operation InvalidReturnFromWithinBorrowing4 () : Unit { - borrowing q = Qubit() { + borrow q = Qubit() { return (); repeat {} until(true) @@ -1025,7 +1025,7 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation InvalidReturnFromWithinBorrowing5 () : Unit { - borrowing q = Qubit() { + borrow q = Qubit() { repeat { DoNothing(); } until(false) fixup { return (); } @@ -1033,7 +1033,7 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation InvalidReturnFromWithinBorrowing6 () : Unit { - borrowing q = Qubit() { + borrow q = Qubit() { repeat { return (); DoNothing(); @@ -1044,7 +1044,7 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation InvalidReturnFromWithinBorrowing7 () : Unit { - borrowing q = Qubit() { + borrow q = Qubit() { repeat { DoNothing(); } until(true) fixup { @@ -1055,35 +1055,35 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation InvalidReturnFromWithinBorrowing8 () : Unit { - borrowing q = Qubit() { + borrow q = Qubit() { within { return(); } apply {} } } operation InvalidReturnFromWithinBorrowing9 () : Unit { - borrowing q = Qubit() { + borrow q = Qubit() { within {} apply { return(); } } } operation InvalidReturnFromWithinBorrowing10 () : Unit { - borrowing q = Qubit() { + borrow q = Qubit() { return (); for i in 1..10 {} } } operation InvalidReturnFromWithinBorrowing11 () : Unit { - borrowing q = Qubit() { + borrow q = Qubit() { if (true) { return (); } DoNothing(); } } operation InvalidReturnFromWithinBorrowing12 () : Unit { - borrowing q = Qubit() { + borrow q = Qubit() { if (true) { DoNothing(); } elif (true) { return (); } else { DoNothing(); } @@ -1092,7 +1092,7 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation InvalidReturnFromWithinBorrowing13 () : Unit { - borrowing q = Qubit() { + borrow q = Qubit() { if (true) { DoNothing(); } elif (true) { DoNothing(); } else { return (); } @@ -1101,7 +1101,7 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation InvalidReturnFromWithinBorrowing14 () : Unit { - borrowing q = Qubit() { + borrow q = Qubit() { if (true) { return (); } elif (true) { return (); } else { return (); } @@ -1110,7 +1110,7 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation InvalidReturnFromWithinBorrowing15 () : Unit { - borrowing q = Qubit() { + borrow q = Qubit() { if (true) { return(); } elif (true) { return (); @@ -1121,7 +1121,7 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation InvalidReturnFromWithinBorrowing16 () : Unit { - borrowing q = Qubit() { + borrow q = Qubit() { if (true) { return(); DoNothing(); @@ -1133,7 +1133,7 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation InvalidReturnFromWithinBorrowing17 () : Unit { - borrowing q = Qubit() { + borrow q = Qubit() { if (true) { return(); } elif (true) { return (); } else { @@ -1147,93 +1147,93 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { // valid uses of return within multiple possibly nested qubit scopes operation ValidReturnPlacement1 () : Unit { - using q = Qubit() { + use q = Qubit() { return (); } DoNothing(); } operation ValidReturnPlacement2 () : Unit { - borrowing q = Qubit() { + borrow q = Qubit() { return (); } DoNothing(); } operation ValidReturnPlacement3 () : Unit { - using q = Qubit() { + use q = Qubit() { if (true) { return (); } } DoNothing(); } operation ValidReturnPlacement4 () : Unit { - borrowing q = Qubit() { + borrow q = Qubit() { if (true) { return (); } } DoNothing(); } operation ValidReturnPlacement5 () : Unit { - using q = Qubit() { + use q = Qubit() { if (true) { return (); } } - borrowing q = Qubit() { + borrow q = Qubit() { DoNothing(); return (); } } operation ValidReturnPlacement6 () : Unit { - using q = Qubit() { + use q = Qubit() { if (true) { return (); } } - using q = Qubit() { + use q = Qubit() { DoNothing(); return (); } } operation ValidReturnPlacement7 () : Unit { - using q = Qubit() { + use q = Qubit() { DoNothing(); - using c = Qubit() { + use c = Qubit() { return (); } } } operation ValidReturnPlacement8 () : Unit { - using q = Qubit() { + use q = Qubit() { DoNothing(); - borrowing c = Qubit() { + borrow c = Qubit() { return (); } } } operation ValidReturnPlacement9 () : Unit { - borrowing q = Qubit() { + borrow q = Qubit() { DoNothing(); - using c = Qubit() { + use c = Qubit() { return (); } } } operation ValidReturnPlacement10 () : Unit { - borrowing q = Qubit() { + borrow q = Qubit() { DoNothing(); - borrowing c = Qubit() { + borrow c = Qubit() { return (); } } } operation ValidReturnPlacement11 () : Unit { - using q = Qubit() { + use q = Qubit() { if (true) { - using c = Qubit() { + use c = Qubit() { return (); } } @@ -1244,10 +1244,10 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation ValidReturnPlacement12 () : Unit { - using q = Qubit() { + use q = Qubit() { if (true) { } else { - using c = Qubit() { + use c = Qubit() { return (); } } @@ -1255,9 +1255,9 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation ValidReturnPlacement13 () : Unit { - using q = Qubit() { + use q = Qubit() { repeat { - using c = Qubit() { + use c = Qubit() { return (); } } @@ -1269,9 +1269,9 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation ValidReturnPlacement14 () : Unit { - using q = Qubit() { + use q = Qubit() { for i in 1 .. 10 { - using c = Qubit() { + use c = Qubit() { if (i == 1) { return (); } } } @@ -1280,7 +1280,7 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { operation ValidReturnPlacement15 () : Unit { for i in 1 .. 10 { - using c = Qubit() { + use c = Qubit() { if (i == 1) { return (); } } DoNothing(); @@ -1291,8 +1291,8 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { // invalid uses of return within multiple possibly nested qubit scopes operation InvalidReturnPlacement1 () : Unit { - using q = Qubit() { - using c = Qubit() { + use q = Qubit() { + use c = Qubit() { return (); } DoNothing(); @@ -1300,8 +1300,8 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation InvalidReturnPlacement2 () : Unit { - using q = Qubit() { - borrowing c = Qubit() { + use q = Qubit() { + borrow c = Qubit() { return (); } DoNothing(); @@ -1309,8 +1309,8 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation InvalidReturnPlacement3 () : Unit { - borrowing q = Qubit() { - using c = Qubit() { + borrow q = Qubit() { + use c = Qubit() { return (); } DoNothing(); @@ -1318,8 +1318,8 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation InvalidReturnPlacement4 () : Unit { - borrowing q = Qubit() { - borrowing c = Qubit() { + borrow q = Qubit() { + borrow c = Qubit() { return (); } DoNothing(); @@ -1327,9 +1327,9 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation InvalidReturnPlacement5 () : Unit { - using q = Qubit() { + use q = Qubit() { if (true) { - using c = Qubit() { + use c = Qubit() { return (); } } @@ -1338,10 +1338,10 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation InvalidReturnPlacement6 () : Unit { - using q = Qubit() { + use q = Qubit() { if (true) {} else { - using c = Qubit() { + use c = Qubit() { return (); } } @@ -1350,10 +1350,10 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation InvalidReturnPlacement7 () : Unit { - using q = Qubit() { + use q = Qubit() { if (true) { } else { - using c = Qubit() { + use c = Qubit() { return (); } DoNothing(); @@ -1362,11 +1362,11 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation InvalidReturnPlacement8 () : Unit { - using q = Qubit() { + use q = Qubit() { repeat {} until (true) fixup { - using c = Qubit() { + use c = Qubit() { return (); } } @@ -1375,11 +1375,11 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation InvalidReturnPlacement9 () : Unit { - using q = Qubit() { + use q = Qubit() { repeat {} until (true) fixup { - using c = Qubit() { + use c = Qubit() { return (); } DoNothing(); @@ -1388,9 +1388,9 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation InvalidReturnPlacement10 () : Unit { - using q = Qubit() { + use q = Qubit() { repeat { - using c = Qubit() { + use c = Qubit() { return (); } } @@ -1401,9 +1401,9 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation InvalidReturnPlacement11 () : Unit { - using q = Qubit() { + use q = Qubit() { repeat { - using c = Qubit() { + use c = Qubit() { return (); } DoNothing(); @@ -1414,9 +1414,9 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation InvalidReturnPlacement12 () : Unit { - using q = Qubit() { + use q = Qubit() { for i in 1 .. 10 { - using c = Qubit() { + use c = Qubit() { if (i == 1) { return (); } } } @@ -1425,9 +1425,9 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation InvalidReturnPlacement13 () : Unit { - using q = Qubit() { + use q = Qubit() { for i in 1 .. 10 { - using c = Qubit() { + use c = Qubit() { if (i == 1) { return (); } } DoNothing(); @@ -1436,9 +1436,9 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation InvalidReturnPlacement14 () : Unit { - using q = Qubit() { + use q = Qubit() { for i in 1 .. 10 { - using c = Qubit() { + use c = Qubit() { if (i == 1) { return (); } DoNothing(); } @@ -1447,11 +1447,11 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation InvalidReturnPlacement15 () : Unit { - using q = Qubit() { + use q = Qubit() { repeat {} until (true) fixup { - using c = Qubit() { + use c = Qubit() { return (); } } @@ -1459,10 +1459,10 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation InvalidReturnPlacement16 () : Unit { - using q = Qubit() { + use q = Qubit() { within {} apply { - using c = Qubit() { + use c = Qubit() { return (); } } @@ -1470,9 +1470,9 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation InvalidReturnPlacement17 () : Unit { - using q = Qubit() { + use q = Qubit() { within { - using c = Qubit() { + use c = Qubit() { return (); } } @@ -1481,7 +1481,7 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation InvalidReturnPlacement18 (arg : Bool) : Unit { - using q = Qubit() { + use q = Qubit() { within {} apply { if (arg) { return (); } @@ -1490,7 +1490,7 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation InvalidReturnPlacement19 (arg : Bool) : Unit { - using q = Qubit() { + use q = Qubit() { within { if (arg) { return (); } } @@ -1499,7 +1499,7 @@ namespace Microsoft.Quantum.Testing.GlobalVerification { } operation InvalidReturnPlacement20 () : Unit { - using q = Qubit() { + use q = Qubit() { within { within { return(); diff --git a/src/QsCompiler/Tests.Compiler/TestCases/LocalVerification.qs b/src/QsCompiler/Tests.Compiler/TestCases/LocalVerification.qs index 6fad1bdde4..010c79e672 100644 --- a/src/QsCompiler/Tests.Compiler/TestCases/LocalVerification.qs +++ b/src/QsCompiler/Tests.Compiler/TestCases/LocalVerification.qs @@ -226,43 +226,43 @@ namespace Microsoft.Quantum.Testing.LocalVerification { // variable declarations operation VariableDeclaration1 () : Unit { - using q = Qubit() {} + use q = Qubit() {} } operation VariableDeclaration2 () : Unit { - using q = (Qubit()) {} + use q = (Qubit()) {} } operation VariableDeclaration3 () : Unit { - using (q) = Qubit() {} + use (q) = Qubit() {} } operation VariableDeclaration4 () : Unit { - using (q) = (Qubit()) {} + use (q) = (Qubit()) {} } operation VariableDeclaration5 () : Unit { - using (q1, q2) = (Qubit(), Qubit()) {} + use (q1, q2) = (Qubit(), Qubit()) {} } operation VariableDeclaration6 () : Unit { - using (q1, (q2)) = (Qubit(), Qubit()) {} + use (q1, (q2)) = (Qubit(), Qubit()) {} } operation VariableDeclaration7 () : Unit { - using (qs) = (Qubit(), Qubit()) {} + use (qs) = (Qubit(), Qubit()) {} } operation VariableDeclaration8 () : Unit { - using qs = (Qubit(), Qubit()) {} + use qs = (Qubit(), Qubit()) {} } operation VariableDeclaration9 () : Unit { - using (q1, q2) = (Qubit()) {} + use (q1, q2) = (Qubit()) {} } operation VariableDeclaration10 () : Unit { - using (q1, q2, q3) = (Qubit(), (Qubit(), Qubit())) {} + use (q1, q2, q3) = (Qubit(), (Qubit(), Qubit())) {} } operation VariableDeclaration11<'T>(cnt: Int, arg : 'T) : Unit { @@ -1450,19 +1450,37 @@ namespace Microsoft.Quantum.Testing.LocalVerification { } } - operation ParensUsing() : Unit { - using (q = Qubit()) { } + operation ParensUse() : Unit { + use (q = Qubit()) { } + } + + operation NoParensUse() : Unit { + use q = Qubit() { } + } + + operation ParensBorrow() : Unit { + borrow (q = Qubit()) { } + } + + operation NoParensBorrow() : Unit { + borrow q = Qubit() { } } - operation NoParensUsing() : Unit { + // Deprecated qubit allocation keywords + + operation DeprecatedUsingKeyword() : Unit { using q = Qubit() { } } - operation ParensBorrowing() : Unit { - borrowing (q = Qubit()) { } + operation DeprecatedUsingKeywordParens() : Unit { + using (q = Qubit()) { } } - operation NoParensBorrowing() : Unit { + operation DeprecatedBorrowingKeyword() : Unit { borrowing q = Qubit() { } } + + operation DeprecatedBorrowingKeywordParens() : Unit { + borrowing (q = Qubit()) { } + } } From 77e09bc27613ab7cc61bb84071a691598f166db5 Mon Sep 17 00:00:00 2001 From: Sarah Marshall Date: Wed, 6 Jan 2021 11:44:20 -0800 Subject: [PATCH 4/7] Update code completion --- .../Tests.Compiler/CompletionParsingTests.fs | 69 ++++++++++++++++++- .../CodeCompletion/FragmentParsing.fs | 8 ++- 2 files changed, 72 insertions(+), 5 deletions(-) diff --git a/src/QsCompiler/Tests.Compiler/CompletionParsingTests.fs b/src/QsCompiler/Tests.Compiler/CompletionParsingTests.fs index a03b43355f..4d6607b02a 100644 --- a/src/QsCompiler/Tests.Compiler/CompletionParsingTests.fs +++ b/src/QsCompiler/Tests.Compiler/CompletionParsingTests.fs @@ -10,7 +10,6 @@ open Microsoft.Quantum.QsCompiler.SyntaxTokens open Microsoft.Quantum.QsCompiler.TextProcessing.CodeCompletion open Microsoft.Quantum.QsCompiler.TextProcessing.CodeCompletion.FragmentParsing - let private matches scope previous (text, expected) = match GetCompletionKinds scope previous text with | Success actual -> @@ -75,7 +74,15 @@ let private callableStatement = let private functionStatement = callableStatement @ [ Keyword "while" ] let private operationStatement = - callableStatement @ [ Keyword "repeat"; Keyword "using"; Keyword "borrowing"; Keyword "within" ] + callableStatement + @ [ + Keyword "repeat" + Keyword "use" + Keyword "using" + Keyword "borrow" + Keyword "borrowing" + Keyword "within" + ] let private operationTopLevelStatement = operationStatement @ [ Keyword "body"; Keyword "adjoint"; Keyword "controlled" ] @@ -500,7 +507,34 @@ let ``Operation statement parser tests`` () = [ ("repeat ", []) ("within ", []) - ("using ", []) + ("use ", [ Declaration ]) + ("use q ", []) + ("use q =", [ Keyword "Qubit" ]) + ("use q = Qubit", [ Keyword "Qubit" ]) + ("use q = Qubit(", []) + ("use q = Qubit()", []) + ("use q = Qubit[", expression) + ("use q = Qubit[5", []) + ("use q = Qubit[5]", []) + ("use q = Qubit[n", expression) + ("use q = Qubit[n ", infix) + ("use q = Qubit[n +", expression) + ("use q = Qubit[n +1", []) + ("use q = Qubit[n +x", expression) + ("use q = Qubit[n + ", expression) + ("use q = Qubit[n + 1", []) + ("use q = Qubit[n + 1]", []) + ("use (", [ Declaration ]) + ("use (q,", [ Declaration ]) + ("use (q, r)", []) + ("use (q, r) =", [ Keyword "Qubit" ]) + ("use (q, r) = (", [ Keyword "Qubit" ]) + ("use (q, r) = (Qubit(", []) + ("use (q, r) = (Qubit()", []) + ("use (q, r) = (Qubit(),", [ Keyword "Qubit" ]) + ("use (q, r) = (Qubit(), Qubit()", []) + ("use (q, r) = (Qubit(), Qubit())", []) + ("using ", [ Declaration ]) ("using (", [ Declaration ]) ("using (q ", []) ("using (q =", [ Keyword "Qubit" ]) @@ -531,6 +565,34 @@ let ``Operation statement parser tests`` () = ("using ((q, r) = (Qubit(),", [ Keyword "Qubit" ]) ("using ((q, r) = (Qubit(), Qubit()", []) ("using ((q, r) = (Qubit(), Qubit())", []) + ("using ((q, r) = (Qubit(), Qubit()))", []) + ("borrow ", [ Declaration ]) + ("borrow q ", []) + ("borrow q =", [ Keyword "Qubit" ]) + ("borrow q = Qubit", [ Keyword "Qubit" ]) + ("borrow q = Qubit(", []) + ("borrow q = Qubit()", []) + ("borrow q = Qubit[", expression) + ("borrow q = Qubit[5", []) + ("borrow q = Qubit[5]", []) + ("borrow q = Qubit[n", expression) + ("borrow q = Qubit[n ", infix) + ("borrow q = Qubit[n +", expression) + ("borrow q = Qubit[n +1", []) + ("borrow q = Qubit[n +x", expression) + ("borrow q = Qubit[n + ", expression) + ("borrow q = Qubit[n + 1]", []) + ("borrow (", [ Declaration ]) + ("borrow (q,", [ Declaration ]) + ("borrow (q, r)", []) + ("borrow (q, r) =", [ Keyword "Qubit" ]) + ("borrow (q, r) = (", [ Keyword "Qubit" ]) + ("borrow (q, r) = (Qubit(", []) + ("borrow (q, r) = (Qubit()", []) + ("borrow (q, r) = (Qubit(),", [ Keyword "Qubit" ]) + ("borrow (q, r) = (Qubit(), Qubit()", []) + ("borrow (q, r) = (Qubit(), Qubit())", []) + ("borrowing ", [ Declaration ]) ("borrowing (", [ Declaration ]) ("borrowing (q ", []) ("borrowing (q =", [ Keyword "Qubit" ]) @@ -560,6 +622,7 @@ let ``Operation statement parser tests`` () = ("borrowing ((q, r) = (Qubit(),", [ Keyword "Qubit" ]) ("borrowing ((q, r) = (Qubit(), Qubit()", []) ("borrowing ((q, r) = (Qubit(), Qubit())", []) + ("borrowing ((q, r) = (Qubit(), Qubit()))", []) ] testElifElse Operation (Value(IfClause { Expression = InvalidExpr; Range = Null })) diff --git a/src/QsCompiler/TextProcessor/CodeCompletion/FragmentParsing.fs b/src/QsCompiler/TextProcessor/CodeCompletion/FragmentParsing.fs index 87331f93f2..e4a3343ede 100644 --- a/src/QsCompiler/TextProcessor/CodeCompletion/FragmentParsing.fs +++ b/src/QsCompiler/TextProcessor/CodeCompletion/FragmentParsing.fs @@ -154,12 +154,16 @@ let rec private qubitInitializerTuple = /// Parses a using-block intro. let private usingHeader = let binding = symbolTuple Declaration ?>> expected equal ?>> qubitInitializerTuple - expectedKeyword qsUsing ?>> expectedBrackets (lTuple, rTuple) binding + + expectedKeyword qsUse <|>@ expectedKeyword qsUsing + ?>> (brackets (lTuple, rTuple) binding <|>@ binding) /// Parses a borrowing-block intro. let private borrowingHeader = let binding = symbolTuple Declaration ?>> expected equal ?>> qubitInitializerTuple - expectedKeyword qsBorrowing ?>> expectedBrackets (lTuple, rTuple) binding + + expectedKeyword qsBorrow <|>@ expectedKeyword qsBorrowing + ?>> (brackets (lTuple, rTuple) binding <|>@ binding) /// Parses an operation specialization declaration. let private specializationDeclaration = From 7a2f2193d871472e5dfc917a683e50eb820a8471 Mon Sep 17 00:00:00 2001 From: Sarah Marshall Date: Wed, 6 Jan 2021 11:52:13 -0800 Subject: [PATCH 5/7] Update VS Code snippet --- src/VSCodeExtension/snippets/qsharp.json | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/VSCodeExtension/snippets/qsharp.json b/src/VSCodeExtension/snippets/qsharp.json index 109e58cb60..eef5b8ea8a 100644 --- a/src/VSCodeExtension/snippets/qsharp.json +++ b/src/VSCodeExtension/snippets/qsharp.json @@ -60,12 +60,10 @@ "description": "Documentation comments" }, - "Using": { - "prefix": "using", + "Use": { + "prefix": "use", "body": [ - "${1|using,borrowing|} (${2:name} = Qubit()) {", - " ${3:// ...}", - "}" + "${1|use,borrow|} ${2:name} = Qubit();" ], "description": "Allocate a new qubit or register" } From ccbd5e38a0a01a91837b80ae7b1a285a37a7e8af Mon Sep 17 00:00:00 2001 From: Sarah Marshall <33814365+samarsha@users.noreply.github.com> Date: Mon, 11 Jan 2021 11:27:28 -0800 Subject: [PATCH 6/7] Consistent phrasing in deprecated keyword warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: César Zaragoza Cortés --- src/QsCompiler/DataStructures/Diagnostics.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/QsCompiler/DataStructures/Diagnostics.fs b/src/QsCompiler/DataStructures/Diagnostics.fs index 99b64c2d5b..4988c98cb5 100644 --- a/src/QsCompiler/DataStructures/Diagnostics.fs +++ b/src/QsCompiler/DataStructures/Diagnostics.fs @@ -892,7 +892,7 @@ type DiagnosticItem = "Double underscores as well as underscores before a dot or at the end of a namespace name will be reserved for internal use in the future." | WarningCode.DeprecatedTupleBrackets -> "Deprecated syntax. Parentheses here are no longer required and will not be supported in the future." - | WarningCode.DeprecatedKeyword -> "The \"{0}\" keyword is deprecated. Use the keyword \"{1}\" instead." + | WarningCode.DeprecatedKeyword -> "The \"{0}\" keyword is deprecated. Use the \"{1}\" keyword instead." | WarningCode.DeprecatedRUSloopInFunction -> "The use of repeat-until-success-loops within functions may not be supported in the future. Please use a while-loop instead." From 70e9b7fc9e93dae9bde6250cf92eb43d3f04e1b4 Mon Sep 17 00:00:00 2001 From: Sarah Marshall Date: Mon, 11 Jan 2021 12:39:17 -0800 Subject: [PATCH 7/7] Update use/borrow keyword in tests --- .../TestCases/LocalVerification.qs | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/QsCompiler/Tests.Compiler/TestCases/LocalVerification.qs b/src/QsCompiler/Tests.Compiler/TestCases/LocalVerification.qs index 2562c4e357..1fe47e1983 100644 --- a/src/QsCompiler/Tests.Compiler/TestCases/LocalVerification.qs +++ b/src/QsCompiler/Tests.Compiler/TestCases/LocalVerification.qs @@ -338,28 +338,28 @@ namespace Microsoft.Quantum.Testing.LocalVerification { } operation VariableDeclaration22() : Unit { - using q = Qubit(); + use q = Qubit(); } operation VariableDeclaration23() : Unit { - using q = Qubit(); + use q = Qubit(); Operation(q); } operation VariableDeclaration24() : Unit { - using q = Qubit(); + use q = Qubit(); Operation(foo); } operation VariableDeclaration25() : Result { - using q = Qubit(); + use q = Qubit(); Operation(q); return M(q); } operation VariableDeclaration26() : Result { if (true) { - using q = Qubit(); + use q = Qubit(); Operation(q); return M(q); } else { @@ -368,7 +368,7 @@ namespace Microsoft.Quantum.Testing.LocalVerification { } operation VariableDeclaration27() : Bool { - using q = Qubit(); + use q = Qubit(); Operation(q); if M(q) == One { return true; @@ -378,30 +378,30 @@ namespace Microsoft.Quantum.Testing.LocalVerification { } operation VariableDeclaration28() : Unit { - using q = Qubit() + use q = Qubit() } operation VariableDeclaration29() : Unit { if (true) { - using q = Qubit(); + use q = Qubit(); Operation(q); } Operation(q); } operation VariableDeclaration30() : Result { - borrowing q = Qubit(); + borrow q = Qubit(); Operation(q); return M(q); } operation VariableDeclaration31() : Unit { - borrowing q = Qubit() + borrow q = Qubit() } operation VariableDeclaration32() : Unit { if (true) { - borrowing q = Qubit(); + borrow q = Qubit(); Operation(q); } Operation(q);