Skip to content

Commit b4c2e1f

Browse files
Make polonius_souffle an optional dependency
1 parent 1ef7b4e commit b4c2e1f

File tree

5 files changed

+43
-13
lines changed

5 files changed

+43
-13
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ polonius-parser = { path = "./polonius-parser" }
1616
[dependencies]
1717
rustc-hash = "1.0.0"
1818
polonius-engine = { path = "polonius-engine" }
19-
polonius-souffle = { path = "polonius-souffle" }
19+
polonius-souffle = { path = "polonius-souffle", optional = true }
2020
log = "0.4"
2121
petgraph = "0.4.13"
2222
pico-args = "0.2"

polonius-engine/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ keywords = ["compiler", "borrowck", "datalog"]
1111
[dependencies]
1212
datafrog = "2.0.0"
1313
polonius-facts = { path = "../polonius-facts" }
14-
polonius-souffle = { path = "../polonius-souffle" }
14+
polonius-souffle = { path = "../polonius-souffle", optional = true }
1515
rustc-hash = "1.0.0"
1616
log = "0.4"

polonius-engine/src/output/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ impl<T: FactTypes> Output<T> {
187187
/// partial results can also be stored in the context, so that the following
188188
/// variant can use it to prune its own input data
189189
pub fn compute(all_facts: &AllFacts<T>, algorithm: Algorithm, dump_enabled: bool) -> Self {
190+
#[cfg(polonius_souffle)]
190191
if algorithm.engine() == Engine::Souffle {
191192
let name = algorithm
192193
.souffle_name()

src/cli.rs

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ use polonius_engine::{Algorithm, Engine};
44
use std::env;
55
use std::error;
66
use std::fmt;
7-
use std::path::Path;
7+
use std::path::{Path, PathBuf};
88
use std::process::exit;
99
use std::str::FromStr;
1010
use std::time::{Duration, Instant};
1111

1212
use crate::dump;
1313
use crate::dump::Output;
14+
use crate::facts::AllFacts;
1415
use crate::intern;
1516
use crate::tab_delim;
1617

@@ -77,16 +78,9 @@ pub fn main(opt: Options) -> Result<(), Error> {
7778
.souffle_name()
7879
.expect("Algorithm does not have Soufflé version");
7980

80-
// FIXME This time includes loading/unloading tuples across the FFI boundary.
81-
let (duration, output) = timed(|| polonius_souffle::run_from_facts(name, &all_facts));
82-
if !opt.skip_timing {
83-
let seconds = duration.as_secs() as f64;
84-
let millis = f64::from(duration.subsec_nanos()) * 0.000_000_001_f64;
85-
println!("Time: {:0.3}s", seconds + millis);
86-
}
87-
if opt.show_tuples {
88-
dump::dump_souffle_output(&output, &output_directory, tables, opt.verbose)
89-
.expect("Failed to write output");
81+
if let Err(e) = run_polonius_souffle(&all_facts, &output_directory, tables, name, &opt)
82+
{
83+
error!("`{}`: {}", facts_dir, e);
9084
}
9185

9286
continue;
@@ -115,6 +109,40 @@ pub fn main(opt: Options) -> Result<(), Error> {
115109
Ok(())
116110
}
117111

112+
#[cfg(polonius_souffle)]
113+
fn run_polonius_souffle(
114+
all_facts: &AllFacts,
115+
output_directory: &Option<PathBuf>,
116+
tables: &intern::InternerTables,
117+
souffle_name: &str,
118+
opt: &Options,
119+
) {
120+
// FIXME This time includes loading/unloading tuples across the FFI boundary.
121+
let (duration, output) = timed(|| polonius_souffle::run_from_facts(souffle_name, &all_facts));
122+
if !opt.skip_timing {
123+
let seconds = duration.as_secs() as f64;
124+
let millis = f64::from(duration.subsec_nanos()) * 0.000_000_001_f64;
125+
println!("Time: {:0.3}s", seconds + millis);
126+
}
127+
if opt.show_tuples {
128+
dump::dump_souffle_output(&output, &output_directory, tables, opt.verbose)
129+
.expect("Failed to write output");
130+
}
131+
}
132+
133+
#[cfg(not(polonius_souffle))]
134+
fn run_polonius_souffle(
135+
_: &AllFacts,
136+
_: &Option<PathBuf>,
137+
_: &intern::InternerTables,
138+
_: &str,
139+
_: &Options,
140+
) -> Result<(), Error> {
141+
Err(Error(
142+
"`polonius` was compiled without Soufflé backend (`--feature polonius_souffle`)".into(),
143+
))
144+
}
145+
118146
fn timed<T>(op: impl FnOnce() -> T) -> (Duration, T) {
119147
let start = Instant::now();
120148
let output = op();

src/dump.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use std::path::PathBuf;
1515

1616
pub(crate) type Output = PoloniusEngineOutput<LocalFacts>;
1717

18+
#[cfg(polonius_souffle)]
1819
pub(crate) fn dump_souffle_output(
1920
output: &HashMap<String, polonius_souffle::DynTuples>,
2021
output_dir: &Option<PathBuf>,

0 commit comments

Comments
 (0)