Skip to content

Commit

Permalink
rustfmt 7 scryer-prolog lib.rs and children
Browse files Browse the repository at this point in the history
using rustfmt build from rustfmt master with rust-lang/rustfmt#5205 applied
  • Loading branch information
Skgland committed Jan 30, 2022
1 parent 90bf964 commit 55d0891
Show file tree
Hide file tree
Showing 39 changed files with 7,459 additions and 6,151 deletions.
9 changes: 2 additions & 7 deletions src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,8 @@ pub(crate) trait Allocator<'a> {
fn mark_anon_var<Target>(&mut self, _: Level, _: GenContext, _: &mut Code)
where
Target: crate::targets::CompilationTarget<'a>;
fn mark_non_var<Target>(
&mut self,
_: Level,
_: GenContext,
_: &'a Cell<RegType>,
_: &mut Code,
) where
fn mark_non_var<Target>(&mut self, _: Level, _: GenContext, _: &'a Cell<RegType>, _: &mut Code)
where
Target: crate::targets::CompilationTarget<'a>;
fn mark_reserved_var<Target>(
&mut self,
Expand Down
20 changes: 13 additions & 7 deletions src/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ macro_rules! arena_alloc {
($e:expr, $arena:expr) => {{
let result = $e;
#[allow(unused_unsafe)]
unsafe { $arena.alloc(result) }
unsafe {
$arena.alloc(result)
}
}};
}

Expand Down Expand Up @@ -150,7 +152,9 @@ impl<T: ?Sized> TypedArenaPtr<T> {

#[inline]
pub fn set_tag(&mut self, tag: ArenaHeaderTag) {
unsafe { (*self.header_ptr_mut()).set_tag(tag); }
unsafe {
(*self.header_ptr_mut()).set_tag(tag);
}
}

#[inline]
Expand Down Expand Up @@ -415,8 +419,7 @@ unsafe fn drop_slab_in_place(value: &mut AllocSlab) {
ArenaHeaderTag::LiveLoadState | ArenaHeaderTag::InactiveLoadState => {
ptr::drop_in_place(value.payload_offset::<LiveLoadState>());
}
ArenaHeaderTag::Dropped => {
}
ArenaHeaderTag::Dropped => {}
ArenaHeaderTag::TcpListener => {
ptr::drop_in_place(value.payload_offset::<TcpListener>());
}
Expand All @@ -426,8 +429,7 @@ unsafe fn drop_slab_in_place(value: &mut AllocSlab) {
ArenaHeaderTag::StandardErrorStream => {
ptr::drop_in_place(value.payload_offset::<StreamLayout<StandardErrorStream>>());
}
ArenaHeaderTag::F64 | ArenaHeaderTag::NullStream => {
}
ArenaHeaderTag::F64 | ArenaHeaderTag::NullStream => {}
}
}

Expand Down Expand Up @@ -656,7 +658,11 @@ mod tests {

// complete string

let pstr_var_cell = put_partial_string(&mut wam.machine_st.heap, "ronan", &mut wam.machine_st.atom_tbl);
let pstr_var_cell = put_partial_string(
&mut wam.machine_st.heap,
"ronan",
&mut wam.machine_st.atom_tbl,
);
let pstr_cell = wam.machine_st.heap[pstr_var_cell.get_value() as usize];

assert_eq!(pstr_cell.get_tag(), HeapCellValueTag::PStr);
Expand Down
32 changes: 24 additions & 8 deletions src/atom_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ impl<'a> From<&'a Atom> for Atom {
impl From<bool> for Atom {
#[inline]
fn from(value: bool) -> Self {
if value { atom!("true") } else { atom!("false") }
if value {
atom!("true")
} else {
atom!("false")
}
}
}

Expand Down Expand Up @@ -90,9 +94,11 @@ impl RawBlockTraits for AtomTable {
#[bitfield]
#[derive(Copy, Clone, Debug)]
struct AtomHeader {
#[allow(unused)] m: bool,
#[allow(unused)]
m: bool,
len: B50,
#[allow(unused)] padding: B13,
#[allow(unused)]
padding: B13,
}

impl AtomHeader {
Expand Down Expand Up @@ -175,7 +181,11 @@ impl Atom {
let c1 = it.next();
let c2 = it.next();

if c2.is_none() { c1 } else { None }
if c2.is_none() {
c1
} else {
None
}
}

#[inline]
Expand Down Expand Up @@ -269,7 +279,10 @@ impl AtomTable {

#[inline(always)]
fn lookup_str(&self, string: &str) -> Option<Atom> {
STATIC_ATOMS_MAP.get(string).or_else(|| self.table.get(string)).cloned()
STATIC_ATOMS_MAP
.get(string)
.or_else(|| self.table.get(string))
.cloned()
}

pub fn build_with(&mut self, string: &str) -> Atom {
Expand Down Expand Up @@ -320,9 +333,12 @@ impl AtomTable {
pub struct AtomCell {
name: B46,
arity: B10,
#[allow(unused)] f: bool,
#[allow(unused)] m: bool,
#[allow(unused)] tag: B6,
#[allow(unused)]
f: bool,
#[allow(unused)]
m: bool,
#[allow(unused)]
tag: B6,
}

impl AtomCell {
Expand Down
52 changes: 32 additions & 20 deletions src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ impl<'a, 'b: 'a, TermMarker: Allocator<'a>> CodeGenerator<'b, TermMarker> {
code: &mut Code,
) -> RegType {
let mut target = Code::new();
self.marker.mark_var::<QueryInstruction>(name, Level::Shallow, vr, term_loc, &mut target);
self.marker
.mark_var::<QueryInstruction>(name, Level::Shallow, vr, term_loc, &mut target);

if !target.is_empty() {
code.extend(target.into_iter());
Expand Down Expand Up @@ -296,7 +297,8 @@ impl<'a, 'b: 'a, TermMarker: Allocator<'a>> CodeGenerator<'b, TermMarker> {
target: &mut Code,
) {
if is_exposed || self.get_var_count(var.as_ref()) > 1 {
self.marker.mark_var::<Target>(var.clone(), Level::Deep, cell, term_loc, target);
self.marker
.mark_var::<Target>(var.clone(), Level::Deep, cell, term_loc, target);
} else {
Self::add_or_increment_void_instr::<Target>(target);
}
Expand All @@ -311,15 +313,17 @@ impl<'a, 'b: 'a, TermMarker: Allocator<'a>> CodeGenerator<'b, TermMarker> {
) {
match subterm {
&Term::AnonVar if is_exposed => {
self.marker.mark_anon_var::<Target>(Level::Deep, term_loc, target);
self.marker
.mark_anon_var::<Target>(Level::Deep, term_loc, target);
}
&Term::AnonVar => {
Self::add_or_increment_void_instr::<Target>(target);
}
&Term::Cons(ref cell, ..)
| &Term::Clause(ref cell, ..)
| Term::PartialString(ref cell, ..) => {
self.marker.mark_non_var::<Target>(Level::Deep, term_loc, cell, target);
self.marker
.mark_non_var::<Target>(Level::Deep, term_loc, cell, target);
target.push(Target::clause_arg_to_instr(cell.get()));
}
&Term::Literal(_, ref constant) => {
Expand Down Expand Up @@ -349,34 +353,40 @@ impl<'a, 'b: 'a, TermMarker: Allocator<'a>> CodeGenerator<'b, TermMarker> {
if let GenContext::Head = term_loc {
self.marker.advance_arg();
} else {
self.marker.mark_anon_var::<Target>(lvl, term_loc, &mut target);
self.marker
.mark_anon_var::<Target>(lvl, term_loc, &mut target);
}
}
TermRef::Clause(lvl, cell, ct, terms) => {
self.marker.mark_non_var::<Target>(lvl, term_loc, cell, &mut target);
self.marker
.mark_non_var::<Target>(lvl, term_loc, cell, &mut target);
target.push(Target::to_structure(ct.name(), terms.len(), cell.get()));

for subterm in terms {
self.subterm_to_instr::<Target>(subterm, term_loc, is_exposed, &mut target);
}
}
TermRef::Cons(lvl, cell, head, tail) => {
self.marker.mark_non_var::<Target>(lvl, term_loc, cell, &mut target);
self.marker
.mark_non_var::<Target>(lvl, term_loc, cell, &mut target);
target.push(Target::to_list(lvl, cell.get()));

self.subterm_to_instr::<Target>(head, term_loc, is_exposed, &mut target);
self.subterm_to_instr::<Target>(tail, term_loc, is_exposed, &mut target);
}
TermRef::Literal(lvl @ Level::Shallow, cell, Literal::String(ref string)) => {
self.marker.mark_non_var::<Target>(lvl, term_loc, cell, &mut target);
self.marker
.mark_non_var::<Target>(lvl, term_loc, cell, &mut target);
target.push(Target::to_pstr(lvl, *string, cell.get(), false));
}
TermRef::Literal(lvl @ Level::Shallow, cell, constant) => {
self.marker.mark_non_var::<Target>(lvl, term_loc, cell, &mut target);
self.marker
.mark_non_var::<Target>(lvl, term_loc, cell, &mut target);
target.push(Target::to_constant(lvl, *constant, cell.get()));
}
TermRef::PartialString(lvl, cell, string, tail) => {
self.marker.mark_non_var::<Target>(lvl, term_loc, cell, &mut target);
self.marker
.mark_non_var::<Target>(lvl, term_loc, cell, &mut target);

if let Some(tail) = tail {
target.push(Target::to_pstr(lvl, string, cell.get(), true));
Expand All @@ -401,10 +411,12 @@ impl<'a, 'b: 'a, TermMarker: Allocator<'a>> CodeGenerator<'b, TermMarker> {
}
}

self.marker.mark_var::<Target>(var.clone(), lvl, cell, term_loc, &mut target);
self.marker
.mark_var::<Target>(var.clone(), lvl, cell, term_loc, &mut target);
}
TermRef::Var(lvl @ Level::Shallow, cell, var) => {
self.marker.mark_var::<Target>(var.clone(), lvl, cell, term_loc, &mut target);
self.marker
.mark_var::<Target>(var.clone(), lvl, cell, term_loc, &mut target);
}
_ => {}
};
Expand Down Expand Up @@ -553,8 +565,10 @@ impl<'a, 'b: 'a, TermMarker: Allocator<'a>> CodeGenerator<'b, TermMarker> {
}
},
&InlinedClauseType::IsCompound(..) => match &terms[0] {
&Term::Clause(..) | &Term::Cons(..) | &Term::PartialString(..) |
&Term::Literal(_, Literal::String(..)) => {
&Term::Clause(..)
| &Term::Cons(..)
| &Term::PartialString(..)
| &Term::Literal(_, Literal::String(..)) => {
code.push(instr!("$succeed", 0));
}
&Term::Var(ref vr, ref name) => {
Expand Down Expand Up @@ -747,7 +761,8 @@ impl<'a, 'b: 'a, TermMarker: Allocator<'a>> CodeGenerator<'b, TermMarker> {
let mut target = Code::new();

self.marker.reset_arg(1);
self.marker.mark_var::<QueryInstruction>(var, Level::Shallow, cell, term_loc, &mut target);
self.marker
.mark_var::<QueryInstruction>(var, Level::Shallow, cell, term_loc, &mut target);

if !target.is_empty() {
code.extend(target.into_iter());
Expand Down Expand Up @@ -923,11 +938,8 @@ impl<'a, 'b: 'a, TermMarker: Allocator<'a>> CodeGenerator<'b, TermMarker> {
self.marker.reset_at_head(args);

let iter = FactInstruction::iter(term);
let mut compiled_fact = self.compile_target::<FactInstruction, _>(
iter,
GenContext::Head,
false,
);
let mut compiled_fact =
self.compile_target::<FactInstruction, _>(iter, GenContext::Head, false);

self.mark_unsafe_fact_vars(&mut compiled_fact);

Expand Down
3 changes: 1 addition & 2 deletions src/debray_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,7 @@ impl<'a> Allocator<'a> for DebrayAllocator {
lvl: Level,
term_loc: GenContext,
target: &mut Vec<Instruction>,
)
where
) where
Target: CompilationTarget<'a>,
{
let r = RegType::Temp(self.alloc_reg_to_non_var());
Expand Down
6 changes: 2 additions & 4 deletions src/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,7 @@ impl UnsafeVarMarker {

pub(crate) fn mark_safe_vars(&mut self, query_instr: &Instruction) -> bool {
match query_instr {
&Instruction::PutVariable(r @ RegType::Temp(_), _) |
&Instruction::SetVariable(r) => {
&Instruction::PutVariable(r @ RegType::Temp(_), _) | &Instruction::SetVariable(r) => {
self.safe_vars.insert(r);
true
}
Expand All @@ -285,8 +284,7 @@ impl UnsafeVarMarker {

pub(crate) fn mark_phase(&mut self, query_instr: &Instruction, phase: usize) {
match query_instr {
&Instruction::PutValue(r @ RegType::Perm(_), _) |
&Instruction::SetValue(r) => {
&Instruction::PutValue(r @ RegType::Perm(_), _) | &Instruction::SetValue(r) => {
let p = self.unsafe_vars.entry(r).or_insert(0);
*p = phase;
}
Expand Down
20 changes: 5 additions & 15 deletions src/forms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,6 @@ pub(crate) fn fixity(spec: u32) -> Fixity {
}
}


impl OpDecl {
#[inline]
pub(crate) fn new(op_desc: OpDesc, name: Atom) -> Self {
Expand Down Expand Up @@ -369,12 +368,8 @@ impl AtomOrString {
#[inline]
pub fn to_string(self) -> String {
match self {
AtomOrString::Atom(atom) => {
atom.as_str().to_owned()
}
AtomOrString::String(string) => {
string
}
AtomOrString::Atom(atom) => atom.as_str().to_owned(),
AtomOrString::String(string) => string,
}
}
}
Expand Down Expand Up @@ -430,9 +425,7 @@ pub(crate) fn fetch_op_spec(name: Atom, arity: usize, op_dir: &OpDir) -> Option<
}
})
}
0 => {
fetch_atom_op_spec(name, None, op_dir)
}
0 => fetch_atom_op_spec(name, None, op_dir),
_ => None,
}
}
Expand Down Expand Up @@ -464,10 +457,7 @@ pub struct Module {

// Module's and related types are defined in forms.
impl Module {
pub(crate) fn new(
module_decl: ModuleDecl,
listing_src: ListingSource,
) -> Self {
pub(crate) fn new(module_decl: ModuleDecl, listing_src: ListingSource) -> Self {
Module {
module_decl,
code_dir: CodeDir::with_hasher(FxBuildHasher::default()),
Expand All @@ -489,7 +479,7 @@ impl Module {
meta_predicates: MetaPredicateDir::with_hasher(FxBuildHasher::default()),
extensible_predicates: ExtensiblePredicates::with_hasher(FxBuildHasher::default()),
local_extensible_predicates: LocalExtensiblePredicates::with_hasher(
FxBuildHasher::default()
FxBuildHasher::default(),
),
listing_src: ListingSource::DynamicallyGenerated,
}
Expand Down
Loading

0 comments on commit 55d0891

Please sign in to comment.