`__guard case` on a field of a `TrivialRegisterPassable` value fails with "operand #0 does not dominate this use"

Ouverte
#7,690 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 2 jours

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
42/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Domaine
compilers

Piste de recherche

Start by running the supplied mojo run repro.mojo example and inspect the compiler pass that handles multi-clause __guard bindings. Trace how a temporary matched by a later case clause is kept alive when its binding is used after the guard. Done means the example compiles and prints 3 -1 -1.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

bug bug_feature_triaged compiler: frontend repro: confirmed symptom: internal-error symptom: rejects-valid Team: Mojo Compiler

EDIT: Main already has a fix for the multi-clause case that this issue first reported (below the line). The fix is not in 1.3.0.dev2026112105 or earlier nightlies. This issue now tracks a related case that still fails on main.

A __guard case fails in the pass manager when all of these are true:

  • The subject is a field of a TrivialRegisterPassable value.
  • The pattern binds by reference.
  • The code uses the binding after the guard.
from std.collections import OptionalReg


@fieldwise_init
struct Holder(TrivialRegisterPassable):
    var opt: OptionalReg[Int]


def get(h: Holder) -> Int:
    __guard case .Some(x) = h.opt else:
        return -1
    return x


def main():
    print(get(Holder(OptionalReg[Int](3))), get(Holder(OptionalReg[Int]())))

mojo run repro.mojo:

repro.mojo:12:12: error: operand #0 does not dominate this use
    return x
           ^
repro.mojo:10:24: note: operand defined here (op in a child region)
    __guard case .Some(x) = h.opt else:
                       ^
mojo: error: failed to run the pass manager

Expected: prints 3 -1.

Each of these changes makes the program compile and print 3 -1:

  • Bind by value: case .Some(var x).
  • Declare Holder as Copyable, Movable.
  • Copy h.opt to a local variable before the guard.

A method of a register-passable struct fails in the same way on self.field. All the builds that we tried fail, from the 1.3.0.dev2026111605 nightly to main.


ORIGINAL TITLE: Multi-clause __guard: a later case clause on a temporary fails with "operand #0 does not dominate this use"

A multi-clause __guard fails in the pass manager in one specific case. It needs a case clause that follows an earlier case clause, matches a temporary, binds by reference, and has its binding used after the guard.

def maybe(v: Int) -> Optional[Int]:
    return Optional(v) if v >= 0 else None


def f(a: Optional[Int]) -> Int:
    __guard case .Some(x) = a; case .Some(y) = maybe(x) else:
        return -1
    return y


def main():
    print(f(Optional(3)), f(None), f(Optional(-2)))

mojo run repro.mojo:

repro.mojo:8:12: error: operand #0 does not dominate this use
    return y
           ^
repro.mojo:8:12: note: see current operation: "pop.stack_alloc.lifetime.end"(%18) : (!kgen.pointer<struct<(struct<(variant<struct<()>, struct<(struct<(scalar<index>) isParamPack>)>>)>)>>) -> ()
repro.mojo:6:53: note: operand defined here (op in a child region)
    __guard case .Some(x) = a; case .Some(y) = maybe(x) else:
                                                    ^
mojo: error: failed to run the pass manager

Expected: prints 3 -1 -1.

Langage dominant
Mojo
Étoiles
30.2k
Forks
3.2k
Merge moyen
6 j 20 h
PR mergées (30 j)
25

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de modular/modular

Toutes les issues de modular/modular

Issues similaires

Plus d'issues Compilers

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.