Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Serialization fails when AST contains unlifted lambdas #1387

Open
bamarsha opened this issue Mar 22, 2022 · 0 comments
Open

Serialization fails when AST contains unlifted lambdas #1387

bamarsha opened this issue Mar 22, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@bamarsha
Copy link
Contributor

Serialization doesn't work when the AST contains a lambda that hasn't been lifted, either because lifting lambdas is disabled or there are compilation errors. For example

namespace App {
    open Microsoft.Quantum.Intrinsic;

    @EntryPoint()
    operation Main() : Unit {
        let f = x -> x + 1;
        X(); // compilation error
    }
}

produces

  System.ArgumentException: Unsupported QsExpressionKind Lambda
    { kind = Function
      paramTuple =
                  QsTuple
                    (seq
                       [QsTupleItem
                          { VariableName = ValidName "x"
                            Type =
                                  { kind = Int
                                    range =
                                           Inferred
                                             (Range
                                                (Position (0,8),Position (0,9))) }
                            InferredInformation =
                                                 { IsMutable = false
                                                   HasLocalQuantumDependency =
                                                                              false }
                            Position = Value (Position (1,8))
                            Range = Range (Position (0,8),Position (0,9)) }])
      body =
            { Expression =
                          ADD
                            ({ Expression = Identifier (LocalVariable "x",Null)
                               TypeArguments = seq []
                               ResolvedType =
                                             { kind = Int
                                               range =
                                                      Inferred
                                                        (Range
                                                           (Position (0,13),
                                                            Position (0,14))) }
                               InferredInformation =
                                                    { IsMutable = false
                                                      HasLocalQuantumDependency =
                                                                                 false }
                               Range =
                                      Value
                                        (Range (Position (0,13),Position (0,14))) },
                             { Expression = IntLiteral 1L
                               TypeArguments = seq []
                               ResolvedType =
                                             { kind = Int
                                               range =
                                                      Inferred
                                                        (Range
                                                           (Position (0,17),
                                                            Position (0,18))) }
                               InferredInformation =
                                                    { IsMutable = false
                                                      HasLocalQuantumDependency =
                                                                                 false }
                               Range =
                                      Value
                                        (Range (Position (0,17),Position (0,18))) })
              TypeArguments = seq []
              ResolvedType =
                            { kind = Int
                              range =
                                     Inferred
                                       (Range (Position (0,13),Position (0,18))) }
              InferredInformation = { IsMutable = false
                                      HasLocalQuantumDependency = false }
              Range = Value (Range (Position (0,13),Position (0,18))) } }
     at Microsoft.Quantum.QsCompiler.BondSchemas.BondSchemaTranslator.ToBondSchemaGeneric[TBondExpression,TBondSymbol,TBondType,TCompilerExpression,TCompilerSymbol,TCompilerType](QsExpressionKind`3 qsExpressionKind, Func`2 expressionTranslator, Func`2 symbolTranslator, Func`2 typeTranslator) in C:\Users\samarsha\Code\microsoft\qsharp-compiler\src\QsCompiler\BondSchemas\BondSchemaTranslator.cs:line 1098
     at Microsoft.Quantum.QsCompiler.BondSchemas.BondSchemaTranslator.ToBondSchema(QsExpressionKind`3 qsExpressionKind) in C:\Users\samarsha\Code\microsoft\qsharp-compiler\src\QsCompiler\BondSchemas\BondSchemaTranslator.cs:line 196
     at Microsoft.Quantum.QsCompiler.BondSchemas.BondSchemaTranslator.ToBondSchema(TypedExpression typedExpression) in C:\Users\samarsha\Code\microsoft\qsharp-compiler\src\QsCompiler\BondSchemas\BondSchemaTranslator.cs:line 660
     at Microsoft.Quantum.QsCompiler.BondSchemas.BondSchemaTranslator.ToBondSchemaGeneric[TBond,TCompiler](QsBinding`1 qsBinding, Func`2 typeTranslator) in C:\Users\samarsha\Code\microsoft\qsharp-compiler\src\QsCompiler\BondSchemas\BondSchemaTranslator.cs:line 744
     at Microsoft.Quantum.QsCompiler.BondSchemas.BondSchemaTranslator.ToBondSchema(QsStatementKind qsStatementKind) in C:\Users\samarsha\Code\microsoft\qsharp-compiler\src\QsCompiler\BondSchemas\BondSchemaTranslator.cs:line 429
     at Microsoft.Quantum.QsCompiler.BondSchemas.BondSchemaTranslator.ToBondSchema(QsStatement qsStatement) in C:\Users\samarsha\Code\microsoft\qsharp-compiler\src\QsCompiler\BondSchemas\BondSchemaTranslator.cs:line 389
     at Microsoft.Quantum.QsCompiler.BondSchemas.BondSchemaTranslator.<>c.<ToBondSchema>b__32_0(QsStatement s) in C:\Users\samarsha\Code\microsoft\qsharp-compiler\src\QsCompiler\BondSchemas\BondSchemaTranslator.cs:line 355
     at System.Linq.Enumerable.SelectArrayIterator`2.ToList()
     at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
     at Microsoft.Quantum.QsCompiler.BondSchemas.BondSchemaTranslator.ToBondSchema(QsScope qsScope) in C:\Users\samarsha\Code\microsoft\qsharp-compiler\src\QsCompiler\BondSchemas\BondSchemaTranslator.cs:line 353
     at Microsoft.Quantum.QsCompiler.BondSchemas.BondSchemaTranslator.ToSpecializationImplementationKindProvided(QsTuple`1 tuple, QsScope implementation) in C:\Users\samarsha\Code\microsoft\qsharp-compiler\src\QsCompiler\BondSchemas\BondSchemaTranslator.cs:line 1448       
     at Microsoft.Quantum.QsCompiler.BondSchemas.BondSchemaTranslator.ToBondSchema(SpecializationImplementation specializationImplementation) in C:\Users\samarsha\Code\microsoft\qsharp-compiler\src\QsCompiler\BondSchemas\BondSchemaTranslator.cs:line 606
     at Microsoft.Quantum.QsCompiler.BondSchemas.BondSchemaTranslator.ToBondSchema(QsSpecialization qsSpecialization) in C:\Users\samarsha\Code\microsoft\qsharp-compiler\src\QsCompiler\BondSchemas\BondSchemaTranslator.cs:line 360
     at Microsoft.Quantum.QsCompiler.BondSchemas.BondSchemaTranslator.<>c.<ToBondSchema>b__10_1(QsSpecialization s) in C:\Users\samarsha\Code\microsoft\qsharp-compiler\src\QsCompiler\BondSchemas\BondSchemaTranslator.cs:line 130
     at System.Linq.Enumerable.SelectArrayIterator`2.ToList()
     at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
     at Microsoft.Quantum.QsCompiler.BondSchemas.BondSchemaTranslator.ToBondSchema(QsCallable qsCallable) in C:\Users\samarsha\Code\microsoft\qsharp-compiler\src\QsCompiler\BondSchemas\BondSchemaTranslator.cs:line 118
     at Microsoft.Quantum.QsCompiler.BondSchemas.BondSchemaTranslator.ToBondSchema(QsNamespaceElement qsNamespaceElement) in C:\Users\samarsha\Code\microsoft\qsharp-compiler\src\QsCompiler\BondSchemas\BondSchemaTranslator.cs:line 278
     at Microsoft.Quantum.QsCompiler.BondSchemas.BondSchemaTranslator.<>c.<ToBondSchema>b__24_0(QsNamespaceElement e) in C:\Users\samarsha\Code\microsoft\qsharp-compiler\src\QsCompiler\BondSchemas\BondSchemaTranslator.cs:line 266
     at System.Linq.Enumerable.SelectArrayIterator`2.ToList()
     at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
     at Microsoft.Quantum.QsCompiler.BondSchemas.BondSchemaTranslator.ToBondSchema(QsNamespace qsNamespace) in C:\Users\samarsha\Code\microsoft\qsharp-compiler\src\QsCompiler\BondSchemas\BondSchemaTranslator.cs:line 263
     at Microsoft.Quantum.QsCompiler.BondSchemas.BondSchemaTranslator.<>c.<CreateBondCompilation>b__0_0(QsNamespace n) in C:\Users\samarsha\Code\microsoft\qsharp-compiler\src\QsCompiler\BondSchemas\BondSchemaTranslator.cs:line 23
     at System.Linq.Enumerable.SelectArrayIterator`2.ToList()
     at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
     at Microsoft.Quantum.QsCompiler.BondSchemas.BondSchemaTranslator.CreateBondCompilation(QsCompilation qsCompilation) in C:\Users\samarsha\Code\microsoft\qsharp-compiler\src\QsCompiler\BondSchemas\BondSchemaTranslator.cs:line 21
     at Microsoft.Quantum.QsCompiler.BondSchemas.Protocols.SerializeQsCompilationToSimpleBinary(QsCompilation qsCompilation, Stream stream) in C:\Users\samarsha\Code\microsoft\qsharp-compiler\src\QsCompiler\BondSchemas\Protocols.cs:line 111
     at Microsoft.Quantum.QsCompiler.CompilationLoader.SerializeSyntaxTree(QsCompilation syntaxTree, Stream stream, Action`1 onException) in C:\Users\samarsha\Code\microsoft\qsharp-compiler\src\QsCompiler\Compiler\CompilationLoader.cs:line 1212

EXEC(1,1): error Microsoft.VisualStudio.LanguageServer.Protocol.SumType`2[System.Int32,System.String]: Unable to serialize the built compilation. [C:\Users\samarsha\Code\samarsha\qsharp-sandbox\App\App.csproj]

  ____________________________________________

  Q# compilation failed: 2 errors, 0 warnings
  1 logged exception
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
1 participant