Skip to content

Commit 84d5ce0

Browse files
authored
Merge pull request #2309 from coasys/library-use-case
Iron-out edge cases for library use-case, adding extensive real-world test assertions
2 parents 419623d + e9982dc commit 84d5ce0

File tree

16 files changed

+12550
-276
lines changed

16 files changed

+12550
-276
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
- name: Setup Rust
2222
uses: ./.github/actions/setup-rust
2323
with:
24-
rust-version: nightly
24+
rust-version: stable
2525
targets: x86_64-unknown-linux-gnu
2626
components: clippy, rustfmt
2727
cache-context: style
@@ -44,7 +44,8 @@ jobs:
4444
# architectures
4545
- { os: ubuntu-22.04, rust-version: stable, target: 'x86_64-unknown-linux-gnu', publish: true }
4646
- { os: ubuntu-22.04, rust-version: stable, target: 'i686-unknown-linux-gnu', publish: true }
47-
- { os: ubuntu-22.04, rust-version: nightly, target: 'wasm32-unknown-unknown', publish: true, args: '--no-default-features' }
47+
# FIXME(issue #2138): run wasm tests, failing to run since https://github.com/mthom/scryer-prolog/pull/2137 removed wasm-pack
48+
- { os: ubuntu-22.04, rust-version: nightly, target: 'wasm32-unknown-unknown', publish: true, args: '--no-default-features' , test-args: '--no-run --no-default-features' }
4849
# rust versions
4950
- { os: ubuntu-22.04, rust-version: "1.70", target: 'x86_64-unknown-linux-gnu'}
5051
- { os: ubuntu-22.04, rust-version: beta, target: 'x86_64-unknown-linux-gnu'}
@@ -63,11 +64,9 @@ jobs:
6364

6465
# Build and test.
6566
- name: Build library
66-
continue-on-error: ${{ contains(matrix.target,'wasm32') }} # allow wasm builds to fail tests for now
6767
run: cargo build --all-targets --target ${{ matrix.target }} ${{ matrix.args }} --verbose
6868
- name: Test
69-
continue-on-error: ${{ contains(matrix.target,'wasm32') }} # allow wasm builds to fail tests for now
70-
run: cargo test --target ${{ matrix.target }} ${{ matrix.args }} --all
69+
run: cargo test --target ${{ matrix.target }} ${{ matrix.test-args }} --all
7170

7271
# On stable rust builds, build a binary and publish as a github actions
7372
# artifact. These binaries could be useful for testing the pipeline but
@@ -138,7 +137,7 @@ jobs:
138137
- name: Setup Rust
139138
uses: ./.github/actions/setup-rust
140139
with:
141-
rust-version: nightly
140+
rust-version: stable
142141
targets: x86_64-unknown-linux-gnu
143142
cache-context: report
144143
- run: |

Cargo.lock

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -37,52 +37,55 @@ to-syn-value_derive = "0.1.1"
3737
walkdir = "2"
3838

3939
[dependencies]
40+
base64 = "0.12.3"
4041
bit-set = "0.5.3"
4142
bitvec = "1"
43+
blake2 = "0.8.1"
44+
bytes = "1"
45+
chrono = "0.4.11"
4246
cpu-time = "1.0.0"
47+
crrl = "0.6.0"
48+
dashu = "0.4.0"
49+
derive_deref = "1.1.1"
4350
dirs-next = "2.0.0"
4451
divrem = "0.1.0"
52+
futures = "0.3"
4553
fxhash = "0.2.1"
4654
git-version = "0.3.4"
4755
indexmap = "1.0.2"
4856
lazy_static = "1.4.0"
4957
lexical = "5.2.2"
5058
libc = "0.2.62"
59+
libloading = "0.7"
5160
modular-bitfield = "0.11.2"
61+
num-order = { version = "1.2.0" }
5262
ordered-float = "2.6.0"
5363
phf = { version = "0.9", features = ["macros"] }
64+
rand = "0.8.5"
5465
ref_thread_local = "0.0.0"
66+
regex = "1.9.1"
67+
ring = { version = "0.17.5", features = ["wasm32_unknown_unknown_js"] }
5568
ripemd160 = "0.8.0"
56-
sha3 = "0.8.2"
57-
blake2 = "0.8.1"
58-
crrl = "0.6.0"
59-
chrono = "0.4.11"
60-
select = "0.6.0"
6169
roxmltree = "0.11.0"
62-
base64 = "0.12.3"
70+
ryu = "1.0.9"
71+
select = "0.6.0"
72+
sha3 = "0.8.2"
6373
smallvec = "1.8.0"
6474
static_assertions = "1.1.0"
65-
ryu = "1.0.9"
66-
futures = "0.3"
67-
regex = "1.9.1"
68-
libloading = "0.7"
69-
derive_deref = "1.1.1"
70-
bytes = "1"
71-
dashu = "0.4.0"
72-
num-order = { version = "1.2.0" }
73-
rand = "0.8.5"
74-
ring = { version = "0.17.5", features = ["wasm32_unknown_unknown_js"] }
75+
76+
serde_json = "1.0.95"
77+
serde = "1.0.159"
7578

