Skip to content

Rollup of 5 pull requests #71566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Apr 26, 2020
Merged
Changes from 2 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
2b25c0c
Don't load the same allocation twice when reading a scalar pair from it
oli-obk Apr 14, 2020
740f228
Remove `predecessors_for`
ecstatic-morse Apr 21, 2020
59c7460
Use a ref-counted pointer for ownership of the predecessor cache
ecstatic-morse Apr 21, 2020
34dfbc3
Add module docs and restrict visibility
ecstatic-morse Apr 23, 2020
af44cdf
Disallow statics initializing themselves
oli-obk Apr 23, 2020
e4ab4ee
Update src/librustc_mir/interpret/memory.rs
oli-obk Apr 23, 2020
cff5b99
add a few more DefKinds
mark-i-m Mar 16, 2020
d1db782
Split out the `Generator` case from `DefKind::Closure`.
eddyb Apr 17, 2020
95b3c42
Remove `Option` from the return type of `def_kind`.
eddyb Apr 17, 2020
18be5a0
Tweak `descr` for `AnonConst` and fix `article` for `Use` and `Extern…
eddyb Apr 17, 2020
d00f94f
Remove redundant `descr`/`descriptive_variant` methods from HIR.
eddyb Apr 17, 2020
087c0d7
fix a couple more uses of def_kind
mark-i-m Apr 24, 2020
258ebfe
tidy
mark-i-m Apr 24, 2020
1474fac
Add regression test for #26376
wesleywiser Apr 25, 2020
357f4ce
Replace thread_local with generator resume arguments in box_region.
gizmondo Mar 31, 2020
e51cbc8
Rollup merge of #70043 - mark-i-m:def-kind-more, r=eddyb
Dylan-DPC Apr 25, 2020
b964451
Rollup merge of #71140 - oli-obk:static_cycle, r=RalfJung
Dylan-DPC Apr 25, 2020
98a43ca
Rollup merge of #71392 - ecstatic-morse:body-predecessor-cache-arc, r…
Dylan-DPC Apr 25, 2020
fde4727
Rollup merge of #71541 - wesleywiser:issue_26376, r=Dylan-DPC
Dylan-DPC Apr 25, 2020
f70c9db
Rollup merge of #71554 - gizmondo:68922, r=jonas-schievink
Dylan-DPC Apr 25, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 27 additions & 20 deletions src/librustc_data_structures/box_region.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
use std::cell::Cell;
//! 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;
@@ -14,24 +25,23 @@ impl AccessAction {

#[derive(Copy, Clone)]
pub enum Action {
Initial,
Access(AccessAction),
Complete,
}

thread_local!(pub static BOX_REGION_ARG: Cell<Action> = Cell::new(Action::Complete));

pub struct PinnedGenerator<I, A, R> {
generator: Pin<Box<dyn Generator<Yield = YieldType<I, A>, Return = 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<Yield = YieldType<I, A>, Return = R> + 'static>(
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(()) {
let init = match Pin::new(&mut result.generator).resume(Action::Initial) {
GeneratorState::Yielded(YieldType::Initial(y)) => y,
_ => panic!(),
};
@@ -40,21 +50,17 @@ impl<I, A, R> PinnedGenerator<I, A, R> {
}

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(()) {
// 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
BOX_REGION_ARG.with(|i| i.set(Action::Complete));

let result = Pin::new(&mut self.generator).resume(());
let result = Pin::new(&mut self.generator).resume(Action::Complete);
if let GeneratorState::Complete(r) = result { r } else { panic!() }
}
}
@@ -89,7 +95,7 @@ macro_rules! declare_box_region_type {
>);

impl $name {
fn new<T: ::std::ops::Generator<Yield = $yield_type, Return = $retc> + 'static>(
fn new<T: ::std::ops::Generator<$crate::box_region::Action, Yield = $yield_type, Return = $retc> + 'static>(
generator: T
) -> ($reti, Self) {
let (initial, pinned) = $crate::box_region::PinnedGenerator::new(generator);
@@ -98,7 +104,7 @@ macro_rules! declare_box_region_type {

$v fn access<F: for<$($lifetimes)*> FnOnce($($args,)*) -> R, R>(&mut self, f: F) -> R {
// Turn the FnOnce closure into *mut dyn FnMut()
// so we can pass it in to the generator using the BOX_REGION_ARG thread local
// so we can pass it in to the generator
let mut r = None;
let mut f = Some(f);
let mut_f: &mut dyn for<$($lifetimes)*> FnMut(($($args,)*)) =
@@ -140,9 +146,9 @@ macro_rules! declare_box_region_type {
#[macro_export]
#[allow_internal_unstable(fn_traits)]
macro_rules! box_region_allow_access {
(for($($lifetimes:tt)*), ($($args:ty),*), ($($exprs:expr),*) ) => {
(for($($lifetimes:tt)*), ($($args:ty),*), ($($exprs:expr),*), $action:ident) => {
loop {
match $crate::box_region::BOX_REGION_ARG.with(|i| i.get()) {
match $action {
$crate::box_region::Action::Access(accessor) => {
let accessor: &mut dyn for<$($lifetimes)*> FnMut($($args),*) = unsafe {
::std::mem::transmute(accessor.get())
@@ -152,10 +158,11 @@ macro_rules! box_region_allow_access {
let marker = $crate::box_region::Marker::<
for<$($lifetimes)*> fn(($($args,)*))
>::new();
yield $crate::box_region::YieldType::Accessor(marker)
$action = yield $crate::box_region::YieldType::Accessor(marker);
};
}
$crate::box_region::Action::Complete => break,
$crate::box_region::Action::Initial => panic!("unexpected box_region action: Initial"),
}
}
}
7 changes: 4 additions & 3 deletions src/librustc_interface/passes.rs
Original file line number Diff line number Diff line change
@@ -109,7 +109,8 @@ pub fn configure_and_expand(
// its contents but the results of name resolution on those contents. Hopefully we'll push
// this back at some point.
let crate_name = crate_name.to_string();
let (result, resolver) = BoxedResolver::new(static move || {
let (result, resolver) = BoxedResolver::new(static move |mut action| {
let _ = action;
let sess = &*sess;
let resolver_arenas = Resolver::arenas();
let res = configure_and_expand_inner(
@@ -126,11 +127,11 @@ pub fn configure_and_expand(
panic!()
}
Ok((krate, resolver)) => {
yield BoxedResolver::initial_yield(Ok(krate));
action = yield BoxedResolver::initial_yield(Ok(krate));
resolver
}
};
box_region_allow_access!(for(), (&mut Resolver<'_>), (&mut resolver));
box_region_allow_access!(for(), (&mut Resolver<'_>), (&mut resolver), action);
resolver.into_outputs()
});
result.map(|k| (k, resolver))