Skip to content

Commit

Permalink
chore: add rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
hbina authored Oct 18, 2021
1 parent 87cef82 commit 4f615b0
Show file tree
Hide file tree
Showing 48 changed files with 766 additions and 530 deletions.
21 changes: 15 additions & 6 deletions .github/workflows/synth-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ name: synth-cargo-test

on:
push:
branches: [ master ]
paths: [ '**/*.rs' ]
branches: [master]
paths: ["**/*.rs"]
pull_request:
branches: [ master ]
paths: [ '**/*.rs' ]
branches: [master]
paths: ["**/*.rs"]

workflow_dispatch:

Expand All @@ -15,7 +15,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-latest, windows-latest ]
os: [ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
Expand All @@ -33,4 +33,13 @@ jobs:
override: true
components: clippy
- run: cargo clippy --tests --all-targets -- -D warnings

fmt_test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
components: rustfmt
- run: cargo fmt --all -- --check
7 changes: 6 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ To compile from source, see the `Compiling from source` tab in the [docs](https:

## Running Tests

Synth has reasonable test coverage - and we are working on improving this every day. We encourage PRs to come with tests. If you're not sure about what a test shoud look like get in touch.
Synth has reasonable test coverage - and we are working on improving this
every day. We encourage PRs to come with tests. If you're not sure about
what a test should look like, feel free to get in touch.

To run the test suite - just run `cargo test` at the root of the repository.

Expand All @@ -21,3 +23,6 @@ We use the [Angular Commit Guidelines](https://github.com/angular/angular/blob/m
Furthermore, commits should be squashed before being merged to master.

Also, make sure your commits don't trigger any warnings from Clippy by running: `cargo clippy --tests --all-targets`. If you have a good reason to contradict Clippy, insert an #allow[] macro, so that it won't complain.

Plus, make sure your commits are properly formatted. You can automate this
process by copying over the `pre-commit` file in `tools/hooks/pre-commit` to `.git/hooks/pre-commit` which will make git automatically format your code before committing them.
2 changes: 1 addition & 1 deletion core/src/compile/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,4 @@ impl From<FieldRef> for Address {
fn from(field: FieldRef) -> Self {
field.into_iter().collect()
}
}
}
58 changes: 28 additions & 30 deletions core/src/compile/link.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use synth_gen::prelude::{Generator, GeneratorState};

use std::cell::RefCell;
use std::iter::IntoIterator;
use std::ops::Range;
use std::rc::Rc;
use std::iter::IntoIterator;

use crate::graph::prelude::Rng;

pub struct Slice {
generation: usize,
start: usize
start: usize,
}

pub struct Tape<Y, R> {
Expand All @@ -21,7 +21,7 @@ impl<Y, R> Tape<Y, R> {
fn new() -> Self {
Self {
slices: Vec::new(),
buffer: Vec::new()
buffer: Vec::new(),
}
}

Expand Down Expand Up @@ -52,7 +52,7 @@ pub type SharedTape<Y, R> = Rc<RefCell<Tape<Y, R>>>;

pub(super) struct SliceRef<Y, R> {
index: usize,
tape: SharedTape<Y, R>
tape: SharedTape<Y, R>,
}

pub(super) type GeneratorSliceRef<G: Generator> = SliceRef<G::Yield, G::Return>;
Expand All @@ -61,7 +61,7 @@ impl<Y, R> Clone for SliceRef<Y, R> {
fn clone(&self) -> Self {
Self {
index: self.index,
tape: self.tape.clone()
tape: self.tape.clone(),
}
}
}
Expand All @@ -75,7 +75,7 @@ impl<Y, R> SliceRef<Y, R> {
TapeView(TapeViewImpl {
slice: self.clone(),
generation: 0,
range: Range::default()
range: Range::default(),
})
}

Expand All @@ -99,22 +99,22 @@ impl<G, Y, R> RecorderImpl<G, Y, R> {
let mut tape = (*self.tape).borrow_mut();
let slice = Slice {
generation: 0,
start: tape.buffer.len()
start: tape.buffer.len(),
};
tape.slices.push(slice);
tape.slices.len() - 1
};
SliceRef {
index,
tape: self.tape.clone()
tape: self.tape.clone(),
}
}
}

impl<G, Y, R> Generator for RecorderImpl<G, Y, R>
where
G: Generator<Yield = Y, Return = R>,
GeneratorState<Y, R>: Clone,
where
G: Generator<Yield = Y, Return = R>,
GeneratorState<Y, R>: Clone,
{
type Yield = Y;

Expand All @@ -128,8 +128,8 @@ impl<G, Y, R> Generator for RecorderImpl<G, Y, R>
}

impl<G, Y, R> RecorderImpl<G, Y, R>
where
G: Generator<Yield = Y, Return = R>,
where
G: Generator<Yield = Y, Return = R>,
{
fn complete<RR: Rng>(&mut self, rng: &mut RR) {
#[allow(clippy::blocks_in_if_conditions)]
Expand Down Expand Up @@ -158,14 +158,14 @@ impl<G, Y, R> Recorder<G, Y, R> {
pub(super) fn wrap(inner: G) -> Self {
Self(RecorderImpl {
inner,
tape: Rc::new(RefCell::new(Tape::new()))
tape: Rc::new(RefCell::new(Tape::new())),
})
}
}

impl<G, Y, R> Recorder<G, Y, R>
where
G: Generator<Yield = Y, Return = R>,
where
G: Generator<Yield = Y, Return = R>,
{
fn complete<RR: Rng>(&mut self, rng: &mut RR) {
self.0.complete(rng)
Expand All @@ -175,7 +175,7 @@ impl<G, Y, R> Recorder<G, Y, R>
pub(super) struct TapeViewImpl<Y, R> {
slice: SliceRef<Y, R>,
generation: usize,
range: Range<usize>
range: Range<usize>,
}

impl<Y, R> TapeViewImpl<Y, R> {
Expand Down Expand Up @@ -229,17 +229,15 @@ pub(super) struct OrderedImpl<G, Y, R> {
}

impl<G, Y, R> Generator for OrderedImpl<G, Y, R>
where
G: Generator<Yield = Y, Return = R>,
where
G: Generator<Yield = Y, Return = R>,
{
type Yield = Y;
type Return = R;

fn next<RR: Rng>(&mut self, rng: &mut RR) -> GeneratorState<Self::Yield, Self::Return> {
if !self.is_complete {
self.scope.iter_mut().for_each(|slice| {
slice.reset()
});
self.scope.iter_mut().for_each(|slice| slice.reset());
self.children.iter_mut().for_each(|(_, recorder)| {
recorder.complete(rng);
});
Expand All @@ -265,13 +263,13 @@ impl<G, Y, R> Ordered<G, Y, R> {
pub(super) fn new<S, C>(scope: S, children: C, src: G) -> Self
where
S: IntoIterator<Item = SliceRef<Y, R>>,
C: IntoIterator<Item = (String, Recorder<G, Y, R>)>
C: IntoIterator<Item = (String, Recorder<G, Y, R>)>,
{
Self(OrderedImpl {
is_complete: false,
scope: scope.into_iter().collect(),
children: children.into_iter().collect(),
src
src,
})
}
}
Expand All @@ -286,13 +284,13 @@ pub enum Link<G, Y, R> {
Ordered(Ordered<G, Y, R>),
/// A variant used in compilation as a placeholder prior to setting the node to its final
/// value.
Dummy
Dummy,
}

impl<G, Y, R> Generator for Link<G, Y, R>
where
G: Generator<Yield = Y, Return = R>,
GeneratorState<Y, R>: Clone
GeneratorState<Y, R>: Clone,
{
type Yield = Y;

Expand All @@ -303,7 +301,7 @@ where
Self::Recorder(Recorder(recorder)) => recorder.next(rng).map_complete(Some),
Self::View(TapeView(view)) => view.next(rng),
Self::Ordered(Ordered(ordered)) => ordered.next(rng).map_complete(Some),
Self::Dummy => panic!("tried to generate values from a dummy")
Self::Dummy => panic!("tried to generate values from a dummy"),
}
}
}
Expand All @@ -317,8 +315,8 @@ impl<G, Y, R> Link<G, Y, R> {
match self {
Self::Ordered(Ordered(OrderedImpl { children, .. })) => {
Some(children.iter().map(|(name, _)| name.as_str()))
},
_ => None
}
_ => None,
}
}
}
Expand All @@ -337,4 +335,4 @@ pub trait FromLink: Sized {
fn dummy() -> Self {
Self::from_link(Link::new_dummy())
}
}
}
Loading

0 comments on commit 4f615b0

Please sign in to comment.