Skip to content

Commit ffbe2a8

Browse files
committed
---
yaml --- r: 72673 b: refs/heads/dist-snap c: 989d008 h: refs/heads/master i: 72671: 35b4603 v: v3
1 parent 543934f commit ffbe2a8

File tree

7 files changed

+42
-205
lines changed

7 files changed

+42
-205
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
99
refs/heads/incoming: b50030718cf28f2a5a81857a26b57442734fe854
10-
refs/heads/dist-snap: ccf2f7b979ad4e4defd9b856f6d16108c5760829
10+
refs/heads/dist-snap: 989d008124d62f7c1284633e6619db1a9e8b6598
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1313
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/Makefile.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ endif
110110
ifdef SAVE_TEMPS
111111
CFG_RUSTC_FLAGS += --save-temps
112112
endif
113+
ifdef ASM_COMMENTS
114+
CFG_RUSTC_FLAGS += -z asm-comments
115+
endif
113116
ifdef TIME_PASSES
114117
CFG_RUSTC_FLAGS += -Z time-passes
115118
endif

branches/dist-snap/src/librustc/middle/trans/_match.rs

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -969,30 +969,17 @@ pub fn pats_require_rooting(bcx: block,
969969
})
970970
}
971971
972-
pub fn root_pats_as_necessary(bcx: block,
972+
pub fn root_pats_as_necessary(mut bcx: block,
973973
m: &[@Match],
974974
col: uint,
975975
val: ValueRef)
976976
-> block {
977-
let mut bcx = bcx;
978977
for vec::each(m) |br| {
979978
let pat_id = br.pats[col].id;
980-
981-
let key = root_map_key {id: pat_id, derefs: 0u };
982-
match bcx.ccx().maps.root_map.find(&key) {
983-
None => (),
984-
Some(&root_info) => {
985-
// Note: the scope_id will always be the id of the match. See
986-
// the extended comment in rustc::middle::borrowck::preserve()
987-
// for details (look for the case covering cat_discr).
988-
989-
let datum = Datum {val: val, ty: node_id_type(bcx, pat_id),
990-
mode: ByRef, source: ZeroMem};
991-
bcx = datum.root(bcx, br.pats[col].span, key, root_info);
992-
// If we kept going, we'd only re-root the same value, so
993-
// return now.
994-
return bcx;
995-
}
979+
if pat_id != 0 {
980+
let datum = Datum {val: val, ty: node_id_type(bcx, pat_id),
981+
mode: ByRef, source: ZeroMem};
982+
bcx = datum.root_and_write_guard(bcx, br.pats[col].span, pat_id, 0);
996983
}
997984
}
998985
return bcx;

branches/dist-snap/src/librustc/middle/trans/common.rs

Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@ use middle::resolve;
2727
use middle::trans::adt;
2828
use middle::trans::base;
2929
use middle::trans::build;
30-
use middle::trans::callee;
3130
use middle::trans::datum;
3231
use middle::trans::debuginfo;
33-
use middle::trans::expr;
3432
use middle::trans::glue;
3533
use middle::trans::reachable;
3634
use middle::trans::shape;
3735
use middle::trans::type_of;
3836
use middle::trans::type_use;
37+
use middle::trans::write_guard;
3938
use middle::ty::substs;
4039
use middle::ty;
4140
use middle::typeck;
41+
use middle::borrowck::root_map_key;
4242
use util::ppaux::{Repr};
4343

4444
use core::cast::transmute;
@@ -468,6 +468,7 @@ pub fn add_clean_temp_mem(bcx: block, val: ValueRef, t: ty::t) {
468468
}
469469
}
470470
pub fn add_clean_return_to_mut(bcx: block,
471+
root_key: root_map_key,
471472
frozen_val_ref: ValueRef,
472473
bits_val_ref: ValueRef,
473474
filename_val: ValueRef,
@@ -488,44 +489,12 @@ pub fn add_clean_return_to_mut(bcx: block,
488489
scope_info.cleanups.push(
489490
clean_temp(
490491
frozen_val_ref,
491-
|bcx| {
492-
let mut bcx = bcx;
493-
494-
let box_ptr =
495-
build::Load(bcx,
496-
build::PointerCast(bcx,
497-
frozen_val_ref,
498-
T_ptr(T_ptr(T_i8()))));
499-
500-
let bits_val =
501-
build::Load(bcx,
502-
bits_val_ref);
503-
504-
if bcx.tcx().sess.opts.optimize == session::No {
505-
bcx = callee::trans_lang_call(
506-
bcx,
507-
bcx.tcx().lang_items.unrecord_borrow_fn(),
508-
~[
509-
box_ptr,
510-
bits_val,
511-
filename_val,
512-
line_val
513-
],
514-
expr::Ignore);
515-
}
516-
517-
callee::trans_lang_call(
518-
bcx,
519-
bcx.tcx().lang_items.return_to_mut_fn(),
520-
~[
521-
box_ptr,
522-
bits_val,
523-
filename_val,
524-
line_val
525-
],
526-
expr::Ignore
527-
)
528-
},
492+
|bcx| write_guard::return_to_mut(bcx,
493+
root_key,
494+
frozen_val_ref,
495+
bits_val_ref,
496+
filename_val,
497+
line_val),
529498
normal_exit_only));
530499
scope_clean_changed(scope_info);
531500
}
@@ -1563,6 +1532,15 @@ pub fn dummy_substs(tps: ~[ty::t]) -> ty::substs {
15631532
}
15641533
}
15651534

1535+
pub fn filename_and_line_num_from_span(bcx: block,
1536+
span: span) -> (ValueRef, ValueRef) {
1537+
let loc = bcx.sess().parse_sess.cm.lookup_char_pos(span.lo);
1538+
let filename_cstr = C_cstr(bcx.ccx(), @/*bad*/copy loc.file.name);
1539+
let filename = build::PointerCast(bcx, filename_cstr, T_ptr(T_i8()));
1540+
let line = C_int(bcx.ccx(), loc.line as int);
1541+
(filename, line)
1542+
}
1543+
15661544
// Casts a Rust bool value to an i1.
15671545
pub fn bool_to_i1(bcx: block, llval: ValueRef) -> ValueRef {
15681546
build::ICmp(bcx, lib::llvm::IntNE, llval, C_bool(false))

branches/dist-snap/src/librustc/middle/trans/controlflow.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -385,13 +385,7 @@ fn trans_fail_value(bcx: block,
385385
pub fn trans_fail_bounds_check(bcx: block, sp: span,
386386
index: ValueRef, len: ValueRef) -> block {
387387
let _icx = bcx.insn_ctxt("trans_fail_bounds_check");
388-
let ccx = bcx.ccx();
389-
390-
let loc = bcx.sess().parse_sess.cm.lookup_char_pos(sp.lo);
391-
let line = C_int(ccx, loc.line as int);
392-
let filename_cstr = C_cstr(bcx.ccx(), @/*bad*/copy loc.file.name);
393-
let filename = PointerCast(bcx, filename_cstr, T_ptr(T_i8()));
394-
388+
let (filename, line) = filename_and_line_num_from_span(bcx, sp);
395389
let args = ~[filename, line, index, len];
396390
let bcx = callee::trans_lang_call(
397391
bcx, bcx.tcx().lang_items.fail_bounds_check_fn(), args, expr::Ignore);

branches/dist-snap/src/librustc/middle/trans/datum.rs

Lines changed: 13 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -87,21 +87,19 @@
8787

8888
use lib;
8989
use lib::llvm::ValueRef;
90-
use middle::borrowck::{RootInfo, root_map_key, DynaImm, DynaMut};
9190
use middle::trans::adt;
9291
use middle::trans::base::*;
9392
use middle::trans::build::*;
94-
use middle::trans::callee;
9593
use middle::trans::common::*;
9694
use middle::trans::common;
9795
use middle::trans::expr;
9896
use middle::trans::glue;
9997
use middle::trans::tvec;
10098
use middle::trans::type_of;
99+
use middle::trans::write_guard;
101100
use middle::ty;
102101
use util::common::indenter;
103102
use util::ppaux::ty_to_str;
104-
use driver::session;
105103

106104
use core::container::Set; // XXX: this should not be necessary
107105
use core::to_bytes;
@@ -518,113 +516,6 @@ pub impl Datum {
518516
}
519517
}
520518

521-
fn root(&self, mut bcx: block, span: span,
522-
root_key: root_map_key, root_info: RootInfo) -> block {
523-
/*!
524-
*
525-
* In some cases, borrowck will decide that an @T/@[]/@str
526-
* value must be rooted for the program to be safe. In that
527-
* case, we will call this function, which will stash a copy
528-
* away until we exit the scope `scope_id`. */
529-
530-
debug!("root(root_map_key=%?, root_info=%?, self=%?)",
531-
root_key, root_info, self.to_str(bcx.ccx()));
532-
533-
if bcx.sess().trace() {
534-
trans_trace(
535-
bcx, None,
536-
@fmt!("preserving until end of scope %d",
537-
root_info.scope));
538-
}
539-
540-
// First, root the datum. Note that we must zero this value,
541-
// because sometimes we root on one path but not another.
542-
// See e.g. #4904.
543-
let scratch = scratch_datum(bcx, self.ty, true);
544-
self.copy_to_datum(bcx, INIT, scratch);
545-
let cleanup_bcx = find_bcx_for_scope(bcx, root_info.scope);
546-
add_clean_temp_mem(cleanup_bcx, scratch.val, scratch.ty);
547-
548-
// Now, consider also freezing it.
549-
match root_info.freeze {
550-
None => {}
551-
Some(freeze_kind) => {
552-
let loc = bcx.sess().parse_sess.cm.lookup_char_pos(span.lo);
553-
let line = C_int(bcx.ccx(), loc.line as int);
554-
let filename_cstr = C_cstr(bcx.ccx(), @/*bad*/copy loc.file.name);
555-
let filename = PointerCast(bcx, filename_cstr, T_ptr(T_i8()));
556-
557-
// in this case, we don't have to zero, because
558-
// scratch.val will be NULL should the cleanup get
559-
// called without the freezing actually occurring, and
560-
// return_to_mut checks for this condition.
561-
let scratch_bits = scratch_datum(bcx, ty::mk_uint(), false);
562-
563-
let freeze_did = match freeze_kind {
564-
DynaImm => bcx.tcx().lang_items.borrow_as_imm_fn(),
565-
DynaMut => bcx.tcx().lang_items.borrow_as_mut_fn(),
566-
};
567-
568-
let box_ptr = Load(bcx,
569-
PointerCast(bcx,
570-
scratch.val,
571-
T_ptr(T_ptr(T_i8()))));
572-
573-
bcx = callee::trans_lang_call(
574-
bcx,
575-
freeze_did,
576-
~[
577-
box_ptr,
578-
filename,
579-
line
580-
],
581-
expr::SaveIn(scratch_bits.val));
582-
583-
if bcx.tcx().sess.opts.optimize == session::No {
584-
bcx = callee::trans_lang_call(
585-
bcx,
586-
bcx.tcx().lang_items.record_borrow_fn(),
587-
~[
588-
box_ptr,
589-
Load(bcx, scratch_bits.val),
590-
filename,
591-
line
592-
],
593-
expr::Ignore);
594-
}
595-
596-
add_clean_return_to_mut(
597-
cleanup_bcx, scratch.val, scratch_bits.val,
598-
filename, line);
599-
}
600-
}
601-
602-
bcx
603-
}
604-
605-
fn perform_write_guard(&self, bcx: block, span: span) -> block {
606-
debug!("perform_write_guard");
607-
608-
// Create scratch space, but do not root it.
609-
let llval = match self.mode {
610-
ByValue => self.val,
611-
ByRef => Load(bcx, self.val),
612-
};
613-
614-
let loc = bcx.sess().parse_sess.cm.lookup_char_pos(span.lo);
615-
let line = C_int(bcx.ccx(), loc.line as int);
616-
let filename_cstr = C_cstr(bcx.ccx(), @/*bad*/copy loc.file.name);
617-
let filename = PointerCast(bcx, filename_cstr, T_ptr(T_i8()));
618-
619-
callee::trans_lang_call(
620-
bcx,
621-
bcx.tcx().lang_items.check_not_borrowed_fn(),
622-
~[PointerCast(bcx, llval, T_ptr(T_i8())),
623-
filename,
624-
line],
625-
expr::Ignore)
626-
}
627-
628519
fn drop_val(&self, bcx: block) -> block {
629520
if !ty::type_needs_drop(bcx.tcx(), self.ty) {
630521
return bcx;
@@ -687,7 +578,9 @@ pub impl Datum {
687578
debug!("try_deref(expr_id=%?, derefs=%?, is_auto=%b, self=%?)",
688579
expr_id, derefs, is_auto, self.to_str(bcx.ccx()));
689580

690-
let bcx = self.root_and_write_guard(bcx, span, expr_id, derefs);
581+
let bcx =
582+
write_guard::root_and_write_guard(
583+
self, bcx, span, expr_id, derefs);
691584

692585
match ty::get(self.ty).sty {
693586
ty::ty_box(_) | ty::ty_uniq(_) => {
@@ -841,33 +734,6 @@ pub impl Datum {
841734
DatumBlock { bcx: bcx, datum: datum }
842735
}
843736

844-
fn root_and_write_guard(&self,
845-
mut bcx: block,
846-
span: span,
847-
expr_id: ast::node_id,
848-
derefs: uint) -> block {
849-
let key = root_map_key { id: expr_id, derefs: derefs };
850-
debug!("root_and_write_guard(key=%?)", key);
851-
852-
// root the autoderef'd value, if necessary:
853-
//
854-
// (Note: root'd values are always boxes)
855-
let ccx = bcx.ccx();
856-
bcx = match ccx.maps.root_map.find(&key) {
857-
None => bcx,
858-
Some(&root_info) => self.root(bcx, span, key, root_info)
859-
};
860-
861-
// Perform the write guard, if necessary.
862-
//
863-
// (Note: write-guarded values are always boxes)
864-
if ccx.maps.write_guard_map.contains(&key) {
865-
self.perform_write_guard(bcx, span)
866-
} else {
867-
bcx
868-
}
869-
}
870-
871737
fn get_vec_base_and_len(&self,
872738
mut bcx: block,
873739
span: span,
@@ -877,7 +743,7 @@ pub impl Datum {
877743
//! and write guards checks.
878744
879745
// only imp't for @[] and @str, but harmless
880-
bcx = self.root_and_write_guard(bcx, span, expr_id, 0);
746+
bcx = write_guard::root_and_write_guard(self, bcx, span, expr_id, 0);
881747
let (base, len) = self.get_vec_base_and_len_no_root(bcx);
882748
(bcx, base, len)
883749
}
@@ -890,6 +756,14 @@ pub impl Datum {
890756
tvec::get_base_and_len(bcx, llval, self.ty)
891757
}
892758

759+
fn root_and_write_guard(&self,
760+
bcx: block,
761+
span: span,
762+
expr_id: ast::node_id,
763+
derefs: uint) -> block {
764+
write_guard::root_and_write_guard(self, bcx, span, expr_id, derefs)
765+
}
766+
893767
fn to_result(&self, bcx: block) -> common::Result {
894768
rslt(bcx, self.to_appropriate_llval(bcx))
895769
}

branches/dist-snap/src/librustc/rustc.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ pub mod middle {
4747
pub mod controlflow;
4848
pub mod glue;
4949
pub mod datum;
50+
pub mod write_guard;
5051
pub mod callee;
5152
pub mod expr;
5253
pub mod common;

0 commit comments

Comments
 (0)