Skip to content

Commit

Permalink
Merge pull request #2523 from bakaq/visibility
Browse files Browse the repository at this point in the history
Be conservative with visibility
  • Loading branch information
mthom authored Sep 25, 2024
2 parents 3fa6b69 + 16734ec commit 383eb5b
Show file tree
Hide file tree
Showing 33 changed files with 120 additions and 385 deletions.
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::machine::parsed_results::QueryResolution;
use scryer_prolog::QueryResolution;

use super::setup;

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

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

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

struct BenchResult {
Expand Down
55 changes: 30 additions & 25 deletions build/instructions_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ enum InlinedClauseType {
#[allow(dead_code)]
#[derive(ToDeriveInput, EnumDiscriminants)]
#[strum_discriminants(derive(EnumProperty, EnumString))]
enum REPLCodePtr {
enum ReplCodePtr {
#[strum_discriminants(strum(props(Arity = "4", Name = "$add_discontiguous_predicate")))]
AddDiscontiguousPredicate,
#[strum_discriminants(strum(props(Arity = "4", Name = "$add_dynamic_predicate")))]
Expand Down Expand Up @@ -534,7 +534,7 @@ enum SystemClauseType {
#[strum_discriminants(strum(props(Arity = "2", Name = "$shell")))]
Shell,
#[strum_discriminants(strum(props(Arity = "1", Name = "$pid")))]
PID,
Pid,
#[strum_discriminants(strum(props(Arity = "4", Name = "$chars_base64")))]
CharsBase64,
#[strum_discriminants(strum(props(Arity = "1", Name = "$devour_whitespace")))]
Expand Down Expand Up @@ -608,7 +608,7 @@ enum SystemClauseType {
InferenceLimitExceeded,
#[strum_discriminants(strum(props(Arity = "1", Name = "$argv")))]
Argv,
REPL(REPLCodePtr),
Repl(ReplCodePtr),
}

#[allow(dead_code)]
Expand Down Expand Up @@ -811,7 +811,7 @@ fn derive_input(ty: &Type) -> Option<DeriveInput> {
let system_clause_type: Type = parse_quote! { SystemClauseType };
let compare_term_type: Type = parse_quote! { CompareTerm };
let compare_number_type: Type = parse_quote! { CompareNumber };
let repl_code_ptr_type: Type = parse_quote! { REPLCodePtr };
let repl_code_ptr_type: Type = parse_quote! { ReplCodePtr };

if ty == &clause_type {
Some(ClauseType::to_derive_input())
Expand All @@ -826,7 +826,7 @@ fn derive_input(ty: &Type) -> Option<DeriveInput> {
} else if ty == &compare_term_type {
Some(CompareTerm::to_derive_input())
} else if ty == &repl_code_ptr_type {
Some(REPLCodePtr::to_derive_input())
Some(ReplCodePtr::to_derive_input())
} else {
None
}
Expand Down Expand Up @@ -983,6 +983,7 @@ fn generate_instruction_preface() -> TokenStream {
}

/// `IndexingInstruction` cf. page 110 of wambook.
#[allow(clippy::enum_variant_names)]
#[derive(Clone, Debug)]
pub enum IndexingInstruction {
// The first index is the optimal argument being indexed.
Expand Down Expand Up @@ -1867,7 +1868,7 @@ fn generate_instruction_preface() -> TokenStream {
&Instruction::CallSetEnv |
&Instruction::CallUnsetEnv |
&Instruction::CallShell |
&Instruction::CallPID |
&Instruction::CallPid |
&Instruction::CallCharsBase64 |
&Instruction::CallDevourWhitespace |
&Instruction::CallIsSTOEnabled |
Expand Down Expand Up @@ -2104,7 +2105,7 @@ fn generate_instruction_preface() -> TokenStream {
&Instruction::ExecuteSetEnv |
&Instruction::ExecuteUnsetEnv |
&Instruction::ExecuteShell |
&Instruction::ExecutePID |
&Instruction::ExecutePid |
&Instruction::ExecuteCharsBase64 |
&Instruction::ExecuteDevourWhitespace |
&Instruction::ExecuteIsSTOEnabled |
Expand Down Expand Up @@ -2357,7 +2358,7 @@ pub fn generate_instructions_rs() -> TokenStream {
let builtin_type_variants = attributeless_enum::<BuiltInClauseType>();
let inlined_type_variants = attributeless_enum::<InlinedClauseType>();
let system_clause_type_variants = attributeless_enum::<SystemClauseType>();
let repl_code_ptr_variants = attributeless_enum::<REPLCodePtr>();
let repl_code_ptr_variants = attributeless_enum::<ReplCodePtr>();
let compare_number_variants = attributeless_enum::<CompareNumber>();
let compare_term_variants = attributeless_enum::<CompareTerm>();

Expand Down Expand Up @@ -2708,28 +2709,28 @@ pub fn generate_instructions_rs() -> TokenStream {

clause_type_from_name_and_arity_arms.push(if !variant_fields.is_empty() {
quote! {
(atom!(#name), #arity) => ClauseType::System(SystemClauseType::REPL(
REPLCodePtr::#ident(#(#variant_fields),*)
(atom!(#name), #arity) => ClauseType::System(SystemClauseType::Repl(
ReplCodePtr::#ident(#(#variant_fields),*)
))
}
} else {
quote! {
(atom!(#name), #arity) => ClauseType::System(SystemClauseType::REPL(
REPLCodePtr::#ident
(atom!(#name), #arity) => ClauseType::System(SystemClauseType::Repl(
ReplCodePtr::#ident
))
}
});

clause_type_name_arms.push(if !variant_fields.is_empty() {
quote! {
ClauseType::System(
SystemClauseType::REPL(REPLCodePtr::#ident(..))
SystemClauseType::Repl(ReplCodePtr::#ident(..))
) => atom!(#name)
}
} else {
quote! {
ClauseType::System(
SystemClauseType::REPL(REPLCodePtr::#ident)
SystemClauseType::Repl(ReplCodePtr::#ident)
) => atom!(#name)
}
});
Expand All @@ -2743,14 +2744,14 @@ pub fn generate_instructions_rs() -> TokenStream {

clause_type_to_instr_arms.push(if !variant_fields.is_empty() {
quote! {
ClauseType::System(SystemClauseType::REPL(
REPLCodePtr::#ident(#(#placeholder_ids),*)
ClauseType::System(SystemClauseType::Repl(
ReplCodePtr::#ident(#(#placeholder_ids),*)
)) => Instruction::#instr_ident(#(*#placeholder_ids),*)
}
} else {
quote! {
ClauseType::System(SystemClauseType::REPL(
REPLCodePtr::#ident
ClauseType::System(SystemClauseType::Repl(
ReplCodePtr::#ident
)) => Instruction::#instr_ident
}
});
Expand Down Expand Up @@ -3109,13 +3110,15 @@ pub fn generate_instructions_rs() -> TokenStream {
quote! {
#preface_tokens

#[allow(clippy::enum_variant_names)]
#[derive(Clone, Debug)]
pub enum CompareTerm {
#(
#compare_term_variants,
)*
}

#[allow(clippy::enum_variant_names)]
#[derive(Clone, Copy, Debug)]
pub enum CompareNumber {
#(
Expand Down Expand Up @@ -3161,7 +3164,7 @@ pub fn generate_instructions_rs() -> TokenStream {
}

#[derive(Clone, Debug)]
pub enum REPLCodePtr {
pub enum ReplCodePtr {
#(
#repl_code_ptr_variants,
)*
Expand Down Expand Up @@ -3228,7 +3231,7 @@ pub fn generate_instructions_rs() -> TokenStream {
}
}

pub fn to_default(self) -> Instruction {
pub fn into_default(self) -> Instruction {
match self {
#(
#to_default_arms,
Expand All @@ -3237,7 +3240,7 @@ pub fn generate_instructions_rs() -> TokenStream {
}
}

pub fn to_execute(self) -> Instruction {
pub fn into_execute(self) -> Instruction {
match self {
#(
#to_execute_arms,
Expand All @@ -3252,6 +3255,7 @@ pub fn generate_instructions_rs() -> TokenStream {
)
}

#[allow(dead_code)]
pub fn is_ctrl_instr(&self) -> bool {
matches!(self,
Instruction::Allocate(_) |
Expand All @@ -3262,6 +3266,7 @@ pub fn generate_instructions_rs() -> TokenStream {
)
}

#[allow(dead_code)]
pub fn is_query_instr(&self) -> bool {
matches!(self,
&Instruction::GetVariable(..) |
Expand All @@ -3281,14 +3286,14 @@ pub fn generate_instructions_rs() -> TokenStream {
}
}

#[macro_export]
macro_rules! _instr {
#(
#instr_macro_arms
);*
}

pub use _instr as instr; // https://github.com/rust-lang/rust/pull/52234#issuecomment-976702997
// https://github.com/rust-lang/rust/pull/52234#issuecomment-976702997
pub(crate) use _instr as instr;
}
}

Expand Down Expand Up @@ -3416,8 +3421,8 @@ impl InstructionData {
);

(name, arity, CountableInference::NotCounted)
} else if id == "REPLCodePtr" {
let (name, arity) = add_discriminant_data::<REPLCodePtrDiscriminants>(
} else if id == "ReplCodePtr" {
let (name, arity) = add_discriminant_data::<ReplCodePtrDiscriminants>(
&variant,
prefix,
&mut self.repl_code_ptr_variants,
Expand Down
3 changes: 0 additions & 3 deletions build/static_string_indexing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,12 @@ pub fn index_static_strings(instruction_rs_path: &std::path::Path) -> TokenStrea
let static_strs: &Vec<_> = &visitor.static_strs.into_iter().collect();

quote! {
use phf;

static STRINGS: [&str; #static_strs_len] = [
#(
#static_strs,
)*
];

#[macro_export]
macro_rules! atom {
#((#static_strs) => { Atom { index: #indices_iter } };)*
}
Expand Down
4 changes: 2 additions & 2 deletions src/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,13 @@ use std::ptr::addr_of_mut;
use std::ptr::NonNull;
use std::sync::RwLock;

#[macro_export]
macro_rules! arena_alloc {
($e:expr, $arena:expr) => {{
let result = $e;
$crate::arena::AllocateInArena::arena_allocate(result, $arena)
}};
}

#[macro_export]
macro_rules! float_alloc {
($e:expr, $arena:expr) => {{
let result = $e;
Expand Down Expand Up @@ -896,6 +894,8 @@ const_assert!(mem::size_of::<OrderedFloat<f64>>() == 8);
mod tests {
use std::ops::Deref;

use crate::arena::*;
use crate::atom_table::*;
use crate::machine::mock_wam::*;
use crate::machine::partial_string::*;

Expand Down
7 changes: 0 additions & 7 deletions src/atom_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,6 @@ impl Hash for Atom {
}
}

#[macro_export]
macro_rules! is_char {
($s:expr) => {
!$s.is_empty() && $s.chars().nth(1).is_none()
};
}

pub enum AtomString<'a> {
Static(&'a str),
Dynamic(AtomTableRef<str>),
Expand Down
26 changes: 1 addition & 25 deletions src/bin/scryer-prolog.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,3 @@
fn main() -> std::process::ExitCode {
use scryer_prolog::atom_table::Atom;
use scryer_prolog::*;

#[cfg(feature = "repl")]
ctrlc::set_handler(move || {
scryer_prolog::machine::INTERRUPT.store(true, std::sync::atomic::Ordering::Relaxed);
})
.unwrap();

#[cfg(target_arch = "wasm32")]
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap();

#[cfg(not(target_arch = "wasm32"))]
let runtime = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap();

runtime.block_on(async move {
let mut wam = machine::Machine::new(Default::default());
wam.run_module_predicate(atom!("$toplevel"), (atom!("$repl"), 0))
})
scryer_prolog::run_binary()
}
8 changes: 3 additions & 5 deletions src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ use crate::instructions::*;
use crate::iterators::*;
use crate::parser::ast::*;
use crate::targets::*;
use crate::temp_v;
use crate::types::*;
use crate::variable_records::*;

use crate::instr;
use crate::machine::disjuncts::*;
use crate::machine::machine_errors::*;

Expand Down Expand Up @@ -559,14 +557,14 @@ impl<'b> CodeGenerator<'b> {
match call_policy {
CallPolicy::Default => {
if self.marker.in_tail_position {
code.push_back(call_instr.to_execute().to_default());
code.push_back(call_instr.into_execute().into_default());
} else {
code.push_back(call_instr.to_default())
code.push_back(call_instr.into_default())
}
}
CallPolicy::Counted => {
if self.marker.in_tail_position {
code.push_back(call_instr.to_execute());
code.push_back(call_instr.into_execute());
} else {
code.push_back(call_instr)
}
Expand Down
11 changes: 0 additions & 11 deletions src/forms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,6 @@ impl ChunkedTermVec {
.push_back(ChunkedTerms::Branch(Vec::with_capacity(capacity)));
}

pub fn push_branch_arm(&mut self, branch: VecDeque<ChunkedTerms>) {
match self.chunk_vec.back_mut().unwrap() {
ChunkedTerms::Branch(branches) => {
branches.push(branch);
}
ChunkedTerms::Chunk(_) => {
self.chunk_vec.push_back(ChunkedTerms::Branch(vec![branch]));
}
}
}

#[inline]
pub fn add_chunk(&mut self) {
self.chunk_vec
Expand Down
Loading

0 comments on commit 383eb5b

Please sign in to comment.