summaryrefslogtreecommitdiff
path: root/yjit/src/asm
diff options
context:
space:
mode:
authorAlan Wu <XrXr@users.noreply.github.com>2022-04-29 18:20:23 -0400
committerGitHub <noreply@github.com>2022-04-29 18:20:23 -0400
commit5c843a1a6e24aeabb3497065a362caf7b3e2d3b1 (patch)
tree3933db10caabd1ac0f527f8a2e6e7c0d84f63611 /yjit/src/asm
parent7c039e423cb59c9e5d76df9f1dc1bf8b1a1b9a6b (diff)
downloadruby-5c843a1a6e24aeabb3497065a362caf7b3e2d3b1.tar.gz
YJIT: Enable default rustc lints (warnings) (#5864)
`rustc` performs in depth dead code analysis and issues warning even for things like unused struct fields and unconstructed enum variants. This was annoying for us during the port but hopefully they are less of an issue now. This patch enables all the unused warnings we disabled and address all the warnings we previously ignored. Generally, the approach I've taken is to use `cfg!` instead of using the `cfg` attribute and to delete code where it makes sense. I've put `#[allow(unused)]` on things we intentionally keep around for printf style debugging and on items that are too annoying to keep warning-free in all build configs.
Diffstat (limited to 'yjit/src/asm')
-rw-r--r--yjit/src/asm/mod.rs34
-rw-r--r--yjit/src/asm/x86_64/mod.rs4
-rw-r--r--yjit/src/asm/x86_64/tests.rs2
3 files changed, 10 insertions, 30 deletions
diff --git a/yjit/src/asm/mod.rs b/yjit/src/asm/mod.rs
index 79a08a7381..1d31facb78 100644
--- a/yjit/src/asm/mod.rs
+++ b/yjit/src/asm/mod.rs
@@ -1,6 +1,8 @@
-use std::collections::BTreeMap;
use std::mem;
+#[cfg(feature = "asm_comments")]
+use std::collections::BTreeMap;
+
// Lots of manual vertical alignment in there that rustfmt doesn't handle well.
#[rustfmt::skip]
pub mod x86_64;
@@ -23,6 +25,7 @@ impl CodePtr {
*ptr as i64
}
+ #[allow(unused)]
fn into_usize(&self) -> usize {
let CodePtr(ptr) = self;
*ptr as usize
@@ -36,21 +39,6 @@ impl From<*mut u8> for CodePtr {
}
}
-/// Compute an offset in bytes of a given struct field
-macro_rules! offset_of {
- ($struct_type:ty, $field_name:tt) => {{
- // Null pointer to our struct type
- let foo = (0 as *const $struct_type);
-
- unsafe {
- let ptr_field = (&(*foo).$field_name as *const _ as usize);
- let ptr_base = (foo as usize);
- ptr_field - ptr_base
- }
- }};
-}
-pub(crate) use offset_of;
-
//
// TODO: need a field_size_of macro, to compute the size of a struct field in bytes
//
@@ -71,6 +59,7 @@ struct LabelRef {
pub struct CodeBlock {
// Block of non-executable memory used for dummy code blocks
// This memory is owned by this block and lives as long as the block
+ #[allow(unused)]
dummy_block: Vec<u8>,
// Pointer to memory we are writing into
@@ -110,6 +99,7 @@ pub struct CodeBlock {
}
impl CodeBlock {
+ #[cfg(test)]
pub fn new_dummy(mem_size: usize) -> Self {
// Allocate some non-executable memory
let mut dummy_block = vec![0; mem_size];
@@ -131,6 +121,7 @@ impl CodeBlock {
}
}
+ #[cfg(not(test))]
pub fn new(mem_block: *mut u8, mem_size: usize, page_size: usize) -> Self {
Self {
dummy_block: vec![0; 0],
@@ -175,11 +166,6 @@ impl CodeBlock {
pub fn comments_at(&self, pos: usize) -> Option<&Vec<String>> {
self.asm_comments.get(&pos)
}
- #[cfg(not(feature = "asm_comments"))]
- #[inline]
- pub fn comments_at(&self, _: usize) -> Option<&Vec<String>> {
- None
- }
pub fn get_mem_size(&self) -> usize {
self.mem_size
@@ -246,12 +232,6 @@ impl CodeBlock {
}
}
- // Read a single byte at the given position
- pub fn read_byte(&self, pos: usize) -> u8 {
- assert!(pos < self.mem_size);
- unsafe { self.mem_block.add(pos).read() }
- }
-
// Write multiple bytes starting from the current position
pub fn write_bytes(&mut self, bytes: &[u8]) {
for byte in bytes {
diff --git a/yjit/src/asm/x86_64/mod.rs b/yjit/src/asm/x86_64/mod.rs
index 902b3eb9cc..a2549faab8 100644
--- a/yjit/src/asm/x86_64/mod.rs
+++ b/yjit/src/asm/x86_64/mod.rs
@@ -1,5 +1,5 @@
-use std::io::{Result, Write};
-use std::mem;
+#![allow(dead_code)] // For instructions we don't currently generate
+
use crate::asm::*;
// Import the assembler tests module
diff --git a/yjit/src/asm/x86_64/tests.rs b/yjit/src/asm/x86_64/tests.rs
index f8c34fd3b7..08f65b8821 100644
--- a/yjit/src/asm/x86_64/tests.rs
+++ b/yjit/src/asm/x86_64/tests.rs
@@ -7,7 +7,7 @@ use std::fmt;
impl<'a> fmt::LowerHex for super::CodeBlock {
fn fmt(&self, fmtr: &mut fmt::Formatter) -> fmt::Result {
for pos in 0..self.write_pos {
- let byte = self.read_byte(pos);
+ let byte = unsafe { self.mem_block.add(pos).read() };
fmtr.write_fmt(format_args!("{:02x}", byte))?;
}
Ok(())