Skip to content

Commit 1069810

Browse files
author
Grant Wuerker
committed
Resolution handler API and ingot graph resolution.
1 parent c853e01 commit 1069810

32 files changed

+895
-681
lines changed

Cargo.lock

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

crates/common/src/config.rs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub struct Config;

crates/common/src/input.rs

+10
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ impl InputFile {
7474
pub fn abs_path(&self, db: &dyn InputDb, ingot: InputIngot) -> Utf8PathBuf {
7575
ingot.path(db).join(self.path(db))
7676
}
77+
78+
pub fn parse_config(&self, db: &dyn InputDb) -> IngotConfig {
79+
todo!()
80+
}
7781
}
7882

7983
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -120,3 +124,9 @@ impl Ord for IngotDependency {
120124
}
121125

122126
pub type Version = semver::Version;
127+
128+
struct IngotConfig {
129+
pub name: (),
130+
pub version: (),
131+
pub dependencies: (),
132+
}

crates/common/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
pub mod config;
12
pub mod core;
23
pub mod diagnostics;
34
pub mod indexmap;

crates/driver/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ common.workspace = true
1818
hir.workspace = true
1919
hir-analysis.workspace = true
2020
resolver.workspace = true
21+
indexmap = "2.9"

crates/driver/src/db.rs

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use hir_analysis::{
1717
ImplAnalysisPass, ImplTraitAnalysisPass, TraitAnalysisPass, TypeAliasAnalysisPass,
1818
},
1919
};
20+
use resolver::ResolutionHandler;
2021

2122
use crate::diagnostics::ToCsDiag;
2223

crates/driver/src/lib.rs

-153
Original file line numberDiff line numberDiff line change
@@ -7,156 +7,3 @@ use common::{
77
input::IngotKind,
88
};
99
pub use db::DriverDataBase;
10-
11-
use clap::{Parser, Subcommand};
12-
use hir::hir_def::TopLevelMod;
13-
use resolver::{
14-
ingot::{config::Config, source_files::SourceFiles, Ingot, IngotResolver},
15-
Resolver,
16-
};
17-
18-
pub fn run(opts: &Options) {
19-
match &opts.command {
20-
Command::Build => eprintln!("`fe build` doesn't work at the moment"),
21-
Command::Check { path, core } => {
22-
let db = DriverDataBase::default();
23-
let mut ingot_resolver = IngotResolver::default();
24-
25-
let core_ingot = if let Some(core_path) = core {
26-
match ingot_resolver.resolve(core_path) {
27-
Ok(Ingot::Folder {
28-
config:
29-
Some(Config {
30-
version: Some(version),
31-
..
32-
}),
33-
source_files:
34-
Some(SourceFiles {
35-
root: Some(root),
36-
files,
37-
}),
38-
}) => {
39-
let diagnostics = ingot_resolver.take_diagnostics();
40-
if !diagnostics.is_empty() {
41-
eprintln!("an error was encountered while resolving `{core_path}`");
42-
for diagnostic in diagnostics {
43-
eprintln!("{diagnostic}")
44-
}
45-
std::process::exit(2)
46-
}
47-
IngotBuilder::new(&db, "core")
48-
.kind(IngotKind::Core)
49-
.version(version)
50-
.entrypoint(root)
51-
.files_from_contents(files)
52-
.build()
53-
.0
54-
}
55-
Ok(Ingot::SingleFile { .. }) => {
56-
eprintln!("standalone core ingot not supported");
57-
std::process::exit(2)
58-
}
59-
Ok(_) => {
60-
eprintln!("an error was encountered while resolving `{core_path}`");
61-
for diagnostic in ingot_resolver.take_diagnostics() {
62-
eprintln!("{diagnostic}")
63-
}
64-
std::process::exit(2)
65-
}
66-
Err(error) => {
67-
eprintln!("an error was encountered while resolving `{core_path}`");
68-
eprintln!("{error}");
69-
std::process::exit(2)
70-
}
71-
}
72-
} else {
73-
builtin_core(&db)
74-
};
75-
76-
let local_ingot = match ingot_resolver.resolve(path) {
77-
Ok(Ingot::Folder {
78-
config:
79-
Some(Config {
80-
version: Some(version),
81-
..
82-
}),
83-
source_files:
84-
Some(SourceFiles {
85-
root: Some(root),
86-
files,
87-
}),
88-
}) => {
89-
let diagnostics = ingot_resolver.take_diagnostics();
90-
if !diagnostics.is_empty() {
91-
eprintln!("an error was encountered while resolving `{path}`");
92-
for diagnostic in diagnostics {
93-
eprintln!("{diagnostic}")
94-
}
95-
std::process::exit(2)
96-
}
97-
// db.local_ingot(path, &version, &root, files, core_ingot).0
98-
IngotBuilder::new(&db, path)
99-
.kind(IngotKind::Local)
100-
.version(version)
101-
.entrypoint(root)
102-
.files_from_contents(files)
103-
.build()
104-
.0
105-
}
106-
Ok(Ingot::SingleFile { path, content }) => {
107-
IngotBuilder::standalone(&db, path, content)
108-
.with_core_ingot(core_ingot)
109-
.build()
110-
.0
111-
}
112-
Ok(_) => {
113-
eprintln!("an error was encountered while resolving `{path}`");
114-
for diagnostic in ingot_resolver.take_diagnostics() {
115-
eprintln!("{diagnostic}")
116-
}
117-
std::process::exit(2)
118-
}
119-
Err(error) => {
120-
eprintln!("an error was encountered while resolving `{path}`");
121-
eprintln!("{error}");
122-
std::process::exit(2)
123-
}
124-
};
125-
126-
let core_diags = db.run_on_ingot(core_ingot);
127-
let local_diags = db.run_on_ingot(local_ingot);
128-
129-
if !core_diags.is_empty() || !local_diags.is_empty() {
130-
core_diags.emit(&db);
131-
local_diags.emit(&db);
132-
std::process::exit(1);
133-
}
134-
}
135-
Command::New => eprintln!("`fe new` doesn't work at the moment"),
136-
}
137-
}
138-
139-
#[derive(Debug, Clone, Parser)]
140-
#[command(version, about, long_about = None)]
141-
pub struct Options {
142-
#[command(subcommand)]
143-
pub command: Command,
144-
}
145-
146-
#[derive(Debug, Clone, Subcommand)]
147-
pub enum Command {
148-
Build,
149-
Check {
150-
// #[clap(default_value_t = find_project_root().unwrap_or(Utf8PathBuf::from(".")))]
151-
path: Utf8PathBuf,
152-
#[arg(short, long)]
153-
core: Option<Utf8PathBuf>,
154-
},
155-
New,
156-
}
157-
158-
fn _dump_scope_graph(db: &DriverDataBase, top_mod: TopLevelMod) -> String {
159-
let mut s = vec![];
160-
top_mod.scope_graph(db).write_as_dot(db, &mut s).unwrap();
161-
String::from_utf8(s).unwrap()
162-
}

