mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-22 19:34:23 +00:00
[ty] Reduce size of TypeInference
(#19435)
This commit is contained in:
parent
af62d0368f
commit
5e29278aa2
8 changed files with 678 additions and 164 deletions
|
@ -104,7 +104,10 @@ pub fn check_types(db: &dyn Db, file: File) -> Vec<Diagnostic> {
|
|||
|
||||
for scope_id in index.scope_ids() {
|
||||
let result = infer_scope_types(db, scope_id);
|
||||
diagnostics.extend(result.diagnostics());
|
||||
|
||||
if let Some(scope_diagnostics) = result.diagnostics() {
|
||||
diagnostics.extend(scope_diagnostics);
|
||||
}
|
||||
}
|
||||
|
||||
diagnostics.extend_diagnostics(
|
||||
|
@ -116,7 +119,7 @@ pub fn check_types(db: &dyn Db, file: File) -> Vec<Diagnostic> {
|
|||
|
||||
check_suppressions(db, file, &mut diagnostics);
|
||||
|
||||
diagnostics.into_vec()
|
||||
diagnostics.into_diagnostics()
|
||||
}
|
||||
|
||||
/// Infer the type of a binding.
|
||||
|
|
|
@ -32,7 +32,7 @@ use crate::{
|
|||
/// ## Consuming
|
||||
/// It's important that the context is explicitly consumed before dropping by calling
|
||||
/// [`InferContext::finish`] and the returned diagnostics must be stored
|
||||
/// on the current [`TypeInference`](super::infer::TypeInference) result.
|
||||
/// on the current [`TypeInferenceBuilder`](super::infer::TypeInferenceBuilder) result.
|
||||
pub(crate) struct InferContext<'db, 'ast> {
|
||||
db: &'db dyn Db,
|
||||
scope: ScopeId<'db>,
|
||||
|
|
|
@ -1671,18 +1671,26 @@ impl TypeCheckDiagnostics {
|
|||
self.diagnostics.shrink_to_fit();
|
||||
}
|
||||
|
||||
pub(crate) fn into_vec(self) -> Vec<Diagnostic> {
|
||||
pub(crate) fn into_diagnostics(self) -> Vec<Diagnostic> {
|
||||
self.diagnostics
|
||||
}
|
||||
|
||||
pub(crate) fn is_empty(&self) -> bool {
|
||||
self.diagnostics.is_empty() && self.used_suppressions.is_empty()
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> std::slice::Iter<'_, Diagnostic> {
|
||||
self.diagnostics.iter()
|
||||
self.diagnostics().iter()
|
||||
}
|
||||
|
||||
fn diagnostics(&self) -> &[Diagnostic] {
|
||||
self.diagnostics.as_slice()
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for TypeCheckDiagnostics {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
self.diagnostics.fmt(f)
|
||||
self.diagnostics().fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1691,7 +1699,7 @@ impl IntoIterator for TypeCheckDiagnostics {
|
|||
type IntoIter = std::vec::IntoIter<Diagnostic>;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.diagnostics.into_iter()
|
||||
self.into_diagnostics().into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1699,8 +1707,9 @@ impl<'a> IntoIterator for &'a TypeCheckDiagnostics {
|
|||
type Item = &'a Diagnostic;
|
||||
type IntoIter = std::slice::Iter<'a, Diagnostic>;
|
||||
|
||||
#[inline]
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.diagnostics.iter()
|
||||
self.iter()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue