Skip to content

Commit 0bb6de3

Browse files
committed
De-@ move maps and rework parts of trans.
1 parent 3f64d41 commit 0bb6de3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+982
-1068
lines changed

src/librustc/back/link.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ fn get_symbol_hash(ccx: &CrateContext, t: ty::t) -> ~str {
559559

560560
let mut type_hashcodes = ccx.type_hashcodes.borrow_mut();
561561
let mut symbol_hasher = ccx.symbol_hasher.borrow_mut();
562-
let hash = symbol_hash(ccx.tcx, symbol_hasher.get(), t, &ccx.link_meta);
562+
let hash = symbol_hash(ccx.tcx(), symbol_hasher.get(), t, &ccx.link_meta);
563563
type_hashcodes.get().insert(t, hash.clone());
564564
hash
565565
}
@@ -694,7 +694,7 @@ pub fn mangle_exported_name(ccx: &CrateContext, path: PathElems,
694694
pub fn mangle_internal_name_by_type_only(ccx: &CrateContext,
695695
t: ty::t,
696696
name: &str) -> ~str {
697-
let s = ppaux::ty_to_short_str(ccx.tcx, t);
697+
let s = ppaux::ty_to_short_str(ccx.tcx(), t);
698698
let path = [PathName(token::intern(name)),
699699
PathName(token::intern(s))];
700700
let hash = get_symbol_hash(ccx, t);
@@ -704,7 +704,7 @@ pub fn mangle_internal_name_by_type_only(ccx: &CrateContext,
704704
pub fn mangle_internal_name_by_type_and_seq(ccx: &CrateContext,
705705
t: ty::t,
706706
name: &str) -> ~str {
707-
let s = ppaux::ty_to_str(ccx.tcx, t);
707+
let s = ppaux::ty_to_str(ccx.tcx(), t);
708708
let path = [PathName(token::intern(s)),
709709
gensym_name(name)];
710710
let hash = get_symbol_hash(ccx, t);

src/librustc/driver/driver.rs

+19-12
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use std::cell::{Cell, RefCell};
3535
use std::io;
3636
use std::io::fs;
3737
use std::io::MemReader;
38+
use std::mem::drop;
3839
use std::os;
3940
use std::vec_ng::Vec;
4041
use std::vec_ng;
@@ -357,17 +358,20 @@ pub fn phase_3_run_analysis_passes(sess: Session,
357358

358359
time(time_passes, "match checking", (), |_|
359360
middle::check_match::check_crate(&ty_cx, method_map,
360-
moves_map, krate));
361+
&moves_map, krate));
361362

362363
time(time_passes, "liveness checking", (), |_|
363364
middle::liveness::check_crate(&ty_cx, method_map,
364-
capture_map, krate));
365+
&capture_map, krate));
365366

366367
let root_map =
367368
time(time_passes, "borrow checking", (), |_|
368369
middle::borrowck::check_crate(&ty_cx, method_map,
369-
moves_map, moved_variables_set,
370-
capture_map, krate));
370+
&moves_map, &moved_variables_set,
371+
&capture_map, krate));
372+
373+
drop(moves_map);
374+
drop(moved_variables_set);
371375

