Skip to content

Commit 1fc7654

Browse files
author
Grant Wuerker
committed
library2
1 parent fabcd29 commit 1fc7654

Some content is hidden

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

55 files changed

+1803
-40
lines changed

Diff for: Cargo.lock

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

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+
// }

0 commit comments

Comments
 (0)