diff options
| author | bjorn3 <bjorn3@users.noreply.github.com> | 2021-05-31 15:20:50 +0200 |
|---|---|---|
| committer | bjorn3 <bjorn3@users.noreply.github.com> | 2021-06-08 19:24:16 +0200 |
| commit | 99e112d28288566d7b3305e78d010bffd2aec89d (patch) | |
| tree | adf07cbb727670db05df97e21617f78f2a4c237d /compiler/rustc_data_structures | |
| parent | 86b3ebe2da46081b58a1f6208eb0f9c3ac4f3ec0 (diff) | |
| download | rust-99e112d28288566d7b3305e78d010bffd2aec89d.tar.gz rust-99e112d28288566d7b3305e78d010bffd2aec89d.zip | |
Inline the rest of box_region
Diffstat (limited to 'compiler/rustc_data_structures')
| -rw-r--r-- | compiler/rustc_data_structures/src/box_region.rs | 80 | ||||
| -rw-r--r-- | compiler/rustc_data_structures/src/lib.rs | 2 |
2 files changed, 0 insertions, 82 deletions
diff --git a/compiler/rustc_data_structures/src/box_region.rs b/compiler/rustc_data_structures/src/box_region.rs deleted file mode 100644 index a1a757b7054..00000000000 --- a/compiler/rustc_data_structures/src/box_region.rs +++ /dev/null @@ -1,80 +0,0 @@ -//! This module provides a way to deal with self-referential data. -//! -//! The main idea is to allocate such data in a generator frame and then -//! give access to it by executing user-provided closures inside that generator. -//! The module provides a safe abstraction for the latter task. -//! -//! The interface consists of two exported macros meant to be used together: -//! * `declare_box_region_type` wraps a generator inside a struct with `access` -//! method which accepts closures. -//! * `box_region_allow_access` is a helper which should be called inside -//! a generator to actually execute those closures. - -use std::marker::PhantomData; -use std::ops::{Generator, GeneratorState}; -use std::pin::Pin; - -#[derive(Copy, Clone)] -pub struct AccessAction(*mut dyn FnMut()); - -impl AccessAction { - pub fn get(self) -> *mut dyn FnMut() { - self.0 - } -} - -#[derive(Copy, Clone)] -pub enum Action { - Initial, - Access(AccessAction), - Complete, -} - -pub struct PinnedGenerator<I, A, R> { - generator: Pin<Box<dyn Generator<Action, Yield = YieldType<I, A>, Return = R>>>, -} - -impl<I, A, R> PinnedGenerator<I, A, R> { - pub fn new<T: Generator<Action, Yield = YieldType<I, A>, Return = R> + 'static>( - generator: T, - ) -> (I, Self) { - let mut result = PinnedGenerator { generator: Box::pin(generator) }; - - // Run it to the first yield to set it up - let init = match Pin::new(&mut result.generator).resume(Action::Initial) { - GeneratorState::Yielded(YieldType::Initial(y)) => y, - _ => panic!(), - }; - - (init, result) - } - - pub unsafe fn access(&mut self, closure: *mut dyn FnMut()) { - // Call the generator, which in turn will call the closure - if let GeneratorState::Complete(_) = - Pin::new(&mut self.generator).resume(Action::Access(AccessAction(closure))) - { - panic!() - } - } - - pub fn complete(&mut self) -> R { - // Tell the generator we want it to complete, consuming it and yielding a result - let result = Pin::new(&mut self.generator).resume(Action::Complete); - if let GeneratorState::Complete(r) = result { r } else { panic!() } - } -} - -#[derive(PartialEq)] -pub struct Marker<T>(PhantomData<T>); - -impl<T> Marker<T> { - pub unsafe fn new() -> Self { - Marker(PhantomData) - } -} - -pub enum YieldType<I, A> { - Initial(I), - Accessor(Marker<A>), -} diff --git a/compiler/rustc_data_structures/src/lib.rs b/compiler/rustc_data_structures/src/lib.rs index a8b9f479f1e..d55e471810c 100644 --- a/compiler/rustc_data_structures/src/lib.rs +++ b/compiler/rustc_data_structures/src/lib.rs @@ -10,7 +10,6 @@ #![feature(array_windows)] #![feature(control_flow_enum)] #![feature(in_band_lifetimes)] -#![feature(generator_trait)] #![feature(min_specialization)] #![feature(auto_traits)] #![feature(nll)] @@ -63,7 +62,6 @@ macro_rules! unlikely { pub mod base_n; pub mod binary_search_util; -pub mod box_region; pub mod captures; pub mod flock; pub mod functor; |
