Skip to content

Commit 96e01a6

Browse files
committed
librustc: Convert some large structural records over to structs. rs=perf
No effect on compile-time performance.
1 parent fa96740 commit 96e01a6

File tree

9 files changed

+81
-54
lines changed

9 files changed

+81
-54
lines changed

src/librustc/middle/trans/base.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,8 +1086,13 @@ fn new_block(cx: fn_ctxt, parent: Option<block>, +kind: block_kind,
10861086
}
10871087

10881088
fn simple_block_scope() -> block_kind {
1089-
block_scope({loop_break: None, loop_label: None, mut cleanups: ~[],
1090-
mut cleanup_paths: ~[], mut landing_pad: None})
1089+
block_scope(scope_info {
1090+
loop_break: None,
1091+
loop_label: None,
1092+
mut cleanups: ~[],
1093+
mut cleanup_paths: ~[],
1094+
mut landing_pad: None
1095+
})
10911096
}
10921097

10931098
// Use this when you're at the top block of a function or the like.
@@ -1105,7 +1110,7 @@ fn scope_block(bcx: block,
11051110

11061111
fn loop_scope_block(bcx: block, loop_break: block, loop_label: Option<ident>,
11071112
n: ~str, opt_node_info: Option<node_info>) -> block {
1108-
return new_block(bcx.fcx, Some(bcx), block_scope({
1113+
return new_block(bcx.fcx, Some(bcx), block_scope(scope_info {
11091114
loop_break: Some(loop_break),
11101115
loop_label: loop_label,
11111116
mut cleanups: ~[],
@@ -1436,7 +1441,8 @@ fn new_fn_ctxt_w_id(ccx: @crate_ctxt,
14361441
param_substs: Option<param_substs>,
14371442
sp: Option<span>) -> fn_ctxt {
14381443
let llbbs = mk_standard_basic_blocks(llfndecl);
1439-
return @{llfn: llfndecl,
1444+
return @fn_ctxt_ {
1445+
llfn: llfndecl,
14401446
llenv: llvm::LLVMGetParam(llfndecl, 1u as c_uint),
14411447
llretptr: llvm::LLVMGetParam(llfndecl, 0u as c_uint),
14421448
mut llstaticallocas: llbbs.sa,
@@ -1453,7 +1459,8 @@ fn new_fn_ctxt_w_id(ccx: @crate_ctxt,
14531459
param_substs: param_substs,
14541460
span: sp,
14551461
path: path,
1456-
ccx: ccx};
1462+
ccx: ccx
1463+
};
14571464
}
14581465
14591466
fn new_fn_ctxt(ccx: @crate_ctxt, path: path, llfndecl: ValueRef,
@@ -2814,8 +2821,8 @@ fn trans_crate(sess: session::Session,
28142821
option::None
28152822
};
28162823

2817-
let ccx =
2818-
@{sess: sess,
2824+
let ccx = @crate_ctxt {
2825+
sess: sess,
28192826
llmod: llmod,
28202827
td: td,
28212828
tn: tn,
@@ -2875,8 +2882,8 @@ fn trans_crate(sess: session::Session,
28752882
crate_map: crate_map,
28762883
mut uses_gc: false,
28772884
dbg_cx: dbg_cx,
2878-
mut do_not_commit_warning_issued: false};
2879-
2885+
mut do_not_commit_warning_issued: false
2886+
};
28802887

28812888
gather_rtcalls(ccx, crate);
28822889

src/librustc/middle/trans/common.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ fn BuilderRef_res(B: BuilderRef) -> BuilderRef_res {
141141
}
142142

143143
// Crate context. Every crate we compile has one of these.
144-
type crate_ctxt = {
144+
struct crate_ctxt {
145145
sess: session::Session,
146146
llmod: ModuleRef,
147147
td: target_data,
@@ -211,7 +211,8 @@ type crate_ctxt = {
211211
// is not emitted by LLVM's GC pass when no functions use GC.
212212
mut uses_gc: bool,
213213
dbg_cx: Option<debuginfo::debug_ctxt>,
214-
mut do_not_commit_warning_issued: bool};
214+
mut do_not_commit_warning_issued: bool
215+
}
215216

216217
// Types used for llself.
217218
struct ValSelfData {
@@ -224,10 +225,12 @@ enum local_val { local_mem(ValueRef), local_imm(ValueRef), }
224225

225226
// Here `self_ty` is the real type of the self parameter to this method. It
226227
// will only be set in the case of default methods.
227-
type param_substs = {tys: ~[ty::t],
228-
vtables: Option<typeck::vtable_res>,
229-
bounds: @~[ty::param_bounds],
230-
self_ty: Option<ty::t>};
228+
struct param_substs {
229+
tys: ~[ty::t],
230+
vtables: Option<typeck::vtable_res>,
231+
bounds: @~[ty::param_bounds],
232+
self_ty: Option<ty::t>
233+
}
231234

232235
fn param_substs_to_str(tcx: ty::ctxt, substs: &param_substs) -> ~str {
233236
fmt!("param_substs {tys:%?, vtables:%?, bounds:%?}",
@@ -238,7 +241,7 @@ fn param_substs_to_str(tcx: ty::ctxt, substs: &param_substs) -> ~str {
238241

239242
// Function context. Every LLVM function we create will have one of
240243
// these.
241-
type fn_ctxt = @{
244+
struct fn_ctxt_ {
242245
// The ValueRef returned from a call to llvm::LLVMAddFunction; the
243246
// address of the first instruction in the sequence of
244247
// instructions for this function that will go in the .text
@@ -302,7 +305,9 @@ type fn_ctxt = @{
302305

303306
// This function's enclosing crate context.
304307
ccx: @crate_ctxt
305-
};
308+
}
309+
310+
pub type fn_ctxt = @fn_ctxt_;
306311

307312
fn warn_not_to_commit(ccx: @crate_ctxt, msg: ~str) {
308313
if !ccx.do_not_commit_warning_issued {
@@ -484,7 +489,7 @@ enum block_kind {
484489
block_non_scope,
485490
}
486491

487-
type scope_info = {
492+
struct scope_info {
488493
loop_break: Option<block>,
489494
loop_label: Option<ident>,
490495
// A list of functions that must be run at when leaving this
@@ -496,7 +501,7 @@ type scope_info = {
496501
mut cleanup_paths: ~[cleanup_path],
497502
// Unwinding landing pad. Also cleared when cleanups change.
498503
mut landing_pad: Option<BasicBlockRef>,
499-
};
504+
}
500505

501506
trait get_node_info {
502507
fn info() -> Option<node_info>;
@@ -1171,11 +1176,11 @@ enum mono_param_id {
11711176
datum::DatumMode),
11721177
}
11731178
1174-
type mono_id_ = {
1179+
struct mono_id_ {
11751180
def: ast::def_id,
11761181
params: ~[mono_param_id],
11771182
impl_did_opt: Option<ast::def_id>
1178-
};
1183+
}
11791184
11801185
type mono_id = @mono_id_;
11811186

src/librustc/middle/trans/controlflow.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,11 @@ fn trans_break_cont(bcx: block, opt_label: Option<ident>, to_end: bool)
224224
let mut target;
225225
loop {
226226
match unwind.kind {
227-
block_scope({loop_break: Some(brk), loop_label: l, _}) => {
227+
block_scope(scope_info {
228+
loop_break: Some(brk),
229+
loop_label: l,
230+
_
231+
}) => {
228232
// If we're looking for a labeled loop, check the label...
229233
target = if to_end {
230234
brk

src/librustc/middle/trans/meth.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ fn trans_impl(ccx: @crate_ctxt, path: path, name: ast::ident,
5959
match self_ty {
6060
None => param_substs_opt = None,
6161
Some(self_ty) => {
62-
param_substs_opt = Some({
62+
param_substs_opt = Some(param_substs {
6363
tys: ~[],
6464
vtables: None,
6565
bounds: @~[],
@@ -112,7 +112,7 @@ fn trans_method(ccx: @crate_ctxt,
112112
}
113113
let self_ty = match param_substs {
114114
None => self_ty,
115-
Some({tys: ref tys, _}) => {
115+
Some(param_substs {tys: ref tys, _}) => {
116116
ty::subst_tps(ccx.tcx, *tys, None, self_ty)
117117
}
118118
};
@@ -722,9 +722,11 @@ fn vtable_id(ccx: @crate_ctxt, origin: typeck::vtable_origin) -> mono_id {
722722
None)
723723
}
724724
typeck::vtable_trait(trait_id, substs) => {
725-
@{def: trait_id,
726-
params: vec::map(substs, |t| mono_precise(*t, None)),
727-
impl_did_opt: None}
725+
@mono_id_ {
726+
def: trait_id,
727+
params: vec::map(substs, |t| mono_precise(*t, None)),
728+
impl_did_opt: None
729+
}
728730
}
729731
// can't this be checked at the callee?
730732
_ => fail ~"vtable_id"

src/librustc/middle/trans/monomorphize.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ fn monomorphic_fn(ccx: @crate_ctxt,
156156
lldecl
157157
};
158158

159-
let psubsts = Some({
159+
let psubsts = Some(param_substs {
160160
tys: substs,
161161
vtables: vtables,
162162
bounds: tpt.bounds,
@@ -381,5 +381,5 @@ fn make_mono_id(ccx: @crate_ctxt, item: ast::def_id, substs: ~[ty::t],
381381
})
382382
}
383383
};
384-
@{def: item, params: param_ids, impl_did_opt: impl_did_opt}
384+
@mono_id_ {def: item, params: param_ids, impl_did_opt: impl_did_opt}
385385
}

src/librustc/middle/trans/reachable.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,22 @@ export map, find_reachable;
3232

3333
type map = HashMap<node_id, ()>;
3434

35-
type ctx = {exp_map2: resolve::ExportMap2,
36-
tcx: ty::ctxt,
37-
method_map: typeck::method_map,
38-
rmap: map};
35+
struct ctx {
36+
exp_map2: resolve::ExportMap2,
37+
tcx: ty::ctxt,
38+
method_map: typeck::method_map,
39+
rmap: map
40+
}
3941

4042
fn find_reachable(crate_mod: _mod, exp_map2: resolve::ExportMap2,
4143
tcx: ty::ctxt, method_map: typeck::method_map) -> map {
4244
let rmap = HashMap();
43-
let cx = {exp_map2: exp_map2, tcx: tcx,
44-
method_map: method_map, rmap: rmap};
45+
let cx = ctx {
46+
exp_map2: exp_map2,
47+
tcx: tcx,
48+
method_map: method_map,
49+
rmap: rmap
50+
};
4551
traverse_public_mod(cx, ast::crate_node_id, crate_mod);
4652
traverse_all_resources_and_impls(cx, crate_mod);
4753
rmap

src/librustc/middle/typeck/check/alt.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fn check_alt(fcx: @fn_ctxt,
3333
// Typecheck the patterns first, so that we get types for all the
3434
// bindings.
3535
for arms.each |arm| {
36-
let pcx = {
36+
let pcx = pat_ctxt {
3737
fcx: fcx,
3838
map: pat_id_map(tcx.def_map, arm.pats[0]),
3939
alt_region: ty::re_scope(expr.id),
@@ -61,12 +61,12 @@ fn check_alt(fcx: @fn_ctxt,
6161
return bot;
6262
}
6363

64-
type pat_ctxt = {
64+
struct pat_ctxt {
6565
fcx: @fn_ctxt,
6666
map: PatIdMap,
6767
alt_region: ty::Region, // Region for the alt as a whole
6868
block_region: ty::Region, // Region for the block of the arm
69-
};
69+
}
7070

7171
fn check_pat_variant(pcx: pat_ctxt, pat: @ast::pat, path: @ast::path,
7272
subpats: Option<~[@ast::pat]>, expected: ty::t) {

src/librustc/middle/typeck/check/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ use middle::ty;
8484
use middle::typeck::astconv::{ast_conv, ast_path_to_ty};
8585
use middle::typeck::astconv::{ast_region_to_region, ast_ty_to_ty};
8686
use middle::typeck::astconv;
87+
use middle::typeck::check::alt::pat_ctxt;
8788
use middle::typeck::check::method::TransformTypeNormally;
8889
use middle::typeck::check::regionmanip::replace_bound_regions_in_fn_ty;
8990
use middle::typeck::check::vtable::{LocationInfo, VtableContext};
@@ -421,7 +422,7 @@ fn check_fn(ccx: @crate_ctxt,
421422

422423
// Check the pattern.
423424
let region = fcx.block_region();
424-
let pcx = {
425+
let pcx = pat_ctxt {
425426
fcx: fcx,
426427
map: pat_id_map(tcx.def_map, input.pat),
427428
alt_region: region,
@@ -2485,7 +2486,7 @@ fn check_decl_local(fcx: @fn_ctxt, local: @ast::local) -> bool {
24852486

24862487
let region =
24872488
ty::re_scope(tcx.region_map.get(local.node.id));
2488-
let pcx = {
2489+
let pcx = pat_ctxt {
24892490
fcx: fcx,
24902491
map: pat_id_map(tcx.def_map, local.node.pat),
24912492
alt_region: region,

src/librustc/middle/typeck/mod.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -216,16 +216,17 @@ impl vtable_origin {
216216

217217
type vtable_map = HashMap<ast::node_id, vtable_res>;
218218

219-
type crate_ctxt_ = {// A mapping from method call sites to traits that have
220-
// that method.
221-
trait_map: resolve::TraitMap,
222-
method_map: method_map,
223-
vtable_map: vtable_map,
224-
coherence_info: @coherence::CoherenceInfo,
225-
tcx: ty::ctxt};
219+
struct crate_ctxt__ {
220+
// A mapping from method call sites to traits that have that method.
221+
trait_map: resolve::TraitMap,
222+
method_map: method_map,
223+
vtable_map: vtable_map,
224+
coherence_info: @coherence::CoherenceInfo,
225+
tcx: ty::ctxt
226+
}
226227

227228
enum crate_ctxt {
228-
crate_ctxt_(crate_ctxt_)
229+
crate_ctxt_(crate_ctxt__)
229230
}
230231

231232
// Functions that write types into the node type table
@@ -392,12 +393,13 @@ fn check_crate(tcx: ty::ctxt,
392393
crate: @ast::crate)
393394
-> (method_map, vtable_map) {
394395

395-
let ccx = @crate_ctxt_({trait_map: trait_map,
396-
method_map: map::HashMap(),
397-
vtable_map: map::HashMap(),
398-
coherence_info: @coherence::CoherenceInfo(),
399-
tcx: tcx
400-
});
396+
let ccx = @crate_ctxt_(crate_ctxt__ {
397+
trait_map: trait_map,
398+
method_map: map::HashMap(),
399+
vtable_map: map::HashMap(),
400+
coherence_info: @coherence::CoherenceInfo(),
401+
tcx: tcx
402+
});
401403
collect::collect_item_types(ccx, crate);
402404
coherence::check_coherence(ccx, crate);
403405

0 commit comments

Comments
 (0)