Skip to content

Commit b92345e

Browse files
committed
---
yaml --- r: 142803 b: refs/heads/try2 c: 38dc832 h: refs/heads/master i: 142801: 0d4ff31 142799: fed6978 v: v3
1 parent 13f704e commit b92345e

File tree

2 files changed

+40
-21
lines changed

2 files changed

+40
-21
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: a8e4301a5d78409ae05669be3514e848316e48f8
8+
refs/heads/try2: 38dc832154c00b57a71294be4327225d134e4aec
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/librustc/middle/trans/type_use.rs

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ pub type type_uses = uint; // Bitmask
4949
pub static use_repr: uint = 1; /* Dependency on size/alignment/mode and
5050
take/drop glue */
5151
pub static use_tydesc: uint = 2; /* Takes the tydesc, or compares */
52+
pub static use_all: uint = use_repr|use_tydesc;
53+
5254

5355
pub struct Context {
5456
ccx: @mut CrateContext,
@@ -57,6 +59,14 @@ pub struct Context {
5759

5860
pub fn type_uses_for(ccx: @mut CrateContext, fn_id: def_id, n_tps: uint)
5961
-> @~[type_uses] {
62+
63+
fn store_type_uses(cx: Context, fn_id: def_id) -> @~[type_uses] {
64+
let Context { uses, ccx } = cx;
65+
let uses = @copy *uses; // freeze
66+
ccx.type_use_cache.insert(fn_id, uses);
67+
uses
68+
}
69+
6070
match ccx.type_use_cache.find(&fn_id) {
6171
Some(uses) => return *uses,
6272
None => ()
@@ -69,28 +79,25 @@ pub fn type_uses_for(ccx: @mut CrateContext, fn_id: def_id, n_tps: uint)
6979
};
7080

7181
// Conservatively assume full use for recursive loops
72-
ccx.type_use_cache.insert(fn_id, @vec::from_elem(n_tps, 3u));
82+
ccx.type_use_cache.insert(fn_id, @vec::from_elem(n_tps, use_all));
7383

7484
let cx = Context {
7585
ccx: ccx,
7686
uses: @mut vec::from_elem(n_tps, 0)
7787
};
78-
match ty::get(ty::lookup_item_type(cx.ccx.tcx, fn_id).ty).sty {
79-
ty::ty_bare_fn(ty::BareFnTy {sig: ref sig, _}) |
80-
ty::ty_closure(ty::ClosureTy {sig: ref sig, _}) => {
81-
for sig.inputs.iter().advance |arg| {
82-
type_needs(&cx, use_repr, *arg);
83-
}
84-
}
85-
_ => ()
86-
}
8788

88-
if fn_id_loc.crate != local_crate {
89-
let Context { uses, _ } = cx;
90-
let uses = @copy *uses; // freeze
91-
ccx.type_use_cache.insert(fn_id, uses);
92-
return uses;
89+
// If the method is a default method, we mark all of the types as
90+
// used. This is imprecise, but simple. Getting it right is
91+
// tricky because the substs on the call and the substs on the
92+
// default method differ, because of substs on the trait/impl.
93+
let is_default = ccx.tcx.provided_method_sources.contains_key(&fn_id_loc);
94+
// We also mark all of the params as used if it is an extern thing
95+
// that we haven't been able to inline yet.
96+
if is_default || fn_id_loc.crate != local_crate {
97+
for uint::range(0u, n_tps) |n| { cx.uses[n] |= use_all; }
98+
return store_type_uses(cx, fn_id);
9399
}
100+
94101
let map_node = match ccx.tcx.items.find(&fn_id_loc.node) {
95102
Some(x) => (/*bad*/copy *x),
96103
None => ccx.sess.bug(fmt!("type_uses_for: unbound item ID %?",
@@ -106,7 +113,10 @@ pub fn type_uses_for(ccx: @mut CrateContext, fn_id: def_id, n_tps: uint)
106113
// This will be a static trait method. For now, we just assume
107114
// it fully depends on all of the type information. (Doing
108115
// otherwise would require finding the actual implementation).
109-
for uint::range(0u, n_tps) |n| { cx.uses[n] |= use_repr|use_tydesc;}
116+
for uint::range(0u, n_tps) |n| { cx.uses[n] |= use_all;}
117+
// We need to return early, before the arguments are processed,
118+
// because of difficulties in the handling of Self.
119+
return store_type_uses(cx, fn_id);
110120
}
111121
ast_map::node_variant(_, _, _) => {
112122
for uint::range(0u, n_tps) |n| { cx.uses[n] |= use_repr;}
@@ -171,10 +181,19 @@ pub fn type_uses_for(ccx: @mut CrateContext, fn_id: def_id, n_tps: uint)
171181
token::get_ident_interner())));
172182
}
173183
}
174-
let Context { uses, _ } = cx;
175-
let uses = @copy *uses; // freeze
176-
ccx.type_use_cache.insert(fn_id, uses);
177-
uses
184+
185+
// Now handle arguments
186+
match ty::get(ty::lookup_item_type(cx.ccx.tcx, fn_id).ty).sty {
187+
ty::ty_bare_fn(ty::BareFnTy {sig: ref sig, _}) |
188+
ty::ty_closure(ty::ClosureTy {sig: ref sig, _}) => {
189+
for sig.inputs.iter().advance |arg| {
190+
type_needs(&cx, use_repr, *arg);
191+
}
192+
}
193+
_ => ()
194+
}
195+
196+
store_type_uses(cx, fn_id)
178197
}
179198

180199
pub fn type_needs(cx: &Context, use_: uint, ty: ty::t) {

0 commit comments

Comments
 (0)