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

Abierto
#7,690 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
42/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Área
compilers

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Mojo
Estrellas
30.2k
Forks
3.2k
Merge medio
6 d 20 h
PR fusionados (30 d)
25

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de modular/modular

Todos los issues de modular/modular

Issues similares

Más issues de Compilers

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.