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

Đang mở
#7,706 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Lĩnh vực
compilers

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Mojo
Star
30.2k
Fork
3.2k
Merge trung bình
6 ngày 20 giờ
Pull request đã merge (30 ngày)
25

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của modular/modular

Tất cả issue của modular/modular

Issue tương tự

Thêm issue về Compilers

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.