microsoft / microsoft/qdk

Wasm stack overflow during QIR generation

Open
#3,440 3 comments 0 reactions 1 assignee Claimed by @idavis View on GitHub
bug needs triage
Dominant language
Rust
Stars
1k
Forks
212
Avg merge
3d 8h
Merged PRs (30d)
65

Description

**Describe the bug**

```qsharp
// Recursive wrapper: lets a value be applied to itself.
struct SelfApp {
Run : SelfApp -> (Int -> Int)
}

// Fixed-point (Y / Z) combinator.
function Fix(f : (Int -> Int) -> (Int -> Int)) : Int -> Int {
let g = new SelfApp {
Run = x -> f(v -> (x.Run(x))(v)) // eta-expanded for strict eval
};
g.Run(g)
}

@EntryPoint()
function Main() : Unit {
// Factorial with no named recursion — recursion comes entirely from Fix.
let factorial = Fix(rec -> (n -> n <= 1 ? 1 | n * rec(n - 1)));
for n in 0..6 {
Message($"{n}! = {factorial(n)}");
}
}
```

```
[error] QIR generation failed. Compiling to QIR failed.
RangeError: Maximum call stack size exceeded
```

**To Reproduce**

Generate QIR from VS Code command palette.

**Screenshots**

Image

**System information**

1.29.7-dev

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.