@@ -263,7 +263,8 @@ use self::symbol_state::{
263263 LiveBindingsIterator , LiveDeclaration , LiveDeclarationsIterator , ScopedDefinitionId ,
264264 SymbolBindings , SymbolDeclarations , SymbolState ,
265265} ;
266- use crate :: semantic_index:: ast_ids:: { ScopedExpressionId , ScopedUseId } ;
266+ use crate :: node_key:: NodeKey ;
267+ use crate :: semantic_index:: ast_ids:: ScopedUseId ;
267268use crate :: semantic_index:: definition:: Definition ;
268269use crate :: semantic_index:: narrowing_constraints:: {
269270 NarrowingConstraints , NarrowingConstraintsBuilder , NarrowingConstraintsIterator ,
@@ -297,8 +298,8 @@ pub(crate) struct UseDefMap<'db> {
297298 /// [`SymbolBindings`] reaching a [`ScopedUseId`].
298299 bindings_by_use : IndexVec < ScopedUseId , SymbolBindings > ,
299300
300- /// Tracks whether or not a given expression is reachable from the start of the scope.
301- expression_reachability : FxHashMap < ScopedExpressionId , ScopedVisibilityConstraintId > ,
301+ /// Tracks whether or not a given AST node is reachable from the start of the scope.
302+ node_reachability : FxHashMap < NodeKey , ScopedVisibilityConstraintId > ,
302303
303304 /// If the definition is a binding (only) -- `x = 1` for example -- then we need
304305 /// [`SymbolDeclarations`] to know whether this binding is permitted by the live declarations.
@@ -361,23 +362,19 @@ impl<'db> UseDefMap<'db> {
361362
362363 /// Check whether or not a given expression is reachable from the start of the scope. This
363364 /// is a local analysis which does not capture the possibility that the entire scope might
364- /// be unreachable. Use [`super::SemanticIndex::is_expression_reachable `] for the global
365+ /// be unreachable. Use [`super::SemanticIndex::is_node_reachable `] for the global
365366 /// analysis.
366367 #[ track_caller]
367- pub ( super ) fn is_expression_reachable (
368- & self ,
369- db : & dyn crate :: Db ,
370- expression_id : ScopedExpressionId ,
371- ) -> bool {
368+ pub ( super ) fn is_node_reachable ( & self , db : & dyn crate :: Db , node_key : NodeKey ) -> bool {
372369 !self
373370 . visibility_constraints
374371 . evaluate (
375372 db,
376373 & self . predicates ,
377374 * self
378- . expression_reachability
379- . get ( & expression_id )
380- . expect ( "`is_expression_reachable ` should only be called on expressions with recorded reachability" ) ,
375+ . node_reachability
376+ . get ( & node_key )
377+ . expect ( "`is_node_reachable ` should only be called on AST nodes with recorded reachability" ) ,
381378 )
382379 . is_always_false ( )
383380 }
@@ -636,8 +633,8 @@ pub(super) struct UseDefMapBuilder<'db> {
636633 /// The use of `x` is recorded with a reachability constraint of `[test]`.
637634 pub ( super ) reachability : ScopedVisibilityConstraintId ,
638635
639- /// Tracks whether or not a given expression is reachable from the start of the scope.
640- expression_reachability : FxHashMap < ScopedExpressionId , ScopedVisibilityConstraintId > ,
636+ /// Tracks whether or not a given AST node is reachable from the start of the scope.
637+ node_reachability : FxHashMap < NodeKey , ScopedVisibilityConstraintId > ,
641638
642639 /// Live declarations for each so-far-recorded binding.
643640 declarations_by_binding : FxHashMap < Definition < ' db > , SymbolDeclarations > ,
@@ -663,7 +660,7 @@ impl Default for UseDefMapBuilder<'_> {
663660 scope_start_visibility : ScopedVisibilityConstraintId :: ALWAYS_TRUE ,
664661 bindings_by_use : IndexVec :: new ( ) ,
665662 reachability : ScopedVisibilityConstraintId :: ALWAYS_TRUE ,
666- expression_reachability : FxHashMap :: default ( ) ,
663+ node_reachability : FxHashMap :: default ( ) ,
667664 declarations_by_binding : FxHashMap :: default ( ) ,
668665 bindings_by_declaration : FxHashMap :: default ( ) ,
669666 symbol_states : IndexVec :: new ( ) ,
@@ -822,7 +819,7 @@ impl<'db> UseDefMapBuilder<'db> {
822819 & mut self ,
823820 symbol : ScopedSymbolId ,
824821 use_id : ScopedUseId ,
825- expression_id : ScopedExpressionId ,
822+ node_key : NodeKey ,
826823 ) {
827824 // We have a use of a symbol; clone the current bindings for that symbol, and record them
828825 // as the live bindings for this use.
@@ -833,12 +830,11 @@ impl<'db> UseDefMapBuilder<'db> {
833830
834831 // Track reachability of all uses of symbols to silence `unresolved-reference`
835832 // diagnostics in unreachable code.
836- self . record_expression_reachability ( expression_id ) ;
833+ self . record_node_reachability ( node_key ) ;
837834 }
838835
839- pub ( super ) fn record_expression_reachability ( & mut self , expression_id : ScopedExpressionId ) {
840- self . expression_reachability
841- . insert ( expression_id, self . reachability ) ;
836+ pub ( super ) fn record_node_reachability ( & mut self , node_key : NodeKey ) {
837+ self . node_reachability . insert ( node_key, self . reachability ) ;
842838 }
843839
844840 pub ( super ) fn snapshot_eager_bindings (
@@ -935,7 +931,7 @@ impl<'db> UseDefMapBuilder<'db> {
935931 self . all_definitions . shrink_to_fit ( ) ;
936932 self . symbol_states . shrink_to_fit ( ) ;
937933 self . bindings_by_use . shrink_to_fit ( ) ;
938- self . expression_reachability . shrink_to_fit ( ) ;
934+ self . node_reachability . shrink_to_fit ( ) ;
939935 self . declarations_by_binding . shrink_to_fit ( ) ;
940936 self . bindings_by_declaration . shrink_to_fit ( ) ;
941937 self . eager_bindings . shrink_to_fit ( ) ;
@@ -946,7 +942,7 @@ impl<'db> UseDefMapBuilder<'db> {
946942 narrowing_constraints : self . narrowing_constraints . build ( ) ,
947943 visibility_constraints : self . visibility_constraints . build ( ) ,
948944 bindings_by_use : self . bindings_by_use ,
949- expression_reachability : self . expression_reachability ,
945+ node_reachability : self . node_reachability ,
950946 public_symbols : self . symbol_states ,
951947 declarations_by_binding : self . declarations_by_binding ,
952948 bindings_by_declaration : self . bindings_by_declaration ,
0 commit comments