Skip to content

Commit

Permalink
fix: add debug assertions to PackageBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
mtshiba committed Sep 18, 2024
1 parent ed6ad90 commit d508db7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
8 changes: 6 additions & 2 deletions crates/els/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{mpsc, Arc};
use std::time::Duration;

use erg_common::config::ErgConfig;
use erg_common::config::{ErgConfig, ErgMode};
use erg_common::consts::PYTHON_MODE;
use erg_common::dict::Dict;
use erg_common::env::erg_path;
Expand Down Expand Up @@ -213,7 +213,11 @@ impl Server {
#[allow(unused)]
pub fn bind_fake_client() -> FakeClient<Server> {
let (sender, receiver) = std::sync::mpsc::channel();
FakeClient::new(Server::new(ErgConfig::default(), Some(sender)), receiver)
let cfg = ErgConfig {
mode: ErgMode::LanguageServer,
..Default::default()
};
FakeClient::new(Server::new(cfg, Some(sender)), receiver)
}
}

Expand Down
18 changes: 17 additions & 1 deletion crates/erg_compiler/build_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,14 @@ impl<ASTBuilder: ASTBuildable, HIRBuilder: Buildable>
let deps = self.build_deps_and_module(&path, &mut graph);
log!(info "All dependencies have started to analyze");
debug_power_assert!(self.asts.len(), ==, 0);
if self.cfg.mode != ErgMode::LanguageServer {
for path in self.shared.graph.ancestors(&path) {
assert!(
self.shared.promises.is_registered(&path),
"{path} is not registered"
);
}
}
self.finalize();
match self.main_builder.build_from_ast(ast, mode) {
Ok(artifact) => Ok(CompleteArtifact::new(
Expand Down Expand Up @@ -895,6 +903,7 @@ impl<ASTBuilder: ASTBuildable, HIRBuilder: Buildable>
self.shared.promises.wait_until_finished(path);
} else if let Some(inliner) = self.inlines.get(path).cloned() {
self.build_deps_and_module(&inliner, graph);
self.shared.promises.mark_as_joined(path.clone());
} else {
unreachable!("{path} is not found in self.inlines and self.asts");
}
Expand Down Expand Up @@ -998,10 +1007,17 @@ impl<ASTBuilder: ASTBuildable, HIRBuilder: Buildable>
}
Err(artifact) => {
let ctx = builder.pop_context().unwrap();
py_mod_cache.register(path, raw_ast, artifact.object, ctx, CheckStatus::Failed);
py_mod_cache.register(
path.clone(),
raw_ast,
artifact.object,
ctx,
CheckStatus::Failed,
);
self.shared.warns.extend(artifact.warns);
self.shared.errors.extend(artifact.errors);
}
}
self.shared.promises.mark_as_joined(path);
}
}

0 comments on commit d508db7

Please sign in to comment.