Skip to content

Commit 048e43b

Browse files
author
Grant Wuerker
committed
library2
1 parent 4a18de0 commit 048e43b

File tree

21 files changed

+1267
-5
lines changed

21 files changed

+1267
-5
lines changed

Diff for: Cargo.lock

+9
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

+1-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

Diff for: crates/driver2/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ 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" }

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

+22-3
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

@@ -142,7 +161,7 @@ impl Default for DriverDataBase {
142161
}
143162
}
144163

145-
fn initialize_analysis_pass(db: &DriverDataBase) -> AnalysisPassManager<'_> {
164+
pub fn initialize_analysis_pass(db: &DriverDataBase) -> AnalysisPassManager<'_> {
146165
let mut pass_manager = AnalysisPassManager::new();
147166
pass_manager.add_module_pass(Box::new(ParsingPass::new(db)));
148167
pass_manager.add_module_pass(Box::new(DefConflictAnalysisPass::new(db)));

Diff for: crates/driver2/tests/std_lib.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use fe_driver2::DriverDataBase;
2+
3+
#[test]
4+
fn check_std_lib() {
5+
let mut driver = DriverDataBase::default();
6+
let std_ingot = library2::std_lib_input_ingot(&mut driver);
7+
driver.run_on_ingot(std_ingot);
8+
9+
let diags = driver.format_diags();
10+
if !diags.is_empty() {
11+
panic!("{diags}")
12+
}
13+
}

Diff for: crates/hir/src/analysis_pass.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use crate::{diagnostics::DiagnosticVoucher, hir_def::TopLevelMod};
1+
use crate::{
2+
diagnostics::DiagnosticVoucher,
3+
hir_def::{ModuleTree, TopLevelMod},
4+
};
25

36
/// All analysis passes that run analysis on the HIR top level module
47
/// granularity should implement this trait.
@@ -27,4 +30,14 @@ impl<'db> AnalysisPassManager<'db> {
2730
}
2831
diags
2932
}
33+
34+
pub fn run_on_module_tree(&mut self, tree: &ModuleTree) -> Vec<Box<dyn DiagnosticVoucher>> {
35+
let mut diags = vec![];
36+
for module in tree.all_modules() {
37+
for pass in self.module_passes.iter_mut() {
38+
diags.extend(pass.run_on_module(module));
39+
}
40+
}
41+
diags
42+
}
3043
}

Diff for: crates/library2/Cargo.toml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "fe-library2"
3+
version = "0.23.0"
4+
authors = ["The Fe Developers <[email protected]>"]
5+
edition = "2021"
6+
license = "Apache-2.0"
7+
repository = "https://github.com/ethereum/fe"
8+
9+
[dependencies]
10+
include_dir = "0.7.2"
11+
common = { path = "../common2", package = "fe-common2" }

Diff for: crates/library2/build.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!("cargo:rerun-if-changed=./std");
3+
}

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

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
use std::collections::BTreeSet;
2+
3+
pub use ::include_dir;
4+
use common::{
5+
input::{IngotKind, Version},
6+
InputDb, InputFile, InputIngot,
7+
};
8+
use include_dir::{include_dir, Dir};
9+
10+
pub const STD: Dir = include_dir!("$CARGO_MANIFEST_DIR/std");
11+
12+
fn std_src_input_files(db: &mut dyn InputDb, ingot: InputIngot) -> BTreeSet<InputFile> {
13+
static_dir_files(&STD)
14+
.into_iter()
15+
.map(|(path, content)| InputFile::new(db, ingot, path.into(), content.into()))
16+
.collect()
17+
}
18+
19+
pub fn std_lib_input_ingot(db: &mut dyn InputDb) -> InputIngot {
20+
let ingot = InputIngot::new(
21+
db,
22+
"/",
23+
IngotKind::Std,
24+
Version::new(0, 0, 0),
25+
BTreeSet::default(),
26+
);
27+
28+
let input_files = std_src_input_files(db, ingot);
29+
let root_file = input_files
30+
.iter()
31+
.find(|file| file.path(db).ends_with("lib.fe"))
32+
.unwrap()
33+
.to_owned();
34+
35+
ingot.set_root_file(db, root_file);
36+
ingot.set_files(db, input_files);
37+
38+
ingot
39+
}
40+
41+
pub fn static_dir_files(dir: &'static Dir) -> Vec<(&'static str, &'static str)> {
42+
fn add_files(dir: &'static Dir, accum: &mut Vec<(&'static str, &'static str)>) {
43+
accum.extend(dir.files().map(|file| {
44+
(
45+
file.path().to_str().unwrap(),
46+
file.contents_utf8().expect("non-utf8 static file"),
47+
)
48+
}));
49+
50+
for sub_dir in dir.dirs() {
51+
add_files(sub_dir, accum)
52+
}
53+
}
54+
55+
let mut files = vec![];
56+
add_files(dir, &mut files);
57+
files
58+
}

