Skip to content

Commit

Permalink
Fix bootstrap rustc build
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-schievink committed Jan 25, 2020
1 parent fed12c3 commit 344c971
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/librustc_data_structures/box_region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub struct PinnedGenerator<I, A, R> {
}

impl<I, A, R> PinnedGenerator<I, A, R> {
#[cfg(bootstrap)]
pub fn new<T: Generator<Yield = YieldType<I, A>, Return = R> + 'static>(
generator: T,
) -> (I, Self) {
Expand All @@ -39,6 +40,22 @@ impl<I, A, R> PinnedGenerator<I, A, R> {
(init, result)
}

#[cfg(not(bootstrap))]
pub fn new<T: Generator<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(()) {
GeneratorState::Yielded(YieldType::Initial(y)) => y,
_ => panic!(),
};

(init, result)
}

#[cfg(bootstrap)]
pub unsafe fn access(&mut self, closure: *mut dyn FnMut()) {
BOX_REGION_ARG.with(|i| {
i.set(Action::Access(AccessAction(closure)));
Expand All @@ -50,13 +67,35 @@ impl<I, A, R> PinnedGenerator<I, A, R> {
}
}

#[cfg(not(bootstrap))]
pub unsafe fn access(&mut self, closure: *mut dyn FnMut()) {
BOX_REGION_ARG.with(|i| {
i.set(Action::Access(AccessAction(closure)));
});

// Call the generator, which in turn will call the closure in BOX_REGION_ARG
if let GeneratorState::Complete(_) = Pin::new(&mut self.generator).resume(()) {
panic!()
}
}

#[cfg(bootstrap)]
pub fn complete(&mut self) -> R {
// Tell the generator we want it to complete, consuming it and yielding a result
BOX_REGION_ARG.with(|i| i.set(Action::Complete));

let result = Pin::new(&mut self.generator).resume();
if let GeneratorState::Complete(r) = result { r } else { panic!() }
}

#[cfg(not(bootstrap))]
pub fn complete(&mut self) -> R {
// Tell the generator we want it to complete, consuming it and yielding a result
BOX_REGION_ARG.with(|i| i.set(Action::Complete));

let result = Pin::new(&mut self.generator).resume(());
if let GeneratorState::Complete(r) = result { r } else { panic!() }
}
}

#[derive(PartialEq)]
Expand Down

0 comments on commit 344c971

Please sign in to comment.