BartMassey / BartMassey/randomly

Optimize

Open
#1 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
0
Forks
0
PR merge metrics
No merged PRs in 30d

Description

Right now, the "match statement" generated by this macro is of the form:
```rust
match thread_rng().gen_range(3) {
x if x == 0 => { /* block 0 */ }
x if x == 0 + 1 => { /* block 1 */ }
x if x == 0 + 1 + 1 => { /* block 2 */ }
_ => panic!(),
}
```
(Thanks to [this thread](https://users.rust-lang.org/t/how-to-generate-in-macro/56774/6) for that neat trick!) A really naïve compiler will fail to simplify those patterns, and thus will walk the match arms from top to bottom.

It would be nicer to generate something direct
```rust
match thread_rng().gen_range(3) {
0 => { /* block 0 */ }
1 => { /* block 1 */ }
2 => { /* block 2 */ }
_ => panic!(),
}
```
but as far as I know Rust declarative macros can't do this. The macros can't do the arithmetic to simplify the patterns, and the pattern matcher won't take constant expressions, so gridlock.

Contributor guide

No contributing guide indexed for this repository

Research direction

No file or test is named. Start by locating the macro that generates the match statement and inspect its generated Rust output; compare the current guard-based arms with the requested literal-arm form. Done means the generated match uses direct literal patterns without regressing the macro's existing behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
performance, tooling
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.