Skip to content

Commit 7801eb8

Browse files
committed
---
yaml --- r: 68585 b: refs/heads/auto c: 77b9824 h: refs/heads/master i: 68583: 0e71cd4 v: v3
1 parent 6502ed0 commit 7801eb8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1366
-2509
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1414
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1515
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1616
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
17-
refs/heads/auto: ef5c439fb006875d3d54b3b100f5411efc2c40f3
17+
refs/heads/auto: 77b98247a26dcba11bd04f27ff8f5252ecd97df5
1818
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1919
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c

branches/auto/src/librustc/middle/region.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ pass builds up the `scope_map`, which describes the parent links in
1515
the region hierarchy. The second pass infers which types must be
1616
region parameterized.
1717
18-
Most of the documentation on regions can be found in
19-
`middle/typeck/infer/region_inference.rs`
20-
2118
*/
2219

2320

branches/auto/src/librustc/middle/typeck/check/_match.rs

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use middle::typeck::check::demand;
1515
use middle::typeck::check::{check_block, check_expr_has_type, FnCtxt};
1616
use middle::typeck::check::{instantiate_path, lookup_def};
1717
use middle::typeck::check::{structure_of, valid_range_bounds};
18-
use middle::typeck::infer;
1918
use middle::typeck::require_same_types;
2019