crates/fe/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ edition = "2021"
66
[dependencies]
77
clap.workspace = true
88
driver.workspace = true
9+
resolver.workspace = true
10+
camino.workspace = true

crates/fe/src/check.rs

Whitespace-only changes.

crates/fe/src/main.rs

+43-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,44 @@
1-
use clap::Parser;
2-
use driver::Options;
1+
fn main() {}
32

4-
fn main() {
5-
let opts = Options::parse();
6-
driver::run(&opts);
7-
}
3+
// mod check;
4+
// mod tree;
5+
//
6+
// use clap::Parser;
7+
// use driver::Options;
8+
//
9+
// #[derive(Debug, Clone, Parser)]
10+
// #[command(version, about, long_about = None)]
11+
// pub struct Options {
12+
// #[command(subcommand)]
13+
// pub command: Command,
14+
// }
15+
//
16+
// #[derive(Debug, Clone, Subcommand)]
17+
// pub enum Command {
18+
// Build,
19+
// Check {
20+
// // #[clap(default_value_t = find_project_root().unwrap_or(Utf8PathBuf::from(".")))]
21+
// path: Utf8PathBuf,
22+
// #[arg(short, long)]
23+
// core: Option<Utf8PathBuf>,
24+
// },
25+
// Tree {
26+
// path: Utf8PathBuf,
27+
// },
28+
// New,
29+
// }
30+
//
31+
// fn main() {
32+
// let opts = Options::parse();
33+
// run(&opts);
34+
// }
35+
// pub fn run(opts: &Options) {
36+
// match &opts.command {
37+
// Command::Build => eprintln!("`fe build` doesn't work at the moment"),
38+
// Command::Check { path, core } => {
39+
// todo!()
40+
// }
41+
// Command::Tree { path } => {}
42+
// Command::New => eprintln!("`fe new` doesn't work at the moment"),
43+
// }
44+
// }

