From eff2884e5ff3eaa5338e3308ac6e6a2bfbd0b664 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Mon, 14 Aug 2017 07:23:35 +0200 Subject: [PATCH] Make generator interior types deterministic --- .../check/generator_interior.rs | 42 +++++++------------ 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/src/librustc_typeck/check/generator_interior.rs b/src/librustc_typeck/check/generator_interior.rs index 5bfcf77cda8..f50fb7e4a13 100644 --- a/src/librustc_typeck/check/generator_interior.rs +++ b/src/librustc_typeck/check/generator_interior.rs @@ -18,13 +18,14 @@ use syntax::ast::NodeId; use syntax::codemap::Span; use std::rc::Rc; use super::FnCtxt; -use util::nodemap::FxHashSet; use util::nodemap::FxHashMap; struct InteriorVisitor<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { fcx: &'a FnCtxt<'a, 'gcx, 'tcx>, cache: FxHashMap>, - types: FxHashSet>, + + // FIXME: Use an ordered hash map here + types: Vec>, region_maps: Rc, } @@ -37,26 +38,19 @@ impl<'a, 'gcx, 'tcx> InteriorVisitor<'a, 'gcx, 'tcx> { }).unwrap_or(true); if live_across_yield { + let ty = self.fcx.resolve_type_vars_if_possible(&ty); + if log_enabled!(log::LogLevel::Debug) { - if let Some(s) = scope { - let span = s.span(&self.fcx.tcx.hir).unwrap_or(DUMMY_SP); - debug!("type in generator with scope = {:?}, type = {:?}, span = {:?}", - scope, - self.fcx.resolve_type_vars_if_possible(&ty), - span); - } else { - debug!("type in generator WITHOUT scope, type = {:?}", - self.fcx.resolve_type_vars_if_possible(&ty)); - } - if let Some(e) = expr { - debug!("type from expression: {:?}, span={:?}", e, e.span); - } + let span = scope.map(|s| s.span(&self.fcx.tcx.hir).unwrap_or(DUMMY_SP)); + debug!("type in expr = {:?}, scope = {:?}, type = {:?}, span = {:?}", + expr, scope, ty, span); + } + + if !self.types.contains(&ty) { + self.types.push(ty); } - self.types.insert(ty); } else { - if let Some(e) = expr { - debug!("NO type from expression: {:?}, span = {:?}", e, e.span); - } + debug!("no type in expr = {:?}, span = {:?}", expr, expr.map(|e| e.span)); } } } @@ -68,19 +62,13 @@ pub fn resolve_interior<'a, 'gcx, 'tcx>(fcx: &'a FnCtxt<'a, 'gcx, 'tcx>, let body = fcx.tcx.hir.body(body_id); let mut visitor = InteriorVisitor { fcx, - types: FxHashSet(), + types: Vec::new(), cache: FxHashMap(), region_maps: fcx.tcx.region_maps(def_id), }; intravisit::walk_body(&mut visitor, body); - // Deduplicate types - let set: FxHashSet<_> = visitor.types.into_iter() - .map(|t| fcx.resolve_type_vars_if_possible(&t)) - .collect(); - let types: Vec<_> = set.into_iter().collect(); - - let tuple = fcx.tcx.intern_tup(&types, false); + let tuple = fcx.tcx.intern_tup(&visitor.types, false); debug!("Types in generator {:?}, span = {:?}", tuple, body.value.span);