Skip to content

Commit 2db4259

Browse files
committed
Stop inferring bot/static when types/regions are unconstrained.
Also, some other changes that came up along the way: - add a 'blk' region for the current block. - detect unused type/region variables.
1 parent 079c3b0 commit 2db4259

30 files changed

+234
-154
lines changed

src/libcore/priv.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ native mod rustrt {
1414
fn rust_task_unweaken(ch: rust_port_id);
1515
}
1616

17-
type global_ptr<T: send> = *libc::uintptr_t;
17+
type global_ptr = *libc::uintptr_t;
1818

1919
#[doc = "
2020
Atomically gets a channel from a pointer to a pointer-sized memory location
2121
or, if no channel exists creates and installs a new channel and sets up a new
2222
task to receive from it.
2323
"]
2424
unsafe fn chan_from_global_ptr<T: send>(
25-
global: global_ptr<T>,
25+
global: global_ptr,
2626
builder: fn() -> task::builder,
2727
f: fn~(comm::port<T>)
2828
) -> comm::chan<T> {

src/libcore/vec.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,9 @@ mod unsafe {
11681168
#[inline(always)]
11691169
unsafe fn form_slice<T,U>(p: *T, len: uint, f: fn([T]/&) -> U) -> U {
11701170
let pair = (p, len * sys::size_of::<T>());
1171-
let v : *([T]/&) = ::unsafe::reinterpret_cast(ptr::addr_of(pair));
1171+
// FIXME: should use &blk not &static here, but a snapshot is req'd
1172+
let v : *([T]/&static) =
1173+
::unsafe::reinterpret_cast(ptr::addr_of(pair));
11721174
f(*v)
11731175
}
11741176
}

src/librustsyntax/ast.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -452,11 +452,7 @@ enum prim_ty {
452452
type region = {id: node_id, node: region_};
453453

454454
#[auto_serialize]
455-
enum region_ {
456-
re_anon,
457-
re_named(ident),
458-
re_static
459-
}
455+
enum region_ { re_anon, re_named(ident) }
460456

461457
#[auto_serialize]
462458
enum ty_ {

src/librustsyntax/parse/parser.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -250,16 +250,7 @@ fn parse_ret_ty(p: parser) -> (ast::ret_style, @ast::ty) {
250250

251251
fn region_from_name(p: parser, s: option<str>) -> @ast::region {
252252
let r = alt s {
253-
some (string) {
254-
// FIXME: To be consistent with our type resolution, the
255-
// static region should probably be resolved during type
256-
// checking, not in the parser. (Issue #2256)
257-
if string == "static" {
258-
ast::re_static
259-
} else {
260-
ast::re_named(string)
261-
}
262-
}
253+
some (string) { ast::re_named(string) }
263254
none { ast::re_anon }
264255
};
265256

src/librustsyntax/print/pprust.rs

-1
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,6 @@ fn print_native_mod(s: ps, nmod: ast::native_mod, attrs: [ast::attribute]) {
329329
fn print_region(s: ps, region: @ast::region) {
330330
alt region.node {
331331
ast::re_anon { word_space(s, "&"); }
332-
ast::re_static { word_space(s, "&static"); }
333332
ast::re_named(name) {
334333
word(s.s, "&");
335334
word_space(s, name);

src/rustc/metadata/creader.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -251,23 +251,23 @@ fn find_library_crate_aux(sess: session::session,
251251
if !(str::starts_with(f, prefix) && str::ends_with(f, suffix)) {
252252
#debug("skipping %s, doesn't look like %s*%s", path, prefix,
253253
suffix);
254-
option::none
254+
option::none::<()>
255255
} else {
256256
#debug("%s is a candidate", path);
257257
alt get_metadata_section(sess, path) {
258258
option::some(cvec) {
259259
if !crate_matches(cvec, metas, hash) {
260260
#debug("skipping %s, metadata doesn't match", path);
261-
option::none
261+
option::none::<()>
262262
} else {
263263
#debug("found %s with matching metadata", path);
264264
matches += [{ident: path, data: cvec}];
265-
option::none
265+
option::none::<()>
266266
}
267267
}
268268
_ {
269269
#debug("could not load metadata for %s", path);
270-
option::none
270+
option::none::<()>
271271
}
272272
}
273273
}

src/rustc/middle/infer.rs

+14-9
Original file line numberDiff line numberDiff line change
@@ -579,11 +579,8 @@ impl unify_methods for infer_ctxt {
579579
// [B]. Deep resolution, on the other hand, would yield [int].
580580
//
581581
// But there is one more knob: the force_vars variable controls the
582-
// behavior in the face of unconstrained variables. If we have A, B
583-
// and only the constraint that A <: B, then the result is [_|_] if
584-
// force_vars is true and [B] otherwise. We use force_vars == true
585-
// when resolving types after typeck, but false otherwise (for
586-
// example, when pretty-printing them for errors).
582+
// behavior in the face of unconstrained variables. If it is true,
583+
// then unconstrained variables result in an error.
587584

588585
type resolve_state = @{
589586
infcx: infer_ctxt,
@@ -673,8 +670,12 @@ impl methods for resolve_state {
673670
let r1 = alt bounds {
674671
{ ub:_, lb:some(t) } { self.resolve_region(t) }
675672
{ ub:some(t), lb:_ } { self.resolve_region(t) }
676-
{ ub:none, lb:none } if self.force_vars { ty::re_static }
677-
{ ub:none, lb:none } { ty::re_var(rid) }
673+
{ ub:none, lb:none } {
674+
if self.force_vars {
675+
self.err = some(unresolved_region(rid));
676+
}
677+
ty::re_var(rid)
678+
}
678679
};
679680
vec::pop(self.r_seen);
680681
ret r1;
@@ -700,8 +701,12 @@ impl methods for resolve_state {
700701
{ ub:_, lb:some(t) } if !type_is_bot(t) { self.resolve1(t) }
701702
{ ub:some(t), lb:_ } { self.resolve1(t) }
702703
{ ub:_, lb:some(t) } { self.resolve1(t) }
703-
{ ub:none, lb:none } if self.force_vars { ty::mk_bot(tcx) }
704-
{ ub:none, lb:none } { ty::mk_var(tcx, vid) }
704+
{ ub:none, lb:none } {
705+
if self.force_vars {
706+
self.err = some(unresolved_ty(vid));
707+
}
708+
ty::mk_var(tcx, vid)
709+
}
705710
};
706711
vec::pop(self.v_seen);
707712
ret t1;

src/rustc/middle/kind.rs

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import syntax::codemap::span;
44
import ty::{kind, kind_copyable, kind_sendable, kind_noncopyable};
55
import driver::session::session;
66
import std::map::hashmap;
7+
import syntax::print::pprust::expr_to_str;
78

89
// Kind analysis pass. There are three kinds:
910
//
@@ -138,6 +139,7 @@ fn check_block(b: blk, cx: ctx, v: visit::vt<ctx>) {
138139
}
139140

140141
fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) {
142+
#debug["kind::check_expr(%s)", expr_to_str(e)];
141143
alt e.node {
142144
expr_assign(_, ex) | expr_assign_op(_, _, ex) |
143145
expr_unary(box(_), ex) | expr_unary(uniq(_), ex) |

src/rustc/middle/ty.rs

+24-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export expr_ty_params_and_ty;
3737
export expr_is_lval;
3838
export field_ty;
3939
export fold_ty, fold_sty_to_ty, fold_region, fold_regions, fold_ty_var;
40-
export fold_regions_and_ty;
40+
export fold_regions_and_ty, walk_regions_and_ty;
4141
export field;
4242
export field_idx;
4343
export get_field;
@@ -97,7 +97,7 @@ export ty_tup, mk_tup;
9797
export ty_type, mk_type;
9898
export ty_uint, mk_uint, mk_mach_uint;
9999
export ty_uniq, mk_uniq, mk_imm_uniq, type_is_unique_box;
100-
export ty_var, mk_var;
100+
export ty_var, mk_var, type_is_var;
101101
export ty_self, mk_self;
102102
export region, bound_region;
103103
export get, type_has_params, type_has_vars, type_has_regions;
@@ -818,6 +818,21 @@ fn fold_ty_var(cx: ctxt, t0: t, fldop: fn(ty_vid) -> t) -> t {
818818
}
819819
}
820820

821+
fn walk_regions_and_ty(
822+
cx: ctxt,
823+
ty: t,
824+
walkr: fn(r: region),
825+
walkt: fn(t: t) -> bool) {
826+
827+
if (walkt(ty)) {
828+
fold_regions_and_ty(
829+
cx, ty,
830+
{ |r| walkr(r); r },
831+
{ |t| walkt(t); walk_regions_and_ty(cx, t, walkr, walkt); t },
832+
{ |t| walkt(t); walk_regions_and_ty(cx, t, walkr, walkt); t });
833+
}
834+
}
835+
821836
fn fold_regions_and_ty(
822837
cx: ctxt,
823838
ty: t,
@@ -1000,6 +1015,13 @@ fn type_is_nil(ty: t) -> bool { get(ty).struct == ty_nil }
10001015

10011016
fn type_is_bot(ty: t) -> bool { get(ty).struct == ty_bot }
10021017

1018+
fn type_is_var(ty: t) -> bool {
1019+
alt get(ty).struct {
1020+
ty_var(_) { true }
1021+
_ { false }
1022+
}
1023+
}
1024+
10031025
fn type_is_bool(ty: t) -> bool { get(ty).struct == ty_bool }
10041026

10051027
fn type_is_structural(ty: t) -> bool {

0 commit comments

Comments
 (0)