Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

[Panic] Ctl operation that calls an element of an operation-array parameter panics

Aperta
#3,974 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
compilers

Direzione di ricerca

Start with the reported invariant failure in qsc_fir_transforms/src/invariants.rs:1926, then inspect the defunctionalization evaluation and index order changes from #3893. Use the Q# example and Python reproduction in the issue to compare indexed calls under Ctl and Adj controls. Done means the reproductions compile without panicking across the listed profiles while the control cases continue to compile.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug needs triage
operation W(q : Qubit, ops : (Qubit => Unit is Ctl)[]) : Unit is Ctl {
    ops[0](q);
}
operation Main() : Result {
    use q = Qubit();
    W(q, [S]);
    MResetZ(q)
}
  • Failure: every profile, including Base, panics in qsc_fir_transforms/src/invariants.rs:1926:
    PostArgPromote/PostAll call invariant violation: Expr 67 passes Expr 66 with type Tuple([Array(Prim(Qubit)), Prim(Qubit)]) to callee Expr 65 expecting input type Prim(Qubit). The program never uses Controlled, so the
    panic probably comes from the generated controlled specialization of W, which passes (ctls, q) to an array
    element.
  • What triggers it: is Ctl or is Adj + Ctl, together with indexing (ops[i](q)). It compiles with is Adj
    alone, with for op in ops { op(q); }, or with a single operation parameter instead of an array.
  • Regression: a bisect over the commits between merge base 7c6a2b51 and main gives 6adfda105 (#3891)
    compiles it, and 84d1ec2e4 "Defunctionalization: evaluation and index order (#3893)" panics. Branches without
    #3893 (f05438eb, ca2fe553) compile it correctly.
  • Related: #3966 (open) reports the same invariant violation when
    Controlled is applied to a callable-array closure through the Python callable API. This is a much simpler
    trigger in plain Q#, with no closure, no Controlled call, and no Python, so it's likely the same root cause.
  • Impact: this accounts for half of all panics in the run, including all 8 Base panics, and stops every program
    with a W gate-array operation from compiling.
"""Panic: an `is Ctl` operation that calls an element of an operation-array parameter.

Every profile, including Base, panics in qsc_fir_transforms (invariants.rs) with
"PostArgPromote/PostAll call invariant violation ... passes ... Tuple([Array(Prim(Qubit)), Prim(Qubit)]) to callee
... expecting input type Prim(Qubit)". The program never uses `Controlled`, so the panic probably comes from the
generated controlled specialization of `W`. It's a regression: a bisect over upstream/main gives 6adfda105 (#3891) good,
84d1ec2e4 "Defunctionalization: evaluation and index order (#3893)" bad. Related: #3966 (the same invariant through the
Python callable API with a callable-array closure).

The controls show what the trigger needs: `is Ctl` (or `is Adj + Ctl`) and indexing into the array. They compile.

Requires only the `qdk` package. Exits 0 while the panic reproduces.
"""

import sys

from qdk import Context, TargetProfile

PROFILES = ("Base", "Adaptive_RI", "Adaptive_RIF", "Adaptive")

MAIN = """
operation Main() : Result {
    use q = Qubit();
    W(q, [S]);
    MResetZ(q)
}
"""


def w(functors: str, body: str) -> str:
    return f"operation W(q : Qubit, ops : (Qubit => Unit is {functors})[]) : Unit is {functors} {{ {body} }}"


PROGRAMS = {
    "Ctl, indexed (bug)": w("Ctl", "ops[0](q);"),
    "Adj + Ctl, indexed (bug)": w("Adj + Ctl", "ops[0](q);"),
    "Adj only, indexed (control)": w("Adj", "ops[0](q);"),
    "Ctl, for loop (control)": w("Ctl", "for op in ops { op(q); }"),
}


def compile_status(source: str, profile: str) -> str:
    ctx = Context(target_profile=getattr(TargetProfile, profile))
    try:
        ctx.eval(source)
        ctx.compile("Main()")
        return "ok"
    except BaseException as e:  # pyo3's PanicException derives from BaseException
        kind = "PANIC" if type(e).__name__ == "PanicException" else "error"
        return f"{kind}: {' '.join(str(e).split())[:110]}"


reproduced = False
for label, w in PROGRAMS.items():
    print(label)
    for profile in PROFILES:
        status = compile_status(w + MAIN, profile)
        print(f"  {profile:13s} {status}")
        if "(bug)" in label and "PostArgPromote" in status:
            reproduced = True

print("REPRODUCED" if reproduced else "NOT REPRODUCED")
sys.exit(0 if reproduced else 1)
Lingua principale
Rust
Stelle
1k
Fork
219
Merge medio
3g 19h
PR unite (30g)
93

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di microsoft/qdk

Tutte le issue di microsoft/qdk

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.