Track unresolved references in the semantic model (#5902)

## Summary

As part of my continued quest to separate semantic model-building from
diagnostic emission, this PR moves our unresolved-reference rules to a
deferred pass. So, rather than emitting diagnostics as we encounter
unresolved references, we now track those unresolved references on the
semantic model (just like resolved references), and after traversal,
emit the relevant rules for any unresolved references.
This commit is contained in:
Charlie Marsh 2023-07-19 18:19:55 -04:00 committed by GitHub
parent 23cde4d1f5
commit 963f240e46
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 261 additions and 202 deletions

View file

@ -10,7 +10,7 @@ use ruff_python_ast::source_code::Locator;
use crate::context::ExecutionContext;
use crate::model::SemanticModel;
use crate::node::NodeId;
use crate::reference::ReferenceId;
use crate::reference::ResolvedReferenceId;
use crate::ScopeId;
#[derive(Debug, Clone)]
@ -24,7 +24,7 @@ pub struct Binding<'a> {
/// The statement in which the [`Binding`] was defined.
pub source: Option<NodeId>,
/// The references to the [`Binding`].
pub references: Vec<ReferenceId>,
pub references: Vec<ResolvedReferenceId>,
/// The exceptions that were handled when the [`Binding`] was defined.
pub exceptions: Exceptions,
/// Flags for the [`Binding`].
@ -38,7 +38,7 @@ impl<'a> Binding<'a> {
}
/// Returns an iterator over all references for the current [`Binding`].
pub fn references(&self) -> impl Iterator<Item = ReferenceId> + '_ {
pub fn references(&self) -> impl Iterator<Item = ResolvedReferenceId> + '_ {
self.references.iter().copied()
}