Skip to content

Commit 2b484e4

Browse files
committed
---
yaml --- r: 213968 b: refs/heads/master c: bc383f6 h: refs/heads/master v: v3
1 parent 3e45faf commit 2b484e4

File tree

8 files changed

+256
-223
lines changed

8 files changed

+256
-223
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 84b49b2d355e49c429703eade10f93680cc3bd47
2+
refs/heads/master: bc383f62941ae079188a9725eb49f3b8a42e35ae
33
refs/heads/snap-stage3: ba0e1cd8147d452c356aacb29fb87568ca26f111
44
refs/heads/try: b53c0f93eedcdedd4fd89bccc5a3a09d1c5cd23e
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

trunk/src/librustc/middle/ty.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2810,20 +2810,22 @@ impl<'tcx> CommonTypes<'tcx> {
28102810
}
28112811
}
28122812

2813-
pub fn mk_ctxt<'tcx>(s: Session,
2814-
arenas: &'tcx CtxtArenas<'tcx>,
2815-
def_map: DefMap,
2816-
named_region_map: resolve_lifetime::NamedRegionMap,
2817-
map: ast_map::Map<'tcx>,
2818-
freevars: RefCell<FreevarMap>,
2819-
region_maps: RegionMaps,
2820-
lang_items: middle::lang_items::LanguageItems,
2821-
stability: stability::Index<'tcx>) -> ctxt<'tcx>
2813+
pub fn with_ctxt<'tcx, F, R>(s: Session,
2814+
arenas: &'tcx CtxtArenas<'tcx>,
2815+
def_map: DefMap,
2816+
named_region_map: resolve_lifetime::NamedRegionMap,
2817+
map: ast_map::Map<'tcx>,
2818+
freevars: RefCell<FreevarMap>,
2819+
region_maps: RegionMaps,
2820+
lang_items: middle::lang_items::LanguageItems,
2821+
stability: stability::Index<'tcx>,
2822+
f: F) -> (Session, R)
2823+
where F: FnOnce(&ctxt<'tcx>) -> R
28222824
{
28232825
let mut interner = FnvHashMap();
28242826
let common_types = CommonTypes::new(&arenas.type_, &mut interner);
28252827

2826-
ctxt {
2828+
let tcx = ctxt {
28272829
arenas: arenas,
28282830
interner: RefCell::new(interner),
28292831
substs_interner: RefCell::new(FnvHashMap()),
@@ -2885,7 +2887,9 @@ pub fn mk_ctxt<'tcx>(s: Session,
28852887
const_qualif_map: RefCell::new(NodeMap()),
28862888
custom_coerce_unsized_kinds: RefCell::new(DefIdMap()),
28872889
cast_kinds: RefCell::new(NodeMap()),
2888-
}
2890+
};
2891+
let result = f(&tcx);
2892+
(tcx.sess, result)
28892893
}
28902894

28912895
// Type constructors

trunk/src/librustc_driver/driver.rs

Lines changed: 135 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub fn compile_input(sess: Session,
6565
// We need nested scopes here, because the intermediate results can keep
6666
// large chunks of memory alive and we want to free them as soon as
6767
// possible to keep the peak memory usage low
68-
let (outputs, trans, sess) = {
68+
let (sess, result) = {
6969
let (outputs, expanded_crate, id) = {
7070
let krate = phase_1_parse_input(&sess, cfg, input);
7171

@@ -119,37 +119,52 @@ pub fn compile_input(sess: Session,
119119
&ast_map.krate(),
120120
&id[..]));
121121

122-
let (tcx, analysis) = phase_3_run_analysis_passes(sess,
123-
ast_map,
124-
&arenas,
125-
id,
126-
control.make_glob_map);
127-
128-
controller_entry_point!(after_analysis,
129-
tcx.sess,
130-
CompileState::state_after_analysis(input,
131-
&tcx.sess,
132-
outdir,
133-
tcx.map.krate(),
134-
&analysis,
135-
&tcx));
136-
137-
if log_enabled!(::log::INFO) {
138-
println!("Pre-trans");
139-
tcx.print_debug_stats();
140-
}
141-
let trans = phase_4_translate_to_llvm(&tcx, analysis);
122+
phase_3_run_analysis_passes(sess,
123+
ast_map,
124+
&arenas,
125+
id,
126+
control.make_glob_map,
127+
|tcx, analysis| {
128+
129+
{
130+
let state = CompileState::state_after_analysis(input,
131+
&tcx.sess,
132+
outdir,
133+
tcx.map.krate(),
134+
&analysis,
135+
tcx);
136+
(control.after_analysis.callback)(state);
137+
138+
tcx.sess.abort_if_errors();
139+
if control.after_analysis.stop == Compilation::Stop {
140+
return Err(());
141+
}
142+
}
142143

143-
if log_enabled!(::log::INFO) {
144-
println!("Post-trans");
145-
tcx.print_debug_stats();
146-
}
144+
if log_enabled!(::log::INFO) {
145+
println!("Pre-trans");
146+
tcx.print_debug_stats();
147+
}
148+
let trans = phase_4_translate_to_llvm(tcx, analysis);
149+
150+
if log_enabled!(::log::INFO) {
151+
println!("Post-trans");
152+
tcx.print_debug_stats();
153+
}
147154

148-
// Discard interned strings as they are no longer required.
149-
token::get_ident_interner().clear();
155+
// Discard interned strings as they are no longer required.
156+
token::get_ident_interner().clear();
150157

151-
(outputs, trans, tcx.sess)
158+
Ok((outputs, trans))
159+
})
152160
};
161+
162+
let (outputs, trans) = if let Ok(out) = result {
163+
out
164+
} else {
165+
return;
166+
};
167+
153168
phase_5_run_llvm_passes(&sess, &trans, &outputs);
154169

155170
controller_entry_point!(after_llvm,
@@ -578,12 +593,16 @@ pub fn assign_node_ids_and_map<'ast>(sess: &Session,
578593
/// Run the resolution, typechecking, region checking and other
579594
/// miscellaneous analysis passes on the crate. Return various
580595
/// structures carrying the results of the analysis.
581-
pub fn phase_3_run_analysis_passes<'tcx>(sess: Session,
582-
ast_map: ast_map::Map<'tcx>,
583-
arenas: &'tcx ty::CtxtArenas<'tcx>,
584-
name: String,
585-
make_glob_map: resolve::MakeGlobMap)
586-
-> (ty::ctxt<'tcx>, ty::CrateAnalysis) {
596+
pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: Session,
597+
ast_map: ast_map::Map<'tcx>,
598+
arenas: &'tcx ty::CtxtArenas<'tcx>,
599+
name: String,
600+
make_glob_map: resolve::MakeGlobMap,
601+
f: F)
602+
-> (Session, R)
603+
where F: FnOnce(&ty::ctxt<'tcx>,
604+
ty::CrateAnalysis) -> R
605+
{
587606
let time_passes = sess.time_passes();
588607
let krate = ast_map.krate();
589608

@@ -627,86 +646,88 @@ pub fn phase_3_run_analysis_passes<'tcx>(sess: Session,
627646
time(time_passes, "static item recursion checking", (), |_|
628647
middle::check_static_recursion::check_crate(&sess, krate, &def_map, &ast_map));
629648

630-
let ty_cx = ty::mk_ctxt(sess,
631-
arenas,
632-
def_map,
633-
named_region_map,
634-
ast_map,
635-
freevars,
636-
region_map,
637-
lang_items,
638-
stability::Index::new(krate));
639-
640-
// passes are timed inside typeck
641-
typeck::check_crate(&ty_cx, trait_map);
642-
643-
time(time_passes, "const checking", (), |_|
644-
middle::check_const::check_crate(&ty_cx));
645-
646-
let (exported_items, public_items) =
647-
time(time_passes, "privacy checking", (), |_|
648-
rustc_privacy::check_crate(&ty_cx, &export_map, external_exports));
649-
650-
// Do not move this check past lint
651-
time(time_passes, "stability index", (), |_|
652-
ty_cx.stability.borrow_mut().build(&ty_cx, krate, &public_items));
653-
654-
time(time_passes, "intrinsic checking", (), |_|
655-
middle::intrinsicck::check_crate(&ty_cx));
656-
657-
time(time_passes, "effect checking", (), |_|
658-
middle::effect::check_crate(&ty_cx));
659-
660-
time(time_passes, "match checking", (), |_|
661-
middle::check_match::check_crate(&ty_cx));
662-
663-
time(time_passes, "liveness checking", (), |_|
664-
middle::liveness::check_crate(&ty_cx));
665-
666-
time(time_passes, "borrow checking", (), |_|
667-
borrowck::check_crate(&ty_cx));
668-
669-
time(time_passes, "rvalue checking", (), |_|
670-
middle::check_rvalues::check_crate(&ty_cx, krate));
671-
672-
// Avoid overwhelming user with errors if type checking failed.
673-
// I'm not sure how helpful this is, to be honest, but it avoids a
674-
// lot of annoying errors in the compile-fail tests (basically,
675-
// lint warnings and so on -- kindck used to do this abort, but
676-
// kindck is gone now). -nmatsakis
677-
ty_cx.sess.abort_if_errors();
678-
679-
let reachable_map =
680-
time(time_passes, "reachability checking", (), |_|
681-
reachable::find_reachable(&ty_cx, &exported_items));
682-
683-
time(time_passes, "death checking", (), |_| {
684-
middle::dead::check_crate(&ty_cx,
685-
&exported_items,
686-
&reachable_map)
687-
});
688-
689-
let ref lib_features_used =
690-
time(time_passes, "stability checking", (), |_|
691-
stability::check_unstable_api_usage(&ty_cx));
692-
693-
time(time_passes, "unused lib feature checking", (), |_|
694-
stability::check_unused_or_stable_features(
695-
&ty_cx.sess, lib_features_used));
696-
697-
time(time_passes, "lint checking", (), |_|
698-
lint::check_crate(&ty_cx, &exported_items));
699-
700-
// The above three passes generate errors w/o aborting
701-
ty_cx.sess.abort_if_errors();
702-
703-
(ty_cx, ty::CrateAnalysis {
704-
export_map: export_map,
705-
exported_items: exported_items,
706-
public_items: public_items,
707-
reachable: reachable_map,
708-
name: name,
709-
glob_map: glob_map,
649+
ty::with_ctxt(sess,
650+
arenas,
651+
def_map,
652+
named_region_map,
653+
ast_map,
654+
freevars,
655+
region_map,
656+
lang_items,
657+
stability::Index::new(krate),
658+
|tcx| {
659+
660+
// passes are timed inside typeck
661+
typeck::check_crate(tcx, trait_map);
662+
663+
time(time_passes, "const checking", (), |_|
664+
middle::check_const::check_crate(tcx));
665+
666+
let (exported_items, public_items) =
667+
time(time_passes, "privacy checking", (), |_|
668+
rustc_privacy::check_crate(tcx, &export_map, external_exports));
669+
670+
// Do not move this check past lint
671+
time(time_passes, "stability index", (), |_|
672+
tcx.stability.borrow_mut().build(tcx, krate, &public_items));
673+
674+
time(time_passes, "intrinsic checking", (), |_|
675+
middle::intrinsicck::check_crate(tcx));
676+
677+
time(time_passes, "effect checking", (), |_|
678+
middle::effect::check_crate(tcx));
679+
680+
time(time_passes, "match checking", (), |_|
681+
middle::check_match::check_crate(tcx));
682+
683+
time(time_passes, "liveness checking", (), |_|
684+
middle::liveness::check_crate(tcx));
685+
686+
time(time_passes, "borrow checking", (), |_|
687+
borrowck::check_crate(tcx));
688+
689+
time(time_passes, "rvalue checking", (), |_|
690+
middle::check_rvalues::check_crate(tcx, krate));
691+
692+
// Avoid overwhelming user with errors if type checking failed.
693+
// I'm not sure how helpful this is, to be honest, but it avoids a
694+
// lot of annoying errors in the compile-fail tests (basically,
695+
// lint warnings and so on -- kindck used to do this abort, but
696+
// kindck is gone now). -nmatsakis
697+
tcx.sess.abort_if_errors();
698+
699+
let reachable_map =
700+
time(time_passes, "reachability checking", (), |_|
701+
reachable::find_reachable(tcx, &exported_items));
702+
703+
time(time_passes, "death checking", (), |_| {
704+
middle::dead::check_crate(tcx,
705+
&exported_items,
706+
&reachable_map)
707+
});
708+
709+
let ref lib_features_used =
710+
time(time_passes, "stability checking", (), |_|
711+
stability::check_unstable_api_usage(tcx));
712+
713+
time(time_passes, "unused lib feature checking", (), |_|
714+
stability::check_unused_or_stable_features(
715+
&tcx.sess, lib_features_used));
716+
717+
time(time_passes, "lint checking", (), |_|
718+
lint::check_crate(tcx, &exported_items));
719+
720+
// The above three passes generate errors w/o aborting
721+
tcx.sess.abort_if_errors();
722+
723+
f(tcx, ty::CrateAnalysis {
724+
export_map: export_map,
725+
exported_items: exported_items,
726+
public_items: public_items,
727+
reachable: reachable_map,
728+
name: name,
729+
glob_map: glob_map,
730+
})
710731
})
711732
}
712733

trunk/src/librustc_driver/pretty.rs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,15 @@ impl PpSourceMode {
148148
}
149149
PpmTyped => {
150150
let ast_map = ast_map.expect("--pretty=typed missing ast_map");
151-
let (tcx, _) = driver::phase_3_run_analysis_passes(sess,
152-
ast_map,
153-
arenas,
154-
id,
155-
resolve::MakeGlobMap::No);
156-
let annotation = TypedAnnotation { tcx: tcx };
157-
f(&annotation, payload)
151+
driver::phase_3_run_analysis_passes(sess,
152+
ast_map,
153+
arenas,
154+
id,
155+
resolve::MakeGlobMap::No,
156+
|tcx, _| {
157+
let annotation = TypedAnnotation { tcx: tcx };
158+
f(&annotation, payload)
159+
}).1
158160
}
159161
}
160162
}
@@ -284,11 +286,11 @@ impl<'ast> pprust::PpAnn for HygieneAnnotation<'ast> {
284286
}
285287

286288

287-
struct TypedAnnotation<'tcx> {
288-
tcx: ty::ctxt<'tcx>,
289+
struct TypedAnnotation<'a, 'tcx: 'a> {
290+
tcx: &'a ty::ctxt<'tcx>,
289291
}
290292

291-
impl<'tcx> PrinterSupport<'tcx> for TypedAnnotation<'tcx> {
293+
impl<'b, 'tcx> PrinterSupport<'tcx> for TypedAnnotation<'b, 'tcx> {
292294
fn sess<'a>(&'a self) -> &'a Session { &self.tcx.sess }
293295

294296
fn ast_map<'a>(&'a self) -> Option<&'a ast_map::Map<'tcx>> {
@@ -298,7 +300,7 @@ impl<'tcx> PrinterSupport<'tcx> for TypedAnnotation<'tcx> {
298300
fn pp_ann<'a>(&'a self) -> &'a pprust::PpAnn { self }
299301
}
300302

301-
impl<'tcx> pprust::PpAnn for TypedAnnotation<'tcx> {
303+
impl<'a, 'tcx> pprust::PpAnn for TypedAnnotation<'a, 'tcx> {
302304
fn pre(&self,
303305
s: &mut pprust::State,
304306
node: pprust::AnnNode) -> io::Result<()> {
@@ -645,12 +647,14 @@ pub fn pretty_print_input(sess: Session,
645647
match code {
646648
Some(code) => {
647649
let variants = gather_flowgraph_variants(&sess);
648-
let (tcx, _) = driver::phase_3_run_analysis_passes(sess,
649-
ast_map,
650-
&arenas,
651-
id,
652-
resolve::MakeGlobMap::No);
653-
print_flowgraph(variants, &tcx, code, mode, out)
650+
driver::phase_3_run_analysis_passes(sess,
651+
ast_map,
652+
&arenas,
653+
id,
654+
resolve::MakeGlobMap::No,
655+
|tcx, _| {
656+
print_flowgraph(variants, tcx, code, mode, out)
657+
}).1
654658
}
655659
None => {
656660
let message = format!("--pretty=flowgraph needs \

0 commit comments

Comments
 (0)