From 3bc7b85ccb0d56f600b9cc92bfe7c397e510480f Mon Sep 17 00:00:00 2001 From: Bettina Heim Date: Thu, 16 Apr 2020 07:03:31 -0700 Subject: [PATCH 01/10] propagate the Q# OutputType --- src/QsCompiler/DataStructures/ReservedKeywords.fs | 3 +++ src/QuantumSdk/Sdk/Sdk.targets | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/QsCompiler/DataStructures/ReservedKeywords.fs b/src/QsCompiler/DataStructures/ReservedKeywords.fs index b636ebd09e..f1687a0ecb 100644 --- a/src/QsCompiler/DataStructures/ReservedKeywords.fs +++ b/src/QsCompiler/DataStructures/ReservedKeywords.fs @@ -234,6 +234,9 @@ module GeneratedAttributes = module AssemblyConstants = let OutputPath = "OutputPath" let AssemblyName = "AssemblyName" + let QsharpOutputType = "ResolvedQsharpOutputType" + let QsharpExe = "QsharpExe" + let QsharpLibrary = "QsharpLibrary" let ExecutionTarget = "ResolvedExecutionTarget" let AlfredProcessor = "AlfredProcessor" let BrunoProcessor = "BrunoProcessor" diff --git a/src/QuantumSdk/Sdk/Sdk.targets b/src/QuantumSdk/Sdk/Sdk.targets index 9b8b732f22..86f3887fe1 100644 --- a/src/QuantumSdk/Sdk/Sdk.targets +++ b/src/QuantumSdk/Sdk/Sdk.targets @@ -77,7 +77,7 @@ <_QscCommandRuntimeFlag>--runtime $(ResolvedRuntimeCapabilites) <_QscCommandTargetPackageFlag Condition="'$(ResolvedTargetPackage)' != ''">--target-package "$(ResolvedTargetPackage)" <_QscCommandTestNamesFlag Condition="$(ExposeReferencesViaTestNames)">--load-test-names - <_QscCommandPredefinedAssemblyProperties>ResolvedExecutionTarget:$(ResolvedQsharpExecutionTarget) + <_QscCommandPredefinedAssemblyProperties>ResolvedExecutionTarget:$(ResolvedQsharpExecutionTarget) ResolvedQsharpOutputType:$(ResolvedQsharpOutputType) <_QscCommandPredefinedAssemblyProperties Condition="$(DefaultSimulator) != ''">$(_QscCommandPredefinedAssemblyProperties) DefaultSimulator:$(DefaultSimulator) <_QscCommandAssemblyPropertiesFlag>--assembly-properties $(_QscCommandPredefinedAssemblyProperties) $(QscCommandAssemblyProperties) <_QscPackageLoadFallbackFoldersFlag Condition="@(ResolvedPackageLoadFallbackFolders->Count()) > 0">--package-load-fallback-folders "@(ResolvedPackageLoadFallbackFolders,'" "')" From b7d7950ac148e218db0b80beb9698119ff5da2c4 Mon Sep 17 00:00:00 2001 From: Bettina Heim Date: Thu, 16 Apr 2020 07:26:55 -0700 Subject: [PATCH 02/10] require an entry point when executing on a quantum processor --- src/QsCompiler/Compiler/CompilationLoader.cs | 4 ++-- src/QsCompiler/DataStructures/Diagnostics.fs | 16 +++++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/QsCompiler/Compiler/CompilationLoader.cs b/src/QsCompiler/Compiler/CompilationLoader.cs index 2c53d9179f..8e24efc50f 100644 --- a/src/QsCompiler/Compiler/CompilationLoader.cs +++ b/src/QsCompiler/Compiler/CompilationLoader.cs @@ -447,8 +447,8 @@ public CompilationLoader(SourceLoader loadSources, ReferenceLoader loadReference if (this.Config.IsExecutable && this.CompilationOutput?.EntryPoints.Length == 0) { - this.Logger?.Log(WarningCode.MissingEntryPoint, Array.Empty()); - + if (this.Config.RuntimeCapabilities == RuntimeCapabilities.Unknown) this.Logger?.Log(WarningCode.MissingEntryPoint, Array.Empty()); + else this.LogAndUpdate(ref this.CompilationStatus.Validation, ErrorCode.MissingEntryPoint, Array.Empty()); } // TODO: // give warnings and ignore entry points in libraries, diff --git a/src/QsCompiler/DataStructures/Diagnostics.fs b/src/QsCompiler/DataStructures/Diagnostics.fs index 9c2df007e8..08ab8c5d5d 100644 --- a/src/QsCompiler/DataStructures/Diagnostics.fs +++ b/src/QsCompiler/DataStructures/Diagnostics.fs @@ -237,13 +237,14 @@ type ErrorCode = | InnerTupleInEntryPointArgument = 6234 | ArrayOfArrayInEntryPointArgument = 6235 | MultipleEntryPoints = 6236 - | InvalidEntryPointSpecialization = 6237 - | DuplicateEntryPointArgumentName = 6238 - | InvalidTestAttributePlacement = 6239 - | InvalidExecutionTargetForTest = 6240 - | ExpectingFullNameAsAttributeArgument = 6241 - | AttributeInvalidOnSpecialization = 6242 - | AttributeInvalidOnCallable = 6243 + | MissingEntryPoint = 6237 + | InvalidEntryPointSpecialization = 6238 + | DuplicateEntryPointArgumentName = 6239 + | InvalidTestAttributePlacement = 6240 + | InvalidExecutionTargetForTest = 6241 + | ExpectingFullNameAsAttributeArgument = 6242 + | AttributeInvalidOnSpecialization = 6243 + | AttributeInvalidOnCallable = 6244 | TypeMismatchInReturn = 6301 | TypeMismatchInValueUpdate = 6302 @@ -610,6 +611,7 @@ type DiagnosticItem = | ErrorCode.InnerTupleInEntryPointArgument -> "Anonymous tuple items or arrays of tuples are not supported in entry point arguments. All items need to be named." | ErrorCode.ArrayOfArrayInEntryPointArgument -> "Multi-dimensional arrays are not supported in entry point arguments." | ErrorCode.MultipleEntryPoints -> "Invalid entry point. An entry point {0} already exists in {1}." + | ErrorCode.MissingEntryPoint -> "Missing entry point. Execution on a quantum processor requires that a Q# entry point is defined using the @EntryPoint() attribute. Any C# driver code should be defined in a separate project." | ErrorCode.InvalidEntryPointSpecialization -> "Entry points cannot have any other specializations besides the default body." | ErrorCode.DuplicateEntryPointArgumentName -> "Invalid name for entry point argument. A similar argument name is already in use." | ErrorCode.InvalidTestAttributePlacement -> "Invalid test attribute. Test attributes may only occur on callables that have no arguments and return Unit." From bede64831043c5a2d03a776a2aa4ceb5b187cce8 Mon Sep 17 00:00:00 2001 From: Bettina Heim Date: Thu, 16 Apr 2020 09:32:27 -0700 Subject: [PATCH 03/10] add am undocumented NoEntryPoint override in Sdk --- src/QuantumSdk/DefaultItems/DefaultItems.targets | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/QuantumSdk/DefaultItems/DefaultItems.targets b/src/QuantumSdk/DefaultItems/DefaultItems.targets index 4f8243ac80..eefb86e7e9 100644 --- a/src/QuantumSdk/DefaultItems/DefaultItems.targets +++ b/src/QuantumSdk/DefaultItems/DefaultItems.targets @@ -19,8 +19,8 @@ - QsharpLibrary - QsharpExe + QsharpLibrary + QsharpExe Possible values are 'Exe', or 'Library'. From 8e43d5f8ff8243aa4f4dc5ee67dde620b09c2f63 Mon Sep 17 00:00:00 2001 From: Bettina Heim Date: Thu, 16 Apr 2020 09:41:30 -0700 Subject: [PATCH 04/10] forgot something --- src/QuantumSdk/DefaultItems/DefaultItems.targets | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/QuantumSdk/DefaultItems/DefaultItems.targets b/src/QuantumSdk/DefaultItems/DefaultItems.targets index eefb86e7e9..f6077a7fb1 100644 --- a/src/QuantumSdk/DefaultItems/DefaultItems.targets +++ b/src/QuantumSdk/DefaultItems/DefaultItems.targets @@ -27,12 +27,12 @@ - AlfredProcessor - BrunoProcessor - ClementineProcessor + AlfredProcessor + BrunoProcessor + ClementineProcessor Unspecified - Possible values are 'Alfred', 'Bruno', 'Clementine', or 'Any'. + Possible values are 'Alfred', 'Bruno', 'Clementine', or 'Any'. The execution target for a Q# library needs to be 'Any'. From 6ead4b552e5f22b465b7e3ed727d4d934e223d57 Mon Sep 17 00:00:00 2001 From: Bettina Heim Date: Thu, 16 Apr 2020 10:11:05 -0700 Subject: [PATCH 05/10] fix --- src/QuantumSdk/DefaultItems/DefaultItems.targets | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/QuantumSdk/DefaultItems/DefaultItems.targets b/src/QuantumSdk/DefaultItems/DefaultItems.targets index f6077a7fb1..111fdaa88e 100644 --- a/src/QuantumSdk/DefaultItems/DefaultItems.targets +++ b/src/QuantumSdk/DefaultItems/DefaultItems.targets @@ -27,12 +27,12 @@ - AlfredProcessor - BrunoProcessor - ClementineProcessor + AlfredProcessor + BrunoProcessor + ClementineProcessor Unspecified - Possible values are 'Alfred', 'Bruno', 'Clementine', or 'Any'. + Possible values are 'Alfred', 'Bruno', 'Clementine', or 'Any'. The execution target for a Q# library needs to be 'Any'. From 6a5e65c8d540f772bc678bd72df9f4186d7cba5a Mon Sep 17 00:00:00 2001 From: Bettina Heim Date: Thu, 16 Apr 2020 16:54:36 -0700 Subject: [PATCH 06/10] fixing renaming transformations --- .../RewriteSteps/ClassicallyControlled.cs | 1 - .../Transformations/SearchAndReplace.cs | 23 ++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/QsCompiler/Compiler/RewriteSteps/ClassicallyControlled.cs b/src/QsCompiler/Compiler/RewriteSteps/ClassicallyControlled.cs index 582a33d833..0d718936ee 100644 --- a/src/QsCompiler/Compiler/RewriteSteps/ClassicallyControlled.cs +++ b/src/QsCompiler/Compiler/RewriteSteps/ClassicallyControlled.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; -using Microsoft.Quantum.QsCompiler.DataTypes; using Microsoft.Quantum.QsCompiler.SyntaxTree; using Microsoft.Quantum.QsCompiler.Transformations.ClassicallyControlled; diff --git a/src/QsCompiler/Transformations/SearchAndReplace.cs b/src/QsCompiler/Transformations/SearchAndReplace.cs index 8d629913a6..c918341e0a 100644 --- a/src/QsCompiler/Transformations/SearchAndReplace.cs +++ b/src/QsCompiler/Transformations/SearchAndReplace.cs @@ -430,9 +430,12 @@ public class UniqueVariableNames public class TransformationState { private int VariableNr = 0; - private Dictionary, NonNullable> UniqueNames = + private readonly Dictionary, NonNullable> UniqueNames = new Dictionary, NonNullable>(); + internal bool TryGetUniqueName(NonNullable name, out NonNullable unique) => + this.UniqueNames.TryGetValue(name, out unique); + internal QsExpressionKind AdaptIdentifier(Identifier sym, QsNullable> tArgs) => sym is Identifier.LocalVariable varName && this.UniqueNames.TryGetValue(varName.Item, out var unique) ? QsExpressionKind.NewIdentifier(Identifier.NewLocalVariable(unique), tArgs) @@ -453,6 +456,7 @@ internal NonNullable GenerateUniqueName(NonNullable varName) public UniqueVariableNames() : base(new TransformationState()) { + this.Statements = new StatementTransformation(this); this.StatementKinds = new StatementKindTransformation(this); this.ExpressionKinds = new ExpressionKindTransformation(this); this.Types = new TypeTransformation(this, TransformationOptions.Disabled); @@ -472,6 +476,23 @@ public static NonNullable StripUniqueName(NonNullable uniqueName // helper classes + private class StatementTransformation + : StatementTransformation + { + public StatementTransformation(SyntaxTreeTransformation parent) + : base(parent) { } + + public override LocalDeclarations OnLocalDeclarations(LocalDeclarations decl) + { + var variables = decl.Variables.Select(decl => + this.SharedState.TryGetUniqueName(decl.VariableName, out var unique) + ? new LocalVariableDeclaration>(unique, decl.Type, decl.InferredInformation, decl.Position, decl.Range) + : decl + ); + return base.OnLocalDeclarations(new LocalDeclarations(variables.ToImmutableArray())); + } + } + private class StatementKindTransformation : StatementKindTransformation { From 1fcb37a74a93794e002c03fc894490068df68a80 Mon Sep 17 00:00:00 2001 From: Bettina Heim Date: Thu, 16 Apr 2020 18:12:07 -0700 Subject: [PATCH 07/10] ... more of the same --- src/QsCompiler/Core/NamespaceTransformation.fs | 15 +++++++++++++-- src/QsCompiler/Core/StatementTransformation.fs | 8 ++++++-- .../Transformations/SearchAndReplace.cs | 11 ++--------- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/QsCompiler/Core/NamespaceTransformation.fs b/src/QsCompiler/Core/NamespaceTransformation.fs index e258301ea6..459bb7bde9 100644 --- a/src/QsCompiler/Core/NamespaceTransformation.fs +++ b/src/QsCompiler/Core/NamespaceTransformation.fs @@ -52,6 +52,9 @@ type NamespaceTransformationBase internal (options : TransformationOptions, _int abstract member OnAttribute : QsDeclarationAttribute -> QsDeclarationAttribute default this.OnAttribute att = att + abstract member OnItemName : NonNullable -> NonNullable + default this.OnItemName name = this.Statements.OnVariableName name + abstract member OnTypeItems : QsTuple -> QsTuple default this.OnTypeItems tItem = match tItem with @@ -63,10 +66,17 @@ type NamespaceTransformationBase internal (options : TransformationOptions, _int QsTupleItem << Anonymous |> Node.BuildOr original t | QsTupleItem (Named item) as original -> let loc = item.Position, item.Range + let name = this.OnItemName item.VariableName let t = this.Statements.Expressions.Types.OnType item.Type let info = this.Statements.Expressions.OnExpressionInformation item.InferredInformation - QsTupleItem << Named << LocalVariableDeclaration<_>.New info.IsMutable |> Node.BuildOr original (loc, item.VariableName, t, info.HasLocalQuantumDependency) + QsTupleItem << Named << LocalVariableDeclaration<_>.New info.IsMutable |> Node.BuildOr original (loc, name, t, info.HasLocalQuantumDependency) + abstract member OnArgumentName : QsLocalSymbol -> QsLocalSymbol + default this.OnArgumentName arg = + match arg with + | ValidName name -> ValidName |> Node.BuildOr arg (this.Statements.OnVariableName name) + | InvalidName -> arg + abstract member OnArgumentTuple : QsArgumentTuple -> QsArgumentTuple default this.OnArgumentTuple arg = match arg with @@ -75,9 +85,10 @@ type NamespaceTransformationBase internal (options : TransformationOptions, _int QsTuple |> Node.BuildOr original transformed | QsTupleItem item as original -> let loc = item.Position, item.Range + let name = this.OnArgumentName item.VariableName let t = this.Statements.Expressions.Types.OnType item.Type let info = this.Statements.Expressions.OnExpressionInformation item.InferredInformation - QsTupleItem << LocalVariableDeclaration<_>.New info.IsMutable |> Node.BuildOr original (loc, item.VariableName, t, info.HasLocalQuantumDependency) + QsTupleItem << LocalVariableDeclaration<_>.New info.IsMutable |> Node.BuildOr original (loc, name, t, info.HasLocalQuantumDependency) abstract member OnSignature : ResolvedSignature -> ResolvedSignature default this.OnSignature (s : ResolvedSignature) = diff --git a/src/QsCompiler/Core/StatementTransformation.fs b/src/QsCompiler/Core/StatementTransformation.fs index 83e5d98ce1..f8614335e2 100644 --- a/src/QsCompiler/Core/StatementTransformation.fs +++ b/src/QsCompiler/Core/StatementTransformation.fs @@ -213,14 +213,18 @@ and StatementTransformationBase internal (options : TransformationOptions, _inte abstract member OnLocation : QsNullable -> QsNullable default this.OnLocation loc = loc + abstract member OnVariableName : NonNullable -> NonNullable + default this.OnVariableName name = name + /// If DisableRebuild is set to true, this method won't walk the local variables declared by the statement. abstract member OnLocalDeclarations : LocalDeclarations -> LocalDeclarations default this.OnLocalDeclarations decl = let onLocalVariableDeclaration (local : LocalVariableDeclaration>) = let loc = local.Position, local.Range - let info = this.Expressions.OnExpressionInformation local.InferredInformation + let name = this.OnVariableName local.VariableName let varType = this.Expressions.Types.OnType local.Type - LocalVariableDeclaration.New info.IsMutable (loc, local.VariableName, varType, info.HasLocalQuantumDependency) + let info = this.Expressions.OnExpressionInformation local.InferredInformation + LocalVariableDeclaration.New info.IsMutable (loc, name, varType, info.HasLocalQuantumDependency) let variableDeclarations = decl.Variables |> Seq.map onLocalVariableDeclaration LocalDeclarations.New << ImmutableArray.CreateRange |> Node.BuildOr decl variableDeclarations diff --git a/src/QsCompiler/Transformations/SearchAndReplace.cs b/src/QsCompiler/Transformations/SearchAndReplace.cs index c918341e0a..ba3af7efff 100644 --- a/src/QsCompiler/Transformations/SearchAndReplace.cs +++ b/src/QsCompiler/Transformations/SearchAndReplace.cs @@ -482,15 +482,8 @@ private class StatementTransformation public StatementTransformation(SyntaxTreeTransformation parent) : base(parent) { } - public override LocalDeclarations OnLocalDeclarations(LocalDeclarations decl) - { - var variables = decl.Variables.Select(decl => - this.SharedState.TryGetUniqueName(decl.VariableName, out var unique) - ? new LocalVariableDeclaration>(unique, decl.Type, decl.InferredInformation, decl.Position, decl.Range) - : decl - ); - return base.OnLocalDeclarations(new LocalDeclarations(variables.ToImmutableArray())); - } + public override NonNullable OnVariableName(NonNullable name) => + this.SharedState.TryGetUniqueName(name, out var unique) ? unique : name; } private class StatementKindTransformation From 220000855bc2911851aab74bb52b48e52c6401db Mon Sep 17 00:00:00 2001 From: Bettina Heim Date: Thu, 16 Apr 2020 18:17:10 -0700 Subject: [PATCH 08/10] minor change --- src/QsCompiler/Core/NamespaceTransformation.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/QsCompiler/Core/NamespaceTransformation.fs b/src/QsCompiler/Core/NamespaceTransformation.fs index 459bb7bde9..d157e3d944 100644 --- a/src/QsCompiler/Core/NamespaceTransformation.fs +++ b/src/QsCompiler/Core/NamespaceTransformation.fs @@ -53,7 +53,7 @@ type NamespaceTransformationBase internal (options : TransformationOptions, _int default this.OnAttribute att = att abstract member OnItemName : NonNullable -> NonNullable - default this.OnItemName name = this.Statements.OnVariableName name + default this.OnItemName name = name abstract member OnTypeItems : QsTuple -> QsTuple default this.OnTypeItems tItem = From 969ad0c29a42996c09d5098a023d48d9c2bcdb0f Mon Sep 17 00:00:00 2001 From: Bettina Heim Date: Thu, 16 Apr 2020 20:39:49 -0700 Subject: [PATCH 09/10] forgot to add control qubits declaration to scopes when generating controlled --- .../Transformations/CodeTransformations.cs | 4 +-- .../Transformations/FunctorGeneration.cs | 35 ++++++++++++++++--- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/QsCompiler/Transformations/CodeTransformations.cs b/src/QsCompiler/Transformations/CodeTransformations.cs index f4f5ccd0af..78ca034df1 100644 --- a/src/QsCompiler/Transformations/CodeTransformations.cs +++ b/src/QsCompiler/Transformations/CodeTransformations.cs @@ -35,8 +35,8 @@ public static QsScope GenerateAdjoint(this QsScope scope) } /// - /// Given the body of an operation, auto-generates the (content of the) controlled specialization - /// using the default name for control qubits. + /// Given the body of an operation, auto-generates the (content of the) controlled specialization using the default name + /// for control qubits. Adds the control qubits names to the list of defined variables for the scope and each subscope. /// Throws an ArgumentNullException if the given scope is null. /// public static QsScope GenerateControlled(this QsScope scope) diff --git a/src/QsCompiler/Transformations/FunctorGeneration.cs b/src/QsCompiler/Transformations/FunctorGeneration.cs index f47871d31a..c936365fd7 100644 --- a/src/QsCompiler/Transformations/FunctorGeneration.cs +++ b/src/QsCompiler/Transformations/FunctorGeneration.cs @@ -18,7 +18,8 @@ namespace Microsoft.Quantum.QsCompiler.Transformations.FunctorGeneration /// /// Scope transformation that replaces each operation call within a given scope /// with a call to the operation after application of the functor given on initialization. - /// The default values used for auto-generation will be used for the additional functor arguments. + /// The default values used for auto-generation will be used for the additional functor arguments. + /// Additional functor arguments will be added to the list of defined variables for each scope. /// public class ApplyFunctorToOperationCalls : SyntaxTreeTransformation @@ -31,10 +32,10 @@ public TransformationsState(QsFunctor functor) => this.FunctorToApply = functor ?? throw new ArgumentNullException(nameof(functor)); } - public ApplyFunctorToOperationCalls(QsFunctor functor) : base(new TransformationsState(functor)) - { + { + if (functor.IsControlled) this.Statements = new AddVariableDeclarations(this, ControlQubitsDeclaration); this.StatementKinds = new IgnoreOuterBlockInConjugations(this); this.ExpressionKinds = new ExpressionKindTransformation(this); this.Types = new TypeTransformation(this, TransformationOptions.Disabled); @@ -43,8 +44,19 @@ public ApplyFunctorToOperationCalls(QsFunctor functor) // static methods for convenience + private static readonly NonNullable ControlQubitsName = + NonNullable.New(InternalUse.ControlQubitsName); + + private static readonly LocalVariableDeclaration> ControlQubitsDeclaration = + new LocalVariableDeclaration>( + ControlQubitsName, + ControlQubits.ResolvedType, + ControlQubits.InferredInformation, + QsNullable>.Null, + QsCompilerDiagnostic.DefaultRange); + private static readonly TypedExpression ControlQubits = - SyntaxGenerator.ImmutableQubitArrayWithName(NonNullable.New(InternalUse.ControlQubitsName)); + SyntaxGenerator.ImmutableQubitArrayWithName(ControlQubitsName); public static readonly Func ApplyAdjoint = new ApplyFunctorToOperationCalls(QsFunctor.Adjoint).Statements.OnScope; @@ -86,6 +98,21 @@ public override QsExpressionKind OnOp } } + /// + /// Adds the given variable declarations to the list of defined variables for each scope. + /// + public class AddVariableDeclarations + : StatementTransformation + { + private readonly IEnumerable>> AddedVariableDeclarations; + + public AddVariableDeclarations(SyntaxTreeTransformation parent, params LocalVariableDeclaration>[] addedVars) + : base(parent) => + AddedVariableDeclarations = addedVars ?? throw new ArgumentNullException(nameof(addedVars)); + + public override LocalDeclarations OnLocalDeclarations(LocalDeclarations decl) => + base.OnLocalDeclarations(new LocalDeclarations(decl.Variables.AddRange(this.AddedVariableDeclarations))); + } /// /// Ensures that the outer block of conjugations is ignored during transformation. From ab4d12de4346f1addc6f8887f1e49e8b2346e157 Mon Sep 17 00:00:00 2001 From: Bettina Heim Date: Thu, 16 Apr 2020 21:10:18 -0700 Subject: [PATCH 10/10] order of declaration --- .../Transformations/FunctorGeneration.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/QsCompiler/Transformations/FunctorGeneration.cs b/src/QsCompiler/Transformations/FunctorGeneration.cs index c936365fd7..14819e0977 100644 --- a/src/QsCompiler/Transformations/FunctorGeneration.cs +++ b/src/QsCompiler/Transformations/FunctorGeneration.cs @@ -47,16 +47,16 @@ public ApplyFunctorToOperationCalls(QsFunctor functor) private static readonly NonNullable ControlQubitsName = NonNullable.New(InternalUse.ControlQubitsName); + private static readonly TypedExpression ControlQubits = + SyntaxGenerator.ImmutableQubitArrayWithName(ControlQubitsName); + private static readonly LocalVariableDeclaration> ControlQubitsDeclaration = new LocalVariableDeclaration>( - ControlQubitsName, - ControlQubits.ResolvedType, - ControlQubits.InferredInformation, + ControlQubitsName, + ControlQubits.ResolvedType, + ControlQubits.InferredInformation, QsNullable>.Null, - QsCompilerDiagnostic.DefaultRange); - - private static readonly TypedExpression ControlQubits = - SyntaxGenerator.ImmutableQubitArrayWithName(ControlQubitsName); + QsCompilerDiagnostic.DefaultRange); public static readonly Func ApplyAdjoint = new ApplyFunctorToOperationCalls(QsFunctor.Adjoint).Statements.OnScope; @@ -108,7 +108,7 @@ public class AddVariableDeclarations public AddVariableDeclarations(SyntaxTreeTransformation parent, params LocalVariableDeclaration>[] addedVars) : base(parent) => - AddedVariableDeclarations = addedVars ?? throw new ArgumentNullException(nameof(addedVars)); + this.AddedVariableDeclarations = addedVars ?? throw new ArgumentNullException(nameof(addedVars)); public override LocalDeclarations OnLocalDeclarations(LocalDeclarations decl) => base.OnLocalDeclarations(new LocalDeclarations(decl.Variables.AddRange(this.AddedVariableDeclarations)));