microsoft / qsharp-compiler

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

[QIR] QIR Generation fails when a passing a generic callabe as a parameter with an inherited type specifier. #964

Closed swernli closed 3 years ago

swernli commented 3 years ago

The standard library includes two functions, RectangularArrayFact and SquareArrayFact, that make use of the generic Length function as a parameter while using an inherited type specifier: Any(Compose(NotEqualI(numColumns, _), Length<'T>), Rest(array)) This fails QIR generation in the compiler with the error

System.NotImplementedException: Llvm type could not be constructed
     at Microsoft.Quantum.QsCompiler.QIR.GenerationContext.LlvmTypeFromQsharpType(ResolvedType resolvedType) in D:\a\1\s\submodules\qsharp-compiler\src\QsCompiler\QirGeneration\Context.cs:line 1310

when trying to process the argument tuple. It's unclear whether this is an issue specific to QIR generation or perhaps a corner case interaction with Monomorphization (maybe the generic doesn't get fully resolved in the callable tree?). We can work around this in the libraries for now, since it only occurs in those two functions, but we should investigate a fix to ensure QIR generation can handle this case.

bettinaheim commented 3 years ago

This is a tricky one. I think the monomorphization itself is resolved with one of the latest PRs I did. However, I don't think that is actually what would prevent this from working; I believe that when building the callable value, we may actually need to make some special accommodations. I'll look into it with my next batch of fixing things.

bettinaheim commented 3 years ago

Different manifestation of the same issue: https://github.com/microsoft/qsharp-compiler/issues/955

bettinaheim commented 3 years ago

Fixed with #990.