-
Notifications
You must be signed in to change notification settings - Fork 153
Add type-system-chess to stress trait resolution. #1680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "rust" | ||
version = "0.1.0" | ||
edition = "2021" | ||
license = "MIT" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
|
||
[workspace] |
5 changes: 5 additions & 0 deletions
5
collector/compile-benchmarks/type-system-chess/perf-config.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"category": "secondary", | ||
"artifact": "library", | ||
"excluded_profiles": ["Debug", "Opt", "Doc"] | ||
} | ||
4 changes: 4 additions & 0 deletions
4
collector/compile-benchmarks/type-system-chess/src/board_rep.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
pub mod board; | ||
pub mod color; | ||
pub mod piece; | ||
pub mod square; |
93 changes: 93 additions & 0 deletions
93
collector/compile-benchmarks/type-system-chess/src/board_rep/board.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
use super::piece::ColoredPieceTy; | ||
use crate::values; | ||
use std::marker::PhantomData; | ||
|
||
pub mod idx; | ||
pub mod write; | ||
|
||
pub(crate) trait CellEn { | ||
fn reify() -> values::Cell; | ||
} | ||
pub(crate) struct Empty; | ||
pub(crate) struct Filled<P: ColoredPieceTy>(PhantomData<P>); | ||
|
||
impl CellEn for Empty { | ||
fn reify() -> values::Cell { | ||
values::Cell::Empty | ||
} | ||
} | ||
impl<P: ColoredPieceTy> CellEn for Filled<P> { | ||
fn reify() -> values::Cell { | ||
values::Cell::Filled(P::reify()) | ||
} | ||
} | ||
|
||
pub(crate) trait BoardRankTy { | ||
fn reify() -> values::BoardRank; | ||
} | ||
pub(crate) struct BoardRank< | ||
A: CellEn, | ||
B: CellEn, | ||
C: CellEn, | ||
D: CellEn, | ||
E: CellEn, | ||
F: CellEn, | ||
G: CellEn, | ||
H: CellEn, | ||
>(PhantomData<(A, B, C, D, E, F, G, H)>); | ||
|
||
impl<A: CellEn, B: CellEn, C: CellEn, D: CellEn, E: CellEn, F: CellEn, G: CellEn, H: CellEn> | ||
BoardRankTy for BoardRank<A, B, C, D, E, F, G, H> | ||
{ | ||
fn reify() -> values::BoardRank { | ||
values::BoardRank { | ||
a: A::reify(), | ||
b: B::reify(), | ||
c: C::reify(), | ||
d: D::reify(), | ||
e: E::reify(), | ||
f: F::reify(), | ||
g: G::reify(), | ||
h: H::reify(), | ||
} | ||
} | ||
} | ||
|
||
pub(crate) trait BoardTy { | ||
fn reify() -> values::Board; | ||
} | ||
pub(crate) struct Board< | ||
R1: BoardRankTy, | ||
R2: BoardRankTy, | ||
R3: BoardRankTy, | ||
R4: BoardRankTy, | ||
R5: BoardRankTy, | ||
R6: BoardRankTy, | ||
R7: BoardRankTy, | ||
R8: BoardRankTy, | ||
>(PhantomData<(R1, R2, R3, R4, R5, R6, R7, R8)>); | ||
|
||
impl< | ||
R1: BoardRankTy, | ||
R2: BoardRankTy, | ||
R3: BoardRankTy, | ||
R4: BoardRankTy, | ||
R5: BoardRankTy, | ||
R6: BoardRankTy, | ||
R7: BoardRankTy, | ||
R8: BoardRankTy, | ||
> BoardTy for Board<R1, R2, R3, R4, R5, R6, R7, R8> | ||
{ | ||
fn reify() -> values::Board { | ||
values::Board { | ||
r1: R1::reify(), | ||
r2: R2::reify(), | ||
r3: R3::reify(), | ||
r4: R4::reify(), | ||
r5: R5::reify(), | ||
r6: R6::reify(), | ||
r7: R7::reify(), | ||
r8: R8::reify(), | ||
} | ||
} | ||
} |
175 changes: 175 additions & 0 deletions
175
collector/compile-benchmarks/type-system-chess/src/board_rep/board/idx.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
use super::{Board, BoardRank, BoardRankTy, BoardTy, CellEn}; | ||
use crate::board_rep::square::{ | ||
file::{self, FileEn}, | ||
rank::{self, RankEn}, | ||
Square, SquareTy, | ||
}; | ||
|
||
pub(crate) trait RunIdxRank<With> { | ||
type Output: CellEn; | ||
} | ||
pub(crate) type IdxRank<B, F> = <B as RunIdxRank<F>>::Output; | ||
|
||
impl<A: CellEn, B: CellEn, C: CellEn, D: CellEn, E: CellEn, F: CellEn, G: CellEn, H: CellEn> | ||
RunIdxRank<file::FA> for BoardRank<A, B, C, D, E, F, G, H> | ||
{ | ||
type Output = A; | ||
} | ||
impl<A: CellEn, B: CellEn, C: CellEn, D: CellEn, E: CellEn, F: CellEn, G: CellEn, H: CellEn> | ||
RunIdxRank<file::FB> for BoardRank<A, B, C, D, E, F, G, H> | ||
{ | ||
type Output = B; | ||
} | ||
impl<A: CellEn, B: CellEn, C: CellEn, D: CellEn, E: CellEn, F: CellEn, G: CellEn, H: CellEn> | ||
RunIdxRank<file::FC> for BoardRank<A, B, C, D, E, F, G, H> | ||
{ | ||
type Output = C; | ||
} | ||
impl<A: CellEn, B: CellEn, C: CellEn, D: CellEn, E: CellEn, F: CellEn, G: CellEn, H: CellEn> | ||
RunIdxRank<file::FD> for BoardRank<A, B, C, D, E, F, G, H> | ||
{ | ||
type Output = D; | ||
} | ||
impl<A: CellEn, B: CellEn, C: CellEn, D: CellEn, E: CellEn, F: CellEn, G: CellEn, H: CellEn> | ||
RunIdxRank<file::FE> for BoardRank<A, B, C, D, E, F, G, H> | ||
{ | ||
type Output = E; | ||
} | ||
impl<A: CellEn, B: CellEn, C: CellEn, D: CellEn, E: CellEn, F: CellEn, G: CellEn, H: CellEn> | ||
RunIdxRank<file::FF> for BoardRank<A, B, C, D, E, F, G, H> | ||
{ | ||
type Output = F; | ||
} | ||
impl<A: CellEn, B: CellEn, C: CellEn, D: CellEn, E: CellEn, F: CellEn, G: CellEn, H: CellEn> | ||
RunIdxRank<file::FG> for BoardRank<A, B, C, D, E, F, G, H> | ||
{ | ||
type Output = G; | ||
} | ||
impl<A: CellEn, B: CellEn, C: CellEn, D: CellEn, E: CellEn, F: CellEn, G: CellEn, H: CellEn> | ||
RunIdxRank<file::FH> for BoardRank<A, B, C, D, E, F, G, H> | ||
{ | ||
type Output = H; | ||
} | ||
|
||
pub(crate) trait RunIdxBoardRank<With> { | ||
type Output: BoardRankTy; | ||
} | ||
pub(crate) type IdxBoardRank<B, R> = <B as RunIdxBoardRank<R>>::Output; | ||
|
||
impl< | ||
R1: BoardRankTy, | ||
R2: BoardRankTy, | ||
R3: BoardRankTy, | ||
R4: BoardRankTy, | ||
R5: BoardRankTy, | ||
R6: BoardRankTy, | ||
R7: BoardRankTy, | ||
R8: BoardRankTy, | ||
> RunIdxBoardRank<rank::R1> for Board<R1, R2, R3, R4, R5, R6, R7, R8> | ||
{ | ||
type Output = R1; | ||
} | ||
impl< | ||
R1: BoardRankTy, | ||
R2: BoardRankTy, | ||
R3: BoardRankTy, | ||
R4: BoardRankTy, | ||
R5: BoardRankTy, | ||
R6: BoardRankTy, | ||
R7: BoardRankTy, | ||
R8: BoardRankTy, | ||
> RunIdxBoardRank<rank::R2> for Board<R1, R2, R3, R4, R5, R6, R7, R8> | ||
{ | ||
type Output = R2; | ||
} | ||
impl< | ||
R1: BoardRankTy, | ||
R2: BoardRankTy, | ||
R3: BoardRankTy, | ||
R4: BoardRankTy, | ||
R5: BoardRankTy, | ||
R6: BoardRankTy, | ||
R7: BoardRankTy, | ||
R8: BoardRankTy, | ||
> RunIdxBoardRank<rank::R3> for Board<R1, R2, R3, R4, R5, R6, R7, R8> | ||
{ | ||
type Output = R3; | ||
} | ||
impl< | ||
R1: BoardRankTy, | ||
R2: BoardRankTy, | ||
R3: BoardRankTy, | ||
R4: BoardRankTy, | ||
R5: BoardRankTy, | ||
R6: BoardRankTy, | ||
R7: BoardRankTy, | ||
R8: BoardRankTy, | ||
> RunIdxBoardRank<rank::R4> for Board<R1, R2, R3, R4, R5, R6, R7, R8> | ||
{ | ||
type Output = R4; | ||
} | ||
impl< | ||
R1: BoardRankTy, | ||
R2: BoardRankTy, | ||
R3: BoardRankTy, | ||
R4: BoardRankTy, | ||
R5: BoardRankTy, | ||
R6: BoardRankTy, | ||
R7: BoardRankTy, | ||
R8: BoardRankTy, | ||
> RunIdxBoardRank<rank::R5> for Board<R1, R2, R3, R4, R5, R6, R7, R8> | ||
{ | ||
type Output = R5; | ||
} | ||
impl< | ||
R1: BoardRankTy, | ||
R2: BoardRankTy, | ||
R3: BoardRankTy, | ||
R4: BoardRankTy, | ||
R5: BoardRankTy, | ||
R6: BoardRankTy, | ||
R7: BoardRankTy, | ||
R8: BoardRankTy, | ||
> RunIdxBoardRank<rank::R6> for Board<R1, R2, R3, R4, R5, R6, R7, R8> | ||
{ | ||
type Output = R6; | ||
} | ||
impl< | ||
R1: BoardRankTy, | ||
R2: BoardRankTy, | ||
R3: BoardRankTy, | ||
R4: BoardRankTy, | ||
R5: BoardRankTy, | ||
R6: BoardRankTy, | ||
R7: BoardRankTy, | ||
R8: BoardRankTy, | ||
> RunIdxBoardRank<rank::R7> for Board<R1, R2, R3, R4, R5, R6, R7, R8> | ||
{ | ||
type Output = R7; | ||
} | ||
impl< | ||
R1: BoardRankTy, | ||
R2: BoardRankTy, | ||
R3: BoardRankTy, | ||
R4: BoardRankTy, | ||
R5: BoardRankTy, | ||
R6: BoardRankTy, | ||
R7: BoardRankTy, | ||
R8: BoardRankTy, | ||
> RunIdxBoardRank<rank::R8> for Board<R1, R2, R3, R4, R5, R6, R7, R8> | ||
{ | ||
type Output = R8; | ||
} | ||
|
||
pub(crate) trait RunIdxBoard<With: SquareTy> { | ||
type Output: CellEn; | ||
} | ||
pub(crate) type IdxBoard<B, S> = <B as RunIdxBoard<S>>::Output; | ||
|
||
impl<R: RankEn, F: FileEn, B: BoardTy> RunIdxBoard<Square<R, F>> for B | ||
where | ||
B: RunIdxBoardRank<R>, | ||
IdxBoardRank<B, R>: RunIdxRank<F>, | ||
{ | ||
type Output = IdxRank<IdxBoardRank<B, R>, F>; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.