372376
time(time_passes, "kind checking", (), |_|
373377
kind::check_crate(&ty_cx, method_map, krate));
@@ -396,7 +400,7 @@ pub fn phase_3_run_analysis_passes(sess: Session,
396400
root_map: root_map,
397401
method_map: method_map,
398402
vtable_map: vtable_map,
399-
capture_map: capture_map
403+
capture_map: RefCell::new(capture_map)
400404
},
401405
reachable: reachable_map
402406
}
@@ -414,10 +418,13 @@ pub struct CrateTranslation {
414418
/// Run the translation phase to LLVM, after which the AST and analysis can
415419
/// be discarded.
416420
pub fn phase_4_translate_to_llvm(krate: ast::Crate,
417-
analysis: &CrateAnalysis,
418-
outputs: &OutputFilenames) -> CrateTranslation {
419-
time(analysis.ty_cx.sess.time_passes(), "translation", krate, |krate|
420-
trans::base::trans_crate(krate, analysis, outputs))
421+
analysis: CrateAnalysis,
422+
outputs: &OutputFilenames) -> (ty::ctxt, CrateTranslation) {
423+
// Option dance to work around the lack of stack once closures.
424+
let time_passes = analysis.ty_cx.sess.time_passes();
425+
let mut analysis = Some(analysis);
426+
time(time_passes, "translation", krate, |krate|
427+
trans::base::trans_crate(krate, analysis.take_unwrap(), outputs))
421428
}
422429

423430
/// Run LLVM itself, producing a bitcode file, assembly file or object file
@@ -582,9 +589,9 @@ pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &Input,
582589

583590
let analysis = phase_3_run_analysis_passes(sess, &expanded_crate, ast_map);
584591
if stop_after_phase_3(&analysis.ty_cx.sess) { return; }
585-
let trans = phase_4_translate_to_llvm(expanded_crate,
586-
&analysis, &outputs);
587-
(outputs, trans, analysis.ty_cx.sess)
592+
let (tcx, trans) = phase_4_translate_to_llvm(expanded_crate,
593+
analysis, &outputs);
594+
(outputs, trans, tcx.sess)
588595
};
589596
phase_5_run_llvm_passes(&sess, &trans, &outputs);
590597
if stop_after_phase_5(&sess) { return; }

src/librustc/middle/astencode.rs

+16-19
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use syntax;
3434

3535
use std::libc;
3636
use std::cast;
37+
use std::cell::RefCell;
3738
use std::io::Seek;
3839
use std::rc::Rc;
3940
use std::vec_ng::Vec;
@@ -53,13 +54,13 @@ pub struct Maps {
5354
root_map: middle::borrowck::root_map,
5455
method_map: middle::typeck::MethodMap,
5556
vtable_map: middle::typeck::vtable_map,
56-
capture_map: middle::moves::CaptureMap,
57+
capture_map: RefCell<middle::moves::CaptureMap>,
5758
}
5859

5960
struct DecodeContext<'a> {
6061
cdata: @cstore::crate_metadata,
6162
tcx: &'a ty::ctxt,
62-
maps: Maps
63+
maps: &'a Maps
6364
}
6465

