Skip to content

Commit 13fc615

Browse files
committed
---
yaml --- r: 64223 b: refs/heads/snap-stage3 c: 7e97277 h: refs/heads/master i: 64221: 0f4bd73 64219: d17572a 64215: 6495056 64207: 63c2753 64191: 91e4ac4 v: v3
1 parent 2e56f81 commit 13fc615

File tree

8 files changed

+51
-224
lines changed

8 files changed

+51
-224
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 278ed50e0a66f4c549e43c82e4a545890091e9ba
4+
refs/heads/snap-stage3: 7e972772890ec0d28d2aa4e7ff5c7b004e5463e8
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/librustc/middle/trans/closure.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -220,24 +220,16 @@ pub fn store_environment(bcx: block,
220220
// compute the type of the closure
221221
let cdata_ty = mk_closure_tys(tcx, bound_values);
222222

223+
// allocate closure in the heap
224+
let Result {bcx: bcx, val: llbox} = allocate_cbox(bcx, sigil, cdata_ty);
225+
223226
// cbox_ty has the form of a tuple: (a, b, c) we want a ptr to a
224227
// tuple. This could be a ptr in uniq or a box or on stack,
225228
// whatever.
226229
let cbox_ty = tuplify_box_ty(tcx, cdata_ty);
227230
let cboxptr_ty = ty::mk_ptr(tcx, ty::mt {ty:cbox_ty, mutbl:ast::m_imm});
228-
let llboxptr_ty = type_of(ccx, cboxptr_ty);
229-
230-
// If there are no bound values, no point in allocating anything.
231-
if bound_values.is_empty() {
232-
return ClosureResult {llbox: C_null(llboxptr_ty),
233-
cdata_ty: cdata_ty,
234-
bcx: bcx};
235-
}
236231

237-
// allocate closure in the heap
238-
let Result {bcx: bcx, val: llbox} = allocate_cbox(bcx, sigil, cdata_ty);
239-
240-
let llbox = PointerCast(bcx, llbox, llboxptr_ty);
232+
let llbox = PointerCast(bcx, llbox, type_of(ccx, cboxptr_ty));
241233
debug!("tuplify_box_ty = %s", ty_to_str(tcx, cbox_ty));
242234

243235
// Copy expr values into boxed bindings.
@@ -276,7 +268,6 @@ pub fn build_closure(bcx0: block,
276268
sigil: ast::Sigil,
277269
include_ret_handle: Option<ValueRef>) -> ClosureResult {
278270
let _icx = push_ctxt("closure::build_closure");
279-
280271
// If we need to, package up the iterator body to call
281272
let bcx = bcx0;
282273

branches/snap-stage3/src/librustc/middle/trans/foreign.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -725,24 +725,21 @@ pub fn trans_intrinsic(ccx: @mut CrateContext,
725725
}
726726

727727
if !ty::type_is_nil(out_type) {
728-
// NB: Do not use a Load and Store here. This causes massive
729-
// code bloat when `transmute` is used on large structural
730-
// types.
731728
let lldestptr = fcx.llretptr.get();
732-
let lldestptr = PointerCast(bcx, lldestptr, Type::i8p());
733-
734729
let llsrcval = get_param(decl, first_real_arg);
735-
let llsrcptr = if ty::type_is_immediate(ccx.tcx, in_type) {
736-
let llsrcptr = alloca(bcx, llintype, "__llsrcptr");
737-
Store(bcx, llsrcval, llsrcptr);
738-
llsrcptr
730+
if ty::type_is_immediate(ccx.tcx, in_type) {
731+
let lldestptr = PointerCast(bcx, lldestptr, llintype.ptr_to());
732+
Store(bcx, llsrcval, lldestptr);
739733
} else {
740-
llsrcval
734+
// NB: Do not use a Load and Store here. This causes massive
735+
// code bloat when `transmute` is used on large structural
736+
// types.
737+
let lldestptr = PointerCast(bcx, lldestptr, Type::i8p());
738+
let llsrcptr = PointerCast(bcx, llsrcval, Type::i8p());
739+
740+
let llsize = llsize_of(ccx, llintype);
741+
call_memcpy(bcx, lldestptr, llsrcptr, llsize, 1);
741742
};
742-
let llsrcptr = PointerCast(bcx, llsrcptr, Type::i8p());
743-
744-
let llsize = llsize_of(ccx, llintype);
745-
call_memcpy(bcx, lldestptr, llsrcptr, llsize, 1);
746743
}
747744
}
748745
"needs_drop" => {

branches/snap-stage3/src/librustc/middle/typeck/check/regionck.rs

Lines changed: 12 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@ use syntax::visit;
4848

4949
pub struct Rcx {
5050
fcx: @mut FnCtxt,
51-
errors_reported: uint,
52-
53-
// id of innermost fn or loop
54-
repeating_scope: ast::node_id,
51+
errors_reported: uint
5552
}
5653

5754
pub type rvt = visit::vt<@mut Rcx>;
@@ -81,12 +78,6 @@ impl Rcx {
8178
self.fcx.ccx.tcx
8279
}
8380

84-
pub fn set_repeating_scope(&mut self, scope: ast::node_id) -> ast::node_id {
85-
let old_scope = self.repeating_scope;
86-
self.repeating_scope = scope;
87-
old_scope
88-
}
89-
9081
pub fn resolve_type(&mut self, unresolved_ty: ty::t) -> ty::t {
9182
/*!
9283
* Try to resolve the type for the given node, returning
@@ -143,8 +134,7 @@ impl Rcx {
143134
}
144135

145136
pub fn regionck_expr(fcx: @mut FnCtxt, e: @ast::expr) {
146-
let rcx = @mut Rcx { fcx: fcx, errors_reported: 0,
147-
repeating_scope: e.id };
137+
let rcx = @mut Rcx { fcx: fcx, errors_reported: 0 };
148138
if fcx.err_count_since_creation() == 0 {
149139
// regionck assumes typeck succeeded
150140
let v = regionck_visitor();
@@ -154,8 +144,7 @@ pub fn regionck_expr(fcx: @mut FnCtxt, e: @ast::expr) {
154144
}
155145

156146
pub fn regionck_fn(fcx: @mut FnCtxt, blk: &ast::blk) {
157-
let rcx = @mut Rcx { fcx: fcx, errors_reported: 0,
158-
repeating_scope: blk.node.id };
147+
let rcx = @mut Rcx { fcx: fcx, errors_reported: 0 };
159148
if fcx.err_count_since_creation() == 0 {
160149
// regionck assumes typeck succeeded
161150
let v = regionck_visitor();
@@ -242,8 +231,7 @@ fn constrain_bindings_in_pat(pat: @ast::pat, rcx: @mut Rcx) {
242231
}
243232

244233
fn visit_expr(expr: @ast::expr, (rcx, v): (@mut Rcx, rvt)) {
245-
debug!("regionck::visit_expr(e=%s, repeating_scope=%?)",
246-
expr.repr(rcx.fcx.tcx()), rcx.repeating_scope);
234+
debug!("regionck::visit_expr(e=?)");
247235

248236
let has_method_map = rcx.fcx.inh.method_map.contains_key(&expr.id);
249237

@@ -286,9 +274,6 @@ fn visit_expr(expr: @ast::expr, (rcx, v): (@mut Rcx, rvt)) {
286274
}
287275
}
288276
}
289-
ast::expr_loop(ref body, _) => {
290-
tcx.region_maps.record_cleanup_scope(body.node.id);
291-
}
292277
ast::expr_while(cond, ref body) => {
293278
tcx.region_maps.record_cleanup_scope(cond.id);
294279
tcx.region_maps.record_cleanup_scope(body.node.id);
@@ -328,14 +313,10 @@ fn visit_expr(expr: @ast::expr, (rcx, v): (@mut Rcx, rvt)) {
328313
ast::expr_call(callee, ref args, _) => {
329314
constrain_callee(rcx, callee.id, expr, callee);
330315
constrain_call(rcx, callee.id, expr, None, *args, false);
331-
332-
visit::visit_expr(expr, (rcx, v));
333316
}
334317

335318
ast::expr_method_call(callee_id, arg0, _, _, ref args, _) => {
336319
constrain_call(rcx, callee_id, expr, Some(arg0), *args, false);
337-
338-
visit::visit_expr(expr, (rcx, v));
339320
}
340321

341322
ast::expr_index(callee_id, lhs, rhs) |
@@ -346,31 +327,23 @@ fn visit_expr(expr: @ast::expr, (rcx, v): (@mut Rcx, rvt)) {
346327
// implicit "by ref" sort of passing style here. This
347328
// should be converted to an adjustment!
348329
constrain_call(rcx, callee_id, expr, Some(lhs), [rhs], true);
349-
350-
visit::visit_expr(expr, (rcx, v));
351330
}
352331

353332
ast::expr_unary(callee_id, _, lhs) if has_method_map => {
354333
// As above.
355334
constrain_call(rcx, callee_id, expr, Some(lhs), [], true);
356-
357-
visit::visit_expr(expr, (rcx, v));
358335
}
359336

360337
ast::expr_unary(_, ast::deref, base) => {
361338
// For *a, the lifetime of a must enclose the deref
362339
let base_ty = rcx.resolve_node_type(base.id);
363340
constrain_derefs(rcx, expr, 1, base_ty);
364-
365-
visit::visit_expr(expr, (rcx, v));
366341
}
367342

368343
ast::expr_index(_, vec_expr, _) => {
369344
// For a[b], the lifetime of a must enclose the deref
370345
let vec_type = rcx.resolve_expr_type_adjusted(vec_expr);
371346
constrain_index(rcx, expr, vec_type);
372-
373-
visit::visit_expr(expr, (rcx, v));
374347
}
375348

376349
ast::expr_cast(source, _) => {
@@ -399,8 +372,6 @@ fn visit_expr(expr: @ast::expr, (rcx, v): (@mut Rcx, rvt)) {
399372
}
400373
_ => ()
401374
}
402-
403-
visit::visit_expr(expr, (rcx, v));
404375
}
405376

406377
ast::expr_addr_of(_, base) => {
@@ -416,87 +387,29 @@ fn visit_expr(expr: @ast::expr, (rcx, v): (@mut Rcx, rvt)) {
416387
let ty0 = rcx.resolve_node_type(expr.id);
417388
constrain_regions_in_type(rcx, ty::re_scope(expr.id),
418389
infer::AddrOf(expr.span), ty0);
419-
visit::visit_expr(expr, (rcx, v));
420390
}
421391

422392
ast::expr_match(discr, ref arms) => {
423393
guarantor::for_match(rcx, discr, *arms);
424-
425-
visit::visit_expr(expr, (rcx, v));
426-
}
427-
428-
ast::expr_loop_body(subexpr) => {
429-
check_expr_fn_block(rcx, subexpr, v, true);
430394
}
431395

432396
ast::expr_fn_block(*) => {
433-
check_expr_fn_block(rcx, expr, v, false);
434-
}
435-
436-
ast::expr_loop(ref body, _) => {
437-
let repeating_scope = rcx.set_repeating_scope(body.node.id);
438-
visit::visit_expr(expr, (rcx, v));
439-
rcx.set_repeating_scope(repeating_scope);
440-
}
441-
442-
ast::expr_while(cond, ref body) => {
443-
let repeating_scope = rcx.set_repeating_scope(cond.id);
444-
(v.visit_expr)(cond, (rcx, v));
445-
446-
rcx.set_repeating_scope(body.node.id);
447-
(v.visit_block)(body, (rcx, v));
448-
449-
rcx.set_repeating_scope(repeating_scope);
450-
}
451-
452-
_ => {
453-
visit::visit_expr(expr, (rcx, v));
454-
}
455-
}
456-
}
457-
458-
fn check_expr_fn_block(rcx: @mut Rcx,
459-
expr: @ast::expr,
460-
v: rvt,
461-
is_loop_body: bool) {
462-
let tcx = rcx.fcx.tcx();
463-
match expr.node {
464-
ast::expr_fn_block(_, ref body) => {
397+
// The lifetime of a block fn must not outlive the variables
398+
// it closes over
465399
let function_type = rcx.resolve_node_type(expr.id);
466400
match ty::get(function_type).sty {
467-
ty::ty_closure(
468-
ty::ClosureTy {
469-
sigil: ast::BorrowedSigil, region: region, _}) => {
470-
if get_freevars(tcx, expr.id).is_empty() && !is_loop_body {
471-
// No free variables means that the environment
472-
// will be NULL at runtime and hence the closure
473-
// has static lifetime.
474-
} else {
475-
// Otherwise, the closure must not outlive the
476-
// variables it closes over, nor can it
477-
// outlive the innermost repeating scope
478-
// (since otherwise that would require
479-
// infinite stack).
480-
constrain_free_variables(rcx, region, expr);
481-
let repeating_scope = ty::re_scope(rcx.repeating_scope);
482-
rcx.fcx.mk_subr(true, infer::InfStackClosure(expr.span),
483-
region, repeating_scope);
484-
}
401+
ty::ty_closure(ty::ClosureTy {sigil: ast::BorrowedSigil,
402+
region: region, _}) => {
403+
constrain_free_variables(rcx, region, expr);
485404
}
486405
_ => ()
487406
}
488-
489-
let repeating_scope = rcx.set_repeating_scope(body.node.id);
490-
visit::visit_expr(expr, (rcx, v));
491-
rcx.set_repeating_scope(repeating_scope);
492407
}
493408

494-
_ => {
495-
tcx.sess.span_bug(
496-
expr.span,
497-
"Expected expr_fn_block");
498-
}
409+
_ => ()
499410
}
411+
412+
visit::visit_expr(expr, (rcx, v));
500413
}
501414

502415
fn constrain_callee(rcx: @mut Rcx,

branches/snap-stage3/src/librustc/middle/typeck/infer/error_reporting.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -231,21 +231,6 @@ impl ErrorReporting for InferCtxt {
231231
sup,
232232
"");
233233
}
234-
infer::InfStackClosure(span) => {
235-
self.tcx.sess.span_err(
236-
span,
237-
"closure outlives stack frame");
238-
note_and_explain_region(
239-
self.tcx,
240-
"...the closure must be valid for ",
241-
sub,
242-
"...");
243-
note_and_explain_region(
244-
self.tcx,
245-
"...but the closure's stack frame is only valid for ",
246-
sup,
247-
"");
248-
}
249234
infer::InvokeClosure(span) => {
250235
self.tcx.sess.span_err(
251236
span,

branches/snap-stage3/src/librustc/middle/typeck/infer/mod.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,6 @@ pub enum SubregionOrigin {
141141
// Arose from a subtyping relation
142142
Subtype(TypeTrace),
143143

144-
// Stack-allocated closures cannot outlive innermost loop
145-
// or function so as to ensure we only require finite stack
146-
InfStackClosure(span),
147-
148144
// Invocation of closure must be within its lifetime
149145
InvokeClosure(span),
150146

@@ -833,7 +829,6 @@ impl SubregionOrigin {
833829
pub fn span(&self) -> span {
834830
match *self {
835831
Subtype(a) => a.span(),
836-
InfStackClosure(a) => a,
837832
InvokeClosure(a) => a,
838833
DerefPointer(a) => a,
839834
FreeVariable(a) => a,
@@ -855,7 +850,6 @@ impl Repr for SubregionOrigin {
855850
fn repr(&self, tcx: ty::ctxt) -> ~str {
856851
match *self {
857852
Subtype(a) => fmt!("Subtype(%s)", a.repr(tcx)),
858-
InfStackClosure(a) => fmt!("InfStackClosure(%s)", a.repr(tcx)),
859853
InvokeClosure(a) => fmt!("InvokeClosure(%s)", a.repr(tcx)),
860854
DerefPointer(a) => fmt!("DerefPointer(%s)", a.repr(tcx)),
861855
FreeVariable(a) => fmt!("FreeVariable(%s)", a.repr(tcx)),

0 commit comments

Comments
 (0)