Skip to content

Commit a2d0401

Browse files
committed
Pass file to checker
1 parent 22f2d87 commit a2d0401

File tree

6 files changed

+18
-8
lines changed

6 files changed

+18
-8
lines changed

benchmark/benches/typecheck_benchmark.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ pub fn benchmark_type_checker(c: &mut Criterion) {
3333
let builder = BuildManager::new(Settings::test_settings());
3434
let file_path = PathBuf::from(path);
3535
builder.build_one(&PathBuf::from("../../"), &file_path);
36-
builder.type_check(&file_path);
36+
let file = builder.get_state(&file_path);
37+
builder.type_check(&file_path, &file);
3738

3839
0
3940
});

enderpy/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ fn check(path: &Path) -> Result<()> {
126126
let build_manager = BuildManager::new(settings);
127127
build_manager.build(root);
128128
build_manager.build_one(root, path);
129-
build_manager.type_check(path);
129+
let file = build_manager.get_state(path);
130+
build_manager.type_check(path, &file);
130131

131132
if build_manager.diagnostics.is_empty() {
132133
println!("zero errors");

lsp/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ impl<'a> Backend {
1515
fn build(&self, path: PathBuf) {
1616
let root = find_project_root(&path);
1717
self.manager.build_one(root, &path);
18-
self.manager.type_check(&path);
18+
let file = self.manager.get_state(&path);
19+
self.manager.type_check(&path, &file);
1920
}
2021
}
2122

typechecker/src/build.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,13 @@ impl<'a> BuildManager {
104104

105105
// Performs type checking passes over the code
106106
// This step happens after the binding phase
107-
pub fn type_check(&self, path: &Path) -> TypeChecker {
107+
pub fn type_check(&'a self, path: &Path, file: &'a EnderpyFile) -> TypeChecker<'a> {
108108
let mut module_to_check = self.get_state(path);
109109

110110
let span = span!(Level::TRACE, "type check", path = %path.display());
111111
let _guard = span.enter();
112112
let mut checker = TypeChecker::new(
113+
file,
113114
self.get_symbol_table(path),
114115
&self.symbol_tables,
115116
&self.module_ids,
@@ -132,7 +133,7 @@ impl<'a> BuildManager {
132133

133134
pub fn get_hover_information(&self, path: &Path, line: u32, column: u32) -> String {
134135
let module = self.get_state(path);
135-
let checker = self.type_check(path);
136+
let checker = self.type_check(path, &module);
136137
let symbol_table = self.get_symbol_table(path);
137138
let hovered_offset = module.line_starts[line as usize] + column;
138139

typechecker/src/checker.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use enderpy_python_parser as parser;
77
use enderpy_python_parser::ast::{self, *};
88

99
use super::{type_evaluator::TypeEvaluator, types::PythonType};
10+
use crate::file::EnderpyFile;
1011
use crate::symbol_table::Id;
1112
use crate::types::ModuleRef;
1213
use crate::{ast_visitor::TraversalVisitor, diagnostic::CharacterSpan, symbol_table::SymbolTable};
@@ -28,13 +29,14 @@ pub struct TypeCheckError {
2829
#[allow(unused)]
2930
impl<'a> TypeChecker<'a> {
3031
pub fn new(
32+
file: &'a EnderpyFile,
3133
symbol_table: SymbolTable,
3234
symbol_tables: &'a DashMap<Id, SymbolTable>,
3335
ids: &'a DashMap<PathBuf, Id>,
3436
) -> Self {
3537
TypeChecker {
3638
errors: vec![],
37-
type_evaluator: TypeEvaluator::new(symbol_table, symbol_tables, ids),
39+
type_evaluator: TypeEvaluator::new(file, symbol_table, symbol_tables, ids),
3840
types: Lapper::new(vec![]),
3941
}
4042
}
@@ -629,7 +631,8 @@ mod tests {
629631
let root = &PathBuf::from("");
630632
manager.build(root);
631633
manager.build_one(root, &path);
632-
let checker = manager.type_check(&path);
634+
let module = manager.get_state(&path);
635+
let checker = manager.type_check(&path, &module);
633636
let module = manager.get_state(&path);
634637

635638
let result = checker.types;

typechecker/src/type_evaluator.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ use super::{
2323
},
2424
};
2525
use crate::{
26+
file::EnderpyFile,
2627
semantic_analyzer::get_member_access_info,
2728
symbol_table::{
2829
self, Class, Declaration, Id, LookupSymbolRequest, SymbolTable, SymbolTableNode,
29-
TypeParameter,
3030
},
3131
types::CallableArgs,
3232
};
@@ -40,6 +40,7 @@ const SPECIAL_FORM: &str = "_SpecialForm";
4040
#[derive(Clone, Debug)]
4141
pub struct TypeEvaluator<'a> {
4242
// TODO: make this a reference to the symbol table in the checker
43+
pub file: &'a EnderpyFile,
4344
pub symbol_table: SymbolTable,
4445
pub imported_symbol_tables: &'a DashMap<Id, SymbolTable>,
4546
pub ids: &'a DashMap<PathBuf, Id>,
@@ -68,12 +69,14 @@ bitflags::bitflags! {
6869
/// Struct for evaluating the type of an expression
6970
impl<'a> TypeEvaluator<'a> {
7071
pub fn new(
72+
file: &'a EnderpyFile,
7173
symbol_table: SymbolTable,
7274
imported_symbol_tables: &'a DashMap<Id, SymbolTable>,
7375
ids: &'a DashMap<PathBuf, Id>,
7476
) -> Self {
7577
TypeEvaluator {
7678
symbol_table,
79+
file,
7780
imported_symbol_tables,
7881
ids,
7982
flags: Cell::new(GetTypeFlags::empty()),

0 commit comments

Comments
 (0)