Skip to content

Commit

Permalink
Create CI and companion scripts (#100)
Browse files Browse the repository at this point in the history
## What Changed?

Refactors the CI commands into locally runnable scripts.

`integration-tests.sh` and `compiler-tests.sh` are for testing.
`dock-check.sh` lints the documentation of the public-facing crates.
`format.sh` is responsible for `clippy` and `rustfmt` checks.
To run all doc and format checks use `check-all.sh`.

In addition there are the "companion scripts" for `clippy` and `rustfmt`
which
apply the suggested fixes by passing `clippy-fix` and `fmt-fix` to
`format.sh`
respectively. Most of the time you'll want to use `fix-all.sh` which
invokes
both in series, to get your code in the shape the CI expects.

Also now includes test crates in the formatting.

## Why Does It Need To?

Closes #90 

## Checklist

- [x] Above description has been filled out so that upon quash merge we
have a
  good record of what changed.
- [x] New functions, methods, types are documented. Old documentation is
updated
  if necessary
- [ ] Documentation in Notion has been updated
- [ ] Tests for new behaviors are provided
  - [ ] New test suites (if any) ave been added to the CI tests (in
`.github/workflows/rust.yml`) either as compiler test or integration
test.
*Or* justification for their omission from CI has been provided in this
PR
    description.
  • Loading branch information
JustusAdam authored Oct 30, 2023
1 parent ee875f9 commit cb72c3f
Show file tree
Hide file tree
Showing 22 changed files with 288 additions and 193 deletions.
41 changes: 6 additions & 35 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,7 @@ jobs:
- name: Build
run: cargo install --locked --path crates/paralegal-flow --verbose
- name: Run tests
run: |
cargo test -p paralegal-flow --test non_transitive_graph_tests
cargo test -p paralegal-flow --test call_chain_analysis_tests
cargo test -p paralegal-flow --test control_flow_tests
cargo test -p paralegal-flow --test new_alias_analysis_tests
cargo test -p paralegal-flow --test async_tests
cargo test -p paralegal-flow --test inline_elision_tests
cargo test -p paralegal-policy --lib
- name: Build Test Policies
run: |
cd props
cargo build --verbose
- name: Test Guide Project
run: |
cargo run
working-directory: guide/deletion-policy
run: scripts/compiler-tests.sh

intergration-tests:
name: Integration Tests
Expand Down Expand Up @@ -86,7 +71,7 @@ jobs:
cd forge
raco pkg install --auto || raco setup forge
- name: Run Tests
run: cargo test -p paralegal-flow --test external_annotation_tests
run: scripts/integration-tests.sh

format-check:
name: Format Control
Expand All @@ -100,17 +85,8 @@ jobs:
with:
path: ~/.rustup
key: ${{ runner.os }}-rust-toolchain-${{ hashFiles('rust-toolchain.toml') }}
- name: Check main repo
run: cargo fmt --check
- name: Check properties
run: cargo fmt --check
working-directory: props
- name: Check Guide Project
run: cargo fmt --check
working-directory: guide/file-db-example
- name: Check Guide Policy
run: cargo fmt --check
working-directory: guide/deletion-policy
- name: Run checks
run: scripts/format.sh fmt-check

linting:
name: Clippy
Expand All @@ -133,10 +109,7 @@ jobs:
target/
key: ${{ runner.os }}-rust-deps-${{ hashFiles('Cargo.lock', 'rust-toolchain.toml') }}
- name: Here come the complaints
run: cargo clippy --all -- -D warnings
- name: Complaints about properties
run: cargo clippy --all -- -D warnings
working-directory: props
run: scripts/format.sh clippy-check

documentation:
name: Documentation Test
Expand All @@ -159,6 +132,4 @@ jobs:
target/
key: ${{ runner.os }}-rust-deps-${{ hashFiles('Cargo.lock', 'rust-toolchain.toml') }}
- name: Here come the complaints
run: |
cargo rustdoc -p paralegal-spdg -- -Drustdoc::all
cargo rustdoc -p paralegal-policy -- -Drustdoc::all
run: scripts/doc-check.sh
31 changes: 11 additions & 20 deletions crates/paralegal-flow/tests/async-tests/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ fn get_user_data2() -> UserData {
data: vec![1, 2, 3],
};
}
#[paralegal::marker(yey_paralegal_flow_now_needs_this_label_or_it_will_recurse_into_this_function, return)]
#[paralegal::marker(
yey_paralegal_flow_now_needs_this_label_or_it_will_recurse_into_this_function,
return
)]
fn dp_user_data(user_data: &mut UserData) {
for i in &mut user_data.data {
*i = 2;
Expand All @@ -33,7 +36,10 @@ async fn async_get_user_data() -> UserData {
};
}

#[paralegal::marker(yey_paralegal_flow_now_needs_this_label_or_it_will_recurse_into_this_function, return)]
#[paralegal::marker(
yey_paralegal_flow_now_needs_this_label_or_it_will_recurse_into_this_function,
return
)]
async fn async_dp_user_data(user_data: &mut UserData) {
for i in &mut user_data.data {
*i = 2;
Expand All @@ -44,8 +50,6 @@ async fn inlineable_async_dp_user_data(user_data: &mut UserData) {
dp_user_data(user_data)
}



#[paralegal::marker{ sink, arguments = [0] }]
async fn async_send_user_data(user_data: &UserData) {}

Expand Down Expand Up @@ -88,10 +92,6 @@ async fn inlining_crate_local_async_fns() {
send_user_data(&user_data);
}





async fn arity2_inlineable_async_dp_user_data(_: &mut UserData, user_data: &mut UserData) {
dp_user_data(user_data)
}
Expand All @@ -105,10 +105,6 @@ async fn no_inlining_overtaint() {
send_user_data2(&ud2);
}





async fn send_both(ud1: &UserData, ud2: &UserData) {
send_user_data(&ud1);
send_user_data2(&ud2);
Expand Down Expand Up @@ -137,14 +133,10 @@ fn another_input() -> usize {
}

#[paralegal::marker(target)]
fn target(i: usize) {

}
fn target(i: usize) {}

#[paralegal::marker(target)]
fn another_target(i: usize) {

}
fn another_target(i: usize) {}

async fn id_fun<T>(t: T) -> T {
let _ = f();
Expand All @@ -168,5 +160,4 @@ async fn no_overtaint_over_poll() {
another_target(t.1);
}


fn main() {}
fn main() {}
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,19 @@ struct S {
#[paralegal::marker(noinline, return)]
fn read_usize(u: usize) {}

#[paralegal::marker(noinline ,return)]
#[paralegal::marker(noinline, return)]
fn read_string(s: String) {}

fn modify_a_field(s: &mut S) {
s.usize_field = produce_usize();
}

#[paralegal::marker(noinline ,return)]
#[paralegal::marker(noinline, return)]
fn produce_usize() -> usize {
0
}

#[paralegal::marker(noinline ,return)]
#[paralegal::marker(noinline, return)]
fn produce_string() -> String {
"".to_string()
}
Expand Down
44 changes: 22 additions & 22 deletions crates/paralegal-flow/tests/control-flow-tests/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,39 +31,39 @@ fn process_if_after() {
fn process_nested_if() {
let user_data = get_user_data();
if check_user_data(&user_data) {
if check2(&user_data) {
send_user_data(&user_data);
}
if check2(&user_data) {
send_user_data(&user_data);
}
}
}

#[paralegal::analyze]
fn process_if_multiple_statements() {
let mut user_data = get_user_data();
if check_user_data(&user_data) {
modify(&mut user_data);
send_user_data(&user_data);
modify(&mut user_data);
send_user_data(&user_data);
}
}

#[paralegal::analyze]
fn process_if_not_function_call() {
let x = get_x();
let mut user_data = get_user_data();
let x = get_x();
let mut user_data = get_user_data();
if x > 5 {
modify(&mut user_data);
modify(&mut user_data);
}
send_user_data(&user_data);
send_user_data(&user_data);
}

#[paralegal::analyze]
fn process_no_args() {
let x = get_x();
let mut user_data = UserData{data: vec![]};
let x = get_x();
let mut user_data = UserData { data: vec![] };
if x > 5 {
user_data = get_user_data();
user_data = get_user_data();
}
send_user_data(&user_data);
send_user_data(&user_data);
}

#[paralegal::marker{ noinline, return }]
Expand All @@ -73,35 +73,35 @@ fn get_x() -> i64 {

#[paralegal::marker{source, return}]
fn get_user_data() -> UserData {
return UserData{data: vec![1, 2, 3]}
return UserData {
data: vec![1, 2, 3],
};
}

#[paralegal::marker{checks, arguments = [0]}]
fn check_user_data(user_data: &UserData) -> bool {
for i in &user_data.data {
if i < &0 {
return false
return false;
}
}
return true
return true;
}

#[paralegal::marker{checks, arguments = [0]}]
fn check2(user_data: &UserData) -> bool {
for i in &user_data.data {
if i < &0 {
return false
return false;
}
}
return true
return true;
}

#[paralegal::marker{ sink, arguments = [0] }]
fn send_user_data(_user_data: &UserData) {
}
fn send_user_data(_user_data: &UserData) {}

#[paralegal::marker{ noinline, return }]
fn modify(_user_data: &mut UserData) {
}
fn modify(_user_data: &mut UserData) {}

fn main() {}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ use std::vec::Vec;
fn main() {
let mut v = Vec::new();
v.push(0);
v.push(1);
v.push(1);
}
Loading

0 comments on commit cb72c3f

Please sign in to comment.