Skip to content

Commit 783f10a

Browse files
committed
fix: clippy happy
1 parent a785ec2 commit 783f10a

4 files changed

Lines changed: 60 additions & 63 deletions

File tree

pd-edge/src/runtime/vm_runner.rs

Lines changed: 41 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -38,69 +38,60 @@ pub async fn execute_vm_with_context(
3838
let program = program.program.clone();
3939
let async_ops = new_shared_vm_async_ops();
4040

41-
if debug.attach_debugger {
42-
let async_ops_for_debug = async_ops.clone();
43-
let vm_context_for_debug = vm_context.clone();
44-
let program_for_debug = program.clone();
45-
let task = tokio::task::spawn_blocking(move || {
46-
let mut vm = Vm::with_locals_shared(program_for_debug, local_count);
47-
vm.set_async_bridge(Box::new(VmAsyncOpBridge::new(async_ops_for_debug.clone())));
48-
register_host_modules(&mut vm, vm_context_for_debug.clone(), async_ops_for_debug)
49-
.map_err(VmExecutionError::HostRegistration)?;
50-
51-
loop {
52-
let status = run_vm_with_optional_debugger(
53-
&debug_session,
54-
&debug.request_headers,
55-
&debug.request_path,
56-
&debug.request_id,
57-
&mut vm,
58-
)
59-
.map_err(VmExecutionError::Vm)?;
60-
61-
match status {
62-
VmStatus::Halted => break,
63-
VmStatus::Yielded => continue,
64-
VmStatus::Waiting(_op_id) => tokio::runtime::Handle::current()
65-
.block_on(vm.await_waiting_host_op())
66-
.map_err(VmExecutionError::Vm)?,
67-
}
68-
}
69-
70-
Ok(snapshot_execution_outcome(&vm_context_for_debug))
71-
});
41+
let task = tokio::task::spawn_blocking(move || {
42+
run_vm_blocking(
43+
program,
44+
local_count,
45+
vm_context,
46+
debug_session,
47+
debug,
48+
async_ops,
49+
register_host_modules,
50+
)
51+
});
7252

73-
return task.await.map_err(|err| {
74-
VmExecutionError::Vm(vm::VmError::HostError(format!(
75-
"vm blocking execution task failed: {err}"
76-
)))
77-
})?;
78-
}
53+
task.await.map_err(|err| {
54+
VmExecutionError::Vm(vm::VmError::HostError(format!(
55+
"vm blocking execution task failed: {err}"
56+
)))
57+
})?
58+
}
7959

