about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbjorn3 <bjorn3@users.noreply.github.com>2021-05-31 15:17:04 +0200
committerbjorn3 <bjorn3@users.noreply.github.com>2021-06-08 19:24:15 +0200
commit86b3ebe2da46081b58a1f6208eb0f9c3ac4f3ec0 (patch)
treed7c2fa41b8d2f94a7d876d4890bda285a72fdf12
parent8f397bc8a0d8f2569d9aec7ad787b484c4b147e4 (diff)
downloadrust-86b3ebe2da46081b58a1f6208eb0f9c3ac4f3ec0.tar.gz
rust-86b3ebe2da46081b58a1f6208eb0f9c3ac4f3ec0.zip
Inline box_region macro calls
-rw-r--r--compiler/rustc_data_structures/src/box_region.rs80
-rw-r--r--compiler/rustc_interface/src/passes.rs82
2 files changed, 77 insertions, 85 deletions
diff --git a/compiler/rustc_data_structures/src/box_region.rs b/compiler/rustc_data_structures/src/box_region.rs
index 2f212b03e08..a1a757b7054 100644
--- a/compiler/rustc_data_structures/src/box_region.rs
+++ b/compiler/rustc_data_structures/src/box_region.rs
@@ -78,83 +78,3 @@ pub enum YieldType<I, A> {
     Initial(I),
     Accessor(Marker<A>),
 }
