Skip to content

Commit 3bcd4fe

Browse files
committed
Start on in-crate monomorphizing
Adds a --monomorpize flag to rustc to turn it on. You probably don't want to use it yet, since it's broken in a whole bunch of ways, but it successfully monomorphizes simple generic functions called from within the crate. Issue #1736
1 parent a02f332 commit 3bcd4fe

File tree

12 files changed

+169
-125
lines changed

12 files changed

+169
-125
lines changed

src/comp/driver/driver.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ fn build_session_options(match: getopts::match,
357357
if opt_present(match, "no-lint-ctypes") {
358358
lint_opts += [(lint::ctypes, false)];
359359
}
360+
let monomorphize = opt_present(match, "monomorphize");
360361

361362
let output_type =
362363
if parse_only || no_trans {
@@ -434,6 +435,7 @@ fn build_session_options(match: getopts::match,
434435
parse_only: parse_only,
435436
no_trans: no_trans,
436437
no_asm_comments: no_asm_comments,
438+
monomorphize: monomorphize,
437439
warn_unused_imports: warn_unused_imports};
438440
ret sopts;
439441
}
@@ -493,6 +495,7 @@ fn opts() -> [getopts::opt] {
493495
optflag("time-passes"), optflag("time-llvm-passes"),
494496
optflag("no-verify"),
495497
optflag("no-lint-ctypes"),
498+
optflag("monomorphize"),
496499
optmulti("cfg"), optflag("test"),
497500
optflag("lib"), optflag("bin"), optflag("static"), optflag("gc"),
498501
optflag("no-asm-comments"),

src/comp/driver/session.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type options =
4747
parse_only: bool,
4848
no_trans: bool,
4949
no_asm_comments: bool,
50+
monomorphize: bool,
5051
warn_unused_imports: bool};
5152

5253
type crate_metadata = {name: str, data: [u8]};

src/comp/middle/debuginfo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ fn create_local_var(bcx: @block_ctxt, local: @ast::local)
668668
});
669669
let loc = codemap::lookup_char_pos(cx.sess.codemap,
670670
local.span.lo);
671-
let ty = base::node_id_type(cx, local.node.id);
671+
let ty = node_id_type(bcx, local.node.id);
672672
let tymd = create_ty(cx, ty, local.node.ty);
673673
let filemd = create_file(cx, loc.filename);
674674
let context = alt bcx.parent {
@@ -717,7 +717,7 @@ fn create_arg(bcx: @block_ctxt, arg: ast::arg, sp: span)
717717
};*/
718718
let loc = codemap::lookup_char_pos(cx.sess.codemap,
719719
sp.lo);
720-
let ty = base::node_id_type(cx, arg.id);
720+
let ty = node_id_type(bcx, arg.id);
721721
let tymd = create_ty(cx, ty, arg.ty);
722722
let filemd = create_file(cx, loc.filename);
723723
let context = create_function(bcx.fcx);

src/comp/middle/trans/alt.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ fn trans_alt(cx: @block_ctxt, expr: @ast::expr, arms_: [ast::arm],
692692
}
693693

694694
let exit_map = [];
695-
let t = base::node_id_type(cx.fcx.ccx, expr.id);
695+
let t = node_id_type(cx, expr.id);
696696
let vr = base::spill_if_immediate(er.bcx, er.val, t);
697697
compile_submatch(vr.bcx, match, [vr.val],
698698
bind mk_fail(alt_cx, expr.span, fail_cx), exit_map);
@@ -725,7 +725,7 @@ fn bind_irrefutable_pat(bcx: @block_ctxt, pat: @ast::pat, val: ValueRef,
725725
alt normalize_pat(bcx_tcx(bcx), pat).node {
726726
ast::pat_ident(_,inner) {
727727
if make_copy || ccx.copy_map.contains_key(pat.id) {
728-
let ty = ty::node_id_to_type(ccx.tcx, pat.id);
728+
let ty = node_id_type(bcx, pat.id);
729729
// FIXME: Could constrain pat_bind to make this
730730
// check unnecessary.
731731
check (type_has_static_size(ccx, ty));
@@ -753,7 +753,7 @@ fn bind_irrefutable_pat(bcx: @block_ctxt, pat: @ast::pat, val: ValueRef,
753753
}
754754
}
755755
ast::pat_rec(fields, _) {
756-
let rec_ty = ty::node_id_to_type(ccx.tcx, pat.id);
756+
let rec_ty = node_id_type(bcx, pat.id);
757757
let rec_fields = ty::get_fields(ccx.tcx, rec_ty);
758758
for f: ast::field_pat in fields {
759759
let ix = option::get(ty::field_idx(f.ident, rec_fields));
@@ -764,7 +764,7 @@ fn bind_irrefutable_pat(bcx: @block_ctxt, pat: @ast::pat, val: ValueRef,
764764
}
765765
}
766766
ast::pat_tup(elems) {
767-
let tup_ty = ty::node_id_to_type(ccx.tcx, pat.id);
767+
let tup_ty = node_id_type(bcx, pat.id);
768768
let i = 0u;
769769
for elem in elems {
770770
// how to get rid of this check?

0 commit comments

Comments
 (0)