Skip to content

Commit 9cf48d3

Browse files
committed
Preparation for kind system overhaul
This goes before a snapshot, so that subsequenct patches can make the transition without breaking the build. Disables kind checking pass, makes parser accept both new and old-style kind annotation. Issue #1177
1 parent eff7fae commit 9cf48d3

26 files changed

+78
-58
lines changed

src/comp/metadata/decoder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ fn item_ty_param_kinds(item: ebml::doc) -> [ast::kind] {
116116
while i < vi.val {
117117
let k =
118118
alt dat[vi.next + i] as char {
119-
'u' { ast::kind_unique }
120-
's' { ast::kind_shared }
121-
'p' { ast::kind_pinned }
119+
's' { ast::kind_sendable }
120+
'c' { ast::kind_copyable }
121+
'a' { ast::kind_noncopyable }
122122
};
123123
ks += [k];
124124
i += 1u;

src/comp/metadata/encoder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@ fn encode_type_param_kinds(ebml_w: ebml::writer, tps: [ty_param]) {
170170
ebml::write_vint(ebml_w.writer, vec::len::<ty_param>(tps));
171171
for tp: ty_param in tps {
172172
let c = alt ast_util::ty_param_kind(tp) {
173-
kind_unique. { 'u' }
174-
kind_shared. { 's' }
175-
kind_pinned. { 'p' }
173+
kind_sendable. { 's' }
174+
kind_copyable. { 'c' }
175+
kind_noncopyable. { 'a' }
176176
};
177177
ebml_w.writer.write([c as u8]);
178178
}

src/comp/metadata/tydecode.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,9 @@ fn parse_ty(st: @pstate, sd: str_def) -> ty::t {
204204
'p' {
205205
let k =
206206
alt next(st) as char {
207-
'u' { kind_unique }
208-
's' { kind_shared }
209-
'p' { kind_pinned }
207+
's' { kind_sendable }
208+
'c' { kind_copyable }
209+
'a' { kind_noncopyable }
210210
c {
211211
log_err "unexpected char in encoded type param: ";
212212
log_err c;

src/comp/metadata/tyencode.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,9 @@ fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) {
172172
}
173173
ty::ty_param(id, k) {
174174
alt k {
175-
kind_unique. { w.write_str("pu"); }
176-
kind_shared. { w.write_str("ps"); }
177-
kind_pinned. { w.write_str("pp"); }
175+
kind_sendable. { w.write_str("ps"); }
176+
kind_copyable. { w.write_str("pc"); }
177+
kind_noncopyable. { w.write_str("pa"); }
178178
}
179179
w.write_str(uint::str(id));
180180
}

src/comp/middle/kind.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,14 @@
8484
*
8585
*/
8686

87-
import syntax::{ast, ast_util, visit, codemap};
88-
import std::{vec, option};
89-
import ast::{kind, kind_unique, kind_shared, kind_pinned};
87+
import syntax::ast;
88+
import ast::{kind, kind_sendable, kind_copyable, kind_noncopyable};
9089

9190
fn kind_lteq(a: kind, b: kind) -> bool {
9291
alt a {
93-
kind_pinned. { true }
94-
kind_shared. { b != kind_pinned }
95-
kind_unique. { b == kind_unique }
92+
kind_noncopyable. { true }
93+
kind_copyable. { b != kind_noncopyable }
94+
kind_sendable. { b == kind_sendable }
9695
}
9796
}
9897

@@ -102,12 +101,12 @@ fn lower_kind(a: kind, b: kind) -> kind {
102101

103102
fn kind_to_str(k: kind) -> str {
104103
alt k {
105-
ast::kind_pinned. { "pinned" }
106-
ast::kind_unique. { "unique" }
107-
ast::kind_shared. { "shared" }
104+
ast::kind_sendable. { "sendable" }
105+
ast::kind_copyable. { "copyable" }
106+
ast::kind_noncopyable. { "noncopyable" }
108107
}
109108
}
110-
109+
/*
111110
fn type_and_kind(tcx: ty::ctxt, e: @ast::expr) ->
112111
{ty: ty::t, kind: ast::kind} {
113112
let t = ty::expr_ty(tcx, e);
@@ -138,8 +137,8 @@ fn demand_kind(tcx: ty::ctxt, sp: codemap::span, t: ty::t,
138137
}
139138
140139
fn need_shared_lhs_rhs(tcx: ty::ctxt, a: @ast::expr, b: @ast::expr, op: str) {
141-
need_expr_kind(tcx, a, ast::kind_shared, op + " lhs");
142-
need_expr_kind(tcx, b, ast::kind_shared, op + " rhs");
140+
need_expr_kind(tcx, a, ast::kind_copyable, op + " lhs");
141+
need_expr_kind(tcx, b, ast::kind_copyable, op + " rhs");
143142
}
144143
145144
/*
@@ -296,14 +295,15 @@ fn check_stmt(tcx: ty::ctxt, stmt: @ast::stmt) {
296295
_ { /* fall through */ }
297296
}
298297
}
299-
300-
fn check_crate(tcx: ty::ctxt, crate: @ast::crate) {
301-
let visit =
298+
*/
299+
fn check_crate(_tcx: ty::ctxt, _crate: @ast::crate) {
300+
// FIXME stubbed out
301+
/* let visit =
302302
visit::mk_simple_visitor(@{visit_expr: bind check_expr(tcx, _),
303303
visit_stmt: bind check_stmt(tcx, _)
304304
with *visit::default_simple_visitor()});
305305
visit::visit_crate(*crate, (), visit);
306-
tcx.sess.abort_if_errors();
306+
tcx.sess.abort_if_errors();*/
307307
}
308308

309309
//

src/comp/middle/ty.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ fn type_kind(cx: ctxt, ty: t) -> ast::kind {
993993
none. {/* fall through */ }
994994
}
995995

996-
let result = ast::kind_unique;
996+
let result = ast::kind_noncopyable;
997997

998998
// Insert a default in case we loop back on self recursively.
999999
cx.kind_cache.insert(ty, result);
@@ -1011,21 +1011,21 @@ fn type_kind(cx: ctxt, ty: t) -> ast::kind {
10111011
// FIXME: obj is broken for now, since we aren't asserting
10121012
// anything about its fields.
10131013
ty_obj(_) {
1014-
result = kind_shared;
1014+
result = kind_copyable;
10151015
}
10161016
// FIXME: the environment capture mode is not fully encoded
10171017
// here yet, leading to weirdness around closure.
10181018
ty_fn(proto, _, _, _, _) {
10191019
result = alt proto {
1020-
ast::proto_block. { ast::kind_pinned }
1021-
ast::proto_shared(_) { ast::kind_shared }
1022-
ast::proto_bare. { ast::kind_unique }
1020+
ast::proto_block. { ast::kind_noncopyable }
1021+
ast::proto_shared(_) { ast::kind_copyable }
1022+
ast::proto_bare. { ast::kind_sendable }
10231023
};
10241024
}
10251025
// Those with refcounts-to-inner raise pinned to shared,
10261026
// lower unique to shared. Therefore just set result to shared.
10271027
ty_box(mt) {
1028-
result = ast::kind_shared;
1028+
result = ast::kind_copyable;
10291029
}
10301030
// Pointers and unique containers raise pinned to shared.
10311031
ty_ptr(tm) | ty_vec(tm) | ty_uniq(tm) {
@@ -1044,14 +1044,14 @@ fn type_kind(cx: ctxt, ty: t) -> ast::kind {
10441044
ty_rec(flds) {
10451045
for f: field in flds {
10461046
result = kind::lower_kind(result, type_kind(cx, f.mt.ty));
1047-
if result == ast::kind_pinned { break; }
1047+
if result == ast::kind_noncopyable { break; }
10481048
}
10491049
}
10501050
// Tuples lower to the lowest of their members.
10511051
ty_tup(tys) {
10521052
for ty: t in tys {
10531053
result = kind::lower_kind(result, type_kind(cx, ty));
1054-
if result == ast::kind_pinned { break; }
1054+
if result == ast::kind_noncopyable { break; }
10551055
}
10561056
}
10571057
// Tags lower to the lowest of their variants.
@@ -1062,14 +1062,14 @@ fn type_kind(cx: ctxt, ty: t) -> ast::kind {
10621062
// Perform any type parameter substitutions.
10631063
let arg_ty = substitute_type_params(cx, tps, aty);
10641064
result = kind::lower_kind(result, type_kind(cx, arg_ty));
1065-
if result == ast::kind_pinned { break; }
1065+
if result == ast::kind_noncopyable { break; }
10661066
}
1067-
if result == ast::kind_pinned { break; }
1067+
if result == ast::kind_noncopyable { break; }
10681068
}
10691069
}
10701070
// Resources are always pinned.
10711071
ty_res(did, inner, tps) {
1072-
result = ast::kind_pinned;
1072+
result = ast::kind_noncopyable;
10731073
}
10741074
ty_var(_) {
10751075
fail;

src/comp/syntax/ast.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ type def_id = {crate: crate_num, node: node_id};
2323

2424
const local_crate: crate_num = 0;
2525

26+
tag plicit<T> { explicit(T); implicit(T); }
27+
2628
type ty_param = {ident: ident, kind: plicit<kind>};
2729

2830
tag def {
@@ -99,8 +101,7 @@ tag pat_ {
99101

100102
tag mutability { mut; imm; maybe_mut; }
101103

102-
tag plicit<T> { explicit(T); implicit(T); }
103-
tag kind { kind_pinned; kind_shared; kind_unique; kind_auto; }
104+
tag kind { kind_sendable; kind_copyable; kind_noncopyable; }
104105

105106
tag _auth { auth_unsafe; }
106107

src/comp/syntax/ast_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ fn ret_by_ref(style: ret_style) -> bool {
229229
}
230230

231231
fn ty_param_kind(tp: ty_param) -> kind {
232-
alt tp.kind { explicit(x) | implicit(x) { x } }
232+
alt tp.kind { ast::implicit(x) | ast::explicit(x) { x } }
233233
}
234234

235235
// Local Variables:

src/comp/syntax/parse/parser.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,21 +1738,24 @@ fn parse_block_tail(p: parser, lo: uint, s: ast::blk_check_mode) -> ast::blk {
17381738
ret spanned(lo, hi, bloc);
17391739
}
17401740

1741-
fn parse_ty_param(default: ast::kind, p: parser) -> ast::ty_param {
1742-
let k = if eat_word(p, "pin") { ast::explicit(ast::kind_pinned) }
1743-
else if eat_word(p, "uniq") { ast::explicit(ast::kind_unique) }
1744-
else if eat_word(p, "shar") { ast::explicit(ast::kind_shared) }
1745-
// FIXME distinguish implied shared from explicit
1746-
else { ast::implicit(default) };
1741+
fn parse_ty_param(p: parser, def: ast::kind) -> ast::ty_param {
1742+
// Accept both old and new kind names for now. FIXME remove this
1743+
let k = if eat_word(p, "send") | eat_word(p, "uniq")
1744+
{ ast::explicit(ast::kind_sendable) }
1745+
else if eat_word(p, "copy") | eat_word(p, "shar")
1746+
{ ast::explicit(ast::kind_copyable) }
1747+
else if eat_word(p, "nocopy") | eat_word(p, "pin")
1748+
{ ast::explicit(ast::kind_noncopyable) }
1749+
else { ast::implicit(def) };
17471750
ret {ident: parse_ident(p), kind: k};
17481751
}
17491752

1750-
fn parse_ty_params(p: parser, default: ast::kind) -> [ast::ty_param] {
1753+
fn parse_ty_params(p: parser, def: ast::kind) -> [ast::ty_param] {
17511754
let ty_params: [ast::ty_param] = [];
17521755
if p.peek() == token::LT {
17531756
p.bump();
17541757
ty_params = parse_seq_to_gt(some(token::COMMA),
1755-
{|p| parse_ty_param(default, p)}, p);
1758+
{|p| parse_ty_param(p, def)}, p);
17561759
}
17571760
ret ty_params;
17581761
}
@@ -1805,7 +1808,7 @@ fn parse_fn(p: parser, proto: ast::proto, purity: ast::purity,
18051808

18061809
fn parse_fn_header(p: parser) -> {ident: ast::ident, tps: [ast::ty_param]} {
18071810
let id = parse_value_ident(p);
1808-
let ty_params = parse_ty_params(p, ast::kind_shared);
1811+
let ty_params = parse_ty_params(p, ast::kind_copyable);
18091812
ret {ident: id, tps: ty_params};
18101813
}
18111814

@@ -1858,7 +1861,7 @@ fn parse_method(p: parser) -> @ast::method {
18581861
fn parse_item_obj(p: parser, attrs: [ast::attribute]) -> @ast::item {
18591862
let lo = p.get_last_lo_pos();
18601863
let ident = parse_value_ident(p);
1861-
let ty_params = parse_ty_params(p, ast::kind_pinned);
1864+
let ty_params = parse_ty_params(p, ast::kind_copyable);
18621865
let fields: ast::spanned<[ast::obj_field]> =
18631866
parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA),
18641867
parse_obj_field, p);
@@ -1875,7 +1878,7 @@ fn parse_item_obj(p: parser, attrs: [ast::attribute]) -> @ast::item {
18751878
fn parse_item_res(p: parser, attrs: [ast::attribute]) -> @ast::item {
18761879
let lo = p.get_last_lo_pos();
18771880
let ident = parse_value_ident(p);
1878-
let ty_params = parse_ty_params(p, ast::kind_pinned);
1881+
let ty_params = parse_ty_params(p, ast::kind_noncopyable);
18791882
expect(p, token::LPAREN);
18801883
let arg_ident = parse_value_ident(p);
18811884
expect(p, token::COLON);
@@ -2039,7 +2042,7 @@ fn parse_type_decl(p: parser) -> {lo: uint, ident: ast::ident} {
20392042

20402043
fn parse_item_type(p: parser, attrs: [ast::attribute]) -> @ast::item {
20412044
let t = parse_type_decl(p);
2042-
let tps = parse_ty_params(p, ast::kind_pinned);
2045+
let tps = parse_ty_params(p, ast::kind_noncopyable);
20432046
expect(p, token::EQ);
20442047
let ty = parse_ty(p, false);
20452048
let hi = p.get_hi_pos();
@@ -2050,7 +2053,7 @@ fn parse_item_type(p: parser, attrs: [ast::attribute]) -> @ast::item {
20502053
fn parse_item_tag(p: parser, attrs: [ast::attribute]) -> @ast::item {
20512054
let lo = p.get_last_lo_pos();
20522055
let id = parse_ident(p);
2053-
let ty_params = parse_ty_params(p, ast::kind_pinned);
2056+
let ty_params = parse_ty_params(p, ast::kind_noncopyable);
20542057
let variants: [ast::variant] = [];
20552058
// Newtype syntax
20562059
if p.peek() == token::EQ {

src/comp/syntax/print/pprust.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,10 +1168,10 @@ fn print_arg_mode(s: ps, m: ast::mode) {
11681168
11691169
fn print_kind(s: ps, kind: ast::plicit<ast::kind>) {
11701170
alt kind {
1171+
ast::explicit(ast::kind_sendable.) { word_nbsp(s, "send"); }
1172+
ast::explicit(ast::kind_copyable.) { word_nbsp(s, "copy"); }
1173+
ast::explicit(ast::kind_noncopyable.) { word_nbsp(s, "nocopy"); }
11711174
ast::implicit(_) {}
1172-
ast::explicit(ast::kind_unique.) { word_nbsp(s, "uniq"); }
1173-
ast::explicit(ast::kind_pinned.) { word_nbsp(s, "pin"); }
1174-
ast::explicit(ast::kind_shared.) { word_nbsp(s, "shar"); }
11751175
}
11761176
}
11771177

src/test/compile-fail/block-copy.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// error-pattern: needed shared type, got pinned type block
2+
// xfail-test
23

34
fn lol(f: block()) -> block() { ret f; }
45
fn main() { let i = 8; let f = lol(block () { log_err i; }); f(); }

src/test/compile-fail/copy-a-resource.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// error-pattern:cannot copy pinned type foo
2+
// xfail-test
23

34
resource foo(i: int) { }
45

src/test/compile-fail/copy-res-into-box.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// error-pattern:mismatched kinds for '@' operand
2+
// xfail-test
23
resource r(i: @mutable int) {
34
*i = *i + 1;
45
}

src/test/compile-fail/copy-res-into-rec.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// error-pattern:mismatched kinds for record field
2+
// xfail-test
23
resource r(i: @mutable int) {
34
*i = *i + 1;
45
}

src/test/compile-fail/copy-res-into-tup.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// error-pattern:mismatched kinds for tuple parameter
2+
// xfail-test
23
resource r(i: @mutable int) {
34
*i = *i + 1;
45
}

src/test/compile-fail/copy-res-into-unique.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// error-pattern:mismatched kinds for '~' operand
2+
// xfail-test
23
resource r(i: @mutable int) {
34
*i = *i + 1;
45
}

src/test/compile-fail/pinned-deep-copy.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// error-pattern: cannot copy pinned type ~~~{y: r}
2+
// xfail-test
23

34
resource r(i: @mutable int) {
45
*i = *i + 1;

src/test/compile-fail/resource-let2.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// error-pattern: mismatched kind
2+
// xfail-test
23

34
resource r(b: bool) {
45
}

src/test/compile-fail/unique-pinned-nocopy.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// error-pattern: mismatched kind
2+
// xfail-test
23

34
resource r(b: bool) {
45
}

src/test/compile-fail/unique-swap2.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// error-pattern:needed shared type, got pinned type ~r
2+
// xfail-test
23

34
resource r(i: @mutable int) {
45
*i += 1;

src/test/compile-fail/unique-unique-kind.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// error-pattern: needed unique type
2+
// xfail-test
23

34
fn f<uniq T>(i: T) {
45
}

src/test/compile-fail/unique-vec-res.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// error-pattern: needed shared type, got pinned type ~r
2+
// xfail-test
23

34
resource r(i: @mutable int) {
45
*i = *i + 1;

src/test/compile-fail/vec-pinned-nocopy-2.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// error-pattern: mismatched kind
2+
// xfail-test
23

34
resource r(b: bool) {
45
}

src/test/compile-fail/vec-pinned-nocopy-3.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// error-pattern: mismatched kind
2+
// xfail-test
23

34
resource r(b: bool) {
45
}

0 commit comments

Comments
 (0)