@@ -293,19 +293,22 @@ pub(crate) struct UseDefMap<'db> {
293293 /// [`SymbolBindings`] reaching a [`ScopedUseId`].
294294 bindings_by_use : IndexVec < ScopedUseId , SymbolBindings > ,
295295
296- /// [`SymbolBindings`] or [`SymbolDeclarations`] reaching a given [`Definition`].
297- ///
298296 /// If the definition is a binding (only) -- `x = 1` for example -- then we need
299297 /// [`SymbolDeclarations`] to know whether this binding is permitted by the live declarations.
300298 ///
299+ /// If the definition is both a declaration and a binding -- `x: int = 1` for example -- then
300+ /// we don't actually need anything here, all we'll need to validate is that our own RHS is a
301+ /// valid assignment to our own annotation.
302+ declarations_by_binding : FxHashMap < Definition < ' db > , SymbolDeclarations > ,
303+
301304 /// If the definition is a declaration (only) -- `x: int` for example -- then we need
302305 /// [`SymbolBindings`] to know whether this declaration is consistent with the previously
303306 /// inferred type.
304307 ///
305308 /// If the definition is both a declaration and a binding -- `x: int = 1` for example -- then
306309 /// we don't actually need anything here, all we'll need to validate is that our own RHS is a
307310 /// valid assignment to our own annotation.
308- definitions_by_definition : FxHashMap < Definition < ' db > , SymbolDefinitions > ,
311+ bindings_by_declaration : FxHashMap < Definition < ' db > , SymbolBindings > ,
309312
310313 /// [`SymbolState`] visible at end of scope for each symbol.
311314 public_symbols : IndexVec < ScopedSymbolId , SymbolState > ,
@@ -343,25 +346,14 @@ impl<'db> UseDefMap<'db> {
343346 & self ,
344347 declaration : Definition < ' db > ,
345348 ) -> BindingWithConstraintsIterator < ' _ , ' db > {
346- if let SymbolDefinitions :: Bindings ( bindings) = & self . definitions_by_definition [ & declaration]
347- {
348- self . bindings_iterator ( bindings)
349- } else {
350- unreachable ! ( "Declaration has non-Bindings in definitions_by_definition" ) ;
351- }
349+ self . bindings_iterator ( & self . bindings_by_declaration [ & declaration] )
352350 }
353351
354- pub ( crate ) fn declarations_at_binding < ' map > (
355- & ' map self ,
352+ pub ( crate ) fn declarations_at_binding (
353+ & self ,
356354 binding : Definition < ' db > ,
357- ) -> DeclarationsIterator < ' map , ' db > {
358- if let SymbolDefinitions :: Declarations ( declarations) =
359- & self . definitions_by_definition [ & binding]
360- {
361- self . declarations_iterator ( declarations)
362- } else {
363- unreachable ! ( "Binding has non-Declarations in definitions_by_definition" ) ;
364- }
355+ ) -> DeclarationsIterator < ' _ , ' db > {
356+ self . declarations_iterator ( & self . declarations_by_binding [ & binding] )
365357 }
366358
367359 pub ( crate ) fn public_declarations < ' map > (
@@ -421,13 +413,6 @@ pub(crate) struct EagerBindingsKey {
421413/// A snapshot of bindings that can be used to resolve a reference in a nested eager scope.
422414type EagerBindings = IndexVec < ScopedEagerBindingsId , SymbolBindings > ;
423415
424- /// Either live bindings or live declarations for a symbol.
425- #[ derive( Debug , PartialEq , Eq , salsa:: Update ) ]
426- enum SymbolDefinitions {
427- Bindings ( SymbolBindings ) ,
428- Declarations ( SymbolDeclarations ) ,
429- }
430-
431416#[ derive( Debug ) ]
432417pub ( crate ) struct BindingWithConstraintsIterator < ' map , ' db > {
433418 all_definitions : & ' map IndexVec < ScopedDefinitionId , Option < Definition < ' db > > > ,
@@ -539,8 +524,11 @@ pub(super) struct UseDefMapBuilder<'db> {
539524 /// Live bindings at each so-far-recorded use.
540525 bindings_by_use : IndexVec < ScopedUseId , SymbolBindings > ,
541526
542- /// Live bindings or declarations for each so-far-recorded definition.
543- definitions_by_definition : FxHashMap < Definition < ' db > , SymbolDefinitions > ,
527+ /// Live declarations for each so-far-recorded binding.
528+ declarations_by_binding : FxHashMap < Definition < ' db > , SymbolDeclarations > ,
529+
530+ /// Live bindings for each so-far-recorded declaration.
531+ bindings_by_declaration : FxHashMap < Definition < ' db > , SymbolBindings > ,
544532
545533 /// Currently live bindings and declarations for each symbol.
546534 symbol_states : IndexVec < ScopedSymbolId , SymbolState > ,
@@ -558,7 +546,8 @@ impl Default for UseDefMapBuilder<'_> {
558546 visibility_constraints : VisibilityConstraintsBuilder :: default ( ) ,
559547 scope_start_visibility : ScopedVisibilityConstraintId :: ALWAYS_TRUE ,
560548 bindings_by_use : IndexVec :: new ( ) ,
561- definitions_by_definition : FxHashMap :: default ( ) ,
549+ declarations_by_binding : FxHashMap :: default ( ) ,
550+ bindings_by_declaration : FxHashMap :: default ( ) ,
562551 symbol_states : IndexVec :: new ( ) ,
563552 eager_bindings : EagerBindings :: default ( ) ,
564553 }
@@ -580,10 +569,8 @@ impl<'db> UseDefMapBuilder<'db> {
580569 pub ( super ) fn record_binding ( & mut self , symbol : ScopedSymbolId , binding : Definition < ' db > ) {
581570 let def_id = self . all_definitions . push ( Some ( binding) ) ;
582571 let symbol_state = & mut self . symbol_states [ symbol] ;
583- self . definitions_by_definition . insert (
584- binding,
585- SymbolDefinitions :: Declarations ( symbol_state. declarations ( ) . clone ( ) ) ,
586- ) ;
572+ self . declarations_by_binding
573+ . insert ( binding, symbol_state. declarations ( ) . clone ( ) ) ;
587574 symbol_state. record_binding ( def_id, self . scope_start_visibility ) ;
588575 }
589576
@@ -660,10 +647,8 @@ impl<'db> UseDefMapBuilder<'db> {
660647 ) {
661648 let def_id = self . all_definitions . push ( Some ( declaration) ) ;
662649 let symbol_state = & mut self . symbol_states [ symbol] ;
663- self . definitions_by_definition . insert (
664- declaration,
665- SymbolDefinitions :: Bindings ( symbol_state. bindings ( ) . clone ( ) ) ,
666- ) ;
650+ self . bindings_by_declaration
651+ . insert ( declaration, symbol_state. bindings ( ) . clone ( ) ) ;
667652 symbol_state. record_declaration ( def_id) ;
668653 }
669654
@@ -672,7 +657,8 @@ impl<'db> UseDefMapBuilder<'db> {
672657 symbol : ScopedSymbolId ,
673658 definition : Definition < ' db > ,
674659 ) {
675- // We don't need to store anything in self.definitions_by_definition.
660+ // We don't need to store anything in self.bindings_by_declaration or
661+ // self.declarations_by_binding.
676662 let def_id = self . all_definitions . push ( Some ( definition) ) ;
677663 let symbol_state = & mut self . symbol_states [ symbol] ;
678664 symbol_state. record_declaration ( def_id) ;
@@ -771,7 +757,8 @@ impl<'db> UseDefMapBuilder<'db> {
771757 self . all_definitions . shrink_to_fit ( ) ;
772758 self . symbol_states . shrink_to_fit ( ) ;
773759 self . bindings_by_use . shrink_to_fit ( ) ;
774- self . definitions_by_definition . shrink_to_fit ( ) ;
760+ self . declarations_by_binding . shrink_to_fit ( ) ;
761+ self . bindings_by_declaration . shrink_to_fit ( ) ;
775762 self . eager_bindings . shrink_to_fit ( ) ;
776763
777764 UseDefMap {
@@ -780,7 +767,8 @@ impl<'db> UseDefMapBuilder<'db> {
780767 visibility_constraints : self . visibility_constraints . build ( ) ,
781768 bindings_by_use : self . bindings_by_use ,
782769 public_symbols : self . symbol_states ,
783- definitions_by_definition : self . definitions_by_definition ,
770+ declarations_by_binding : self . declarations_by_binding ,
771+ bindings_by_declaration : self . bindings_by_declaration ,
784772 eager_bindings : self . eager_bindings ,
785773 }
786774 }
0 commit comments