7679
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
77-
libffi = { version = "3.2.0", optional = true }
78-
hostname = { version = "0.3.1", optional = true }
7980
crossterm = { version = "0.20.0", optional = true }
8081
ctrlc = { version = "3.2.2", optional = true }
81-
rustyline = { version = "12.0.0", optional = true }
82+
hostname = { version = "0.3.1", optional = true }
83+
libffi = { version = "3.2.0", optional = true }
8284
native-tls = { version = "0.2.4", optional = true }
83-
warp = { version = "=0.3.5", features = ["tls"], optional = true }
8485
reqwest = { version = "0.11.18", optional = true }
86+
rustyline = { version = "12.0.0", optional = true }
8587
tokio = { version = "1.28.2", features = ["full"] }
88+
warp = { version = "=0.3.5", features = ["tls"], optional = true }
8689

8790
[target.'cfg(target_arch = "wasm32")'.dependencies]
8891
getrandom = { version = "0.2.10", features = ["js"] }
@@ -99,19 +102,26 @@ console_error_panic_hook = "0.1"
99102
wasm-bindgen = "0.2.87"
100103
wasm-bindgen-futures = "0.4"
101104
serde-wasm-bindgen = "0.5"
102-
web-sys = { version = "0.3", features = ["Document", "Window", "Element", "Performance"] }
105+
web-sys = { version = "0.3", features = [
106+
"Document",
107+
"Window",
108+
"Element",
109+
"Performance",
110+
] }
103111
js-sys = "0.3"
104112

105113
[dev-dependencies]
106-
assert_cmd = "1.0.3"
107-
predicates-core = "1.0.2"
108114
maplit = "1.0.2"
115+
predicates-core = "1.0.2"
109116
serial_test = "2.0.0"
110-
iai-callgrind = { git = "https://github.com/iai-callgrind/iai-callgrind.git", rev = "c77bc3c83d7f4e976cc42d4597236a8db259e772" }
117+
118+
[target.'cfg(not(all(target_arch = "wasm32", target_os = "unknown")))'.dev-dependencies]
119+
assert_cmd = "1.0.3"
111120
criterion = "0.5.1"
121+
iai-callgrind = { git = "https://github.com/iai-callgrind/iai-callgrind.git", rev = "c77bc3c83d7f4e976cc42d4597236a8db259e772" }
112122
trycmd = "0.14.19"
113123

114-
[target.'cfg(not(target_os = "windows"))'.dev-dependencies]
124+
[target.'cfg(not(any(target_os = "windows", all(target_arch = "wasm32", target_os = "unknown"))))'.dev-dependencies]
115125
pprof = { version = "0.13.0", features = ["criterion", "flamegraph"] }
116126

117127
[patch.crates-io]

benches/run_criterion.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
12
use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
23

4+
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
35
#[cfg(not(target_os = "windows"))]
46
use pprof::criterion::{Output, PProfProfiler};
57

8+
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
69
mod setup;
710

