Skip to content

Commit 50bdc7a

Browse files
author
Grant Wuerker
committed
library2
1 parent 70fca41 commit 50bdc7a

File tree

23 files changed

+513
-38
lines changed

23 files changed

+513
-38
lines changed

Diff for: Cargo.lock

+60-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: crates/common2/src/input.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::InputDb;
1010
#[salsa::input(constructor = __new_impl)]
1111
pub struct InputIngot {
1212
/// An absolute path to the ingot root directory.
13-
/// The all files in the ingot should be located under this directory.
13+
/// All files in the ingot should be located under this directory.
1414
#[return_ref]
1515
pub path: Utf8PathBuf,
1616

@@ -23,6 +23,7 @@ pub struct InputIngot {
2323

2424
/// A list of ingots which the current ingot depends on.
2525
#[return_ref]
26+
#[set(__set_external_ingots_impl)]
2627
pub external_ingots: BTreeSet<IngotDependency>,
2728

2829
/// A list of files which the current ingot contains.
@@ -72,6 +73,10 @@ impl InputIngot {
7273
pub fn root_file(&self, db: &dyn InputDb) -> InputFile {
7374
self.__get_root_file_impl(db).unwrap()
7475
}
76+
77+
pub fn set_external_ingots(self, db: &mut dyn InputDb, ingots: BTreeSet<IngotDependency>) {
78+
self.__set_external_ingots_impl(db).to(ingots);
79+
}
7580
}
7681

7782
#[salsa::input]

Diff for: crates/driver2/Cargo.toml

+5
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@ description = "Provides Fe driver"
1212
[dependencies]
1313
salsa = { git = "https://github.com/salsa-rs/salsa", package = "salsa-2022" }
1414
codespan-reporting = "0.11"
15+
library2 = { path = "../library2", package = "fe-library2" }
1516

1617
hir = { path = "../hir", package = "fe-hir" }
1718
common = { path = "../common2", package = "fe-common2" }
1819
macros = { path = "../macros", package = "fe-macros" }
1920
hir-analysis = { path = "../hir-analysis", package = "fe-hir-analysis" }
2021
camino = "1.1.4"
2122
clap = { version = "4.3", features = ["derive"] }
23+
toml = "0.8.13"
24+
serde = { version = "1", features = ["derive"] }
25+
semver = "1.0.23"
26+
walkdir = "2"

Diff for: crates/driver2/src/check.rs

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
use crate::{load_ingot, set_src_files, CheckArgs};
2+
use common::input::{IngotDependency, InputFile};
3+
use common::{input::IngotKind, InputDb, InputIngot};
4+
use fe_driver2::DriverDataBase;
5+
use semver::Version;
6+
use std::fs;
7+
use std::{collections::BTreeSet, path::Path};
8+
9+
pub fn run_check(args: &CheckArgs) {
10+
let std_path = Path::new(&args.std_path);
11+
if !std_path.exists() {
12+
eprintln!(
13+
"Standard library path '{}' does not exist",
14+
std_path.display()
15+
);
16+
std::process::exit(2);
17+
}
18+
19+
let path = Path::new(&args.path);
20+
if !path.exists() {
21+
eprintln!("Path '{}' does not exist", path.display());
22+
std::process::exit(2);
23+
}
24+
25+
let mut db = DriverDataBase::default();
26+
27+
let std_ingot = load_ingot(&std_path, &mut db, IngotKind::Std, &mut BTreeSet::new());
28+
29+
if path.is_file() {
30+
let source = fs::read_to_string(path).unwrap();
31+
check_single_file(path, source, std_ingot, &mut db, args.dump_scope_graph);
32+
} else if path.is_dir() {
33+
check_ingot(path, std_ingot, &mut db, args.dump_scope_graph);
34+
} else {
35+
eprintln!(
36+
"Path '{}' is neither a file nor a directory",
37+
path.display()
38+
);
39+
std::process::exit(2);
40+
}
41+
}
42+
43+
pub fn check_single_file(
44+
path: &Path,
45+
source: String,
46+
std_ingot: InputIngot,
47+
db: &mut DriverDataBase,
48+
dump_scope_graph: bool,
49+
) {
50+
let mut dependencies = BTreeSet::from([IngotDependency::new("std", std_ingot)]);
51+
let ingot = InputIngot::new(
52+
db,
53+
path.parent().unwrap().to_str().unwrap(),
54+
IngotKind::StandAlone,
55+
Version::new(0, 1, 0),
56+
dependencies.clone(),
57+
);
58+
59+
// let input_file = InputFile::new(
60+
// db,
61+
// ingot.clone(),
62+
// path.file_name().unwrap().to_str().unwrap().into(),
63+
// source,
64+
// );
65+
// ingot.set_files(db, BTreeSet::from([input_file.clone()]));
66+
// ingot.set_root_file(db, input_file);
67+
68+
let top_mod = db.top_mod_from_file(path, &source);
69+
db.run_on_top_mod(top_mod);
70+
db.emit_diags();
71+
72+
// if dump_scope_graph {
73+
// println!("{}", dump_scope_graph(db, top_mod));
74+
// }
75+
}
76+
77+
pub fn check_ingot(
78+
path: &Path,
79+
std_ingot: InputIngot,
80+
db: &mut DriverDataBase,
81+
dump_scope_graph: bool,
82+
) {
83+
let mut dependencies = BTreeSet::from([IngotDependency::new("std", std_ingot)]);
84+
let mut main_ingot = load_ingot(path, db, IngotKind::Local, &mut dependencies);
85+
86+
main_ingot.set_external_ingots(db, dependencies);
87+
88+
db.run_on_ingot(std_ingot);
89+
90+
let diags = db.format_diags();
91+
if !diags.is_empty() {
92+
panic!("{diags}")
93+
}
94+
95+
// let top_mod = db.top_mod_from_ingot(main_ingot);
96+
// db.run_on_top_mod(top_mod);
97+
// db.emit_diags();
98+
99+
// if dump_scope_graph {
100+
// println!("{}", dump_scope_graph(db, top_mod));
101+
// }
102+
}

Diff for: crates/driver2/src/lib.rs

+21-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ use common::{
1212
InputDb, InputFile, InputIngot,
1313
};
1414
use hir::{
15-
analysis_pass::AnalysisPassManager, diagnostics::DiagnosticVoucher, hir_def::TopLevelMod,
16-
lower::map_file_to_mod, HirDb, LowerHirDb, ParsingPass, SpannedHirDb,
15+
analysis_pass::AnalysisPassManager,
16+
diagnostics::DiagnosticVoucher,
17+
hir_def::TopLevelMod,
18+
lower::{map_file_to_mod, module_tree},
19+
HirDb, LowerHirDb, ParsingPass, SpannedHirDb,
1720
};
1821
use hir_analysis::{
1922
name_resolution::{DefConflictAnalysisPass, ImportAnalysisPass, PathAnalysisPass},
@@ -58,6 +61,10 @@ impl DriverDataBase {
5861
self.run_on_file_with_pass_manager(top_mod, initialize_analysis_pass);
5962
}
6063

64+
pub fn run_on_ingot(&mut self, ingot: InputIngot) {
65+
self.run_on_ingot_with_pass_manager(ingot, initialize_analysis_pass);
66+
}
67+
6168
pub fn run_on_file_with_pass_manager<F>(&mut self, top_mod: TopLevelMod, pm_builder: F)
6269
where
6370
F: FnOnce(&DriverDataBase) -> AnalysisPassManager<'_>,
@@ -69,6 +76,18 @@ impl DriverDataBase {
6976
};
7077
}
7178

79+
pub fn run_on_ingot_with_pass_manager<F>(&mut self, ingot: InputIngot, pm_builder: F)
80+
where
81+
F: FnOnce(&DriverDataBase) -> AnalysisPassManager<'_>,
82+
{
83+
self.diags.clear();
84+
let tree = module_tree(self, ingot);
85+
self.diags = {
86+
let mut pass_manager = pm_builder(self);
87+
pass_manager.run_on_module_tree(tree)
88+
};
89+
}
90+
7291
pub fn top_mod_from_file(&mut self, file_path: &path::Path, source: &str) -> TopLevelMod {
7392
let kind = IngotKind::StandAlone;
7493

0 commit comments

Comments
 (0)