From 5b7029fe814271b8236ddeeaea99ad8dd36c0ef6 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Thu, 21 Mar 2024 03:55:02 +0100 Subject: [PATCH] ci: download llvm --- .github/workflows/ci.yml | 59 +++++++++++++++++----------- crates/revm-jit-core/src/lib.rs | 2 + crates/revm-jit-cranelift/src/lib.rs | 1 + crates/revm-jit-llvm/src/lib.rs | 1 + crates/revm-jit/src/bytecode.rs | 57 ++++++++++++++++----------- crates/revm-jit/src/compiler.rs | 2 +- crates/revm-jit/src/lib.rs | 3 +- 7 files changed, 77 insertions(+), 48 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b08c080..5ab7bc8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,6 +7,7 @@ on: env: CARGO_TERM_COLOR: always + LLVM_VERSION: "17.0" concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} @@ -14,43 +15,45 @@ concurrency: jobs: test: - name: test ${{ matrix.rust }} ${{ matrix.flags }} + name: test runs-on: ubuntu-latest timeout-minutes: 30 - strategy: - fail-fast: false - matrix: - rust: ["stable", "nightly"] - # flags: [""] steps: - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@master + - uses: KyleMayes/install-llvm-action@v1 with: - toolchain: ${{ matrix.rust }} + version: ${{ env.LLVM_VERSION }} + - uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@v2 with: cache-on-failure: true - name: test - run: cargo test --workspace # ${{ matrix.flags }} + run: cargo test --workspace - # feature-checks: - # runs-on: ubuntu-latest - # timeout-minutes: 30 - # steps: - # - uses: actions/checkout@v4 - # - uses: dtolnay/rust-toolchain@stable - # - uses: taiki-e/install-action@cargo-hack - # - uses: Swatinem/rust-cache@v2 - # with: - # cache-on-failure: true - # - name: cargo hack - # run: cargo hack check --feature-powerset --depth 2 + feature-checks: + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - uses: actions/checkout@v4 + - uses: KyleMayes/install-llvm-action@v1 + with: + version: ${{ env.LLVM_VERSION }} + - uses: dtolnay/rust-toolchain@stable + - uses: taiki-e/install-action@cargo-hack + - uses: Swatinem/rust-cache@v2 + with: + cache-on-failure: true + - name: cargo hack + run: cargo hack check --feature-powerset --depth 2 clippy: runs-on: ubuntu-latest timeout-minutes: 30 steps: - uses: actions/checkout@v4 + - uses: KyleMayes/install-llvm-action@v1 + with: + version: ${{ env.LLVM_VERSION }} - uses: dtolnay/rust-toolchain@clippy - uses: Swatinem/rust-cache@v2 with: @@ -64,13 +67,25 @@ jobs: timeout-minutes: 30 steps: - uses: actions/checkout@v4 + - uses: KyleMayes/install-llvm-action@v1 + with: + version: ${{ env.LLVM_VERSION }} - uses: dtolnay/rust-toolchain@nightly - uses: Swatinem/rust-cache@v2 with: cache-on-failure: true - run: cargo doc --workspace --all-features --no-deps --document-private-items env: - RUSTDOCFLAGS: "--cfg docsrs -D warnings" + RUSTDOCFLAGS: + --cfg docsrs -D warnings --show-type-layout --generate-link-to-definition + --enable-index-page -Zunstable-options + # - name: Deploy documentation + # uses: peaceiris/actions-gh-pages@v3 + # if: github.event_name == 'push' && github.ref == 'refs/heads/main' + # with: + # github_token: ${{ secrets.GITHUB_TOKEN }} + # publish_dir: target/doc + # force_orphan: true fmt: runs-on: ubuntu-latest diff --git a/crates/revm-jit-core/src/lib.rs b/crates/revm-jit-core/src/lib.rs index 7a5db7a..eef537c 100644 --- a/crates/revm-jit-core/src/lib.rs +++ b/crates/revm-jit-core/src/lib.rs @@ -1,6 +1,8 @@ //! TODO #![allow(missing_docs)] +#![cfg_attr(not(test), warn(unused_extern_crates))] +#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] mod context; pub use context::*; diff --git a/crates/revm-jit-cranelift/src/lib.rs b/crates/revm-jit-cranelift/src/lib.rs index 0852910..841a276 100644 --- a/crates/revm-jit-cranelift/src/lib.rs +++ b/crates/revm-jit-cranelift/src/lib.rs @@ -1,5 +1,6 @@ #![doc = include_str!("../README.md")] #![cfg_attr(not(test), warn(unused_extern_crates))] +#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] use cranelift::{codegen::ir::StackSlot, prelude::*}; use cranelift_jit::{JITBuilder, JITModule}; diff --git a/crates/revm-jit-llvm/src/lib.rs b/crates/revm-jit-llvm/src/lib.rs index 4943263..31a8520 100644 --- a/crates/revm-jit-llvm/src/lib.rs +++ b/crates/revm-jit-llvm/src/lib.rs @@ -1,6 +1,7 @@ //! TODO // #![doc = include_str!("../README.md")] #![cfg_attr(not(test), warn(unused_extern_crates))] +#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] use inkwell::{ attributes::{Attribute, AttributeLoc}, diff --git a/crates/revm-jit/src/bytecode.rs b/crates/revm-jit/src/bytecode.rs index 241f801..e2e3472 100644 --- a/crates/revm-jit/src/bytecode.rs +++ b/crates/revm-jit/src/bytecode.rs @@ -50,18 +50,21 @@ impl<'a> RawBytecodeIter<'a> { } impl<'a> Iterator for RawBytecodeIter<'a> { - type Item = BytecodeOpcode<'a>; + type Item = RawOpcode<'a>; #[inline] fn next(&mut self) -> Option { self.iter.next().copied().map(|opcode| { - let immediate = imm_len(opcode).and_then(|len| { + let len = imm_len(opcode); + let immediate = if len > 0 { let r = self.iter.as_slice().get(..len); // TODO: Use `advance_by` when stable. self.iter.by_ref().take(len).for_each(drop); r - }); - BytecodeOpcode { opcode, immediate } + } else { + None + }; + RawOpcode { opcode, immediate } }) } @@ -76,20 +79,20 @@ impl std::iter::FusedIterator for RawBytecodeIter<'_> {} /// An opcode and its immediate data. Returned by [`RawBytecodeIterator`]. #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] -pub struct BytecodeOpcode<'a> { +pub struct RawOpcode<'a> { /// The opcode. pub opcode: u8, /// The immediate data, if any. pub immediate: Option<&'a [u8]>, } -impl fmt::Debug for BytecodeOpcode<'_> { +impl fmt::Debug for RawOpcode<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(self, f) } } -impl fmt::Display for BytecodeOpcode<'_> { +impl fmt::Display for RawOpcode<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match OPCODE_JUMPMAP[self.opcode as usize] { Some(s) => f.write_str(s), @@ -102,13 +105,22 @@ impl fmt::Display for BytecodeOpcode<'_> { } } -/// Returns the length of the immediate data for the given opcode, if any. +/// Returns the length of the immediate data for the given opcode, or `0` if none. #[inline] -pub const fn imm_len(op: u8) -> Option { +pub const fn imm_len(op: u8) -> usize { match op { - op::PUSH1..=op::PUSH32 => Some((op - op::PUSH0) as usize), - // op::DUPN | op::SWAPN => Some(2), - _ => None, + op::PUSH1..=op::PUSH32 => (op - op::PUSH0) as usize, + // op::DATALOADN => 1, + // + // op::RJUMP => 2, + // op::RJUMPI => 2, + // op::RJUMPV => 2, + // op::CALLF => 2, + // op::JUMPF => 2, + // op::DUPN => 1, + // op::SWAPN => 1, + // op::EXCHANGE => 1, + _ => 0, } } @@ -127,11 +139,11 @@ mod tests { let bytecode = [0x01, 0x02, 0x03, 0x04, 0x05]; let mut iter = RawBytecodeIter::new(&bytecode); - assert_eq!(iter.next(), Some(BytecodeOpcode { opcode: 0x01, immediate: None })); - assert_eq!(iter.next(), Some(BytecodeOpcode { opcode: 0x02, immediate: None })); - assert_eq!(iter.next(), Some(BytecodeOpcode { opcode: 0x03, immediate: None })); - assert_eq!(iter.next(), Some(BytecodeOpcode { opcode: 0x04, immediate: None })); - assert_eq!(iter.next(), Some(BytecodeOpcode { opcode: 0x05, immediate: None })); + assert_eq!(iter.next(), Some(RawOpcode { opcode: 0x01, immediate: None })); + assert_eq!(iter.next(), Some(RawOpcode { opcode: 0x02, immediate: None })); + assert_eq!(iter.next(), Some(RawOpcode { opcode: 0x03, immediate: None })); + assert_eq!(iter.next(), Some(RawOpcode { opcode: 0x04, immediate: None })); + assert_eq!(iter.next(), Some(RawOpcode { opcode: 0x05, immediate: None })); assert_eq!(iter.next(), None); } @@ -140,14 +152,11 @@ mod tests { let bytecode = [op::PUSH0, op::PUSH1, 0x69, op::PUSH2, 0x01, 0x02]; let mut iter = RawBytecodeIter::new(&bytecode); - assert_eq!(iter.next(), Some(BytecodeOpcode { opcode: op::PUSH0, immediate: None })); + assert_eq!(iter.next(), Some(RawOpcode { opcode: op::PUSH0, immediate: None })); + assert_eq!(iter.next(), Some(RawOpcode { opcode: op::PUSH1, immediate: Some(&[0x69]) })); assert_eq!( iter.next(), - Some(BytecodeOpcode { opcode: op::PUSH1, immediate: Some(&[0x69]) }) - ); - assert_eq!( - iter.next(), - Some(BytecodeOpcode { opcode: op::PUSH2, immediate: Some(&[0x01, 0x02]) }) + Some(RawOpcode { opcode: op::PUSH2, immediate: Some(&[0x01, 0x02]) }) ); assert_eq!(iter.next(), None); } @@ -157,7 +166,7 @@ mod tests { let bytecode = [op::PUSH2, 0x69]; let mut iter = RawBytecodeIter::new(&bytecode); - assert_eq!(iter.next(), Some(BytecodeOpcode { opcode: op::PUSH2, immediate: None })); + assert_eq!(iter.next(), Some(RawOpcode { opcode: op::PUSH2, immediate: None })); assert_eq!(iter.next(), None); } diff --git a/crates/revm-jit/src/compiler.rs b/crates/revm-jit/src/compiler.rs index 8c08b7e..9094ec9 100644 --- a/crates/revm-jit/src/compiler.rs +++ b/crates/revm-jit/src/compiler.rs @@ -112,8 +112,8 @@ impl FunctionCx { } fn translate_opcode(&mut self, opcode: u8, imm: Option<&[u8]>) -> Result<()> { - self.bcx.nop(); /* + self.bcx.nop(); if self.clif_comments.enabled() { let inst = self.last_inst(); let mut comment = String::with_capacity(16); diff --git a/crates/revm-jit/src/lib.rs b/crates/revm-jit/src/lib.rs index 465d739..a4fbe81 100644 --- a/crates/revm-jit/src/lib.rs +++ b/crates/revm-jit/src/lib.rs @@ -1,5 +1,6 @@ #![doc = include_str!("../README.md")] #![cfg_attr(not(test), warn(unused_extern_crates))] +#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] use revm_primitives::U256; @@ -24,7 +25,7 @@ mod compiler; pub use compiler::JitEvm; mod bytecode; -pub use bytecode::{format_bytecode, imm_len, BytecodeOpcode, RawBytecodeIter}; +pub use bytecode::{format_bytecode, imm_len, RawBytecodeIter, RawOpcode}; #[allow(dead_code)] const MINUS_1: U256 = U256::MAX;