1
1
mirror of https://github.com/tweag/nickel.git synced 2024-10-05 15:47:33 +03:00

Linearize imports in dependents-first (#1488)

Fixes #1480
This commit is contained in:
jneem 2023-07-31 07:49:51 -05:00 committed by GitHub
parent 74f1a355d8
commit c4ac9c368a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 3 deletions

View File

@ -680,6 +680,11 @@ impl Cache {
/// component: this return value is currently used by the LSP to re-run code analysis on new
/// files/modified files.
///
/// The resolved imports are ordered by a pre-order depth-first-search. In
/// particular, earlier elements in the returned list might import later
/// elements but -- unless there are cyclic imports -- later elements do not
/// import earlier elements.
///
/// It only accumulates errors if the cache is in error tolerant mode, otherwise it returns an
/// `Err(..)` containing a `CacheError`.
#[allow(clippy::type_complexity)]
@ -705,7 +710,7 @@ impl Cache {
}
};
// unwrap!(): we called `unwrap()` at the beggining of the enclosing if branch
// unwrap!(): we called `unwrap()` at the beginning of the enclosing if branch
// on the result of `self.terms.get(&file_id)`. We only made recursive calls to
// `resolve_imports` in between, which don't remove anything from `self.terms`.
let cached_term = self.terms.get_mut(&file_id).unwrap();

View File

@ -35,7 +35,8 @@ impl CacheExt for Cache {
let mut typecheck_import_diagnostics: Vec<FileId> = Vec::new();
if let Ok(CacheOp::Done((ids, errors))) = self.resolve_imports(file_id) {
import_errors = errors;
for id in ids {
// Reverse the imports, so we try to typecheck the leaf dependencies first.
for &id in ids.iter().rev() {
let _ = self.typecheck_with_analysis(id, initial_ctxt, initial_env, lin_registry);
}
}

View File

@ -541,7 +541,7 @@ impl<'a> Linearizer for AnalysisHost<'a> {
wildcards,
}: Extra,
) -> Linearization<Completed> {
debug!("linearizing");
debug!("linearizing {:?}", self.file);
// TODO: Storing defers while linearizing?
let mut defers: Vec<(ItemId, ItemId, Ident)> = lin