crates/fe/src/tree.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use std::fmt::Display;
2+
3+
use camino::Utf8PathBuf;
4+
use resolver::{
5+
ingot::{basic_ingot_graph_resolver, BasicIngotGraphResolver},
6+
Resolver,
7+
};
8+
9+
pub fn print_tree(path: &Utf8PathBuf) {
10+
let mut graph_resolver = basic_ingot_graph_resolver();
11+
let ingot_graph = graph_resolver.transient_resolve(path).unwrap();
12+
}
13+
14+
pub fn print_graph_as_tree(graph: ()) {
15+
todo!()
16+
}

crates/resolver/Cargo.toml

+5-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ common.workspace = true
1313
camino.workspace = true
1414
glob.workspace = true
1515
semver.workspace = true
16-
smol_str = "0.1"
16+
indexmap = "2.9"
17+
petgraph = "0.8"
18+
git2 = "0.19"
19+
dir-test.workspace = true
1720
toml = "0.8"
18-
serde = { version = "1", features = ["derive"] }
21+
test-utils.workspace = true
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
source: crates/resolver/tests/graph.rs
3+
expression: "format!(\"{:#?}\\n{:#?}\", graph, resolver.take_diagnostics())"
4+
input_file: fixtures/graph/dag.toml
5+
---
6+
Graph {
7+
Ty: "Directed",
8+
node_count: 5,
9+
edge_count: 7,
10+
edges: (0, 1), (1, 2), (0, 3), (3, 1), (0, 4), (4, 3), (4, 1),
11+
node weights: {
12+
0: "a",
13+
1: "d",
14+
2: "e",
15+
3: "c",
16+
4: "b",
17+
},
18+
}
19+
[]
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"a" = ["b","c","d"]
2+
"b" = ["c","d"]
3+
"c" = ["d"]
4+
"d" = ["e"]
5+
"e" = []
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
source: crates/resolver/tests/graph.rs
3+
expression: "format!(\"{:#?}\\n{:#?}\", graph, resolver.take_diagnostics())"
4+
input_file: fixtures/graph/dcg.toml
5+
---
6+
Graph {
7+
Ty: "Directed",
8+
node_count: 5,
9+
edge_count: 9,
10+
edges: (0, 1), (1, 2), (0, 3), (3, 0), (3, 1), (0, 4), (2, 4), (4, 3), (4, 1),
11+
node weights: {
12+
0: "a",
13+
1: "d",
14+
2: "e",
15+
3: "c",
16+
4: "b",
17+
},
18+
}
19+
[]
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"a" = ["b","c","d"]
2+
"b" = ["c","d"]
3+
"c" = ["a", "d"]
4+
"d" = ["e"]
5+
"e" = ["b"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
source: crates/resolver/tests/graph.rs
3+
expression: "format!(\"{:#?}\\n{:#?}\", graph, resolver.take_diagnostics())"
4+
input_file: fixtures/graph/unresolvable_nodes.toml
5+
---
6+
Graph {
7+
Ty: "Directed",
8+
node_count: 2,
9+
edge_count: 1,
10+
edges: (0, 1),
11+
node weights: {
12+
0: "a",
13+
1: "b",
14+
},
15+
}
16+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"a" = ["b", "c"]
2+
"b" = ["d"]

crates/resolver/fixtures/ingots.snap

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
source: crates/resolver/tests/ingot_graph.rs
3+
expression: "format!(\"{:#?}\\n{:#?}\", ingot_graph, resolver.take_diagnostics())"
4+
---
5+
Graph {
6+
Ty: "Directed",
7+
node_count: 5,
8+
edge_count: 6,
9+
edges: (0, 1), (1, 2), (1, 3), (3, 0), (0, 4), (4, 1),
10+
node weights: {
11+
0: "/home/grantwuerker/workshop/fe/crates/resolver/fixtures/ingots/A",
12+
1: "/home/grantwuerker/workshop/fe/crates/resolver/fixtures/ingots/C",
13+
2: "/home/grantwuerker/workshop/fe/crates/resolver/fixtures/ingots/E",
14+
3: "/home/grantwuerker/workshop/fe/crates/resolver/fixtures/ingots/D",
15+
4: "/home/grantwuerker/workshop/fe/crates/resolver/fixtures/ingots/B",
16+
},
17+
}
18+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[ingot]
2+
name = "A"
3+
version = "0.1"
4+
5+
[dependencies]
6+
B = "../B"
7+
C = "../C"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[ingot]
2+
name = "B"
3+
version = "0.2"
4+
5+
[dependencies]
6+
C = "../C"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[ingot]
2+
name = "C"
3+
version = "0.3"
4+
5+
[dependencies]
6+
E = "../E"
7+
D = "../D"

0 commit comments

Comments
 (0)