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

Fix non-linux compilation warnings. #248

Merged
merged 10 commits into from
Jan 31, 2025
8 changes: 8 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ jobs:
run: ./ci/jobs/build-and-test.sh
- name: Build and test (macOS-only)
run: ./ci/jobs/build-and-test-macos.sh
clippy-macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- name: Install clippy (base toolchain)
run: rustup component add clippy
- name: Run clippy
run: ./ci/jobs/clippy.sh
build-and-test-windows:
runs-on: windows-latest
steps:
Expand Down
12 changes: 8 additions & 4 deletions ci/jobs/clippy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ cd ../..
echo ">> cargo clippy"
RUSTFLAGS="-D warnings" cargo clippy --all

echo ">> cargo clippy (zygote)"
cd crates/polkavm-zygote
RUSTFLAGS="-D warnings" cargo clippy --all
cd ../..
case "$OSTYPE" in
linux*)
echo ">> cargo clippy (zygote)"
cd crates/polkavm-zygote
RUSTFLAGS="-D warnings" cargo clippy --all
cd ../..
;;
esac

echo ">> cargo clippy (guests)"

Expand Down
58 changes: 35 additions & 23 deletions crates/polkavm/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ use alloc::vec::Vec;
use polkavm_common::abi::{MemoryMap, MemoryMapBuilder, VM_ADDR_RETURN_TO_HOST};
use polkavm_common::cast::cast;
use polkavm_common::program::{
build_static_dispatch_table, FrameKind, ISA32_V1_NoSbrk, ISA64_V1_NoSbrk, Imports, InstructionSet, Instructions, JumpTable, Opcode,
ProgramBlob, Reg, ISA32_V1, ISA64_V1,
FrameKind, ISA32_V1_NoSbrk, Imports, InstructionSet, Instructions, JumpTable, Opcode, ProgramBlob, Reg, ISA32_V1, ISA64_V1,
};
use polkavm_common::utils::{ArcBytes, AsUninitSliceMut};

if_compiler_is_supported! {
use polkavm_common::program::{
build_static_dispatch_table, ISA64_V1_NoSbrk,
};
}

use crate::config::{BackendKind, Config, GasMeteringKind, ModuleConfig, SandboxKind};
use crate::error::{bail, bail_static, Error};
use crate::interpreter::{InterpretedInstance, InterpretedModule};
Expand Down Expand Up @@ -226,6 +231,7 @@ impl CompiledModuleKind {
}

pub(crate) struct ModulePrivate {
#[allow(dead_code)]
engine_state: Option<Arc<EngineState>>,
crosscheck: bool,

Expand Down Expand Up @@ -282,8 +288,10 @@ impl Module {
self.state().dynamic_paging
}

pub(crate) fn compiled_module(&self) -> &CompiledModuleKind {
&self.state().compiled_module
if_compiler_is_supported! {
pub(crate) fn compiled_module(&self) -> &CompiledModuleKind {
&self.state().compiled_module
}
}

pub(crate) fn interpreted_module(&self) -> Option<&InterpretedModule> {
Expand Down Expand Up @@ -340,8 +348,10 @@ impl Module {
self.round_to_page_size_down(value) + (u32::from((value & self.state().page_size_mask) != 0) << self.state().page_shift)
}

pub(crate) fn address_to_page(&self, address: u32) -> u32 {
address >> self.state().page_shift
if_compiler_is_supported! {
pub(crate) fn address_to_page(&self, address: u32) -> u32 {
address >> self.state().page_shift
}
}

/// Creates a new module by deserializing the program from the given `bytes`.
Expand Down Expand Up @@ -407,24 +417,26 @@ impl Module {
}
};

let exports = {
log::trace!("Parsing exports...");
let mut exports = Vec::with_capacity(1);
for export in blob.exports() {
log::trace!(" Export at {}: {}", export.program_counter(), export.symbol());
if config.is_strict && cast(export.program_counter().0).to_usize() >= blob.code().len() {
bail!(
"out of range export found; export {} points to code offset {}, while the code blob is only {} bytes",
export.symbol(),
export.program_counter(),
blob.code().len(),
);
}
if_compiler_is_supported! {
let exports = {
log::trace!("Parsing exports...");
let mut exports = Vec::with_capacity(1);
for export in blob.exports() {
log::trace!(" Export at {}: {}", export.program_counter(), export.symbol());
if config.is_strict && cast(export.program_counter().0).to_usize() >= blob.code().len() {
bail!(
"out of range export found; export {} points to code offset {}, while the code blob is only {} bytes",
export.symbol(),
export.program_counter(),
blob.code().len(),
);
}

exports.push(export);
}
exports
};
exports.push(export);
}
exports
};
}

let init = GuestInit {
page_size: config.page_size,
Expand Down
21 changes: 13 additions & 8 deletions crates/polkavm/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use alloc::format;
use alloc::string::{String, ToString};
use polkavm_common::program::ProgramParseError;

Expand Down Expand Up @@ -69,15 +68,21 @@ impl Error {
pub(crate) fn from_static_str(message: &'static str) -> Self {
Error(ErrorKind::Static(message))
}
}

#[cold]
pub(crate) fn context(self, message: impl core::fmt::Display) -> Self {
let string = match self.0 {
ErrorKind::Owned(buffer) => format!("{}: {}", message, buffer),
error => format!("{}: {}", message, Error(error)),
};
if_compiler_is_supported! {
impl Error {
#[cold]
pub(crate) fn context(self, message: impl core::fmt::Display) -> Self {
use alloc::format;

Error(ErrorKind::Owned(string))
let string = match self.0 {
ErrorKind::Owned(buffer) => format!("{}: {}", message, buffer),
error => format!("{}: {}", message, Error(error)),
};

Error(ErrorKind::Owned(string))
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/polkavm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ mod config;
mod gas;
mod interpreter;
mod linker;
mod page_set;
#[cfg(feature = "std")]
mod source_cache;
mod utils;
Expand Down Expand Up @@ -90,6 +89,7 @@ mod module_cache;

if_compiler_is_supported! {
mod compiler;
mod page_set;
mod sandbox;

#[cfg(all(target_os = "linux", not(feature = "export-internals-for-testing")))]
Expand Down
1 change: 1 addition & 0 deletions crates/polkavm/src/mutex_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ impl<T> Mutex<T> {
}

#[inline]
#[allow(dead_code)]
pub fn lock(&self) -> std::sync::MutexGuard<T> {
match self.0.lock() {
Ok(mutable) => mutable,
Expand Down
3 changes: 3 additions & 0 deletions crates/polkavm/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ where
}

#[inline]
#[allow(dead_code)]
pub fn new_reusing_memory(mut memory: Self, capacity: u32) -> Self {
memory.inner.clear();
memory.inner.resize_with(capacity as usize, || None);
Expand All @@ -72,6 +73,7 @@ where
}

#[inline]
#[allow(dead_code)]
pub fn len(&self) -> u32 {
self.inner.len() as u32
}
Expand All @@ -82,6 +84,7 @@ where
}

#[inline]
#[allow(dead_code)]
pub fn clear(&mut self) {
self.inner.clear();
}
Expand Down