Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
3141b2d
restore ubuntu testing to ci.yml with rust version 1.77
mthom May 13, 2024
fa1b052
remove Term
mthom Jul 16, 2024
a8c0c5d
variable revision
mthom Jul 31, 2024
62bea56
introduce bespoke Heap type for in-heap partial strings
mthom May 14, 2024
dfe41eb
unmark_cell_bits! in push_literal (#2645)
mthom Nov 1, 2024
afd3be1
dereference clause_clause value, reserve more parser space (#2579)
mthom Nov 15, 2024
8aa4fae
Add safety proofs and assertions around Atom::as_ptr
adri326 Dec 29, 2024
b38103d
Turn RawBlockTraits::align() into a const
adri326 Dec 29, 2024
c2c8969
Fix RawBlock::alloc not aligning values to T::ALIGN
adri326 Dec 29, 2024
3a458bb
Properly encapsulate `raw_block` to enforce its invariants
adri326 Dec 29, 2024
78c7b99
Prove safety of AtomTable::build_with
adri326 Dec 29, 2024
7abf65f
Switch to Cell in RawBlock to reduce the number of invariants
adri326 Dec 29, 2024
e3c6a80
Fix miri warning about pointer->integer->pointer cast in stack.rs
adri326 Dec 29, 2024
7cf2333
Panic if Stack::truncate is called with an unaligned value
adri326 Dec 30, 2024
b4fbeb7
Add assertions in stack.rs and TODOs for leftover unsafe operations
adri326 Dec 30, 2024
0cda0ec
Tighten assertions in RawBlock::get to require indices to be less tha…
adri326 Dec 30, 2024
963ca37
Fix Machine::get_clause_p panicking from trying to read a dangling frame
adri326 Dec 31, 2024
2cd2f96
Rename InnerAtomTable::table to hash_set and make it private
adri326 Dec 31, 2024
b843a93
Add offsets to AtomTable, making Atom::as_ptr fully safe
adri326 Dec 31, 2024
77006e9
Move the logic of read_atom within AtomTable
adri326 Dec 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benches/run_iai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod setup;
mod iai {
use iai_callgrind::{library_benchmark, library_benchmark_group, main};

use scryer_prolog::QueryResolution;
use scryer_prolog::machine::parsed_results::QueryResolution;

use super::setup;

Expand Down
7 changes: 5 additions & 2 deletions benches/setup.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use std::{collections::BTreeMap, fs, path::Path};

use maplit::btreemap;
use scryer_prolog::{Machine, QueryResolution, Value};
use scryer_prolog::machine::{
parsed_results::{QueryResolution, Value},
Machine,
};

pub fn prolog_benches() -> BTreeMap<&'static str, PrologBenchmark> {
[
Expand Down Expand Up @@ -85,7 +88,7 @@ mod test {
#[test]
fn validate_benchmarks() {
use super::prolog_benches;
use scryer_prolog::{QueryMatch, QueryResolution};
use scryer_prolog::machine::parsed_results::{QueryMatch, QueryResolution};
use std::{fmt::Write, fs};

struct BenchResult {
Expand Down
396 changes: 158 additions & 238 deletions build/instructions_template.rs

Large diffs are not rendered by default.

39 changes: 33 additions & 6 deletions build/static_string_indexing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ impl<'ast> Visit<'ast> for StaticStrVisitor {
}
}

const INLINED_ATOM_MAX_LEN: usize = 6;

fn static_string_index(string: &str, index: usize) -> u64 {
if 0 < string.len() && string.len() <= INLINED_ATOM_MAX_LEN {
let mut string_buf: [u8; 8] = [0u8; 8];
string_buf[.. string.len()].copy_from_slice(string.as_bytes());
(u64::from_le_bytes(string_buf) << 1) | 1
} else {
(index << 1) as u64
}
}

pub fn index_static_strings(instruction_rs_path: &std::path::Path) -> TokenStream {
use quote::*;

Expand Down Expand Up @@ -149,11 +161,26 @@ pub fn index_static_strings(instruction_rs_path: &std::path::Path) -> TokenStrea
visitor.visit_file(&syntax)
}

let indices = (0..visitor.static_strs.len()).map(|i| (i << 3) as u64);
let indices_iter = indices.clone();
let mut static_str_keys = vec![];
let mut static_strs = vec![];
let mut static_str_indices = vec![];

let indices: Vec<u64> = visitor.static_strs.iter().map(|string| {
let index = static_string_index(string, static_strs.len());

static_str_keys.push(string);

if index & 1 == 1 {
index
} else {
static_str_indices.push(index);
static_strs.push(string);
index
}
}).collect();

let static_strs_len = visitor.static_strs.len();
let static_strs: &Vec<_> = &visitor.static_strs.into_iter().collect();
let static_strs_len = static_strs.len(); // visitor.static_strs.len();
//let static_strs: &Vec<_> = &visitor.static_strs.into_iter().collect();

quote! {
static STRINGS: [&str; #static_strs_len] = [
Expand All @@ -163,11 +190,11 @@ pub fn index_static_strings(instruction_rs_path: &std::path::Path) -> TokenStrea
];

macro_rules! atom {
#((#static_strs) => { Atom { index: #indices_iter } };)*
#((#static_str_keys) => { Atom { index: #indices } };)*
}

pub static STATIC_ATOMS_MAP: phf::Map<&'static str, Atom> = phf::phf_map! {
#(#static_strs => { Atom { index: #indices } },)*
#(#static_strs => { Atom { index: #static_str_indices } },)*
};
}
}
19 changes: 8 additions & 11 deletions src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ use crate::parser::ast::*;

use crate::forms::*;
use crate::instructions::*;
use crate::machine::heap::Heap;
use crate::targets::*;

use std::cell::Cell;

pub(crate) trait Allocator {
fn new() -> Self;

Expand All @@ -14,42 +13,40 @@ pub(crate) trait Allocator {
lvl: Level,
context: GenContext,
code: &mut CodeDeque,
);
) -> RegType;

fn mark_non_var<'a, Target: CompilationTarget<'a>>(
&mut self,
lvl: Level,
heap_loc: usize,
context: GenContext,
cell: &'a Cell<RegType>,
code: &mut CodeDeque,
);
) -> RegType;

#[allow(clippy::too_many_arguments)]
fn mark_reserved_var<'a, Target: CompilationTarget<'a>>(
&mut self,
var_num: usize,
lvl: Level,
cell: &Cell<VarReg>,
term_loc: GenContext,
context: GenContext,
code: &mut CodeDeque,
r: RegType,
is_new_var: bool,
);
) -> RegType;

fn mark_cut_var(&mut self, var_num: usize, chunk_num: usize) -> RegType;

fn mark_var<'a, Target: CompilationTarget<'a>>(
&mut self,
var_num: usize,
lvl: Level,
cell: &Cell<VarReg>,
context: GenContext,
code: &mut CodeDeque,
);
) -> RegType;

fn reset(&mut self);
fn reset_arg(&mut self, arg_num: usize);
fn reset_at_head(&mut self, args: &[Term]);
fn reset_at_head(&mut self, heap: &mut Heap, head_loc: usize);
fn reset_contents(&mut self);

fn advance_arg(&mut self);
Expand Down
54 changes: 15 additions & 39 deletions src/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,7 @@ impl RawBlockTraits for F64Table {
F64_TABLE_INIT_SIZE
}

#[inline]
fn align() -> usize {
F64_TABLE_ALIGN
}
const ALIGN: usize = F64_TABLE_ALIGN;
}