6566
struct ExtendedDecodeContext<'a> {
@@ -82,7 +83,7 @@ trait tr_intern {
8283
pub fn encode_inlined_item(ecx: &e::EncodeContext,
8384
ebml_w: &mut writer::Encoder,
8485
ii: e::InlinedItemRef,
85-
maps: Maps) {
86+
maps: &Maps) {
8687
let id = match ii {
8788
e::IIItemRef(i) => i.id,
8889
e::IIForeignRef(i) => i.id,
@@ -115,7 +116,7 @@ pub fn encode_exported_macro(ebml_w: &mut writer::Encoder, i: &ast::Item) {
115116

116117
pub fn decode_inlined_item(cdata: @cstore::crate_metadata,
117118
tcx: &ty::ctxt,
118-
maps: Maps,
119+
maps: &Maps,
119120
path: Vec<ast_map::PathElem>,
120121
par_doc: ebml::Doc)
121122
-> Result<ast::InlinedItem, Vec<ast_map::PathElem>> {
@@ -906,7 +907,7 @@ impl<'a> write_tag_and_id for writer::Encoder<'a> {
906907
struct SideTableEncodingIdVisitor<'a,'b> {
907908
ecx_ptr: *libc::c_void,
908909
new_ebml_w: &'a mut writer::Encoder<'b>,
909-
maps: Maps,
910+
maps: &'a Maps,
910911
}
911912

912913
impl<'a,'b> ast_util::IdVisitingOperation for
@@ -929,7 +930,7 @@ impl<'a,'b> ast_util::IdVisitingOperation for
929930
}
930931

931932
fn encode_side_tables_for_ii(ecx: &e::EncodeContext,
932-
maps: Maps,
933+
maps: &Maps,
933934
ebml_w: &mut writer::Encoder,
934935
ii: &ast::InlinedItem) {
935936
ebml_w.start_tag(c::tag_table as uint);
@@ -951,7 +952,7 @@ fn encode_side_tables_for_ii(ecx: &e::EncodeContext,
951952
}
952953

953954
fn encode_side_tables_for_id(ecx: &e::EncodeContext,
954-
maps: Maps,
955+
maps: &Maps,
955956
ebml_w: &mut writer::Encoder,
956957
id: ast::NodeId) {
957958
let tcx = ecx.tcx;
@@ -1075,20 +1076,16 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
10751076
}
10761077
}
10771078

1078-
{
1079-
let capture_map = maps.capture_map.borrow();
1080-
let r = capture_map.get().find(&id);
1081-
for &cap_vars in r.iter() {
1082-
ebml_w.tag(c::tag_table_capture_map, |ebml_w| {
1083-
ebml_w.id(id);
1084-
ebml_w.tag(c::tag_table_val, |ebml_w| {
1085-
ebml_w.emit_from_vec(cap_vars.deref().as_slice(),
1086-
|ebml_w, cap_var| {
1087-
cap_var.encode(ebml_w);
1088-
})
1079+
for &cap_vars in maps.capture_map.borrow().get().find(&id).iter() {
1080+
ebml_w.tag(c::tag_table_capture_map, |ebml_w| {
1081+
ebml_w.id(id);
1082+
ebml_w.tag(c::tag_table_val, |ebml_w| {
1083+
ebml_w.emit_from_vec(cap_vars.deref().as_slice(),
1084+
|ebml_w, cap_var| {
1085+
cap_var.encode(ebml_w);
10891086
})
10901087
})
1091-
}
1088+
})
10921089
}
10931090
}
10941091

src/librustc/middle/borrowck/check_loans.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -715,9 +715,7 @@ impl<'a> CheckLoanCtxt<'a> {
715715
fn check_captured_variables(&self,
716716
closure_id: ast::NodeId,
717717
span: Span) {
718-
let capture_map = self.bccx.capture_map.borrow();
719-
let cap_vars = capture_map.get().get(&closure_id);
720-
for cap_var in cap_vars.deref().iter() {
718+
for cap_var in self.bccx.capture_map.get(&closure_id).deref().iter() {
721719
let var_id = ast_util::def_id_of_def(cap_var.def).node;
722720
let var_path = @LpVar(var_id);
723721
self.check_if_path_is_moved(closure_id, span,

src/librustc/middle/borrowck/gather_loans/gather_moves.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ pub fn gather_move_from_pat(bccx: &BorrowckCtxt,
4747
pub fn gather_captures(bccx: &BorrowckCtxt,
4848
move_data: &MoveData,
4949
closure_expr: &ast::Expr) {
50-
let capture_map = bccx.capture_map.borrow();
51-
let captured_vars = capture_map.get().get(&closure_expr.id);
52-
for captured_var in captured_vars.deref().iter() {
50+
for captured_var in bccx.capture_map.get(&closure_expr.id).deref().iter() {
5351
match captured_var.mode {
5452
moves::CapMove => {
5553
let cmt = bccx.cat_captured_var(closure_expr.id,

src/librustc/middle/borrowck/gather_loans/lifetime.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,7 @@ impl<'a> GuaranteeLifetimeContext<'a> {
261261
match cmt.guarantor().cat {
262262
mc::cat_local(id) |
263263
mc::cat_arg(id) => {
264-
let moved_variables_set = self.bccx
265-
.moved_variables_set
266-
.borrow();
267-
moved_variables_set.get().contains(&id)
264+
self.bccx.moved_variables_set.contains(&id)
268265
}
269266
mc::cat_rvalue(..) |
270267
mc::cat_static_item |

src/librustc/middle/borrowck/gather_loans/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,7 @@ impl<'a> GatherLoanCtxt<'a> {
440440

441441
fn guarantee_captures(&mut self,
442442
closure_expr: &ast::Expr) {
443-
let capture_map = self.bccx.capture_map.borrow();
444-
let captured_vars = capture_map.get().get(&closure_expr.id);
445-
for captured_var in captured_vars.deref().iter() {
443+
for captured_var in self.bccx.capture_map.get(&closure_expr.id).deref().iter() {
446444
match captured_var.mode {
447445
moves::CapCopy | moves::CapMove => { continue; }
448446
moves::CapRef => { }

src/librustc/middle/borrowck/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use middle::typeck;
1818
use middle::moves;
1919
use middle::dataflow::DataFlowContext;
2020
use middle::dataflow::DataFlowOperator;
21+
use util::nodemap::NodeSet;
2122
use util::ppaux::{note_and_explain_region, Repr, UserString};
2223

2324
use std::cell::{Cell, RefCell};
@@ -72,9 +73,9 @@ impl<'a> Visitor<()> for BorrowckCtxt<'a> {
7273

7374
pub fn check_crate(tcx: &ty::ctxt,
7475
method_map: typeck::MethodMap,
75-
moves_map: moves::MovesMap,
76-
moved_variables_set: moves::MovedVariablesSet,
77-
capture_map: moves::CaptureMap,
76+
moves_map: &NodeSet,
77+
moved_variables_set: &NodeSet,
78+
capture_map: &moves::CaptureMap,
7879
krate: &ast::Crate)
7980
-> root_map {
8081
let mut bccx = BorrowckCtxt {
@@ -157,9 +158,9 @@ fn borrowck_fn(this: &mut BorrowckCtxt,
157158
pub struct BorrowckCtxt<'a> {
158159
tcx: &'a ty::ctxt,
159160
method_map: typeck::MethodMap,
160-
moves_map: moves::MovesMap,
161-
moved_variables_set: moves::MovedVariablesSet,
162-
capture_map: moves::CaptureMap,
161+
moves_map: &'a NodeSet,
162+
moved_variables_set: &'a NodeSet,
163+
capture_map: &'a moves::CaptureMap,
163164
root_map: root_map,
164165

165166
// Statistics:
@@ -416,8 +417,7 @@ impl<'a> BorrowckCtxt<'a> {
416417
}
417418

418419
pub fn is_move(&self, id: ast::NodeId) -> bool {
419-
let moves_map = self.moves_map.borrow();
420-
moves_map.get().contains(&id)
420+
self.moves_map.contains(&id)
421421
}
422422

423423
pub fn mc(&self) -> mc::MemCategorizationContext<TcxTyper<'a>> {

src/librustc/middle/check_match.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use middle::pat_util::*;
1616
use middle::ty::*;
1717
use middle::ty;
1818
use middle::typeck::MethodMap;
19-
use middle::moves;
19+
use util::nodemap::NodeSet;
2020
use util::ppaux::ty_to_str;
2121

2222
use std::cmp;
@@ -33,7 +33,7 @@ use syntax::visit::{Visitor, FnKind};
3333
struct MatchCheckCtxt<'a> {
3434
tcx: &'a ty::ctxt,
3535
method_map: MethodMap,
36-
moves_map: moves::MovesMap
36+
moves_map: &'a NodeSet
3737
}
3838

3939
impl<'a> Visitor<()> for MatchCheckCtxt<'a> {
@@ -50,7 +50,7 @@ impl<'a> Visitor<()> for MatchCheckCtxt<'a> {
5050

5151
pub fn check_crate(tcx: &ty::ctxt,
5252
method_map: MethodMap,
53-
moves_map: moves::MovesMap,
53+
moves_map: &NodeSet,
5454
krate: &Crate) {
5555
let mut cx = MatchCheckCtxt {
5656
tcx: tcx,
@@ -953,8 +953,7 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt,
953953
by_ref_span = Some(span);
954954
}
955955
BindByValue(_) => {
956-
let moves_map = cx.moves_map.borrow();
957-
if moves_map.get().contains(&id) {
956+
if cx.moves_map.contains(&id) {
958957
any_by_move = true;
959958
}
960959
}
@@ -991,8 +990,7 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt,
991990
if pat_is_binding(def_map, p) {
992991
match p.node {
993992
PatIdent(_, _, sub) => {
994-
let moves_map = cx.moves_map.borrow();
995-
if moves_map.get().contains(&p.id) {
993+
if cx.moves_map.contains(&p.id) {
996994
check_move(p, sub);
997995
}
998996
}

src/librustc/middle/const_eval.rs

+9-18
Original file line numberDiff line numberDiff line change
@@ -126,23 +126,18 @@ pub fn lookup_variant_by_id(tcx: &ty::ctxt,
126126
}
127127
}
128128
} else {
129-
{
130-
let extern_const_variants = tcx.extern_const_variants.borrow();
131-
match extern_const_variants.get().find(&variant_def) {
132-
Some(&e) => return e,
133-
None => {}
134-
}
129+
match tcx.extern_const_variants.borrow().get().find(&variant_def) {
130+
Some(&e) => return e,
131+
None => {}
135132
}
136133
let maps = astencode::Maps {
137134
root_map: @RefCell::new(HashMap::new()),
138135
method_map: @RefCell::new(FnvHashMap::new()),
139136
vtable_map: @RefCell::new(NodeMap::new()),
140-
capture_map: @RefCell::new(NodeMap::new())
137+
capture_map: RefCell::new(NodeMap::new())
141138
};
142139
let e = match csearch::maybe_get_item_ast(tcx, enum_def,
143-
|a, b, c, d| astencode::decode_inlined_item(a, b,
144-
maps,
145-
c, d)) {
140+
|a, b, c, d| astencode::decode_inlined_item(a, b, &maps, c, d)) {
146141
csearch::found(ast::IIItem(item)) => match item.node {
147142
ItemEnum(ast::EnumDef { variants: ref variants }, _) => {
148143
variant_expr(variants.as_slice(), variant_def.node)
@@ -151,12 +146,8 @@ pub fn lookup_variant_by_id(tcx: &ty::ctxt,
151146
},
152147
_ => None
153148
};
154-
{
155-
let mut extern_const_variants = tcx.extern_const_variants
156-
.borrow_mut();
157-
extern_const_variants.get().insert(variant_def, e);
158-
return e;
159-
}
149+
tcx.extern_const_variants.borrow_mut().get().insert(variant_def, e);
150+
return e;
160151
}
161152
}
162153

@@ -187,10 +178,10 @@ pub fn lookup_const_by_id(tcx: &ty::ctxt, def_id: ast::DefId)
187178
root_map: @RefCell::new(HashMap::new()),
188179
method_map: @RefCell::new(FnvHashMap::new()),
189180
vtable_map: @RefCell::new(NodeMap::new()),
190-
capture_map: @RefCell::new(NodeMap::new())
181+
capture_map: RefCell::new(NodeMap::new())
191182
};
192183
let e = match csearch::maybe_get_item_ast(tcx, def_id,
193-
|a, b, c, d| astencode::decode_inlined_item(a, b, maps, c, d)) {
184+
|a, b, c, d| astencode::decode_inlined_item(a, b, &maps, c, d)) {
194185
csearch::found(ast::IIItem(item)) => match item.node {
195186
ItemStatic(_, ast::MutImmutable, const_expr) => Some(const_expr),
196187
_ => None

0 commit comments

Comments
 (0)