@@ -1779,7 +1779,7 @@ impl<'db> ProtocolClassLiteral<'db> {
1779
1779
/// It is illegal for a protocol class to have any instance attributes that are not declared
1780
1780
/// in the protocol's class body. If any are assigned to, they are not taken into account in
1781
1781
/// the protocol's list of members.
1782
- pub ( super ) fn protocol_members ( self , db : & ' db dyn Db ) -> & ' db ordermap :: set :: Slice < Name > {
1782
+ pub ( super ) fn protocol_members ( self , db : & ' db dyn Db ) -> FxOrderSet < Name > {
1783
1783
/// The list of excluded members is subject to change between Python versions,
1784
1784
/// especially for dunders, but it probably doesn't matter *too* much if this
1785
1785
/// list goes out of date. It's up to date as of Python commit 87b1ea016b1454b1e83b9113fa9435849b7743aa
@@ -1816,58 +1816,52 @@ impl<'db> ProtocolClassLiteral<'db> {
1816
1816
)
1817
1817
}
1818
1818
1819
- #[ salsa:: tracked( return_ref) ]
1820
- fn cached_protocol_members < ' db > (
1821
- db : & ' db dyn Db ,
1822
- class : ClassLiteralType < ' db > ,
1823
- ) -> Box < ordermap:: set:: Slice < Name > > {
1824
- let mut members = FxOrderSet :: default ( ) ;
1819
+ let mut members = FxOrderSet :: default ( ) ;
1825
1820
1826
- for parent_protocol in class
1827
- . iter_mro ( db, None )
1828
- . filter_map ( ClassBase :: into_class)
1829
- . filter_map ( |class| class. class_literal ( db) . 0 . into_protocol_class ( db) )
1830
- {
1831
- let parent_scope = parent_protocol. body_scope ( db) ;
1832
- let use_def_map = use_def_map ( db, parent_scope) ;
1833
- let symbol_table = symbol_table ( db, parent_scope) ;
1834
-
1835
- members. extend (
1836
- use_def_map
1837
- . all_public_declarations ( )
1838
- . flat_map ( |( symbol_id, declarations) | {
1839
- symbol_from_declarations ( db, declarations)
1840
- . map ( |symbol| ( symbol_id, symbol) )
1841
- } )
1842
- . filter_map ( |( symbol_id, symbol) | {
1843
- symbol. symbol . ignore_possibly_unbound ( ) . map ( |_| symbol_id)
1844
- } )
1845
- // Bindings in the class body that are not declared in the class body
1846
- // are not valid protocol members, and we plan to emit diagnostics for them
1847
- // elsewhere. Invalid or not, however, it's important that we still consider
1848
- // them to be protocol members. The implementation of `issubclass()` and
1849
- // `isinstance()` for runtime-checkable protocols considers them to be protocol
1850
- // members at runtime, and it's important that we accurately understand
1851
- // type narrowing that uses `isinstance()` or `issubclass()` with
1852
- // runtime-checkable protocols.
1853
- . chain ( use_def_map. all_public_bindings ( ) . filter_map (
1854
- |( symbol_id, bindings) | {
1821
+ for parent_protocol in self
1822
+ . iter_mro ( db, None )
1823
+ . filter_map ( ClassBase :: into_class)
1824
+ . filter_map ( |class| class. class_literal ( db) . 0 . into_protocol_class ( db) )
1825
+ {
1826
+ let parent_scope = parent_protocol. body_scope ( db) ;
1827
+ let use_def_map = use_def_map ( db, parent_scope) ;
1828
+ let symbol_table = symbol_table ( db, parent_scope) ;
1829
+
1830
+ members. extend (
1831
+ use_def_map
1832
+ . all_public_declarations ( )
1833
+ . flat_map ( |( symbol_id, declarations) | {
1834
+ symbol_from_declarations ( db, declarations) . map ( |symbol| ( symbol_id, symbol) )
1835
+ } )
1836
+ . filter_map ( |( symbol_id, symbol) | {
1837
+ symbol. symbol . ignore_possibly_unbound ( ) . map ( |_| symbol_id)
1838
+ } )
1839
+ // Bindings in the class body that are not declared in the class body
1840
+ // are not valid protocol members, and we plan to emit diagnostics for them
1841
+ // elsewhere. Invalid or not, however, it's important that we still consider
1842
+ // them to be protocol members. The implementation of `issubclass()` and
1843
+ // `isinstance()` for runtime-checkable protocols considers them to be protocol
1844
+ // members at runtime, and it's important that we accurately understand
1845
+ // type narrowing that uses `isinstance()` or `issubclass()` with
1846
+ // runtime-checkable protocols.
1847
+ . chain (
1848
+ use_def_map
1849
+ . all_public_bindings ( )
1850
+ . filter_map ( |( symbol_id, bindings) | {
1855
1851
symbol_from_bindings ( db, bindings)
1856
1852
. ignore_possibly_unbound ( )
1857
1853
. map ( |_| symbol_id)
1858
- } ,
1859
- ) )
1860
- . map ( |symbol_id| symbol_table. symbol ( symbol_id) . name ( ) )
1861
- . filter ( |name| !excluded_from_proto_members ( name) )
1862
- . cloned ( ) ,
1863
- ) ;
1864
- }
1865
-
1866
- members. sort ( ) ;
1867
- members. into_boxed_slice ( )
1854
+ } ) ,
1855
+ )
1856
+ . map ( |symbol_id| symbol_table. symbol ( symbol_id) . name ( ) )
1857
+ . filter ( |name| !excluded_from_proto_members ( name) )
1858
+ . cloned ( ) ,
1859
+ ) ;
1868
1860
}
1869
1861
1870
- cached_protocol_members ( db, * self )
1862
+ members. sort ( ) ;
1863
+ members. shrink_to_fit ( ) ;
1864
+ members
1871
1865
}
1872
1866
1873
1867
pub ( super ) fn is_runtime_checkable ( self , db : & ' db dyn Db ) -> bool {
0 commit comments