Skip to content

Commit 7876e0d

Browse files
author
Grant Wuerker
committed
library2
1 parent fabcd29 commit 7876e0d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1725
-36
lines changed

Diff for: crates/common2/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ smol_str = "0.1.24"
1616
salsa = { git = "https://github.com/salsa-rs/salsa", rev = "a1bf3a6" }
1717
indexmap = "2.2"
1818
parser = { path = "../parser2", package = "fe-parser2" }
19+
toml = "0.8.13"
20+
serde = { version = "1", features = ["derive"] }
21+
git2 = "0.18.3"

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

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use std::env::VarError;
2+
3+
use camino::Utf8PathBuf;
4+
5+
pub struct HomeDir(Utf8PathBuf);
6+
7+
impl HomeDir {
8+
pub fn load() -> Self {
9+
match std::env::var("HOME") {
10+
Ok(home) => HomeDir(Utf8PathBuf::from(home)),
11+
Err(VarError::NotPresent) => HomeDir(Utf8PathBuf::from("~/.fe")),
12+
Err(_) => panic!("no unicode"),
13+
}
14+
}
15+
16+
pub fn path(&self) -> Utf8PathBuf {
17+
self.0.clone()
18+
}
19+
}

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{indexmap::IndexSet, InputDb};
88
#[salsa::input(constructor = __new_impl)]
99
pub struct InputIngot {
1010
/// An absolute path to the ingot root directory.
11-
/// The all files in the ingot should be located under this directory.
11+
/// All files in the ingot should be located under this directory.
1212
#[return_ref]
1313
pub path: Utf8PathBuf,
1414

@@ -60,7 +60,7 @@ impl InputIngot {
6060
}
6161

6262
/// Set the list of files which the ingot contains.
63-
/// All files must bee set before the ingot is used.
63+
/// All files must be set before the ingot is used.
6464
pub fn set_files(self, db: &mut dyn InputDb, files: IndexSet<InputFile>) {
6565
self.__set_files_impl(db).to(files);
6666
}
@@ -103,8 +103,8 @@ pub enum IngotKind {
103103
/// An external ingot which is depended on by the current ingot.
104104
External,
105105

106-
/// Standard library ingot.
107-
Std,
106+
/// Core library ingot.
107+
Core,
108108
}
109109

110110
#[derive(Debug, Clone, PartialEq, Eq, Hash)]

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

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pub mod diagnostics;
2+
pub mod home_dir;
23
pub mod indexmap;
34
pub mod input;
45

Diff for: crates/driver2/Cargo.toml

+6
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,11 @@ codespan-reporting = "0.11"
1616
hir = { path = "../hir", package = "fe-hir" }
1717
common = { path = "../common2", package = "fe-common2" }
1818
hir-analysis = { path = "../hir-analysis", package = "fe-hir-analysis" }
19+
resolver = { path = "../resolver", package = "fe-resolver" }
1920
camino = "1.1.4"
2021
clap = { version = "4.3", features = ["derive"] }
22+
semver = "1.0.23"
23+
walkdir = "2"
24+
include_dir = "0.7"
25+
dirs = "5.0.1"
26+
serde = { version = "1", features = ["derive"] }

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

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
use crate::CheckArgs;
2+
use common::indexmap::IndexSet;
3+
use common::input::IngotDependency;
4+
use common::{input::IngotKind, InputIngot};
5+
use fe_driver2::DriverDataBase;
6+
use include_dir::Dir;
7+
use semver::Version;
8+
use std::fs;
9+
use std::{collections::BTreeSet, path::Path};
10+
11+
pub fn check_standalone(
12+
path: &Path,
13+
source: String,
14+
std_ingot: InputIngot,
15+
db: &mut DriverDataBase,
16+
dump_scope_graph: bool,
17+
) {
18+
let mut dependencies = IndexSet::default();
19+
dependencies.insert(IngotDependency::new("std", std_ingot));
20+
let ingot = InputIngot::new(
21+
db,
22+
path.parent().unwrap().to_str().unwrap(),
23+
IngotKind::StandAlone,
24+
Version::new(0, 1, 0),
25+
dependencies.clone(),
26+
);
27+
28+
// let input_file = InputFile::new(
29+
// db,
30+
// ingot.clone(),
31+
// path.file_name().unwrap().to_str().unwrap().into(),
32+
// source,
33+
// );
34+
// ingot.set_files(db, BTreeSet::from([input_file.clone()]));
35+
// ingot.set_root_file(db, input_file);
36+
37+
let top_mod = db.standalone(path, &source);
38+
// db.run_on_top_mod(top_mod);
39+
// db.emit_diags();
40+
41+
// if dump_scope_graph {
42+
// println!("{}", dump_scope_graph(db, top_mod));
43+
// }
44+
}
45+
46+
pub fn check_ingot(
47+
path: &Path,
48+
std_ingot: InputIngot,
49+
db: &mut DriverDataBase,
50+
dump_scope_graph: bool,
51+
) {
52+
// let mut dependencies = BTreeSet::from([IngotDependency::new("std", std_ingot)]);
53+
// let mut dependencies = IndexSet::default();
54+
// let mut main_ingot = load_ingot(path, db, IngotKind::Local, &mut dependencies);
55+
56+
// main_ingot.set_external_ingots(db, dependencies);
57+
58+
let diags = db.run_on_ingot(std_ingot);
59+
60+
// let diags = db.format_diags();
61+
// if !diags.is_empty() {
62+
// panic!("{diags}")
63+
// }
64+
65+
// db.run_on_ingot(main_ingot);
66+
67+
// let diags = db.format_diags();
68+
// if !diags.is_empty() {
69+
// panic!("{:?}", diags)
70+
// }
71+
72+
// if dump_scope_graph {
73+
// println!("{}", dump_scope_graph(db, top_mod));
74+
// }
75+
}
76+
77+
// use include_dir::{include_dir, Dir};
78+
// use std::path::PathBuf;
79+
// use std::{collections::BTreeSet, path::Path};
80+
81+
// fn check_std_lib_exists(std_lib_files: &Dir, std_lib_path: &Path) -> bool {
82+
// true
83+
// }
84+
85+
// fn write_std_lib(std_lib_files: &Dir, std_lib_path: &Path) {
86+
// write_files_recursive(std_lib_files, std_lib_path);
87+
// }
88+
89+
// fn default_std_lib_path() -> PathBuf {
90+
// let home_dir = dirs::home_dir().expect("Failed to get user home directory");
91+
// home_dir.join(".fe/std")
92+
// }
93+
94+
// fn write_files_recursive(dir: &Dir<'_>, base_path: &Path) {
95+
// for file in dir.files() {
96+
// let file_path = base_path.join(file.path());
97+
// if let Some(parent_dir) = file_path.parent() {
98+
// std::fs::create_dir_all(parent_dir).unwrap();
99+
// }
100+
// std::fs::write(file_path, file.contents()).unwrap();
101+
// }
102+
103+
// for subdir in dir.dirs() {
104+
// let subdir_path = base_path.join(subdir.path());
105+
// std::fs::create_dir_all(&subdir_path).unwrap();
106+
// write_files_recursive(subdir, &base_path);
107+
// }
108+
// }

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

+66-4
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,23 @@ pub mod diagnostics;
22

33
use std::path;
44

5+
use camino::Utf8PathBuf;
56
use codespan_reporting::term::{
67
self,
78
termcolor::{BufferWriter, ColorChoice},
89
};
910
use common::{
1011
diagnostics::CompleteDiagnostic,
11-
indexmap::IndexSet,
12-
input::{IngotKind, Version},
12+
indexmap::{IndexMap, IndexSet},
13+
input::{IngotDependency, IngotKind, Version},
1314
InputDb, InputFile, InputIngot,
1415
};
1516
use hir::{
16-
analysis_pass::AnalysisPassManager, diagnostics::DiagnosticVoucher, hir_def::TopLevelMod,
17-
lower::map_file_to_mod, HirDb, LowerHirDb, ParsingPass, SpannedHirDb,
17+
analysis_pass::AnalysisPassManager,
18+
diagnostics::DiagnosticVoucher,
19+
hir_def::TopLevelMod,
20+
lower::{map_file_to_mod, module_tree},
21+
HirDb, LowerHirDb, ParsingPass, SpannedHirDb,
1822
};
1923
use hir_analysis::{
2024
name_resolution::{DefConflictAnalysisPass, ImportAnalysisPass, PathAnalysisPass},
@@ -24,6 +28,7 @@ use hir_analysis::{
2428
},
2529
HirAnalysisDb,
2630
};
31+
use resolver::ingot::{dependency_graph::DependencyGraph, src_files::SourceFiles};
2732

2833
use crate::diagnostics::ToCsDiag;
2934

@@ -71,6 +76,63 @@ impl DriverDataBase {
7176
DiagnosticsCollection(pass_manager.run_on_module(top_mod))
7277
}
7378

79+
pub fn run_on_ingot<'db>(&'db mut self, ingot: InputIngot) -> DiagnosticsCollection<'db> {
80+
self.run_on_ingot_with_pass_manager(ingot, initialize_analysis_pass)
81+
}
82+
83+
pub fn run_on_ingot_with_pass_manager<'db, F>(
84+
&'db mut self,
85+
ingot: InputIngot,
86+
pm_builder: F,
87+
) -> DiagnosticsCollection<'db>
88+
where
89+
F: FnOnce(&'db DriverDataBase) -> AnalysisPassManager<'db>,
90+
{
91+
let tree = module_tree(self, ingot);
92+
let mut pass_manager = pm_builder(self);
93+
DiagnosticsCollection(pass_manager.run_on_module_tree(tree))
94+
}
95+
96+
pub fn local_ingot(
97+
&mut self,
98+
core_ingot: InputIngot,
99+
dependency_graph: &DependencyGraph,
100+
) -> (InputIngot, IndexMap<Utf8PathBuf, InputIngot>) {
101+
let mut all_ingots = IndexMap::new();
102+
103+
for path in dependency_graph.reverse_toposort() {
104+
let external_ingots = dependency_graph
105+
.dependencies(&path)
106+
.into_iter()
107+
.map(|dependency| IngotDependency {
108+
name: dependency.name,
109+
ingot: all_ingots[&dependency.target_path],
110+
})
111+
.collect();
112+
113+
all_ingots[&path] = InputIngot::new(
114+
self,
115+
&path.to_string(),
116+
IngotKind::External,
117+
Version::new(0, 0, 0),
118+
external_ingots,
119+
);
120+
}
121+
122+
let local_ingot = all_ingots
123+
.shift_remove(&dependency_graph.local_path)
124+
.expect("local is missing from input ingots");
125+
(local_ingot, all_ingots)
126+
}
127+
128+
pub fn core_ingot(&mut self, path: &Utf8PathBuf) -> InputIngot {
129+
todo!();
130+
}
131+
132+
pub fn set_ingot_files(&mut self, ingot: InputIngot, files: SourceFiles) {
133+
todo!()
134+
}
135+
74136
pub fn standalone(&mut self, file_path: &path::Path, source: &str) -> InputFile {
75137
let kind = IngotKind::StandAlone;
76138

0 commit comments

Comments
 (0)