Skip to content
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

add more stringent formatting #10

Merged
merged 5 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
core:
- changed-files:
- any-glob-to-any-file: 'src/core/**'
- any-glob-to-any-file: "src/core/**"
execution:
- changed-files:
- any-glob-to-any-file: 'src/execution/**'
- any-glob-to-any-file: "src/execution/**"
validation:
- changed-files:
- any-glob-to-any-file: 'src/validation/**'
- any-glob-to-any-file: "src/validation/**"

tests:
- changed-files:
- any-glob-to-any-file: 'tests/**'
- any-glob-to-any-file: "tests/**"

examples:
- changed-files:
- any-glob-to-any-file: 'examples/**'
- any-glob-to-any-file: "examples/**"

priority-high:
# Hotfixes are critical
- head-branch: ['^hotfix', 'hotfix']
- changed-files:
- any-glob-to-any-file: [
'src/**',
# We treat configuration modification as high priority
# as I reckon we'll have critical CI/CD workflow changes
# and other changes that are highly needed for a
# healthy functioning of the project
'.github/**'
]
- head-branch: ["^hotfix", "hotfix"]
- changed-files:
- any-glob-to-any-file: [
"src/**",
# We treat configuration modification as high priority
# as I reckon we'll have critical CI/CD workflow changes
# and other changes that are highly needed for a
# healthy functioning of the project
".github/**",
]

# We treat tests as medium priority (for now)
# as we get to have specialized tests
# (for functionality that is not critical)
# we will then have different priorities for different tests
priority-medium:
- changed-files:
- any-glob-to-any-file: 'tests/**'
- any-glob-to-any-file: "tests/**"

priority-low:
- changed-files:
- any-glob-to-any-file: 'examples/**'
- any-glob-to-any-file: "examples/**"

hotfix:
- head-branch: ['^hotfix', 'hotfix']
- head-branch: ["^hotfix", "hotfix"]
bugfix:
- head-branch: ['^bugfix', 'bugfix']
- head-branch: ["^bugfix", "bugfix"]
feature:
- head-branch: ['^feature', 'feature']
- head-branch: ["^feature", "feature"]
7 changes: 2 additions & 5 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,26 @@

This pull request adds/changes/fixes...


### Testing Strategy

This pull request was tested by...


### TODO or Help Wanted

This pull request still needs...


### Formatting

- [ ] Ran `cargo fmt`
- [ ] Ran `cargo check`
- [ ] Ran `cargo build`

- [ ] Ran `nix fmt`
- [ ] Ran `treefmt`

### Github Issue

This pull request closes <GITHUB_ISSUE>


### Author

Signed-off-by: <YOUR_NAME> <YOUR_EMAIL_HERE@EXAMPLE.COM>
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

name: wasm-interpreter-ci

on:
Expand Down Expand Up @@ -28,4 +27,4 @@ jobs:
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
run: cargo test --verbose
4 changes: 2 additions & 2 deletions .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: "Pull Request Labeler"
on:
- pull_request_target
- pull_request_target

jobs:
labeler:
Expand All @@ -9,4 +9,4 @@ jobs:
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/labeler@v5
- uses: actions/labeler@v5
25 changes: 25 additions & 0 deletions .github/workflows/nix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Nix Related Actions

on:
pull_request:
push:
branches: [main]

jobs:
checks:
name: Nix Checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v27
with:
nix_path: nixpkgs=channel:nixos-stable
extra_nix_config: |
experimental-features = nix-command flakes
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- uses: cachix/cachix-action@v14
with:
name: dlr-ft
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
- name: Run Checks
run: nix flake check
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
.direnv/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ fully `no_std`.
## More information

- `A fast in-place interpreter` by Ben L. Titzer: https://arxiv.org/abs/2205.01183
- WebAssembly spec: https://webassembly.github.io/spec/core/index.html
- WebAssembly spec: https://webassembly.github.io/spec/core/index.html
21 changes: 21 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 24 additions & 11 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@
url = "git+https://github.com/nix-community/naersk.git";
inputs.nixpkgs.follows = "nixpkgs";
};
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, utils, naersk, devshell, ... }@inputs:
outputs = { self, nixpkgs, utils, naersk, devshell, treefmt-nix, ... }@inputs:
utils.lib.eachSystem [ "x86_64-linux" "i686-linux" "aarch64-linux" ] (system:
let
lib = nixpkgs.lib;
Expand All @@ -23,6 +27,9 @@
overlays = [ devshell.overlays.default ];
};

# universal formatter
treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;

# rust target name of the `system`
rust-target = pkgs.rust.toRustTarget pkgs.pkgsStatic.targetPlatform;