-
-#[macro_export]
-#[allow_internal_unstable(fn_traits)]
-macro_rules! declare_box_region_type {
-    ($v:vis $name: ident, ($($args:ty),*) -> ($reti:ty, $retc:ty)) => {
-        $v struct $name($crate::box_region::PinnedGenerator<
-            $reti,
-            fn(($($args,)*)),
-            $retc
-        >);
-
-        impl $name {
-            fn new<T>(generator: T) -> ($reti, Self)
-            where T: ::std::ops::Generator<
-                $crate::box_region::Action,
-                Yield = $crate::box_region::YieldType<$reti, fn(($($args,)*))>,
-                Return = $retc,
-            > + 'static {
-                let (initial, pinned) = $crate::box_region::PinnedGenerator::new(generator);
-                (initial, $name(pinned))
-            }
-
-            $v fn access<F: 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
-                let mut r = None;
-                let mut f = Some(f);
-                let mut_f: &mut dyn FnMut(($($args,)*)) =
-                    &mut |args| {
-                        let f = f.take().unwrap();
-                        r = Some(FnOnce::call_once(f, args));
-                };
-                let mut_f = mut_f as *mut dyn FnMut(($($args,)*));
-
-                // Get the generator to call our closure
-                unsafe {
-                    self.0.access(::std::mem::transmute(mut_f));
-                }
-
-                // Unwrap the result
-                r.unwrap()
-            }
-
-            $v fn complete(mut self) -> $retc {
-                self.0.complete()
-            }
-
-            fn initial_yield(
-                value: $reti,
-            ) -> $crate::box_region::YieldType<$reti, fn(($($args,)*))> {
-                $crate::box_region::YieldType::Initial(value)
-            }
-        }
-    };
-}
-
-#[macro_export]
-#[allow_internal_unstable(fn_traits)]
-macro_rules! box_region_allow_access {
-    (($($args:ty),*), ($($exprs:expr),*), $action:ident) => {
-        loop {
-            match $action {
-                $crate::box_region::Action::Access(accessor) => {
-                    let accessor: &mut dyn FnMut($($args),*) = unsafe {
-                        ::std::mem::transmute(accessor.get())
-                    };
-                    (*accessor)(($($exprs),*));
-                    unsafe {
-                        let marker = $crate::box_region::Marker::<
-                            fn(($($args,)*))
-                        >::new();
-                        $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"),
-            }
-        }
-    }
-}
diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs
index 478b2ef4d8f..383917e41b5 100644
--- a/compiler/rustc_interface/src/passes.rs
+++ b/compiler/rustc_interface/src/passes.rs
@@ -6,10 +6,10 @@ use rustc_ast::mut_visit::MutVisitor;
 use rustc_ast::{self as ast, visit};
 use rustc_codegen_ssa::back::link::emit_metadata;
 use rustc_codegen_ssa::traits::CodegenBackend;
+use rustc_data_structures::parallel;
 use rustc_data_structures::steal::Steal;
 use rustc_data_structures::sync::{par_iter, Lrc, OnceCell, ParallelIterator, WorkerLocal};
 use rustc_data_structures::temp_dir::MaybeTempDir;
-use rustc_data_structures::{box_region_allow_access, declare_box_region_type, parallel};
 use rustc_errors::{ErrorReported, PResult};
 use rustc_expand::base::ExtCtxt;
 use rustc_hir::def_id::LOCAL_CRATE;
@@ -85,11 +85,62 @@ fn count_nodes(krate: &ast::Crate) -> usize {
     counter.count
 }
 
-declare_box_region_type!(
-    pub BoxedResolver,
-    (&mut Resolver<'_>) -> (Result<ast::Crate>, ResolverOutputs)
+pub struct BoxedResolver(
+    rustc_data_structures::box_region::PinnedGenerator<
+        Result<ast::Crate>,
+        fn(&mut Resolver<'_>),
+        ResolverOutputs,
+    >,
 );
 
+impl BoxedResolver {
+    fn new<T>(generator: T) -> (Result<ast::Crate>, Self)
+    where
+        T: ::std::ops::Generator<
+                rustc_data_structures::box_region::Action,
+                Yield = rustc_data_structures::box_region::YieldType<
+                    Result<ast::Crate>,
+                    fn(&mut Resolver<'_>),
+                >,
+                Return = ResolverOutputs,
+            > + 'static,
+    {
+        let (initial, pinned) = rustc_data_structures::box_region::PinnedGenerator::new(generator);
+        (initial, BoxedResolver(pinned))
+    }
+
+    pub fn access<F: FnOnce(&mut Resolver<'_>) -> R, R>(&mut self, f: F) -> R {
+        // Turn the FnOnce closure into *mut dyn FnMut()
+        // so we can pass it in to the generator
+        let mut r = None;
+        let mut f = Some(f);
+        let mut_f: &mut dyn FnMut(&mut Resolver<'_>) = &mut |resolver| {
+            let f = f.take().unwrap();
+            r = Some(f(resolver));
+        };
+        let mut_f = mut_f as *mut dyn FnMut(&mut Resolver<'_>);
+
+        // Get the generator to call our closure
+        unsafe {
+            self.0.access(::std::mem::transmute(mut_f));
+        }
+
+        // Unwrap the result
+        r.unwrap()
+    }
+
+    pub fn complete(mut self) -> ResolverOutputs {
+        self.0.complete()
+    }
+
+    fn initial_yield(
+        value: Result<ast::Crate>,
+    ) -> rustc_data_structures::box_region::YieldType<Result<ast::Crate>, fn(&mut Resolver<'_>)>
+    {
+        rustc_data_structures::box_region::YieldType::Initial(value)
+    }
+}
+
 /// Runs the "early phases" of the compiler: initial `cfg` processing, loading compiler plugins,
 /// syntax expansion, secondary `cfg` expansion, synthesis of a test
 /// harness if one is to be provided, injection of a dependency on the
@@ -132,7 +183,28 @@ pub fn configure_and_expand(
                 resolver
             }
         };
-        box_region_allow_access!((&mut Resolver<'_>), (&mut resolver), action);
+
+        loop {
+            match action {
+                rustc_data_structures::box_region::Action::Access(accessor) => {
+                    let accessor: &mut dyn FnMut(&mut Resolver<'_>) =
+                        unsafe { ::std::mem::transmute(accessor.get()) };
+                    (*accessor)(&mut resolver);
+                    unsafe {
+                        let marker = rustc_data_structures::box_region::Marker::<
+                            fn(&mut Resolver<'_>),
+                        >::new();
+                        action =
+                            yield rustc_data_structures::box_region::YieldType::Accessor(marker);
+                    };
+                }
+                rustc_data_structures::box_region::Action::Complete => break,
+                rustc_data_structures::box_region::Action::Initial => {
+                    panic!("unexpected box_region action: Initial")
+                }
+            }
+        }
+
         resolver.into_outputs()
     });
     result.map(|k| (k, resolver))