Skip to content

Commit f7b9f20

Browse files
authored
Update rust toolchain to v1.81.0 (#442)
* Update rust toolchain to v1.81.0 * Add lints config * Avoid to use legacy numeric method * Fix cargo check
1 parent a4dab6b commit f7b9f20

26 files changed

+99
-104
lines changed

Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ version = "0.24.0"
55
license = "MIT"
66
authors = ["Nervos Core Dev <dev@nervos.org>"]
77
edition = "2021"
8-
rust-version = "1.75.0"
8+
rust-version = "1.81.0"
99
build = "build.rs"
1010
exclude = ["/benches", "/tests"]
1111
homepage = "https://github.com/nervosnetwork/ckb-vm"
@@ -54,3 +54,6 @@ harness = false
5454
name = "vm_benchmark"
5555
path = "benches/vm_benchmark.rs"
5656
harness = false
57+
58+
[lints.rust]
59+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(has_asm)'] }

benches/vm_benchmark.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn asm_benchmark(c: &mut Criterion) {
4242
"bar"].into_iter().map(|a| a.into()).collect();
4343

4444
b.iter(|| {
45-
let asm_core = AsmCoreMachine::new(ISA_IMC, VERSION0, u64::max_value());
45+
let asm_core = AsmCoreMachine::new(ISA_IMC, VERSION0, u64::MAX);
4646
let core = DefaultMachineBuilder::new(asm_core).build();
4747
let mut machine = AsmMachine::new(core);
4848
machine.load_program(&buffer, &args[..]).unwrap();
@@ -61,7 +61,7 @@ fn mop_benchmark(c: &mut Criterion) {
6161
"foo",
6262
"bar"].into_iter().map(|a| a.into()).collect();
6363
b.iter(|| {
64-
let asm_core = AsmCoreMachine::new(ISA_IMC | ISA_B | ISA_MOP, VERSION2, u64::max_value());
64+
let asm_core = AsmCoreMachine::new(ISA_IMC | ISA_B | ISA_MOP, VERSION2, u64::MAX);
6565
let core = DefaultMachineBuilder::<Box<AsmCoreMachine>>::new(asm_core)
6666
.build();
6767
let mut machine = AsmMachine::new(core);
@@ -83,15 +83,15 @@ fn mop_memoized_benchmark(c: &mut Criterion) {
8383
"foo",
8484
"bar"].into_iter().map(|a| a.into()).collect();
8585
let mut decoder = MemoizedFixedTraceDecoder::new(build_decoder::<u64>(isa, version));
86-
let asm_core = AsmCoreMachine::new(isa, version, u64::max_value());
86+
let asm_core = AsmCoreMachine::new(isa, version, u64::MAX);
8787
let core = DefaultMachineBuilder::<Box<AsmCoreMachine>>::new(asm_core)
8888
.build();
8989
let mut machine = AsmMachine::new(core);
9090
machine.load_program(&buffer, &args).unwrap();
9191
machine.run_with_decoder(&mut decoder).unwrap();
9292

9393
b.iter(|| {
94-
let asm_core = AsmCoreMachine::new(isa, version, u64::max_value());
94+
let asm_core = AsmCoreMachine::new(isa, version, u64::MAX);
9595
let core = DefaultMachineBuilder::<Box<AsmCoreMachine>>::new(asm_core)
9696
.build();
9797
let mut machine = AsmMachine::new(core);
@@ -114,15 +114,15 @@ fn mop_memoized_dynamic_benchmark(c: &mut Criterion) {
114114
"foo",
115115
"bar"].into_iter().map(|a| a.into()).collect();
116116
let mut decoder = MemoizedDynamicTraceDecoder::new(build_decoder::<u64>(isa, version));
117-
let asm_core = AsmCoreMachine::new(isa, version, u64::max_value());
117+
let asm_core = AsmCoreMachine::new(isa, version, u64::MAX);
118118
let core = DefaultMachineBuilder::<Box<AsmCoreMachine>>::new(asm_core)
119119
.build();
120120
let mut machine = AsmMachine::new(core);
121121
machine.load_program(&buffer, &args).unwrap();
122122
machine.run_with_decoder(&mut decoder).unwrap();
123123

124124
b.iter(|| {
125-
let asm_core = AsmCoreMachine::new(isa, version, u64::max_value());
125+
let asm_core = AsmCoreMachine::new(isa, version, u64::MAX);
126126
let core = DefaultMachineBuilder::<Box<AsmCoreMachine>>::new(asm_core)
127127
.build();
128128
let mut machine = AsmMachine::new(core);

definitions/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ version = "0.24.0"
55
license = "MIT"
66
authors = ["Nervos Core Dev <dev@nervos.org>"]
77
edition = "2021"
8-
rust-version = "1.75.0"
8+
rust-version = "1.81.0"
99
autobins = false
1010
homepage = "https://github.com/nervosnetwork/ckb-vm"
1111
repository = "https://github.com/nervosnetwork/ckb-vm"

definitions/src/asm.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ impl AsmCoreMachine {
147147
machine.frames_size = (memory_size / MEMORY_FRAMESIZE) as u64;
148148
machine.flags_size = (memory_size / RISCV_PAGESIZE) as u64;
149149

150-
machine.last_read_frame = u64::max_value();
151-
machine.last_write_page = u64::max_value();
150+
machine.last_read_frame = u64::MAX;
151+
machine.last_write_page = u64::MAX;
152152

153153
let memory_layout = Layout::array::<u8>(machine.memory_size as usize).unwrap();
154154
machine.memory_ptr = unsafe { alloc(memory_layout) } as u64;

definitions/src/instructions.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ macro_rules! __for_each_inst_inner {
293293
/// a callback macro that takes (at least) 3 arguments:
294294
///
295295
/// 1. $name: an identifier containing the full defined opcode name,
296-
/// e.g., OP_ADD
296+
/// e.g., OP_ADD
297297
/// 2. $real_name: an identifier containing just the opcode part, e.g., ADD
298298
/// 3. $code: an expr containing the actual opcode number
299299
///
@@ -324,10 +324,10 @@ macro_rules! for_each_inst2 {
324324
/// arguments:
325325
///
326326
/// * A callback macro that takes the exact same arguments as callback
327-
/// macro in +for_each_inst+
327+
/// macro in +for_each_inst+
328328
/// * A value expression containing the actual value to match against.
329329
/// * An expression used as wildcard matches when the passed value does
330-
/// not match any opcode
330+
/// not match any opcode
331331
///
332332
/// * Free variables are attached to the variants ending with match1, match2, etc.
333333
#[macro_export]
@@ -357,7 +357,7 @@ macro_rules! for_each_inst_match2 {
357357
/// Generates an array on all instructions
358358
///
359359
/// * A callback macro that takes the exact same arguments as callback
360-
/// macro in +for_each_inst+
360+
/// macro in +for_each_inst+
361361
///
362362
/// * Free variables are attached to the variants ending with fold1, fold2, etc.
363363
#[macro_export]

examples/check_real_memory.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn get_current_memory_linux() -> usize {
6969
}
7070

7171
fn get_current_memory() -> usize {
72-
if !cfg!(linux) {
72+
if !cfg!(target_os = "linux") {
7373
get_current_memory_linux()
7474
} else {
7575
let pid = format!("{}", id());
@@ -168,8 +168,7 @@ fn check_asm(memory_size: usize) -> Result<(), ()> {
168168
);
169169
println!("Base memory: {}", get_current_memory());
170170
for _ in 0..G_CHECK_LOOP {
171-
let asm_core =
172-
AsmCoreMachine::new_with_memory(ISA_IMC, VERSION0, u64::max_value(), memory_size);
171+
let asm_core = AsmCoreMachine::new_with_memory(ISA_IMC, VERSION0, u64::MAX, memory_size);
173172
let core = DefaultMachineBuilder::new(asm_core).build();
174173
let mut machine = AsmMachine::new(core);
175174
machine
@@ -193,8 +192,7 @@ fn check_asm_in_thread(memory_size: usize) -> Result<(), ()> {
193192
);
194193
println!("Base memory: {}", get_current_memory());
195194
for _ in 0..G_CHECK_LOOP {
196-
let asm_core =
197-
AsmCoreMachine::new_with_memory(ISA_IMC, VERSION0, u64::max_value(), memory_size);
195+
let asm_core = AsmCoreMachine::new_with_memory(ISA_IMC, VERSION0, u64::MAX, memory_size);
198196
let core = DefaultMachineBuilder::new(asm_core).build();
199197
let mut machine = AsmMachine::new(core);
200198
machine

fuzz/fuzz_targets/snapshot2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl DataSource<u32> for DummyData {
6565

6666
fn build_machine() -> DefaultMachine<Box<AsmCoreMachine>> {
6767
let isa = ISA_IMC | ISA_A | ISA_B | ISA_MOP;
68-
let core_machine = AsmCoreMachine::new(isa, VERSION2, u64::max_value());
68+
let core_machine = AsmCoreMachine::new(isa, VERSION2, u64::MAX);
6969
DefaultMachineBuilder::new(core_machine).build()
7070
}
7171

rust-toolchain

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.75.0
1+
1.81.0

src/bits.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ mod tests {
2424
assert_eq!(16, roundup(15, 16));
2525
assert_eq!(16, roundup(16, 16));
2626
assert_eq!(32, roundup(17, 16));
27-
assert_eq!(u64::max_value() - 15, roundup(u64::max_value() - 15, 16));
28-
assert_eq!(0, roundup(u64::max_value(), 16));
27+
assert_eq!(u64::MAX - 15, roundup(u64::MAX - 15, 16));
28+
assert_eq!(0, roundup(u64::MAX, 16));
2929
}
3030

3131
#[test]
@@ -35,7 +35,7 @@ mod tests {
3535
assert_eq!(0, rounddown(15, 16));
3636
assert_eq!(16, rounddown(16, 16));
3737
assert_eq!(16, rounddown(17, 16));
38-
assert_eq!(u64::max_value() - 15, rounddown(u64::max_value(), 16));
38+
assert_eq!(u64::MAX - 15, rounddown(u64::MAX, 16));
3939
}
4040

4141
proptest! {

src/instructions/ast.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,11 @@ impl Register for Value {
149149
}
150150

151151
fn min_value() -> Value {
152-
Value::Imm(u64::min_value())
152+
Value::Imm(u64::MIN)
153153
}
154154

155155
fn max_value() -> Value {
156-
Value::Imm(u64::max_value())
156+
Value::Imm(u64::MAX)
157157
}
158158

159159
fn eq(&self, other: &Value) -> Value {

src/instructions/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -457,14 +457,14 @@ mod tests {
457457
fn test_stype_display() {
458458
// This is "sd a5,568(sp)"
459459
let sd_inst = 0x22f13c23;
460-
let decoded = factory::<u64>(sd_inst, u32::max_value()).expect("decoding");
460+
let decoded = factory::<u64>(sd_inst, u32::MAX).expect("decoding");
461461
let stype = Stype(decoded);
462462

463463
assert_eq!("sd a5,568(sp)", format!("{}", stype));
464464

465465
// This is "beq a0,a5,1012e"
466466
let sd_inst = 0xf4f500e3;
467-
let decoded = factory::<u64>(sd_inst, u32::max_value()).expect("decoding");
467+
let decoded = factory::<u64>(sd_inst, u32::MAX).expect("decoding");
468468
let stype = Stype(decoded);
469469

470470
assert_eq!("beq a0,a5,-192", format!("{}", stype));

src/instructions/register.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ impl Register for u32 {
138138
}
139139

140140
fn min_value() -> u32 {
141-
u32::min_value()
141+
u32::MIN
142142
}
143143

144144
fn max_value() -> u32 {
145-
u32::max_value()
145+
u32::MAX
146146
}
147147

148148
fn eq(&self, other: &u32) -> u32 {
@@ -183,7 +183,7 @@ impl Register for u32 {
183183

184184
fn overflowing_div(&self, rhs: &u32) -> u32 {
185185
if *rhs == 0 {
186-
Self::max_value()
186+
Self::MAX
187187
} else {
188188
(*self).overflowing_div(*rhs).0
189189
}
@@ -423,11 +423,11 @@ impl Register for u64 {
423423
}
424424

425425
fn min_value() -> u64 {
426-
u64::min_value()
426+
u64::MIN
427427
}
428428

429429
fn max_value() -> u64 {
430-
u64::max_value()
430+
u64::MAX
431431
}
432432

433433
fn eq(&self, other: &u64) -> u64 {
@@ -468,7 +468,7 @@ impl Register for u64 {
468468

469469
fn overflowing_div(&self, rhs: &u64) -> u64 {
470470
if *rhs == 0 {
471-
Self::max_value()
471+
Self::MAX
472472
} else {
473473
(*self).overflowing_div(*rhs).0
474474
}

src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub fn run<R: Register, M: Memory<REG = R> + Default>(
4343
let core_machine = DefaultCoreMachine::<R, WXorXMemory<M>>::new_with_memory(
4444
ISA_IMC | ISA_A | ISA_B | ISA_MOP,
4545
machine::VERSION2,
46-
u64::max_value(),
46+
u64::MAX,
4747
WXorXMemory::new(M::default()),
4848
);
4949
let mut machine = TraceMachine::new(DefaultMachineBuilder::new(core_machine).build());
@@ -59,7 +59,7 @@ pub fn run_with_memory<R: Register, M: Memory<REG = R>>(
5959
let core_machine = DefaultCoreMachine::<R, WXorXMemory<M>>::new_with_memory(
6060
ISA_IMC | ISA_A | ISA_B | ISA_MOP,
6161
machine::VERSION2,
62-
u64::max_value(),
62+
u64::MAX,
6363
WXorXMemory::new(memory),
6464
);
6565
let mut machine = TraceMachine::new(DefaultMachineBuilder::new(core_machine).build());

src/machine/asm/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,8 @@ impl Memory for Box<AsmCoreMachine> {
366366
let slice = self.cast_ptr_to_slice_mut(self.frames_ptr, 0, self.frames_size as usize);
367367
memset(slice, 0);
368368
self.load_reservation_address = u64::MAX;
369-
self.last_read_frame = u64::max_value();
370-
self.last_write_page = u64::max_value();
369+
self.last_read_frame = u64::MAX;
370+
self.last_write_page = u64::MAX;
371371
Ok(())
372372
}
373373

@@ -421,8 +421,8 @@ impl Memory for Box<AsmCoreMachine> {
421421
current_addr += RISCV_PAGESIZE as u64;
422422
}
423423
// Clear last read/write page cache
424-
self.last_read_frame = u64::max_value();
425-
self.last_write_page = u64::max_value();
424+
self.last_read_frame = u64::MAX;
425+
self.last_write_page = u64::MAX;
426426
Ok(())
427427
}
428428

@@ -443,7 +443,7 @@ impl Memory for Box<AsmCoreMachine> {
443443
let slice = self.cast_ptr_to_slice_mut(self.flags_ptr, page as usize, 1);
444444
slice[0] |= flag;
445445
// Clear last write page cache
446-
self.last_write_page = u64::max_value();
446+
self.last_write_page = u64::MAX;
447447
Ok(())
448448
} else {
449449
Err(Error::MemOutOfBound(
@@ -458,7 +458,7 @@ impl Memory for Box<AsmCoreMachine> {
458458
let slice = self.cast_ptr_to_slice_mut(self.flags_ptr, page as usize, 1);
459459
slice[0] &= !flag;
460460
// Clear last write page cache
461-
self.last_write_page = u64::max_value();
461+
self.last_write_page = u64::MAX;
462462
Ok(())
463463
} else {
464464
Err(Error::MemOutOfBound(

src/snapshot2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl<I: Clone + PartialEq, D: DataSource<I>> Snapshot2Context<I, D> {
140140
/// 1. use elf::parse_elf to generate ProgramMetadata
141141
/// 2. use DefaultMachine::load_program_with_metadata to load the program
142142
/// 3. Pass ProgramMetadata to this method so we can track memory pages from
143-
/// program, so as to further reduce the size of the generated snapshot.
143+
/// program, so as to further reduce the size of the generated snapshot.
144144
///
145145
/// One can also use the original DefaultMachine::load_program, and parse the
146146
/// ELF a second time to extract metadata for this method. However the above

tests/machine_build.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl<Mac: SupportMachine> Syscalls<Mac> for SleepSyscall {
3232
#[cfg(has_asm)]
3333
pub fn asm_v1_imcb(path: &str) -> AsmMachine {
3434
let buffer: Bytes = std::fs::read(path).unwrap().into();
35-
let asm_core = AsmCoreMachine::new(ISA_IMC | ISA_B, VERSION1, u64::max_value());
35+
let asm_core = AsmCoreMachine::new(ISA_IMC | ISA_B, VERSION1, u64::MAX);
3636
let core = DefaultMachineBuilder::<Box<AsmCoreMachine>>::new(asm_core)
3737
.instruction_cycle_func(Box::new(constant_cycles))
3838
.syscall(Box::new(SleepSyscall {}))
@@ -51,7 +51,7 @@ pub fn int_v1_imcb(
5151
let core_machine = DefaultCoreMachine::<u64, WXorXMemory<SparseMemory<u64>>>::new(
5252
ISA_IMC | ISA_B,
5353
VERSION1,
54-
u64::max_value(),
54+
u64::MAX,
5555
);
5656
let mut machine = TraceMachine::new(
5757
DefaultMachineBuilder::new(core_machine)
@@ -73,7 +73,7 @@ pub fn asm_v1_mop(path: &str, args: Vec<Bytes>) -> AsmMachine {
7373
#[cfg(has_asm)]
7474
pub fn asm_mop(path: &str, args: Vec<Bytes>, version: u32) -> AsmMachine {
7575
let buffer: Bytes = std::fs::read(path).unwrap().into();
76-
let asm_core = AsmCoreMachine::new(ISA_IMC | ISA_B | ISA_MOP, version, u64::max_value());
76+
let asm_core = AsmCoreMachine::new(ISA_IMC | ISA_B | ISA_MOP, version, u64::MAX);
7777
let core = DefaultMachineBuilder::<Box<AsmCoreMachine>>::new(asm_core)
7878
.instruction_cycle_func(Box::new(constant_cycles))
7979
.syscall(Box::new(SleepSyscall {}))
@@ -101,7 +101,7 @@ pub fn int_mop(
101101
let core_machine = DefaultCoreMachine::<u64, WXorXMemory<SparseMemory<u64>>>::new(
102102
ISA_IMC | ISA_B | ISA_MOP,
103103
version,
104-
u64::max_value(),
104+
u64::MAX,
105105
);
106106
let mut machine = TraceMachine::new(
107107
DefaultMachineBuilder::new(core_machine)
@@ -118,7 +118,7 @@ pub fn int_mop(
118118
#[cfg(has_asm)]
119119
pub fn asm_v2_imacb(path: &str) -> AsmMachine {
120120
let buffer: Bytes = std::fs::read(path).unwrap().into();
121-
let asm_core = AsmCoreMachine::new(ISA_IMC | ISA_A | ISA_B, VERSION2, u64::max_value());
121+
let asm_core = AsmCoreMachine::new(ISA_IMC | ISA_A | ISA_B, VERSION2, u64::MAX);
122122
let core = DefaultMachineBuilder::<Box<AsmCoreMachine>>::new(asm_core)
123123
.instruction_cycle_func(Box::new(constant_cycles))
124124
.syscall(Box::new(SleepSyscall {}))
@@ -137,7 +137,7 @@ pub fn int_v2_imacb(
137137
let core_machine = DefaultCoreMachine::<u64, WXorXMemory<SparseMemory<u64>>>::new(
138138
ISA_IMC | ISA_A | ISA_B,
139139
VERSION2,
140-
u64::max_value(),
140+
u64::MAX,
141141
);
142142
let mut machine = TraceMachine::new(
143143
DefaultMachineBuilder::new(core_machine)

0 commit comments

Comments
 (0)