Skip to content

Commit

Permalink
Just some clippy & fmt related action
Browse files Browse the repository at this point in the history
  • Loading branch information
rdaum committed Feb 6, 2024
1 parent 6182db5 commit c3b050f
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 89 deletions.
5 changes: 3 additions & 2 deletions crates/db/benches/tb_single_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion};
use moor_db::rdb::{RelBox, RelationInfo};
use moor_db::testing::jepsen::{History, Type, Value};
use moor_values::util::SliceRef;
use std::rc::Rc;
use std::sync::Arc;
use std::time::{Duration, Instant};

Expand Down Expand Up @@ -71,7 +72,7 @@ fn list_append_scan_workload(iters: u64, events: &Vec<History>) -> Duration {
match e.r#type {
Type::invoke => {
// Start a transaction.
let tx = Arc::new(db.clone().start_tx());
let tx = Rc::new(db.clone().start_tx());
assert!(
!processes.check(e.process as usize),
"T{} already exists committed",
Expand Down Expand Up @@ -129,7 +130,7 @@ fn list_append_seek_workload(iters: u64, events: &Vec<History>) -> Duration {
match e.r#type {
Type::invoke => {
// Start a transaction.
let tx = Arc::new(db.clone().start_tx());
let tx = Rc::new(db.clone().start_tx());
assert!(
!processes.check(e.process as usize),
"T{} already exists committed",
Expand Down
3 changes: 2 additions & 1 deletion crates/db/tests/jepsen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub mod support {
#[cfg(test)]
mod tests {
use std::collections::{BTreeSet, HashMap};
use std::rc::Rc;
use std::sync::Arc;
use tracing_test::traced_test;

Expand Down Expand Up @@ -152,7 +153,7 @@ mod tests {
match e.r#type {
Type::invoke => {
// Start a transaction.
let tx = Arc::new(db.clone().start_tx());
let tx = Rc::new(db.clone().start_tx());
let existing = processes.insert(e.process, tx.clone());
assert!(
existing.is_none(),
Expand Down
5 changes: 3 additions & 2 deletions crates/db/tests/rdb_restore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
mod test {
use std::collections::HashMap;
use std::path::PathBuf;
use std::rc::Rc;
use std::sync::Arc;
use tracing_test::traced_test;

Expand All @@ -36,13 +37,13 @@ mod test {
fn fill_db(
db: Arc<RelBox>,
events: &Vec<History>,
processes: &mut HashMap<i64, Arc<Transaction>>,
processes: &mut HashMap<i64, Rc<Transaction>>,
) {
for e in events {
match e.r#type {
Type::invoke => {
// Start a transaction.
let tx = Arc::new(db.clone().start_tx());
let tx = Rc::new(db.clone().start_tx());
let existing = processes.insert(e.process, tx.clone());
assert!(
existing.is_none(),
Expand Down
80 changes: 9 additions & 71 deletions crates/kernel/src/builtins/bf_verbs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,14 @@ fn bf_verb_info(bf_args: &mut BfCallState<'_>) -> Result<BfRet, Error> {
return Err(E_TYPE);
};

if !bf_args
.world_state
.valid(*obj)

.map_err(world_state_err)?
{
if !bf_args.world_state.valid(*obj).map_err(world_state_err)? {
return Err(E_INVARG);
}

let verb_info = match bf_args.args[1].variant() {
Variant::Str(verb_desc) => bf_args
.world_state
.get_verb(bf_args.task_perms_who(), *obj, verb_desc.as_str())

.map_err(world_state_err)?,
Variant::Int(verb_index) => {
let verb_index = *verb_index;
Expand All @@ -78,7 +72,6 @@ fn bf_verb_info(bf_args: &mut BfCallState<'_>) -> Result<BfRet, Error> {
bf_args
.world_state
.get_verb_at_index(bf_args.task_perms_who(), *obj, verb_index)

.map_err(world_state_err)?
}
_ => {
Expand Down Expand Up @@ -122,7 +115,6 @@ fn get_verbdef(
bf_args
.world_state
.get_verb(bf_args.task_perms_who(), obj, verb_desc)

}
Variant::Int(verb_index) => {
let verb_index = *verb_index;
Expand All @@ -133,7 +125,6 @@ fn get_verbdef(
bf_args
.world_state
.get_verb_at_index(bf_args.task_perms_who(), obj, verb_index)

}
_ => return Err(E_TYPE),
};
Expand Down Expand Up @@ -201,12 +192,7 @@ fn bf_set_verb_info(bf_args: &mut BfCallState<'_>) -> Result<BfRet, Error> {
}
let update_attrs = parse_verb_info(info)?;

if !bf_args
.world_state
.valid(*obj)

.map_err(world_state_err)?
{
if !bf_args.world_state.valid(*obj).map_err(world_state_err)? {
return Err(E_INVARG);
}

Expand All @@ -220,7 +206,6 @@ fn bf_set_verb_info(bf_args: &mut BfCallState<'_>) -> Result<BfRet, Error> {
verb_name.as_str(),
update_attrs,
)

.map_err(world_state_err)?;
}
Variant::Int(verb_index) => {
Expand All @@ -232,7 +217,6 @@ fn bf_set_verb_info(bf_args: &mut BfCallState<'_>) -> Result<BfRet, Error> {
bf_args
.world_state
.update_verb_at_index(bf_args.task_perms_who(), *obj, verb_index, update_attrs)

.map_err(world_state_err)?;
}
_ => return Err(E_TYPE),
Expand All @@ -249,12 +233,7 @@ fn bf_verb_args(bf_args: &mut BfCallState<'_>) -> Result<BfRet, Error> {
let Variant::Obj(obj) = bf_args.args[0].variant() else {
return Err(E_TYPE);
};
if !bf_args
.world_state
.valid(*obj)

.map_err(world_state_err)?
{
if !bf_args.world_state.valid(*obj).map_err(world_state_err)? {
return Err(E_INVARG);
}

Expand Down Expand Up @@ -311,12 +290,7 @@ fn bf_set_verb_args(bf_args: &mut BfCallState<'_>) -> Result<BfRet, Error> {
if verbinfo.len() != 3 {
return Err(E_INVARG);
}
if !bf_args
.world_state
.valid(*obj)

.map_err(world_state_err)?
{
if !bf_args.world_state.valid(*obj).map_err(world_state_err)? {
return Err(E_INVARG);
}

Expand All @@ -341,7 +315,6 @@ fn bf_set_verb_args(bf_args: &mut BfCallState<'_>) -> Result<BfRet, Error> {
verb_name.as_str(),
update_attrs,
)

.map_err(world_state_err)?;
}
Variant::Int(verb_index) => {
Expand All @@ -353,7 +326,6 @@ fn bf_set_verb_args(bf_args: &mut BfCallState<'_>) -> Result<BfRet, Error> {
bf_args
.world_state
.update_verb_at_index(bf_args.task_perms_who(), *obj, verb_index, update_attrs)

.map_err(world_state_err)?;
}
_ => return Err(E_TYPE),
Expand All @@ -370,19 +342,13 @@ fn bf_verb_code(bf_args: &mut BfCallState<'_>) -> Result<BfRet, Error> {
let Variant::Obj(obj) = bf_args.args[0].variant() else {
return Err(E_TYPE);
};
if !bf_args
.world_state
.valid(*obj)

.map_err(world_state_err)?
{
if !bf_args.world_state.valid(*obj).map_err(world_state_err)? {
return Err(E_INVARG);
}

// Verify caller is a programmer.
if !bf_args
.task_perms()

.map_err(world_state_err)?
.flags
.contains(ObjFlag::Programmer)
Expand All @@ -408,7 +374,6 @@ fn bf_verb_code(bf_args: &mut BfCallState<'_>) -> Result<BfRet, Error> {
let verb_info = bf_args
.world_state
.retrieve_verb(bf_args.task_perms_who(), *obj, verbdef.uuid())

.map_err(world_state_err)?;

// If the binary is empty, just return empty rather than try to decode it.
Expand Down Expand Up @@ -451,19 +416,13 @@ fn bf_set_verb_code(bf_args: &mut BfCallState<'_>) -> Result<BfRet, Error> {
let Variant::Obj(obj) = bf_args.args[0].variant() else {
return Err(E_TYPE);
};
if !bf_args
.world_state
.valid(*obj)

.map_err(world_state_err)?
{
if !bf_args.world_state.valid(*obj).map_err(world_state_err)? {
return Err(E_INVARG);
}

// Verify caller is a programmer.
if !bf_args
.task_perms()

.map_err(world_state_err)?
.flags
.contains(ObjFlag::Programmer)
Expand Down Expand Up @@ -519,7 +478,6 @@ fn bf_set_verb_code(bf_args: &mut BfCallState<'_>) -> Result<BfRet, Error> {
bf_args
.world_state
.update_verb_with_id(bf_args.task_perms_who(), *obj, verbdef.uuid(), update_attrs)

.map_err(world_state_err)?;
Ok(Ret(v_none()))
}
Expand All @@ -539,19 +497,13 @@ fn bf_add_verb(bf_args: &mut BfCallState<'_>) -> Result<BfRet, Error> {
let Variant::List(args) = bf_args.args[2].variant() else {
return Err(E_TYPE);
};
if !bf_args
.world_state
.valid(*obj)

.map_err(world_state_err)?
{
if !bf_args.world_state.valid(*obj).map_err(world_state_err)? {
return Err(E_INVARG);
}

// Verify caller is a programmer.
if !bf_args
.task_perms()

.map_err(world_state_err)?
.flags
.contains(ObjFlag::Programmer)
Expand All @@ -573,7 +525,6 @@ fn bf_add_verb(bf_args: &mut BfCallState<'_>) -> Result<BfRet, Error> {
Vec::new(),
BinaryType::LambdaMoo18X,
)

.map_err(world_state_err)?;

Ok(Ret(v_none()))
Expand All @@ -588,19 +539,13 @@ fn bf_delete_verb(bf_args: &mut BfCallState<'_>) -> Result<BfRet, Error> {
let Variant::Obj(obj) = bf_args.args[0].variant() else {
return Err(E_TYPE);
};
if !bf_args
.world_state
.valid(*obj)

.map_err(world_state_err)?
{
if !bf_args.world_state.valid(*obj).map_err(world_state_err)? {
return Err(E_INVARG);
}

// Verify caller is a programmer.
if !bf_args
.task_perms()

.map_err(world_state_err)?
.flags
.contains(ObjFlag::Programmer)
Expand All @@ -616,7 +561,6 @@ fn bf_delete_verb(bf_args: &mut BfCallState<'_>) -> Result<BfRet, Error> {
bf_args
.world_state
.remove_verb(bf_args.task_perms_who(), *obj, verbdef.uuid())

.map_err(world_state_err)?;

Ok(Ret(v_none()))
Expand All @@ -635,12 +579,7 @@ fn bf_disassemble(bf_args: &mut BfCallState<'_>) -> Result<BfRet, Error> {
let Variant::Obj(obj) = bf_args.args[0].variant() else {
return Err(E_TYPE);
};
if !bf_args
.world_state
.valid(*obj)

.map_err(world_state_err)?
{
if !bf_args.world_state.valid(*obj).map_err(world_state_err)? {
return Err(E_INVARG);
}

Expand All @@ -658,7 +597,6 @@ fn bf_disassemble(bf_args: &mut BfCallState<'_>) -> Result<BfRet, Error> {
let verb_info = bf_args
.world_state
.retrieve_verb(bf_args.task_perms_who(), *obj, verbdef.uuid())

.map_err(world_state_err)?;

if verb_info.binary().is_empty() {
Expand Down
12 changes: 4 additions & 8 deletions crates/kernel/src/vm/activation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ impl Activation {
frame.set_gvar(GlobalName::iobjstr, v_str(""));
}

let a = Self {
Self {
frame,
this: verb_call_request.call.this,
player: verb_call_request.call.player,
Expand All @@ -302,9 +302,7 @@ impl Activation {
bf_trampoline_arg: None,
args: verb_call_request.call.args.clone(),
permissions: verb_owner,
};

a
}
}

pub fn for_eval(permissions: Objid, player: Objid, program: Program) -> Self {
Expand Down Expand Up @@ -346,7 +344,7 @@ impl Activation {
frame.set_gvar(GlobalName::iobj, v_objid(NOTHING));
frame.set_gvar(GlobalName::iobjstr, v_str(""));

let a = Self {
Self {
frame,
this: player,
player,
Expand All @@ -358,9 +356,7 @@ impl Activation {
bf_trampoline_arg: None,
args: vec![],
permissions,
};

a
}
}
pub fn for_bf_call(
bf_index: usize,
Expand Down
8 changes: 5 additions & 3 deletions crates/kernel/src/vm/vm_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,13 @@ impl VM {
pub(crate) fn exec_fork_vector(&self, vm_state: &mut VMExecState, fork_request: Fork) {
// Set the activation up with the new task ID, and the new code.
let mut a = fork_request.activation;
a.frame.program.main_vector =
Arc::new(a.frame.program.fork_vectors[fork_request.fork_vector_offset.0 as usize].clone());
a.frame.program.main_vector = Arc::new(
a.frame.program.fork_vectors[fork_request.fork_vector_offset.0 as usize].clone(),
);
a.frame.pc = 0;
if let Some(task_id_name) = fork_request.task_id {
a.frame.set_var_offset(&task_id_name, v_int(vm_state.task_id as i64))
a.frame
.set_var_offset(&task_id_name, v_int(vm_state.task_id as i64))
.expect("Unable to set task_id in activation frame");
}

Expand Down
2 changes: 1 addition & 1 deletion crates/kernel/src/vm/vm_execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ impl VM {

for _i in 0..num_excepts {
f.pop(); /* code list */
f.handler_stack.pop();
f.handler_stack.pop();
}
if is_catch {
f.push(v);
Expand Down
Loading

0 comments on commit c3b050f

Please sign in to comment.