Skip to content

Commit c9ea320

Browse files
caizixianqinsoon
andauthored
Apply style check on auxiliary crates (macros and dummyvm) (#913)
This commit was originally backed out of #905. Add clippy check and cargo fmt check for auxiliary crates (`macros` and `dummyvm`). --------- Co-authored-by: Yi Lin <qinsoon@gmail.com>
1 parent a099b19 commit c9ea320

20 files changed

+219
-109
lines changed

.github/scripts/ci-style.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
export RUSTFLAGS="-D warnings"
44

5+
# --- Check main crate ---
6+
57
# check base
68
cargo clippy
79
# check all features
@@ -10,8 +12,6 @@ for_all_features "cargo clippy"
1012
for_all_features "cargo clippy --release"
1113
# check for tests
1214
for_all_features "cargo clippy --tests"
13-
# check for dummyvm
14-
cargo clippy --manifest-path=vmbindings/dummyvm/Cargo.toml
1515

1616
# target-specific features
1717
if [[ $arch == "x86_64" && $os == "linux" ]]; then
@@ -20,5 +20,14 @@ if [[ $arch == "x86_64" && $os == "linux" ]]; then
2020
cargo clippy --tests --features perf_counter
2121
fi
2222

23-
# check format
24-
cargo fmt -- --check
23+
# --- Check auxiliary crate ---
24+
25+
style_check_auxiliary_crate() {
26+
crate_path=$1
27+
28+
cargo clippy --manifest-path=$crate_path/Cargo.toml
29+
cargo fmt --manifest-path=$crate_path/Cargo.toml -- --check
30+
}
31+
32+
style_check_auxiliary_crate macros
33+
style_check_auxiliary_crate vmbindings/dummyvm

macros/src/lib.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
extern crate proc_macro;
2-
extern crate syn;
32
extern crate proc_macro_error;
43
extern crate quote;
4+
extern crate syn;
55

66
use proc_macro::TokenStream;
7-
use proc_macro_error::proc_macro_error;
8-
use syn::{parse_macro_input};
97
use proc_macro_error::abort_call_site;
8+
use proc_macro_error::proc_macro_error;
109
use quote::quote;
10+
use syn::parse_macro_input;
1111
use syn::DeriveInput;
1212

13-
mod util;
1413
mod plan_trace_object_impl;
14+
mod util;
1515

1616
const DEBUG_MACRO_OUTPUT: bool = false;
1717

@@ -37,15 +37,22 @@ pub fn derive_plan_trace_object(input: TokenStream) -> TokenStream {
3737
let output = if let syn::Data::Struct(syn::DataStruct {
3838
fields: syn::Fields::Named(ref fields),
3939
..
40-
}) = input.data {
40+
}) = input.data
41+
{
4142
let spaces = util::get_fields_with_attribute(fields, "trace");
4243
let post_scan_spaces = util::get_fields_with_attribute(fields, "post_scan");
4344
let fallback = util::get_unique_field_with_attribute(fields, "fallback_trace");
4445

45-
let trace_object_function = plan_trace_object_impl::generate_trace_object(&spaces, &fallback, &ty_generics);
46-
let post_scan_object_function = plan_trace_object_impl::generate_post_scan_object(&post_scan_spaces, &fallback, &ty_generics);
47-
let may_move_objects_function = plan_trace_object_impl::generate_may_move_objects(&spaces, &fallback, &ty_generics);
48-
quote!{
46+
let trace_object_function =
47+
plan_trace_object_impl::generate_trace_object(&spaces, &fallback, &ty_generics);
48+
let post_scan_object_function = plan_trace_object_impl::generate_post_scan_object(
49+
&post_scan_spaces,
50+
&fallback,
51+
&ty_generics,
52+
);
53+
let may_move_objects_function =
54+
plan_trace_object_impl::generate_may_move_objects(&spaces, &fallback, &ty_generics);
55+
quote! {
4956
impl #impl_generics crate::plan::PlanTraceObject #ty_generics for #ident #ty_generics #where_clause {
5057
#trace_object_function
5158

macros/src/plan_trace_object_impl.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use proc_macro2::TokenStream as TokenStream2;
12
use quote::quote;
23
use syn::{Field, TypeGenerics};
3-
use proc_macro2::TokenStream as TokenStream2;
44

55
use crate::util;
66

@@ -12,7 +12,7 @@ pub(crate) fn generate_trace_object<'a>(
1212
// Generate a check with early return for each space
1313
let space_field_handler = space_fields.iter().map(|f| {
1414
let f_ident = f.ident.as_ref().unwrap();
15-
let ref f_ty = f.ty;
15+
let f_ty = &f.ty;
1616

1717
// Figure out copy
1818
let trace_attr = util::get_field_attribute(f, "trace").unwrap();
@@ -42,7 +42,7 @@ pub(crate) fn generate_trace_object<'a>(
4242
// Generate a fallback to the parent plan
4343
let parent_field_delegator = if let Some(f) = parent_field {
4444
let f_ident = f.ident.as_ref().unwrap();
45-
let ref f_ty = f.ty;
45+
let f_ty = &f.ty;
4646
quote! {
4747
<#f_ty as PlanTraceObject #ty_generics>::trace_object::<Q, KIND>(&self.#f_ident, __mmtk_queue, __mmtk_objref, __mmtk_worker)
4848
}
@@ -70,7 +70,7 @@ pub(crate) fn generate_post_scan_object<'a>(
7070
) -> TokenStream2 {
7171
let scan_field_handler = post_scan_object_fields.iter().map(|f| {
7272
let f_ident = f.ident.as_ref().unwrap();
73-
let ref f_ty = f.ty;
73+
let f_ty = &f.ty;
7474

7575
quote! {
7676
if self.#f_ident.in_space(__mmtk_objref) {
@@ -84,7 +84,7 @@ pub(crate) fn generate_post_scan_object<'a>(
8484
// Generate a fallback to the parent plan
8585
let parent_field_delegator = if let Some(f) = parent_field {
8686
let f_ident = f.ident.as_ref().unwrap();
87-
let ref f_ty = f.ty;
87+
let f_ty = &f.ty;
8888
quote! {
8989
<#f_ty as PlanTraceObject #ty_generics>::post_scan_object(&self.#f_ident, __mmtk_objref)
9090
}
@@ -110,15 +110,15 @@ pub(crate) fn generate_may_move_objects<'a>(
110110
) -> TokenStream2 {
111111
// If any space or the parent may move objects, the plan may move objects
112112
let space_handlers = space_fields.iter().map(|f| {
113-
let ref f_ty = f.ty;
113+
let f_ty = &f.ty;
114114

115115
quote! {
116116
|| <#f_ty as PolicyTraceObject #ty_generics>::may_move_objects::<KIND>()
117117
}
118118
});
119119

120120
let parent_handler = if let Some(p) = parent_field {
121-
let ref p_ty = p.ty;
121+
let p_ty = &p.ty;
122122

123123
quote! {
124124
|| <#p_ty as PlanTraceObject #ty_generics>::may_move_objects::<KIND>()

vmbindings/dummyvm/src/active_plan.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
use mmtk::Plan;
2-
use mmtk::vm::ActivePlan;
3-
use mmtk::util::opaque_pointer::*;
4-
use mmtk::Mutator;
51
use crate::DummyVM;
62
use crate::SINGLETON;
3+
use mmtk::util::opaque_pointer::*;
4+
use mmtk::vm::ActivePlan;
5+
use mmtk::Mutator;
6+
use mmtk::Plan;
77

8-
pub struct VMActivePlan<> {}
8+
pub struct VMActivePlan {}
99

1010
impl ActivePlan<DummyVM> for VMActivePlan {
11-
fn global() -> &'static dyn Plan<VM=DummyVM> {
11+
fn global() -> &'static dyn Plan<VM = DummyVM> {
1212
SINGLETON.get_plan()
1313
}
1414

vmbindings/dummyvm/src/api.rs

Lines changed: 55 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
11
// All functions here are extern function. There is no point for marking them as unsafe.
22
#![allow(clippy::not_unsafe_ptr_arg_deref)]
33

4+
use crate::DummyVM;
5+
use crate::BUILDER;
6+
use crate::SINGLETON;
47
use libc::c_char;
5-
use std::sync::atomic::Ordering;
6-
use std::ffi::CStr;
78
use mmtk::memory_manager;
8-
use mmtk::AllocationSemantics;
9-
use mmtk::util::{ObjectReference, Address};
10-
use mmtk::util::opaque_pointer::*;
119
use mmtk::scheduler::{GCController, GCWorker};
10+
use mmtk::util::opaque_pointer::*;
11+
use mmtk::util::{Address, ObjectReference};
12+
use mmtk::AllocationSemantics;
1213
use mmtk::Mutator;
13-
use crate::DummyVM;
14-
use crate::SINGLETON;
15-
use crate::BUILDER;
14+
use std::ffi::CStr;
15+
use std::sync::atomic::Ordering;
1616

1717
#[no_mangle]
1818
pub extern "C" fn mmtk_init(heap_size: usize) {
1919
// set heap size first
2020
{
2121
let mut builder = BUILDER.lock().unwrap();
22-
let success = builder.options.gc_trigger.set(mmtk::util::options::GCTriggerSelector::FixedHeapSize(heap_size));
22+
let success =
23+
builder
24+
.options
25+
.gc_trigger
26+
.set(mmtk::util::options::GCTriggerSelector::FixedHeapSize(
27+
heap_size,
28+
));
2329
assert!(success, "Failed to set heap size to {}", heap_size);
2430
}
2531

@@ -43,18 +49,37 @@ pub extern "C" fn mmtk_destroy_mutator(mutator: *mut Mutator<DummyVM>) {
4349
}
4450

4551
#[no_mangle]
46-
pub extern "C" fn mmtk_alloc(mutator: *mut Mutator<DummyVM>, size: usize,
47-
align: usize, offset: usize, mut semantics: AllocationSemantics) -> Address {
48-
if size >= SINGLETON.get_plan().constraints().max_non_los_default_alloc_bytes {
52+
pub extern "C" fn mmtk_alloc(
53+
mutator: *mut Mutator<DummyVM>,
54+
size: usize,
55+
align: usize,
56+
offset: usize,
57+
mut semantics: AllocationSemantics,
58+
) -> Address {
59+
if size
60+
>= SINGLETON
61+
.get_plan()
62+
.constraints()
63+
.max_non_los_default_alloc_bytes
64+
{
4965
semantics = AllocationSemantics::Los;
5066
}
5167
memory_manager::alloc::<DummyVM>(unsafe { &mut *mutator }, size, align, offset, semantics)
5268
}
5369

5470
#[no_mangle]
55-
pub extern "C" fn mmtk_post_alloc(mutator: *mut Mutator<DummyVM>, refer: ObjectReference,
56-
bytes: usize, mut semantics: AllocationSemantics) {
57-
if bytes >= SINGLETON.get_plan().constraints().max_non_los_default_alloc_bytes {
71+
pub extern "C" fn mmtk_post_alloc(
72+
mutator: *mut Mutator<DummyVM>,
73+
refer: ObjectReference,
74+
bytes: usize,
75+
mut semantics: AllocationSemantics,
76+
) {
77+
if bytes
78+
>= SINGLETON
79+
.get_plan()
80+
.constraints()
81+
.max_non_los_default_alloc_bytes
82+
{
5883
semantics = AllocationSemantics::Los;
5984
}
6085
memory_manager::post_alloc::<DummyVM>(unsafe { &mut *mutator }, refer, bytes, semantics)
@@ -66,7 +91,10 @@ pub extern "C" fn mmtk_will_never_move(object: ObjectReference) -> bool {
6691
}
6792

6893
#[no_mangle]
69-
pub extern "C" fn mmtk_start_control_collector(tls: VMWorkerThread, controller: &'static mut GCController<DummyVM>) {
94+
pub extern "C" fn mmtk_start_control_collector(
95+
tls: VMWorkerThread,
96+
controller: &'static mut GCController<DummyVM>,
97+
) {
7098
memory_manager::start_control_collector(&SINGLETON, tls, controller);
7199
}
72100

@@ -106,7 +134,7 @@ pub extern "C" fn mmtk_total_bytes() -> usize {
106134
}
107135

108136
#[no_mangle]
109-
pub extern "C" fn mmtk_is_live_object(object: ObjectReference) -> bool{
137+
pub extern "C" fn mmtk_is_live_object(object: ObjectReference) -> bool {
110138
memory_manager::is_live_object(object)
111139
}
112140

@@ -166,7 +194,11 @@ pub extern "C" fn mmtk_process(name: *const c_char, value: *const c_char) -> boo
166194
let name_str: &CStr = unsafe { CStr::from_ptr(name) };
167195
let value_str: &CStr = unsafe { CStr::from_ptr(value) };
168196
let mut builder = BUILDER.lock().unwrap();
169-
memory_manager::process(&mut builder, name_str.to_str().unwrap(), value_str.to_str().unwrap())
197+
memory_manager::process(
198+
&mut builder,
199+
name_str.to_str().unwrap(),
200+
value_str.to_str().unwrap(),
201+
)
170202
}
171203

172204
#[no_mangle]
@@ -201,7 +233,11 @@ pub extern "C" fn mmtk_calloc(num: usize, size: usize) -> Address {
201233

202234
#[no_mangle]
203235
#[cfg(feature = "malloc_counted_size")]
204-
pub extern "C" fn mmtk_realloc_with_old_size(addr: Address, size: usize, old_size: usize) -> Address {
236+
pub extern "C" fn mmtk_realloc_with_old_size(
237+
addr: Address,
238+
size: usize,
239+
old_size: usize,
240+
) -> Address {
205241
memory_manager::realloc_with_old_size::<DummyVM>(&SINGLETON, addr, size, old_size)
206242
}
207243
#[no_mangle]

vmbindings/dummyvm/src/object_model.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
use crate::DummyVM;
12
use mmtk::util::copy::{CopySemantics, GCWorkerCopyContext};
23
use mmtk::util::{Address, ObjectReference};
34
use mmtk::vm::*;
4-
use crate::DummyVM;
55

66
pub struct VMObjectModel {}
77

@@ -11,10 +11,13 @@ pub const OBJECT_REF_OFFSET: usize = 4;
1111

1212
impl ObjectModel<DummyVM> for VMObjectModel {
1313
const GLOBAL_LOG_BIT_SPEC: VMGlobalLogBitSpec = VMGlobalLogBitSpec::in_header(0);
14-
const LOCAL_FORWARDING_POINTER_SPEC: VMLocalForwardingPointerSpec = VMLocalForwardingPointerSpec::in_header(0);
15-
const LOCAL_FORWARDING_BITS_SPEC: VMLocalForwardingBitsSpec = VMLocalForwardingBitsSpec::in_header(0);
14+
const LOCAL_FORWARDING_POINTER_SPEC: VMLocalForwardingPointerSpec =
15+
VMLocalForwardingPointerSpec::in_header(0);
16+
const LOCAL_FORWARDING_BITS_SPEC: VMLocalForwardingBitsSpec =
17+
VMLocalForwardingBitsSpec::in_header(0);
1618
const LOCAL_MARK_BIT_SPEC: VMLocalMarkBitSpec = VMLocalMarkBitSpec::in_header(0);
17-
const LOCAL_LOS_MARK_NURSERY_SPEC: VMLocalLOSMarkNurserySpec = VMLocalLOSMarkNurserySpec::in_header(0);
19+
const LOCAL_LOS_MARK_NURSERY_SPEC: VMLocalLOSMarkNurserySpec =
20+
VMLocalLOSMarkNurserySpec::in_header(0);
1821

1922
const OBJECT_REF_OFFSET_LOWER_BOUND: isize = OBJECT_REF_OFFSET as isize;
2023

vmbindings/dummyvm/src/reference_glue.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use mmtk::vm::ReferenceGlue;
2-
use mmtk::util::ObjectReference;
3-
use mmtk::util::opaque_pointer::VMWorkerThread;
41
use crate::DummyVM;
2+
use mmtk::util::opaque_pointer::VMWorkerThread;
3+
use mmtk::util::ObjectReference;
4+
use mmtk::vm::ReferenceGlue;
55

66
pub struct VMReferenceGlue {}
77

vmbindings/dummyvm/src/scanning.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::DummyVM;
21
use crate::edges::DummyVMEdge;
2+
use crate::DummyVM;
33
use mmtk::util::opaque_pointer::*;
44
use mmtk::util::ObjectReference;
55
use mmtk::vm::EdgeVisitor;

vmbindings/dummyvm/src/tests/allocate_align_offset.rs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// GITHUB-CI: MMTK_PLAN=all
22

33
use crate::api;
4+
use crate::tests::fixtures::{MutatorFixture, SerialFixture};
45
use crate::DummyVM;
5-
use crate::tests::fixtures::{SerialFixture, MutatorFixture};
6+
use log::info;
67
use mmtk::plan::AllocationSemantics;
78
use mmtk::vm::VMBinding;
8-
use log::info;
99

1010
lazy_static! {
1111
static ref MUTATOR: SerialFixture<MutatorFixture> = SerialFixture::new();
@@ -21,7 +21,12 @@ pub fn allocate_alignment() {
2121
while align <= max {
2222
info!("Test allocation with alignment {}", align);
2323
let addr = api::mmtk_alloc(fixture.mutator, 8, align, 0, AllocationSemantics::Default);
24-
assert!(addr.is_aligned_to(align), "Expected allocation alignment {}, returned address is {:?}", align, addr);
24+
assert!(
25+
addr.is_aligned_to(align),
26+
"Expected allocation alignment {}, returned address is {:?}",
27+
align,
28+
addr
29+
);
2530
align *= 2;
2631
}
2732
})
@@ -36,9 +41,23 @@ pub fn allocate_offset() {
3641
info!("Allowed alignment between {} and {}", min, max);
3742
let mut align = min;
3843
while align <= max {
39-
info!("Test allocation with alignment {} and offset {}", align, OFFSET);
40-
let addr = api::mmtk_alloc(fixture.mutator, 8, align, OFFSET, AllocationSemantics::Default);
41-
assert!((addr + OFFSET).is_aligned_to(align), "Expected allocation alignment {}, returned address is {:?}", align, addr);
44+
info!(
45+
"Test allocation with alignment {} and offset {}",
46+
align, OFFSET
47+
);
48+
let addr = api::mmtk_alloc(
49+
fixture.mutator,
50+
8,
51+
align,
52+
OFFSET,
53+
AllocationSemantics::Default,
54+
);
55+
assert!(
56+
(addr + OFFSET).is_aligned_to(align),
57+
"Expected allocation alignment {}, returned address is {:?}",
58+
align,
59+
addr
60+
);
4261
align *= 2;
4362
}
4463
})

0 commit comments

Comments
 (0)