Can't use `usize::unchecked_mul()` because "checked mul is not supported yet"
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
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ả
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
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của Rust-GPU/rust-gpu
-
enhancement
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 68/100
-
enhancement
Rust-GPU/rust-gpu#643 · 3 bình luận · 1 reaction · 1 người được giao ·
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
-
bug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 48/100
-
async functions cause ICE Đang mởbug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
Tất cả issue của Rust-GPU/rust-gpu
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
ontola/atomic-server#1625 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
VirusTotal/yara-x#777 ·
-
has_tail_capacity wraps and get_writable_raw_unchecked commits raw_len before the bounds check Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
stratum-mining/stratum#2404 ·
-
bug ci good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100