|
| 1 | +//! Copied partly from rustc `compiler/rustc_borrowck/src/facts.rs`, which is dual-licensed MIT and |
| 2 | +//! Apache 2.0. |
1 | 3 | use crate::borrowck::atoms::{AllFacts, AtomMaps, Loan, Origin, Output, Path, Point, Variable};
|
2 | 4 | use rustc_hash::{FxHashMap, FxHashSet};
|
3 |
| -/// Copied partly from rustc `compiler/rustc_borrowck/src/facts.rs`, which is dual-licensed MIT and |
4 |
| -/// Apache 2.0. |
5 | 5 | use std::collections::{BTreeMap, BTreeSet};
|
| 6 | +use std::env; |
6 | 7 | use std::error::Error;
|
7 | 8 | use std::fmt::Write as _;
|
8 | 9 | use std::fs::{self, File};
|
9 | 10 | use std::hash::Hash;
|
10 | 11 | use std::io::{BufWriter, Write};
|
11 | 12 | use std::path;
|
12 | 13 |
|
| 14 | +thread_local! { |
| 15 | + static DUMP_FACTS: bool = { |
| 16 | + env::var("C2RUST_ANALYZE_DUMP_POLONIUS_FACTS").map_or(false, |val| &val == "1") |
| 17 | + }; |
| 18 | +} |
| 19 | + |
13 | 20 | pub fn dump_facts_to_dir(
|
14 | 21 | facts: &AllFacts,
|
15 | 22 | maps: &AtomMaps,
|
16 | 23 | dir: impl AsRef<path::Path>,
|
17 | 24 | ) -> Result<(), Box<dyn Error>> {
|
| 25 | + if !DUMP_FACTS.with(|&flag| flag) { |
| 26 | + return Ok(()); |
| 27 | + } |
18 | 28 | let dir: &path::Path = dir.as_ref();
|
19 | 29 | fs::create_dir_all(dir)?;
|
20 | 30 | let wr = FactWriter { maps, dir };
|
@@ -60,6 +70,9 @@ pub fn dump_output_to_dir(
|
60 | 70 | maps: &AtomMaps,
|
61 | 71 | dir: impl AsRef<path::Path>,
|
62 | 72 | ) -> Result<(), Box<dyn Error>> {
|
| 73 | + if !DUMP_FACTS.with(|&flag| flag) { |
| 74 | + return Ok(()); |
| 75 | + } |
63 | 76 | let dir: &path::Path = dir.as_ref();
|
64 | 77 | fs::create_dir_all(dir)?;
|
65 | 78 | let wr = FactWriter { maps, dir };
|
|
0 commit comments