11+
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
812
fn bench_criterion(c: &mut Criterion) {
913
for (&name, bench) in setup::prolog_benches().iter() {
1014
match bench.strategy {
@@ -15,7 +19,7 @@ fn bench_criterion(c: &mut Criterion) {
1519
};
1620
}
1721
}
18-
22+
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
1923
#[cfg(not(target_os = "windows"))]
2024
fn config() -> Criterion {
2125
Criterion::default()
@@ -28,9 +32,15 @@ fn config() -> Criterion {
2832
Criterion::default().sample_size(20)
2933
}
3034

35+
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
3136
criterion_group!(
3237
name = benches;
3338
config = config();
3439
targets = bench_criterion
3540
);
41+
42+
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
3643
criterion_main!(benches);
44+
45+
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
46+
fn main() {}

benches/run_iai.rs

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,38 @@
1-
use iai_callgrind::{library_benchmark, library_benchmark_group, main};
2-
use scryer_prolog::machine::parsed_results::QueryResolution;
3-
1+
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
42
mod setup;
53

6-
#[library_benchmark]
7-
#[bench::count_edges(setup::prolog_benches()["count_edges"].setup())]
8-
#[bench::numlist(setup::prolog_benches()["numlist"].setup())]
9-
#[bench::csv_codename(setup::prolog_benches()["csv_codename"].setup())]
10-
fn bench(mut run: impl FnMut() -> QueryResolution) -> QueryResolution {
11-
run()
4+
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
5+
mod iai {
6+
use iai_callgrind::{library_benchmark, library_benchmark_group, main};
7+
8+
use scryer_prolog::machine::parsed_results::QueryResolution;
9+
10+
use super::setup;
11+
12+
#[library_benchmark]
13+
#[bench::count_edges(setup::prolog_benches()["count_edges"].setup())]
14+
#[bench::numlist(setup::prolog_benches()["numlist"].setup())]
15+
#[bench::csv_codename(setup::prolog_benches()["csv_codename"].setup())]
16+
fn bench(mut run: impl FnMut() -> QueryResolution) -> QueryResolution {
17+
run()
18+
}
19+
20+
library_benchmark_group!(
21+
name = benches;
22+
benchmarks = bench
23+
);
24+
25+
main!(library_benchmark_groups = benches);
26+
27+
pub fn call_main() {
28+
main()
29+
}
30+
}
31+
32+
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
33+
fn main() {
34+
iai::call_main();
1235
}
1336

14-
library_benchmark_group!(
15-
name = benches;
16-
benchmarks = bench
17-
);
18-
main!(library_benchmark_groups = benches);
37+
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
38+
fn main() {}

benches/setup.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ impl PrologBenchmark {
7171
machine
7272
}
7373

74+
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
7475
pub fn setup(&self) -> impl FnMut() -> QueryResolution {
7576
let mut machine = self.make_machine();
7677
let query = self.query;

build/instructions_template.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,27 +1157,27 @@ fn generate_instruction_preface() -> TokenStream {
11571157
impl Instruction {
11581158
#[inline]
11591159
pub fn registers(&self) -> Vec<RegType> {
1160-
match self {
1161-
&Instruction::GetConstant(_, _, r) => vec![r],
1162-
&Instruction::GetList(_, r) => vec![r],
1163-
&Instruction::GetPartialString(_, _, r, _) => vec![r],
1164-
&Instruction::GetStructure(_, _, _, r) => vec![r],
1165-
&Instruction::GetVariable(r, t) => vec![r, temp_v!(t)],
1166-
&Instruction::GetValue(r, t) => vec![r, temp_v!(t)],
1167-
&Instruction::UnifyLocalValue(r) => vec![r],
1168-
&Instruction::UnifyVariable(r) => vec![r],
1169-
&Instruction::PutConstant(_, _, r) => vec![r],
1170-
&Instruction::PutList(_, r) => vec![r],
1171-
&Instruction::PutPartialString(_, _, r, _) => vec![r],
1172-
&Instruction::PutStructure(_, _, r) => vec![r],
1173-
&Instruction::PutValue(r, t) => vec![r, temp_v!(t)],
1174-
&Instruction::PutVariable(r, t) => vec![r, temp_v!(t)],
1175-
&Instruction::SetLocalValue(r) => vec![r],
1176-
&Instruction::SetVariable(r) => vec![r],
1177-
&Instruction::SetValue(r) => vec![r],
1178-
&Instruction::GetLevel(r) => vec![r],
1179-
&Instruction::GetPrevLevel(r) => vec![r],
1180-
&Instruction::GetCutPoint(r) => vec![r],
1160+
match *self {
1161+
Instruction::GetConstant(_, _, r) => vec![r],
1162+
Instruction::GetList(_, r) => vec![r],
1163+
Instruction::GetPartialString(_, _, r, _) => vec![r],
1164+
Instruction::GetStructure(_, _, _, r) => vec![r],
1165+
Instruction::GetVariable(r, t) => vec![r, temp_v!(t)],
1166+
Instruction::GetValue(r, t) => vec![r, temp_v!(t)],
1167+
Instruction::UnifyLocalValue(r) => vec![r],
1168+
Instruction::UnifyVariable(r) => vec![r],
1169+
Instruction::PutConstant(_, _, r) => vec![r],
1170+
Instruction::PutList(_, r) => vec![r],
1171+
Instruction::PutPartialString(_, _, r, _) => vec![r],
1172+
Instruction::PutStructure(_, _, r) => vec![r],
1173+
Instruction::PutValue(r, t) => vec![r, temp_v!(t)],
1174+
Instruction::PutVariable(r, t) => vec![r, temp_v!(t)],
1175+
Instruction::SetLocalValue(r) => vec![r],
1176+
Instruction::SetVariable(r) => vec![r],
1177+
Instruction::SetValue(r) => vec![r],
1178+
Instruction::GetLevel(r) => vec![r],
1179+
Instruction::GetPrevLevel(r) => vec![r],
1180+
Instruction::GetCutPoint(r) => vec![r],
11811181
_ => vec![],
11821182
}
11831183
}

src/bin/scryer-prolog.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
fn main() -> std::process::ExitCode {
22
use scryer_prolog::atom_table::Atom;
33
use scryer_prolog::*;
4-
use std::sync::atomic::Ordering;
54

65
#[cfg(feature = "repl")]
76
ctrlc::set_handler(move || {
8-
scryer_prolog::machine::INTERRUPT.store(true, Ordering::Relaxed);
7+
scryer_prolog::machine::INTERRUPT.store(true, std::sync::atomic::Ordering::Relaxed);
98
})
109
.unwrap();
1110

src/ffi.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use std::collections::HashMap;
2727
use std::convert::TryFrom;
2828
use std::error::Error;
2929
use std::ffi::{c_void, CString};
30+
use std::ptr::addr_of_mut;
3031

3132
use libffi::low::type_tag::STRUCT;
3233
use libffi::low::{ffi_abi_FFI_DEFAULT_ABI, ffi_cif, ffi_type, prep_cif, types, CodePtr};
@@ -90,20 +91,20 @@ impl ForeignFunctionTable {
9091
fn map_type_ffi(&mut self, source: &Atom) -> *mut ffi_type {
9192
unsafe {
9293
match source {
93-
atom!("sint64") => &mut types::sint64,
94-
atom!("sint32") => &mut types::sint32,
95-
atom!("sint16") => &mut types::sint16,
96-
atom!("sint8") => &mut types::sint8,
97-
atom!("uint64") => &mut types::uint64,
98-
atom!("uint32") => &mut types::uint32,
99-
atom!("uint16") => &mut types::uint16,
100-
atom!("uint8") => &mut types::uint8,
101-
atom!("bool") => &mut types::sint8,
102-
atom!("void") => &mut types::void,
103-
atom!("cstr") => &mut types::pointer,
104-
atom!("ptr") => &mut types::pointer,
105-
atom!("f32") => &mut types::float,
106-
atom!("f64") => &mut types::double,
94+
atom!("sint64") => addr_of_mut!(types::sint64),
95+
atom!("sint32") => addr_of_mut!(types::sint32),
96+
atom!("sint16") => addr_of_mut!(types::sint16),
97+
atom!("sint8") => addr_of_mut!(types::sint8),
98+
atom!("uint64") => addr_of_mut!(types::uint64),
99+
atom!("uint32") => addr_of_mut!(types::uint32),
100+
atom!("uint16") => addr_of_mut!(types::uint16),
101+
atom!("uint8") => addr_of_mut!(types::uint8),
102+
atom!("bool") => addr_of_mut!(types::sint8),
103+
atom!("void") => addr_of_mut!(types::void),
104+
atom!("cstr") => addr_of_mut!(types::pointer),
105+
atom!("ptr") => addr_of_mut!(types::pointer),
106+
atom!("f32") => addr_of_mut!(types::float),
107+
atom!("f64") => addr_of_mut!(types::double),
107108
struct_name => match self.structs.get_mut(&*struct_name.as_str()) {
108109
Some(ref mut struct_type) => &mut struct_type.ffi_type,
109110
None => unreachable!(),
@@ -161,7 +162,7 @@ impl ForeignFunctionTable {
161162
}
162163

163164
fn build_pointer_args(
164-
args: &mut Vec<Value>,
165+
args: &mut [Value],
165166
type_args: &[*mut ffi_type],
166167
structs_table: &mut HashMap<String, StructImpl>,
167168
) -> Result<PointerArgs, FFIError> {

src/heap_print.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1727,7 +1727,7 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> {
17271727
self.print_stream(stream, max_depth);
17281728
}
17291729
(ArenaHeaderTag::TcpListener, listener) => {
1730-
self.print_tcp_listener(&*listener, max_depth);
1730+
self.print_tcp_listener(&listener, max_depth);
17311731
}
17321732
(ArenaHeaderTag::Dropped, _value) => {
17331733
self.print_impromptu_atom(atom!("$dropped_value"));

0 commit comments

Comments
 (0)