Diff for: crates/library2/std/src/lib.fe

Whitespace-only changes.

Diff for: crates/library2/std/src/num.fe

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub type isize = i256
2+
pub type usize = u256

Diff for: crates/library2/std/src/num/int/extend.fe

+156
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
extern {
2+
fn __u8_u16_extend(_ x: u8) -> u16
3+
fn __u8_u32_extend(_ x: u8) -> u32
4+
fn __u8_u64_extend(_ x: u8) -> u64
5+
fn __u8_u128_extend(_ x: u8) -> u128
6+
fn __u8_u256_extend(_ x: u8) -> u256
7+
fn __u16_u32_extend(_ x: u16) -> u32
8+
fn __u16_u64_extend(_ x: u16) -> u64
9+
fn __u16_u128_extend(_ x: u16) -> u128
10+
fn __u16_u256_extend(_ x: u16) -> u256
11+
fn __u32_u64_extend(_ x: u32) -> u64
12+
fn __u32_u128_extend(_ x: u32) -> u128
13+
fn __u32_u256_extend(_ x: u32) -> u256
14+
fn __u64_u128_extend(_ x: u64) -> u128
15+
fn __u64_u256_extend(_ x: u64) -> u256
16+
fn __u128_u256_extend(_ x: u128) -> u256
17+
fn __i8_i16_extend(_ x: i8) -> i16
18+
fn __i8_i32_extend(_ x: i8) -> i32
19+
fn __i8_i64_extend(_ x: i8) -> i64
20+
fn __i8_i128_extend(_ x: i8) -> i128
21+
fn __i8_i256_extend(_ x: i8) -> i256
22+
fn __i16_i32_extend(_ x: i16) -> i32
23+
fn __i16_i64_extend(_ x: i16) -> i64
24+
fn __i16_i128_extend(_ x: i16) -> i128
25+
fn __i16_i256_extend(_ x: i16) -> i256
26+
fn __i32_i64_extend(_ x: i32) -> i64
27+
fn __i32_i128_extend(_ x: i32) -> i128
28+
fn __i32_i256_extend(_ x: i32) -> i256
29+
fn __i64_i128_extend(_ x: i64) -> i128
30+
fn __i64_i256_extend(_ x: i64) -> i256
31+
fn __i128_i256_extend(_ x: i128) -> i256
32+
}
33+
34+
pub trait Extend<Out> {
35+
fn extend(self) -> Out
36+
}
37+
38+
impl Extend<u16> for u8 {
39+
fn extend(self) -> u16 { __u8_u16_extend(self) }
40+
}
41+
42+
impl Extend<u32> for u8 {
43+
fn extend(self) -> u32 { __u8_u32_extend(self) }
44+
}
45+
46+
impl Extend<u64> for u8 {
47+
fn extend(self) -> u64 { __u8_u64_extend(self) }
48+
}
49+
50+
impl Extend<u128> for u8 {
51+
fn extend(self) -> u128 { __u8_u128_extend(self) }
52+
}
53+
54+
impl Extend<u256> for u8 {
55+
fn extend(self) -> u256 { __u8_u256_extend(self) }
56+
}
57+
58+
impl Extend<u32> for u16 {
59+
fn extend(self) -> u32 { __u16_u32_extend(self) }
60+
}
61+
62+
impl Extend<u64> for u16 {
63+
fn extend(self) -> u64 { __u16_u64_extend(self) }
64+
}
65+
66+
impl Extend<u128> for u16 {
67+
fn extend(self) -> u128 { __u16_u128_extend(self) }
68+
}
69+
70+
impl Extend<u256> for u16 {
71+
fn extend(self) -> u256 { __u16_u256_extend(self) }
72+
}
73+
74+
impl Extend<u64> for u32 {
75+
fn extend(self) -> u64 { __u32_u64_extend(self) }
76+
}
77+
78+
impl Extend<u128> for u32 {
79+
fn extend(self) -> u128 { __u32_u128_extend(self) }
80+
}
81+
82+
impl Extend<u256> for u32 {
83+
fn extend(self) -> u256 { __u32_u256_extend(self) }
84+
}
85+
86+
impl Extend<u128> for u64 {
87+
fn extend(self) -> u128 { __u64_u128_extend(self) }
88+
}
89+
90+
impl Extend<u256> for u64 {
91+
fn extend(self) -> u256 { __u64_u256_extend(self) }
92+
}
93+
94+
impl Extend<u256> for u128 {
95+
fn extend(self) -> u256 { __u128_u256_extend(self) }
96+
}
97+
98+
impl Extend<i16> for i8 {
99+
fn extend(self) -> i16 { __i8_i16_extend(self) }
100+
}
101+
102+
impl Extend<i32> for i8 {
103+
fn extend(self) -> i32 { __i8_i32_extend(self) }
104+
}
105+
106+
impl Extend<i64> for i8 {
107+
fn extend(self) -> i64 { __i8_i64_extend(self) }
108+
}
109+
110+
impl Extend<i128> for i8 {
111+
fn extend(self) -> i128 { __i8_i128_extend(self) }
112+
}
113+
114+
impl Extend<i256> for i8 {
115+
fn extend(self) -> i256 { __i8_i256_extend(self) }
116+
}
117+
118+
impl Extend<i32> for i16 {
119+
fn extend(self) -> i32 { __i16_i32_extend(self) }
120+
}
121+
122+
impl Extend<i64> for i16 {
123+
fn extend(self) -> i64 { __i16_i64_extend(self) }
124+
}
125+
126+
impl Extend<i128> for i16 {
127+
fn extend(self) -> i128 { __i16_i128_extend(self) }
128+
}
129+
130+
impl Extend<i256> for i16 {
131+
fn extend(self) -> i256 { __i16_i256_extend(self) }
132+
}
133+
134+
impl Extend<i64> for i32 {
135+
fn extend(self) -> i64 { __i32_i64_extend(self) }
136+
}
137+
138+
impl Extend<i128> for i32 {
139+
fn extend(self) -> i128 { __i32_i128_extend(self) }
140+
}
141+
142+
impl Extend<i256> for i32 {
143+
fn extend(self) -> i256 { __i32_i256_extend(self) }
144+
}
145+
146+
impl Extend<i128> for i64 {
147+
fn extend(self) -> i128 { __i64_i128_extend(self) }
148+
}
149+
150+
impl Extend<i256> for i64 {
151+
fn extend(self) -> i256 { __i64_i256_extend(self) }
152+
}
153+
154+
impl Extend<i256> for i128 {
155+
fn extend(self) -> i256 { __i128_i256_extend(self) }
156+
}

Diff for: crates/library2/std/src/num/int/ops.fe

Whitespace-only changes.

0 commit comments

Comments
 (0)