Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

librustc: Replace scope regions with SEME regions. #16996

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/libcore/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1972,6 +1972,7 @@ impl<A: Add<A, A> + PartialOrd + Clone + ToPrimitive> Iterator<A> for Range<A> {
// the i64/u64 might lie within their range.
let bound = match self.state.to_i64() {
Some(a) => {
let a = a;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this?

let sz = self.stop.to_i64().map(|b| b.checked_sub(&a));
match sz {
Some(Some(bound)) => bound.to_uint(),
Expand All @@ -1980,6 +1981,7 @@ impl<A: Add<A, A> + PartialOrd + Clone + ToPrimitive> Iterator<A> for Range<A> {
},
None => match self.state.to_u64() {
Some(a) => {
let a = a;
let sz = self.stop.to_u64().map(|b| b.checked_sub(&a));
match sz {
Some(Some(bound)) => bound.to_uint(),
Expand Down
16 changes: 9 additions & 7 deletions src/libregex_macros/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ fn exec<'t>(which: ::regex::native::MatchKind, input: &'t str,
_ => quote_expr!(self.cx, nlist.add($pc, &*groups)),
};
self.arm_inst(pc, body)
}).collect::<Vec<ast::Arm>>();
}).collect::<Vec<Gc<ast::Arm>>>();

self.match_insts(arms)
}
Expand Down Expand Up @@ -516,7 +516,7 @@ fn exec<'t>(which: ::regex::native::MatchKind, input: &'t str,
_ => self.empty_block(),
};
self.arm_inst(pc, body)
}).collect::<Vec<ast::Arm>>();
}).collect::<Vec<Gc<ast::Arm>>>();

self.match_insts(arms)
}
Expand All @@ -535,7 +535,7 @@ fn exec<'t>(which: ::regex::native::MatchKind, input: &'t str,
let pat = self.cx.pat(self.sp, ast::PatRange(quote_expr!(self.cx, $start),
quote_expr!(self.cx, $end)));
self.cx.arm(self.sp, vec!(pat), expr_true)
}).collect::<Vec<ast::Arm>>();
}).collect::<Vec<Gc<ast::Arm>>>();

arms.push(self.wild_arm_expr(quote_expr!(self.cx, false)));

