Skip to content

Commit 75e6fb4

Browse files
committed
Fix monomorphization of resource constructors
1 parent 0e5da37 commit 75e6fb4

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/rustc/middle/trans/base.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2137,6 +2137,11 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, substs: [ty::t],
21372137
ast_map::node_method(m, _, pt) { (pt, m.ident) }
21382138
// We can't monomorphize native functions
21392139
ast_map::node_native_item(_, _, _) { ret none; }
2140+
ast_map::node_ctor(i) {
2141+
alt check ccx.tcx.items.get(i.id) {
2142+
ast_map::node_item(i, pt) { (pt, i.ident) }
2143+
}
2144+
}
21402145
_ { fail "unexpected node type"; }
21412146
};
21422147
let pt = *pt + [path_name(ccx.names(name))];
@@ -2146,26 +2151,37 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, substs: [ty::t],
21462151

21472152
let psubsts = some({tys: substs, dicts: dicts, bounds: tpt.bounds});
21482153
alt check map_node {
2149-
ast_map::node_item(@{node: ast::item_fn(decl, _, body), _}, _) {
2154+
ast_map::node_item(i@@{node: ast::item_fn(decl, _, body), _}, _) {
2155+
set_inline_hint_if_appr(i.attrs, lldecl);
21502156
trans_fn(ccx, pt, decl, body, lldecl, no_self, [],
21512157
psubsts, fn_id.node, none);
21522158
}
2153-
ast_map::node_item(@{node: ast::item_res(decl, _, _, _, _), _}, _) {
2154-
trans_res_ctor(ccx, pt, decl, fn_id.node, [], psubsts, lldecl);
2155-
}
21562159
ast_map::node_variant(v, enum_item, _) {
21572160
let tvs = ty::enum_variants(ccx.tcx, local_def(enum_item.id));
21582161
let this_tv = option::get(vec::find(*tvs, {|tv|
21592162
tv.id.node == fn_id.node}));
2163+
set_inline_hint(lldecl);
21602164
trans_enum_variant(ccx, enum_item.id, v, this_tv.disr_val,
21612165
(*tvs).len() == 1u, [], psubsts, lldecl);
21622166
}
21632167
ast_map::node_method(mth, impl_def_id, _) {
2168+
set_inline_hint_if_appr(mth.attrs, lldecl);
21642169
let selfty = ty::node_id_to_type(ccx.tcx, mth.self_id);
21652170
let selfty = ty::substitute_type_params(ccx.tcx, substs, selfty);
21662171
trans_fn(ccx, pt, mth.decl, mth.body, lldecl,
21672172
impl_self(selfty), [], psubsts, fn_id.node, none);
21682173
}
2174+
ast_map::node_ctor(i) {
2175+
alt check ccx.tcx.items.get(i.id) {
2176+
ast_map::node_item(@{node: ast::item_res(decl, _, _, _, _), _}, _) {
2177+
set_inline_hint(lldecl);
2178+
trans_res_ctor(ccx, pt, decl, fn_id.node, [], psubsts, lldecl);
2179+
}
2180+
ast_map::node_item(@{node: ast::item_class(_, _, ctor), _}, _) {
2181+
ccx.sess.unimpl("monomorphic class constructor");
2182+
}
2183+
}
2184+
}
21692185
}
21702186
some({llfn: lldecl, fty: mono_ty})
21712187
}
@@ -4433,6 +4449,7 @@ fn trans_item(ccx: @crate_ctxt, item: ast::item) {
44334449
native::trans_native_mod(ccx, native_mod, abi);
44344450
}
44354451
ast::item_class(tps, items, ctor) {
4452+
// FIXME factor our ctor translation, call from monomorphic_fn
44364453
let llctor_decl = get_item_val(ccx, ctor.node.id);
44374454
// Translate the ctor
44384455
// First, add a preamble that

0 commit comments

Comments
 (0)