Expand Down Expand Up @@ -51,7 +58,7 @@
# a devshell with all the necessary bells and whistles
devShells.default = (pkgs.devshell.mkShell {
imports = [ "${devshell}/extra/git/hooks.nix" ];
name = "aa";
name = "wasm-interpreter";
packages = with pkgs; [
stdenv.cc
coreutils
Expand All @@ -62,26 +69,32 @@
cargo-watch
cargo-audit
cargo-expand
nixpkgs-fmt
nodePackages.prettier
wabt

# utilities
nixpkgs-fmt
nodePackages.prettier
treefmtEval.config.build.wrapper
];
git.hooks = {
enable = true;
pre-commit.text = "nix flake check";
};
});


# for `nix fmt`
formatter = treefmtEval.config.build.wrapper;

# always check these
checks = {
nixpkgs-fmt = pkgs.runCommand "nixpkgs-fmt"
{
nativeBuildInputs = [ pkgs.nixpkgs-fmt ];
} "nixpkgs-fmt --check ${./.}; touch $out";
cargo-fmt = pkgs.runCommand "cargo-fmt"
{
nativeBuildInputs = [ rust-toolchain ];
} "cd ${./.}; cargo fmt --check; touch $out";
formatting = treefmtEval.config.build.check self;
# TODO remove once https://github.com/numtide/treefmt/issues/153 is closed
format-bug-fix = pkgs.runCommand "yaml-fmt"
{
nativeBuildInputs = [ pkgs.nodePackages.prettier ];
} "cd ${./.} && prettier --check .github; touch $out";
};
});
}
Expand Down
7 changes: 6 additions & 1 deletion src/core/indices.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// /// This macro defines index types. Currently (2024-06-10) all indices are [`u32`].
// /// See <https://webassembly.github.io/spec/core/binary/modules.html#indices> for more information.
// macro_rules! def_idx_types {
// ($($name:ident),*) => {
// $(
Expand All @@ -10,6 +12,9 @@
// // #[allow(dead_code)]
// def_idx_types!(TypeIdx, FuncIdx, TableIdx, MemIdx, GlobalIdx, /* ElemIdx, DataIdx, */ LocalIdx/* , LabelIdx */);

// TODO check whether is is clever to internally use usize instead of u32; potential problems are:
// - unsound on architectures where `usize` < `u32`
// - wasteful in memory on architectures where `usize` > `u32`
pub type TypeIdx = usize;
pub type FuncIdx = usize;
pub type TableIdx = usize;
Expand All @@ -21,4 +26,4 @@ pub type ElemIdx = usize;
pub type DataIdx = usize;
pub type LocalIdx = usize;
#[allow(dead_code)]
pub type LabelIdx = usize;
pub type LabelIdx = usize;
4 changes: 2 additions & 2 deletions src/core/reader/types/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ impl WasmReadable for Global {
fn read(wasm: &mut WasmReader) -> Result<Self> {
Ok(Self {
ty: GlobalType::read(wasm)?,
init_expr: ()/* todo!("read constant expression") */,
init_expr: (), /* todo!("read constant expression") */
})
}

fn read_unvalidated(wasm: &mut WasmReader) -> Self {
Self {
ty: GlobalType::read_unvalidated(wasm),
init_expr: ()/* todo!("read constant expression") */,
init_expr: (), /* todo!("read constant expression") */
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/execution/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,7 @@ impl InteropValueList for () {
}

#[allow(warnings)]
fn from_values(_values: impl Iterator<Item = Value>) -> Self {

}
fn from_values(_values: impl Iterator<Item = Value>) -> Self {}
}

impl<A: InteropValue> InteropValueList for A {
Expand Down
1 change: 0 additions & 1 deletion src/validation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ pub fn validate(wasm: &[u8]) -> Result<ValidationInfo> {

let globals = handle_section(&mut wasm, &mut header, SectionTy::Global, |wasm, _| {
wasm.read_vec(|wasm| {

// TODO validate instructions in `global.init_expr`. Furthermore all of these instructions need to be constant.
// See https://webassembly.github.io/spec/core/valid/instructions.html#valid-constant
// Maybe we can also execute constant expressions right here so they do not even exist in the runtime environment. <-- Needs further research to check if this is even possible
Expand Down
13 changes: 13 additions & 0 deletions treefmt.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{ pkgs, ... }:
{
# Used to find the project root
projectRootFile = "flake.nix";
programs.prettier = {
enable = true;
settings = {
plugins = [
"${pkgs.nodePackages.prettier-plugin-toml}/lib/node_modules/prettier-plugin-toml/lib/index.js"
];
};
};
}
17 changes: 17 additions & 0 deletions treefmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[formatter.nix]
command = "nixpkgs-fmt"
includes = ["*.nix"]

[formatter.prettier]
command = "prettier"
options = ["--write"]
includes = [
"*.yaml",
"*.yml",
"*.md",
]

[formatter.rust]
command = "rustfmt"
options = ["--edition", "2021"]
includes = ["*.rs"]