Skip to content

Commit

Permalink
feat: display progress
Browse files Browse the repository at this point in the history
  • Loading branch information
mtshiba committed Sep 9, 2024
1 parent 60ea11a commit 948a14b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
1 change: 1 addition & 0 deletions crates/erg_common/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ pub struct ErgConfig {
/// verbosity level for system messages.
/// * 0: display errors, warns
/// * 1 (default): display errors, warnings and hints
/// * 2: display errors, warnings, hints and progress
pub verbose: u8,
/// needed for `jupyter-erg`
pub ps1: &'static str,
Expand Down
28 changes: 27 additions & 1 deletion crates/erg_compiler/build_package.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::ffi::OsStr;
use std::fmt;
use std::fs::{metadata, remove_file, File};
use std::io::{BufRead, BufReader};
use std::io::{stdout, BufRead, BufReader, Write};
use std::marker::PhantomData;
use std::option::Option;
use std::path::Path;
Expand Down Expand Up @@ -829,10 +829,33 @@ impl<ASTBuilder: ASTBuildable, HIRBuilder: Buildable>

fn build_deps_and_module(&mut self, path: &NormalizedPathBuf, graph: &mut ModuleGraph) {
let mut ancestors = graph.ancestors(path).into_vec();
let nmods = ancestors.len();
let pad = nmods.to_string().len();
let print_progress =
nmods > 0 && !self.cfg.mode.is_language_server() && self.cfg.verbose >= 2;
if print_progress && !self.inlines.contains_key(path) {
let mut out = stdout().lock();
write!(out, "Checking 0/{nmods}").unwrap();
out.flush().unwrap();
}
while let Some(ancestor) = ancestors.pop() {
if graph.ancestors(&ancestor).is_empty() {
graph.remove(&ancestor);
if let Some(entry) = self.asts.remove(&ancestor) {
if print_progress {
let name = ancestor.file_name().unwrap_or_default().to_string_lossy();
let checked = nmods - ancestors.len();
let percentage = (checked as f64 / nmods as f64) * 100.0;
let spaces = " ".repeat(((100.0 - percentage) / 5.0) as usize);
let eqs = "=".repeat((percentage / 5.0) as usize);
let mut out = stdout().lock();
write!(
out,
"\rChecking [{eqs}{spaces}] {checked:>pad$}/{nmods}: {name:<30}"
)
.unwrap();
out.flush().unwrap();
}
self.start_analysis_process(entry.ast, entry.name, ancestor);
} else {
self.build_inlined_module(&ancestor, graph);
Expand All @@ -841,6 +864,9 @@ impl<ASTBuilder: ASTBuildable, HIRBuilder: Buildable>
ancestors.insert(0, ancestor);
}
}
if print_progress {
println!();
}
}

fn build_inlined_module(&mut self, path: &NormalizedPathBuf, graph: &mut ModuleGraph) {
Expand Down
12 changes: 11 additions & 1 deletion crates/erg_compiler/lib/pystd/collections.d/__init__.d.er
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,20 @@
.NamedTuple = 'namedtuple': ClassType
.NamedTuple.
__call__: (typename: Str, field_names: Sequence(Str), rename := Bool) -> (*Obj, **Obj) -> NamedTuple
.Deque = 'deque': ClassType
.Deque! = 'deque': ClassType
.Deque!.
__call__: (iterable := Iterable(Obj)) -> Deque!
.ChainMap: ClassType
.ChainMap.
maps: [Mapping; _]
__call__: (*maps: Mapping(Obj, Obj)) -> ChainMap
new_child: (m := Mapping(Obj, Obj), **kwargs: Obj) -> ChainMap
.Counter: ClassType
.Counter.
__call__: (iterable_or_mapping := Iterable(Obj) or Mapping(Obj, Obj), **kwargs: Obj) -> Counter
.OrderedDict: ClassType
.OrderedDict.
__call__: (mapping: Mapping(Obj, Obj)) -> OrderedDict
.Defaultdict = 'defaultDict': ClassType
.UserDict: ClassType
.UserList: ClassType
Expand Down
2 changes: 2 additions & 0 deletions crates/erg_compiler/module/promise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,15 @@ impl SharedPromises {
self.promises.borrow().get(path).is_some()
}

/// If the path is not registered, return `false`.
pub fn is_joined(&self, path: &NormalizedPathBuf) -> bool {
self.promises
.borrow()
.get(path)
.is_some_and(|promise| promise.is_joined())
}

/// If the path is not registered, return `false`.
pub fn is_finished(&self, path: &NormalizedPathBuf) -> bool {
self.promises
.borrow()
Expand Down

0 comments on commit 948a14b

Please sign in to comment.