60+
fn run_vm_blocking(
61+
program: std::sync::Arc<vm::Program>,
62+
local_count: usize,
63+
vm_context: SharedProxyVmContext,
64+
debug_session: SharedDebugSession,
65+
debug: VmDebugInvocation,
66+
async_ops: SharedVmAsyncOps,
67+
register_host_modules: HostModuleRegistrar,
68+
) -> Result<VmExecutionOutcome, VmExecutionError> {
8069
let mut vm = Vm::with_locals_shared(program, local_count);
8170
vm.set_async_bridge(Box::new(VmAsyncOpBridge::new(async_ops.clone())));
8271
register_host_modules(&mut vm, vm_context.clone(), async_ops)
8372
.map_err(VmExecutionError::HostRegistration)?;
8473

8574
loop {
86-
let status = run_vm_with_optional_debugger(
87-
&debug_session,
88-
&debug.request_headers,
89-
&debug.request_path,
90-
&debug.request_id,
91-
&mut vm,
92-
)
75+
let status = if debug.attach_debugger {
76+
run_vm_with_optional_debugger(
77+
&debug_session,
78+
&debug.request_headers,
79+
&debug.request_path,
80+
&debug.request_id,
81+
&mut vm,
82+
)
83+
} else {
84+
vm.run()
85+
}
9386
.map_err(VmExecutionError::Vm)?;
9487
match status {
9588
VmStatus::Halted => break,
9689
VmStatus::Yielded => {
97-
tokio::task::yield_now().await;
98-
}
99-
VmStatus::Waiting(_op_id) => {
100-
vm.await_waiting_host_op()
101-
.await
102-
.map_err(VmExecutionError::Vm)?;
90+
std::thread::yield_now();
10391
}
92+
VmStatus::Waiting(_op_id) => tokio::runtime::Handle::current()
93+
.block_on(vm.await_waiting_host_op())
94+
.map_err(VmExecutionError::Vm)?,
10495
}
10596
}
10697

pd-vm/src/compiler/lifetime.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl AvailabilityAnalyzer {
109109
let after_possible = state.possible[slot];
110110
let after_definite = state.definite[slot];
111111
let entered_uncertain =
112-
after_possible && !after_definite && !(before_possible && !before_definite);
112+
after_possible && !after_definite && (!before_possible || before_definite);
113113
if entered_uncertain {
114114
rewritten.push(Stmt::Assign {
115115
index: slot as u8,
@@ -198,8 +198,10 @@ impl AvailabilityAnalyzer {
198198
// `for` loop condition executes before each iteration and at least once.
199199
// Body/post execution is optional, so only condition-side availability is guaranteed after loop.
200200
let mut possible = cond_state.possible.clone();
201-
for slot in 0..self.local_count {
202-
possible[slot] = possible[slot] || post_state.possible[slot];
201+
for (possible_slot, post_possible) in
202+
possible.iter_mut().zip(post_state.possible.iter())
203+
{
204+
*possible_slot = *possible_slot || *post_possible;
203205
}
204206
let out = FlowState {
205207
reachable: state.reachable && cond_state.reachable,
@@ -227,8 +229,10 @@ impl AvailabilityAnalyzer {
227229

228230
// `while` condition executes at least once; body execution is optional.
229231
let mut possible = cond_state.possible.clone();
230-
for slot in 0..self.local_count {
231-
possible[slot] = possible[slot] || body_state.possible[slot];
232+
for (possible_slot, body_possible) in
233+
possible.iter_mut().zip(body_state.possible.iter())
234+
{
235+
*possible_slot = *possible_slot || *body_possible;
232236
}
233237
let out = FlowState {
234238
reachable: state.reachable && cond_state.reachable,

pd-vm/src/vm/jit/native/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub(super) enum CompiledNativeTrace {
8888
code: Vec<u8>,
8989
},
9090
#[cfg(feature = "cranelift-jit")]
91-
Cranelift(CraneliftCompiledTrace),
91+
Cranelift(Box<CraneliftCompiledTrace>),
9292
}
9393

9494
pub(super) fn compile_native_trace(
@@ -139,9 +139,9 @@ pub(super) fn take_bridge_error() -> Option<VmError> {
139139
fn compile_native_trace_cranelift(trace: &super::JitTrace) -> VmResult<CompiledNativeTrace> {
140140
#[cfg(feature = "cranelift-jit")]
141141
{
142-
return Ok(CompiledNativeTrace::Cranelift(cranelift::compile_trace(
143-
trace,
144-
)?));
142+
Ok(CompiledNativeTrace::Cranelift(Box::new(
143+
cranelift::compile_trace(trace)?,
144+
)))
145145
}
146146

147147
#[cfg(not(feature = "cranelift-jit"))]

pd-vm/src/vm/jit/runtime.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use super::super::{ExecOutcome, HostCallExecOutcome, Vm, VmError, VmResult};
22
use super::{JitTrace, JitTraceTerminal, TraceStep, native};
33
use std::collections::HashMap;
4+
#[cfg(feature = "cranelift-jit")]
5+
use std::rc::Rc;
46
use std::sync::Arc;
57
#[cfg(any(
68
all(
@@ -41,7 +43,7 @@ type NativeTraceEntry = unsafe extern "C" fn(*mut Vm) -> i32;
4143
type NativeTraceEntry = fn(*mut Vm) -> i32;
4244

4345
#[cfg(feature = "cranelift-jit")]
44-
type MaybeCraneliftKeepalive = Option<Arc<native::CraneliftTraceKeepAlive>>;
46+
type MaybeCraneliftKeepalive = Option<Rc<native::CraneliftTraceKeepAlive>>;
4547

4648
pub(crate) struct NativeTrace {
4749
#[cfg(any(
@@ -113,7 +115,7 @@ struct NativeTraceCache {
113115
#[derive(Clone)]
114116
struct CraneliftNativeTraceCacheEntry {
115117
entry: NativeTraceEntry,
116-
keepalive: Arc<native::CraneliftTraceKeepAlive>,
118+
keepalive: Rc<native::CraneliftTraceKeepAlive>,
117119
code: Arc<[u8]>,
118120
}
119121

@@ -635,12 +637,12 @@ impl Vm {
635637
std::mem::transmute::<*const u8, NativeTraceEntry>(compiled.entry)
636638
};
637639
let code = Arc::<[u8]>::from(compiled.code.into_boxed_slice());
638-
let keepalive = Arc::new(compiled.keepalive);
640+
let keepalive = Rc::new(compiled.keepalive);
639641
#[cfg(feature = "cranelift-jit")]
640642
{
641643
let cached = CraneliftNativeTraceCacheEntry {
642644
entry,
643-
keepalive: Arc::clone(&keepalive),
645+
keepalive: Rc::clone(&keepalive),
644646
code: Arc::clone(&code),
645647
};
646648
let key = native_trace_cache_key(

0 commit comments

Comments
 (0)