]> git.lizzy.rs Git - rust.git/commitdiff
Remove TypeId from stack in Builder
authorMark Simulacrum <mark.simulacrum@gmail.com>
Tue, 18 Jul 2017 00:01:48 +0000 (18:01 -0600)
committerMark Simulacrum <mark.simulacrum@gmail.com>
Thu, 20 Jul 2017 17:24:37 +0000 (11:24 -0600)
src/bootstrap/builder.rs

index 2338ac1a692c56d49b566746ead16f5c0ca1fe7c..50ecdeb988a01305f3a2ece773ed06e355389a90 100644 (file)
@@ -15,7 +15,7 @@
 use std::process::Command;
 use std::fs;
 use std::ops::Deref;
-use std::any::{TypeId, Any};
+use std::any::Any;
 
 use compile;
 use install;
@@ -35,7 +35,7 @@ pub struct Builder<'a> {
     pub top_stage: u32,
     pub kind: Kind,
     cache: Cache,
-    stack: RefCell<Vec<(TypeId, Box<Any>)>>,
+    stack: RefCell<Vec<Box<Any>>>,
 }
 
 impl<'a> Deref for Builder<'a> {
@@ -477,12 +477,12 @@ fn maybe_run<S: Step>(&self, path: Option<&Path>) {
     /// cache the step, so it is safe (and good!) to call this as often as
     /// needed to ensure that all dependencies are built.
     pub fn ensure<S: Step>(&'a self, step: S) -> S::Output {
-        let type_id = TypeId::of::<S>();
         {
             let mut stack = self.stack.borrow_mut();
-            for &(stack_type_id, ref stack_step) in stack.iter() {
-                if !(type_id == stack_type_id && step == *stack_step.downcast_ref().unwrap()) {
-                    continue
+            for stack_step in stack.iter() {
+                // should skip
+                if stack_step.downcast_ref::<S>().map_or(true, |stack_step| *stack_step != step) {
+                    continue;
                 }
                 let mut out = String::new();
                 out += &format!("\n\nCycle in build detected when adding {:?}\n", step);
@@ -497,13 +497,13 @@ pub fn ensure<S: Step>(&'a self, step: S) -> S::Output {
                 return out;
             }
             self.build.verbose(&format!("{}> {:?}", "  ".repeat(stack.len()), step));
-            stack.push((type_id, Box::new(step.clone())));
+            stack.push(Box::new(step.clone()));
         }
         let out = step.clone().run(self);
         {
             let mut stack = self.stack.borrow_mut();
-            let (cur_type_id, cur_step) = stack.pop().expect("step stack empty");
-            assert_eq!((cur_type_id, cur_step.downcast_ref()), (type_id, Some(&step)));
+            let cur_step = stack.pop().expect("step stack empty");
+            assert_eq!(cur_step.downcast_ref(), Some(&step));
         }
         self.build.verbose(&format!("{}< {:?}", "  ".repeat(self.stack.borrow().len()), step));
         self.cache.put(step, out.clone());