Skip to content

Commit c391a73

Browse files
author
Grant Wuerker
committed
hacking
1 parent 0c2a16b commit c391a73

File tree

19 files changed

+405
-244
lines changed

19 files changed

+405
-244
lines changed

Cargo.lock

Lines changed: 20 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/common2/src/input.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ pub enum IngotKind {
105105

106106
/// Standard library ingot.
107107
Std,
108+
109+
/// Core library ingot.
110+
Core,
108111
}
109112

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

crates/common2/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ pub mod config;
22
pub mod diagnostics;
33
pub mod indexmap;
44
pub mod input;
5-
pub mod resolver;
65

76
pub use input::{InputFile, InputIngot};
87

crates/driver2/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ 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"] }
2122
semver = "1.0.23"

crates/driver2/src/lib.rs

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ 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::{
@@ -27,6 +28,12 @@ use hir_analysis::{
2728
},
2829
HirAnalysisDb,
2930
};
31+
use resolver::{
32+
ingot::{
33+
config::ConfigResolver, dependencies::DependenciesResolver, src_files::SrcFilesResolver,
34+
},
35+
Resolver,
36+
};
3037

3138
use crate::diagnostics::ToCsDiag;
3239

@@ -91,6 +98,47 @@ impl DriverDataBase {
9198
DiagnosticsCollection(pass_manager.run_on_module_tree(tree))
9299
}
93100

