Skip to content

Commit 579c614

Browse files
committed
auto merge of #7124 : Aatch/rust/trans-refactor-pt1, r=brson
This removes all of the explicit `@mut` fields from `CrateContext`. There are still a few that are managed, but no longer do we have `@mut bool` in the structure. Most of the changes are changing `@CrateContext` to `@mut CrateContext`, though I did change as many as I could get away with to `&CrateContext` and `&mut CrateContext`. The biggest thing preventing me from changing to `&[mut]` in most places was the instruction counter thing. In two cases, where I got a static borrow error and a dynamic borrow error, I opted to remove the count call there as it was literally the only thing preventing me from switching to `&mut CrateContext` parameters in both cases. Other things to note: * the EncoderContext uses borrowed pointers with lifetimes, since it can, though that required me to work around the limitation of not being able to move a structure with borrowed pointers into a heap closure. I changed as much as I could to stack closures, but unfortunately I hit the AST visitor and changing that is somewhat outside the scope of this PR. Instead (and there is a comment to this effect) I choose to unsafely get the structure into the heap, this is because I know the lifetimes involved are safe, even though the compiler can't prove it. * Many of the changes are workarounds because of the borrow checker, either dynamically freezing it for too long, or inferring too large a scope. This is mostly just from nested function calls where each borrow is considered to last for the entire statement. Other cases are where `CrateContext` was borrowed in a `match` causing it to be borrowed for the entire length of the match, even though that wasn't wanted (or needed). * I haven't yet tested to see if this changes compilation times in any way. I doubt there will be much of an impact however, as the only major improvements are less indirection and fewer refcount bumps. * This lays the foundations to remove many more heap allocations in trans as many cases can be changed to use lifetimes instead. ===== This change includes some other, minor refactorings, as I am planning a series, however I don't want to submit them all at once as it will be hell to continually rebase.
2 parents 998e41a + f2a7fc6 commit 579c614

30 files changed

+1005
-844
lines changed

src/librustc/back/link.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use lib::llvm::ModuleRef;
1818
use lib;
1919
use metadata::common::LinkMeta;
2020
use metadata::{encoder, csearch, cstore};
21-
use middle::trans::common::CrateContext;
21+
use middle::trans::context::CrateContext;
2222
use middle::ty;
2323
use util::ppaux;
2424

@@ -622,11 +622,11 @@ pub fn symbol_hash(tcx: ty::ctxt,
622622
hash.to_managed()
623623
}
624624

