Can't use `usize::unchecked_mul()` because "checked mul is not supported yet"

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

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

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
48/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
rust
Lĩnh vực
compilers

Hướng nghiên cứu

Tái hiện lỗi biên dịch shader, sau đó bắt đầu trong core/src/num/mod.rs và lần theo usize::unchecked_mul qua assert_unsafe_precondition! và overflowing_mul. So sánh đường đi đó với Layout::repeat và xác định liệu việc hỗ trợ checked multiplication hoặc vô hiệu hóa unsafe preconditions có khắc phục được lỗi đã báo cáo hay không; hoàn tất khi reproducer biên dịch thành công.

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

Mô tả

bug

I've stumbled upon this while trying to use core::alloc::Layout type in my shader code.
You see, Layout::repeat() function uses checked math to return an error, but in my case this should not be possible, so I've reimplemented it using usize::unchecked_mul().
I expected my code to compile, but got this compiler error instead:

error: checked mul is not supported yet
      --> ***\.rustup\toolchains\nightly-2025-06-30-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\num\mod.rs:1224:5
       |
  1224 | /     uint_impl! {
  1225 | |         Self = usize,
  1226 | |         ActualT = u32,
  1227 | |         SignedT = isize,
  ...    |
  1241 | |         bound_condition = " on 32-bit targets",
  1242 | |     }
       | |_____^
       |
  note: used from within `<usize>::overflowing_mul`
      --> ***\.rustup\toolchains\nightly-2025-06-30-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\num\mod.rs:1224:5
       |
  1224 | /     uint_impl! {
  1225 | |         Self = usize,
  1226 | |         ActualT = u32,
  1227 | |         SignedT = isize,
  ...    |
  1241 | |         bound_condition = " on 32-bit targets",
  1242 | |     }
       | |_____^
  note: called by `<usize>::unchecked_mul::precondition_check`
      --> ***\.rustup\toolchains\nightly-2025-06-30-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\num\mod.rs:1224:5
       |
  1224 | /     uint_impl! {
  1225 | |         Self = usize,
  1226 | |         ActualT = u32,
  1227 | |         SignedT = isize,
  ...    |
  1241 | |         bound_condition = " on 32-bit targets",
  1242 | |     }
       | |_____^
  note: called by `<usize>::unchecked_mul`
      --> ***\.rustup\toolchains\nightly-2025-06-30-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\num\mod.rs:1224:5
       |
  1224 | /     uint_impl! {
  1225 | |         Self = usize,
  1226 | |         ActualT = u32,
  1227 | |         SignedT = isize,
  ...    |
  1241 | |         bound_condition = " on 32-bit targets",
  1242 | |     }
       | |_____^
  note: 

I guess it tries to compile assert_unsafe_precondition! macro call which contains a call to usize::overflowing_mul() (which is used to do checked multiplication), and fails to do so.
I thought it should be compiled out because I'm compiling my shader in release mode (as by default) which suggests that debug_assertions are set to false (which should disable unsafe preconditions), but it seems this is not the case here.

I think it will be best to resolve such issue by implementing checked mul (as it is already implemented in Zig SPIR-V compiler, which I guess was the inspiration for rust-gpu's checked math functions)...
But if it is possible to disable unsafe preconditions completely, I can do just that.

Ngôn ngữ chính
Rust
Star
3.4k
Fork
126
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

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 Rust-GPU/rust-gpu

Tất cả issue của Rust-GPU/rust-gpu

Issue tương tự

Thêm issue về Rust

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.