A where clause that is an or cannot prove a constraint that each disjunct implies

Abierto
#7,706 0 comentarios 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
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Área
compilers

Línea de trabajo

Start by reading the compiler's handling of where clause disjunctions and how it derives evidence from trait refinement; the issue does not name the relevant files or tests. Reproduce the needs_base and needs_copyable examples, then identify or add coverage for each. Done means both calls are accepted when every disjunct implies the required constraint, including the stdlib predicate cases.

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

Descripción

bug_feature_triaged Team: Mojo Compiler

When a function's where clause is a disjunction, the compiler can't use it to prove a constraint that follows from every disjunct.

Calls that need that constraint fail with "lacking evidence to prove correctness".

from std.traits import IsTriviallyCopyable


trait Base:
    pass

trait Left(Base):
    pass

trait Right(Base):
    pass


def needs_base[T: AnyType]() where conforms_to(T, Base):
    pass


def either_refinement[T: AnyType]() where conforms_to(T, Left) or conforms_to(
    T, Right
):
    needs_base[T]()  # error


def needs_copyable[T: AnyType]() where conforms_to(T, Copyable):
    pass


def trivially_copyable[T: AnyType]() where IsTriviallyCopyable[T]:
    needs_copyable[T]()  # error
  error: invalid call to 'needs_base': lacking evidence to prove correctness
  note: constraint declared here needs evidence for 'conforms_to(T, Base)'

  error: invalid call to 'needs_copyable': lacking evidence to prove correctness
  note: constraint declared here needs evidence for 'conforms_to(T, Copyable)'


Both Left and Right refine Base, so either disjunct proves conforms_to(T, Base).

The second case matters more. The stdlib's IsTriviallyCopyable, IsTriviallyMovable and IsTriviallyDeinitable are all disjunctions.

For example:

  conforms_to(T, TrivialRegisterPassable) or
    (conforms_to(T, Copyable) and downcast[T, Copyable].__copy_ctor_is_trivial)


So where IsTriviallyCopyable[T] proves only that exact proposition. It doesn't prove conforms_to(T, Copyable), and it doesn't prove that the copy constructor is trivial. That makes these stdlib predicates much less useful in generic code.

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.