625-
pub fn get_symbol_hash(ccx: @CrateContext, t: ty::t) -> @str {
625+
pub fn get_symbol_hash(ccx: &mut CrateContext, t: ty::t) -> @str {
626626
match ccx.type_hashcodes.find(&t) {
627627
Some(&h) => h,
628628
None => {
629-
let hash = symbol_hash(ccx.tcx, ccx.symbol_hasher, t, ccx.link_meta);
629+
let hash = symbol_hash(ccx.tcx, &mut ccx.symbol_hasher, t, ccx.link_meta);
630630
ccx.type_hashcodes.insert(t, hash);
631631
hash
632632
}
@@ -705,7 +705,7 @@ pub fn exported_name(sess: Session,
705705
path_name(sess.ident_of(vers))));
706706
}
707707

708-
pub fn mangle_exported_name(ccx: @CrateContext,
708+
pub fn mangle_exported_name(ccx: &mut CrateContext,
709709
path: path,
710710
t: ty::t) -> ~str {
711711
let hash = get_symbol_hash(ccx, t);
@@ -714,7 +714,7 @@ pub fn mangle_exported_name(ccx: @CrateContext,
714714
ccx.link_meta.vers);
715715
}
716716

717-
pub fn mangle_internal_name_by_type_only(ccx: @CrateContext,
717+
pub fn mangle_internal_name_by_type_only(ccx: &mut CrateContext,
718718
t: ty::t,
719719
name: &str) -> ~str {
720720
let s = ppaux::ty_to_short_str(ccx.tcx, t);
@@ -725,7 +725,7 @@ pub fn mangle_internal_name_by_type_only(ccx: @CrateContext,
725725
path_name(ccx.sess.ident_of(hash))]);
726726
}
727727

728-
pub fn mangle_internal_name_by_type_and_seq(ccx: @CrateContext,
728+
pub fn mangle_internal_name_by_type_and_seq(ccx: &mut CrateContext,
729729
t: ty::t,
730730
name: &str) -> ~str {
731731
let s = ppaux::ty_to_str(ccx.tcx, t);
@@ -736,18 +736,18 @@ pub fn mangle_internal_name_by_type_and_seq(ccx: @CrateContext,
736736
path_name((ccx.names)(name))]);
737737
}
738738

739-
pub fn mangle_internal_name_by_path_and_seq(ccx: @CrateContext,
739+
pub fn mangle_internal_name_by_path_and_seq(ccx: &mut CrateContext,
740740
path: path,
741741
flav: &str) -> ~str {
742742
return mangle(ccx.sess,
743743
vec::append_one(path, path_name((ccx.names)(flav))));
744744
}
745745

746-
pub fn mangle_internal_name_by_path(ccx: @CrateContext, path: path) -> ~str {
746+
pub fn mangle_internal_name_by_path(ccx: &mut CrateContext, path: path) -> ~str {
747747
return mangle(ccx.sess, path);
748748
}
749749

750-
pub fn mangle_internal_name_by_seq(ccx: @CrateContext, flav: &str) -> ~str {
750+
pub fn mangle_internal_name_by_seq(ccx: &mut CrateContext, flav: &str) -> ~str {
751751
return fmt!("%s_%u", flav, (ccx.names)(flav).name);
752752
}
753753

src/librustc/driver/driver.rs

Lines changed: 78 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -219,109 +219,109 @@ pub fn compile_rest(sess: Session,
219219
crate = time(time_passes, ~"intrinsic injection", ||
220220
front::intrinsic_inject::inject_intrinsic(sess, crate));
221221

222-
crate = time(time_passes, ~"extra injection", ||
223-
front::std_inject::maybe_inject_libstd_ref(sess, crate));
222+
crate = time(time_passes, ~"extra injection", ||
223+
front::std_inject::maybe_inject_libstd_ref(sess, crate));
224224

225-
let ast_map = time(time_passes, ~"ast indexing", ||
226-
syntax::ast_map::map_crate(sess.diagnostic(), crate));
225+
let ast_map = time(time_passes, ~"ast indexing", ||
226+
syntax::ast_map::map_crate(sess.diagnostic(), crate));
227227

228-
time(time_passes, ~"external crate/lib resolution", ||
229-
creader::read_crates(sess.diagnostic(), crate, sess.cstore,
230-
sess.filesearch,
231-
session::sess_os_to_meta_os(sess.targ_cfg.os),
232-
sess.opts.is_static,
233-
token::get_ident_interner()));
228+
time(time_passes, ~"external crate/lib resolution", ||
229+
creader::read_crates(sess.diagnostic(), crate, sess.cstore,
230+
sess.filesearch,
231+
session::sess_os_to_meta_os(sess.targ_cfg.os),
232+
sess.opts.is_static,
233+
token::get_ident_interner()));
234234

235-
let lang_items = time(time_passes, ~"language item collection", ||
236-
middle::lang_items::collect_language_items(crate, sess));
235+
let lang_items = time(time_passes, ~"language item collection", ||
236+
middle::lang_items::collect_language_items(crate, sess));
237237

238-
let middle::resolve::CrateMap {
239-
def_map: def_map,
240-
exp_map2: exp_map2,
241-
trait_map: trait_map
242-
} =
243-
time(time_passes, ~"resolution", ||
244-
middle::resolve::resolve_crate(sess, lang_items, crate));
238+
let middle::resolve::CrateMap {
239+
def_map: def_map,
240+
exp_map2: exp_map2,
241+
trait_map: trait_map
242+
} =
243+
time(time_passes, ~"resolution", ||
244+
middle::resolve::resolve_crate(sess, lang_items, crate));
245245

246-
time(time_passes, ~"looking for entry point",
247-
|| middle::entry::find_entry_point(sess, crate, ast_map));
246+
time(time_passes, ~"looking for entry point",
247+
|| middle::entry::find_entry_point(sess, crate, ast_map));
248248

249-
let freevars = time(time_passes, ~"freevar finding", ||
250-
freevars::annotate_freevars(def_map, crate));
249+
let freevars = time(time_passes, ~"freevar finding", ||
250+
freevars::annotate_freevars(def_map, crate));
251251

252-
let region_map = time(time_passes, ~"region resolution", ||
253-
middle::region::resolve_crate(sess, def_map, crate));
252+
let region_map = time(time_passes, ~"region resolution", ||
253+
middle::region::resolve_crate(sess, def_map, crate));
254254

255-
let rp_set = time(time_passes, ~"region parameterization inference", ||
256-
middle::region::determine_rp_in_crate(sess, ast_map, def_map, crate));
255+
let rp_set = time(time_passes, ~"region parameterization inference", ||
256+
middle::region::determine_rp_in_crate(sess, ast_map, def_map, crate));
257257

258-
let ty_cx = ty::mk_ctxt(sess, def_map, ast_map, freevars,
259-
region_map, rp_set, lang_items);
258+
let ty_cx = ty::mk_ctxt(sess, def_map, ast_map, freevars,
259+
region_map, rp_set, lang_items);
260260

261-
// passes are timed inside typeck
262-
let (method_map, vtable_map) = typeck::check_crate(
263-
ty_cx, trait_map, crate);
261+
// passes are timed inside typeck
262+
let (method_map, vtable_map) = typeck::check_crate(
263+
ty_cx, trait_map, crate);
264264

265-
// These next two const passes can probably be merged
266-
time(time_passes, ~"const marking", ||
267-
middle::const_eval::process_crate(crate, ty_cx));
265+
// These next two const passes can probably be merged
266+
time(time_passes, ~"const marking", ||
267+
middle::const_eval::process_crate(crate, ty_cx));
268268

269-
time(time_passes, ~"const checking", ||
270-
middle::check_const::check_crate(sess, crate, ast_map, def_map,
271-
method_map, ty_cx));
269+
time(time_passes, ~"const checking", ||
270+
middle::check_const::check_crate(sess, crate, ast_map, def_map,
271+
method_map, ty_cx));
272272

273-
if phases.to == cu_typeck { return (Some(crate), Some(ty_cx)); }
273+
if phases.to == cu_typeck { return (Some(crate), Some(ty_cx)); }
274274

275-
time(time_passes, ~"privacy checking", ||
276-
middle::privacy::check_crate(ty_cx, &method_map, crate));
275+
time(time_passes, ~"privacy checking", ||
276+
middle::privacy::check_crate(ty_cx, &method_map, crate));
277277

278-
time(time_passes, ~"effect checking", ||
279-
middle::effect::check_crate(ty_cx, method_map, crate));
278+
time(time_passes, ~"effect checking", ||
279+
middle::effect::check_crate(ty_cx, method_map, crate));
280280

281-
time(time_passes, ~"loop checking", ||
282-
middle::check_loop::check_crate(ty_cx, crate));
281+
time(time_passes, ~"loop checking", ||
282+
middle::check_loop::check_crate(ty_cx, crate));
283283

284-
let middle::moves::MoveMaps {moves_map, moved_variables_set,
285-
capture_map} =
286-
time(time_passes, ~"compute moves", ||
287-
middle::moves::compute_moves(ty_cx, method_map, crate));
284+
let middle::moves::MoveMaps {moves_map, moved_variables_set,
285+
capture_map} =
286+
time(time_passes, ~"compute moves", ||
287+
middle::moves::compute_moves(ty_cx, method_map, crate));
288288

289-
time(time_passes, ~"match checking", ||
290-
middle::check_match::check_crate(ty_cx, method_map,
291-
moves_map, crate));
289+
time(time_passes, ~"match checking", ||
290+
middle::check_match::check_crate(ty_cx, method_map,
291+
moves_map, crate));
292292

293-
time(time_passes, ~"liveness checking", ||
294-
middle::liveness::check_crate(ty_cx, method_map,
295-
capture_map, crate));
296-
297-
let (root_map, write_guard_map) =
298-
time(time_passes, ~"borrow checking", ||
299-
middle::borrowck::check_crate(ty_cx, method_map,
300-
moves_map, moved_variables_set,
293+
time(time_passes, ~"liveness checking", ||
294+
middle::liveness::check_crate(ty_cx, method_map,
301295
capture_map, crate));
302296

303-
time(time_passes, ~"kind checking", ||
304-
kind::check_crate(ty_cx, method_map, crate));
297+
let (root_map, write_guard_map) =
298+
time(time_passes, ~"borrow checking", ||
299+
middle::borrowck::check_crate(ty_cx, method_map,
300+
moves_map, moved_variables_set,
301+
capture_map, crate));
305302

306-
time(time_passes, ~"lint checking", ||
307-
lint::check_crate(ty_cx, crate));
303+
time(time_passes, ~"kind checking", ||
304+
kind::check_crate(ty_cx, method_map, crate));
308305

309-
if phases.to == cu_no_trans { return (Some(crate), Some(ty_cx)); }
306+
time(time_passes, ~"lint checking", ||
307+
lint::check_crate(ty_cx, crate));
310308

311-
let maps = astencode::Maps {
312-
root_map: root_map,
313-
method_map: method_map,
314-
vtable_map: vtable_map,
315-
write_guard_map: write_guard_map,
316-
moves_map: moves_map,
317-
capture_map: capture_map
318-
};
309+
if phases.to == cu_no_trans { return (Some(crate), Some(ty_cx)); }
319310

320-
let outputs = outputs.get_ref();
321-
time(time_passes, ~"translation", ||
322-
trans::base::trans_crate(sess, crate, ty_cx,
323-
&outputs.obj_filename,
324-
exp_map2, maps))
311+
let maps = astencode::Maps {
312+
root_map: root_map,
313+
method_map: method_map,
314+
vtable_map: vtable_map,
315+
write_guard_map: write_guard_map,
316+
moves_map: moves_map,
317+
capture_map: capture_map
318+
};
319+
320+
let outputs = outputs.get_ref();
321+
time(time_passes, ~"translation", ||
322+
trans::base::trans_crate(sess, crate, ty_cx,
323+
&outputs.obj_filename,
324+
exp_map2, maps))
325325
};
326326

327327
let outputs = outputs.get_ref();

0 commit comments

Comments
 (0)