mirror of
				https://github.com/rust-lang/rust.git
				synced 2025-10-31 04:57:19 +00:00 
			
		
		
		
	 36b495f3cf
			
		
	
	
		36b495f3cf
		
	
	
	
	
		
			
			This reduces peak memory usage significantly for some programs with very large functions, such as: - `keccak`, `unicode_normalization`, and `match-stress-enum`, from the `rustc-perf` benchmark suite; - `http-0.2.6` from crates.io. The new type is used in the analyses where the bitsets can get huge (e.g. 10s of thousands of bits): `MaybeInitializedPlaces`, `MaybeUninitializedPlaces`, and `EverInitializedPlaces`. Some refactoring was required in `rustc_mir_dataflow`. All existing analysis domains are either `BitSet` or a trivial wrapper around `BitSet`, and access in a few places is done via `Borrow<BitSet>` or `BorrowMut<BitSet>`. Now that some of these domains are `ClusterBitSet`, that no longer works. So this commit replaces the `Borrow`/`BorrowMut` usage with a new trait `BitSetExt` containing the needed bitset operations. The impls just forward these to the underlying bitset type. This required fiddling with trait bounds in a few places. The commit also: - Moves `static_assert_size` from `rustc_data_structures` to `rustc_index` so it can be used in the latter; the former now re-exports it so existing users are unaffected. - Factors out some common "clear excess bits in the final word" functionality in `bit_set.rs`. - Uses `fill` in a few places instead of loops.
		
			
				
	
	
		
			38 lines
		
	
	
		
			973 B
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			38 lines
		
	
	
		
			973 B
		
	
	
	
		
			Rust
		
	
	
	
	
	
| #[macro_export]
 | |
| macro_rules! enum_from_u32 {
 | |
|     ($(#[$attr:meta])* pub enum $name:ident {
 | |
|         $($(#[$var_attr:meta])* $variant:ident = $e:expr,)*
 | |
|     }) => {
 | |
|         $(#[$attr])*
 | |
|         pub enum $name {
 | |
|             $($(#[$var_attr])* $variant = $e),*
 | |
|         }
 | |
| 
 | |
|         impl $name {
 | |
|             pub fn from_u32(u: u32) -> Option<$name> {
 | |
|                 $(if u == $name::$variant as u32 {
 | |
|                     return Some($name::$variant)
 | |
|                 })*
 | |
|                 None
 | |
|             }
 | |
|         }
 | |
|     };
 | |
|     ($(#[$attr:meta])* pub enum $name:ident {
 | |
|         $($(#[$var_attr:meta])* $variant:ident,)*
 | |
|     }) => {
 | |
|         $(#[$attr])*
 | |
|         pub enum $name {
 | |
|             $($(#[$var_attr])* $variant,)*
 | |
|         }
 | |
| 
 | |
|         impl $name {
 | |
|             pub fn from_u32(u: u32) -> Option<$name> {
 | |
|                 $(if u == $name::$variant as u32 {
 | |
|                     return Some($name::$variant)
 | |
|                 })*
 | |
|                 None
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| }
 |