101+
pub fn ingot(&mut self, ingot_path: &path::Path) -> InputIngot {
102+
let config_resolver = ConfigResolver;
103+
let dep_resolver = DependenciesResolver { config_resolver };
104+
let src_files_resolver = SrcFilesResolver;
105+
106+
let dep_graph = dep_resolver.resolve(ingot_path).unwrap();
107+
108+
let input_ingots = IndexMap::new();
109+
110+
for path in dep_graph.reverse_toposort() {
111+
let ingot_kind = if path == ingot_path {
112+
IngotKind::Local
113+
} else {
114+
IngotKind::External
115+
};
116+
let external_ingots =
117+
dep_graph
118+
.dependencies(&dep)
119+
.iter()
120+
.map(|(name, _, path)| IngotDependency {
121+
name,
122+
ingot: input_ingots[path],
123+
});
124+
input_ingot[ingot_path] =
125+
InputIngot::new(self, path, ingot_kind, version, external_ingots);
126+
}
127+
128+
for (ingot_path, input_ingot) in input_ingots {
129+
let files = src_files_resolver.resolve(&ingot_path);
130+
let input_files = files
131+
.into_iter()
132+
.map(|(path, content)| InputFile::new(self, input_ingot, file_path, content))
133+
.collect();
134+
input_ingot.set_files(db, input_files);
135+
// match lib.fe and main.fe
136+
// input_ingot.set_root_file(db, input_files[0]);
137+
}
138+
139+
input_ingots[ingot_path]
140+
}
141+
94142
pub fn standalone(&mut self, file_path: &path::Path, source: &str) -> InputFile {
95143
let kind = IngotKind::StandAlone;
96144

crates/resolver/src/files.rs

Lines changed: 0 additions & 38 deletions
This file was deleted.

crates/resolver/src/files/local.rs

Lines changed: 0 additions & 39 deletions
This file was deleted.

crates/resolver/src/ingot.rs

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,41 @@ use serde::Deserialize;
22
use smol_str::SmolStr;
33
use std::hash::Hash;
44

5-
use crate::files::AnyFilesDesc;
5+
use crate::{path::PathDescription, remote::GitDescription};
66

7-
mod config;
8-
mod dep_graph;
9-
mod src_files;
7+
pub mod config;
8+
pub mod dependencies;
9+
pub mod src_files;
1010

11-
#[derive(Deserialize, Hash, Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
12-
pub struct IngotDesc<FD>
13-
where
14-
FD: Hash,
15-
{
11+
#[derive(Deserialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
12+
pub struct IngotDescription<FD> {
1613
pub version: Option<SmolStr>,
14+
// pub fe_version: SmolStr,
15+
// pub features: Vec<SmolStr>,
1716
#[serde(flatten)]
18-
pub files_desc: FD,
17+
pub files_description: FD,
1918
}
2019

21-
pub type AnyIngotDesc = IngotDesc<AnyFilesDesc>;
20+
#[derive(Deserialize, PartialEq, Debug, Clone, Eq)]
21+
pub enum AnyIngotDescription {
22+
Path(IngotDescription<PathDescription>),
23+
Remote(IngotDescription<GitDescription>),
24+
Registered(IngotDescription<()>),
25+
}
26+
27+
// pub struct IngotPathResolver;
28+
29+
// pub enum IngotPathResolutionError {
30+
// RemotePathOutOfScope,
31+
// LocalPathDoesNotExist,
32+
// }
33+
34+
// impl Resolver for IngotPathResolver {
35+
// type ResourceDesc = Vec<AnyIngotDesc>;
36+
// type Resource = Utf8PathBuf;
37+
// type ResolutionError = IngotPathResolutionError;
38+
39+
// fn resolve(&self, desc: &Self::ResourceDesc) -> Result<Self::Resource, Self::ResolutionError> {
40+
// todo!()
41+
// }
42+
// }

crates/resolver/src/ingot/config.rs

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,48 @@
11
use camino::Utf8PathBuf;
2-
use serde::de::DeserializeOwned;
32
use serde::Deserialize;
43
use smol_str::SmolStr;
5-
use std::hash::Hash;
64
use std::{collections::HashMap, fs};
75
use toml;
86

97
use crate::Resolver;
108

11-
use super::IngotDesc;
9+
use super::AnyIngotDescription;
1210

13-
#[derive(Deserialize)]
14-
pub struct Config<FD>
15-
where
16-
FD: Hash,
17-
{
11+
#[derive(Deserialize, Debug, Clone, PartialEq, Eq)]
12+
pub struct Config {
1813
pub name: SmolStr,
1914
pub version: SmolStr,
20-
pub dependencies: HashMap<SmolStr, IngotDesc<FD>>,
15+
pub dependencies: HashMap<SmolStr, AnyIngotDescription>,
16+
}
17+
18+
pub enum InvalidConfigError {
19+
MissingVersion,
20+
MissingName,
21+
UnrecognizedField(String),
2122
}
2223

2324
#[derive(Debug)]
2425
pub enum ConfigResolutionError {
25-
FileNotFound,
26+
ConfigNotFound,
2627
FileReadError(std::io::Error),
2728
TomlParseError(toml::de::Error),
2829
InvalidConfig(String),
2930
}
3031

31-
pub struct ConfigResolver<FR> {
32-
files_resolver: FR,
33-
}
32+
pub struct ConfigResolver;
3433

35-
impl<FR> Resolver for ConfigResolver<FR>
36-
where
37-
FR: Resolver,
38-
FR::ResourceDesc: Hash,
39-
FR::Resource: AsRef<Utf8PathBuf>,
40-
Config<FR::ResourceDesc>: DeserializeOwned,
41-
{
42-
type Config = ();
43-
type ResourceDesc = IngotDesc<FR::ResourceDesc>;
44-
type Resource = Config<FR::ResourceDesc>;
34+
impl Resolver for ConfigResolver {
35+
type Description = Utf8PathBuf;
36+
type Resource = Config;
4537
type ResolutionError = ConfigResolutionError;
4638

47-
fn from_config(_config: &Self::Config) -> Self {
48-
todo!()
49-
}
50-
51-
fn resolve(
52-
&self,
53-
desc: &IngotDesc<FR::ResourceDesc>,
54-
) -> Result<Config<FR::ResourceDesc>, ConfigResolutionError> {
55-
let config_path = self
56-
.files_resolver
57-
.resolve(&desc.files_desc)
58-
.map_err(|_| ConfigResolutionError::FileNotFound)?
59-
.as_ref()
60-
.join("fe.toml");
39+
fn resolve(&self, desc: &Utf8PathBuf) -> Result<Config, ConfigResolutionError> {
40+
let config_path = desc.join("fe.toml");
6141

6242
let file_content =
6343
fs::read_to_string(&config_path).map_err(ConfigResolutionError::FileReadError)?;
6444

65-
let config: Config<FR::ResourceDesc> =
45+
let config: Config =
6646
toml::from_str(&file_content).map_err(ConfigResolutionError::TomlParseError)?;
6747

6848
if config.name.is_empty() {

0 commit comments

Comments
 (0)