From 0eebfaa369a9b3de50d098e3d51b891e238a5f64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Zaragoza=20Cort=C3=A9s?= Date: Thu, 14 Jan 2021 18:02:51 -0800 Subject: [PATCH 01/17] Basic new setup to support multiple protocol versions. --- .../BondFiles/CompilerDataStructuresV0.1.bond | 914 ++++++++++++++++++ .../BondFiles/CompilerDataStructuresV0.2.bond | 23 + .../BondSchemas/BondSchemaTranslator.cs | 7 + src/QsCompiler/BondSchemas/Protocols.cs | 8 + .../CompilationManager/AssemblyLoader.cs | 24 + 5 files changed, 976 insertions(+) create mode 100644 src/QsCompiler/BondSchemas/BondFiles/CompilerDataStructuresV0.1.bond create mode 100644 src/QsCompiler/BondSchemas/BondFiles/CompilerDataStructuresV0.2.bond diff --git a/src/QsCompiler/BondSchemas/BondFiles/CompilerDataStructuresV0.1.bond b/src/QsCompiler/BondSchemas/BondFiles/CompilerDataStructuresV0.1.bond new file mode 100644 index 0000000000..01fdf5cf48 --- /dev/null +++ b/src/QsCompiler/BondSchemas/BondFiles/CompilerDataStructuresV0.1.bond @@ -0,0 +1,914 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +// This schema corresponds to the C# code at Generated/CompilerDataStructures.cs +// N.B Whenever this schema changes, C# code must be generated again. + +namespace Microsoft.Quantum.QsCompiler.BondSchemas.v01; + +// Data structures from DataTypes.fs + +struct Position +{ + 5: int32 Line; + + 10: int32 Column; +} + +struct Range +{ + 5: Position Start; + + 10: Position End; +} + +// Data structures from SyntaxTokens.fs + +enum AccessModifier +{ + DefaultAccess, + Internal +} + +struct Modifiers +{ + 5: AccessModifier Access = DefaultAccess; +} + +enum QsGeneratorDirective +{ + SelfInverse, + Invert, + Distribute, + InvalidGenerator +} + +enum QsResult +{ + Zero, + One +} + +enum QsPauli +{ + PauliX, + PauliY, + PauliZ, + PauliI +} + +// N.B. Does not completely represent F#'s QsExpressionKind. +// Used by QsExpressionKindComposition to do a complete representation of the original F# type. +enum QsExpressionKind +{ + UnitValue, + Identifier, + ValueTuple, + IntLiteral, + BigIntLiteral, + DoubleLiteral, + BoolLiteral, + StringLiteral, + ResultLiteral, + PauliLiteral, + RangeLiteral, + NewArray, + ValueArray, + ArrayItem, + NamedItem, + NEG, + NOT, + BNOT, + ADD, + SUB, + MUL, + DIV, + MOD, + POW, + EQ, + NEQ, + LT, + LTE, + GT, + GTE, + AND, + OR, + BOR, + BAND, + BXOR, + LSHIFT, + RSHIFT, + CONDITIONAL, + CopyAndUpdate, + UnwrapApplication, + AdjointApplication, + ControlledApplication, + CallLikeExpression, + MissingExpr, + InvalidExpr +} + +// Used to encapsulate data when QsExpressionKind is Identifier. +// N.B. Does not have an equivalent F# type. +struct QsExpressionKindIdentifier +{ + 5: TSymbol Symbol; + + 10: nullable> Types; +} + +// Used to encapsulate data when QsExpressionKind is StringLiteral. +// N.B. Does not have an equivalent F# type. +struct QsExpressionKindStringLiteral +{ + 5: string StringLiteral; + + 10: vector Expressions; +} + +// Used to encapsulate data when QsExpressionKind is RangeLiteral, ArrayItem, ADD, SUB, MUL, DIV, MOD, POW, EQ, NEQ, LT, LTE, GT, GTE, AND, OR, BOR, BAND, BXOR, LSHIFT, RSHIFT, CallLikeApplication. +// N.B. Does not have an equivalent F# type. +struct QsExpressionKindExpressionDouble +{ + 5: TExpression Expression1; + + 10: TExpression Expression2; +} + +// Used to encapsulate data when QsExpressionKind is CONDITIONAL, CopyAndUpdate. +// N.B. Does not have an equivalent F# type. +struct QsExpressionKindExpressionTriple +{ + 5: TExpression Expression1; + + 10: TExpression Expression2; + + 15: TExpression Expression3; +} + +// Used to encapsulate data when QsExpressionKind is NewArray. +// N.B. Does not have an equivalent F# type. +struct QsExpressionKindNewArray +{ + 5: TType Type; + + 10: TExpression Expression; +} + +// Used to encapsulate data when QsExpressionKind is NamedItem. +// N.B. Does not have an equivalent F# type. +struct QsExpressionKindNamedItem +{ + 5: TExpression Expression; + + 10: TSymbol Symbol; +} + +// Completely represents F#'s QsExpressionKind. +// N.B. Does not have an equivalent F# type. +struct QsExpressionKindComposition +{ + 5: required QsExpressionKind Kind = InvalidExpr; + + // Not null when Kind is Identifier. + 10: nullable> Identifier; + + // Not null when Kind is IntLiteral. + 20: nullable IntLiteral; + + // Not null when Kind is BigIntLiteral. + 25: nullable BigIntLiteral; + + // Not null when Kind is DoubleLiteral. + 30: nullable DoubleLiteral; + + // Not null when Kind is BoolLiteral. + 35: nullable BoolLiteral; + + // Not null when Kind is StringLiteral. + 40: nullable> StringLiteral; + + // Not null when Kind is ResultLiteral. + 45: nullable ResultLiteral; + + // Not null when Kind is PauliLiteral. + 50: nullable PauliLiteral; + + // Not null when Kind is NewArray. + 55: nullable> NewArray; + + // Not null when Kind is NamedItem. + 60: nullable> NamedItem; + + // Not null when Kind is NEG, NOT, BNOT, UnwrapApplication, AdjointApplication, ControlledApplication. + 65: nullable Expression; + + // Not null when Kind is RangeLiteral, ArrayItem, ADD, SUB, MUL, DIV, MOD, POW, EQ, NEQ, LT, LTE, GT, GTE, AND, OR, BOR, BAND, BXOR, LSHIFT, RSHIFT, CallLikeApplication. + 70: nullable> ExpressionDouble; + + // Not null when Kind is CONDITIONAL, CopyAndUpdate. + 75: nullable> ExpressionTriple; + + // Not null when Kind is ValueTuple, ValueArray. + 80: nullable> ExpressionArray; +} + +// Data structures from SyntaxTree.fs + +enum QsBindingKind +{ + ImmutableBinding, + MutableBinding +} + +enum QsSpecializationKind +{ + QsBody, + QsAdjoint, + QsControlled, + QsControlledAdjoint +} + +enum QsCallableKind +{ + Operation, + Function, + TypeConstructor +} + +enum QsQubitScopeKind +{ + Allocate, + Borrow +} + +struct QsQualifiedName +{ + 5: string Namespace; + + 10: string Name; +} + +// Represents the possible kinds of SymbolTuple. +// N.B. Does not have an equivalent F# type. +enum SymbolTupleKind +{ + InvalidItem, + VariableName, + VariableNameTuple, + DiscardedItem +} + +struct SymbolTuple +{ + 5: required SymbolTupleKind Kind = InvalidItem; + + // Not null when Kind is VariableName. + 10: nullable VariableName; + + // Not null when Kind is VariableNameTuple. + 15: nullable> VariableNameTuple; +} + +struct QsBinding +{ + 5: QsBindingKind Kind = ImmutableBinding; + + 10: SymbolTuple Lhs; + + 15: T Rhs; +} + +// Represents the possible kinds of Identifier. +// N.B. Does not have an equivalent F# type. +enum IdentifierKind +{ + LocalVariable, + GlobalCallable, + InvalidIdentifier +} + +struct Identifier +{ + 5: required IdentifierKind Kind = LocalVariable; + + // Not null when Kind is LocalVariable. + 10: nullable LocalVariable; + + // Not null when Kind is GlobalCallable. + 15: nullable GlobalCallable; +} + +struct QsLocation +{ + 5: Position Offset; + + 10: Range Range; +} + +struct QsTypeParameter +{ + 5: QsQualifiedName Origin; + + 10: string TypeName; + + 15: nullable Range; +} + +struct UserDefinedType +{ + 5: string Namespace; + + 10: string Name; + + 15: nullable Range; +} + +enum OpProperty +{ + Adjointable, + Controllable +} + +// N.B. Does not completely represent F#'s CharacteristicsKind. +// Used by CharacteristicsKindComposition to do a complete representation of the original F# type. +enum CharacteristicsKind +{ + EmptySet, + SimpleSet, + Union, + Intersection, + InvalidSetExpr +} + +// Used to encapsulate data when CharacteristicsKind is Union or Intersection. +// N.B. Does not have an equivalent F# type. +struct CharacteristicsKindSetOperation +{ + 5: T Set1; + + 10: T Set2; +} + +// Completely represents F#'s CharacteristicsKind. +// N.B. Does not have an equivalent F# type. +struct CharacteristicsKindComposition +{ + 5: required CharacteristicsKind Kind = InvalidSetExpr; + + // Not null when Kind is SimpleSet. + 10: nullable SimpleSet; + + // Not null when Kind is Union or Intersection. + 15: nullable> SetOperation; +} + +struct ResolvedCharacteristics +{ + 5: CharacteristicsKindComposition Expression; +} + +struct InferredCallableInformation +{ + 5: bool IsSelfAdjoint; + + 10: bool IsIntrinsic; +} + +struct CallableInformation +{ + 5: ResolvedCharacteristics Characteristics; + + 10: InferredCallableInformation InferredInformation; +} + +// N.B. Does not completely represent F#'s QsTypeKind. +// Used by QsTypeKindComposition to do a complete representation of the original F# type. +enum QsTypeKind +{ + UnitType, + Int, + BigInt, + Double, + Bool, + String, + Qubit, + Result, + Pauli, + Range, + ArrayType, + TupleType, + UserDefinedType, + TypeParameter, + Operation, + Function, + MissingType, + InvalidType +} + +// Used to encapsulate data when QsTypeKind is Function. +// N.B. Does not have an equivalent F# type. +struct QsTypeKindFunction +{ + 5: T Type1; + + 10: T Type2; +} + +// Used to encapsulate data when QsTypeKind is Operation. +// N.B. Does not have an equivalent F# type. +struct QsTypeKindOperation +{ + 5: TType Type1; + + 10: TType Type2; + + 15: TCharacteristics Characteristics; +} + +// Completely represents F#'s QsTypeKind. +// N.B. Does not have an equivalent F# type. +struct QsTypeKindComposition +{ + 5: required QsTypeKind Kind = InvalidType; + + // Not null when Kind is ArrayType. + 10: nullable ArrayType; + + // Not null when Kind is TupleType. + 15: nullable> TupleType; + + // Not null when Kind is UserDefinedType. + 20: nullable UserDefinedType; + + // Not null when Kind is TypeParameter. + 25: nullable TypeParameter; + + // Not null when Kind is Operation. + 30: nullable> Operation; + + // Not null when Kind is Function. + 35: nullable> Function; +} + +struct ResolvedType +{ + 5: QsTypeKindComposition TypeKind; +} + +struct InferredExpressionInformation +{ + 5: bool IsMutable; + + 10: bool HasLocalQuantumDependency; +} + +struct TypedArgument +{ + 5: QsQualifiedName Callable; + + 10: string Name; + + 15: ResolvedType Resolution; +} + +struct TypedExpression +{ + 5: QsExpressionKindComposition Expression; + + 10: vector TypedArguments; + + 15: ResolvedType ResolvedType; + + 20: InferredExpressionInformation InferredInformation; + + 25: nullable Range; +} + +// N.B. Does not completely represent F#'s QsInitializerKind. +// Used by QsInitializerKindComposition to do a complete representation of the original F# type. +enum QsInitializerKind +{ + SingleQubitAllocation, + QubitRegisterAllocation, + QubitTupleAllocation, + InvalidInitializer +} + +// Completely represents F#'s QsInitializerKind. +// N.B. Does not have an equivalent F# type. +struct QsInitializerKindComposition +{ + 5: required QsInitializerKind Kind = InvalidInitializer; + + // Not null when Kind is QubitRegisterAllocation. + 10: nullable QubitRegisterAllocation; + + // Not null when Kind is QubitTupleAllocation. + 15: nullable> QubitTupleAllocation; +} + +struct ResolvedInitializer +{ + 5: QsInitializerKindComposition Initializer; + + 10: ResolvedType ResolvedType; +} + +struct LocalVariableDeclaration +{ + 5: TVariableName VariableName; + + 10: ResolvedType Type; + + 15: InferredExpressionInformation InferredInformation; + + 20: nullable Position; + + 25: Range Range; +} + +struct LocalDeclarations +{ + 5: vector> Variables; +} + +struct QsValueUpdate +{ + 5: TypedExpression Lhs; + + 10: TypedExpression Rhs; +} + +struct QsComments +{ + 5: vector OpeningComments; + + 10: vector ClosingComments; +} + +struct QsScope; + +struct QsPositionedBlock +{ + 5: QsScope Body; + + 10: nullable Location; + + 15: QsComments Comments; +} + +// Used to encapsulate a conditional block tuple. +// N.B. Does not have an equivalent F# type. +struct QsConditionalBlock +{ + 5: TypedExpression Expression; + + 10: QsPositionedBlock Block; +} + +struct QsConditionalStatement +{ + 5: vector ConditionalBlocks; + + 10: nullable Default; +} + +// Used to encapsulate a loop item tuple. +// N.B. Does not have an equivalent F# type. +struct QsLoopItem +{ + 5: SymbolTuple SymbolTuple; + + 10: ResolvedType ResolvedType; +} + +struct QsForStatement +{ + 5: QsLoopItem LoopItem; + + 10: TypedExpression IterationValues; + + 15: QsScope Body; +} + +struct QsWhileStatement +{ + 5: TypedExpression Condition; + + 10: QsScope Body; +} + +struct QsRepeatStatement +{ + 5: QsPositionedBlock RepeatBlock; + + 10: TypedExpression SuccessCondition; + + 15: QsPositionedBlock FixupBlock; +} + +struct QsConjugation +{ + 5: QsPositionedBlock OuterTransformation; + + 10: QsPositionedBlock InnerTransformation; +} + +struct QsQubitScope +{ + 5: QsQubitScopeKind Kind = Allocate; + + 10: QsBinding Binding; + + 15: QsScope Body; +} + +// N.B. Does not completely represent F#'s QsStatementKind. +// Used by QsStatementKindComposition to do a complete representation of the original F# type. +enum QsStatementKind +{ + QsExpressionStatement, + QsReturnStatement, + QsFailStatement, + QsVariableDeclaration, + QsValueUpdate, + QsConditionalStatement, + QsForStatement, + QsWhileStatement, + QsRepeatStatement, + QsConjugation, + QsQubitScope, + EmptyStatement +} + +// Completely represents F#'s QsStatementKind. +// N.B. Does not have an equivalent F# type. +struct QsStatementKindComposition +{ + 5: required QsStatementKind Kind = EmptyStatement; + + // Not null when Kind is QsExpressionStatement, QsReturnStatement, QsFailStatement. + 10: nullable TypedExpression; + + // Not null when Kind is QsVariableDeclaration. + 15: nullable> VariableDeclaration; + + // Not null when Kind is QsValueUpdate. + 20: nullable ValueUpdate; + + // Not null when Kind is QsConditionalStatement. + 25: nullable ConditionalStatement; + + // Not null when Kind is QsForStatement. + 30: nullable ForStatement; + + // Not null when Kind is QsWhileStatement. + 35: nullable WhileStatement; + + // Not null when Kind is QsRepeatStatement. + 40: nullable RepeatStatement; + + // Not null when Kind is QsConjugation. + 45: nullable Conjugation; + + // Not null when Kind is QsQubitScope. + 50: nullable QubitScope; +} + +struct QsStatement +{ + 5: QsStatementKindComposition Statement; + + 10: LocalDeclarations SymbolDeclarations; + + 15: nullable Location; + + 20: QsComments Comments; +} + +struct QsScope +{ + 5: vector Statements; + + 10: LocalDeclarations KnownSymbols; +} + +// Represents the possible kinds of QsLocalSymbol. +// N.B. Does not have an equivalent F# type. +enum QsLocalSymbolKind +{ + ValidName, + InvalidName +} + +struct QsLocalSymbol +{ + 5: required QsLocalSymbolKind Kind = InvalidName; + + // Non-null when 'Kind' is 'ValidName'. + 10: nullable Name; +} + +struct QsDeclarationAttribute +{ + 5: nullable TypeId; + + 10: TypedExpression Argument; + + 15: Position Offset; + + 20: QsComments Comments; +} + +struct ResolvedSignature +{ + 5: vector TypeParameters; + + 10: ResolvedType ArgumentType; + + 15: ResolvedType ReturnType; + + 20: CallableInformation Information; +} + +// Represents the possible kinds of QsTuple. +// N.B. Does not have an equivalent F# type. +enum QsTupleKind +{ + QsTupleItem, + QsTuple +} + +struct QsTuple +{ + 5: required QsTupleKind Kind = QsTupleItem; + + // Not null when Kind is QsTupleItem. + 10: nullable Item; + + // Not null when Kind is QsTuple. + 15: nullable>> Items; +} + +// Represents the possible kinds of SpecializationImplementation. +// N.B. Does not have an equivalent F# type. +enum SpecializationImplementationKind +{ + Provided, + Intrinsic, + External, + Generated +} + +// Used to encapsulate data when SpecializationImplementationKind is Provided. +// N.B. Does not have an equivalent F# type. +struct SpecializationImplementationKindProvided +{ + 5: QsTuple> Tuple; + + 10: QsScope Implementation; +} + +struct SpecializationImplementation +{ + 5: required SpecializationImplementationKind Kind = Generated; + + // Not null when Kind is Provided. + 10: nullable Provided; + + // Not null when Kind is Generated. + 15: nullable Generated; +} + +struct QsSpecialization +{ + 5: QsSpecializationKind Kind = QsBody; + + 10: QsQualifiedName Parent; + + 15: vector Attributes; + + 20: string SourceFile; + + 25: nullable Location; + + 30: nullable> TypeArguments; + + 35: ResolvedSignature Signature; + + 40: SpecializationImplementation Implementation; + + 45: vector Documentation; + + 50: QsComments Comments; +} + +struct QsCallable +{ + 5: QsCallableKind Kind = Operation; + + 10: QsQualifiedName FullName; + + 15: vector Attributes; + + 20: Modifiers Modifiers; + + 25: string SourceFile; + + 30: nullable Location; + + 35: ResolvedSignature Signature; + + 40: QsTuple> ArgumentTuple; + + 45: vector Specializations; + + 50: vector Documentation; + + 55: QsComments Comments; +} + +// Represents the possible kinds of QsTypeItem. +// N.B. Does not have an equivalent F# type. +enum QsTypeItemKind +{ + Named, + Anonymous +} + +struct QsTypeItem +{ + 5: required QsTypeItemKind Kind = Named; + + // Not null when Kind is Named. + 10: nullable> Named; + + // Not null when Kind is Anonymous. + 15: nullable Anonymous; +} + +struct QsCustomType +{ + 5: QsQualifiedName FullName; + + 10: vector Attributes; + + 15: Modifiers Modifiers; + + 20: string SourceFile; + + 25: nullable Location; + + 30: ResolvedType Type; + + 35: QsTuple TypeItems; + + 40: vector Documentation; + + 45: QsComments Comments; +} + +// Represents the possible kinds of QsNamespaceElement. +// N.B. Does not have an equivalent F# type. +enum QsNamespaceElementKind +{ + QsCallable, + QsCustomType +} + +struct QsNamespaceElement +{ + 5: required QsNamespaceElementKind Kind = QsCallable; + + // Non-null when 'Kind' is 'QsCallable'. + 10: nullable Callable; + + // Non-null when 'Kind' is 'QsCustomType'. + 15: nullable CustomType; +} + +// Used to encapsulate F#'s representation of namespace documentation. +// N.B. Does not have an equivalent F# type. +struct QsSourceFileDocumentation +{ + 5: string FileName; + + 10: vector DocumentationItems; +} + +struct QsNamespace +{ + 5: string Name; + + 10: vector Elements; + + 15: list Documentation; +} + +struct QsCompilation +{ + 5: vector Namespaces; + + 10: vector EntryPoints; +} diff --git a/src/QsCompiler/BondSchemas/BondFiles/CompilerDataStructuresV0.2.bond b/src/QsCompiler/BondSchemas/BondFiles/CompilerDataStructuresV0.2.bond new file mode 100644 index 0000000000..3ff5abf5a0 --- /dev/null +++ b/src/QsCompiler/BondSchemas/BondFiles/CompilerDataStructuresV0.2.bond @@ -0,0 +1,23 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import "CompilerDataStructuresV0.1.bond" + +namespace Microsoft.Quantum.QsCompiler.BondSchemas.v02; + +struct QsNamespace +{ + 5: string Name; + + 10: vector Elements; + + 15: list> Documentation; +} + +struct QsCompilation +{ + 5: vector Namespaces; + + 10: vector EntryPoints; +} + diff --git a/src/QsCompiler/BondSchemas/BondSchemaTranslator.cs b/src/QsCompiler/BondSchemas/BondSchemaTranslator.cs index eee0465d30..777eac076b 100644 --- a/src/QsCompiler/BondSchemas/BondSchemaTranslator.cs +++ b/src/QsCompiler/BondSchemas/BondSchemaTranslator.cs @@ -24,6 +24,13 @@ public static QsCompilation CreateBondCompilation(SyntaxTree.QsCompilation qsCom EntryPoints = qsCompilation.EntryPoints.Select(e => e.ToBondSchema()).ToList() }; + // TODO: Implement. + public static BondType CreateQsCompilation(SyntaxTree.QsCompilation qsCompilation) + { + var t = typeof(BondType); + throw new NotImplementedException(); + } + private static AccessModifier ToBondSchema(this SyntaxTokens.AccessModifier accessModifier) => accessModifier.Tag switch { diff --git a/src/QsCompiler/BondSchemas/Protocols.cs b/src/QsCompiler/BondSchemas/Protocols.cs index fe4142fcd6..4c2988a825 100644 --- a/src/QsCompiler/BondSchemas/Protocols.cs +++ b/src/QsCompiler/BondSchemas/Protocols.cs @@ -19,6 +19,13 @@ namespace Microsoft.Quantum.QsCompiler.BondSchemas /// public static class Protocols { + + // TODO: Document. + public enum Option + { + ExcludeNamespaceDocumentation + } + /// /// Provides thread-safe access to the members and methods of this class. /// @@ -31,6 +38,7 @@ public static class Protocols /// /// Bond simple binary representation of a Q# compilation object. /// This method waits for s to complete and may deadlock if invoked through a . + // TODO: Extend to receive options. public static SyntaxTree.QsCompilation? DeserializeQsCompilationFromSimpleBinary( byte[] byteArray) { diff --git a/src/QsCompiler/CompilationManager/AssemblyLoader.cs b/src/QsCompiler/CompilationManager/AssemblyLoader.cs index bad4a18a42..bbdda68f03 100644 --- a/src/QsCompiler/CompilationManager/AssemblyLoader.cs +++ b/src/QsCompiler/CompilationManager/AssemblyLoader.cs @@ -123,6 +123,30 @@ public static bool LoadSyntaxTree( return compilation != null && IsValidCompilation(compilation); } + // TODO: Document. + public static bool LoadSyntaxTree( + byte[] byteArray, + string resourceName, + BondSchemas.Protocols.Option[] options, + [NotNullWhen(true)] out QsCompilation? compilation, + Action? onDeserializationException = null) + { + compilation = null; + try + { + PerformanceTracking.TaskStart(PerformanceTracking.Task.SyntaxTreeDeserialization); + // TODO: Call into the Protocols API. + PerformanceTracking.TaskEnd(PerformanceTracking.Task.SyntaxTreeDeserialization); + } + catch (Exception ex) + { + onDeserializationException?.Invoke(ex); + return false; + } + + return compilation != null && IsValidCompilation(compilation); + } + /// /// Given a stream containing a binary representation of compiled Q# code, returns the corresponding Q# compilation. /// Returns true if the compilation could be deserialized without throwing an exception, and it is properly instantiated. False otherwise. From 068cedc17f03449e18ac15c40b6182ba299d3080 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Zaragoza=20Cort=C3=A9s?= Date: Fri, 15 Jan 2021 18:59:30 -0800 Subject: [PATCH 02/17] Idea on how to organize Bond schema versions. --- .../BondFiles/CompilerDataStructuresV0.2.bond | 23 ------------- .../BondSchemas/BondSchemaTranslator.cs | 7 ---- src/QsCompiler/BondSchemas/BondSchemas.csproj | 6 +++- .../BondSchemas/CompilerObjectTranslator.cs | 34 +++++++++++++++++++ src/QsCompiler/BondSchemas/Protocols.cs | 4 ++- .../CompilerDataStructuresV1.bond} | 2 +- .../V2/CompilerDataStructuresV2.bond | 23 +++++++++++++ .../CompilationManager/AssemblyLoader.cs | 33 ++++++++++++++++-- 8 files changed, 97 insertions(+), 35 deletions(-) delete mode 100644 src/QsCompiler/BondSchemas/BondFiles/CompilerDataStructuresV0.2.bond rename src/QsCompiler/BondSchemas/{BondFiles/CompilerDataStructuresV0.1.bond => V1/CompilerDataStructuresV1.bond} (99%) create mode 100644 src/QsCompiler/BondSchemas/V2/CompilerDataStructuresV2.bond diff --git a/src/QsCompiler/BondSchemas/BondFiles/CompilerDataStructuresV0.2.bond b/src/QsCompiler/BondSchemas/BondFiles/CompilerDataStructuresV0.2.bond deleted file mode 100644 index 3ff5abf5a0..0000000000 --- a/src/QsCompiler/BondSchemas/BondFiles/CompilerDataStructuresV0.2.bond +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -import "CompilerDataStructuresV0.1.bond" - -namespace Microsoft.Quantum.QsCompiler.BondSchemas.v02; - -struct QsNamespace -{ - 5: string Name; - - 10: vector Elements; - - 15: list> Documentation; -} - -struct QsCompilation -{ - 5: vector Namespaces; - - 10: vector EntryPoints; -} - diff --git a/src/QsCompiler/BondSchemas/BondSchemaTranslator.cs b/src/QsCompiler/BondSchemas/BondSchemaTranslator.cs index 777eac076b..eee0465d30 100644 --- a/src/QsCompiler/BondSchemas/BondSchemaTranslator.cs +++ b/src/QsCompiler/BondSchemas/BondSchemaTranslator.cs @@ -24,13 +24,6 @@ public static QsCompilation CreateBondCompilation(SyntaxTree.QsCompilation qsCom EntryPoints = qsCompilation.EntryPoints.Select(e => e.ToBondSchema()).ToList() }; - // TODO: Implement. - public static BondType CreateQsCompilation(SyntaxTree.QsCompilation qsCompilation) - { - var t = typeof(BondType); - throw new NotImplementedException(); - } - private static AccessModifier ToBondSchema(this SyntaxTokens.AccessModifier accessModifier) => accessModifier.Tag switch { diff --git a/src/QsCompiler/BondSchemas/BondSchemas.csproj b/src/QsCompiler/BondSchemas/BondSchemas.csproj index 61c9bdcf60..c6a272f87c 100644 --- a/src/QsCompiler/BondSchemas/BondSchemas.csproj +++ b/src/QsCompiler/BondSchemas/BondSchemas.csproj @@ -1,4 +1,4 @@ - + @@ -12,6 +12,10 @@ + + + + diff --git a/src/QsCompiler/BondSchemas/CompilerObjectTranslator.cs b/src/QsCompiler/BondSchemas/CompilerObjectTranslator.cs index c19491cc77..3c1e2abf74 100644 --- a/src/QsCompiler/BondSchemas/CompilerObjectTranslator.cs +++ b/src/QsCompiler/BondSchemas/CompilerObjectTranslator.cs @@ -23,6 +23,40 @@ public static SyntaxTree.QsCompilation CreateQsCompilation(QsCompilation bondCom namespaces: bondCompilation.Namespaces.Select(n => n.ToCompilerObject()).ToImmutableArray(), entryPoints: bondCompilation.EntryPoints.Select(e => e.ToCompilerObject()).ToImmutableArray()); + // TODO: Document. + public static SyntaxTree.QsCompilation CreateQsCompilation(TBond bondCompilation) + { + throw new NotImplementedException(); + /* + switch (bondCompilation) + { + case v01.QsCompilation bondCompilationV01: + return CreateQsCompilation(bondCompilationV01); + + case v02.QsCompilation bondCompilationV02: + return CreateQsCompilation(bondCompilationV02); + + default: + // TODO: Use a more meaningful message. + throw new ArgumentException(); + } + */ + } + + /* + private static SyntaxTree.QsCompilation CreateQsCompilation(v01.QsCompilation bondCompilation) + { + // TODO: Implement. + throw new NotImplementedException(); + } + + private static SyntaxTree.QsCompilation CreateQsCompilation(v02.QsCompilation bondCompilation) + { + // TODO: Implement. + throw new NotImplementedException(); + } + */ + private static BigInteger ToBigInteger(this ArraySegment blob) => new BigInteger(blob); diff --git a/src/QsCompiler/BondSchemas/Protocols.cs b/src/QsCompiler/BondSchemas/Protocols.cs index 54d203685a..4088ec5b14 100644 --- a/src/QsCompiler/BondSchemas/Protocols.cs +++ b/src/QsCompiler/BondSchemas/Protocols.cs @@ -40,7 +40,9 @@ public enum Option /// This method waits for s to complete and may deadlock if invoked through a . // TODO: Extend to receive options. public static SyntaxTree.QsCompilation? DeserializeQsCompilationFromSimpleBinary( - byte[] byteArray) + byte[] byteArray, + Type bondType, + Option[]? options = null) { QsCompilation? bondCompilation = null; var inputBuffer = new InputBuffer(byteArray); diff --git a/src/QsCompiler/BondSchemas/BondFiles/CompilerDataStructuresV0.1.bond b/src/QsCompiler/BondSchemas/V1/CompilerDataStructuresV1.bond similarity index 99% rename from src/QsCompiler/BondSchemas/BondFiles/CompilerDataStructuresV0.1.bond rename to src/QsCompiler/BondSchemas/V1/CompilerDataStructuresV1.bond index 01fdf5cf48..15e5a1fb07 100644 --- a/src/QsCompiler/BondSchemas/BondFiles/CompilerDataStructuresV0.1.bond +++ b/src/QsCompiler/BondSchemas/V1/CompilerDataStructuresV1.bond @@ -4,7 +4,7 @@ // This schema corresponds to the C# code at Generated/CompilerDataStructures.cs // N.B Whenever this schema changes, C# code must be generated again. -namespace Microsoft.Quantum.QsCompiler.BondSchemas.v01; +namespace Microsoft.Quantum.QsCompiler.BondSchemas.V1; // Data structures from DataTypes.fs diff --git a/src/QsCompiler/BondSchemas/V2/CompilerDataStructuresV2.bond b/src/QsCompiler/BondSchemas/V2/CompilerDataStructuresV2.bond new file mode 100644 index 0000000000..31378cf457 --- /dev/null +++ b/src/QsCompiler/BondSchemas/V2/CompilerDataStructuresV2.bond @@ -0,0 +1,23 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import "../V1/CompilerDataStructuresV1.bond" + +namespace Microsoft.Quantum.QsCompiler.BondSchemas.V2; + +struct QsNamespace +{ + 5: string Name; + + 10: vector Elements; + + 15: list> Documentation; +} + +struct QsCompilation +{ + 5: vector Namespaces; + + 10: vector EntryPoints; +} + diff --git a/src/QsCompiler/CompilationManager/AssemblyLoader.cs b/src/QsCompiler/CompilationManager/AssemblyLoader.cs index 332f386efe..d7425fc916 100644 --- a/src/QsCompiler/CompilationManager/AssemblyLoader.cs +++ b/src/QsCompiler/CompilationManager/AssemblyLoader.cs @@ -26,6 +26,16 @@ namespace Microsoft.Quantum.QsCompiler /// public static class AssemblyLoader { + /// + /// TODO: Document. + /// + private static IDictionary syntaxTreeResourceBondType = + new Dictionary() + { + { DotnetCoreDll.ResourceName, null }, + //{ DotnetCoreDll.ResourceNameQsDataBondV1, typeof(BondSchemas.v01.QsCompilation) } + }; + /// /// Loads the Q# data structures in a referenced assembly given the Uri to that assembly, /// and returns the loaded content as out parameter. @@ -112,7 +122,8 @@ public static bool LoadSyntaxTree( try { PerformanceTracking.TaskStart(PerformanceTracking.Task.SyntaxTreeDeserialization); - compilation = BondSchemas.Protocols.DeserializeQsCompilationFromSimpleBinary(byteArray); + // TODO: This should be a call to the extended LoadSyntaxTree API. + compilation = BondSchemas.Protocols.DeserializeQsCompilationFromSimpleBinary(byteArray, typeof(BondSchemas.QsCompilation)); PerformanceTracking.TaskEnd(PerformanceTracking.Task.SyntaxTreeDeserialization); } catch (Exception ex) @@ -128,14 +139,17 @@ public static bool LoadSyntaxTree( public static bool LoadSyntaxTree( byte[] byteArray, string resourceName, - BondSchemas.Protocols.Option[] options, [NotNullWhen(true)] out QsCompilation? compilation, + BondSchemas.Protocols.Option[]? options = null, Action? onDeserializationException = null) { compilation = null; + + try { PerformanceTracking.TaskStart(PerformanceTracking.Task.SyntaxTreeDeserialization); + // TODO: Call into the Protocols API. PerformanceTracking.TaskEnd(PerformanceTracking.Task.SyntaxTreeDeserialization); } @@ -309,6 +323,21 @@ private static (string, string)? GetAttribute(MetadataReader metadataReader, Cus return null; } + // TODO: Document. + private static (string ResourceName, ManifestResource Resource)? GetSyntaxTreeResourceTuple(MetadataReader metadataReader) + { + ManifestResource resource; + foreach (var resourceName in syntaxTreeResourceBondType.Keys) + { + if (metadataReader.Resources().TryGetValue(resourceName, out resource)) + { + return (resourceName, resource); + } + } + + return null; + } + /// /// Given a reader for the byte stream of a dotnet dll, read its custom attributes and /// returns a tuple containing the name of the attribute and the constructor argument From ca15ec93ad3e90311f0b5b76e3aa7a0cca25a957 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Zaragoza=20Cort=C3=A9s?= Date: Wed, 20 Jan 2021 14:57:40 -0800 Subject: [PATCH 03/17] Concept for new organization for Bond schemas and translators. --- .../BondSchemas/CompilerDataStructures.bond | 914 --------- .../Generated/CompilerDataStructures.cs | 1791 ----------------- src/QsCompiler/BondSchemas/Protocols.cs | 75 +- src/QsCompiler/BondSchemas/Translators.cs | 28 + .../{ => V1}/BondSchemaTranslator.cs | 2 +- .../{ => V1}/CompilerObjectTranslator.cs | 2 +- .../CompilationManager/AssemblyLoader.cs | 2 +- 7 files changed, 83 insertions(+), 2731 deletions(-) delete mode 100644 src/QsCompiler/BondSchemas/CompilerDataStructures.bond delete mode 100644 src/QsCompiler/BondSchemas/Generated/CompilerDataStructures.cs create mode 100644 src/QsCompiler/BondSchemas/Translators.cs rename src/QsCompiler/BondSchemas/{ => V1}/BondSchemaTranslator.cs (99%) rename src/QsCompiler/BondSchemas/{ => V1}/CompilerObjectTranslator.cs (99%) diff --git a/src/QsCompiler/BondSchemas/CompilerDataStructures.bond b/src/QsCompiler/BondSchemas/CompilerDataStructures.bond deleted file mode 100644 index e078be7987..0000000000 --- a/src/QsCompiler/BondSchemas/CompilerDataStructures.bond +++ /dev/null @@ -1,914 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// This schema corresponds to the C# code at Generated/CompilerDataStructures.cs -// N.B Whenever this schema changes, C# code must be generated again. - -namespace Microsoft.Quantum.QsCompiler.BondSchemas; - -// Data structures from DataTypes.fs - -struct Position -{ - 5: int32 Line; - - 10: int32 Column; -} - -struct Range -{ - 5: Position Start; - - 10: Position End; -} - -// Data structures from SyntaxTokens.fs - -enum AccessModifier -{ - DefaultAccess, - Internal -} - -struct Modifiers -{ - 5: AccessModifier Access = DefaultAccess; -} - -enum QsGeneratorDirective -{ - SelfInverse, - Invert, - Distribute, - InvalidGenerator -} - -enum QsResult -{ - Zero, - One -} - -enum QsPauli -{ - PauliX, - PauliY, - PauliZ, - PauliI -} - -// N.B. Does not completely represent F#'s QsExpressionKind. -// Used by QsExpressionKindComposition to do a complete representation of the original F# type. -enum QsExpressionKind -{ - UnitValue, - Identifier, - ValueTuple, - IntLiteral, - BigIntLiteral, - DoubleLiteral, - BoolLiteral, - StringLiteral, - ResultLiteral, - PauliLiteral, - RangeLiteral, - NewArray, - ValueArray, - ArrayItem, - NamedItem, - NEG, - NOT, - BNOT, - ADD, - SUB, - MUL, - DIV, - MOD, - POW, - EQ, - NEQ, - LT, - LTE, - GT, - GTE, - AND, - OR, - BOR, - BAND, - BXOR, - LSHIFT, - RSHIFT, - CONDITIONAL, - CopyAndUpdate, - UnwrapApplication, - AdjointApplication, - ControlledApplication, - CallLikeExpression, - MissingExpr, - InvalidExpr -} - -// Used to encapsulate data when QsExpressionKind is Identifier. -// N.B. Does not have an equivalent F# type. -struct QsExpressionKindIdentifier -{ - 5: TSymbol Symbol; - - 10: nullable> Types; -} - -// Used to encapsulate data when QsExpressionKind is StringLiteral. -// N.B. Does not have an equivalent F# type. -struct QsExpressionKindStringLiteral -{ - 5: string StringLiteral; - - 10: vector Expressions; -} - -// Used to encapsulate data when QsExpressionKind is RangeLiteral, ArrayItem, ADD, SUB, MUL, DIV, MOD, POW, EQ, NEQ, LT, LTE, GT, GTE, AND, OR, BOR, BAND, BXOR, LSHIFT, RSHIFT, CallLikeApplication. -// N.B. Does not have an equivalent F# type. -struct QsExpressionKindExpressionDouble -{ - 5: TExpression Expression1; - - 10: TExpression Expression2; -} - -// Used to encapsulate data when QsExpressionKind is CONDITIONAL, CopyAndUpdate. -// N.B. Does not have an equivalent F# type. -struct QsExpressionKindExpressionTriple -{ - 5: TExpression Expression1; - - 10: TExpression Expression2; - - 15: TExpression Expression3; -} - -// Used to encapsulate data when QsExpressionKind is NewArray. -// N.B. Does not have an equivalent F# type. -struct QsExpressionKindNewArray -{ - 5: TType Type; - - 10: TExpression Expression; -} - -// Used to encapsulate data when QsExpressionKind is NamedItem. -// N.B. Does not have an equivalent F# type. -struct QsExpressionKindNamedItem -{ - 5: TExpression Expression; - - 10: TSymbol Symbol; -} - -// Completely represents F#'s QsExpressionKind. -// N.B. Does not have an equivalent F# type. -struct QsExpressionKindComposition -{ - 5: required QsExpressionKind Kind = InvalidExpr; - - // Not null when Kind is Identifier. - 10: nullable> Identifier; - - // Not null when Kind is IntLiteral. - 20: nullable IntLiteral; - - // Not null when Kind is BigIntLiteral. - 25: nullable BigIntLiteral; - - // Not null when Kind is DoubleLiteral. - 30: nullable DoubleLiteral; - - // Not null when Kind is BoolLiteral. - 35: nullable BoolLiteral; - - // Not null when Kind is StringLiteral. - 40: nullable> StringLiteral; - - // Not null when Kind is ResultLiteral. - 45: nullable ResultLiteral; - - // Not null when Kind is PauliLiteral. - 50: nullable PauliLiteral; - - // Not null when Kind is NewArray. - 55: nullable> NewArray; - - // Not null when Kind is NamedItem. - 60: nullable> NamedItem; - - // Not null when Kind is NEG, NOT, BNOT, UnwrapApplication, AdjointApplication, ControlledApplication. - 65: nullable Expression; - - // Not null when Kind is RangeLiteral, ArrayItem, ADD, SUB, MUL, DIV, MOD, POW, EQ, NEQ, LT, LTE, GT, GTE, AND, OR, BOR, BAND, BXOR, LSHIFT, RSHIFT, CallLikeApplication. - 70: nullable> ExpressionDouble; - - // Not null when Kind is CONDITIONAL, CopyAndUpdate. - 75: nullable> ExpressionTriple; - - // Not null when Kind is ValueTuple, ValueArray. - 80: nullable> ExpressionArray; -} - -// Data structures from SyntaxTree.fs - -enum QsBindingKind -{ - ImmutableBinding, - MutableBinding -} - -enum QsSpecializationKind -{ - QsBody, - QsAdjoint, - QsControlled, - QsControlledAdjoint -} - -enum QsCallableKind -{ - Operation, - Function, - TypeConstructor -} - -enum QsQubitScopeKind -{ - Allocate, - Borrow -} - -struct QsQualifiedName -{ - 5: string Namespace; - - 10: string Name; -} - -// Represents the possible kinds of SymbolTuple. -// N.B. Does not have an equivalent F# type. -enum SymbolTupleKind -{ - InvalidItem, - VariableName, - VariableNameTuple, - DiscardedItem -} - -struct SymbolTuple -{ - 5: required SymbolTupleKind Kind = InvalidItem; - - // Not null when Kind is VariableName. - 10: nullable VariableName; - - // Not null when Kind is VariableNameTuple. - 15: nullable> VariableNameTuple; -} - -struct QsBinding -{ - 5: QsBindingKind Kind = ImmutableBinding; - - 10: SymbolTuple Lhs; - - 15: T Rhs; -} - -// Represents the possible kinds of Identifier. -// N.B. Does not have an equivalent F# type. -enum IdentifierKind -{ - LocalVariable, - GlobalCallable, - InvalidIdentifier -} - -struct Identifier -{ - 5: required IdentifierKind Kind = LocalVariable; - - // Not null when Kind is LocalVariable. - 10: nullable LocalVariable; - - // Not null when Kind is GlobalCallable. - 15: nullable GlobalCallable; -} - -struct QsLocation -{ - 5: Position Offset; - - 10: Range Range; -} - -struct QsTypeParameter -{ - 5: QsQualifiedName Origin; - - 10: string TypeName; - - 15: nullable Range; -} - -struct UserDefinedType -{ - 5: string Namespace; - - 10: string Name; - - 15: nullable Range; -} - -enum OpProperty -{ - Adjointable, - Controllable -} - -// N.B. Does not completely represent F#'s CharacteristicsKind. -// Used by CharacteristicsKindComposition to do a complete representation of the original F# type. -enum CharacteristicsKind -{ - EmptySet, - SimpleSet, - Union, - Intersection, - InvalidSetExpr -} - -// Used to encapsulate data when CharacteristicsKind is Union or Intersection. -// N.B. Does not have an equivalent F# type. -struct CharacteristicsKindSetOperation -{ - 5: T Set1; - - 10: T Set2; -} - -// Completely represents F#'s CharacteristicsKind. -// N.B. Does not have an equivalent F# type. -struct CharacteristicsKindComposition -{ - 5: required CharacteristicsKind Kind = InvalidSetExpr; - - // Not null when Kind is SimpleSet. - 10: nullable SimpleSet; - - // Not null when Kind is Union or Intersection. - 15: nullable> SetOperation; -} - -struct ResolvedCharacteristics -{ - 5: CharacteristicsKindComposition Expression; -} - -struct InferredCallableInformation -{ - 5: bool IsSelfAdjoint; - - 10: bool IsIntrinsic; -} - -struct CallableInformation -{ - 5: ResolvedCharacteristics Characteristics; - - 10: InferredCallableInformation InferredInformation; -} - -// N.B. Does not completely represent F#'s QsTypeKind. -// Used by QsTypeKindComposition to do a complete representation of the original F# type. -enum QsTypeKind -{ - UnitType, - Int, - BigInt, - Double, - Bool, - String, - Qubit, - Result, - Pauli, - Range, - ArrayType, - TupleType, - UserDefinedType, - TypeParameter, - Operation, - Function, - MissingType, - InvalidType -} - -// Used to encapsulate data when QsTypeKind is Function. -// N.B. Does not have an equivalent F# type. -struct QsTypeKindFunction -{ - 5: T Type1; - - 10: T Type2; -} - -// Used to encapsulate data when QsTypeKind is Operation. -// N.B. Does not have an equivalent F# type. -struct QsTypeKindOperation -{ - 5: TType Type1; - - 10: TType Type2; - - 15: TCharacteristics Characteristics; -} - -// Completely represents F#'s QsTypeKind. -// N.B. Does not have an equivalent F# type. -struct QsTypeKindComposition -{ - 5: required QsTypeKind Kind = InvalidType; - - // Not null when Kind is ArrayType. - 10: nullable ArrayType; - - // Not null when Kind is TupleType. - 15: nullable> TupleType; - - // Not null when Kind is UserDefinedType. - 20: nullable UserDefinedType; - - // Not null when Kind is TypeParameter. - 25: nullable TypeParameter; - - // Not null when Kind is Operation. - 30: nullable> Operation; - - // Not null when Kind is Function. - 35: nullable> Function; -} - -struct ResolvedType -{ - 5: QsTypeKindComposition TypeKind; -} - -struct InferredExpressionInformation -{ - 5: bool IsMutable; - - 10: bool HasLocalQuantumDependency; -} - -struct TypedArgument -{ - 5: QsQualifiedName Callable; - - 10: string Name; - - 15: ResolvedType Resolution; -} - -struct TypedExpression -{ - 5: QsExpressionKindComposition Expression; - - 10: vector TypedArguments; - - 15: ResolvedType ResolvedType; - - 20: InferredExpressionInformation InferredInformation; - - 25: nullable Range; -} - -// N.B. Does not completely represent F#'s QsInitializerKind. -// Used by QsInitializerKindComposition to do a complete representation of the original F# type. -enum QsInitializerKind -{ - SingleQubitAllocation, - QubitRegisterAllocation, - QubitTupleAllocation, - InvalidInitializer -} - -// Completely represents F#'s QsInitializerKind. -// N.B. Does not have an equivalent F# type. -struct QsInitializerKindComposition -{ - 5: required QsInitializerKind Kind = InvalidInitializer; - - // Not null when Kind is QubitRegisterAllocation. - 10: nullable QubitRegisterAllocation; - - // Not null when Kind is QubitTupleAllocation. - 15: nullable> QubitTupleAllocation; -} - -struct ResolvedInitializer -{ - 5: QsInitializerKindComposition Initializer; - - 10: ResolvedType ResolvedType; -} - -struct LocalVariableDeclaration -{ - 5: TVariableName VariableName; - - 10: ResolvedType Type; - - 15: InferredExpressionInformation InferredInformation; - - 20: nullable Position; - - 25: Range Range; -} - -struct LocalDeclarations -{ - 5: vector> Variables; -} - -struct QsValueUpdate -{ - 5: TypedExpression Lhs; - - 10: TypedExpression Rhs; -} - -struct QsComments -{ - 5: vector OpeningComments; - - 10: vector ClosingComments; -} - -struct QsScope; - -struct QsPositionedBlock -{ - 5: QsScope Body; - - 10: nullable Location; - - 15: QsComments Comments; -} - -// Used to encapsulate a conditional block tuple. -// N.B. Does not have an equivalent F# type. -struct QsConditionalBlock -{ - 5: TypedExpression Expression; - - 10: QsPositionedBlock Block; -} - -struct QsConditionalStatement -{ - 5: vector ConditionalBlocks; - - 10: nullable Default; -} - -// Used to encapsulate a loop item tuple. -// N.B. Does not have an equivalent F# type. -struct QsLoopItem -{ - 5: SymbolTuple SymbolTuple; - - 10: ResolvedType ResolvedType; -} - -struct QsForStatement -{ - 5: QsLoopItem LoopItem; - - 10: TypedExpression IterationValues; - - 15: QsScope Body; -} - -struct QsWhileStatement -{ - 5: TypedExpression Condition; - - 10: QsScope Body; -} - -struct QsRepeatStatement -{ - 5: QsPositionedBlock RepeatBlock; - - 10: TypedExpression SuccessCondition; - - 15: QsPositionedBlock FixupBlock; -} - -struct QsConjugation -{ - 5: QsPositionedBlock OuterTransformation; - - 10: QsPositionedBlock InnerTransformation; -} - -struct QsQubitScope -{ - 5: QsQubitScopeKind Kind = Allocate; - - 10: QsBinding Binding; - - 15: QsScope Body; -} - -// N.B. Does not completely represent F#'s QsStatementKind. -// Used by QsStatementKindComposition to do a complete representation of the original F# type. -enum QsStatementKind -{ - QsExpressionStatement, - QsReturnStatement, - QsFailStatement, - QsVariableDeclaration, - QsValueUpdate, - QsConditionalStatement, - QsForStatement, - QsWhileStatement, - QsRepeatStatement, - QsConjugation, - QsQubitScope, - EmptyStatement -} - -// Completely represents F#'s QsStatementKind. -// N.B. Does not have an equivalent F# type. -struct QsStatementKindComposition -{ - 5: required QsStatementKind Kind = EmptyStatement; - - // Not null when Kind is QsExpressionStatement, QsReturnStatement, QsFailStatement. - 10: nullable TypedExpression; - - // Not null when Kind is QsVariableDeclaration. - 15: nullable> VariableDeclaration; - - // Not null when Kind is QsValueUpdate. - 20: nullable ValueUpdate; - - // Not null when Kind is QsConditionalStatement. - 25: nullable ConditionalStatement; - - // Not null when Kind is QsForStatement. - 30: nullable ForStatement; - - // Not null when Kind is QsWhileStatement. - 35: nullable WhileStatement; - - // Not null when Kind is QsRepeatStatement. - 40: nullable RepeatStatement; - - // Not null when Kind is QsConjugation. - 45: nullable Conjugation; - - // Not null when Kind is QsQubitScope. - 50: nullable QubitScope; -} - -struct QsStatement -{ - 5: QsStatementKindComposition Statement; - - 10: LocalDeclarations SymbolDeclarations; - - 15: nullable Location; - - 20: QsComments Comments; -} - -struct QsScope -{ - 5: vector Statements; - - 10: LocalDeclarations KnownSymbols; -} - -// Represents the possible kinds of QsLocalSymbol. -// N.B. Does not have an equivalent F# type. -enum QsLocalSymbolKind -{ - ValidName, - InvalidName -} - -struct QsLocalSymbol -{ - 5: required QsLocalSymbolKind Kind = InvalidName; - - // Non-null when 'Kind' is 'ValidName'. - 10: nullable Name; -} - -struct QsDeclarationAttribute -{ - 5: nullable TypeId; - - 10: TypedExpression Argument; - - 15: Position Offset; - - 20: QsComments Comments; -} - -struct ResolvedSignature -{ - 5: vector TypeParameters; - - 10: ResolvedType ArgumentType; - - 15: ResolvedType ReturnType; - - 20: CallableInformation Information; -} - -// Represents the possible kinds of QsTuple. -// N.B. Does not have an equivalent F# type. -enum QsTupleKind -{ - QsTupleItem, - QsTuple -} - -struct QsTuple -{ - 5: required QsTupleKind Kind = QsTupleItem; - - // Not null when Kind is QsTupleItem. - 10: nullable Item; - - // Not null when Kind is QsTuple. - 15: nullable>> Items; -} - -// Represents the possible kinds of SpecializationImplementation. -// N.B. Does not have an equivalent F# type. -enum SpecializationImplementationKind -{ - Provided, - Intrinsic, - External, - Generated -} - -// Used to encapsulate data when SpecializationImplementationKind is Provided. -// N.B. Does not have an equivalent F# type. -struct SpecializationImplementationKindProvided -{ - 5: QsTuple> Tuple; - - 10: QsScope Implementation; -} - -struct SpecializationImplementation -{ - 5: required SpecializationImplementationKind Kind = Generated; - - // Not null when Kind is Provided. - 10: nullable Provided; - - // Not null when Kind is Generated. - 15: nullable Generated; -} - -struct QsSpecialization -{ - 5: QsSpecializationKind Kind = QsBody; - - 10: QsQualifiedName Parent; - - 15: vector Attributes; - - 20: string SourceFile; - - 25: nullable Location; - - 30: nullable> TypeArguments; - - 35: ResolvedSignature Signature; - - 40: SpecializationImplementation Implementation; - - 45: vector Documentation; - - 50: QsComments Comments; -} - -struct QsCallable -{ - 5: QsCallableKind Kind = Operation; - - 10: QsQualifiedName FullName; - - 15: vector Attributes; - - 20: Modifiers Modifiers; - - 25: string SourceFile; - - 30: nullable Location; - - 35: ResolvedSignature Signature; - - 40: QsTuple> ArgumentTuple; - - 45: vector Specializations; - - 50: vector Documentation; - - 55: QsComments Comments; -} - -// Represents the possible kinds of QsTypeItem. -// N.B. Does not have an equivalent F# type. -enum QsTypeItemKind -{ - Named, - Anonymous -} - -struct QsTypeItem -{ - 5: required QsTypeItemKind Kind = Named; - - // Not null when Kind is Named. - 10: nullable> Named; - - // Not null when Kind is Anonymous. - 15: nullable Anonymous; -} - -struct QsCustomType -{ - 5: QsQualifiedName FullName; - - 10: vector Attributes; - - 15: Modifiers Modifiers; - - 20: string SourceFile; - - 25: nullable Location; - - 30: ResolvedType Type; - - 35: QsTuple TypeItems; - - 40: vector Documentation; - - 45: QsComments Comments; -} - -// Represents the possible kinds of QsNamespaceElement. -// N.B. Does not have an equivalent F# type. -enum QsNamespaceElementKind -{ - QsCallable, - QsCustomType -} - -struct QsNamespaceElement -{ - 5: required QsNamespaceElementKind Kind = QsCallable; - - // Non-null when 'Kind' is 'QsCallable'. - 10: nullable Callable; - - // Non-null when 'Kind' is 'QsCustomType'. - 15: nullable CustomType; -} - -// Used to encapsulate F#'s representation of namespace documentation. -// N.B. Does not have an equivalent F# type. -struct QsSourceFileDocumentation -{ - 5: string FileName; - - 10: vector DocumentationItems; -} - -struct QsNamespace -{ - 5: string Name; - - 10: vector Elements; - - 15: list Documentation; -} - -struct QsCompilation -{ - 5: vector Namespaces; - - 10: vector EntryPoints; -} diff --git a/src/QsCompiler/BondSchemas/Generated/CompilerDataStructures.cs b/src/QsCompiler/BondSchemas/Generated/CompilerDataStructures.cs deleted file mode 100644 index af43d722b2..0000000000 --- a/src/QsCompiler/BondSchemas/Generated/CompilerDataStructures.cs +++ /dev/null @@ -1,1791 +0,0 @@ - -//------------------------------------------------------------------------------ -// This code was generated by a tool. -// -// Tool : Bond Compiler 0.12.0.0 -// Input filename: CompilerDataStructures.bond -// Output filename: CompilerDataStructures_types.cs -// -// Changes to this file may cause incorrect behavior and will be lost when -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -// suppress "Missing XML comment for publicly visible type or member" -#pragma warning disable 1591 - - -#region ReSharper warnings -// ReSharper disable PartialTypeWithSinglePart -// ReSharper disable RedundantNameQualifier -// ReSharper disable InconsistentNaming -// ReSharper disable CheckNamespace -// ReSharper disable UnusedParameter.Local -// ReSharper disable RedundantUsingDirective -#endregion - -namespace Microsoft.Quantum.QsCompiler.BondSchemas -{ - using System.Collections.Generic; - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class Position - { - [global::Bond.Id(5)] - public int Line { get; set; } - - [global::Bond.Id(10)] - public int Column { get; set; } - - public Position() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.Position", "Position") - { } - - protected Position(string fullName, string name) - { - - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class Range - { - [global::Bond.Id(5)] - public Position Start { get; set; } - - [global::Bond.Id(10)] - public Position End { get; set; } - - public Range() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.Range", "Range") - { } - - protected Range(string fullName, string name) - { - Start = new Position(); - End = new Position(); - } - } - - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public enum AccessModifier - { - DefaultAccess, - Internal, - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class Modifiers - { - [global::Bond.Id(5)] - public AccessModifier Access { get; set; } - - public Modifiers() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.Modifiers", "Modifiers") - { } - - protected Modifiers(string fullName, string name) - { - Access = AccessModifier.DefaultAccess; - } - } - - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public enum QsGeneratorDirective - { - SelfInverse, - Invert, - Distribute, - InvalidGenerator, - } - - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public enum QsResult - { - Zero, - One, - } - - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public enum QsPauli - { - PauliX, - PauliY, - PauliZ, - PauliI, - } - - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public enum QsExpressionKind - { - UnitValue, - Identifier, - ValueTuple, - IntLiteral, - BigIntLiteral, - DoubleLiteral, - BoolLiteral, - StringLiteral, - ResultLiteral, - PauliLiteral, - RangeLiteral, - NewArray, - ValueArray, - ArrayItem, - NamedItem, - NEG, - NOT, - BNOT, - ADD, - SUB, - MUL, - DIV, - MOD, - POW, - EQ, - NEQ, - LT, - LTE, - GT, - GTE, - AND, - OR, - BOR, - BAND, - BXOR, - LSHIFT, - RSHIFT, - CONDITIONAL, - CopyAndUpdate, - UnwrapApplication, - AdjointApplication, - ControlledApplication, - CallLikeExpression, - MissingExpr, - InvalidExpr, - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class QsExpressionKindIdentifier - { - [global::Bond.Id(5), global::Bond.Type(typeof(global::Bond.Tag.classT))] - public TSymbol Symbol { get; set; } - - [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.nullable>))] - public List Types { get; set; } - - public QsExpressionKindIdentifier() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.QsExpressionKindIdentifier", "QsExpressionKindIdentifier") - { } - - protected QsExpressionKindIdentifier(string fullName, string name) - { - Symbol = global::Bond.GenericFactory.Create(); - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class QsExpressionKindStringLiteral - { - [global::Bond.Id(5)] - public string StringLiteral { get; set; } - - [global::Bond.Id(10), global::Bond.Type(typeof(List))] - public List Expressions { get; set; } - - public QsExpressionKindStringLiteral() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.QsExpressionKindStringLiteral", "QsExpressionKindStringLiteral") - { } - - protected QsExpressionKindStringLiteral(string fullName, string name) - { - StringLiteral = ""; - Expressions = new List(); - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class QsExpressionKindExpressionDouble - { - [global::Bond.Id(5), global::Bond.Type(typeof(global::Bond.Tag.classT))] - public TExpression Expression1 { get; set; } - - [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.classT))] - public TExpression Expression2 { get; set; } - - public QsExpressionKindExpressionDouble() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.QsExpressionKindExpressionDouble", "QsExpressionKindExpressionDouble") - { } - - protected QsExpressionKindExpressionDouble(string fullName, string name) - { - Expression1 = global::Bond.GenericFactory.Create(); - Expression2 = global::Bond.GenericFactory.Create(); - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class QsExpressionKindExpressionTriple - { - [global::Bond.Id(5), global::Bond.Type(typeof(global::Bond.Tag.classT))] - public TExpression Expression1 { get; set; } - - [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.classT))] - public TExpression Expression2 { get; set; } - - [global::Bond.Id(15), global::Bond.Type(typeof(global::Bond.Tag.classT))] - public TExpression Expression3 { get; set; } - - public QsExpressionKindExpressionTriple() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.QsExpressionKindExpressionTriple", "QsExpressionKindExpressionTriple") - { } - - protected QsExpressionKindExpressionTriple(string fullName, string name) - { - Expression1 = global::Bond.GenericFactory.Create(); - Expression2 = global::Bond.GenericFactory.Create(); - Expression3 = global::Bond.GenericFactory.Create(); - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class QsExpressionKindNewArray - { - [global::Bond.Id(5), global::Bond.Type(typeof(global::Bond.Tag.classT))] - public TType Type { get; set; } - - [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.classT))] - public TExpression Expression { get; set; } - - public QsExpressionKindNewArray() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.QsExpressionKindNewArray", "QsExpressionKindNewArray") - { } - - protected QsExpressionKindNewArray(string fullName, string name) - { - Type = global::Bond.GenericFactory.Create(); - Expression = global::Bond.GenericFactory.Create(); - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class QsExpressionKindNamedItem - { - [global::Bond.Id(5), global::Bond.Type(typeof(global::Bond.Tag.classT))] - public TExpression Expression { get; set; } - - [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.classT))] - public TSymbol Symbol { get; set; } - - public QsExpressionKindNamedItem() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.QsExpressionKindNamedItem", "QsExpressionKindNamedItem") - { } - - protected QsExpressionKindNamedItem(string fullName, string name) - { - Expression = global::Bond.GenericFactory.Create(); - Symbol = global::Bond.GenericFactory.Create(); - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class QsExpressionKindComposition - { - [global::Bond.Id(5), global::Bond.Required] - public QsExpressionKind Kind { get; set; } - - [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.nullable>))] - public QsExpressionKindIdentifier Identifier { get; set; } - - [global::Bond.Id(20), global::Bond.Type(typeof(global::Bond.Tag.nullable))] - public long? IntLiteral { get; set; } - - [global::Bond.Id(25), global::Bond.Type(typeof(global::Bond.Tag.nullable>))] - public System.ArraySegment BigIntLiteral { get; set; } - - [global::Bond.Id(30), global::Bond.Type(typeof(global::Bond.Tag.nullable))] - public double? DoubleLiteral { get; set; } - - [global::Bond.Id(35), global::Bond.Type(typeof(global::Bond.Tag.nullable))] - public bool? BoolLiteral { get; set; } - - [global::Bond.Id(40), global::Bond.Type(typeof(global::Bond.Tag.nullable>))] - public QsExpressionKindStringLiteral StringLiteral { get; set; } - - [global::Bond.Id(45), global::Bond.Type(typeof(global::Bond.Tag.nullable))] - public QsResult? ResultLiteral { get; set; } - - [global::Bond.Id(50), global::Bond.Type(typeof(global::Bond.Tag.nullable))] - public QsPauli? PauliLiteral { get; set; } - - [global::Bond.Id(55), global::Bond.Type(typeof(global::Bond.Tag.nullable>))] - public QsExpressionKindNewArray NewArray { get; set; } - - [global::Bond.Id(60), global::Bond.Type(typeof(global::Bond.Tag.nullable>))] - public QsExpressionKindNamedItem NamedItem { get; set; } - - [global::Bond.Id(65), global::Bond.Type(typeof(global::Bond.Tag.nullable))] - public TExpression Expression { get; set; } - - [global::Bond.Id(70), global::Bond.Type(typeof(global::Bond.Tag.nullable>))] - public QsExpressionKindExpressionDouble ExpressionDouble { get; set; } - - [global::Bond.Id(75), global::Bond.Type(typeof(global::Bond.Tag.nullable>))] - public QsExpressionKindExpressionTriple ExpressionTriple { get; set; } - - [global::Bond.Id(80), global::Bond.Type(typeof(global::Bond.Tag.nullable>))] - public List ExpressionArray { get; set; } - - public QsExpressionKindComposition() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.QsExpressionKindComposition", "QsExpressionKindComposition") - { } - - protected QsExpressionKindComposition(string fullName, string name) - { - Kind = QsExpressionKind.InvalidExpr; - } - } - - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public enum QsBindingKind - { - ImmutableBinding, - MutableBinding, - } - - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public enum QsSpecializationKind - { - QsBody, - QsAdjoint, - QsControlled, - QsControlledAdjoint, - } - - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public enum QsCallableKind - { - Operation, - Function, - TypeConstructor, - } - - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public enum QsQubitScopeKind - { - Allocate, - Borrow, - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class QsQualifiedName - { - [global::Bond.Id(5)] - public string Namespace { get; set; } - - [global::Bond.Id(10)] - public string Name { get; set; } - - public QsQualifiedName() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.QsQualifiedName", "QsQualifiedName") - { } - - protected QsQualifiedName(string fullName, string name) - { - Namespace = ""; - Name = ""; - } - } - - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public enum SymbolTupleKind - { - InvalidItem, - VariableName, - VariableNameTuple, - DiscardedItem, - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class SymbolTuple - { - [global::Bond.Id(5), global::Bond.Required] - public SymbolTupleKind Kind { get; set; } - - [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.nullable))] - public string VariableName { get; set; } - - [global::Bond.Id(15), global::Bond.Type(typeof(global::Bond.Tag.nullable>))] - public List VariableNameTuple { get; set; } - - public SymbolTuple() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.SymbolTuple", "SymbolTuple") - { } - - protected SymbolTuple(string fullName, string name) - { - Kind = SymbolTupleKind.InvalidItem; - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class QsBinding - { - [global::Bond.Id(5)] - public QsBindingKind Kind { get; set; } - - [global::Bond.Id(10)] - public SymbolTuple Lhs { get; set; } - - [global::Bond.Id(15), global::Bond.Type(typeof(global::Bond.Tag.classT))] - public T Rhs { get; set; } - - public QsBinding() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.QsBinding", "QsBinding") - { } - - protected QsBinding(string fullName, string name) - { - Kind = QsBindingKind.ImmutableBinding; - Lhs = new SymbolTuple(); - Rhs = global::Bond.GenericFactory.Create(); - } - } - - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public enum IdentifierKind - { - LocalVariable, - GlobalCallable, - InvalidIdentifier, - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class Identifier - { - [global::Bond.Id(5), global::Bond.Required] - public IdentifierKind Kind { get; set; } - - [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.nullable))] - public string LocalVariable { get; set; } - - [global::Bond.Id(15), global::Bond.Type(typeof(global::Bond.Tag.nullable))] - public QsQualifiedName GlobalCallable { get; set; } - - public Identifier() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.Identifier", "Identifier") - { } - - protected Identifier(string fullName, string name) - { - Kind = IdentifierKind.LocalVariable; - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class QsLocation - { - [global::Bond.Id(5)] - public Position Offset { get; set; } - - [global::Bond.Id(10)] - public Range Range { get; set; } - - public QsLocation() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.QsLocation", "QsLocation") - { } - - protected QsLocation(string fullName, string name) - { - Offset = new Position(); - Range = new Range(); - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class QsTypeParameter - { - [global::Bond.Id(5)] - public QsQualifiedName Origin { get; set; } - - [global::Bond.Id(10)] - public string TypeName { get; set; } - - [global::Bond.Id(15), global::Bond.Type(typeof(global::Bond.Tag.nullable))] - public Range Range { get; set; } - - public QsTypeParameter() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.QsTypeParameter", "QsTypeParameter") - { } - - protected QsTypeParameter(string fullName, string name) - { - Origin = new QsQualifiedName(); - TypeName = ""; - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class UserDefinedType - { - [global::Bond.Id(5)] - public string Namespace { get; set; } - - [global::Bond.Id(10)] - public string Name { get; set; } - - [global::Bond.Id(15), global::Bond.Type(typeof(global::Bond.Tag.nullable))] - public Range Range { get; set; } - - public UserDefinedType() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.UserDefinedType", "UserDefinedType") - { } - - protected UserDefinedType(string fullName, string name) - { - Namespace = ""; - Name = ""; - } - } - - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public enum OpProperty - { - Adjointable, - Controllable, - } - - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public enum CharacteristicsKind - { - EmptySet, - SimpleSet, - Union, - Intersection, - InvalidSetExpr, - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class CharacteristicsKindSetOperation - { - [global::Bond.Id(5), global::Bond.Type(typeof(global::Bond.Tag.classT))] - public T Set1 { get; set; } - - [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.classT))] - public T Set2 { get; set; } - - public CharacteristicsKindSetOperation() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.CharacteristicsKindSetOperation", "CharacteristicsKindSetOperation") - { } - - protected CharacteristicsKindSetOperation(string fullName, string name) - { - Set1 = global::Bond.GenericFactory.Create(); - Set2 = global::Bond.GenericFactory.Create(); - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class CharacteristicsKindComposition - { - [global::Bond.Id(5), global::Bond.Required] - public CharacteristicsKind Kind { get; set; } - - [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.nullable))] - public OpProperty? SimpleSet { get; set; } - - [global::Bond.Id(15), global::Bond.Type(typeof(global::Bond.Tag.nullable>))] - public CharacteristicsKindSetOperation SetOperation { get; set; } - - public CharacteristicsKindComposition() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.CharacteristicsKindComposition", "CharacteristicsKindComposition") - { } - - protected CharacteristicsKindComposition(string fullName, string name) - { - Kind = CharacteristicsKind.InvalidSetExpr; - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class ResolvedCharacteristics - { - [global::Bond.Id(5)] - public CharacteristicsKindComposition Expression { get; set; } - - public ResolvedCharacteristics() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.ResolvedCharacteristics", "ResolvedCharacteristics") - { } - - protected ResolvedCharacteristics(string fullName, string name) - { - Expression = new CharacteristicsKindComposition(); - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class InferredCallableInformation - { - [global::Bond.Id(5)] - public bool IsSelfAdjoint { get; set; } - - [global::Bond.Id(10)] - public bool IsIntrinsic { get; set; } - - public InferredCallableInformation() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.InferredCallableInformation", "InferredCallableInformation") - { } - - protected InferredCallableInformation(string fullName, string name) - { - - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class CallableInformation - { - [global::Bond.Id(5)] - public ResolvedCharacteristics Characteristics { get; set; } - - [global::Bond.Id(10)] - public InferredCallableInformation InferredInformation { get; set; } - - public CallableInformation() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.CallableInformation", "CallableInformation") - { } - - protected CallableInformation(string fullName, string name) - { - Characteristics = new ResolvedCharacteristics(); - InferredInformation = new InferredCallableInformation(); - } - } - - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public enum QsTypeKind - { - UnitType, - Int, - BigInt, - Double, - Bool, - String, - Qubit, - Result, - Pauli, - Range, - ArrayType, - TupleType, - UserDefinedType, - TypeParameter, - Operation, - Function, - MissingType, - InvalidType, - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class QsTypeKindFunction - { - [global::Bond.Id(5), global::Bond.Type(typeof(global::Bond.Tag.classT))] - public T Type1 { get; set; } - - [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.classT))] - public T Type2 { get; set; } - - public QsTypeKindFunction() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.QsTypeKindFunction", "QsTypeKindFunction") - { } - - protected QsTypeKindFunction(string fullName, string name) - { - Type1 = global::Bond.GenericFactory.Create(); - Type2 = global::Bond.GenericFactory.Create(); - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class QsTypeKindOperation - { - [global::Bond.Id(5), global::Bond.Type(typeof(global::Bond.Tag.classT))] - public TType Type1 { get; set; } - - [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.classT))] - public TType Type2 { get; set; } - - [global::Bond.Id(15), global::Bond.Type(typeof(global::Bond.Tag.classT))] - public TCharacteristics Characteristics { get; set; } - - public QsTypeKindOperation() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.QsTypeKindOperation", "QsTypeKindOperation") - { } - - protected QsTypeKindOperation(string fullName, string name) - { - Type1 = global::Bond.GenericFactory.Create(); - Type2 = global::Bond.GenericFactory.Create(); - Characteristics = global::Bond.GenericFactory.Create(); - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class QsTypeKindComposition - { - [global::Bond.Id(5), global::Bond.Required] - public QsTypeKind Kind { get; set; } - - [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.nullable))] - public TType ArrayType { get; set; } - - [global::Bond.Id(15), global::Bond.Type(typeof(global::Bond.Tag.nullable>))] - public List TupleType { get; set; } - - [global::Bond.Id(20), global::Bond.Type(typeof(global::Bond.Tag.nullable))] - public TUdt UserDefinedType { get; set; } - - [global::Bond.Id(25), global::Bond.Type(typeof(global::Bond.Tag.nullable))] - public TParam TypeParameter { get; set; } - - [global::Bond.Id(30), global::Bond.Type(typeof(global::Bond.Tag.nullable>))] - public QsTypeKindOperation Operation { get; set; } - - [global::Bond.Id(35), global::Bond.Type(typeof(global::Bond.Tag.nullable>))] - public QsTypeKindFunction Function { get; set; } - - public QsTypeKindComposition() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.QsTypeKindComposition", "QsTypeKindComposition") - { } - - protected QsTypeKindComposition(string fullName, string name) - { - Kind = QsTypeKind.InvalidType; - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class ResolvedType - { - [global::Bond.Id(5)] - public QsTypeKindComposition TypeKind { get; set; } - - public ResolvedType() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.ResolvedType", "ResolvedType") - { } - - protected ResolvedType(string fullName, string name) - { - TypeKind = new QsTypeKindComposition(); - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class InferredExpressionInformation - { - [global::Bond.Id(5)] - public bool IsMutable { get; set; } - - [global::Bond.Id(10)] - public bool HasLocalQuantumDependency { get; set; } - - public InferredExpressionInformation() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.InferredExpressionInformation", "InferredExpressionInformation") - { } - - protected InferredExpressionInformation(string fullName, string name) - { - - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class TypedArgument - { - [global::Bond.Id(5)] - public QsQualifiedName Callable { get; set; } - - [global::Bond.Id(10)] - public string Name { get; set; } - - [global::Bond.Id(15)] - public ResolvedType Resolution { get; set; } - - public TypedArgument() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.TypedArgument", "TypedArgument") - { } - - protected TypedArgument(string fullName, string name) - { - Callable = new QsQualifiedName(); - Name = ""; - Resolution = new ResolvedType(); - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class TypedExpression - { - [global::Bond.Id(5)] - public QsExpressionKindComposition Expression { get; set; } - - [global::Bond.Id(10)] - public List TypedArguments { get; set; } - - [global::Bond.Id(15)] - public ResolvedType ResolvedType { get; set; } - - [global::Bond.Id(20)] - public InferredExpressionInformation InferredInformation { get; set; } - - [global::Bond.Id(25), global::Bond.Type(typeof(global::Bond.Tag.nullable))] - public Range Range { get; set; } - - public TypedExpression() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.TypedExpression", "TypedExpression") - { } - - protected TypedExpression(string fullName, string name) - { - Expression = new QsExpressionKindComposition(); - TypedArguments = new List(); - ResolvedType = new ResolvedType(); - InferredInformation = new InferredExpressionInformation(); - } - } - - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public enum QsInitializerKind - { - SingleQubitAllocation, - QubitRegisterAllocation, - QubitTupleAllocation, - InvalidInitializer, - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class QsInitializerKindComposition - { - [global::Bond.Id(5), global::Bond.Required] - public QsInitializerKind Kind { get; set; } - - [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.nullable))] - public TExpression QubitRegisterAllocation { get; set; } - - [global::Bond.Id(15), global::Bond.Type(typeof(global::Bond.Tag.nullable>))] - public List QubitTupleAllocation { get; set; } - - public QsInitializerKindComposition() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.QsInitializerKindComposition", "QsInitializerKindComposition") - { } - - protected QsInitializerKindComposition(string fullName, string name) - { - Kind = QsInitializerKind.InvalidInitializer; - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class ResolvedInitializer - { - [global::Bond.Id(5)] - public QsInitializerKindComposition Initializer { get; set; } - - [global::Bond.Id(10)] - public ResolvedType ResolvedType { get; set; } - - public ResolvedInitializer() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.ResolvedInitializer", "ResolvedInitializer") - { } - - protected ResolvedInitializer(string fullName, string name) - { - Initializer = new QsInitializerKindComposition(); - ResolvedType = new ResolvedType(); - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class LocalVariableDeclaration - { - [global::Bond.Id(5), global::Bond.Type(typeof(global::Bond.Tag.classT))] - public TVariableName VariableName { get; set; } - - [global::Bond.Id(10)] - public ResolvedType Type { get; set; } - - [global::Bond.Id(15)] - public InferredExpressionInformation InferredInformation { get; set; } - - [global::Bond.Id(20), global::Bond.Type(typeof(global::Bond.Tag.nullable))] - public Position Position { get; set; } - - [global::Bond.Id(25)] - public Range Range { get; set; } - - public LocalVariableDeclaration() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.LocalVariableDeclaration", "LocalVariableDeclaration") - { } - - protected LocalVariableDeclaration(string fullName, string name) - { - VariableName = global::Bond.GenericFactory.Create(); - Type = new ResolvedType(); - InferredInformation = new InferredExpressionInformation(); - Range = new Range(); - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class LocalDeclarations - { - [global::Bond.Id(5)] - public List> Variables { get; set; } - - public LocalDeclarations() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.LocalDeclarations", "LocalDeclarations") - { } - - protected LocalDeclarations(string fullName, string name) - { - Variables = new List>(); - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class QsValueUpdate - { - [global::Bond.Id(5)] - public TypedExpression Lhs { get; set; } - - [global::Bond.Id(10)] - public TypedExpression Rhs { get; set; } - - public QsValueUpdate() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.QsValueUpdate", "QsValueUpdate") - { } - - protected QsValueUpdate(string fullName, string name) - { - Lhs = new TypedExpression(); - Rhs = new TypedExpression(); - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class QsComments - { - [global::Bond.Id(5)] - public List OpeningComments { get; set; } - - [global::Bond.Id(10)] - public List ClosingComments { get; set; } - - public QsComments() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.QsComments", "QsComments") - { } - - protected QsComments(string fullName, string name) - { - OpeningComments = new List(); - ClosingComments = new List(); - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class QsPositionedBlock - { - [global::Bond.Id(5)] - public QsScope Body { get; set; } - - [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.nullable))] - public QsLocation Location { get; set; } - - [global::Bond.Id(15)] - public QsComments Comments { get; set; } - - public QsPositionedBlock() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.QsPositionedBlock", "QsPositionedBlock") - { } - - protected QsPositionedBlock(string fullName, string name) - { - Body = new QsScope(); - Comments = new QsComments(); - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class QsConditionalBlock - { - [global::Bond.Id(5)] - public TypedExpression Expression { get; set; } - - [global::Bond.Id(10)] - public QsPositionedBlock Block { get; set; } - - public QsConditionalBlock() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.QsConditionalBlock", "QsConditionalBlock") - { } - - protected QsConditionalBlock(string fullName, string name) - { - Expression = new TypedExpression(); - Block = new QsPositionedBlock(); - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class QsConditionalStatement - { - [global::Bond.Id(5)] - public List ConditionalBlocks { get; set; } - - [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.nullable))] - public QsPositionedBlock Default { get; set; } - - public QsConditionalStatement() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.QsConditionalStatement", "QsConditionalStatement") - { } - - protected QsConditionalStatement(string fullName, string name) - { - ConditionalBlocks = new List(); - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class QsLoopItem - { - [global::Bond.Id(5)] - public SymbolTuple SymbolTuple { get; set; } - - [global::Bond.Id(10)] - public ResolvedType ResolvedType { get; set; } - - public QsLoopItem() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.QsLoopItem", "QsLoopItem") - { } - - protected QsLoopItem(string fullName, string name) - { - SymbolTuple = new SymbolTuple(); - ResolvedType = new ResolvedType(); - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class QsForStatement - { - [global::Bond.Id(5)] - public QsLoopItem LoopItem { get; set; } - - [global::Bond.Id(10)] - public TypedExpression IterationValues { get; set; } - - [global::Bond.Id(15)] - public QsScope Body { get; set; } - - public QsForStatement() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.QsForStatement", "QsForStatement") - { } - - protected QsForStatement(string fullName, string name) - { - LoopItem = new QsLoopItem(); - IterationValues = new TypedExpression(); - Body = new QsScope(); - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class QsWhileStatement - { - [global::Bond.Id(5)] - public TypedExpression Condition { get; set; } - - [global::Bond.Id(10)] - public QsScope Body { get; set; } - - public QsWhileStatement() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.QsWhileStatement", "QsWhileStatement") - { } - - protected QsWhileStatement(string fullName, string name) - { - Condition = new TypedExpression(); - Body = new QsScope(); - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class QsRepeatStatement - { - [global::Bond.Id(5)] - public QsPositionedBlock RepeatBlock { get; set; } - - [global::Bond.Id(10)] - public TypedExpression SuccessCondition { get; set; } - - [global::Bond.Id(15)] - public QsPositionedBlock FixupBlock { get; set; } - - public QsRepeatStatement() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.QsRepeatStatement", "QsRepeatStatement") - { } - - protected QsRepeatStatement(string fullName, string name) - { - RepeatBlock = new QsPositionedBlock(); - SuccessCondition = new TypedExpression(); - FixupBlock = new QsPositionedBlock(); - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class QsConjugation - { - [global::Bond.Id(5)] - public QsPositionedBlock OuterTransformation { get; set; } - - [global::Bond.Id(10)] - public QsPositionedBlock InnerTransformation { get; set; } - - public QsConjugation() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.QsConjugation", "QsConjugation") - { } - - protected QsConjugation(string fullName, string name) - { - OuterTransformation = new QsPositionedBlock(); - InnerTransformation = new QsPositionedBlock(); - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class QsQubitScope - { - [global::Bond.Id(5)] - public QsQubitScopeKind Kind { get; set; } - - [global::Bond.Id(10)] - public QsBinding Binding { get; set; } - - [global::Bond.Id(15)] - public QsScope Body { get; set; } - - public QsQubitScope() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.QsQubitScope", "QsQubitScope") - { } - - protected QsQubitScope(string fullName, string name) - { - Kind = QsQubitScopeKind.Allocate; - Binding = new QsBinding(); - Body = new QsScope(); - } - } - - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public enum QsStatementKind - { - QsExpressionStatement, - QsReturnStatement, - QsFailStatement, - QsVariableDeclaration, - QsValueUpdate, - QsConditionalStatement, - QsForStatement, - QsWhileStatement, - QsRepeatStatement, - QsConjugation, - QsQubitScope, - EmptyStatement, - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class QsStatementKindComposition - { - [global::Bond.Id(5), global::Bond.Required] - public QsStatementKind Kind { get; set; } - - [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.nullable))] - public TypedExpression TypedExpression { get; set; } - - [global::Bond.Id(15), global::Bond.Type(typeof(global::Bond.Tag.nullable>))] - public QsBinding VariableDeclaration { get; set; } - - [global::Bond.Id(20), global::Bond.Type(typeof(global::Bond.Tag.nullable))] - public QsValueUpdate ValueUpdate { get; set; } - - [global::Bond.Id(25), global::Bond.Type(typeof(global::Bond.Tag.nullable))] - public QsConditionalStatement ConditionalStatement { get; set; } - - [global::Bond.Id(30), global::Bond.Type(typeof(global::Bond.Tag.nullable))] - public QsForStatement ForStatement { get; set; } - - [global::Bond.Id(35), global::Bond.Type(typeof(global::Bond.Tag.nullable))] - public QsWhileStatement WhileStatement { get; set; } - - [global::Bond.Id(40), global::Bond.Type(typeof(global::Bond.Tag.nullable))] - public QsRepeatStatement RepeatStatement { get; set; } - - [global::Bond.Id(45), global::Bond.Type(typeof(global::Bond.Tag.nullable))] - public QsConjugation Conjugation { get; set; } - - [global::Bond.Id(50), global::Bond.Type(typeof(global::Bond.Tag.nullable))] - public QsQubitScope QubitScope { get; set; } - - public QsStatementKindComposition() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.QsStatementKindComposition", "QsStatementKindComposition") - { } - - protected QsStatementKindComposition(string fullName, string name) - { - Kind = QsStatementKind.EmptyStatement; - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class QsStatement - { - [global::Bond.Id(5)] - public QsStatementKindComposition Statement { get; set; } - - [global::Bond.Id(10)] - public LocalDeclarations SymbolDeclarations { get; set; } - - [global::Bond.Id(15), global::Bond.Type(typeof(global::Bond.Tag.nullable))] - public QsLocation Location { get; set; } - - [global::Bond.Id(20)] - public QsComments Comments { get; set; } - - public QsStatement() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.QsStatement", "QsStatement") - { } - - protected QsStatement(string fullName, string name) - { - Statement = new QsStatementKindComposition(); - SymbolDeclarations = new LocalDeclarations(); - Comments = new QsComments(); - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class QsScope - { - [global::Bond.Id(5)] - public List Statements { get; set; } - - [global::Bond.Id(10)] - public LocalDeclarations KnownSymbols { get; set; } - - public QsScope() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.QsScope", "QsScope") - { } - - protected QsScope(string fullName, string name) - { - Statements = new List(); - KnownSymbols = new LocalDeclarations(); - } - } - - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public enum QsLocalSymbolKind - { - ValidName, - InvalidName, - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class QsLocalSymbol - { - [global::Bond.Id(5), global::Bond.Required] - public QsLocalSymbolKind Kind { get; set; } - - [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.nullable))] - public string Name { get; set; } - - public QsLocalSymbol() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.QsLocalSymbol", "QsLocalSymbol") - { } - - protected QsLocalSymbol(string fullName, string name) - { - Kind = QsLocalSymbolKind.InvalidName; - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class QsDeclarationAttribute - { - [global::Bond.Id(5), global::Bond.Type(typeof(global::Bond.Tag.nullable))] - public UserDefinedType TypeId { get; set; } - - [global::Bond.Id(10)] - public TypedExpression Argument { get; set; } - - [global::Bond.Id(15)] - public Position Offset { get; set; } - - [global::Bond.Id(20)] - public QsComments Comments { get; set; } - - public QsDeclarationAttribute() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.QsDeclarationAttribute", "QsDeclarationAttribute") - { } - - protected QsDeclarationAttribute(string fullName, string name) - { - Argument = new TypedExpression(); - Offset = new Position(); - Comments = new QsComments(); - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class ResolvedSignature - { - [global::Bond.Id(5)] - public List TypeParameters { get; set; } - - [global::Bond.Id(10)] - public ResolvedType ArgumentType { get; set; } - - [global::Bond.Id(15)] - public ResolvedType ReturnType { get; set; } - - [global::Bond.Id(20)] - public CallableInformation Information { get; set; } - - public ResolvedSignature() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.ResolvedSignature", "ResolvedSignature") - { } - - protected ResolvedSignature(string fullName, string name) - { - TypeParameters = new List(); - ArgumentType = new ResolvedType(); - ReturnType = new ResolvedType(); - Information = new CallableInformation(); - } - } - - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public enum QsTupleKind - { - QsTupleItem, - QsTuple, - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class QsTuple - { - [global::Bond.Id(5), global::Bond.Required] - public QsTupleKind Kind { get; set; } - - [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.nullable))] - public T Item { get; set; } - - [global::Bond.Id(15), global::Bond.Type(typeof(global::Bond.Tag.nullable>>))] - public List> Items { get; set; } - - public QsTuple() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.QsTuple", "QsTuple") - { } - - protected QsTuple(string fullName, string name) - { - Kind = QsTupleKind.QsTupleItem; - } - } - - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public enum SpecializationImplementationKind - { - Provided, - Intrinsic, - External, - Generated, - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class SpecializationImplementationKindProvided - { - [global::Bond.Id(5)] - public QsTuple> Tuple { get; set; } - - [global::Bond.Id(10)] - public QsScope Implementation { get; set; } - - public SpecializationImplementationKindProvided() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.SpecializationImplementationKindProvided", "SpecializationImplementationKindProvided") - { } - - protected SpecializationImplementationKindProvided(string fullName, string name) - { - Tuple = new QsTuple>(); - Implementation = new QsScope(); - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class SpecializationImplementation - { - [global::Bond.Id(5), global::Bond.Required] - public SpecializationImplementationKind Kind { get; set; } - - [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.nullable))] - public SpecializationImplementationKindProvided Provided { get; set; } - - [global::Bond.Id(15), global::Bond.Type(typeof(global::Bond.Tag.nullable))] - public QsGeneratorDirective? Generated { get; set; } - - public SpecializationImplementation() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.SpecializationImplementation", "SpecializationImplementation") - { } - - protected SpecializationImplementation(string fullName, string name) - { - Kind = SpecializationImplementationKind.Generated; - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class QsSpecialization - { - [global::Bond.Id(5)] - public QsSpecializationKind Kind { get; set; } - - [global::Bond.Id(10)] - public QsQualifiedName Parent { get; set; } - - [global::Bond.Id(15)] - public List Attributes { get; set; } - - [global::Bond.Id(20)] - public string SourceFile { get; set; } - - [global::Bond.Id(25), global::Bond.Type(typeof(global::Bond.Tag.nullable))] - public QsLocation Location { get; set; } - - [global::Bond.Id(30), global::Bond.Type(typeof(global::Bond.Tag.nullable>))] - public List TypeArguments { get; set; } - - [global::Bond.Id(35)] - public ResolvedSignature Signature { get; set; } - - [global::Bond.Id(40)] - public SpecializationImplementation Implementation { get; set; } - - [global::Bond.Id(45)] - public List Documentation { get; set; } - - [global::Bond.Id(50)] - public QsComments Comments { get; set; } - - public QsSpecialization() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.QsSpecialization", "QsSpecialization") - { } - - protected QsSpecialization(string fullName, string name) - { - Kind = QsSpecializationKind.QsBody; - Parent = new QsQualifiedName(); - Attributes = new List(); - SourceFile = ""; - Signature = new ResolvedSignature(); - Implementation = new SpecializationImplementation(); - Documentation = new List(); - Comments = new QsComments(); - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class QsCallable - { - [global::Bond.Id(5)] - public QsCallableKind Kind { get; set; } - - [global::Bond.Id(10)] - public QsQualifiedName FullName { get; set; } - - [global::Bond.Id(15)] - public List Attributes { get; set; } - - [global::Bond.Id(20)] - public Modifiers Modifiers { get; set; } - - [global::Bond.Id(25)] - public string SourceFile { get; set; } - - [global::Bond.Id(30), global::Bond.Type(typeof(global::Bond.Tag.nullable))] - public QsLocation Location { get; set; } - - [global::Bond.Id(35)] - public ResolvedSignature Signature { get; set; } - - [global::Bond.Id(40)] - public QsTuple> ArgumentTuple { get; set; } - - [global::Bond.Id(45)] - public List Specializations { get; set; } - - [global::Bond.Id(50)] - public List Documentation { get; set; } - - [global::Bond.Id(55)] - public QsComments Comments { get; set; } - - public QsCallable() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.QsCallable", "QsCallable") - { } - - protected QsCallable(string fullName, string name) - { - Kind = QsCallableKind.Operation; - FullName = new QsQualifiedName(); - Attributes = new List(); - Modifiers = new Modifiers(); - SourceFile = ""; - Signature = new ResolvedSignature(); - ArgumentTuple = new QsTuple>(); - Specializations = new List(); - Documentation = new List(); - Comments = new QsComments(); - } - } - - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public enum QsTypeItemKind - { - Named, - Anonymous, - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class QsTypeItem - { - [global::Bond.Id(5), global::Bond.Required] - public QsTypeItemKind Kind { get; set; } - - [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.nullable>))] - public LocalVariableDeclaration Named { get; set; } - - [global::Bond.Id(15), global::Bond.Type(typeof(global::Bond.Tag.nullable))] - public ResolvedType Anonymous { get; set; } - - public QsTypeItem() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.QsTypeItem", "QsTypeItem") - { } - - protected QsTypeItem(string fullName, string name) - { - Kind = QsTypeItemKind.Named; - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class QsCustomType - { - [global::Bond.Id(5)] - public QsQualifiedName FullName { get; set; } - - [global::Bond.Id(10)] - public List Attributes { get; set; } - - [global::Bond.Id(15)] - public Modifiers Modifiers { get; set; } - - [global::Bond.Id(20)] - public string SourceFile { get; set; } - - [global::Bond.Id(25), global::Bond.Type(typeof(global::Bond.Tag.nullable))] - public QsLocation Location { get; set; } - - [global::Bond.Id(30)] - public ResolvedType Type { get; set; } - - [global::Bond.Id(35)] - public QsTuple TypeItems { get; set; } - - [global::Bond.Id(40)] - public List Documentation { get; set; } - - [global::Bond.Id(45)] - public QsComments Comments { get; set; } - - public QsCustomType() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.QsCustomType", "QsCustomType") - { } - - protected QsCustomType(string fullName, string name) - { - FullName = new QsQualifiedName(); - Attributes = new List(); - Modifiers = new Modifiers(); - SourceFile = ""; - Type = new ResolvedType(); - TypeItems = new QsTuple(); - Documentation = new List(); - Comments = new QsComments(); - } - } - - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public enum QsNamespaceElementKind - { - QsCallable, - QsCustomType, - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class QsNamespaceElement - { - [global::Bond.Id(5), global::Bond.Required] - public QsNamespaceElementKind Kind { get; set; } - - [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.nullable))] - public QsCallable Callable { get; set; } - - [global::Bond.Id(15), global::Bond.Type(typeof(global::Bond.Tag.nullable))] - public QsCustomType CustomType { get; set; } - - public QsNamespaceElement() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.QsNamespaceElement", "QsNamespaceElement") - { } - - protected QsNamespaceElement(string fullName, string name) - { - Kind = QsNamespaceElementKind.QsCallable; - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class QsSourceFileDocumentation - { - [global::Bond.Id(5)] - public string FileName { get; set; } - - [global::Bond.Id(10)] - public List DocumentationItems { get; set; } - - public QsSourceFileDocumentation() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.QsSourceFileDocumentation", "QsSourceFileDocumentation") - { } - - protected QsSourceFileDocumentation(string fullName, string name) - { - FileName = ""; - DocumentationItems = new List(); - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class QsNamespace - { - [global::Bond.Id(5)] - public string Name { get; set; } - - [global::Bond.Id(10)] - public List Elements { get; set; } - - [global::Bond.Id(15)] - public LinkedList Documentation { get; set; } - - public QsNamespace() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.QsNamespace", "QsNamespace") - { } - - protected QsNamespace(string fullName, string name) - { - Name = ""; - Elements = new List(); - Documentation = new LinkedList(); - } - } - - [global::Bond.Schema] - [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.0.0")] - public partial class QsCompilation - { - [global::Bond.Id(5)] - public List Namespaces { get; set; } - - [global::Bond.Id(10)] - public List EntryPoints { get; set; } - - public QsCompilation() - : this("Microsoft.Quantum.QsCompiler.BondSchemas.QsCompilation", "QsCompilation") - { } - - protected QsCompilation(string fullName, string name) - { - Namespaces = new List(); - EntryPoints = new List(); - } - } -} // Microsoft.Quantum.QsCompiler.BondSchemas diff --git a/src/QsCompiler/BondSchemas/Protocols.cs b/src/QsCompiler/BondSchemas/Protocols.cs index 4088ec5b14..55d60f400b 100644 --- a/src/QsCompiler/BondSchemas/Protocols.cs +++ b/src/QsCompiler/BondSchemas/Protocols.cs @@ -11,6 +11,7 @@ namespace Microsoft.Quantum.QsCompiler.BondSchemas { + using BondQsCompilation = V1.QsCompilation; using SimpleBinaryDeserializer = Deserializer>; using SimpleBinarySerializer = Serializer>; @@ -44,16 +45,16 @@ public enum Option Type bondType, Option[]? options = null) { - QsCompilation? bondCompilation = null; + BondQsCompilation? bondCompilation = null; var inputBuffer = new InputBuffer(byteArray); var reader = new SimpleBinaryReader(inputBuffer); lock (BondSharedDataStructuresLock) { var deserializer = GetSimpleBinaryDeserializer(); - bondCompilation = deserializer.Deserialize(reader); + bondCompilation = deserializer.Deserialize(reader); } - return CompilerObjectTranslator.CreateQsCompilation(bondCompilation); + return Translators.FromBondSchemaToSyntaxTree(bondCompilation); } /// @@ -64,15 +65,8 @@ public static void Initialize() { lock (BondSharedDataStructuresLock) { - if (simpleBinaryDeserializerInitialization == null) - { - simpleBinaryDeserializerInitialization = QueueSimpleBinaryDeserializerInitialization(); - } - - if (simpleBinarySerializerInitialization == null) - { - simpleBinarySerializerInitialization = QueueSimpleBinarySerializerInitialization(); - } + _ = TryInitializeDeserializer(); + _ = TryInitializeSerializer(); } } @@ -84,10 +78,7 @@ public static void InitializeDeserializer() { lock (BondSharedDataStructuresLock) { - if (simpleBinaryDeserializerInitialization == null) - { - simpleBinaryDeserializerInitialization = QueueSimpleBinaryDeserializerInitialization(); - } + _ = TryInitializeDeserializer(); } } @@ -99,10 +90,7 @@ public static void InitializeSerializer() { lock (BondSharedDataStructuresLock) { - if (simpleBinarySerializerInitialization == null) - { - simpleBinarySerializerInitialization = QueueSimpleBinarySerializerInitialization(); - } + _ = TryInitializeSerializer(); } } @@ -118,7 +106,7 @@ public static void SerializeQsCompilationToSimpleBinary( { var outputBuffer = new OutputBuffer(); var writer = new SimpleBinaryWriter(outputBuffer); - var bondCompilation = BondSchemaTranslator.CreateBondCompilation(qsCompilation); + var bondCompilation = Translators.FromSyntaxTreeToBondSchema(qsCompilation); lock (BondSharedDataStructuresLock) { var serializer = GetSimpleBinarySerializer(); @@ -142,6 +130,24 @@ private static SimpleBinaryDeserializer GetSimpleBinaryDeserializer() return simpleBinaryDeserializerInitialization.Result; } + private static SimpleBinaryDeserializer GetSimpleBinaryDeserializer(Type type) + { + VerifyLockAcquired(BondSharedDataStructuresLock); + Task deserializerInitialization; + if (type == typeof(BondQsCompilation)) + { + deserializerInitialization = TryInitializeDeserializer(); + } + else + { + // TODO: Add a meaningful message. + throw new ArgumentException(); + } + + deserializerInitialization.Wait(); + return deserializerInitialization.Result; + } + private static SimpleBinarySerializer GetSimpleBinarySerializer() { VerifyLockAcquired(BondSharedDataStructuresLock); @@ -157,11 +163,12 @@ private static SimpleBinarySerializer GetSimpleBinarySerializer() private static Task QueueSimpleBinaryDeserializerInitialization() { VerifyLockAcquired(BondSharedDataStructuresLock); + // TODO: Maybe use this method to initialize everything by iterating through a dictionary. // inlineNested is false in order to decrease the time needed to initialize the deserializer. // While this setting may also increase deserialization time, we did not notice any performance drawbacks with our Bond schemas. return Task.Run(() => new SimpleBinaryDeserializer( - type: typeof(QsCompilation), + type: typeof(BondQsCompilation), factory: (Factory?)null, inlineNested: false)); } @@ -169,7 +176,29 @@ private static Task QueueSimpleBinaryDeserializerIniti private static Task QueueSimpleBinarySerializerInitialization() { VerifyLockAcquired(BondSharedDataStructuresLock); - return Task.Run(() => new SimpleBinarySerializer(typeof(QsCompilation))); + return Task.Run(() => new SimpleBinarySerializer(typeof(BondQsCompilation))); + } + + private static Task TryInitializeDeserializer() + { + VerifyLockAcquired(BondSharedDataStructuresLock); + if (simpleBinaryDeserializerInitialization == null) + { + simpleBinaryDeserializerInitialization = QueueSimpleBinaryDeserializerInitialization(); + } + + return simpleBinaryDeserializerInitialization; + } + + private static Task TryInitializeSerializer() + { + VerifyLockAcquired(BondSharedDataStructuresLock); + if (simpleBinarySerializerInitialization == null) + { + simpleBinarySerializerInitialization = QueueSimpleBinarySerializerInitialization(); + } + + return simpleBinarySerializerInitialization; } private static void VerifyLockAcquired(object lockObject) diff --git a/src/QsCompiler/BondSchemas/Translators.cs b/src/QsCompiler/BondSchemas/Translators.cs new file mode 100644 index 0000000000..19d5060d94 --- /dev/null +++ b/src/QsCompiler/BondSchemas/Translators.cs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System; + +namespace Microsoft.Quantum.QsCompiler.BondSchemas +{ + using CurrentBondQsCompilation = V1.QsCompilation; + + internal static class Translators + { + public static SyntaxTree.QsCompilation FromBondSchemaToSyntaxTree(TBond bondCompilation) + { + switch (bondCompilation) + { + case V1.QsCompilation bondCompilationV01: + return V1.CompilerObjectTranslator.CreateQsCompilation(bondCompilationV01); + + default: + // TODO: Use a more meaningful message. + throw new ArgumentException(); + } + } + + public static CurrentBondQsCompilation FromSyntaxTreeToBondSchema(SyntaxTree.QsCompilation qsCompilation) => + V1.BondSchemaTranslator.CreateBondCompilation(qsCompilation); + } +} diff --git a/src/QsCompiler/BondSchemas/BondSchemaTranslator.cs b/src/QsCompiler/BondSchemas/V1/BondSchemaTranslator.cs similarity index 99% rename from src/QsCompiler/BondSchemas/BondSchemaTranslator.cs rename to src/QsCompiler/BondSchemas/V1/BondSchemaTranslator.cs index eee0465d30..bb1d08cf6a 100644 --- a/src/QsCompiler/BondSchemas/BondSchemaTranslator.cs +++ b/src/QsCompiler/BondSchemas/V1/BondSchemaTranslator.cs @@ -7,7 +7,7 @@ using System.Linq; using Microsoft.Quantum.QsCompiler.DataTypes; -namespace Microsoft.Quantum.QsCompiler.BondSchemas +namespace Microsoft.Quantum.QsCompiler.BondSchemas.V1 { /// /// This class translates compiler objects to Bond schema objects. diff --git a/src/QsCompiler/BondSchemas/CompilerObjectTranslator.cs b/src/QsCompiler/BondSchemas/V1/CompilerObjectTranslator.cs similarity index 99% rename from src/QsCompiler/BondSchemas/CompilerObjectTranslator.cs rename to src/QsCompiler/BondSchemas/V1/CompilerObjectTranslator.cs index 3c1e2abf74..b2d762980e 100644 --- a/src/QsCompiler/BondSchemas/CompilerObjectTranslator.cs +++ b/src/QsCompiler/BondSchemas/V1/CompilerObjectTranslator.cs @@ -8,7 +8,7 @@ using Microsoft.Quantum.QsCompiler.DataTypes; using Microsoft.Quantum.QsCompiler.SyntaxTree; -namespace Microsoft.Quantum.QsCompiler.BondSchemas +namespace Microsoft.Quantum.QsCompiler.BondSchemas.V1 { /// /// This class translates Bond schema objects to C# compiler objects. diff --git a/src/QsCompiler/CompilationManager/AssemblyLoader.cs b/src/QsCompiler/CompilationManager/AssemblyLoader.cs index d7425fc916..ed3b60072e 100644 --- a/src/QsCompiler/CompilationManager/AssemblyLoader.cs +++ b/src/QsCompiler/CompilationManager/AssemblyLoader.cs @@ -123,7 +123,7 @@ public static bool LoadSyntaxTree( { PerformanceTracking.TaskStart(PerformanceTracking.Task.SyntaxTreeDeserialization); // TODO: This should be a call to the extended LoadSyntaxTree API. - compilation = BondSchemas.Protocols.DeserializeQsCompilationFromSimpleBinary(byteArray, typeof(BondSchemas.QsCompilation)); + compilation = BondSchemas.Protocols.DeserializeQsCompilationFromSimpleBinary(byteArray, typeof(BondSchemas.V1.QsCompilation)); PerformanceTracking.TaskEnd(PerformanceTracking.Task.SyntaxTreeDeserialization); } catch (Exception ex) From a9a48bbae5cd3671cf41c18ce3a4786fa2618aac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Zaragoza=20Cort=C3=A9s?= Date: Thu, 21 Jan 2021 12:30:46 -0800 Subject: [PATCH 04/17] Created BondSchemaTranslator for V2. --- .../BondSchemas/V1/BondSchemaTranslator.cs | 4 +-- .../BondSchemas/V2/BondSchemaTranslator.cs | 33 +++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 src/QsCompiler/BondSchemas/V2/BondSchemaTranslator.cs diff --git a/src/QsCompiler/BondSchemas/V1/BondSchemaTranslator.cs b/src/QsCompiler/BondSchemas/V1/BondSchemaTranslator.cs index bb1d08cf6a..e5a80154ac 100644 --- a/src/QsCompiler/BondSchemas/V1/BondSchemaTranslator.cs +++ b/src/QsCompiler/BondSchemas/V1/BondSchemaTranslator.cs @@ -222,7 +222,7 @@ private static QsGeneratorDirective ToBondSchema(this SyntaxTokens.QsGeneratorDi _ => throw new ArgumentException($"Unsupported QsGeneratorDirective {qsGeneratorDirective}") }; - private static QsQualifiedName ToBondSchema(this SyntaxTree.QsQualifiedName qsQualifiedName) => + internal static QsQualifiedName ToBondSchema(this SyntaxTree.QsQualifiedName qsQualifiedName) => new QsQualifiedName { Namespace = qsQualifiedName.Namespace, @@ -273,7 +273,7 @@ private static QsNamespace ToBondSchema(this SyntaxTree.QsNamespace qsNamespace) Documentation = qsNamespace.Documentation.ToQsSourceFileDocumentationList() }; - private static QsNamespaceElement ToBondSchema(this SyntaxTree.QsNamespaceElement qsNamespaceElement) + internal static QsNamespaceElement ToBondSchema(this SyntaxTree.QsNamespaceElement qsNamespaceElement) { QsCallable? bondQsCallable = null; QsCustomType? bondQsCustomType = null; diff --git a/src/QsCompiler/BondSchemas/V2/BondSchemaTranslator.cs b/src/QsCompiler/BondSchemas/V2/BondSchemaTranslator.cs new file mode 100644 index 0000000000..c78b22d367 --- /dev/null +++ b/src/QsCompiler/BondSchemas/V2/BondSchemaTranslator.cs @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System.Linq; +using Microsoft.Quantum.QsCompiler.BondSchemas.V1; + +namespace Microsoft.Quantum.QsCompiler.BondSchemas.V2 +{ + /// + /// This class translates compiler objects to Bond schema objects. + /// + internal static class BondSchemaTranslator + { + /// + /// Creates a Bond schema QsCompilation object from a QsCompilation compiler object. + /// + public static QsCompilation CreateBondCompilation(SyntaxTree.QsCompilation qsCompilation) => + new QsCompilation + { + Namespaces = qsCompilation.Namespaces.Select(n => n.ToBondSchema()).ToList(), + EntryPoints = qsCompilation.EntryPoints.Select(e => e.ToBondSchema()).ToList() + }; + + public static QsNamespace ToBondSchema(this SyntaxTree.QsNamespace qsNamespace) => + new QsNamespace + { + Name = qsNamespace.Name, + Elements = qsNamespace.Elements.Select(e => e.ToBondSchema()).ToList(), + // TODO: Implement. + //Documentation = qsNamespace.Documentation.ToQsSourceFileDocumentationList() + }; + } +} From 9d95d540a3f92ae44c36289a3c000e76ebda13da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Zaragoza=20Cort=C3=A9s?= Date: Thu, 21 Jan 2021 18:37:28 -0800 Subject: [PATCH 05/17] Multiplexed deserialization implementation. --- src/QsCompiler/BondSchemas/Protocols.cs | 104 +++++++++++------- src/QsCompiler/BondSchemas/Translators.cs | 13 ++- .../V1/CompilerObjectTranslator.cs | 6 +- .../BondSchemas/V2/BondSchemaTranslator.cs | 3 +- .../V2/CompilerObjectTranslator.cs | 29 +++++ 5 files changed, 103 insertions(+), 52 deletions(-) create mode 100644 src/QsCompiler/BondSchemas/V2/CompilerObjectTranslator.cs diff --git a/src/QsCompiler/BondSchemas/Protocols.cs b/src/QsCompiler/BondSchemas/Protocols.cs index 55d60f400b..3cd908252d 100644 --- a/src/QsCompiler/BondSchemas/Protocols.cs +++ b/src/QsCompiler/BondSchemas/Protocols.cs @@ -2,7 +2,9 @@ // Licensed under the MIT License. using System; +using System.Collections.Generic; using System.IO; +using System.Linq; using System.Threading; using System.Threading.Tasks; using Bond; @@ -11,7 +13,7 @@ namespace Microsoft.Quantum.QsCompiler.BondSchemas { - using BondQsCompilation = V1.QsCompilation; + using BondQsCompilation = V2.QsCompilation; using SimpleBinaryDeserializer = Deserializer>; using SimpleBinarySerializer = Serializer>; @@ -20,7 +22,6 @@ namespace Microsoft.Quantum.QsCompiler.BondSchemas /// public static class Protocols { - // TODO: Document. public enum Option { @@ -31,8 +32,14 @@ public enum Option /// Provides thread-safe access to the members and methods of this class. /// private static readonly object BondSharedDataStructuresLock = new object(); - private static Task? simpleBinaryDeserializerInitialization = null; - private static Task? simpleBinarySerializerInitialization = null; + private static readonly IDictionary?> DeserializerInitializations = + new Dictionary?>() + { + { typeof(V1.QsCompilation), null }, + { typeof(BondQsCompilation), null } + }; + + private static Task? serializerInitialization = null; /// /// Deserializes a Q# compilation object from its Bond simple binary representation. @@ -42,16 +49,18 @@ public enum Option // TODO: Extend to receive options. public static SyntaxTree.QsCompilation? DeserializeQsCompilationFromSimpleBinary( byte[] byteArray, - Type bondType, + Type bondSchemaType, Option[]? options = null) { - BondQsCompilation? bondCompilation = null; + object? bondCompilation = null; var inputBuffer = new InputBuffer(byteArray); var reader = new SimpleBinaryReader(inputBuffer); lock (BondSharedDataStructuresLock) { - var deserializer = GetSimpleBinaryDeserializer(); - bondCompilation = deserializer.Deserialize(reader); + //var deserializer = GetSimpleBinaryDeserializer(bondSchemaType); + //bondCompilation = deserializer.Deserialize(reader); + bondCompilation = DeserializeBondSchemaFromSimpleBinary(reader, bondSchemaType); + Console.WriteLine($"Deserialized: {bondSchemaType}"); } return Translators.FromBondSchemaToSyntaxTree(bondCompilation); @@ -65,7 +74,7 @@ public static void Initialize() { lock (BondSharedDataStructuresLock) { - _ = TryInitializeDeserializer(); + TryInitializeDeserializers(); _ = TryInitializeSerializer(); } } @@ -78,7 +87,7 @@ public static void InitializeDeserializer() { lock (BondSharedDataStructuresLock) { - _ = TryInitializeDeserializer(); + TryInitializeDeserializers(); } } @@ -118,32 +127,29 @@ public static void SerializeQsCompilationToSimpleBinary( stream.Position = 0; } - private static SimpleBinaryDeserializer GetSimpleBinaryDeserializer() + private static object DeserializeBondSchemaFromSimpleBinary( + SimpleBinaryReader reader, + Type bondSchemaType) { - VerifyLockAcquired(BondSharedDataStructuresLock); - if (simpleBinaryDeserializerInitialization == null) + var deserializer = GetSimpleBinaryDeserializer(bondSchemaType); + if (bondSchemaType == typeof(V1.QsCompilation)) + { + return deserializer.Deserialize(reader); + } + else if (bondSchemaType == typeof(BondQsCompilation)) { - simpleBinaryDeserializerInitialization = QueueSimpleBinaryDeserializerInitialization(); + return deserializer.Deserialize(reader); } - simpleBinaryDeserializerInitialization.Wait(); - return simpleBinaryDeserializerInitialization.Result; + // TODO: Use specific message. + throw new ArgumentException(); } - private static SimpleBinaryDeserializer GetSimpleBinaryDeserializer(Type type) + private static SimpleBinaryDeserializer GetSimpleBinaryDeserializer(Type bondSchemaType) { VerifyLockAcquired(BondSharedDataStructuresLock); - Task deserializerInitialization; - if (type == typeof(BondQsCompilation)) - { - deserializerInitialization = TryInitializeDeserializer(); - } - else - { - // TODO: Add a meaningful message. - throw new ArgumentException(); - } - + Console.WriteLine($"GetSimpleBinaryDeserializer: {bondSchemaType}"); + var deserializerInitialization = TryInitializeDeserializer(bondSchemaType); deserializerInitialization.Wait(); return deserializerInitialization.Result; } @@ -151,24 +157,23 @@ private static SimpleBinaryDeserializer GetSimpleBinaryDeserializer(Type type) private static SimpleBinarySerializer GetSimpleBinarySerializer() { VerifyLockAcquired(BondSharedDataStructuresLock); - if (simpleBinarySerializerInitialization == null) + if (serializerInitialization == null) { - simpleBinarySerializerInitialization = QueueSimpleBinarySerializerInitialization(); + serializerInitialization = QueueSimpleBinarySerializerInitialization(); } - simpleBinarySerializerInitialization.Wait(); - return simpleBinarySerializerInitialization.Result; + serializerInitialization.Wait(); + return serializerInitialization.Result; } - private static Task QueueSimpleBinaryDeserializerInitialization() + private static Task QueueSimpleBinaryDeserializerInitialization(Type deserializerType) { VerifyLockAcquired(BondSharedDataStructuresLock); - // TODO: Maybe use this method to initialize everything by iterating through a dictionary. // inlineNested is false in order to decrease the time needed to initialize the deserializer. // While this setting may also increase deserialization time, we did not notice any performance drawbacks with our Bond schemas. return Task.Run(() => new SimpleBinaryDeserializer( - type: typeof(BondQsCompilation), + type: deserializerType, factory: (Factory?)null, inlineNested: false)); } @@ -179,26 +184,41 @@ private static Task QueueSimpleBinarySerializerInitializ return Task.Run(() => new SimpleBinarySerializer(typeof(BondQsCompilation))); } - private static Task TryInitializeDeserializer() + private static Task TryInitializeDeserializer(Type bondSchemaType) { VerifyLockAcquired(BondSharedDataStructuresLock); - if (simpleBinaryDeserializerInitialization == null) + if (!DeserializerInitializations.TryGetValue(bondSchemaType, out var deserializerInitialization)) + { + // TODO: Use the correct message. + throw new ArgumentException(); + } + + if (deserializerInitialization == null) { - simpleBinaryDeserializerInitialization = QueueSimpleBinaryDeserializerInitialization(); + deserializerInitialization = QueueSimpleBinaryDeserializerInitialization(bondSchemaType); + DeserializerInitializations[bondSchemaType] = deserializerInitialization; } - return simpleBinaryDeserializerInitialization; + return deserializerInitialization; + } + + private static void TryInitializeDeserializers() + { + foreach (var bondSchemaType in DeserializerInitializations.Keys.ToList()) + { + _ = TryInitializeDeserializer(bondSchemaType); + } } private static Task TryInitializeSerializer() { VerifyLockAcquired(BondSharedDataStructuresLock); - if (simpleBinarySerializerInitialization == null) + if (serializerInitialization == null) { - simpleBinarySerializerInitialization = QueueSimpleBinarySerializerInitialization(); + serializerInitialization = QueueSimpleBinarySerializerInitialization(); } - return simpleBinarySerializerInitialization; + return serializerInitialization; } private static void VerifyLockAcquired(object lockObject) diff --git a/src/QsCompiler/BondSchemas/Translators.cs b/src/QsCompiler/BondSchemas/Translators.cs index 19d5060d94..1a0ebb3d2a 100644 --- a/src/QsCompiler/BondSchemas/Translators.cs +++ b/src/QsCompiler/BondSchemas/Translators.cs @@ -5,7 +5,7 @@ namespace Microsoft.Quantum.QsCompiler.BondSchemas { - using CurrentBondQsCompilation = V1.QsCompilation; + using BondQsCompilation = V2.QsCompilation; internal static class Translators { @@ -13,8 +13,11 @@ public static SyntaxTree.QsCompilation FromBondSchemaToSyntaxTree(TBond b { switch (bondCompilation) { - case V1.QsCompilation bondCompilationV01: - return V1.CompilerObjectTranslator.CreateQsCompilation(bondCompilationV01); + case V1.QsCompilation bondCompilationV1: + return V1.CompilerObjectTranslator.CreateQsCompilation(bondCompilationV1); + + case BondQsCompilation bondCompilationV2: + return V2.CompilerObjectTranslator.CreateQsCompilation(bondCompilationV2); default: // TODO: Use a more meaningful message. @@ -22,7 +25,7 @@ public static SyntaxTree.QsCompilation FromBondSchemaToSyntaxTree(TBond b } } - public static CurrentBondQsCompilation FromSyntaxTreeToBondSchema(SyntaxTree.QsCompilation qsCompilation) => - V1.BondSchemaTranslator.CreateBondCompilation(qsCompilation); + public static BondQsCompilation FromSyntaxTreeToBondSchema(SyntaxTree.QsCompilation qsCompilation) => + V2.BondSchemaTranslator.CreateBondCompilation(qsCompilation); } } diff --git a/src/QsCompiler/BondSchemas/V1/CompilerObjectTranslator.cs b/src/QsCompiler/BondSchemas/V1/CompilerObjectTranslator.cs index b2d762980e..f8cc728563 100644 --- a/src/QsCompiler/BondSchemas/V1/CompilerObjectTranslator.cs +++ b/src/QsCompiler/BondSchemas/V1/CompilerObjectTranslator.cs @@ -323,7 +323,7 @@ private static SyntaxTree.QsLocation ToCompilerObject(this QsLocation bondQsLoca offset: bondQsLocation.Offset.ToCompilerObject(), range: bondQsLocation.Range.ToCompilerObject()); - private static SyntaxTree.QsNamespace ToCompilerObject(this QsNamespace bondQsNamespace) => + public static SyntaxTree.QsNamespace ToCompilerObject(this QsNamespace bondQsNamespace) => new SyntaxTree.QsNamespace( name: bondQsNamespace.Name, elements: bondQsNamespace.Elements.Select(e => e.ToCompilerObject()).ToImmutableArray(), @@ -331,7 +331,7 @@ private static SyntaxTree.QsNamespace ToCompilerObject(this QsNamespace bondQsNa p => p.FileName, p => p.DocumentationItems.ToImmutableArray())); - private static SyntaxTree.QsNamespaceElement ToCompilerObject(this QsNamespaceElement bondQsNamespaceElement) + public static SyntaxTree.QsNamespaceElement ToCompilerObject(this QsNamespaceElement bondQsNamespaceElement) { string UnexpectedNullFieldMessage(string fieldName) => $"Bond QsNamespaceElement '{fieldName}' field is null when Kind is '{bondQsNamespaceElement.Kind}'"; @@ -366,7 +366,7 @@ private static SyntaxTree.QsPositionedBlock ToCompilerObject(this QsPositionedBl QsNullable.Null, comments: bondQsPositionedBlock.Comments.ToCompilerObject()); - private static SyntaxTree.QsQualifiedName ToCompilerObject(this QsQualifiedName bondQsQualifiedName) => + public static SyntaxTree.QsQualifiedName ToCompilerObject(this QsQualifiedName bondQsQualifiedName) => new SyntaxTree.QsQualifiedName( @namespace: bondQsQualifiedName.Namespace, name: bondQsQualifiedName.Name); diff --git a/src/QsCompiler/BondSchemas/V2/BondSchemaTranslator.cs b/src/QsCompiler/BondSchemas/V2/BondSchemaTranslator.cs index c78b22d367..70d405af7a 100644 --- a/src/QsCompiler/BondSchemas/V2/BondSchemaTranslator.cs +++ b/src/QsCompiler/BondSchemas/V2/BondSchemaTranslator.cs @@ -26,8 +26,7 @@ public static QsNamespace ToBondSchema(this SyntaxTree.QsNamespace qsNamespace) { Name = qsNamespace.Name, Elements = qsNamespace.Elements.Select(e => e.ToBondSchema()).ToList(), - // TODO: Implement. - //Documentation = qsNamespace.Documentation.ToQsSourceFileDocumentationList() + // TODO: Implement Documentation. }; } } diff --git a/src/QsCompiler/BondSchemas/V2/CompilerObjectTranslator.cs b/src/QsCompiler/BondSchemas/V2/CompilerObjectTranslator.cs new file mode 100644 index 0000000000..9a6fa01193 --- /dev/null +++ b/src/QsCompiler/BondSchemas/V2/CompilerObjectTranslator.cs @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System.Collections.Immutable; +using System.Linq; +using Microsoft.Quantum.QsCompiler.BondSchemas.V1; + +namespace Microsoft.Quantum.QsCompiler.BondSchemas.V2 +{ + internal static class CompilerObjectTranslator + { + + /// + /// Creates a C# QsCompilation compiler object from a Bond schema QsCompilation object. + /// + /// // + public static SyntaxTree.QsCompilation CreateQsCompilation(QsCompilation bondCompilation) => + new SyntaxTree.QsCompilation( + namespaces: bondCompilation.Namespaces.Select(n => n.ToCompilerObject()).ToImmutableArray(), + entryPoints: bondCompilation.EntryPoints.Select(e => e.ToCompilerObject()).ToImmutableArray()); + + public static SyntaxTree.QsNamespace ToCompilerObject(this QsNamespace bondQsNamespace) => + new SyntaxTree.QsNamespace( + name: bondQsNamespace.Name, + elements: bondQsNamespace.Elements.Select(e => e.ToCompilerObject()).ToImmutableArray(), + // TODO: Implement. + documentation: default); + } +} From 90a2568e0e86247153307ee552a1abe53a2b8fe2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Zaragoza=20Cort=C3=A9s?= Date: Fri, 22 Jan 2021 21:01:14 -0800 Subject: [PATCH 06/17] Change method scope to internal. --- .../BondSchemas/V1/BondSchemaTranslator.cs | 144 +++++++-------- .../V1/CompilerObjectTranslator.cs | 174 +++++++----------- .../BondSchemas/V2/BondSchemaTranslator.cs | 2 +- .../V2/CompilerObjectTranslator.cs | 2 +- 4 files changed, 144 insertions(+), 178 deletions(-) diff --git a/src/QsCompiler/BondSchemas/V1/BondSchemaTranslator.cs b/src/QsCompiler/BondSchemas/V1/BondSchemaTranslator.cs index e5a80154ac..89d3ef3904 100644 --- a/src/QsCompiler/BondSchemas/V1/BondSchemaTranslator.cs +++ b/src/QsCompiler/BondSchemas/V1/BondSchemaTranslator.cs @@ -24,7 +24,7 @@ public static QsCompilation CreateBondCompilation(SyntaxTree.QsCompilation qsCom EntryPoints = qsCompilation.EntryPoints.Select(e => e.ToBondSchema()).ToList() }; - private static AccessModifier ToBondSchema(this SyntaxTokens.AccessModifier accessModifier) => + internal static AccessModifier ToBondSchema(this SyntaxTokens.AccessModifier accessModifier) => accessModifier.Tag switch { SyntaxTokens.AccessModifier.Tags.DefaultAccess => AccessModifier.DefaultAccess, @@ -32,14 +32,14 @@ private static AccessModifier ToBondSchema(this SyntaxTokens.AccessModifier acce _ => throw new ArgumentException($"Unsupported AccessModifier: {accessModifier}") }; - private static CallableInformation ToBondSchema(this SyntaxTree.CallableInformation callableInformation) => + internal static CallableInformation ToBondSchema(this SyntaxTree.CallableInformation callableInformation) => new CallableInformation { Characteristics = callableInformation.Characteristics.ToBondSchema(), InferredInformation = callableInformation.InferredInformation.ToBondSchema() }; - private static Identifier ToBondSchema(this SyntaxTree.Identifier identifier) + internal static Identifier ToBondSchema(this SyntaxTree.Identifier identifier) { string? bondLocalVariable = null; QsQualifiedName? bondGlobalCallable = null; @@ -71,33 +71,33 @@ private static Identifier ToBondSchema(this SyntaxTree.Identifier identifier) }; } - private static InferredCallableInformation ToBondSchema(this SyntaxTree.InferredCallableInformation inferredCallableInformation) => + internal static InferredCallableInformation ToBondSchema(this SyntaxTree.InferredCallableInformation inferredCallableInformation) => new InferredCallableInformation { IsSelfAdjoint = inferredCallableInformation.IsSelfAdjoint, IsIntrinsic = inferredCallableInformation.IsIntrinsic }; - private static InferredExpressionInformation ToBondSchema(this SyntaxTree.InferredExpressionInformation inferredExpressionInformation) => + internal static InferredExpressionInformation ToBondSchema(this SyntaxTree.InferredExpressionInformation inferredExpressionInformation) => new InferredExpressionInformation { IsMutable = inferredExpressionInformation.IsMutable, HasLocalQuantumDependency = inferredExpressionInformation.HasLocalQuantumDependency }; - private static LocalDeclarations ToBondSchema(this SyntaxTree.LocalDeclarations localDeclarations) => + internal static LocalDeclarations ToBondSchema(this SyntaxTree.LocalDeclarations localDeclarations) => new LocalDeclarations { Variables = localDeclarations.Variables.Select(v => v.ToBondSchemaGeneric(typeTranslator: s => s)).ToList() }; - private static Modifiers ToBondSchema(this SyntaxTokens.Modifiers modifiers) => + internal static Modifiers ToBondSchema(this SyntaxTokens.Modifiers modifiers) => new Modifiers { Access = modifiers.Access.ToBondSchema() }; - private static OpProperty ToBondSchema(this SyntaxTokens.OpProperty opProperty) => + internal static OpProperty ToBondSchema(this SyntaxTokens.OpProperty opProperty) => opProperty.Tag switch { SyntaxTokens.OpProperty.Tags.Adjointable => OpProperty.Adjointable, @@ -105,14 +105,14 @@ private static OpProperty ToBondSchema(this SyntaxTokens.OpProperty opProperty) _ => throw new ArgumentException($"Unsupported OpProperty {opProperty}") }; - private static Position ToBondSchema(this DataTypes.Position position) => + internal static Position ToBondSchema(this DataTypes.Position position) => new Position { Line = position.Line, Column = position.Column }; - private static QsBindingKind ToBondSchema(this SyntaxTree.QsBindingKind qsBindingKind) => + internal static QsBindingKind ToBondSchema(this SyntaxTree.QsBindingKind qsBindingKind) => qsBindingKind.Tag switch { SyntaxTree.QsBindingKind.Tags.ImmutableBinding => QsBindingKind.ImmutableBinding, @@ -120,7 +120,7 @@ private static QsBindingKind ToBondSchema(this SyntaxTree.QsBindingKind qsBindin _ => throw new ArgumentException($"Unsupported QsBindingKind {qsBindingKind}") }; - private static QsCallable ToBondSchema(this SyntaxTree.QsCallable qsCallable) => + internal static QsCallable ToBondSchema(this SyntaxTree.QsCallable qsCallable) => new QsCallable { Kind = qsCallable.Kind.ToBondSchema(), @@ -138,7 +138,7 @@ private static QsCallable ToBondSchema(this SyntaxTree.QsCallable qsCallable) => Comments = qsCallable.Comments.ToBondSchema() }; - private static QsCallableKind ToBondSchema(this SyntaxTree.QsCallableKind qsCallableKind) => + internal static QsCallableKind ToBondSchema(this SyntaxTree.QsCallableKind qsCallableKind) => qsCallableKind.Tag switch { SyntaxTree.QsCallableKind.Tags.Function => QsCallableKind.Function, @@ -147,14 +147,14 @@ private static QsCallableKind ToBondSchema(this SyntaxTree.QsCallableKind qsCall _ => throw new ArgumentException($"Unsupported QsCallableKind {qsCallableKind}") }; - private static QsComments ToBondSchema(this SyntaxTree.QsComments qsComments) => + internal static QsComments ToBondSchema(this SyntaxTree.QsComments qsComments) => new QsComments { OpeningComments = qsComments.OpeningComments.ToList(), ClosingComments = qsComments.ClosingComments.ToList() }; - private static QsConditionalStatement ToBondSchema(this SyntaxTree.QsConditionalStatement qsConditionalStatement) => + internal static QsConditionalStatement ToBondSchema(this SyntaxTree.QsConditionalStatement qsConditionalStatement) => new QsConditionalStatement { ConditionalBlocks = qsConditionalStatement.ConditionalBlocks.Select(c => c.ToQsConditionalBlock()).ToList(), @@ -163,14 +163,14 @@ private static QsConditionalStatement ToBondSchema(this SyntaxTree.QsConditional qsConditionalStatement.Default.Item.ToBondSchema() }; - private static QsConjugation ToBondSchema(this SyntaxTree.QsConjugation qsConjugation) => + internal static QsConjugation ToBondSchema(this SyntaxTree.QsConjugation qsConjugation) => new QsConjugation { OuterTransformation = qsConjugation.OuterTransformation.ToBondSchema(), InnerTransformation = qsConjugation.InnerTransformation.ToBondSchema() }; - private static QsCustomType ToBondSchema(this SyntaxTree.QsCustomType qsCustomType) => + internal static QsCustomType ToBondSchema(this SyntaxTree.QsCustomType qsCustomType) => new QsCustomType { FullName = qsCustomType.FullName.ToBondSchema(), @@ -186,7 +186,7 @@ private static QsCustomType ToBondSchema(this SyntaxTree.QsCustomType qsCustomTy Comments = qsCustomType.Comments.ToBondSchema() }; - private static QsDeclarationAttribute ToBondSchema(this SyntaxTree.QsDeclarationAttribute qsDeclarationAttribute) => + internal static QsDeclarationAttribute ToBondSchema(this SyntaxTree.QsDeclarationAttribute qsDeclarationAttribute) => new QsDeclarationAttribute { TypeId = qsDeclarationAttribute.TypeId.IsNull ? @@ -197,14 +197,14 @@ private static QsDeclarationAttribute ToBondSchema(this SyntaxTree.QsDeclaration Comments = qsDeclarationAttribute.Comments.ToBondSchema() }; - private static QsExpressionKindComposition ToBondSchema( + internal static QsExpressionKindComposition ToBondSchema( this SyntaxTokens.QsExpressionKind qsExpressionKind) => qsExpressionKind.ToBondSchemaGeneric( expressionTranslator: ToBondSchema, symbolTranslator: ToBondSchema, typeTranslator: ToBondSchema); - private static QsForStatement ToBondSchema(this SyntaxTree.QsForStatement qsForStatement) => + internal static QsForStatement ToBondSchema(this SyntaxTree.QsForStatement qsForStatement) => new QsForStatement { LoopItem = qsForStatement.LoopItem.ToQsLoopItem(), @@ -212,7 +212,7 @@ private static QsForStatement ToBondSchema(this SyntaxTree.QsForStatement qsForS Body = qsForStatement.Body.ToBondSchema() }; - private static QsGeneratorDirective ToBondSchema(this SyntaxTokens.QsGeneratorDirective qsGeneratorDirective) => + internal static QsGeneratorDirective ToBondSchema(this SyntaxTokens.QsGeneratorDirective qsGeneratorDirective) => qsGeneratorDirective.Tag switch { SyntaxTokens.QsGeneratorDirective.Tags.Distribute => QsGeneratorDirective.Distribute, @@ -229,7 +229,7 @@ internal static QsQualifiedName ToBondSchema(this SyntaxTree.QsQualifiedName qsQ Name = qsQualifiedName.Name }; - private static QsLocalSymbol ToBondSchema(this SyntaxTree.QsLocalSymbol qsLocalSymbol) + internal static QsLocalSymbol ToBondSchema(this SyntaxTree.QsLocalSymbol qsLocalSymbol) { string? bondValidName = null; QsLocalSymbolKind kind; @@ -254,18 +254,18 @@ private static QsLocalSymbol ToBondSchema(this SyntaxTree.QsLocalSymbol qsLocalS }; } - private static LocalVariableDeclaration ToBondSchema( + internal static LocalVariableDeclaration ToBondSchema( this SyntaxTree.LocalVariableDeclaration localVariableDeclaration) => localVariableDeclaration.ToBondSchemaGeneric(typeTranslator: ToBondSchema); - private static QsLocation ToBondSchema(this SyntaxTree.QsLocation qsLocation) => + internal static QsLocation ToBondSchema(this SyntaxTree.QsLocation qsLocation) => new QsLocation { Offset = qsLocation.Offset.ToBondSchema(), Range = qsLocation.Range.ToBondSchema() }; - private static QsNamespace ToBondSchema(this SyntaxTree.QsNamespace qsNamespace) => + internal static QsNamespace ToBondSchema(this SyntaxTree.QsNamespace qsNamespace) => new QsNamespace { Name = qsNamespace.Name, @@ -303,7 +303,7 @@ internal static QsNamespaceElement ToBondSchema(this SyntaxTree.QsNamespaceEleme return bondQsNamespaceElement; } - private static QsPauli ToBondSchema(this SyntaxTokens.QsPauli qsPauli) => + internal static QsPauli ToBondSchema(this SyntaxTokens.QsPauli qsPauli) => qsPauli.Tag switch { SyntaxTokens.QsPauli.Tags.PauliI => QsPauli.PauliI, @@ -313,7 +313,7 @@ private static QsPauli ToBondSchema(this SyntaxTokens.QsPauli qsPauli) => _ => throw new ArgumentException($"Unsupported ") }; - private static QsPositionedBlock ToBondSchema(this SyntaxTree.QsPositionedBlock qsPositionedBlock) => + internal static QsPositionedBlock ToBondSchema(this SyntaxTree.QsPositionedBlock qsPositionedBlock) => new QsPositionedBlock { Body = qsPositionedBlock.Body.ToBondSchema(), @@ -323,7 +323,7 @@ private static QsPositionedBlock ToBondSchema(this SyntaxTree.QsPositionedBlock Comments = qsPositionedBlock.Comments.ToBondSchema() }; - private static QsQubitScope ToBondSchema(this SyntaxTree.QsQubitScope qsQubitScope) => + internal static QsQubitScope ToBondSchema(this SyntaxTree.QsQubitScope qsQubitScope) => new QsQubitScope { Kind = qsQubitScope.Kind.ToBondSchema(), @@ -331,7 +331,7 @@ private static QsQubitScope ToBondSchema(this SyntaxTree.QsQubitScope qsQubitSco Body = qsQubitScope.Body.ToBondSchema() }; - private static QsQubitScopeKind ToBondSchema(this SyntaxTree.QsQubitScopeKind qsQubitScopeKind) => + internal static QsQubitScopeKind ToBondSchema(this SyntaxTree.QsQubitScopeKind qsQubitScopeKind) => qsQubitScopeKind.Tag switch { SyntaxTree.QsQubitScopeKind.Tags.Allocate => QsQubitScopeKind.Allocate, @@ -339,7 +339,7 @@ private static QsQubitScopeKind ToBondSchema(this SyntaxTree.QsQubitScopeKind qs _ => throw new ArgumentException($"Unsupported QsQubitScopeKind {qsQubitScopeKind}") }; - private static QsRepeatStatement ToBondSchema(this SyntaxTree.QsRepeatStatement qsRepeatStatement) => + internal static QsRepeatStatement ToBondSchema(this SyntaxTree.QsRepeatStatement qsRepeatStatement) => new QsRepeatStatement { RepeatBlock = qsRepeatStatement.RepeatBlock.ToBondSchema(), @@ -347,7 +347,7 @@ private static QsRepeatStatement ToBondSchema(this SyntaxTree.QsRepeatStatement FixupBlock = qsRepeatStatement.FixupBlock.ToBondSchema() }; - private static QsResult ToBondSchema(this SyntaxTokens.QsResult qsResult) => + internal static QsResult ToBondSchema(this SyntaxTokens.QsResult qsResult) => qsResult.Tag switch { SyntaxTokens.QsResult.Tags.Zero => QsResult.Zero, @@ -355,14 +355,14 @@ private static QsResult ToBondSchema(this SyntaxTokens.QsResult qsResult) => _ => throw new ArgumentException($"Unsupported QsResult {qsResult}") }; - private static QsScope ToBondSchema(this SyntaxTree.QsScope qsScope) => + internal static QsScope ToBondSchema(this SyntaxTree.QsScope qsScope) => new QsScope { Statements = qsScope.Statements.Select(s => s.ToBondSchema()).ToList(), KnownSymbols = qsScope.KnownSymbols.ToBondSchema() }; - private static QsSpecialization ToBondSchema(this SyntaxTree.QsSpecialization qsSpecialization) => + internal static QsSpecialization ToBondSchema(this SyntaxTree.QsSpecialization qsSpecialization) => new QsSpecialization { Kind = qsSpecialization.Kind.ToBondSchema(), @@ -381,7 +381,7 @@ private static QsSpecialization ToBondSchema(this SyntaxTree.QsSpecialization qs Comments = qsSpecialization.Comments.ToBondSchema() }; - private static QsSpecializationKind ToBondSchema(this SyntaxTree.QsSpecializationKind qsSpecializationKind) => + internal static QsSpecializationKind ToBondSchema(this SyntaxTree.QsSpecializationKind qsSpecializationKind) => qsSpecializationKind.Tag switch { SyntaxTree.QsSpecializationKind.Tags.QsAdjoint => QsSpecializationKind.QsAdjoint, @@ -391,7 +391,7 @@ private static QsSpecializationKind ToBondSchema(this SyntaxTree.QsSpecializatio _ => throw new ArgumentException($"Unsupported QsSpecializationKind {qsSpecializationKind}") }; - private static QsStatement ToBondSchema(this SyntaxTree.QsStatement qsStatement) => + internal static QsStatement ToBondSchema(this SyntaxTree.QsStatement qsStatement) => new QsStatement { Statement = qsStatement.Statement.ToBondSchema(), @@ -402,7 +402,7 @@ private static QsStatement ToBondSchema(this SyntaxTree.QsStatement qsStatement) Comments = qsStatement.Comments.ToBondSchema() }; - private static QsStatementKindComposition ToBondSchema(this SyntaxTree.QsStatementKind qsStatementKind) + internal static QsStatementKindComposition ToBondSchema(this SyntaxTree.QsStatementKind qsStatementKind) { TypedExpression? bondTypedExpression = null; QsBinding? bondVariableDeclaration = null; @@ -493,15 +493,15 @@ private static QsStatementKindComposition ToBondSchema(this SyntaxTree.QsStateme }; } - private static QsTuple> ToBondSchema( + internal static QsTuple> ToBondSchema( this SyntaxTokens.QsTuple> localVariableDeclaration) => localVariableDeclaration.ToBondSchemaGeneric(typeTranslator: ToBondSchema); - private static QsTuple ToBondSchema( + internal static QsTuple ToBondSchema( this SyntaxTokens.QsTuple qsTypeItem) => qsTypeItem.ToBondSchemaGeneric(typeTranslator: ToBondSchema); - private static QsTypeKindComposition ToBondSchema( + internal static QsTypeKindComposition ToBondSchema( this SyntaxTokens.QsTypeKind qsTypeKind) => qsTypeKind.ToBondSchemaGeneric( dataTranslator: ToBondSchema, @@ -509,7 +509,7 @@ private static QsTypeKindComposition? bondNamed = null; @@ -537,7 +537,7 @@ private static QsTypeItem ToBondSchema(this SyntaxTree.QsTypeItem qsTypeItem) }; } - private static QsTypeParameter ToBondSchema(this SyntaxTree.QsTypeParameter qsTypeParameter) => + internal static QsTypeParameter ToBondSchema(this SyntaxTree.QsTypeParameter qsTypeParameter) => new QsTypeParameter { Origin = qsTypeParameter.Origin.ToBondSchema(), @@ -547,34 +547,34 @@ private static QsTypeParameter ToBondSchema(this SyntaxTree.QsTypeParameter qsTy qsTypeParameter.Range.Item.ToBondSchema() }; - private static QsValueUpdate ToBondSchema(this SyntaxTree.QsValueUpdate valueUpdate) => + internal static QsValueUpdate ToBondSchema(this SyntaxTree.QsValueUpdate valueUpdate) => new QsValueUpdate { Lhs = valueUpdate.Lhs.ToBondSchema(), Rhs = valueUpdate.Rhs.ToBondSchema() }; - private static QsWhileStatement ToBondSchema(this SyntaxTree.QsWhileStatement qsWhileStatement) => + internal static QsWhileStatement ToBondSchema(this SyntaxTree.QsWhileStatement qsWhileStatement) => new QsWhileStatement { Condition = qsWhileStatement.Condition.ToBondSchema(), Body = qsWhileStatement.Body.ToBondSchema() }; - private static Range ToBondSchema(this DataTypes.Range range) => + internal static Range ToBondSchema(this DataTypes.Range range) => new Range { Start = range.Start.ToBondSchema(), End = range.End.ToBondSchema() }; - private static ResolvedCharacteristics ToBondSchema(this SyntaxTree.ResolvedCharacteristics resolvedCharacteristics) => + internal static ResolvedCharacteristics ToBondSchema(this SyntaxTree.ResolvedCharacteristics resolvedCharacteristics) => new ResolvedCharacteristics { Expression = resolvedCharacteristics.Expression.ToBondSchemaGeneric(typeTranslator: ToBondSchema) }; - private static ResolvedInitializer ToBondSchema(this SyntaxTree.ResolvedInitializer resolvedInitializer) => + internal static ResolvedInitializer ToBondSchema(this SyntaxTree.ResolvedInitializer resolvedInitializer) => new ResolvedInitializer { Initializer = resolvedInitializer.Resolution.ToBondSchemaGeneric( @@ -583,7 +583,7 @@ private static ResolvedInitializer ToBondSchema(this SyntaxTree.ResolvedInitiali ResolvedType = resolvedInitializer.Type.ToBondSchema() }; - private static ResolvedSignature ToBondSchema(this SyntaxTree.ResolvedSignature resolvedSignature) => + internal static ResolvedSignature ToBondSchema(this SyntaxTree.ResolvedSignature resolvedSignature) => new ResolvedSignature { TypeParameters = resolvedSignature.TypeParameters.Select(tp => tp.ToBondSchema()).ToList(), @@ -592,13 +592,13 @@ private static ResolvedSignature ToBondSchema(this SyntaxTree.ResolvedSignature Information = resolvedSignature.Information.ToBondSchema() }; - private static ResolvedType ToBondSchema(this SyntaxTree.ResolvedType resolvedType) => + internal static ResolvedType ToBondSchema(this SyntaxTree.ResolvedType resolvedType) => new ResolvedType { TypeKind = resolvedType.Resolution.ToBondSchema() }; - private static SpecializationImplementation ToBondSchema(this SyntaxTree.SpecializationImplementation specializationImplementation) + internal static SpecializationImplementation ToBondSchema(this SyntaxTree.SpecializationImplementation specializationImplementation) { QsGeneratorDirective? bondGenerated = null; SpecializationImplementationKindProvided? bondProvided = null; @@ -631,7 +631,7 @@ private static SpecializationImplementation ToBondSchema(this SyntaxTree.Special }; } - private static SymbolTuple ToBondSchema(this SyntaxTree.SymbolTuple symbolTuple) + internal static SymbolTuple ToBondSchema(this SyntaxTree.SymbolTuple symbolTuple) { string? bondVariableName = null; List? bondVariableNameTuple = null; @@ -664,7 +664,7 @@ private static SymbolTuple ToBondSchema(this SyntaxTree.SymbolTuple symbolTuple) }; } - private static TypedExpression ToBondSchema(this SyntaxTree.TypedExpression typedExpression) => + internal static TypedExpression ToBondSchema(this SyntaxTree.TypedExpression typedExpression) => new TypedExpression { Expression = typedExpression.Expression.ToBondSchema(), @@ -676,7 +676,7 @@ private static TypedExpression ToBondSchema(this SyntaxTree.TypedExpression type typedExpression.Range.Item.ToBondSchema() }; - private static UserDefinedType ToBondSchema(this SyntaxTree.UserDefinedType userDefinedType) => + internal static UserDefinedType ToBondSchema(this SyntaxTree.UserDefinedType userDefinedType) => new UserDefinedType { Namespace = userDefinedType.Namespace, @@ -686,7 +686,7 @@ private static UserDefinedType ToBondSchema(this SyntaxTree.UserDefinedType user userDefinedType.Range.Item.ToBondSchema() }; - private static CharacteristicsKindComposition ToBondSchemaGeneric( + internal static CharacteristicsKindComposition ToBondSchemaGeneric( this SyntaxTokens.CharacteristicsKind characteristicsKind, Func typeTranslator) where TBond : class @@ -734,7 +734,7 @@ private static CharacteristicsKindComposition ToBondSchemaGeneric ToBondSchemaGeneric( + internal static LocalVariableDeclaration ToBondSchemaGeneric( this SyntaxTree.LocalVariableDeclaration localVariableDeclaration, Func typeTranslator) => new LocalVariableDeclaration @@ -748,7 +748,7 @@ private static LocalVariableDeclaration ToBondSchemaGeneric ToBondSchemaGeneric( + internal static QsBinding ToBondSchemaGeneric( this SyntaxTree.QsBinding qsBinding, Func typeTranslator) => new QsBinding @@ -758,7 +758,7 @@ private static QsBinding ToBondSchemaGeneric( Rhs = typeTranslator(qsBinding.Rhs) }; - private static QsExpressionKindComposition ToBondSchemaGeneric< + internal static QsExpressionKindComposition ToBondSchemaGeneric< TBondExpression, TBondSymbol, TBondType, @@ -1121,7 +1121,7 @@ private static QsExpressionKindComposition ToBondSchemaGeneric< + internal static QsInitializerKindComposition ToBondSchemaGeneric< TBondInitializer, TBondExpression, TCompilerInitializer, @@ -1165,7 +1165,7 @@ private static QsInitializerKindComposition T }; } - private static QsTuple ToBondSchemaGeneric( + internal static QsTuple ToBondSchemaGeneric( this SyntaxTokens.QsTuple qsTuple, Func typeTranslator) where TBond : class @@ -1197,7 +1197,7 @@ private static QsTuple ToBondSchemaGeneric( }; } - private static QsTypeKindComposition ToBondSchemaGeneric + internal static QsTypeKindComposition ToBondSchemaGeneric ToCharacteristicsKindSetOperationGeneric( + internal static CharacteristicsKindSetOperation ToCharacteristicsKindSetOperationGeneric( TCompiler set1, TCompiler set2, Func typeTranslator) => @@ -1306,14 +1306,14 @@ private static CharacteristicsKindSetOperation ToCharacteristicsKindSetOp Set2 = typeTranslator(set2) }; - private static QsConditionalBlock ToQsConditionalBlock(this Tuple qsConditionalBlock) => + internal static QsConditionalBlock ToQsConditionalBlock(this Tuple qsConditionalBlock) => new QsConditionalBlock { Expression = qsConditionalBlock.Item1.ToBondSchema(), Block = qsConditionalBlock.Item2.ToBondSchema() }; - private static QsExpressionKindExpressionDouble ToQsExpressionKindExpressionDoubleGeneric( + internal static QsExpressionKindExpressionDouble ToQsExpressionKindExpressionDoubleGeneric( TCompiler expression1, TCompiler expression2, Func typeTranslator) => @@ -1323,7 +1323,7 @@ private static QsExpressionKindExpressionDouble ToQsExpressionKindExpress Expression2 = typeTranslator(expression2) }; - private static QsExpressionKindExpressionTriple ToQsExpressionKindExpressionTripleGeneric( + internal static QsExpressionKindExpressionTriple ToQsExpressionKindExpressionTripleGeneric( TCompiler expression1, TCompiler expression2, TCompiler expression3, @@ -1335,7 +1335,7 @@ private static QsExpressionKindExpressionTriple ToQsExpressionKindExpress Expression3 = typeTranslator(expression3) }; - private static QsExpressionKindIdentifier ToQsExpressionKindIdentifierGeneric< + internal static QsExpressionKindIdentifier ToQsExpressionKindIdentifierGeneric< TBondSymbol, TBondType, TCompilerSymbol, @@ -1350,7 +1350,7 @@ private static QsExpressionKindIdentifier ToQsExpression Types = types.IsNull ? null : types.Item.Select(t => typeTranslator(t)).ToList() }; - private static QsExpressionKindNamedItem ToQsExpressionKindNamedItemGeneric< + internal static QsExpressionKindNamedItem ToQsExpressionKindNamedItemGeneric< TBondExpression, TBondSymbol, TCompilerExpression, @@ -1365,7 +1365,7 @@ private static QsExpressionKindNamedItem ToQsExpre Symbol = symbolTranslator(symbol) }; - private static QsExpressionKindNewArray ToQsExpressionKindNewArrayGeneric< + internal static QsExpressionKindNewArray ToQsExpressionKindNewArrayGeneric< TBondExpression, TBondType, TCompilerExpression, @@ -1380,7 +1380,7 @@ private static QsExpressionKindNewArray ToQsExpressi Expression = expressionTranslator(expression) }; - private static QsExpressionKindStringLiteral ToQsExpressionKindStringLiteralGeneric( + internal static QsExpressionKindStringLiteral ToQsExpressionKindStringLiteralGeneric( string stringLiteral, ImmutableArray expressions, Func typeTranslator) => @@ -1390,14 +1390,14 @@ private static QsExpressionKindStringLiteral ToQsExpressionKindStringLite Expressions = expressions.Select(e => typeTranslator(e)).ToList() }; - private static QsLoopItem ToQsLoopItem(this Tuple loopItem) => + internal static QsLoopItem ToQsLoopItem(this Tuple loopItem) => new QsLoopItem { SymbolTuple = loopItem.Item1.ToBondSchema(), ResolvedType = loopItem.Item2.ToBondSchema() }; - private static LinkedList ToQsSourceFileDocumentationList( + internal static LinkedList ToQsSourceFileDocumentationList( this ILookup> qsDocumentation) { var documentationList = new LinkedList(); @@ -1418,7 +1418,7 @@ private static LinkedList ToQsSourceFileDocumentation return documentationList; } - private static QsTypeKindFunction ToQsTypeKindFunctionGeneric( + internal static QsTypeKindFunction ToQsTypeKindFunctionGeneric( TCompiler type1, TCompiler type2, Func typeTranslator) => @@ -1428,7 +1428,7 @@ private static QsTypeKindFunction ToQsTypeKindFunctionGeneric ToQsTypeKindOperationGeneric< + internal static QsTypeKindOperation ToQsTypeKindOperationGeneric< TBondType, TBondCharacteristics, TCompilerData, @@ -1444,7 +1444,7 @@ private static QsTypeKindOperation ToQsTypeKind Characteristics = characteristicsTranslator(charateristics) }; - private static SpecializationImplementationKindProvided ToSpecializationImplementationKindProvided( + internal static SpecializationImplementationKindProvided ToSpecializationImplementationKindProvided( SyntaxTokens.QsTuple> tuple, SyntaxTree.QsScope implementation) => new SpecializationImplementationKindProvided @@ -1453,7 +1453,7 @@ private static SpecializationImplementationKindProvided ToSpecializationImplemen Implementation = implementation.ToBondSchema() }; - private static TypedArgument ToTypedArgument( + internal static TypedArgument ToTypedArgument( this Tuple typedArgumet) => new TypedArgument { diff --git a/src/QsCompiler/BondSchemas/V1/CompilerObjectTranslator.cs b/src/QsCompiler/BondSchemas/V1/CompilerObjectTranslator.cs index f8cc728563..3154e1611d 100644 --- a/src/QsCompiler/BondSchemas/V1/CompilerObjectTranslator.cs +++ b/src/QsCompiler/BondSchemas/V1/CompilerObjectTranslator.cs @@ -23,57 +23,23 @@ public static SyntaxTree.QsCompilation CreateQsCompilation(QsCompilation bondCom namespaces: bondCompilation.Namespaces.Select(n => n.ToCompilerObject()).ToImmutableArray(), entryPoints: bondCompilation.EntryPoints.Select(e => e.ToCompilerObject()).ToImmutableArray()); - // TODO: Document. - public static SyntaxTree.QsCompilation CreateQsCompilation(TBond bondCompilation) - { - throw new NotImplementedException(); - /* - switch (bondCompilation) - { - case v01.QsCompilation bondCompilationV01: - return CreateQsCompilation(bondCompilationV01); - - case v02.QsCompilation bondCompilationV02: - return CreateQsCompilation(bondCompilationV02); - - default: - // TODO: Use a more meaningful message. - throw new ArgumentException(); - } - */ - } - - /* - private static SyntaxTree.QsCompilation CreateQsCompilation(v01.QsCompilation bondCompilation) - { - // TODO: Implement. - throw new NotImplementedException(); - } - - private static SyntaxTree.QsCompilation CreateQsCompilation(v02.QsCompilation bondCompilation) - { - // TODO: Implement. - throw new NotImplementedException(); - } - */ - - private static BigInteger ToBigInteger(this ArraySegment blob) => + internal static BigInteger ToBigInteger(this ArraySegment blob) => new BigInteger(blob); - private static Source ToSource(this string sourceFile) => + internal static Source ToSource(this string sourceFile) => new Source(sourceFile, QsNullable.Null); - private static DataTypes.Position ToCompilerObject(this Position position) => + internal static DataTypes.Position ToCompilerObject(this Position position) => DataTypes.Position.Create( line: position.Line, column: position.Column); - private static DataTypes.Range ToCompilerObject(this Range range) => + internal static DataTypes.Range ToCompilerObject(this Range range) => DataTypes.Range.Create( start: range.Start.ToCompilerObject(), end: range.End.ToCompilerObject()); - private static SyntaxTokens.AccessModifier ToCompilerObject(this AccessModifier bondAccessModifier) => + internal static SyntaxTokens.AccessModifier ToCompilerObject(this AccessModifier bondAccessModifier) => bondAccessModifier switch { AccessModifier.DefaultAccess => SyntaxTokens.AccessModifier.DefaultAccess, @@ -81,18 +47,18 @@ private static SyntaxTokens.AccessModifier ToCompilerObject(this AccessModifier _ => throw new ArgumentException($"Unsupported Bond AccessModifier '{bondAccessModifier}'") }; - private static SyntaxTokens.CharacteristicsKind ToCompilerObject( + internal static SyntaxTokens.CharacteristicsKind ToCompilerObject( this CharacteristicsKindComposition bondCharacteristicsKindComposition) => bondCharacteristicsKindComposition.ToCompilerObjectGeneric(typeTranslator: ToCompilerObject); - private static SyntaxTokens.QsExpressionKind ToCompilerObject( + internal static SyntaxTokens.QsExpressionKind ToCompilerObject( this QsExpressionKindComposition bondQsExpressionKindComposition) => bondQsExpressionKindComposition.ToCompilerObjectGeneric( expressionTranslator: ToCompilerObject, symbolTranslator: ToCompilerObject, typeTranslator: ToCompilerObject); - private static SyntaxTokens.QsGeneratorDirective ToCompilerObject(this QsGeneratorDirective bondQsGeneratorDirective) => + internal static SyntaxTokens.QsGeneratorDirective ToCompilerObject(this QsGeneratorDirective bondQsGeneratorDirective) => bondQsGeneratorDirective switch { QsGeneratorDirective.Distribute => SyntaxTokens.QsGeneratorDirective.Distribute, @@ -102,17 +68,17 @@ private static SyntaxTokens.QsGeneratorDirective ToCompilerObject(this QsGenerat _ => throw new ArgumentException($"Unsupported Bond QsGeneratorDirective '{bondQsGeneratorDirective}'") }; - private static SyntaxTokens.QsInitializerKind ToCompilerObject( + internal static SyntaxTokens.QsInitializerKind ToCompilerObject( this QsInitializerKindComposition bondQsInitializerKindComposition) => bondQsInitializerKindComposition.ToCompilerObjectGeneric( initializerTranslator: ToCompilerObject, expressionTranslator: ToCompilerObject); - private static SyntaxTokens.Modifiers ToCompilerObject(this Modifiers bondModifiers) => + internal static SyntaxTokens.Modifiers ToCompilerObject(this Modifiers bondModifiers) => new SyntaxTokens.Modifiers( access: bondModifiers.Access.ToCompilerObject()); - private static SyntaxTokens.OpProperty ToCompilerObject(this OpProperty bondOpProperty) => + internal static SyntaxTokens.OpProperty ToCompilerObject(this OpProperty bondOpProperty) => bondOpProperty switch { OpProperty.Adjointable => SyntaxTokens.OpProperty.Adjointable, @@ -120,7 +86,7 @@ private static SyntaxTokens.OpProperty ToCompilerObject(this OpProperty bondOpPr _ => throw new ArgumentException($"Unsupported Bond OpProperty '{bondOpProperty}'") }; - private static SyntaxTokens.QsPauli ToCompilerObject(this QsPauli bondQsPauli) => + internal static SyntaxTokens.QsPauli ToCompilerObject(this QsPauli bondQsPauli) => bondQsPauli switch { QsPauli.PauliI => SyntaxTokens.QsPauli.PauliI, @@ -130,7 +96,7 @@ private static SyntaxTokens.QsPauli ToCompilerObject(this QsPauli bondQsPauli) = _ => throw new ArgumentException($"Unsupported Bond QsPauli '{bondQsPauli}'") }; - private static SyntaxTokens.QsResult ToCompilerObject(this QsResult bondQsResult) => + internal static SyntaxTokens.QsResult ToCompilerObject(this QsResult bondQsResult) => bondQsResult switch { QsResult.Zero => SyntaxTokens.QsResult.Zero, @@ -138,15 +104,15 @@ private static SyntaxTokens.QsResult ToCompilerObject(this QsResult bondQsResult _ => throw new ArgumentException($"Unsupported Bond QsResult '{bondQsResult}'") }; - private static SyntaxTokens.QsTuple> ToCompilerObject( + internal static SyntaxTokens.QsTuple> ToCompilerObject( this QsTuple> bondQsTuple) => bondQsTuple.ToCompilerObjectGeneric(typeTranslator: ToCompilerObject); - private static SyntaxTokens.QsTuple ToCompilerObject( + internal static SyntaxTokens.QsTuple ToCompilerObject( this QsTuple bondQsTuple) => bondQsTuple.ToCompilerObjectGeneric(typeTranslator: ToCompilerObject); - private static SyntaxTokens.QsTypeKind ToCompilerObject( + internal static SyntaxTokens.QsTypeKind ToCompilerObject( this QsTypeKindComposition bondQsTypeKindComposition) => bondQsTypeKindComposition.ToCompilerObjectGeneric( typeTranslator: ToCompilerObject, @@ -154,12 +120,12 @@ private static SyntaxTokens.QsResult ToCompilerObject(this QsResult bondQsResult paramTranslator: ToCompilerObject, characteristicsTranslator: ToCompilerObject); - private static SyntaxTree.CallableInformation ToCompilerObject(this CallableInformation bondCallableInformation) => + internal static SyntaxTree.CallableInformation ToCompilerObject(this CallableInformation bondCallableInformation) => new SyntaxTree.CallableInformation( characteristics: bondCallableInformation.Characteristics.ToCompilerObject(), inferredInformation: bondCallableInformation.InferredInformation.ToCompilerObject()); - private static SyntaxTree.Identifier ToCompilerObject(Identifier bondIdentifier) + internal static SyntaxTree.Identifier ToCompilerObject(Identifier bondIdentifier) { string UnexpectedNullFieldMessage(string fieldName) => $"Bond Identifier '{fieldName}' field is null when Kind is '{bondIdentifier.Kind}'"; @@ -186,40 +152,40 @@ string UnexpectedNullFieldMessage(string fieldName) => } } - private static SyntaxTree.InferredCallableInformation ToCompilerObject( + internal static SyntaxTree.InferredCallableInformation ToCompilerObject( this InferredCallableInformation bondInferredCallableInformation) => new SyntaxTree.InferredCallableInformation( isSelfAdjoint: bondInferredCallableInformation.IsSelfAdjoint, isIntrinsic: bondInferredCallableInformation.IsIntrinsic); - private static SyntaxTree.InferredExpressionInformation ToCompilerObject( + internal static SyntaxTree.InferredExpressionInformation ToCompilerObject( this InferredExpressionInformation bondInferredExpressionInformation) => new SyntaxTree.InferredExpressionInformation( isMutable: bondInferredExpressionInformation.IsMutable, hasLocalQuantumDependency: bondInferredExpressionInformation.HasLocalQuantumDependency); - private static SyntaxTree.LocalDeclarations ToCompilerObject( + internal static SyntaxTree.LocalDeclarations ToCompilerObject( this LocalDeclarations bondLocalDeclarations) => new SyntaxTree.LocalDeclarations( variables: bondLocalDeclarations.Variables.Select(v => v.ToCompilerObject()).ToImmutableArray()); - private static SyntaxTree.LocalVariableDeclaration ToCompilerObject( + internal static SyntaxTree.LocalVariableDeclaration ToCompilerObject( this LocalVariableDeclaration bondLocalVariableDeclaration) => bondLocalVariableDeclaration.ToCompilerObjectGeneric(typeTranslator: s => s); - private static SyntaxTree.LocalVariableDeclaration ToCompilerObject( + internal static SyntaxTree.LocalVariableDeclaration ToCompilerObject( this LocalVariableDeclaration bondLocalVariableDeclaration) => bondLocalVariableDeclaration.ToCompilerObjectGeneric(typeTranslator: ToCompilerObject); - public static SyntaxTree.QsBinding ToCompilerObject( + internal static SyntaxTree.QsBinding ToCompilerObject( this QsBinding bondQsBinding) => bondQsBinding.ToCompilerObjectGeneric(typeTranslator: ToCompilerObject); - private static SyntaxTree.QsBinding ToCompilerObject( + internal static SyntaxTree.QsBinding ToCompilerObject( this QsBinding bondQsBinding) => bondQsBinding.ToCompilerObjectGeneric(typeTranslator: ToCompilerObject); - private static SyntaxTree.QsBindingKind ToCompilerObject(this QsBindingKind bondQsBindingKind) => + internal static SyntaxTree.QsBindingKind ToCompilerObject(this QsBindingKind bondQsBindingKind) => bondQsBindingKind switch { QsBindingKind.ImmutableBinding => SyntaxTree.QsBindingKind.ImmutableBinding, @@ -227,7 +193,7 @@ private static SyntaxTree.QsBindingKind ToCompilerObject(this QsBindingKind bond _ => throw new ArgumentException($"Unsupported Bond QsBindingKind '{bondQsBindingKind}'") }; - private static SyntaxTree.QsCallable ToCompilerObject(this QsCallable bondQsCallable) => + internal static SyntaxTree.QsCallable ToCompilerObject(this QsCallable bondQsCallable) => new SyntaxTree.QsCallable( kind: bondQsCallable.Kind.ToCompilerObject(), fullName: bondQsCallable.FullName.ToCompilerObject(), @@ -243,7 +209,7 @@ private static SyntaxTree.QsCallable ToCompilerObject(this QsCallable bondQsCall documentation: bondQsCallable.Documentation.ToImmutableArray(), comments: bondQsCallable.Comments.ToCompilerObject()); - private static SyntaxTree.QsCallableKind ToCompilerObject(this QsCallableKind bondQsCallableKind) => + internal static SyntaxTree.QsCallableKind ToCompilerObject(this QsCallableKind bondQsCallableKind) => bondQsCallableKind switch { QsCallableKind.Operation => SyntaxTree.QsCallableKind.Operation, @@ -252,24 +218,24 @@ private static SyntaxTree.QsCallableKind ToCompilerObject(this QsCallableKind bo _ => throw new ArgumentException($"Unsupported Bond QsCallableKind '{bondQsCallableKind}'") }; - private static SyntaxTree.QsComments ToCompilerObject(this QsComments bondQsComments) => + internal static SyntaxTree.QsComments ToCompilerObject(this QsComments bondQsComments) => new SyntaxTree.QsComments( openingComments: bondQsComments.OpeningComments.ToImmutableArray(), closingComments: bondQsComments.ClosingComments.ToImmutableArray()); - private static SyntaxTree.QsConditionalStatement ToCompilerObject(this QsConditionalStatement bondQsConditionalStatement) => + internal static SyntaxTree.QsConditionalStatement ToCompilerObject(this QsConditionalStatement bondQsConditionalStatement) => new SyntaxTree.QsConditionalStatement( conditionalBlocks: bondQsConditionalStatement.ConditionalBlocks.Select(c => c.ToCompilerObject()).ToImmutableArray(), @default: bondQsConditionalStatement.Default != null ? bondQsConditionalStatement.Default.ToCompilerObject().ToQsNullableGeneric() : QsNullable.Null); - private static SyntaxTree.QsConjugation ToCompilerObject(this QsConjugation bondQsConjugation) => + internal static SyntaxTree.QsConjugation ToCompilerObject(this QsConjugation bondQsConjugation) => new SyntaxTree.QsConjugation( outerTransformation: bondQsConjugation.OuterTransformation.ToCompilerObject(), innerTransformation: bondQsConjugation.InnerTransformation.ToCompilerObject()); - private static SyntaxTree.QsCustomType ToCompilerObject(this QsCustomType bondQsCustomType) => + internal static SyntaxTree.QsCustomType ToCompilerObject(this QsCustomType bondQsCustomType) => new SyntaxTree.QsCustomType( fullName: bondQsCustomType.FullName.ToCompilerObject(), attributes: bondQsCustomType.Attributes.Select(a => a.ToCompilerObject()).ToImmutableArray(), @@ -283,7 +249,7 @@ private static SyntaxTree.QsCustomType ToCompilerObject(this QsCustomType bondQs documentation: bondQsCustomType.Documentation.ToImmutableArray(), comments: bondQsCustomType.Comments.ToCompilerObject()); - private static SyntaxTree.QsDeclarationAttribute ToCompilerObject(this QsDeclarationAttribute bondQsDeclarationAttribute) => + internal static SyntaxTree.QsDeclarationAttribute ToCompilerObject(this QsDeclarationAttribute bondQsDeclarationAttribute) => new SyntaxTree.QsDeclarationAttribute( typeId: bondQsDeclarationAttribute.TypeId != null ? bondQsDeclarationAttribute.TypeId.ToCompilerObject().ToQsNullableGeneric() : @@ -292,13 +258,13 @@ private static SyntaxTree.QsDeclarationAttribute ToCompilerObject(this QsDeclara offset: bondQsDeclarationAttribute.Offset.ToCompilerObject(), comments: bondQsDeclarationAttribute.Comments.ToCompilerObject()); - private static SyntaxTree.QsForStatement ToCompilerObject(this QsForStatement bondQsForStatement) => + internal static SyntaxTree.QsForStatement ToCompilerObject(this QsForStatement bondQsForStatement) => new SyntaxTree.QsForStatement( loopItem: bondQsForStatement.LoopItem.ToCompilerObject(), iterationValues: bondQsForStatement.IterationValues.ToCompilerObject(), body: bondQsForStatement.Body.ToCompilerObject()); - private static SyntaxTree.QsLocalSymbol ToCompilerObject(this QsLocalSymbol bondQsLocalSymbol) + internal static SyntaxTree.QsLocalSymbol ToCompilerObject(this QsLocalSymbol bondQsLocalSymbol) { if (bondQsLocalSymbol.Kind == QsLocalSymbolKind.ValidName) { @@ -318,12 +284,12 @@ private static SyntaxTree.QsLocalSymbol ToCompilerObject(this QsLocalSymbol bond } } - private static SyntaxTree.QsLocation ToCompilerObject(this QsLocation bondQsLocation) => + internal static SyntaxTree.QsLocation ToCompilerObject(this QsLocation bondQsLocation) => new SyntaxTree.QsLocation( offset: bondQsLocation.Offset.ToCompilerObject(), range: bondQsLocation.Range.ToCompilerObject()); - public static SyntaxTree.QsNamespace ToCompilerObject(this QsNamespace bondQsNamespace) => + internal static SyntaxTree.QsNamespace ToCompilerObject(this QsNamespace bondQsNamespace) => new SyntaxTree.QsNamespace( name: bondQsNamespace.Name, elements: bondQsNamespace.Elements.Select(e => e.ToCompilerObject()).ToImmutableArray(), @@ -331,7 +297,7 @@ public static SyntaxTree.QsNamespace ToCompilerObject(this QsNamespace bondQsNam p => p.FileName, p => p.DocumentationItems.ToImmutableArray())); - public static SyntaxTree.QsNamespaceElement ToCompilerObject(this QsNamespaceElement bondQsNamespaceElement) + internal static SyntaxTree.QsNamespaceElement ToCompilerObject(this QsNamespaceElement bondQsNamespaceElement) { string UnexpectedNullFieldMessage(string fieldName) => $"Bond QsNamespaceElement '{fieldName}' field is null when Kind is '{bondQsNamespaceElement.Kind}'"; @@ -358,7 +324,7 @@ string UnexpectedNullFieldMessage(string fieldName) => } } - private static SyntaxTree.QsPositionedBlock ToCompilerObject(this QsPositionedBlock bondQsPositionedBlock) => + internal static SyntaxTree.QsPositionedBlock ToCompilerObject(this QsPositionedBlock bondQsPositionedBlock) => new SyntaxTree.QsPositionedBlock( body: bondQsPositionedBlock.Body.ToCompilerObject(), location: bondQsPositionedBlock.Location != null ? @@ -366,18 +332,18 @@ private static SyntaxTree.QsPositionedBlock ToCompilerObject(this QsPositionedBl QsNullable.Null, comments: bondQsPositionedBlock.Comments.ToCompilerObject()); - public static SyntaxTree.QsQualifiedName ToCompilerObject(this QsQualifiedName bondQsQualifiedName) => + internal static SyntaxTree.QsQualifiedName ToCompilerObject(this QsQualifiedName bondQsQualifiedName) => new SyntaxTree.QsQualifiedName( @namespace: bondQsQualifiedName.Namespace, name: bondQsQualifiedName.Name); - private static SyntaxTree.QsQubitScope ToCompilerObject(this QsQubitScope bondQsQubitScope) => + internal static SyntaxTree.QsQubitScope ToCompilerObject(this QsQubitScope bondQsQubitScope) => new SyntaxTree.QsQubitScope( kind: bondQsQubitScope.Kind.ToCompilerObject(), binding: bondQsQubitScope.Binding.ToCompilerObject(), body: bondQsQubitScope.Body.ToCompilerObject()); - private static SyntaxTree.QsQubitScopeKind ToCompilerObject(this QsQubitScopeKind bondQsQubitScopeKind) => + internal static SyntaxTree.QsQubitScopeKind ToCompilerObject(this QsQubitScopeKind bondQsQubitScopeKind) => bondQsQubitScopeKind switch { QsQubitScopeKind.Allocate => SyntaxTree.QsQubitScopeKind.Allocate, @@ -385,18 +351,18 @@ private static SyntaxTree.QsQubitScopeKind ToCompilerObject(this QsQubitScopeKin _ => throw new ArgumentException($"Unsupported Bond QsQubitScopeKind '{bondQsQubitScopeKind}'") }; - private static SyntaxTree.QsRepeatStatement ToCompilerObject(this QsRepeatStatement bondQsRepeatStatement) => + internal static SyntaxTree.QsRepeatStatement ToCompilerObject(this QsRepeatStatement bondQsRepeatStatement) => new SyntaxTree.QsRepeatStatement( repeatBlock: bondQsRepeatStatement.RepeatBlock.ToCompilerObject(), successCondition: bondQsRepeatStatement.SuccessCondition.ToCompilerObject(), fixupBlock: bondQsRepeatStatement.FixupBlock.ToCompilerObject()); - private static SyntaxTree.QsScope ToCompilerObject(this QsScope bondQsScope) => + internal static SyntaxTree.QsScope ToCompilerObject(this QsScope bondQsScope) => new SyntaxTree.QsScope( statements: bondQsScope.Statements.Select(s => s.ToCompilerObject()).ToImmutableArray(), knownSymbols: bondQsScope.KnownSymbols.ToCompilerObject()); - private static SyntaxTree.QsSpecialization ToCompilerObject(this QsSpecialization bondQsSpecialization) => + internal static SyntaxTree.QsSpecialization ToCompilerObject(this QsSpecialization bondQsSpecialization) => new SyntaxTree.QsSpecialization( kind: bondQsSpecialization.Kind.ToCompilerObject(), parent: bondQsSpecialization.Parent.ToCompilerObject(), @@ -413,7 +379,7 @@ private static SyntaxTree.QsSpecialization ToCompilerObject(this QsSpecializatio documentation: bondQsSpecialization.Documentation.ToImmutableArray(), comments: bondQsSpecialization.Comments.ToCompilerObject()); - private static SyntaxTree.QsSpecializationKind ToCompilerObject(this QsSpecializationKind bondQsSpecializationKind) => + internal static SyntaxTree.QsSpecializationKind ToCompilerObject(this QsSpecializationKind bondQsSpecializationKind) => bondQsSpecializationKind switch { QsSpecializationKind.QsAdjoint => SyntaxTree.QsSpecializationKind.QsAdjoint, @@ -423,7 +389,7 @@ private static SyntaxTree.QsSpecializationKind ToCompilerObject(this QsSpecializ _ => throw new ArgumentException($"Unsupported Bond QsSpecializationKind '{bondQsSpecializationKind}'") }; - private static SyntaxTree.QsStatement ToCompilerObject(this QsStatement bondQsStatement) => + internal static SyntaxTree.QsStatement ToCompilerObject(this QsStatement bondQsStatement) => new SyntaxTree.QsStatement( statement: bondQsStatement.Statement.ToCompilerObject(), symbolDeclarations: bondQsStatement.SymbolDeclarations.ToCompilerObject(), @@ -432,7 +398,7 @@ private static SyntaxTree.QsStatement ToCompilerObject(this QsStatement bondQsSt QsNullable.Null, comments: bondQsStatement.Comments.ToCompilerObject()); - private static SyntaxTree.QsStatementKind ToCompilerObject( + internal static SyntaxTree.QsStatementKind ToCompilerObject( this QsStatementKindComposition bondQsStatementKindComposition) { string InvalidKindForFieldMessage(string fieldName) => @@ -543,7 +509,7 @@ string UnexpectedNullFieldMessage(string fieldName) => } } - private static SyntaxTree.QsTypeItem ToCompilerObject(this QsTypeItem bondQsTypeItem) + internal static SyntaxTree.QsTypeItem ToCompilerObject(this QsTypeItem bondQsTypeItem) { string UnexpectedNullFieldMessage(string fieldName) => $"Bond QsTypeItem '{fieldName}' field is null when Kind is '{bondQsTypeItem.Kind}'"; @@ -571,7 +537,7 @@ string UnexpectedNullFieldMessage(string fieldName) => } } - private static SyntaxTree.QsTypeParameter ToCompilerObject(this QsTypeParameter bondQsTypeParameter) => + internal static SyntaxTree.QsTypeParameter ToCompilerObject(this QsTypeParameter bondQsTypeParameter) => new SyntaxTree.QsTypeParameter( origin: bondQsTypeParameter.Origin.ToCompilerObject(), typeName: bondQsTypeParameter.TypeName, @@ -579,34 +545,34 @@ private static SyntaxTree.QsTypeParameter ToCompilerObject(this QsTypeParameter bondQsTypeParameter.Range.ToCompilerObject().ToQsNullableGeneric() : QsNullable.Null); - private static SyntaxTree.QsWhileStatement ToCompilerObject(this QsWhileStatement bondQsWhileStatement) => + internal static SyntaxTree.QsWhileStatement ToCompilerObject(this QsWhileStatement bondQsWhileStatement) => new SyntaxTree.QsWhileStatement( condition: bondQsWhileStatement.Condition.ToCompilerObject(), body: bondQsWhileStatement.Body.ToCompilerObject()); - private static SyntaxTree.QsValueUpdate ToCompilerObject(this QsValueUpdate bondQsValueUpdate) => + internal static SyntaxTree.QsValueUpdate ToCompilerObject(this QsValueUpdate bondQsValueUpdate) => new SyntaxTree.QsValueUpdate( lhs: bondQsValueUpdate.Lhs.ToCompilerObject(), rhs: bondQsValueUpdate.Rhs.ToCompilerObject()); - private static SyntaxTree.ResolvedCharacteristics ToCompilerObject(this ResolvedCharacteristics bondResolvedCharacteristics) => + internal static SyntaxTree.ResolvedCharacteristics ToCompilerObject(this ResolvedCharacteristics bondResolvedCharacteristics) => SyntaxTree.ResolvedCharacteristics.New(kind: bondResolvedCharacteristics.Expression.ToCompilerObject()); // TODO: Check whether this translation is correct in a round-trip. - private static SyntaxTree.ResolvedInitializer ToCompilerObject(this ResolvedInitializer bondResolvedInitializer) => + internal static SyntaxTree.ResolvedInitializer ToCompilerObject(this ResolvedInitializer bondResolvedInitializer) => SyntaxTree.ResolvedInitializer.New(kind: bondResolvedInitializer.Initializer.ToCompilerObject()); - private static SyntaxTree.ResolvedSignature ToCompilerObject(this ResolvedSignature bondResolvedSignature) => + internal static SyntaxTree.ResolvedSignature ToCompilerObject(this ResolvedSignature bondResolvedSignature) => new SyntaxTree.ResolvedSignature( typeParameters: bondResolvedSignature.TypeParameters.Select(tp => tp.ToCompilerObject()).ToImmutableArray(), argumentType: bondResolvedSignature.ArgumentType.ToCompilerObject(), returnType: bondResolvedSignature.ReturnType.ToCompilerObject(), information: bondResolvedSignature.Information.ToCompilerObject()); - private static SyntaxTree.ResolvedType ToCompilerObject(this ResolvedType bondResolvedType) => + internal static SyntaxTree.ResolvedType ToCompilerObject(this ResolvedType bondResolvedType) => SyntaxTree.ResolvedType.New(bondResolvedType.TypeKind.ToCompilerObject()); - private static SyntaxTree.SpecializationImplementation ToCompilerObject( + internal static SyntaxTree.SpecializationImplementation ToCompilerObject( this SpecializationImplementation bondSpecializationImplementation) { string UnexpectedNullFieldMessage(string fieldName) => @@ -642,7 +608,7 @@ string UnexpectedNullFieldMessage(string fieldName) => } } - private static SyntaxTree.SymbolTuple ToCompilerObject(this SymbolTuple bondSymbolTuple) + internal static SyntaxTree.SymbolTuple ToCompilerObject(this SymbolTuple bondSymbolTuple) { string UnexpectedNullFieldMessage(string fieldName) => $"Bond SymbolTuple '{fieldName}' field is null when Kind is '{bondSymbolTuple.Kind}'"; @@ -675,7 +641,7 @@ string UnexpectedNullFieldMessage(string fieldName) => } } - private static SyntaxTree.TypedExpression ToCompilerObject(this TypedExpression bondTypedExpression) => + internal static SyntaxTree.TypedExpression ToCompilerObject(this TypedExpression bondTypedExpression) => new SyntaxTree.TypedExpression( expression: bondTypedExpression.Expression.ToCompilerObject(), typeArguments: bondTypedExpression.TypedArguments. @@ -687,7 +653,7 @@ private static SyntaxTree.TypedExpression ToCompilerObject(this TypedExpression bondTypedExpression.Range.ToCompilerObject().ToQsNullableGeneric() : QsNullable.Null); - private static SyntaxTree.UserDefinedType ToCompilerObject(this UserDefinedType bondUserDefinedType) => + internal static SyntaxTree.UserDefinedType ToCompilerObject(this UserDefinedType bondUserDefinedType) => new SyntaxTree.UserDefinedType( @namespace: bondUserDefinedType.Namespace, name: bondUserDefinedType.Name, @@ -695,18 +661,18 @@ private static SyntaxTree.UserDefinedType ToCompilerObject(this UserDefinedType bondUserDefinedType.Range.ToCompilerObject().ToQsNullableGeneric() : QsNullable.Null); - private static Tuple ToCompilerObject(this QsLoopItem bondQsLoopItem) => + internal static Tuple ToCompilerObject(this QsLoopItem bondQsLoopItem) => new Tuple( item1: bondQsLoopItem.SymbolTuple.ToCompilerObject(), item2: bondQsLoopItem.ResolvedType.ToCompilerObject()); - private static Tuple ToCompilerObject( + internal static Tuple ToCompilerObject( this QsConditionalBlock bondQsConditionalBlock) => new Tuple( item1: bondQsConditionalBlock.Expression.ToCompilerObject(), item2: bondQsConditionalBlock.Block.ToCompilerObject()); - private static SyntaxTokens.CharacteristicsKind ToCompilerObjectGeneric( + internal static SyntaxTokens.CharacteristicsKind ToCompilerObjectGeneric( this CharacteristicsKindComposition bondCharacteristicsKindComposition, Func typeTranslator) { @@ -756,7 +722,7 @@ string UnexpectedNullFieldMessage(string fieldName) => } } - private static SyntaxTokens.QsExpressionKind ToCompilerObjectGeneric< + internal static SyntaxTokens.QsExpressionKind ToCompilerObjectGeneric< TCompilerExpression, TCompilerSymbol, TCompilerType, @@ -1033,7 +999,7 @@ string UnexpectedNullFieldMessage(string fieldName) => } } - private static SyntaxTokens.QsInitializerKind ToCompilerObjectGeneric< + internal static SyntaxTokens.QsInitializerKind ToCompilerObjectGeneric< TCompilerInitializer, TCompilerExpression, TBondInitializer, @@ -1076,7 +1042,7 @@ string UnexpectedNullFieldMessage(string fieldName) => } } - private static SyntaxTokens.QsTuple ToCompilerObjectGeneric( + internal static SyntaxTokens.QsTuple ToCompilerObjectGeneric( this QsTuple bondQsTuple, Func typeTranslator) { @@ -1106,7 +1072,7 @@ string UnexpectedNullFieldMessage(string fieldName) => } } - private static SyntaxTokens.QsTypeKind ToCompilerObjectGeneric< + internal static SyntaxTokens.QsTypeKind ToCompilerObjectGeneric< TCompilerType, TCompilerUdt, TCompilerParam, @@ -1217,7 +1183,7 @@ string UnexpectedNullFieldMessage(string fieldName) => } } - private static SyntaxTree.LocalVariableDeclaration ToCompilerObjectGeneric( + internal static SyntaxTree.LocalVariableDeclaration ToCompilerObjectGeneric( this LocalVariableDeclaration bondLocalVariableDeclaration, Func typeTranslator) => new SyntaxTree.LocalVariableDeclaration( @@ -1229,7 +1195,7 @@ private static SyntaxTree.LocalVariableDeclaration ToCompilerObjectGe QsNullable.Null, range: bondLocalVariableDeclaration.Range.ToCompilerObject()); - private static SyntaxTree.QsBinding ToCompilerObjectGeneric( + internal static SyntaxTree.QsBinding ToCompilerObjectGeneric( this QsBinding bondQsBinding, Func typeTranslator) => new SyntaxTree.QsBinding( @@ -1237,7 +1203,7 @@ private static SyntaxTree.QsBinding ToCompilerObjectGeneric ToQsNullableGeneric(this T obj) => + internal static QsNullable ToQsNullableGeneric(this T obj) => QsNullable.NewValue(obj); } } diff --git a/src/QsCompiler/BondSchemas/V2/BondSchemaTranslator.cs b/src/QsCompiler/BondSchemas/V2/BondSchemaTranslator.cs index 70d405af7a..c56a6f35ba 100644 --- a/src/QsCompiler/BondSchemas/V2/BondSchemaTranslator.cs +++ b/src/QsCompiler/BondSchemas/V2/BondSchemaTranslator.cs @@ -21,7 +21,7 @@ public static QsCompilation CreateBondCompilation(SyntaxTree.QsCompilation qsCom EntryPoints = qsCompilation.EntryPoints.Select(e => e.ToBondSchema()).ToList() }; - public static QsNamespace ToBondSchema(this SyntaxTree.QsNamespace qsNamespace) => + internal static QsNamespace ToBondSchema(this SyntaxTree.QsNamespace qsNamespace) => new QsNamespace { Name = qsNamespace.Name, diff --git a/src/QsCompiler/BondSchemas/V2/CompilerObjectTranslator.cs b/src/QsCompiler/BondSchemas/V2/CompilerObjectTranslator.cs index 9a6fa01193..5dc392bd90 100644 --- a/src/QsCompiler/BondSchemas/V2/CompilerObjectTranslator.cs +++ b/src/QsCompiler/BondSchemas/V2/CompilerObjectTranslator.cs @@ -19,7 +19,7 @@ public static SyntaxTree.QsCompilation CreateQsCompilation(QsCompilation bondCom namespaces: bondCompilation.Namespaces.Select(n => n.ToCompilerObject()).ToImmutableArray(), entryPoints: bondCompilation.EntryPoints.Select(e => e.ToCompilerObject()).ToImmutableArray()); - public static SyntaxTree.QsNamespace ToCompilerObject(this QsNamespace bondQsNamespace) => + internal static SyntaxTree.QsNamespace ToCompilerObject(this QsNamespace bondQsNamespace) => new SyntaxTree.QsNamespace( name: bondQsNamespace.Name, elements: bondQsNamespace.Elements.Select(e => e.ToCompilerObject()).ToImmutableArray(), From 7e9787e5c734ae56c284381a2df0337b9a83de13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Zaragoza=20Cort=C3=A9s?= Date: Fri, 22 Jan 2021 22:55:22 -0800 Subject: [PATCH 07/17] Implemented core functionality of lazy deserialization of QsNamespace documentation. --- src/QsCompiler/BondSchemas/Protocols.cs | 7 +-- src/QsCompiler/BondSchemas/Translators.cs | 8 ++-- .../V1/CompilerObjectTranslator.cs | 10 ++-- .../BondSchemas/V2/BondSchemaTranslator.cs | 26 ++++++++++- .../V2/CompilerObjectTranslator.cs | 46 +++++++++++++++---- .../CompilationManager/AssemblyLoader.cs | 10 ++-- 6 files changed, 80 insertions(+), 27 deletions(-) diff --git a/src/QsCompiler/BondSchemas/Protocols.cs b/src/QsCompiler/BondSchemas/Protocols.cs index 3cd908252d..9b25d4a0c4 100644 --- a/src/QsCompiler/BondSchemas/Protocols.cs +++ b/src/QsCompiler/BondSchemas/Protocols.cs @@ -46,7 +46,6 @@ public enum Option /// /// Bond simple binary representation of a Q# compilation object. /// This method waits for s to complete and may deadlock if invoked through a . - // TODO: Extend to receive options. public static SyntaxTree.QsCompilation? DeserializeQsCompilationFromSimpleBinary( byte[] byteArray, Type bondSchemaType, @@ -57,13 +56,10 @@ public enum Option var reader = new SimpleBinaryReader(inputBuffer); lock (BondSharedDataStructuresLock) { - //var deserializer = GetSimpleBinaryDeserializer(bondSchemaType); - //bondCompilation = deserializer.Deserialize(reader); bondCompilation = DeserializeBondSchemaFromSimpleBinary(reader, bondSchemaType); - Console.WriteLine($"Deserialized: {bondSchemaType}"); } - return Translators.FromBondSchemaToSyntaxTree(bondCompilation); + return Translators.FromBondSchemaToSyntaxTree(bondCompilation, options); } /// @@ -148,7 +144,6 @@ private static object DeserializeBondSchemaFromSimpleBinary( private static SimpleBinaryDeserializer GetSimpleBinaryDeserializer(Type bondSchemaType) { VerifyLockAcquired(BondSharedDataStructuresLock); - Console.WriteLine($"GetSimpleBinaryDeserializer: {bondSchemaType}"); var deserializerInitialization = TryInitializeDeserializer(bondSchemaType); deserializerInitialization.Wait(); return deserializerInitialization.Result; diff --git a/src/QsCompiler/BondSchemas/Translators.cs b/src/QsCompiler/BondSchemas/Translators.cs index 1a0ebb3d2a..58e1f0cf7f 100644 --- a/src/QsCompiler/BondSchemas/Translators.cs +++ b/src/QsCompiler/BondSchemas/Translators.cs @@ -9,15 +9,17 @@ namespace Microsoft.Quantum.QsCompiler.BondSchemas internal static class Translators { - public static SyntaxTree.QsCompilation FromBondSchemaToSyntaxTree(TBond bondCompilation) + public static SyntaxTree.QsCompilation FromBondSchemaToSyntaxTree( + TBond bondCompilation, + Protocols.Option[]? options = null) { switch (bondCompilation) { case V1.QsCompilation bondCompilationV1: - return V1.CompilerObjectTranslator.CreateQsCompilation(bondCompilationV1); + return V1.CompilerObjectTranslator.CreateQsCompilation(bondCompilationV1, options); case BondQsCompilation bondCompilationV2: - return V2.CompilerObjectTranslator.CreateQsCompilation(bondCompilationV2); + return V2.CompilerObjectTranslator.CreateQsCompilation(bondCompilationV2, options); default: // TODO: Use a more meaningful message. diff --git a/src/QsCompiler/BondSchemas/V1/CompilerObjectTranslator.cs b/src/QsCompiler/BondSchemas/V1/CompilerObjectTranslator.cs index 3154e1611d..5c1acd52f8 100644 --- a/src/QsCompiler/BondSchemas/V1/CompilerObjectTranslator.cs +++ b/src/QsCompiler/BondSchemas/V1/CompilerObjectTranslator.cs @@ -18,10 +18,12 @@ internal static class CompilerObjectTranslator /// /// Creates a C# QsCompilation compiler object from a Bond schema QsCompilation object. /// - public static SyntaxTree.QsCompilation CreateQsCompilation(QsCompilation bondCompilation) => - new SyntaxTree.QsCompilation( - namespaces: bondCompilation.Namespaces.Select(n => n.ToCompilerObject()).ToImmutableArray(), - entryPoints: bondCompilation.EntryPoints.Select(e => e.ToCompilerObject()).ToImmutableArray()); + public static SyntaxTree.QsCompilation CreateQsCompilation( + QsCompilation bondCompilation, + Protocols.Option[]? options = null) => + new SyntaxTree.QsCompilation( + namespaces: bondCompilation.Namespaces.Select(n => n.ToCompilerObject()).ToImmutableArray(), + entryPoints: bondCompilation.EntryPoints.Select(e => e.ToCompilerObject()).ToImmutableArray()); internal static BigInteger ToBigInteger(this ArraySegment blob) => new BigInteger(blob); diff --git a/src/QsCompiler/BondSchemas/V2/BondSchemaTranslator.cs b/src/QsCompiler/BondSchemas/V2/BondSchemaTranslator.cs index c56a6f35ba..7ccd77af63 100644 --- a/src/QsCompiler/BondSchemas/V2/BondSchemaTranslator.cs +++ b/src/QsCompiler/BondSchemas/V2/BondSchemaTranslator.cs @@ -1,7 +1,10 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +using System.Collections.Generic; +using System.Collections.Immutable; using System.Linq; +using Bond; using Microsoft.Quantum.QsCompiler.BondSchemas.V1; namespace Microsoft.Quantum.QsCompiler.BondSchemas.V2 @@ -26,7 +29,28 @@ internal static QsNamespace ToBondSchema(this SyntaxTree.QsNamespace qsNamespace { Name = qsNamespace.Name, Elements = qsNamespace.Elements.Select(e => e.ToBondSchema()).ToList(), - // TODO: Implement Documentation. + Documentation = qsNamespace.Documentation.ToQsSourceFileDocumentationList() }; + + internal static LinkedList> ToQsSourceFileDocumentationList( + this ILookup> qsDocumentation) + { + var documentationList = new LinkedList>(); + foreach (var qsSourceFileDocumentation in qsDocumentation) + { + foreach (var items in qsSourceFileDocumentation) + { + var qsDocumentationItem = new QsSourceFileDocumentation + { + FileName = qsSourceFileDocumentation.Key, + DocumentationItems = items.ToList() + }; + + documentationList.AddLast(new Bonded(qsDocumentationItem)); + } + } + + return documentationList; + } } } diff --git a/src/QsCompiler/BondSchemas/V2/CompilerObjectTranslator.cs b/src/QsCompiler/BondSchemas/V2/CompilerObjectTranslator.cs index 5dc392bd90..6271c33241 100644 --- a/src/QsCompiler/BondSchemas/V2/CompilerObjectTranslator.cs +++ b/src/QsCompiler/BondSchemas/V2/CompilerObjectTranslator.cs @@ -1,8 +1,11 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +using System; +using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; +using Bond; using Microsoft.Quantum.QsCompiler.BondSchemas.V1; namespace Microsoft.Quantum.QsCompiler.BondSchemas.V2 @@ -14,16 +17,39 @@ internal static class CompilerObjectTranslator /// Creates a C# QsCompilation compiler object from a Bond schema QsCompilation object. /// /// // - public static SyntaxTree.QsCompilation CreateQsCompilation(QsCompilation bondCompilation) => - new SyntaxTree.QsCompilation( - namespaces: bondCompilation.Namespaces.Select(n => n.ToCompilerObject()).ToImmutableArray(), - entryPoints: bondCompilation.EntryPoints.Select(e => e.ToCompilerObject()).ToImmutableArray()); + public static SyntaxTree.QsCompilation CreateQsCompilation( + QsCompilation bondCompilation, + Protocols.Option[]? options = null) => + new SyntaxTree.QsCompilation( + namespaces: bondCompilation.Namespaces.Select(n => n.ToCompilerObject(options)).ToImmutableArray(), + entryPoints: bondCompilation.EntryPoints.Select(e => e.ToCompilerObject()).ToImmutableArray()); - internal static SyntaxTree.QsNamespace ToCompilerObject(this QsNamespace bondQsNamespace) => - new SyntaxTree.QsNamespace( - name: bondQsNamespace.Name, - elements: bondQsNamespace.Elements.Select(e => e.ToCompilerObject()).ToImmutableArray(), - // TODO: Implement. - documentation: default); + internal static SyntaxTree.QsNamespace ToCompilerObject( + this QsNamespace bondQsNamespace, + Protocols.Option[]? options = null) => + new SyntaxTree.QsNamespace( + name: bondQsNamespace.Name, + elements: bondQsNamespace.Elements.Select(e => e.ToCompilerObject()).ToImmutableArray(), + documentation: bondQsNamespace.Documentation.ToCompilerObject(options)); + + internal static ILookup> ToCompilerObject( + this LinkedList> documentation, + Protocols.Option[]? options = null) + { + IEnumerable deserializedDocumentation; + if ((options != null) && + options.Contains(Protocols.Option.ExcludeNamespaceDocumentation)) + { + deserializedDocumentation = Enumerable.Empty(); + } + else + { + deserializedDocumentation = documentation.Select(d => d.Deserialize()); + } + + return deserializedDocumentation.ToLookup( + p => p.FileName, + p => p.DocumentationItems.ToImmutableArray()); + } } } diff --git a/src/QsCompiler/CompilationManager/AssemblyLoader.cs b/src/QsCompiler/CompilationManager/AssemblyLoader.cs index ed3b60072e..2bae12bbea 100644 --- a/src/QsCompiler/CompilationManager/AssemblyLoader.cs +++ b/src/QsCompiler/CompilationManager/AssemblyLoader.cs @@ -33,7 +33,7 @@ public static class AssemblyLoader new Dictionary() { { DotnetCoreDll.ResourceName, null }, - //{ DotnetCoreDll.ResourceNameQsDataBondV1, typeof(BondSchemas.v01.QsCompilation) } + { DotnetCoreDll.ResourceNameQsDataBondV1, typeof(BondSchemas.V1.QsCompilation) } }; /// @@ -122,7 +122,7 @@ public static bool LoadSyntaxTree( try { PerformanceTracking.TaskStart(PerformanceTracking.Task.SyntaxTreeDeserialization); - // TODO: This should be a call to the extended LoadSyntaxTree API. + // TODO: This should be always call the latest version of the Bond schemas. compilation = BondSchemas.Protocols.DeserializeQsCompilationFromSimpleBinary(byteArray, typeof(BondSchemas.V1.QsCompilation)); PerformanceTracking.TaskEnd(PerformanceTracking.Task.SyntaxTreeDeserialization); } @@ -149,8 +149,11 @@ public static bool LoadSyntaxTree( try { PerformanceTracking.TaskStart(PerformanceTracking.Task.SyntaxTreeDeserialization); + compilation = BondSchemas.Protocols.DeserializeQsCompilationFromSimpleBinary( + byteArray, + typeof(BondSchemas.V1.QsCompilation), + options); - // TODO: Call into the Protocols API. PerformanceTracking.TaskEnd(PerformanceTracking.Task.SyntaxTreeDeserialization); } catch (Exception ex) @@ -255,6 +258,7 @@ private static bool FromResource( PerformanceTracking.TaskEnd(PerformanceTracking.Task.LoadDataFromReferenceToStream); // Use the correct method depending on the resource. + // TODO: Refactor this to call the new LoadSyntaxTree method. if (isBondV1ResourcePresent) { return LoadSyntaxTree(resourceData, out compilation, onDeserializationException); From 23f025b574e8b8089eebda968579aedd752ce1f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Zaragoza=20Cort=C3=A9s?= Date: Fri, 22 Jan 2021 23:56:52 -0800 Subject: [PATCH 08/17] New implementation prototype for FromResource. --- src/QsCompiler/BondSchemas/Protocols.cs | 4 +- src/QsCompiler/BondSchemas/Translators.cs | 6 +-- .../CompilationManager/AssemblyLoader.cs | 52 +++++++++++++++++-- .../DataStructures/ReservedKeywords.fs | 1 + 4 files changed, 55 insertions(+), 8 deletions(-) diff --git a/src/QsCompiler/BondSchemas/Protocols.cs b/src/QsCompiler/BondSchemas/Protocols.cs index 9b25d4a0c4..2ac5555818 100644 --- a/src/QsCompiler/BondSchemas/Protocols.cs +++ b/src/QsCompiler/BondSchemas/Protocols.cs @@ -13,7 +13,7 @@ namespace Microsoft.Quantum.QsCompiler.BondSchemas { - using BondQsCompilation = V2.QsCompilation; + using BondQsCompilation = V1.QsCompilation; using SimpleBinaryDeserializer = Deserializer>; using SimpleBinarySerializer = Serializer>; @@ -36,7 +36,7 @@ public enum Option new Dictionary?>() { { typeof(V1.QsCompilation), null }, - { typeof(BondQsCompilation), null } + { typeof(V2.QsCompilation), null } }; private static Task? serializerInitialization = null; diff --git a/src/QsCompiler/BondSchemas/Translators.cs b/src/QsCompiler/BondSchemas/Translators.cs index 58e1f0cf7f..ecf840633e 100644 --- a/src/QsCompiler/BondSchemas/Translators.cs +++ b/src/QsCompiler/BondSchemas/Translators.cs @@ -5,7 +5,7 @@ namespace Microsoft.Quantum.QsCompiler.BondSchemas { - using BondQsCompilation = V2.QsCompilation; + using BondQsCompilation = V1.QsCompilation; internal static class Translators { @@ -18,7 +18,7 @@ public static SyntaxTree.QsCompilation FromBondSchemaToSyntaxTree( case V1.QsCompilation bondCompilationV1: return V1.CompilerObjectTranslator.CreateQsCompilation(bondCompilationV1, options); - case BondQsCompilation bondCompilationV2: + case V2.QsCompilation bondCompilationV2: return V2.CompilerObjectTranslator.CreateQsCompilation(bondCompilationV2, options); default: @@ -28,6 +28,6 @@ public static SyntaxTree.QsCompilation FromBondSchemaToSyntaxTree( } public static BondQsCompilation FromSyntaxTreeToBondSchema(SyntaxTree.QsCompilation qsCompilation) => - V2.BondSchemaTranslator.CreateBondCompilation(qsCompilation); + V1.BondSchemaTranslator.CreateBondCompilation(qsCompilation); } } diff --git a/src/QsCompiler/CompilationManager/AssemblyLoader.cs b/src/QsCompiler/CompilationManager/AssemblyLoader.cs index 2bae12bbea..b8a1e739da 100644 --- a/src/QsCompiler/CompilationManager/AssemblyLoader.cs +++ b/src/QsCompiler/CompilationManager/AssemblyLoader.cs @@ -29,11 +29,12 @@ public static class AssemblyLoader /// /// TODO: Document. /// - private static IDictionary syntaxTreeResourceBondType = + private static IDictionary syntaxTreeResources = new Dictionary() { { DotnetCoreDll.ResourceName, null }, - { DotnetCoreDll.ResourceNameQsDataBondV1, typeof(BondSchemas.V1.QsCompilation) } + { DotnetCoreDll.ResourceNameQsDataBondV1, typeof(BondSchemas.V1.QsCompilation) }, + { DotnetCoreDll.ResourceNameQsDataBondV2, typeof(BondSchemas.V2.QsCompilation) } }; /// @@ -123,6 +124,7 @@ public static bool LoadSyntaxTree( { PerformanceTracking.TaskStart(PerformanceTracking.Task.SyntaxTreeDeserialization); // TODO: This should be always call the latest version of the Bond schemas. + // TODO: Call the new version of LoadSyntaxTree leveraging ResourceName. compilation = BondSchemas.Protocols.DeserializeQsCompilationFromSimpleBinary(byteArray, typeof(BondSchemas.V1.QsCompilation)); PerformanceTracking.TaskEnd(PerformanceTracking.Task.SyntaxTreeDeserialization); } @@ -271,6 +273,50 @@ private static bool FromResource( return false; } + private static bool FromResource2( + PEReader assemblyFile, + [NotNullWhen(true)] out QsCompilation? compilation, + Action? onDeserializationException = null) + { + compilation = null; + var metadataReader = assemblyFile.GetMetadataReader(); + string? resourceName = null; + ManifestResource resource = default; + foreach (var item in syntaxTreeResources) + { + if (metadataReader.Resources().TryGetValue(item.Key, out resource)) + { + resourceName = item.Key; + } + } + + // The offset of resources is relative to the resources directory. + // It is possible that there is no offset given because a valid dll allows for extenal resources. + // In all Q# dlls there will be a resource with the specific name chosen by the compiler. + var resourceDir = assemblyFile.PEHeaders.CorHeader.ResourcesDirectory; + if (!assemblyFile.PEHeaders.TryGetDirectoryOffset(resourceDir, out var directoryOffset) || + (resourceName == null) || + !resource.Implementation.IsNil) + { + return false; + } + + // This is going to be very slow, as it loads the entire assembly into a managed array, byte by byte. + // Due to the finite size of the managed array, that imposes a memory limitation of around 4GB. + // The other alternative would be to have an unsafe block, or to contribute a fix to PEMemoryBlock to expose a ReadOnlySpan. + PerformanceTracking.TaskStart(PerformanceTracking.Task.LoadDataFromReferenceToStream); + var image = assemblyFile.GetEntireImage(); // uses int to denote the length and access parameters + var absResourceOffset = (int)resource.Offset + directoryOffset; + + // the first four bytes of the resource denote how long the resource is, and are followed by the actual resource data + var resourceLength = BitConverter.ToInt32(image.GetContent(absResourceOffset, sizeof(int)).ToArray(), 0); + var resourceData = image.GetContent(absResourceOffset + sizeof(int), resourceLength).ToArray(); + PerformanceTracking.TaskEnd(PerformanceTracking.Task.LoadDataFromReferenceToStream); + + // Use the correct method depending on the resource. + return LoadSyntaxTree(resourceData, resourceName, out compilation, new BondSchemas.Protocols.Option[] { }, onDeserializationException); + } + // tools for loading headers based on attributes in compiled C# code (early setup for shipping Q# libraries) /// @@ -331,7 +377,7 @@ private static (string, string)? GetAttribute(MetadataReader metadataReader, Cus private static (string ResourceName, ManifestResource Resource)? GetSyntaxTreeResourceTuple(MetadataReader metadataReader) { ManifestResource resource; - foreach (var resourceName in syntaxTreeResourceBondType.Keys) + foreach (var resourceName in syntaxTreeResources.Keys) { if (metadataReader.Resources().TryGetValue(resourceName, out resource)) { diff --git a/src/QsCompiler/DataStructures/ReservedKeywords.fs b/src/QsCompiler/DataStructures/ReservedKeywords.fs index cb43ddf15a..168b20e4a9 100644 --- a/src/QsCompiler/DataStructures/ReservedKeywords.fs +++ b/src/QsCompiler/DataStructures/ReservedKeywords.fs @@ -285,6 +285,7 @@ module DotnetCoreDll = let ResourceName = "__qsharp_data__.bson" let ResourceNameQsDataBondV1 = "__qsharp_data_bond_v1__.bson" + let ResourceNameQsDataBondV2 = "__qsharp_data_bond_v2__.bson" // Should always provide the name of the resource currently used by the compiler to attach the syntax tree to a DLL. let SyntaxTreeResourceName = ResourceNameQsDataBondV1 let MetadataNamespace = "__qsharp__" From 097c1d1d6dce50d643f4b1281ed47936eb851d18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Zaragoza=20Cort=C3=A9s?= Date: Sun, 24 Jan 2021 20:51:34 -0800 Subject: [PATCH 09/17] Complete new LoadSyntaxTree implementation. --- .../CompilationManager/AssemblyLoader.cs | 44 +++++++++---------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/src/QsCompiler/CompilationManager/AssemblyLoader.cs b/src/QsCompiler/CompilationManager/AssemblyLoader.cs index b8a1e739da..a6e9c4b784 100644 --- a/src/QsCompiler/CompilationManager/AssemblyLoader.cs +++ b/src/QsCompiler/CompilationManager/AssemblyLoader.cs @@ -29,7 +29,7 @@ public static class AssemblyLoader /// /// TODO: Document. /// - private static IDictionary syntaxTreeResources = + private static readonly IDictionary SyntaxTreeResources = new Dictionary() { { DotnetCoreDll.ResourceName, null }, @@ -138,7 +138,8 @@ public static bool LoadSyntaxTree( } // TODO: Document. - public static bool LoadSyntaxTree( + // TODO: This could be private. + private static bool LoadSyntaxTree( byte[] byteArray, string resourceName, [NotNullWhen(true)] out QsCompilation? compilation, @@ -146,15 +147,27 @@ public static bool LoadSyntaxTree( Action? onDeserializationException = null) { compilation = null; - + if (!SyntaxTreeResources.TryGetValue(resourceName, out var type)) + { + // TODO: Provide a meaningful error message. + onDeserializationException?.Invoke(new ArgumentException()); + return false; + } try { PerformanceTracking.TaskStart(PerformanceTracking.Task.SyntaxTreeDeserialization); - compilation = BondSchemas.Protocols.DeserializeQsCompilationFromSimpleBinary( - byteArray, - typeof(BondSchemas.V1.QsCompilation), - options); + if (type != null) + { + compilation = BondSchemas.Protocols.DeserializeQsCompilationFromSimpleBinary( + byteArray, + type, + options); + } + else + { + LoadSyntaxTree(new MemoryStream(byteArray), out compilation, onDeserializationException); + } PerformanceTracking.TaskEnd(PerformanceTracking.Task.SyntaxTreeDeserialization); } @@ -282,7 +295,7 @@ private static bool FromResource2( var metadataReader = assemblyFile.GetMetadataReader(); string? resourceName = null; ManifestResource resource = default; - foreach (var item in syntaxTreeResources) + foreach (var item in SyntaxTreeResources) { if (metadataReader.Resources().TryGetValue(item.Key, out resource)) { @@ -373,21 +386,6 @@ private static (string, string)? GetAttribute(MetadataReader metadataReader, Cus return null; } - // TODO: Document. - private static (string ResourceName, ManifestResource Resource)? GetSyntaxTreeResourceTuple(MetadataReader metadataReader) - { - ManifestResource resource; - foreach (var resourceName in syntaxTreeResources.Keys) - { - if (metadataReader.Resources().TryGetValue(resourceName, out resource)) - { - return (resourceName, resource); - } - } - - return null; - } - /// /// Given a reader for the byte stream of a dotnet dll, read its custom attributes and /// returns a tuple containing the name of the attribute and the constructor argument From 49d50fa3933174d45c4a844d9f462b6e4aeec9ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Zaragoza=20Cort=C3=A9s?= Date: Sun, 24 Jan 2021 22:51:30 -0800 Subject: [PATCH 10/17] Replaced FromResource implementation. --- .../CompilationManager/AssemblyLoader.cs | 75 +++---------------- 1 file changed, 11 insertions(+), 64 deletions(-) diff --git a/src/QsCompiler/CompilationManager/AssemblyLoader.cs b/src/QsCompiler/CompilationManager/AssemblyLoader.cs index f1cfb5e6b0..eeae8087ee 100644 --- a/src/QsCompiler/CompilationManager/AssemblyLoader.cs +++ b/src/QsCompiler/CompilationManager/AssemblyLoader.cs @@ -166,7 +166,9 @@ private static bool LoadSyntaxTree( } else { +#pragma warning disable 618 // LoadSyntaxTree is obsolete. LoadSyntaxTree(new MemoryStream(byteArray), out compilation, onDeserializationException); +#pragma warning restore 618 } PerformanceTracking.TaskEnd(PerformanceTracking.Task.SyntaxTreeDeserialization); @@ -233,77 +235,19 @@ private static bool FromResource( PEReader assemblyFile, [NotNullWhen(true)] out QsCompilation? compilation, Action? onDeserializationException = null) - { - compilation = null; - var metadataReader = assemblyFile.GetMetadataReader(); - bool isBondV1ResourcePresent = false; - bool isNewtonSoftResourcePresent = false; - ManifestResource resource; - if (metadataReader.Resources().TryGetValue(DotnetCoreDll.ResourceNameQsDataBondV1, out resource)) - { - isBondV1ResourcePresent = true; - } -#pragma warning disable 618 // ResourceName is obsolete. - else if (metadataReader.Resources().TryGetValue(DotnetCoreDll.ResourceName, out resource)) -#pragma warning restore 618 - { - isNewtonSoftResourcePresent = true; - } - - // The offset of resources is relative to the resources directory. - // It is possible that there is no offset given because a valid dll allows for extenal resources. - // In all Q# dlls there will be a resource with the specific name chosen by the compiler. - var isResourcePresent = isBondV1ResourcePresent || isNewtonSoftResourcePresent; - var resourceDir = assemblyFile.PEHeaders.CorHeader.ResourcesDirectory; - if (!assemblyFile.PEHeaders.TryGetDirectoryOffset(resourceDir, out var directoryOffset) || - !isResourcePresent || - !resource.Implementation.IsNil) - { - return false; - } - - // This is going to be very slow, as it loads the entire assembly into a managed array, byte by byte. - // Due to the finite size of the managed array, that imposes a memory limitation of around 4GB. - // The other alternative would be to have an unsafe block, or to contribute a fix to PEMemoryBlock to expose a ReadOnlySpan. - PerformanceTracking.TaskStart(PerformanceTracking.Task.LoadDataFromReferenceToStream); - var image = assemblyFile.GetEntireImage(); // uses int to denote the length and access parameters - var absResourceOffset = (int)resource.Offset + directoryOffset; - - // the first four bytes of the resource denote how long the resource is, and are followed by the actual resource data - var resourceLength = BitConverter.ToInt32(image.GetContent(absResourceOffset, sizeof(int)).ToArray(), 0); - var resourceData = image.GetContent(absResourceOffset + sizeof(int), resourceLength).ToArray(); - PerformanceTracking.TaskEnd(PerformanceTracking.Task.LoadDataFromReferenceToStream); - - // Use the correct method depending on the resource. - // TODO: Refactor this to call the new LoadSyntaxTree method. - if (isBondV1ResourcePresent) - { - return LoadSyntaxTree(resourceData, out compilation, onDeserializationException); - } - else if (isNewtonSoftResourcePresent) - { -#pragma warning disable 618 // LoadSyntaxTree is obsolete. - return LoadSyntaxTree(new MemoryStream(resourceData), out compilation, onDeserializationException); -#pragma warning restore 618 - } - - return false; - } - - private static bool FromResource2( - PEReader assemblyFile, - [NotNullWhen(true)] out QsCompilation? compilation, - Action? onDeserializationException = null) { compilation = null; var metadataReader = assemblyFile.GetMetadataReader(); string? resourceName = null; ManifestResource resource = default; + + // foreach (var item in SyntaxTreeResources) { if (metadataReader.Resources().TryGetValue(item.Key, out resource)) { resourceName = item.Key; + break; } } @@ -329,9 +273,12 @@ private static bool FromResource2( var resourceLength = BitConverter.ToInt32(image.GetContent(absResourceOffset, sizeof(int)).ToArray(), 0); var resourceData = image.GetContent(absResourceOffset + sizeof(int), resourceLength).ToArray(); PerformanceTracking.TaskEnd(PerformanceTracking.Task.LoadDataFromReferenceToStream); - - // Use the correct method depending on the resource. - return LoadSyntaxTree(resourceData, resourceName, out compilation, new BondSchemas.Protocols.Option[] { }, onDeserializationException); + return LoadSyntaxTree( + resourceData, + resourceName, + out compilation, + new BondSchemas.Protocols.Option[] { }, + onDeserializationException); } // tools for loading headers based on attributes in compiled C# code (early setup for shipping Q# libraries) From 57f43cae69ca04380a638aedd18fd0314fcb411e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Zaragoza=20Cort=C3=A9s?= Date: Wed, 3 Feb 2021 15:25:58 -0800 Subject: [PATCH 11/17] Cleaning it up. --- src/QsCompiler/BondSchemas/Protocols.cs | 4 +++- src/QsCompiler/BondSchemas/V2/CompilerObjectTranslator.cs | 5 +++-- src/QsCompiler/CompilationManager/AssemblyLoader.cs | 7 ++++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/QsCompiler/BondSchemas/Protocols.cs b/src/QsCompiler/BondSchemas/Protocols.cs index 2ac5555818..f3a8fbd603 100644 --- a/src/QsCompiler/BondSchemas/Protocols.cs +++ b/src/QsCompiler/BondSchemas/Protocols.cs @@ -22,7 +22,9 @@ namespace Microsoft.Quantum.QsCompiler.BondSchemas /// public static class Protocols { - // TODO: Document. + /// + /// Options that can be provided to APIs related to Bond schemas. + /// public enum Option { ExcludeNamespaceDocumentation diff --git a/src/QsCompiler/BondSchemas/V2/CompilerObjectTranslator.cs b/src/QsCompiler/BondSchemas/V2/CompilerObjectTranslator.cs index 6271c33241..453e7925f6 100644 --- a/src/QsCompiler/BondSchemas/V2/CompilerObjectTranslator.cs +++ b/src/QsCompiler/BondSchemas/V2/CompilerObjectTranslator.cs @@ -10,13 +10,14 @@ namespace Microsoft.Quantum.QsCompiler.BondSchemas.V2 { + /// + /// This class translates Bond schema objects to C# compiler objects. + /// internal static class CompilerObjectTranslator { - /// /// Creates a C# QsCompilation compiler object from a Bond schema QsCompilation object. /// - /// // public static SyntaxTree.QsCompilation CreateQsCompilation( QsCompilation bondCompilation, Protocols.Option[]? options = null) => diff --git a/src/QsCompiler/CompilationManager/AssemblyLoader.cs b/src/QsCompiler/CompilationManager/AssemblyLoader.cs index eeae8087ee..3e26707ef4 100644 --- a/src/QsCompiler/CompilationManager/AssemblyLoader.cs +++ b/src/QsCompiler/CompilationManager/AssemblyLoader.cs @@ -273,11 +273,16 @@ private static bool FromResource( var resourceLength = BitConverter.ToInt32(image.GetContent(absResourceOffset, sizeof(int)).ToArray(), 0); var resourceData = image.GetContent(absResourceOffset + sizeof(int), resourceLength).ToArray(); PerformanceTracking.TaskEnd(PerformanceTracking.Task.LoadDataFromReferenceToStream); + var options = new BondSchemas.Protocols.Option[] + { + BondSchemas.Protocols.Option.ExcludeNamespaceDocumentation + }; + return LoadSyntaxTree( resourceData, resourceName, out compilation, - new BondSchemas.Protocols.Option[] { }, + options, onDeserializationException); } From 2c7937b3389852a8b558bc800002bcd631952a92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Zaragoza=20Cort=C3=A9s?= Date: Fri, 5 Feb 2021 14:19:49 -0800 Subject: [PATCH 12/17] Remove options. --- src/QsCompiler/BondSchemas/Protocols.cs | 18 ++++++------- src/QsCompiler/BondSchemas/Translators.cs | 9 ++++--- .../V1/CompilerObjectTranslator.cs | 3 +-- .../V2/CompilerObjectTranslator.cs | 25 +++++-------------- .../CompilationManager/AssemblyLoader.cs | 14 +++-------- 5 files changed, 23 insertions(+), 46 deletions(-) diff --git a/src/QsCompiler/BondSchemas/Protocols.cs b/src/QsCompiler/BondSchemas/Protocols.cs index f3a8fbd603..026fc5614b 100644 --- a/src/QsCompiler/BondSchemas/Protocols.cs +++ b/src/QsCompiler/BondSchemas/Protocols.cs @@ -22,14 +22,6 @@ namespace Microsoft.Quantum.QsCompiler.BondSchemas /// public static class Protocols { - /// - /// Options that can be provided to APIs related to Bond schemas. - /// - public enum Option - { - ExcludeNamespaceDocumentation - } - /// /// Provides thread-safe access to the members and methods of this class. /// @@ -37,7 +29,9 @@ public enum Option private static readonly IDictionary?> DeserializerInitializations = new Dictionary?>() { +#pragma warning disable IDE0001 // Simplify Names { typeof(V1.QsCompilation), null }, +#pragma warning restore IDE0001 // Simplify Names { typeof(V2.QsCompilation), null } }; @@ -48,10 +42,10 @@ public enum Option /// /// Bond simple binary representation of a Q# compilation object. /// This method waits for s to complete and may deadlock if invoked through a . + // N.B. Consider adding an options argument to this method to allow for selection of payload to deserialize. public static SyntaxTree.QsCompilation? DeserializeQsCompilationFromSimpleBinary( byte[] byteArray, - Type bondSchemaType, - Option[]? options = null) + Type bondSchemaType) { object? bondCompilation = null; var inputBuffer = new InputBuffer(byteArray); @@ -61,7 +55,7 @@ public enum Option bondCompilation = DeserializeBondSchemaFromSimpleBinary(reader, bondSchemaType); } - return Translators.FromBondSchemaToSyntaxTree(bondCompilation, options); + return Translators.FromBondSchemaToSyntaxTree(bondCompilation); } /// @@ -130,6 +124,7 @@ private static object DeserializeBondSchemaFromSimpleBinary( Type bondSchemaType) { var deserializer = GetSimpleBinaryDeserializer(bondSchemaType); +#pragma warning disable IDE0001 // Simplify Names if (bondSchemaType == typeof(V1.QsCompilation)) { return deserializer.Deserialize(reader); @@ -138,6 +133,7 @@ private static object DeserializeBondSchemaFromSimpleBinary( { return deserializer.Deserialize(reader); } +#pragma warning restore IDE0001 // Simplify Names // TODO: Use specific message. throw new ArgumentException(); diff --git a/src/QsCompiler/BondSchemas/Translators.cs b/src/QsCompiler/BondSchemas/Translators.cs index ecf840633e..a20644cf2f 100644 --- a/src/QsCompiler/BondSchemas/Translators.cs +++ b/src/QsCompiler/BondSchemas/Translators.cs @@ -10,20 +10,21 @@ namespace Microsoft.Quantum.QsCompiler.BondSchemas internal static class Translators { public static SyntaxTree.QsCompilation FromBondSchemaToSyntaxTree( - TBond bondCompilation, - Protocols.Option[]? options = null) + TBond bondCompilation) { switch (bondCompilation) { +#pragma warning disable IDE0001 // Simplify Names case V1.QsCompilation bondCompilationV1: - return V1.CompilerObjectTranslator.CreateQsCompilation(bondCompilationV1, options); + return V1.CompilerObjectTranslator.CreateQsCompilation(bondCompilationV1); case V2.QsCompilation bondCompilationV2: - return V2.CompilerObjectTranslator.CreateQsCompilation(bondCompilationV2, options); + return V2.CompilerObjectTranslator.CreateQsCompilation(bondCompilationV2); default: // TODO: Use a more meaningful message. throw new ArgumentException(); +#pragma warning restore IDE0001 // Simplify Names } } diff --git a/src/QsCompiler/BondSchemas/V1/CompilerObjectTranslator.cs b/src/QsCompiler/BondSchemas/V1/CompilerObjectTranslator.cs index 5c1acd52f8..2530baf139 100644 --- a/src/QsCompiler/BondSchemas/V1/CompilerObjectTranslator.cs +++ b/src/QsCompiler/BondSchemas/V1/CompilerObjectTranslator.cs @@ -19,8 +19,7 @@ internal static class CompilerObjectTranslator /// Creates a C# QsCompilation compiler object from a Bond schema QsCompilation object. /// public static SyntaxTree.QsCompilation CreateQsCompilation( - QsCompilation bondCompilation, - Protocols.Option[]? options = null) => + QsCompilation bondCompilation) => new SyntaxTree.QsCompilation( namespaces: bondCompilation.Namespaces.Select(n => n.ToCompilerObject()).ToImmutableArray(), entryPoints: bondCompilation.EntryPoints.Select(e => e.ToCompilerObject()).ToImmutableArray()); diff --git a/src/QsCompiler/BondSchemas/V2/CompilerObjectTranslator.cs b/src/QsCompiler/BondSchemas/V2/CompilerObjectTranslator.cs index 453e7925f6..172345e35e 100644 --- a/src/QsCompiler/BondSchemas/V2/CompilerObjectTranslator.cs +++ b/src/QsCompiler/BondSchemas/V2/CompilerObjectTranslator.cs @@ -19,35 +19,22 @@ internal static class CompilerObjectTranslator /// Creates a C# QsCompilation compiler object from a Bond schema QsCompilation object. /// public static SyntaxTree.QsCompilation CreateQsCompilation( - QsCompilation bondCompilation, - Protocols.Option[]? options = null) => + QsCompilation bondCompilation) => new SyntaxTree.QsCompilation( - namespaces: bondCompilation.Namespaces.Select(n => n.ToCompilerObject(options)).ToImmutableArray(), + namespaces: bondCompilation.Namespaces.Select(n => n.ToCompilerObject()).ToImmutableArray(), entryPoints: bondCompilation.EntryPoints.Select(e => e.ToCompilerObject()).ToImmutableArray()); internal static SyntaxTree.QsNamespace ToCompilerObject( - this QsNamespace bondQsNamespace, - Protocols.Option[]? options = null) => + this QsNamespace bondQsNamespace) => new SyntaxTree.QsNamespace( name: bondQsNamespace.Name, elements: bondQsNamespace.Elements.Select(e => e.ToCompilerObject()).ToImmutableArray(), - documentation: bondQsNamespace.Documentation.ToCompilerObject(options)); + documentation: bondQsNamespace.Documentation.ToCompilerObject()); internal static ILookup> ToCompilerObject( - this LinkedList> documentation, - Protocols.Option[]? options = null) + this LinkedList> documentation) { - IEnumerable deserializedDocumentation; - if ((options != null) && - options.Contains(Protocols.Option.ExcludeNamespaceDocumentation)) - { - deserializedDocumentation = Enumerable.Empty(); - } - else - { - deserializedDocumentation = documentation.Select(d => d.Deserialize()); - } - + var deserializedDocumentation = documentation.Select(d => d.Deserialize()); return deserializedDocumentation.ToLookup( p => p.FileName, p => p.DocumentationItems.ToImmutableArray()); diff --git a/src/QsCompiler/CompilationManager/AssemblyLoader.cs b/src/QsCompiler/CompilationManager/AssemblyLoader.cs index 3e26707ef4..de166079b1 100644 --- a/src/QsCompiler/CompilationManager/AssemblyLoader.cs +++ b/src/QsCompiler/CompilationManager/AssemblyLoader.cs @@ -32,7 +32,9 @@ public static class AssemblyLoader private static readonly IDictionary SyntaxTreeResources = new Dictionary() { +#pragma warning disable CS0618 // Type or member is obsolete { DotnetCoreDll.ResourceName, null }, +#pragma warning restore CS0618 // Type or member is obsolete { DotnetCoreDll.ResourceNameQsDataBondV1, typeof(BondSchemas.V1.QsCompilation) }, { DotnetCoreDll.ResourceNameQsDataBondV2, typeof(BondSchemas.V2.QsCompilation) } }; @@ -143,7 +145,6 @@ private static bool LoadSyntaxTree( byte[] byteArray, string resourceName, [NotNullWhen(true)] out QsCompilation? compilation, - BondSchemas.Protocols.Option[]? options = null, Action? onDeserializationException = null) { compilation = null; @@ -161,8 +162,7 @@ private static bool LoadSyntaxTree( { compilation = BondSchemas.Protocols.DeserializeQsCompilationFromSimpleBinary( byteArray, - type, - options); + type); } else { @@ -241,7 +241,7 @@ private static bool FromResource( string? resourceName = null; ManifestResource resource = default; - // + // Get the resource name of the syntax tree resource name included in this DLL. foreach (var item in SyntaxTreeResources) { if (metadataReader.Resources().TryGetValue(item.Key, out resource)) @@ -273,16 +273,10 @@ private static bool FromResource( var resourceLength = BitConverter.ToInt32(image.GetContent(absResourceOffset, sizeof(int)).ToArray(), 0); var resourceData = image.GetContent(absResourceOffset + sizeof(int), resourceLength).ToArray(); PerformanceTracking.TaskEnd(PerformanceTracking.Task.LoadDataFromReferenceToStream); - var options = new BondSchemas.Protocols.Option[] - { - BondSchemas.Protocols.Option.ExcludeNamespaceDocumentation - }; - return LoadSyntaxTree( resourceData, resourceName, out compilation, - options, onDeserializationException); } From 02c5e16ab5c3cc01e024e7a3bd03545246cd397f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Zaragoza=20Cort=C3=A9s?= Date: Fri, 5 Feb 2021 15:06:07 -0800 Subject: [PATCH 13/17] Removed a few TODOs. --- src/QsCompiler/BondSchemas/Protocols.cs | 3 +-- src/QsCompiler/BondSchemas/Translators.cs | 2 +- src/QsCompiler/CompilationManager/AssemblyLoader.cs | 13 ++++++------- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/QsCompiler/BondSchemas/Protocols.cs b/src/QsCompiler/BondSchemas/Protocols.cs index 026fc5614b..fbe3d311bf 100644 --- a/src/QsCompiler/BondSchemas/Protocols.cs +++ b/src/QsCompiler/BondSchemas/Protocols.cs @@ -135,8 +135,7 @@ private static object DeserializeBondSchemaFromSimpleBinary( } #pragma warning restore IDE0001 // Simplify Names - // TODO: Use specific message. - throw new ArgumentException(); + throw new ArgumentException($"Unknown Bond schema type '{bondSchemaType}'"); } private static SimpleBinaryDeserializer GetSimpleBinaryDeserializer(Type bondSchemaType) diff --git a/src/QsCompiler/BondSchemas/Translators.cs b/src/QsCompiler/BondSchemas/Translators.cs index a20644cf2f..61d3222238 100644 --- a/src/QsCompiler/BondSchemas/Translators.cs +++ b/src/QsCompiler/BondSchemas/Translators.cs @@ -23,7 +23,7 @@ public static SyntaxTree.QsCompilation FromBondSchemaToSyntaxTree( default: // TODO: Use a more meaningful message. - throw new ArgumentException(); + throw new ArgumentException($"Unknown Bond schema type '{typeof(TBond)}'"); #pragma warning restore IDE0001 // Simplify Names } } diff --git a/src/QsCompiler/CompilationManager/AssemblyLoader.cs b/src/QsCompiler/CompilationManager/AssemblyLoader.cs index de166079b1..d05ad47c5d 100644 --- a/src/QsCompiler/CompilationManager/AssemblyLoader.cs +++ b/src/QsCompiler/CompilationManager/AssemblyLoader.cs @@ -19,6 +19,8 @@ namespace Microsoft.Quantum.QsCompiler { + using BondQsCompilation = BondSchemas.V1.QsCompilation; + /// /// This class relies on the ECMA-335 standard to extract information contained in compiled binaries. /// The standard can be found here: https://www.ecma-international.org/publications/files/ECMA-ST/ECMA-335.pdf, @@ -35,8 +37,10 @@ public static class AssemblyLoader #pragma warning disable CS0618 // Type or member is obsolete { DotnetCoreDll.ResourceName, null }, #pragma warning restore CS0618 // Type or member is obsolete +#pragma warning disable IDE0001 // Simplify Names { DotnetCoreDll.ResourceNameQsDataBondV1, typeof(BondSchemas.V1.QsCompilation) }, { DotnetCoreDll.ResourceNameQsDataBondV2, typeof(BondSchemas.V2.QsCompilation) } +#pragma warning restore IDE0001 // Simplify Names }; /// @@ -125,9 +129,7 @@ public static bool LoadSyntaxTree( try { PerformanceTracking.TaskStart(PerformanceTracking.Task.SyntaxTreeDeserialization); - // TODO: This should be always call the latest version of the Bond schemas. - // TODO: Call the new version of LoadSyntaxTree leveraging ResourceName. - compilation = BondSchemas.Protocols.DeserializeQsCompilationFromSimpleBinary(byteArray, typeof(BondSchemas.V1.QsCompilation)); + compilation = BondSchemas.Protocols.DeserializeQsCompilationFromSimpleBinary(byteArray, typeof(BondQsCompilation)); PerformanceTracking.TaskEnd(PerformanceTracking.Task.SyntaxTreeDeserialization); } catch (Exception ex) @@ -139,8 +141,6 @@ public static bool LoadSyntaxTree( return compilation != null && IsValidCompilation(compilation); } - // TODO: Document. - // TODO: This could be private. private static bool LoadSyntaxTree( byte[] byteArray, string resourceName, @@ -150,8 +150,7 @@ private static bool LoadSyntaxTree( compilation = null; if (!SyntaxTreeResources.TryGetValue(resourceName, out var type)) { - // TODO: Provide a meaningful error message. - onDeserializationException?.Invoke(new ArgumentException()); + onDeserializationException?.Invoke(new ArgumentException($"Unknown syntax tree resource name '{resourceName}'")); return false; } From e7a1a91f679dc44ba903b94bb98caec9e0d2fba2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Zaragoza=20Cort=C3=A9s?= Date: Fri, 5 Feb 2021 15:20:42 -0800 Subject: [PATCH 14/17] Change to new version of Bond shcema. --- src/QsCompiler/BondSchemas/Protocols.cs | 13 ++++++------- src/QsCompiler/BondSchemas/Translators.cs | 5 ++--- src/QsCompiler/CompilationManager/AssemblyLoader.cs | 2 +- src/QsCompiler/DataStructures/ReservedKeywords.fs | 2 +- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/QsCompiler/BondSchemas/Protocols.cs b/src/QsCompiler/BondSchemas/Protocols.cs index fbe3d311bf..e053ca7ed9 100644 --- a/src/QsCompiler/BondSchemas/Protocols.cs +++ b/src/QsCompiler/BondSchemas/Protocols.cs @@ -13,7 +13,7 @@ namespace Microsoft.Quantum.QsCompiler.BondSchemas { - using BondQsCompilation = V1.QsCompilation; + using BondQsCompilation = V2.QsCompilation; using SimpleBinaryDeserializer = Deserializer>; using SimpleBinarySerializer = Serializer>; @@ -31,8 +31,8 @@ public static class Protocols { #pragma warning disable IDE0001 // Simplify Names { typeof(V1.QsCompilation), null }, -#pragma warning restore IDE0001 // Simplify Names { typeof(V2.QsCompilation), null } +#pragma warning restore IDE0001 // Simplify Names }; private static Task? serializerInitialization = null; @@ -117,7 +117,7 @@ public static void SerializeQsCompilationToSimpleBinary( stream.Flush(); stream.Position = 0; - } + } private static object DeserializeBondSchemaFromSimpleBinary( SimpleBinaryReader reader, @@ -129,9 +129,9 @@ private static object DeserializeBondSchemaFromSimpleBinary( { return deserializer.Deserialize(reader); } - else if (bondSchemaType == typeof(BondQsCompilation)) + else if (bondSchemaType == typeof(V2.QsCompilation)) { - return deserializer.Deserialize(reader); + return deserializer.Deserialize(reader); } #pragma warning restore IDE0001 // Simplify Names @@ -181,8 +181,7 @@ private static Task TryInitializeDeserializer(Type bon VerifyLockAcquired(BondSharedDataStructuresLock); if (!DeserializerInitializations.TryGetValue(bondSchemaType, out var deserializerInitialization)) { - // TODO: Use the correct message. - throw new ArgumentException(); + throw new ArgumentException($"Unknown Bond schema type '{bondSchemaType}'"); } if (deserializerInitialization == null) diff --git a/src/QsCompiler/BondSchemas/Translators.cs b/src/QsCompiler/BondSchemas/Translators.cs index 61d3222238..2561bdeb73 100644 --- a/src/QsCompiler/BondSchemas/Translators.cs +++ b/src/QsCompiler/BondSchemas/Translators.cs @@ -5,7 +5,7 @@ namespace Microsoft.Quantum.QsCompiler.BondSchemas { - using BondQsCompilation = V1.QsCompilation; + using BondQsCompilation = V2.QsCompilation; internal static class Translators { @@ -22,13 +22,12 @@ public static SyntaxTree.QsCompilation FromBondSchemaToSyntaxTree( return V2.CompilerObjectTranslator.CreateQsCompilation(bondCompilationV2); default: - // TODO: Use a more meaningful message. throw new ArgumentException($"Unknown Bond schema type '{typeof(TBond)}'"); #pragma warning restore IDE0001 // Simplify Names } } public static BondQsCompilation FromSyntaxTreeToBondSchema(SyntaxTree.QsCompilation qsCompilation) => - V1.BondSchemaTranslator.CreateBondCompilation(qsCompilation); + V2.BondSchemaTranslator.CreateBondCompilation(qsCompilation); } } diff --git a/src/QsCompiler/CompilationManager/AssemblyLoader.cs b/src/QsCompiler/CompilationManager/AssemblyLoader.cs index d05ad47c5d..3a9a50d980 100644 --- a/src/QsCompiler/CompilationManager/AssemblyLoader.cs +++ b/src/QsCompiler/CompilationManager/AssemblyLoader.cs @@ -19,7 +19,7 @@ namespace Microsoft.Quantum.QsCompiler { - using BondQsCompilation = BondSchemas.V1.QsCompilation; + using BondQsCompilation = BondSchemas.V2.QsCompilation; /// /// This class relies on the ECMA-335 standard to extract information contained in compiled binaries. diff --git a/src/QsCompiler/DataStructures/ReservedKeywords.fs b/src/QsCompiler/DataStructures/ReservedKeywords.fs index 159f48ade5..31092dab04 100644 --- a/src/QsCompiler/DataStructures/ReservedKeywords.fs +++ b/src/QsCompiler/DataStructures/ReservedKeywords.fs @@ -296,7 +296,7 @@ module DotnetCoreDll = let ResourceNameQsDataBondV1 = "__qsharp_data_bond_v1__.bson" let ResourceNameQsDataBondV2 = "__qsharp_data_bond_v2__.bson" // Should always provide the name of the resource currently used by the compiler to attach the syntax tree to a DLL. - let SyntaxTreeResourceName = ResourceNameQsDataBondV1 + let SyntaxTreeResourceName = ResourceNameQsDataBondV2 let MetadataNamespace = "__qsharp__" let ReferenceAlias = "__qsharp_reference__" let MetadataType = "Metadata" From 6f452cb9735955ce0a41e47e11bd283b7482599f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Zaragoza=20Cort=C3=A9s?= Date: Fri, 5 Feb 2021 15:30:36 -0800 Subject: [PATCH 15/17] Small changes unrelated to code. --- src/QsCompiler/BondSchemas/Protocols.cs | 2 +- src/QsCompiler/CompilationManager/AssemblyLoader.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/QsCompiler/BondSchemas/Protocols.cs b/src/QsCompiler/BondSchemas/Protocols.cs index e053ca7ed9..9bb6f0b4d8 100644 --- a/src/QsCompiler/BondSchemas/Protocols.cs +++ b/src/QsCompiler/BondSchemas/Protocols.cs @@ -117,7 +117,7 @@ public static void SerializeQsCompilationToSimpleBinary( stream.Flush(); stream.Position = 0; - } + } private static object DeserializeBondSchemaFromSimpleBinary( SimpleBinaryReader reader, diff --git a/src/QsCompiler/CompilationManager/AssemblyLoader.cs b/src/QsCompiler/CompilationManager/AssemblyLoader.cs index 3a9a50d980..1c0fde8433 100644 --- a/src/QsCompiler/CompilationManager/AssemblyLoader.cs +++ b/src/QsCompiler/CompilationManager/AssemblyLoader.cs @@ -240,7 +240,7 @@ private static bool FromResource( string? resourceName = null; ManifestResource resource = default; - // Get the resource name of the syntax tree resource name included in this DLL. + // Get the resource name of the syntax tree resource name included in this assembly. foreach (var item in SyntaxTreeResources) { if (metadataReader.Resources().TryGetValue(item.Key, out resource)) From 181843262ff4b1cdc97f0c5977e2da1239083836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Zaragoza=20Cort=C3=A9s?= Date: Mon, 8 Feb 2021 21:44:46 -0800 Subject: [PATCH 16/17] Created script to compile Bond schemas. --- src/QsCompiler/BondSchemas/compile-bond.ps1 | 97 +++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 src/QsCompiler/BondSchemas/compile-bond.ps1 diff --git a/src/QsCompiler/BondSchemas/compile-bond.ps1 b/src/QsCompiler/BondSchemas/compile-bond.ps1 new file mode 100644 index 0000000000..26f7bd8e6f --- /dev/null +++ b/src/QsCompiler/BondSchemas/compile-bond.ps1 @@ -0,0 +1,97 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +<# + .SYNOPSIS + Compiles Bond schemas (*.bond). + + .DESCRIPTION + Compiles Bond schemas (*.bond) present in the parent directory of this script and all its subdirectories. + + .NOTES + Assumes Bond already installed through nuget and available at the "\.nuget\packages\bond.csharp\" path relative to the user's base directory. + E.g. "C:\Users\johndoe\.nuget\packages\bond.csharp\" +#> + +# Global constants. +Set-Variable -Name BondVersion -Value "9.0.3" -Option Constant + +function Get-BondResources +{ + param( + [string]$version + ); + + $bondCompiler = Join-Path $env:UserProfile "\.nuget\packages\bond.csharp\${version}\tools\gbc.exe" + if (!(Test-Path $bondCompiler -PathType Leaf)) + { + Write-Host "Bond compiler could not be found at '${bondCompiler}'" + $bondCompiler = $null + } + + $bondImportDir = Join-Path $env:UserProfile "\.nuget\packages\bond.csharp\${version}\tools\inc" + if (!(Test-Path $bondImportDir)) + { + Write-Host "Bond import directory could not be found at '${bondImportDir}'" + $bondImportDir = $null + } + + return $bondCompiler, $bondImportDir +} + +function Compile-BondToCSharp { + param( + [string]$Schema, + [string]$Compiler, + [string]$ImportDir + ); + + $schemaFullPath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Schema) + $schemaName = [System.Io.Path]::GetFileNameWithoutExtension($schemaFullPath) + $outputDirectory = (Get-Item $schemaFullPath).Directory.FullName + $compileCommand = + "$Compiler" + + " c#" + + " --namespace=bond=Bond" + + " --import-dir=`"" + $ImportDir + "`"" + + " --output-dir=`"" + $outputDirectory + "`"" + + " $schemaFullPath" + + Write-Host "Bond compiler command: $compileCommand" + iex $compileCommand + + $generatedCSharpFileName = "$schemaName" + "_types.cs" + $generatedCSharpFilePath = Join-Path $outputDirectory $generatedCSharpFileName + $newGeneratedCSharpFileName = "${schemaName}.cs" + $newGeneratedCSharpFilePath = Join-Path $outputDirectory $newGeneratedCSharpFileName + if (Test-Path $newGeneratedCSharpFilePath) + { + Write-Host "Removing existing file `"$newGeneratedCSharpFilePath`"" + Remove-Item $newGeneratedCSharpFilePath + } + + Write-Host "Renaming generated C# file: `"$generatedCSharpFilePath`" -> `"$newGeneratedCSharpFilePath`"" + Rename-Item -Path $generatedCSharpFilePath -NewName $newGeneratedCSharpFileName -Force +} + +Write-Host "Using Bond version: $BondVersion" + +# Get the path to the Bond compiler (gbc.exe) and the Bond import directory. +$bondCompiler, $bondImportDir = Get-BondResources -Version $BondVersion +if (($bondCompiler -eq $null) -or ($bondImportDir -eq $null)) +{ + Write-Error "Bond resources not found" + exit 1 +} + +Write-Host "Using Bond compiler: `"$bondCompiler`"" +Write-Host "Using Bond import directory: `"$bondImportDir`"" +Write-Host "`n" + +# Go through all *.bond files recursively and compile them. +Get-ChildItem -Path $PSScriptRoot -Filter *.bond -Recurse -File | ForEach-Object { + $bondSchema = $_.FullName + Write-Host "Compiling $bondSchema ..." + Compile-BondToCSharp -Schema $bondSchema -Compiler $bondCompiler -ImportDir $bondImportDir + Write-Host "`n" +} From bac7e1b59b3b1d36be8c36e916a4719578480f86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Zaragoza=20Cort=C3=A9s?= Date: Mon, 8 Feb 2021 22:53:38 -0800 Subject: [PATCH 17/17] Use generated C# files from Bond. --- src/QsCompiler/BondSchemas/BondSchemas.csproj | 2 +- .../V1/CompilerDataStructuresV1.cs | 1791 +++++++++++++++++ .../V2/CompilerDataStructuresV2.cs | 77 + 3 files changed, 1869 insertions(+), 1 deletion(-) create mode 100644 src/QsCompiler/BondSchemas/V1/CompilerDataStructuresV1.cs create mode 100644 src/QsCompiler/BondSchemas/V2/CompilerDataStructuresV2.cs diff --git a/src/QsCompiler/BondSchemas/BondSchemas.csproj b/src/QsCompiler/BondSchemas/BondSchemas.csproj index f2f6bb5b3f..0020dee504 100644 --- a/src/QsCompiler/BondSchemas/BondSchemas.csproj +++ b/src/QsCompiler/BondSchemas/BondSchemas.csproj @@ -9,7 +9,7 @@ - + diff --git a/src/QsCompiler/BondSchemas/V1/CompilerDataStructuresV1.cs b/src/QsCompiler/BondSchemas/V1/CompilerDataStructuresV1.cs new file mode 100644 index 0000000000..82c4ce958d --- /dev/null +++ b/src/QsCompiler/BondSchemas/V1/CompilerDataStructuresV1.cs @@ -0,0 +1,1791 @@ + +//------------------------------------------------------------------------------ +// This code was generated by a tool. +// +// Tool : Bond Compiler 0.12.1.0 +// Input filename: C:\Microsoft\ReposB\qsharp-compiler\src\QsCompiler\BondSchemas\V1\CompilerDataStructuresV1.bond +// Output filename: CompilerDataStructuresV1_types.cs +// +// Changes to this file may cause incorrect behavior and will be lost when +// the code is regenerated. +// +//------------------------------------------------------------------------------ + + +// suppress "Missing XML comment for publicly visible type or member" +#pragma warning disable 1591 + + +#region ReSharper warnings +// ReSharper disable PartialTypeWithSinglePart +// ReSharper disable RedundantNameQualifier +// ReSharper disable InconsistentNaming +// ReSharper disable CheckNamespace +// ReSharper disable UnusedParameter.Local +// ReSharper disable RedundantUsingDirective +#endregion + +namespace Microsoft.Quantum.QsCompiler.BondSchemas.V1 +{ + using System.Collections.Generic; + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class Position + { + [global::Bond.Id(5)] + public int Line { get; set; } + + [global::Bond.Id(10)] + public int Column { get; set; } + + public Position() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.Position", "Position") + {} + + protected Position(string fullName, string name) + { + + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class Range + { + [global::Bond.Id(5)] + public Position Start { get; set; } + + [global::Bond.Id(10)] + public Position End { get; set; } + + public Range() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.Range", "Range") + {} + + protected Range(string fullName, string name) + { + Start = new Position(); + End = new Position(); + } + } + + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public enum AccessModifier + { + DefaultAccess, + Internal, + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class Modifiers + { + [global::Bond.Id(5)] + public AccessModifier Access { get; set; } + + public Modifiers() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.Modifiers", "Modifiers") + {} + + protected Modifiers(string fullName, string name) + { + Access = AccessModifier.DefaultAccess; + } + } + + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public enum QsGeneratorDirective + { + SelfInverse, + Invert, + Distribute, + InvalidGenerator, + } + + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public enum QsResult + { + Zero, + One, + } + + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public enum QsPauli + { + PauliX, + PauliY, + PauliZ, + PauliI, + } + + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public enum QsExpressionKind + { + UnitValue, + Identifier, + ValueTuple, + IntLiteral, + BigIntLiteral, + DoubleLiteral, + BoolLiteral, + StringLiteral, + ResultLiteral, + PauliLiteral, + RangeLiteral, + NewArray, + ValueArray, + ArrayItem, + NamedItem, + NEG, + NOT, + BNOT, + ADD, + SUB, + MUL, + DIV, + MOD, + POW, + EQ, + NEQ, + LT, + LTE, + GT, + GTE, + AND, + OR, + BOR, + BAND, + BXOR, + LSHIFT, + RSHIFT, + CONDITIONAL, + CopyAndUpdate, + UnwrapApplication, + AdjointApplication, + ControlledApplication, + CallLikeExpression, + MissingExpr, + InvalidExpr, + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsExpressionKindIdentifier + { + [global::Bond.Id(5), global::Bond.Type(typeof(global::Bond.Tag.classT))] + public TSymbol Symbol { get; set; } + + [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.nullable>))] + public List Types { get; set; } + + public QsExpressionKindIdentifier() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.QsExpressionKindIdentifier", "QsExpressionKindIdentifier") + {} + + protected QsExpressionKindIdentifier(string fullName, string name) + { + Symbol = global::Bond.GenericFactory.Create(); + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsExpressionKindStringLiteral + { + [global::Bond.Id(5)] + public string StringLiteral { get; set; } + + [global::Bond.Id(10), global::Bond.Type(typeof(List))] + public List Expressions { get; set; } + + public QsExpressionKindStringLiteral() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.QsExpressionKindStringLiteral", "QsExpressionKindStringLiteral") + {} + + protected QsExpressionKindStringLiteral(string fullName, string name) + { + StringLiteral = ""; + Expressions = new List(); + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsExpressionKindExpressionDouble + { + [global::Bond.Id(5), global::Bond.Type(typeof(global::Bond.Tag.classT))] + public TExpression Expression1 { get; set; } + + [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.classT))] + public TExpression Expression2 { get; set; } + + public QsExpressionKindExpressionDouble() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.QsExpressionKindExpressionDouble", "QsExpressionKindExpressionDouble") + {} + + protected QsExpressionKindExpressionDouble(string fullName, string name) + { + Expression1 = global::Bond.GenericFactory.Create(); + Expression2 = global::Bond.GenericFactory.Create(); + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsExpressionKindExpressionTriple + { + [global::Bond.Id(5), global::Bond.Type(typeof(global::Bond.Tag.classT))] + public TExpression Expression1 { get; set; } + + [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.classT))] + public TExpression Expression2 { get; set; } + + [global::Bond.Id(15), global::Bond.Type(typeof(global::Bond.Tag.classT))] + public TExpression Expression3 { get; set; } + + public QsExpressionKindExpressionTriple() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.QsExpressionKindExpressionTriple", "QsExpressionKindExpressionTriple") + {} + + protected QsExpressionKindExpressionTriple(string fullName, string name) + { + Expression1 = global::Bond.GenericFactory.Create(); + Expression2 = global::Bond.GenericFactory.Create(); + Expression3 = global::Bond.GenericFactory.Create(); + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsExpressionKindNewArray + { + [global::Bond.Id(5), global::Bond.Type(typeof(global::Bond.Tag.classT))] + public TType Type { get; set; } + + [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.classT))] + public TExpression Expression { get; set; } + + public QsExpressionKindNewArray() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.QsExpressionKindNewArray", "QsExpressionKindNewArray") + {} + + protected QsExpressionKindNewArray(string fullName, string name) + { + Type = global::Bond.GenericFactory.Create(); + Expression = global::Bond.GenericFactory.Create(); + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsExpressionKindNamedItem + { + [global::Bond.Id(5), global::Bond.Type(typeof(global::Bond.Tag.classT))] + public TExpression Expression { get; set; } + + [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.classT))] + public TSymbol Symbol { get; set; } + + public QsExpressionKindNamedItem() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.QsExpressionKindNamedItem", "QsExpressionKindNamedItem") + {} + + protected QsExpressionKindNamedItem(string fullName, string name) + { + Expression = global::Bond.GenericFactory.Create(); + Symbol = global::Bond.GenericFactory.Create(); + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsExpressionKindComposition + { + [global::Bond.Id(5), global::Bond.Required] + public QsExpressionKind Kind { get; set; } + + [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.nullable>))] + public QsExpressionKindIdentifier Identifier { get; set; } + + [global::Bond.Id(20), global::Bond.Type(typeof(global::Bond.Tag.nullable))] + public long? IntLiteral { get; set; } + + [global::Bond.Id(25), global::Bond.Type(typeof(global::Bond.Tag.nullable>))] + public System.ArraySegment BigIntLiteral { get; set; } + + [global::Bond.Id(30), global::Bond.Type(typeof(global::Bond.Tag.nullable))] + public double? DoubleLiteral { get; set; } + + [global::Bond.Id(35), global::Bond.Type(typeof(global::Bond.Tag.nullable))] + public bool? BoolLiteral { get; set; } + + [global::Bond.Id(40), global::Bond.Type(typeof(global::Bond.Tag.nullable>))] + public QsExpressionKindStringLiteral StringLiteral { get; set; } + + [global::Bond.Id(45), global::Bond.Type(typeof(global::Bond.Tag.nullable))] + public QsResult? ResultLiteral { get; set; } + + [global::Bond.Id(50), global::Bond.Type(typeof(global::Bond.Tag.nullable))] + public QsPauli? PauliLiteral { get; set; } + + [global::Bond.Id(55), global::Bond.Type(typeof(global::Bond.Tag.nullable>))] + public QsExpressionKindNewArray NewArray { get; set; } + + [global::Bond.Id(60), global::Bond.Type(typeof(global::Bond.Tag.nullable>))] + public QsExpressionKindNamedItem NamedItem { get; set; } + + [global::Bond.Id(65), global::Bond.Type(typeof(global::Bond.Tag.nullable))] + public TExpression Expression { get; set; } + + [global::Bond.Id(70), global::Bond.Type(typeof(global::Bond.Tag.nullable>))] + public QsExpressionKindExpressionDouble ExpressionDouble { get; set; } + + [global::Bond.Id(75), global::Bond.Type(typeof(global::Bond.Tag.nullable>))] + public QsExpressionKindExpressionTriple ExpressionTriple { get; set; } + + [global::Bond.Id(80), global::Bond.Type(typeof(global::Bond.Tag.nullable>))] + public List ExpressionArray { get; set; } + + public QsExpressionKindComposition() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.QsExpressionKindComposition", "QsExpressionKindComposition") + {} + + protected QsExpressionKindComposition(string fullName, string name) + { + Kind = QsExpressionKind.InvalidExpr; + } + } + + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public enum QsBindingKind + { + ImmutableBinding, + MutableBinding, + } + + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public enum QsSpecializationKind + { + QsBody, + QsAdjoint, + QsControlled, + QsControlledAdjoint, + } + + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public enum QsCallableKind + { + Operation, + Function, + TypeConstructor, + } + + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public enum QsQubitScopeKind + { + Allocate, + Borrow, + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsQualifiedName + { + [global::Bond.Id(5)] + public string Namespace { get; set; } + + [global::Bond.Id(10)] + public string Name { get; set; } + + public QsQualifiedName() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.QsQualifiedName", "QsQualifiedName") + {} + + protected QsQualifiedName(string fullName, string name) + { + Namespace = ""; + Name = ""; + } + } + + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public enum SymbolTupleKind + { + InvalidItem, + VariableName, + VariableNameTuple, + DiscardedItem, + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class SymbolTuple + { + [global::Bond.Id(5), global::Bond.Required] + public SymbolTupleKind Kind { get; set; } + + [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.nullable))] + public string VariableName { get; set; } + + [global::Bond.Id(15), global::Bond.Type(typeof(global::Bond.Tag.nullable>))] + public List VariableNameTuple { get; set; } + + public SymbolTuple() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.SymbolTuple", "SymbolTuple") + {} + + protected SymbolTuple(string fullName, string name) + { + Kind = SymbolTupleKind.InvalidItem; + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsBinding + { + [global::Bond.Id(5)] + public QsBindingKind Kind { get; set; } + + [global::Bond.Id(10)] + public SymbolTuple Lhs { get; set; } + + [global::Bond.Id(15), global::Bond.Type(typeof(global::Bond.Tag.classT))] + public T Rhs { get; set; } + + public QsBinding() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.QsBinding", "QsBinding") + {} + + protected QsBinding(string fullName, string name) + { + Kind = QsBindingKind.ImmutableBinding; + Lhs = new SymbolTuple(); + Rhs = global::Bond.GenericFactory.Create(); + } + } + + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public enum IdentifierKind + { + LocalVariable, + GlobalCallable, + InvalidIdentifier, + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class Identifier + { + [global::Bond.Id(5), global::Bond.Required] + public IdentifierKind Kind { get; set; } + + [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.nullable))] + public string LocalVariable { get; set; } + + [global::Bond.Id(15), global::Bond.Type(typeof(global::Bond.Tag.nullable))] + public QsQualifiedName GlobalCallable { get; set; } + + public Identifier() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.Identifier", "Identifier") + {} + + protected Identifier(string fullName, string name) + { + Kind = IdentifierKind.LocalVariable; + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsLocation + { + [global::Bond.Id(5)] + public Position Offset { get; set; } + + [global::Bond.Id(10)] + public Range Range { get; set; } + + public QsLocation() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.QsLocation", "QsLocation") + {} + + protected QsLocation(string fullName, string name) + { + Offset = new Position(); + Range = new Range(); + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsTypeParameter + { + [global::Bond.Id(5)] + public QsQualifiedName Origin { get; set; } + + [global::Bond.Id(10)] + public string TypeName { get; set; } + + [global::Bond.Id(15), global::Bond.Type(typeof(global::Bond.Tag.nullable))] + public Range Range { get; set; } + + public QsTypeParameter() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.QsTypeParameter", "QsTypeParameter") + {} + + protected QsTypeParameter(string fullName, string name) + { + Origin = new QsQualifiedName(); + TypeName = ""; + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class UserDefinedType + { + [global::Bond.Id(5)] + public string Namespace { get; set; } + + [global::Bond.Id(10)] + public string Name { get; set; } + + [global::Bond.Id(15), global::Bond.Type(typeof(global::Bond.Tag.nullable))] + public Range Range { get; set; } + + public UserDefinedType() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.UserDefinedType", "UserDefinedType") + {} + + protected UserDefinedType(string fullName, string name) + { + Namespace = ""; + Name = ""; + } + } + + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public enum OpProperty + { + Adjointable, + Controllable, + } + + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public enum CharacteristicsKind + { + EmptySet, + SimpleSet, + Union, + Intersection, + InvalidSetExpr, + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class CharacteristicsKindSetOperation + { + [global::Bond.Id(5), global::Bond.Type(typeof(global::Bond.Tag.classT))] + public T Set1 { get; set; } + + [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.classT))] + public T Set2 { get; set; } + + public CharacteristicsKindSetOperation() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.CharacteristicsKindSetOperation", "CharacteristicsKindSetOperation") + {} + + protected CharacteristicsKindSetOperation(string fullName, string name) + { + Set1 = global::Bond.GenericFactory.Create(); + Set2 = global::Bond.GenericFactory.Create(); + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class CharacteristicsKindComposition + { + [global::Bond.Id(5), global::Bond.Required] + public CharacteristicsKind Kind { get; set; } + + [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.nullable))] + public OpProperty? SimpleSet { get; set; } + + [global::Bond.Id(15), global::Bond.Type(typeof(global::Bond.Tag.nullable>))] + public CharacteristicsKindSetOperation SetOperation { get; set; } + + public CharacteristicsKindComposition() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.CharacteristicsKindComposition", "CharacteristicsKindComposition") + {} + + protected CharacteristicsKindComposition(string fullName, string name) + { + Kind = CharacteristicsKind.InvalidSetExpr; + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class ResolvedCharacteristics + { + [global::Bond.Id(5)] + public CharacteristicsKindComposition Expression { get; set; } + + public ResolvedCharacteristics() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.ResolvedCharacteristics", "ResolvedCharacteristics") + {} + + protected ResolvedCharacteristics(string fullName, string name) + { + Expression = new CharacteristicsKindComposition(); + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class InferredCallableInformation + { + [global::Bond.Id(5)] + public bool IsSelfAdjoint { get; set; } + + [global::Bond.Id(10)] + public bool IsIntrinsic { get; set; } + + public InferredCallableInformation() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.InferredCallableInformation", "InferredCallableInformation") + {} + + protected InferredCallableInformation(string fullName, string name) + { + + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class CallableInformation + { + [global::Bond.Id(5)] + public ResolvedCharacteristics Characteristics { get; set; } + + [global::Bond.Id(10)] + public InferredCallableInformation InferredInformation { get; set; } + + public CallableInformation() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.CallableInformation", "CallableInformation") + {} + + protected CallableInformation(string fullName, string name) + { + Characteristics = new ResolvedCharacteristics(); + InferredInformation = new InferredCallableInformation(); + } + } + + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public enum QsTypeKind + { + UnitType, + Int, + BigInt, + Double, + Bool, + String, + Qubit, + Result, + Pauli, + Range, + ArrayType, + TupleType, + UserDefinedType, + TypeParameter, + Operation, + Function, + MissingType, + InvalidType, + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsTypeKindFunction + { + [global::Bond.Id(5), global::Bond.Type(typeof(global::Bond.Tag.classT))] + public T Type1 { get; set; } + + [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.classT))] + public T Type2 { get; set; } + + public QsTypeKindFunction() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.QsTypeKindFunction", "QsTypeKindFunction") + {} + + protected QsTypeKindFunction(string fullName, string name) + { + Type1 = global::Bond.GenericFactory.Create(); + Type2 = global::Bond.GenericFactory.Create(); + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsTypeKindOperation + { + [global::Bond.Id(5), global::Bond.Type(typeof(global::Bond.Tag.classT))] + public TType Type1 { get; set; } + + [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.classT))] + public TType Type2 { get; set; } + + [global::Bond.Id(15), global::Bond.Type(typeof(global::Bond.Tag.classT))] + public TCharacteristics Characteristics { get; set; } + + public QsTypeKindOperation() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.QsTypeKindOperation", "QsTypeKindOperation") + {} + + protected QsTypeKindOperation(string fullName, string name) + { + Type1 = global::Bond.GenericFactory.Create(); + Type2 = global::Bond.GenericFactory.Create(); + Characteristics = global::Bond.GenericFactory.Create(); + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsTypeKindComposition + { + [global::Bond.Id(5), global::Bond.Required] + public QsTypeKind Kind { get; set; } + + [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.nullable))] + public TType ArrayType { get; set; } + + [global::Bond.Id(15), global::Bond.Type(typeof(global::Bond.Tag.nullable>))] + public List TupleType { get; set; } + + [global::Bond.Id(20), global::Bond.Type(typeof(global::Bond.Tag.nullable))] + public TUdt UserDefinedType { get; set; } + + [global::Bond.Id(25), global::Bond.Type(typeof(global::Bond.Tag.nullable))] + public TParam TypeParameter { get; set; } + + [global::Bond.Id(30), global::Bond.Type(typeof(global::Bond.Tag.nullable>))] + public QsTypeKindOperation Operation { get; set; } + + [global::Bond.Id(35), global::Bond.Type(typeof(global::Bond.Tag.nullable>))] + public QsTypeKindFunction Function { get; set; } + + public QsTypeKindComposition() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.QsTypeKindComposition", "QsTypeKindComposition") + {} + + protected QsTypeKindComposition(string fullName, string name) + { + Kind = QsTypeKind.InvalidType; + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class ResolvedType + { + [global::Bond.Id(5)] + public QsTypeKindComposition TypeKind { get; set; } + + public ResolvedType() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.ResolvedType", "ResolvedType") + {} + + protected ResolvedType(string fullName, string name) + { + TypeKind = new QsTypeKindComposition(); + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class InferredExpressionInformation + { + [global::Bond.Id(5)] + public bool IsMutable { get; set; } + + [global::Bond.Id(10)] + public bool HasLocalQuantumDependency { get; set; } + + public InferredExpressionInformation() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.InferredExpressionInformation", "InferredExpressionInformation") + {} + + protected InferredExpressionInformation(string fullName, string name) + { + + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class TypedArgument + { + [global::Bond.Id(5)] + public QsQualifiedName Callable { get; set; } + + [global::Bond.Id(10)] + public string Name { get; set; } + + [global::Bond.Id(15)] + public ResolvedType Resolution { get; set; } + + public TypedArgument() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.TypedArgument", "TypedArgument") + {} + + protected TypedArgument(string fullName, string name) + { + Callable = new QsQualifiedName(); + Name = ""; + Resolution = new ResolvedType(); + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class TypedExpression + { + [global::Bond.Id(5)] + public QsExpressionKindComposition Expression { get; set; } + + [global::Bond.Id(10)] + public List TypedArguments { get; set; } + + [global::Bond.Id(15)] + public ResolvedType ResolvedType { get; set; } + + [global::Bond.Id(20)] + public InferredExpressionInformation InferredInformation { get; set; } + + [global::Bond.Id(25), global::Bond.Type(typeof(global::Bond.Tag.nullable))] + public Range Range { get; set; } + + public TypedExpression() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.TypedExpression", "TypedExpression") + {} + + protected TypedExpression(string fullName, string name) + { + Expression = new QsExpressionKindComposition(); + TypedArguments = new List(); + ResolvedType = new ResolvedType(); + InferredInformation = new InferredExpressionInformation(); + } + } + + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public enum QsInitializerKind + { + SingleQubitAllocation, + QubitRegisterAllocation, + QubitTupleAllocation, + InvalidInitializer, + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsInitializerKindComposition + { + [global::Bond.Id(5), global::Bond.Required] + public QsInitializerKind Kind { get; set; } + + [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.nullable))] + public TExpression QubitRegisterAllocation { get; set; } + + [global::Bond.Id(15), global::Bond.Type(typeof(global::Bond.Tag.nullable>))] + public List QubitTupleAllocation { get; set; } + + public QsInitializerKindComposition() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.QsInitializerKindComposition", "QsInitializerKindComposition") + {} + + protected QsInitializerKindComposition(string fullName, string name) + { + Kind = QsInitializerKind.InvalidInitializer; + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class ResolvedInitializer + { + [global::Bond.Id(5)] + public QsInitializerKindComposition Initializer { get; set; } + + [global::Bond.Id(10)] + public ResolvedType ResolvedType { get; set; } + + public ResolvedInitializer() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.ResolvedInitializer", "ResolvedInitializer") + {} + + protected ResolvedInitializer(string fullName, string name) + { + Initializer = new QsInitializerKindComposition(); + ResolvedType = new ResolvedType(); + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class LocalVariableDeclaration + { + [global::Bond.Id(5), global::Bond.Type(typeof(global::Bond.Tag.classT))] + public TVariableName VariableName { get; set; } + + [global::Bond.Id(10)] + public ResolvedType Type { get; set; } + + [global::Bond.Id(15)] + public InferredExpressionInformation InferredInformation { get; set; } + + [global::Bond.Id(20), global::Bond.Type(typeof(global::Bond.Tag.nullable))] + public Position Position { get; set; } + + [global::Bond.Id(25)] + public Range Range { get; set; } + + public LocalVariableDeclaration() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.LocalVariableDeclaration", "LocalVariableDeclaration") + {} + + protected LocalVariableDeclaration(string fullName, string name) + { + VariableName = global::Bond.GenericFactory.Create(); + Type = new ResolvedType(); + InferredInformation = new InferredExpressionInformation(); + Range = new Range(); + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class LocalDeclarations + { + [global::Bond.Id(5)] + public List> Variables { get; set; } + + public LocalDeclarations() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.LocalDeclarations", "LocalDeclarations") + {} + + protected LocalDeclarations(string fullName, string name) + { + Variables = new List>(); + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsValueUpdate + { + [global::Bond.Id(5)] + public TypedExpression Lhs { get; set; } + + [global::Bond.Id(10)] + public TypedExpression Rhs { get; set; } + + public QsValueUpdate() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.QsValueUpdate", "QsValueUpdate") + {} + + protected QsValueUpdate(string fullName, string name) + { + Lhs = new TypedExpression(); + Rhs = new TypedExpression(); + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsComments + { + [global::Bond.Id(5)] + public List OpeningComments { get; set; } + + [global::Bond.Id(10)] + public List ClosingComments { get; set; } + + public QsComments() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.QsComments", "QsComments") + {} + + protected QsComments(string fullName, string name) + { + OpeningComments = new List(); + ClosingComments = new List(); + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsPositionedBlock + { + [global::Bond.Id(5)] + public QsScope Body { get; set; } + + [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.nullable))] + public QsLocation Location { get; set; } + + [global::Bond.Id(15)] + public QsComments Comments { get; set; } + + public QsPositionedBlock() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.QsPositionedBlock", "QsPositionedBlock") + {} + + protected QsPositionedBlock(string fullName, string name) + { + Body = new QsScope(); + Comments = new QsComments(); + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsConditionalBlock + { + [global::Bond.Id(5)] + public TypedExpression Expression { get; set; } + + [global::Bond.Id(10)] + public QsPositionedBlock Block { get; set; } + + public QsConditionalBlock() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.QsConditionalBlock", "QsConditionalBlock") + {} + + protected QsConditionalBlock(string fullName, string name) + { + Expression = new TypedExpression(); + Block = new QsPositionedBlock(); + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsConditionalStatement + { + [global::Bond.Id(5)] + public List ConditionalBlocks { get; set; } + + [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.nullable))] + public QsPositionedBlock Default { get; set; } + + public QsConditionalStatement() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.QsConditionalStatement", "QsConditionalStatement") + {} + + protected QsConditionalStatement(string fullName, string name) + { + ConditionalBlocks = new List(); + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsLoopItem + { + [global::Bond.Id(5)] + public SymbolTuple SymbolTuple { get; set; } + + [global::Bond.Id(10)] + public ResolvedType ResolvedType { get; set; } + + public QsLoopItem() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.QsLoopItem", "QsLoopItem") + {} + + protected QsLoopItem(string fullName, string name) + { + SymbolTuple = new SymbolTuple(); + ResolvedType = new ResolvedType(); + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsForStatement + { + [global::Bond.Id(5)] + public QsLoopItem LoopItem { get; set; } + + [global::Bond.Id(10)] + public TypedExpression IterationValues { get; set; } + + [global::Bond.Id(15)] + public QsScope Body { get; set; } + + public QsForStatement() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.QsForStatement", "QsForStatement") + {} + + protected QsForStatement(string fullName, string name) + { + LoopItem = new QsLoopItem(); + IterationValues = new TypedExpression(); + Body = new QsScope(); + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsWhileStatement + { + [global::Bond.Id(5)] + public TypedExpression Condition { get; set; } + + [global::Bond.Id(10)] + public QsScope Body { get; set; } + + public QsWhileStatement() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.QsWhileStatement", "QsWhileStatement") + {} + + protected QsWhileStatement(string fullName, string name) + { + Condition = new TypedExpression(); + Body = new QsScope(); + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsRepeatStatement + { + [global::Bond.Id(5)] + public QsPositionedBlock RepeatBlock { get; set; } + + [global::Bond.Id(10)] + public TypedExpression SuccessCondition { get; set; } + + [global::Bond.Id(15)] + public QsPositionedBlock FixupBlock { get; set; } + + public QsRepeatStatement() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.QsRepeatStatement", "QsRepeatStatement") + {} + + protected QsRepeatStatement(string fullName, string name) + { + RepeatBlock = new QsPositionedBlock(); + SuccessCondition = new TypedExpression(); + FixupBlock = new QsPositionedBlock(); + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsConjugation + { + [global::Bond.Id(5)] + public QsPositionedBlock OuterTransformation { get; set; } + + [global::Bond.Id(10)] + public QsPositionedBlock InnerTransformation { get; set; } + + public QsConjugation() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.QsConjugation", "QsConjugation") + {} + + protected QsConjugation(string fullName, string name) + { + OuterTransformation = new QsPositionedBlock(); + InnerTransformation = new QsPositionedBlock(); + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsQubitScope + { + [global::Bond.Id(5)] + public QsQubitScopeKind Kind { get; set; } + + [global::Bond.Id(10)] + public QsBinding Binding { get; set; } + + [global::Bond.Id(15)] + public QsScope Body { get; set; } + + public QsQubitScope() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.QsQubitScope", "QsQubitScope") + {} + + protected QsQubitScope(string fullName, string name) + { + Kind = QsQubitScopeKind.Allocate; + Binding = new QsBinding(); + Body = new QsScope(); + } + } + + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public enum QsStatementKind + { + QsExpressionStatement, + QsReturnStatement, + QsFailStatement, + QsVariableDeclaration, + QsValueUpdate, + QsConditionalStatement, + QsForStatement, + QsWhileStatement, + QsRepeatStatement, + QsConjugation, + QsQubitScope, + EmptyStatement, + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsStatementKindComposition + { + [global::Bond.Id(5), global::Bond.Required] + public QsStatementKind Kind { get; set; } + + [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.nullable))] + public TypedExpression TypedExpression { get; set; } + + [global::Bond.Id(15), global::Bond.Type(typeof(global::Bond.Tag.nullable>))] + public QsBinding VariableDeclaration { get; set; } + + [global::Bond.Id(20), global::Bond.Type(typeof(global::Bond.Tag.nullable))] + public QsValueUpdate ValueUpdate { get; set; } + + [global::Bond.Id(25), global::Bond.Type(typeof(global::Bond.Tag.nullable))] + public QsConditionalStatement ConditionalStatement { get; set; } + + [global::Bond.Id(30), global::Bond.Type(typeof(global::Bond.Tag.nullable))] + public QsForStatement ForStatement { get; set; } + + [global::Bond.Id(35), global::Bond.Type(typeof(global::Bond.Tag.nullable))] + public QsWhileStatement WhileStatement { get; set; } + + [global::Bond.Id(40), global::Bond.Type(typeof(global::Bond.Tag.nullable))] + public QsRepeatStatement RepeatStatement { get; set; } + + [global::Bond.Id(45), global::Bond.Type(typeof(global::Bond.Tag.nullable))] + public QsConjugation Conjugation { get; set; } + + [global::Bond.Id(50), global::Bond.Type(typeof(global::Bond.Tag.nullable))] + public QsQubitScope QubitScope { get; set; } + + public QsStatementKindComposition() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.QsStatementKindComposition", "QsStatementKindComposition") + {} + + protected QsStatementKindComposition(string fullName, string name) + { + Kind = QsStatementKind.EmptyStatement; + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsStatement + { + [global::Bond.Id(5)] + public QsStatementKindComposition Statement { get; set; } + + [global::Bond.Id(10)] + public LocalDeclarations SymbolDeclarations { get; set; } + + [global::Bond.Id(15), global::Bond.Type(typeof(global::Bond.Tag.nullable))] + public QsLocation Location { get; set; } + + [global::Bond.Id(20)] + public QsComments Comments { get; set; } + + public QsStatement() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.QsStatement", "QsStatement") + {} + + protected QsStatement(string fullName, string name) + { + Statement = new QsStatementKindComposition(); + SymbolDeclarations = new LocalDeclarations(); + Comments = new QsComments(); + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsScope + { + [global::Bond.Id(5)] + public List Statements { get; set; } + + [global::Bond.Id(10)] + public LocalDeclarations KnownSymbols { get; set; } + + public QsScope() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.QsScope", "QsScope") + {} + + protected QsScope(string fullName, string name) + { + Statements = new List(); + KnownSymbols = new LocalDeclarations(); + } + } + + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public enum QsLocalSymbolKind + { + ValidName, + InvalidName, + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsLocalSymbol + { + [global::Bond.Id(5), global::Bond.Required] + public QsLocalSymbolKind Kind { get; set; } + + [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.nullable))] + public string Name { get; set; } + + public QsLocalSymbol() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.QsLocalSymbol", "QsLocalSymbol") + {} + + protected QsLocalSymbol(string fullName, string name) + { + Kind = QsLocalSymbolKind.InvalidName; + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsDeclarationAttribute + { + [global::Bond.Id(5), global::Bond.Type(typeof(global::Bond.Tag.nullable))] + public UserDefinedType TypeId { get; set; } + + [global::Bond.Id(10)] + public TypedExpression Argument { get; set; } + + [global::Bond.Id(15)] + public Position Offset { get; set; } + + [global::Bond.Id(20)] + public QsComments Comments { get; set; } + + public QsDeclarationAttribute() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.QsDeclarationAttribute", "QsDeclarationAttribute") + {} + + protected QsDeclarationAttribute(string fullName, string name) + { + Argument = new TypedExpression(); + Offset = new Position(); + Comments = new QsComments(); + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class ResolvedSignature + { + [global::Bond.Id(5)] + public List TypeParameters { get; set; } + + [global::Bond.Id(10)] + public ResolvedType ArgumentType { get; set; } + + [global::Bond.Id(15)] + public ResolvedType ReturnType { get; set; } + + [global::Bond.Id(20)] + public CallableInformation Information { get; set; } + + public ResolvedSignature() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.ResolvedSignature", "ResolvedSignature") + {} + + protected ResolvedSignature(string fullName, string name) + { + TypeParameters = new List(); + ArgumentType = new ResolvedType(); + ReturnType = new ResolvedType(); + Information = new CallableInformation(); + } + } + + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public enum QsTupleKind + { + QsTupleItem, + QsTuple, + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsTuple + { + [global::Bond.Id(5), global::Bond.Required] + public QsTupleKind Kind { get; set; } + + [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.nullable))] + public T Item { get; set; } + + [global::Bond.Id(15), global::Bond.Type(typeof(global::Bond.Tag.nullable>>))] + public List> Items { get; set; } + + public QsTuple() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.QsTuple", "QsTuple") + {} + + protected QsTuple(string fullName, string name) + { + Kind = QsTupleKind.QsTupleItem; + } + } + + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public enum SpecializationImplementationKind + { + Provided, + Intrinsic, + External, + Generated, + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class SpecializationImplementationKindProvided + { + [global::Bond.Id(5)] + public QsTuple> Tuple { get; set; } + + [global::Bond.Id(10)] + public QsScope Implementation { get; set; } + + public SpecializationImplementationKindProvided() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.SpecializationImplementationKindProvided", "SpecializationImplementationKindProvided") + {} + + protected SpecializationImplementationKindProvided(string fullName, string name) + { + Tuple = new QsTuple>(); + Implementation = new QsScope(); + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class SpecializationImplementation + { + [global::Bond.Id(5), global::Bond.Required] + public SpecializationImplementationKind Kind { get; set; } + + [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.nullable))] + public SpecializationImplementationKindProvided Provided { get; set; } + + [global::Bond.Id(15), global::Bond.Type(typeof(global::Bond.Tag.nullable))] + public QsGeneratorDirective? Generated { get; set; } + + public SpecializationImplementation() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.SpecializationImplementation", "SpecializationImplementation") + {} + + protected SpecializationImplementation(string fullName, string name) + { + Kind = SpecializationImplementationKind.Generated; + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsSpecialization + { + [global::Bond.Id(5)] + public QsSpecializationKind Kind { get; set; } + + [global::Bond.Id(10)] + public QsQualifiedName Parent { get; set; } + + [global::Bond.Id(15)] + public List Attributes { get; set; } + + [global::Bond.Id(20)] + public string SourceFile { get; set; } + + [global::Bond.Id(25), global::Bond.Type(typeof(global::Bond.Tag.nullable))] + public QsLocation Location { get; set; } + + [global::Bond.Id(30), global::Bond.Type(typeof(global::Bond.Tag.nullable>))] + public List TypeArguments { get; set; } + + [global::Bond.Id(35)] + public ResolvedSignature Signature { get; set; } + + [global::Bond.Id(40)] + public SpecializationImplementation Implementation { get; set; } + + [global::Bond.Id(45)] + public List Documentation { get; set; } + + [global::Bond.Id(50)] + public QsComments Comments { get; set; } + + public QsSpecialization() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.QsSpecialization", "QsSpecialization") + {} + + protected QsSpecialization(string fullName, string name) + { + Kind = QsSpecializationKind.QsBody; + Parent = new QsQualifiedName(); + Attributes = new List(); + SourceFile = ""; + Signature = new ResolvedSignature(); + Implementation = new SpecializationImplementation(); + Documentation = new List(); + Comments = new QsComments(); + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsCallable + { + [global::Bond.Id(5)] + public QsCallableKind Kind { get; set; } + + [global::Bond.Id(10)] + public QsQualifiedName FullName { get; set; } + + [global::Bond.Id(15)] + public List Attributes { get; set; } + + [global::Bond.Id(20)] + public Modifiers Modifiers { get; set; } + + [global::Bond.Id(25)] + public string SourceFile { get; set; } + + [global::Bond.Id(30), global::Bond.Type(typeof(global::Bond.Tag.nullable))] + public QsLocation Location { get; set; } + + [global::Bond.Id(35)] + public ResolvedSignature Signature { get; set; } + + [global::Bond.Id(40)] + public QsTuple> ArgumentTuple { get; set; } + + [global::Bond.Id(45)] + public List Specializations { get; set; } + + [global::Bond.Id(50)] + public List Documentation { get; set; } + + [global::Bond.Id(55)] + public QsComments Comments { get; set; } + + public QsCallable() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.QsCallable", "QsCallable") + {} + + protected QsCallable(string fullName, string name) + { + Kind = QsCallableKind.Operation; + FullName = new QsQualifiedName(); + Attributes = new List(); + Modifiers = new Modifiers(); + SourceFile = ""; + Signature = new ResolvedSignature(); + ArgumentTuple = new QsTuple>(); + Specializations = new List(); + Documentation = new List(); + Comments = new QsComments(); + } + } + + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public enum QsTypeItemKind + { + Named, + Anonymous, + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsTypeItem + { + [global::Bond.Id(5), global::Bond.Required] + public QsTypeItemKind Kind { get; set; } + + [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.nullable>))] + public LocalVariableDeclaration Named { get; set; } + + [global::Bond.Id(15), global::Bond.Type(typeof(global::Bond.Tag.nullable))] + public ResolvedType Anonymous { get; set; } + + public QsTypeItem() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.QsTypeItem", "QsTypeItem") + {} + + protected QsTypeItem(string fullName, string name) + { + Kind = QsTypeItemKind.Named; + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsCustomType + { + [global::Bond.Id(5)] + public QsQualifiedName FullName { get; set; } + + [global::Bond.Id(10)] + public List Attributes { get; set; } + + [global::Bond.Id(15)] + public Modifiers Modifiers { get; set; } + + [global::Bond.Id(20)] + public string SourceFile { get; set; } + + [global::Bond.Id(25), global::Bond.Type(typeof(global::Bond.Tag.nullable))] + public QsLocation Location { get; set; } + + [global::Bond.Id(30)] + public ResolvedType Type { get; set; } + + [global::Bond.Id(35)] + public QsTuple TypeItems { get; set; } + + [global::Bond.Id(40)] + public List Documentation { get; set; } + + [global::Bond.Id(45)] + public QsComments Comments { get; set; } + + public QsCustomType() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.QsCustomType", "QsCustomType") + {} + + protected QsCustomType(string fullName, string name) + { + FullName = new QsQualifiedName(); + Attributes = new List(); + Modifiers = new Modifiers(); + SourceFile = ""; + Type = new ResolvedType(); + TypeItems = new QsTuple(); + Documentation = new List(); + Comments = new QsComments(); + } + } + + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public enum QsNamespaceElementKind + { + QsCallable, + QsCustomType, + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsNamespaceElement + { + [global::Bond.Id(5), global::Bond.Required] + public QsNamespaceElementKind Kind { get; set; } + + [global::Bond.Id(10), global::Bond.Type(typeof(global::Bond.Tag.nullable))] + public QsCallable Callable { get; set; } + + [global::Bond.Id(15), global::Bond.Type(typeof(global::Bond.Tag.nullable))] + public QsCustomType CustomType { get; set; } + + public QsNamespaceElement() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.QsNamespaceElement", "QsNamespaceElement") + {} + + protected QsNamespaceElement(string fullName, string name) + { + Kind = QsNamespaceElementKind.QsCallable; + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsSourceFileDocumentation + { + [global::Bond.Id(5)] + public string FileName { get; set; } + + [global::Bond.Id(10)] + public List DocumentationItems { get; set; } + + public QsSourceFileDocumentation() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.QsSourceFileDocumentation", "QsSourceFileDocumentation") + {} + + protected QsSourceFileDocumentation(string fullName, string name) + { + FileName = ""; + DocumentationItems = new List(); + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsNamespace + { + [global::Bond.Id(5)] + public string Name { get; set; } + + [global::Bond.Id(10)] + public List Elements { get; set; } + + [global::Bond.Id(15)] + public LinkedList Documentation { get; set; } + + public QsNamespace() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.QsNamespace", "QsNamespace") + {} + + protected QsNamespace(string fullName, string name) + { + Name = ""; + Elements = new List(); + Documentation = new LinkedList(); + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsCompilation + { + [global::Bond.Id(5)] + public List Namespaces { get; set; } + + [global::Bond.Id(10)] + public List EntryPoints { get; set; } + + public QsCompilation() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V1.QsCompilation", "QsCompilation") + {} + + protected QsCompilation(string fullName, string name) + { + Namespaces = new List(); + EntryPoints = new List(); + } + } +} // Microsoft.Quantum.QsCompiler.BondSchemas.V1 diff --git a/src/QsCompiler/BondSchemas/V2/CompilerDataStructuresV2.cs b/src/QsCompiler/BondSchemas/V2/CompilerDataStructuresV2.cs new file mode 100644 index 0000000000..29d66fcf63 --- /dev/null +++ b/src/QsCompiler/BondSchemas/V2/CompilerDataStructuresV2.cs @@ -0,0 +1,77 @@ + +//------------------------------------------------------------------------------ +// This code was generated by a tool. +// +// Tool : Bond Compiler 0.12.1.0 +// Input filename: C:\Microsoft\ReposB\qsharp-compiler\src\QsCompiler\BondSchemas\V2\CompilerDataStructuresV2.bond +// Output filename: CompilerDataStructuresV2_types.cs +// +// Changes to this file may cause incorrect behavior and will be lost when +// the code is regenerated. +// +//------------------------------------------------------------------------------ + + +// suppress "Missing XML comment for publicly visible type or member" +#pragma warning disable 1591 + + +#region ReSharper warnings +// ReSharper disable PartialTypeWithSinglePart +// ReSharper disable RedundantNameQualifier +// ReSharper disable InconsistentNaming +// ReSharper disable CheckNamespace +// ReSharper disable UnusedParameter.Local +// ReSharper disable RedundantUsingDirective +#endregion + +namespace Microsoft.Quantum.QsCompiler.BondSchemas.V2 +{ + using System.Collections.Generic; + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsNamespace + { + [global::Bond.Id(5)] + public string Name { get; set; } + + [global::Bond.Id(10)] + public List Elements { get; set; } + + [global::Bond.Id(15)] + public LinkedList> Documentation { get; set; } + + public QsNamespace() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V2.QsNamespace", "QsNamespace") + {} + + protected QsNamespace(string fullName, string name) + { + Name = ""; + Elements = new List(); + Documentation = new LinkedList>(); + } + } + + [global::Bond.Schema] + [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")] + public partial class QsCompilation + { + [global::Bond.Id(5)] + public List Namespaces { get; set; } + + [global::Bond.Id(10)] + public List EntryPoints { get; set; } + + public QsCompilation() + : this("Microsoft.Quantum.QsCompiler.BondSchemas.V2.QsCompilation", "QsCompilation") + {} + + protected QsCompilation(string fullName, string name) + { + Namespaces = new List(); + EntryPoints = new List(); + } + } +} // Microsoft.Quantum.QsCompiler.BondSchemas.V2