Expand Down Expand Up @@ -570,7 +570,7 @@ fn exec<'t>(which: ::regex::native::MatchKind, input: &'t str,
// A wild-card arm is automatically added that executes a no-op. It will
// never be used, but is added to satisfy the compiler complaining about
// non-exhaustive patterns.
fn match_insts(&self, mut arms: Vec<ast::Arm>) -> Gc<ast::Expr> {
fn match_insts(&self, mut arms: Vec<Gc<ast::Arm>>) -> Gc<ast::Expr> {
arms.push(self.wild_arm_expr(self.empty_block()));
self.cx.expr_match(self.sp, quote_expr!(self.cx, pc), arms)
}
Expand All @@ -581,15 +581,15 @@ fn exec<'t>(which: ::regex::native::MatchKind, input: &'t str,

// Creates a match arm for the instruction at `pc` with the expression
// `body`.
fn arm_inst(&self, pc: uint, body: Gc<ast::Expr>) -> ast::Arm {
fn arm_inst(&self, pc: uint, body: Gc<ast::Expr>) -> Gc<ast::Arm> {
let pc_pat = self.cx.pat_lit(self.sp, quote_expr!(self.cx, $pc));

self.cx.arm(self.sp, vec!(pc_pat), body)
}

// Creates a wild-card match arm with the expression `body`.
fn wild_arm_expr(&self, body: Gc<ast::Expr>) -> ast::Arm {
ast::Arm {
fn wild_arm_expr(&self, body: Gc<ast::Expr>) -> Gc<ast::Arm> {
box(GC) ast::Arm {
attrs: vec!(),
pats: vec!(box(GC) ast::Pat{
id: ast::DUMMY_NODE_ID,
Expand All @@ -598,6 +598,8 @@ fn exec<'t>(which: ::regex::native::MatchKind, input: &'t str,
}),
guard: None,
body: body,
id: ast::DUMMY_NODE_ID,
span: self.sp,
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ This API is completely unstable and subject to change.
#![feature(import_shadowing)]

extern crate arena;
extern crate collections;
extern crate debug;
extern crate flate;
extern crate getopts;
Expand Down Expand Up @@ -94,6 +95,7 @@ pub mod middle {
pub mod kind;
pub mod lang_items;
pub mod liveness;
pub mod loop_analysis;
pub mod mem_categorization;
pub mod pat_util;
pub mod privacy;
Expand All @@ -102,6 +104,7 @@ pub mod middle {
pub mod resolve;
pub mod resolve_lifetime;
pub mod save;
pub mod seme_region;
pub mod stability;
pub mod subst;
pub mod trans;
Expand Down
8 changes: 3 additions & 5 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ pub fn write_type(ecx: &EncodeContext,

pub fn write_region(ecx: &EncodeContext,
rbml_w: &mut Encoder,
r: ty::Region) {
r: &ty::Region) {
let ty_str_ctxt = &tyencode::ctxt {
diag: ecx.diag,
ds: def_to_string,
Expand Down Expand Up @@ -231,9 +231,7 @@ fn encode_type(ecx: &EncodeContext,
rbml_w.end_tag();
}

fn encode_region(ecx: &EncodeContext,
rbml_w: &mut Encoder,
r: ty::Region) {
fn encode_region(ecx: &EncodeContext, rbml_w: &mut Encoder, r: &ty::Region) {
rbml_w.start_tag(tag_items_data_region);
write_region(ecx, rbml_w, r);
rbml_w.end_tag();
Expand Down Expand Up @@ -822,7 +820,7 @@ fn encode_generics(rbml_w: &mut Encoder,
rbml_w.wr_tagged_u64(tag_region_param_def_index,
param.index as u64);

for &bound_region in param.bounds.iter() {
for bound_region in param.bounds.iter() {
encode_region(ecx, rbml_w, bound_region);
}

Expand Down
11 changes: 8 additions & 3 deletions src/librustc/metadata/tydecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#![allow(non_camel_case_types)]

use middle::seme_region::SemeRegion;
use middle::subst;
use middle::subst::VecPerParamSpace;
use middle::ty;
Expand Down Expand Up @@ -310,9 +311,13 @@ fn parse_region(st: &mut PState, conv: conv_did) -> ty::Region {
bound_region: br})
}
's' => {
let id = parse_uint(st) as ast::NodeId;
assert_eq!(next(st), '|');
ty::ReScope(id)
assert_eq!(next(st), '[');
let entry = parse_uint(st) as ast::NodeId;
let mut exits = Vec::new();
while next(st) == '|' {
exits.push(parse_uint(st) as ast::NodeId);
}
ty::ReSemeRegion(SemeRegion::new(entry, exits))
}
't' => {
ty::ReStatic
Expand Down
36 changes: 22 additions & 14 deletions src/librustc/metadata/tyencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ fn enc_region_substs(w: &mut SeekableMemWriter, cx: &ctxt, substs: &subst::Regio
subst::NonerasedRegions(ref regions) => {
mywrite!(w, "n");
enc_vec_per_param_space(w, cx, regions,
|w, cx, &r| enc_region(w, cx, r));
|w, cx, r| enc_region(w, cx, r));
}
}
}

pub fn enc_region(w: &mut SeekableMemWriter, cx: &ctxt, r: ty::Region) {
match r {
pub fn enc_region(w: &mut SeekableMemWriter, cx: &ctxt, r: &ty::Region) {
match *r {
ty::ReLateBound(id, br) => {
mywrite!(w, "b[{}|", id);
enc_bound_region(w, cx, br);
Expand All @@ -146,8 +146,12 @@ pub fn enc_region(w: &mut SeekableMemWriter, cx: &ctxt, r: ty::Region) {
enc_bound_region(w, cx, fr.bound_region);
mywrite!(w, "]");
}
ty::ReScope(nid) => {
mywrite!(w, "s{}|", nid);
ty::ReSemeRegion(ref seme_region) => {
mywrite!(w, "s[{}", seme_region.entry);
for exit in seme_region.exits.iter() {
mywrite!(w, "|{}", *exit);
}
mywrite!(w, "]");
}
ty::ReStatic => {
mywrite!(w, "t");
Expand Down Expand Up @@ -183,10 +187,12 @@ pub fn enc_trait_ref(w: &mut SeekableMemWriter, cx: &ctxt, s: &ty::TraitRef) {
enc_substs(w, cx, &s.substs);
}

pub fn enc_trait_store(w: &mut SeekableMemWriter, cx: &ctxt, s: ty::TraitStore) {
match s {
pub fn enc_trait_store(w: &mut SeekableMemWriter,
cx: &ctxt,
s: &ty::TraitStore) {
match *s {
ty::UniqTraitStore => mywrite!(w, "~"),
ty::RegionTraitStore(re, m) => {
ty::RegionTraitStore(ref re, m) => {
mywrite!(w, "&");
enc_region(w, cx, re);
enc_mutability(w, m);
Expand Down Expand Up @@ -247,7 +253,7 @@ fn enc_sty(w: &mut SeekableMemWriter, cx: &ctxt, st: &ty::sty) {
ty::ty_box(typ) => { mywrite!(w, "@"); enc_ty(w, cx, typ); }
ty::ty_uniq(typ) => { mywrite!(w, "~"); enc_ty(w, cx, typ); }
ty::ty_ptr(mt) => { mywrite!(w, "*"); enc_mt(w, cx, mt); }
ty::ty_rptr(r, mt) => {
ty::ty_rptr(ref r, mt) => {
mywrite!(w, "&");
enc_region(w, cx, r);
enc_mt(w, cx, mt);
Expand Down Expand Up @@ -283,7 +289,7 @@ fn enc_sty(w: &mut SeekableMemWriter, cx: &ctxt, st: &ty::sty) {
enc_substs(w, cx, substs);
mywrite!(w, "]");
}
ty::ty_unboxed_closure(def, region) => {
ty::ty_unboxed_closure(def, ref region) => {
mywrite!(w, "k{}", (cx.ds)(def));
enc_region(w, cx, region);
}
Expand Down Expand Up @@ -325,7 +331,7 @@ pub fn enc_bare_fn_ty(w: &mut SeekableMemWriter, cx: &ctxt, ft: &ty::BareFnTy) {
pub fn enc_closure_ty(w: &mut SeekableMemWriter, cx: &ctxt, ft: &ty::ClosureTy) {
enc_fn_style(w, ft.fn_style);
enc_onceness(w, ft.onceness);
enc_trait_store(w, cx, ft.store);
enc_trait_store(w, cx, &ft.store);
enc_existential_bounds(w, cx, &ft.bounds);
enc_fn_sig(w, cx, &ft.sig);
enc_abi(w, ft.abi);
Expand Down Expand Up @@ -358,15 +364,17 @@ pub fn enc_builtin_bounds(w: &mut SeekableMemWriter, _cx: &ctxt, bs: &ty::Builti
mywrite!(w, ".");
}

pub fn enc_existential_bounds(w: &mut SeekableMemWriter, cx: &ctxt, bs: &ty::ExistentialBounds) {
enc_region(w, cx, bs.region_bound);
pub fn enc_existential_bounds(w: &mut SeekableMemWriter,
cx: &ctxt,
bs: &ty::ExistentialBounds) {
enc_region(w, cx, &bs.region_bound);
enc_builtin_bounds(w, cx, &bs.builtin_bounds);
}

pub fn enc_bounds(w: &mut SeekableMemWriter, cx: &ctxt, bs: &ty::ParamBounds) {
enc_builtin_bounds(w, cx, &bs.builtin_bounds);

for &r in bs.opt_region_bound.iter() {
for r in bs.opt_region_bound.iter() {
mywrite!(w, "R");
enc_region(w, cx, r);
}
Expand Down
26 changes: 17 additions & 9 deletions src/librustc/middle/astencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use metadata::tydecode;
use metadata::tydecode::{DefIdSource, NominalType, TypeWithId, TypeParameter};
use metadata::tydecode::{RegionParameter};
use metadata::tyencode;
use middle::seme_region::SemeRegion;
use middle::subst;
use middle::subst::VecPerParamSpace;
use middle::typeck::{MethodCall, MethodCallee, MethodOrigin};
Expand Down Expand Up @@ -506,12 +507,10 @@ impl tr for ty::Region {
ty::ReEarlyBound(id, space, index, ident) => {
ty::ReEarlyBound(xcx.tr_id(id), space, index, ident)
}
ty::ReScope(id) => {
ty::ReScope(xcx.tr_id(id))
}
ty::ReEmpty | ty::ReStatic | ty::ReInfer(..) => {
*self
ty::ReSemeRegion(ref seme_region) => {
ty::ReSemeRegion(seme_region.tr(xcx))
}
ty::ReEmpty | ty::ReStatic | ty::ReInfer(..) => (*self).clone(),
ty::ReFree(ref fr) => {
ty::ReFree(ty::FreeRegion {scope_id: xcx.tr_id(fr.scope_id),
bound_region: fr.bound_region.tr(xcx)})
Expand All @@ -520,6 +519,15 @@ impl tr for ty::Region {
}
}

impl tr for SemeRegion {
fn tr(&self, xcx: &ExtendedDecodeContext) -> SemeRegion {
SemeRegion {
entry: xcx.tr_id(self.entry),
exits: self.exits.iter().map(|id| xcx.tr_id(*id)).collect(),
}
}
}

impl tr for ty::BoundRegion {
fn tr(&self, xcx: &ExtendedDecodeContext) -> ty::BoundRegion {
match *self {
Expand All @@ -534,7 +542,7 @@ impl tr for ty::BoundRegion {
impl tr for ty::TraitStore {
fn tr(&self, xcx: &ExtendedDecodeContext) -> ty::TraitStore {
match *self {
ty::RegionTraitStore(r, m) => {
ty::RegionTraitStore(ref r, m) => {
ty::RegionTraitStore(r.tr(xcx), m)
}
ty::UniqTraitStore => ty::UniqTraitStore
Expand Down Expand Up @@ -1026,7 +1034,7 @@ impl<'a> rbml_writer_helpers for Encoder<'a> {

self.emit_enum("AutoAdjustment", |this| {
match *adj {
ty::AutoAddEnv(store) => {
ty::AutoAddEnv(ref store) => {
this.emit_enum_variant("AutoAddEnv", 0, 1, |this| {
this.emit_enum_variant_arg(0, |this| store.encode(this))
})
Expand All @@ -1047,15 +1055,15 @@ impl<'a> rbml_writer_helpers for Encoder<'a> {

self.emit_enum("AutoRef", |this| {
match autoref {
&ty::AutoPtr(r, m, None) => {
&ty::AutoPtr(ref r, m, None) => {
this.emit_enum_variant("AutoPtr", 0, 3, |this| {
this.emit_enum_variant_arg(0, |this| r.encode(this));
this.emit_enum_variant_arg(1, |this| m.encode(this));
this.emit_enum_variant_arg(2,
|this| this.emit_option(|this| this.emit_option_none()))
})
}
&ty::AutoPtr(r, m, Some(box ref a)) => {
&ty::AutoPtr(ref r, m, Some(box ref a)) => {
this.emit_enum_variant("AutoPtr", 0, 3, |this| {
this.emit_enum_variant_arg(0, |this| r.encode(this));
this.emit_enum_variant_arg(1, |this| m.encode(this));
Expand Down
28 changes: 15 additions & 13 deletions src/librustc/middle/borrowck/check_loans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,9 @@ impl<'a> euv::Delegate for CheckLoanCtxt<'a> {
borrow_id: ast::NodeId,
borrow_span: Span,
cmt: mc::cmt,
loan_region: ty::Region,
loan_region: &ty::Region,
bk: ty::BorrowKind,
loan_cause: euv::LoanCause)
{
loan_cause: euv::LoanCause) {
debug!("borrow(borrow_id={}, cmt={}, loan_region={}, \
bk={}, loan_cause={:?})",
borrow_id, cmt.repr(self.tcx()), loan_region,
Expand Down Expand Up @@ -195,7 +194,7 @@ pub fn check_loans(bccx: &BorrowckCtxt,
};

{
let mut euv = euv::ExprUseVisitor::new(&mut clcx, bccx.tcx);
let mut euv = euv::ExprUseVisitor::new(&mut clcx, bccx);
euv.walk_fn(decl, body);
}
}
Expand Down Expand Up @@ -238,11 +237,14 @@ impl<'a> CheckLoanCtxt<'a> {

let tcx = self.tcx();
self.each_issued_loan(scope_id, |loan| {
if tcx.region_maps.is_subscope_of(scope_id, loan.kill_scope) {
op(loan)
} else {
true
let mut result = true;
for kill_scope in loan.kill_scopes.iter() {
if tcx.region_maps.is_subscope_of(scope_id, *kill_scope) {
result = op(loan);
break
}
}
result
})
}

Expand Down Expand Up @@ -369,8 +371,6 @@ impl<'a> CheckLoanCtxt<'a> {
new_loan.repr(self.tcx()));

// Should only be called for loans that are in scope at the same time.
assert!(self.tcx().region_maps.scopes_intersect(old_loan.kill_scope,
new_loan.kill_scope));

self.report_error_if_loan_conflicts_with_restriction(
old_loan, new_loan, old_loan, new_loan) &&
Expand Down Expand Up @@ -504,9 +504,11 @@ impl<'a> CheckLoanCtxt<'a> {
old_loan.span,
format!("{}; {}", borrow_summary, rule_summary).as_slice());

let old_loan_span = self.tcx().map.span(old_loan.kill_scope);
self.bccx.span_end_note(old_loan_span,
"previous borrow ends here");
for kill_scope in old_loan.kill_scopes.iter() {
let old_loan_span = self.tcx().map.span(*kill_scope);
self.bccx.span_end_note(old_loan_span,
"previous borrow ends here");
}

return false;
}
Expand Down
Loading