forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#135947 - matthiaskrgr:rollup-k9jpfls, r=matth…
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#135073 (Implement `ByteStr` and `ByteString` types) - rust-lang#135492 (Add missing check for async body when suggesting await on futures.) - rust-lang#135766 (handle global trait bounds defining assoc types) - rust-lang#135880 (Get rid of RunCompiler) - rust-lang#135908 (rustc_codegen_llvm: remove outdated asm-to-obj codegen note) - rust-lang#135911 (Allow `arena_cache` queries to return `Option<&'tcx T>`) - rust-lang#135920 (simplify parse_format::Parser::ws by using next_if) r? `@ghost` `@rustbot` modify labels: rollup
- Loading branch information
Showing
42 changed files
with
1,609 additions
and
251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/// Helper trait that allows `arena_cache` queries to return `Option<&T>` | ||
/// instead of `&Option<T>`, and avoid allocating `None` in the arena. | ||
/// | ||
/// An arena-cached query must be declared to return a type that implements | ||
/// this trait, i.e. either `&'tcx T` or `Option<&'tcx T>`. This trait then | ||
/// determines the types returned by the provider and stored in the arena, | ||
/// and provides a function to bridge between the three types. | ||
pub trait ArenaCached<'tcx>: Sized { | ||
/// Type that is returned by the query provider. | ||
type Provided; | ||
/// Type that is stored in the arena. | ||
type Allocated: 'tcx; | ||
|
||
/// Takes a provided value, and allocates it in the arena (if appropriate) | ||
/// with the help of the given `arena_alloc` closure. | ||
fn alloc_in_arena( | ||
arena_alloc: impl Fn(Self::Allocated) -> &'tcx Self::Allocated, | ||
value: Self::Provided, | ||
) -> Self; | ||
} | ||
|
||
impl<'tcx, T> ArenaCached<'tcx> for &'tcx T { | ||
type Provided = T; | ||
type Allocated = T; | ||
|
||
fn alloc_in_arena( | ||
arena_alloc: impl Fn(Self::Allocated) -> &'tcx Self::Allocated, | ||
value: Self::Provided, | ||
) -> Self { | ||
// Just allocate in the arena normally. | ||
arena_alloc(value) | ||
} | ||
} | ||
|
||
impl<'tcx, T> ArenaCached<'tcx> for Option<&'tcx T> { | ||
type Provided = Option<T>; | ||
/// The provide value is `Option<T>`, but we only store `T` in the arena. | ||
type Allocated = T; | ||
|
||
fn alloc_in_arena( | ||
arena_alloc: impl Fn(Self::Allocated) -> &'tcx Self::Allocated, | ||
value: Self::Provided, | ||
) -> Self { | ||
// Don't store None in the arena, and wrap the allocated reference in Some. | ||
value.map(arena_alloc) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.