2120
use std::hashmap::{HashMap, HashSet};
@@ -30,31 +29,26 @@ pub fn check_match(fcx: @mut FnCtxt,
3029
arms: &[ast::arm]) {
3130
let tcx = fcx.ccx.tcx;
3231

33-
let discrim_ty = fcx.infcx().next_ty_var();
34-
check_expr_has_type(fcx, discrim, discrim_ty);
32+
let pattern_ty = fcx.infcx().next_ty_var();
33+
check_expr_has_type(fcx, discrim, pattern_ty);
3534

3635
// Typecheck the patterns first, so that we get types for all the
3736
// bindings.
3837
for arms.iter().advance |arm| {
3938
let pcx = pat_ctxt {
4039
fcx: fcx,
4140
map: pat_id_map(tcx.def_map, arm.pats[0]),
41+
match_region: ty::re_scope(expr.id),
42+
block_region: ty::re_scope(arm.body.node.id)
4243
};
4344

44-
for arm.pats.iter().advance |p| { check_pat(&pcx, *p, discrim_ty);}
45+
for arm.pats.iter().advance |p| { check_pat(&pcx, *p, pattern_ty);}
4546
}
4647

47-
// The result of the match is the common supertype of all the
48-
// arms. Start out the value as bottom, since it's the, well,
49-
// bottom the type lattice, and we'll be moving up the lattice as
50-
// we process each arm. (Note that any match with 0 arms is matching
51-
// on any empty type and is therefore unreachable; should the flow
52-
// of execution reach it, we will fail, so bottom is an appropriate
53-
// type in that case)
54-
let mut result_ty = ty::mk_bot();
55-
5648
// Now typecheck the blocks.
57-
let mut saw_err = ty::type_is_error(discrim_ty);
49+
let mut result_ty = fcx.infcx().next_ty_var();
50+
let mut arm_non_bot = false;
51+
let mut saw_err = false;
5852
for arms.iter().advance |arm| {
5953
let mut guard_err = false;
6054
let mut guard_bot = false;
@@ -81,28 +75,26 @@ pub fn check_match(fcx: @mut FnCtxt,
8175
else if guard_bot {
8276
fcx.write_bot(arm.body.node.id);
8377
}
84-
85-
result_ty =
86-
infer::common_supertype(
87-
fcx.infcx(),
88-
infer::MatchExpression(expr.span),
89-
true, // result_ty is "expected" here
90-
result_ty,
91-
bty);
78+
else if !ty::type_is_bot(bty) {
79+
arm_non_bot = true; // If the match *may* evaluate to a non-_|_
80+
// expr, the whole thing is non-_|_
81+
}
82+
demand::suptype(fcx, arm.body.span, result_ty, bty);
9283
}
93-
9484
if saw_err {
9585
result_ty = ty::mk_err();
96-
} else if ty::type_is_bot(discrim_ty) {
86+
}
87+
else if !arm_non_bot {
9788
result_ty = ty::mk_bot();
9889
}
99-
10090
fcx.write_ty(expr.id, result_ty);
10191
}
10292

10393
pub struct pat_ctxt {
10494
fcx: @mut FnCtxt,
10595
map: PatIdMap,
96+
match_region: ty::Region, // Region for the match as a whole
97+
block_region: ty::Region, // Region for the block of the arm
10698
}
10799

108100
pub fn check_pat_variant(pcx: &pat_ctxt, pat: @ast::pat, path: @ast::Path,
@@ -450,8 +442,8 @@ pub fn check_pat(pcx: &pat_ctxt, pat: @ast::pat, expected: ty::t) {
450442
// then the type of x is &M T where M is the mutability
451443
// and T is the expected type
452444
let region_var =
453-
fcx.infcx().next_region_var(
454-
infer::PatternRegion(pat.span));
445+
fcx.infcx().next_region_var_with_lb(
446+
pat.span, pcx.block_region);
455447
let mt = ty::mt {ty: expected, mutbl: mutbl};
456448
let region_ty = ty::mk_rptr(tcx, region_var, mt);
457449
demand::eqtype(fcx, pat.span, region_ty, typ);
@@ -552,8 +544,9 @@ pub fn check_pat(pcx: &pat_ctxt, pat: @ast::pat, expected: ty::t) {
552544
}
553545
ast::pat_vec(ref before, slice, ref after) => {
554546
let default_region_var =
555-
fcx.infcx().next_region_var(
556-
infer::PatternRegion(pat.span));
547+
fcx.infcx().next_region_var_with_lb(
548+
pat.span, pcx.block_region
549+
);
557550
558551
let (elt_type, region_var) = match structure_of(
559552
fcx, pat.span, expected
@@ -658,4 +651,3 @@ pub fn check_pointer_pat(pcx: &pat_ctxt,
658651

659652
#[deriving(Eq)]
660653
enum PointerKind { Managed, Send, Borrowed }
661-

branches/auto/src/librustc/middle/typeck/check/demand.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn suptype_with_fn(fcx: @mut FnCtxt,
3535
ty_a: ty::t, ty_b: ty::t,
3636
handle_err: &fn(span, ty::t, ty::t, &ty::type_err)) {
3737
// n.b.: order of actual, expected is reversed
38-
match infer::mk_subty(fcx.infcx(), b_is_expected, infer::Misc(sp),
38+
match infer::mk_subty(fcx.infcx(), b_is_expected, sp,
3939
ty_b, ty_a) {
4040
result::Ok(()) => { /* ok */ }
4141
result::Err(ref err) => {
@@ -45,7 +45,7 @@ pub fn suptype_with_fn(fcx: @mut FnCtxt,
4545
}
4646

4747
pub fn eqtype(fcx: @mut FnCtxt, sp: span, expected: ty::t, actual: ty::t) {
48-
match infer::mk_eqty(fcx.infcx(), false, infer::Misc(sp), actual, expected) {
48+
match infer::mk_eqty(fcx.infcx(), false, sp, actual, expected) {
4949
Ok(()) => { /* ok */ }
5050
Err(ref err) => {
5151
fcx.report_mismatched_types(sp, expected, actual, err);

branches/auto/src/librustc/middle/typeck/check/method.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -619,18 +619,14 @@ impl<'self> LookupContext<'self> {
619619
autoref: None}))
620620
}
621621
ty::ty_rptr(_, self_mt) => {
622-
let region =
623-
self.infcx().next_region_var(
624-
infer::Autoref(self.expr.span));
622+
let region = self.infcx().next_region_var_nb(self.expr.span);
625623
(ty::mk_rptr(tcx, region, self_mt),
626624
ty::AutoDerefRef(ty::AutoDerefRef {
627625
autoderefs: autoderefs+1,
628626
autoref: Some(ty::AutoPtr(region, self_mt.mutbl))}))
629627
}
630628
ty::ty_evec(self_mt, vstore_slice(_)) => {
631-
let region =
632-
self.infcx().next_region_var(
633-
infer::Autoref(self.expr.span));
629+
let region = self.infcx().next_region_var_nb(self.expr.span);
634630
(ty::mk_evec(tcx, self_mt, vstore_slice(region)),
635631
ty::AutoDerefRef(ty::AutoDerefRef {
636632
autoderefs: autoderefs,
@@ -762,9 +758,7 @@ impl<'self> LookupContext<'self> {
762758
-> Option<method_map_entry> {
763759
// This is hokey. We should have mutability inference as a
764760
// variable. But for now, try &const, then &, then &mut:
765-
let region =
766-
self.infcx().next_region_var(
767-
infer::Autoref(self.expr.span));
761+
let region = self.infcx().next_region_var_nb(self.expr.span);
768762
for mutbls.iter().advance |mutbl| {
769763
let autoref_ty = mk_autoref_ty(*mutbl, region);
770764
match self.search_for_method(autoref_ty) {
@@ -976,8 +970,7 @@ impl<'self> LookupContext<'self> {
976970
let (_, opt_transformed_self_ty, fn_sig) =
977971
replace_bound_regions_in_fn_sig(
978972
tcx, @Nil, Some(transformed_self_ty), &bare_fn_ty.sig,
979-
|br| self.fcx.infcx().next_region_var(
980-
infer::BoundRegionInFnCall(self.expr.span, br)));
973+
|_br| self.fcx.infcx().next_region_var_nb(self.expr.span));
981974
let transformed_self_ty = opt_transformed_self_ty.get();
982975
let fty = ty::mk_bare_fn(tcx, ty::BareFnTy {sig: fn_sig, ..bare_fn_ty});
983976
debug!("after replacing bound regions, fty=%s", self.ty_to_str(fty));
@@ -989,7 +982,7 @@ impl<'self> LookupContext<'self> {
989982
// variables to unify etc). Since we checked beforehand, and
990983
// nothing has changed in the meantime, this unification
991984
// should never fail.
992-
match self.fcx.mk_subty(false, infer::Misc(self.self_expr.span),
985+
match self.fcx.mk_subty(false, self.self_expr.span,
993986
rcvr_ty, transformed_self_ty) {
994987
result::Ok(_) => (),
995988
result::Err(_) => {

0 commit comments

Comments
 (0)