#[derive(Debug)]
Expand All @@ -98,8 +95,8 @@ pub fn lookup_float(

RcuRef::try_map(f64table.block.read(), |raw_block| unsafe {
raw_block
.base
.add(offset.0)
.get(offset.0)
.unwrap()
.cast_mut()
.cast::<UnsafeCell<OrderedFloat<f64>>>()
.as_ref()
Expand Down Expand Up @@ -154,7 +151,7 @@ impl F64Table {

ptr::write(ptr as *mut OrderedFloat<f64>, OrderedFloat(value));

let float = F64Offset(ptr as usize - block_epoch.base as usize);
let float = F64Offset(block_epoch.offset_of_unchecked(ptr));

// atometable would have to update the index table at this point

Expand Down Expand Up @@ -496,7 +493,11 @@ impl F64Ptr {

#[inline(always)]
pub fn as_offset(&self) -> F64Offset {
F64Offset(self.0.get() as usize - RcuRef::get_root(&self.0).base as usize)
F64Offset(
RcuRef::get_root(&self.0)
.offset_of(self.0.get().cast_const().cast::<u8>())
.unwrap(),
)
}
}

Expand Down Expand Up @@ -897,7 +898,7 @@ mod tests {
use crate::arena::*;
use crate::atom_table::*;
use crate::machine::mock_wam::*;
use crate::machine::partial_string::*;
use crate::types::*;

use crate::parser::dashu::{Integer, Rational};
use ordered_float::OrderedFloat;
Expand Down Expand Up @@ -980,7 +981,7 @@ mod tests {

assert!(!big_int_ptr.as_ptr().is_null());

let cell = HeapCellValue::from(Literal::Integer(big_int_ptr));
let cell = HeapCellValue::from(big_int_ptr);
assert_eq!(cell.get_tag(), HeapCellValueTag::Cons);

let untyped_arena_ptr = match cell.to_untyped_arena_ptr() {
Expand Down Expand Up @@ -1086,31 +1087,6 @@ mod tests {
_ => { unreachable!() }
);

// complete string

let pstr_var_cell =
put_partial_string(&mut wam.machine_st.heap, "ronan", &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);

match pstr_cell.to_pstr() {
Some(pstr) => {
assert_eq!(&*pstr.as_str_from(0), "ronan");
}
None => {
unreachable!();
}
}

read_heap_cell!(pstr_cell,
(HeapCellValueTag::PStr, pstr_atom) => {
let pstr = PartialString::from(pstr_atom);
assert_eq!(&*pstr.as_str_from(0), "ronan");
}
_ => { unreachable!() }
);

// fixnum

let fixnum_cell = fixnum_as_cell!(Fixnum::build_with(3));
Expand Down Expand Up @@ -1188,8 +1164,8 @@ mod tests {
let char_cell = char_as_cell!(c);

read_heap_cell!(char_cell,
(HeapCellValueTag::Char, c) => {
assert_eq!(c, 'c');
(HeapCellValueTag::Atom, (c, _arity)) => {
assert_eq!(&*c.as_str(), "c");
}
_ => { unreachable!() }
);
Expand All @@ -1198,8 +1174,8 @@ mod tests {
let cyrillic_char_cell = char_as_cell!(c);

read_heap_cell!(cyrillic_char_cell,
(HeapCellValueTag::Char, c) => {
assert_eq!(c, 'Ћ');
(HeapCellValueTag::Atom, (c, _arity)) => {
assert_eq!(&*c.as_str(), "Ћ");
}
_ => { unreachable!() }
);
Expand Down
Loading