Skip to content

Commit 9236fdf

Browse files
committed
Move the kind datatype to middle::ty
The AST no longer references it.
1 parent 1ed6a27 commit 9236fdf

File tree

3 files changed

+53
-52
lines changed

3 files changed

+53
-52
lines changed

src/comp/middle/kind.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import option::{some, none};
22
import syntax::{visit, ast_util};
33
import syntax::ast::*;
44
import syntax::codemap::span;
5+
import ty::{kind, kind_copyable, kind_sendable, kind_noncopyable};
56

67
// Kind analysis pass. There are three kinds:
78
//
@@ -135,7 +136,7 @@ fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) {
135136
let ty_fields = alt ty::struct(cx.tcx, t) { ty::ty_rec(f) { f } };
136137
for tf in ty_fields {
137138
if !vec::any(fields, {|f| f.node.ident == tf.ident}) &&
138-
!kind_can_be_copied(ty::type_kind(cx.tcx, tf.mt.ty)) {
139+
!ty::kind_can_be_copied(ty::type_kind(cx.tcx, tf.mt.ty)) {
139140
cx.tcx.sess.span_err(ex.span,
140141
"copying a noncopyable value");
141142
}
@@ -221,13 +222,13 @@ fn check_copy_ex(cx: ctx, ex: @expr, _warn: bool) {
221222
}
222223

223224
fn check_copy(cx: ctx, ty: ty::t, sp: span) {
224-
if !kind_can_be_copied(ty::type_kind(cx.tcx, ty)) {
225+
if !ty::kind_can_be_copied(ty::type_kind(cx.tcx, ty)) {
225226
cx.tcx.sess.span_err(sp, "copying a noncopyable value");
226227
}
227228
}
228229

229230
fn check_send(cx: ctx, ty: ty::t, sp: span) {
230-
if !kind_can_be_sent(ty::type_kind(cx.tcx, ty)) {
231+
if !ty::kind_can_be_sent(ty::type_kind(cx.tcx, ty)) {
231232
cx.tcx.sess.span_err(sp, "not a sendable value");
232233
}
233234
}

src/comp/middle/ty.rs

+49-19
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ export ty_fn_args;
145145
export type_constr;
146146
export type_contains_params;
147147
export type_contains_vars;
148-
export kind_lteq;
149-
export type_kind;
148+
export kind, kind_sendable, kind_copyable, kind_noncopyable;
149+
export kind_can_be_copied, kind_can_be_sent, proto_kind, kind_lteq, type_kind;
150150
export type_err;
151151
export type_err_to_str;
152152
export type_has_dynamic_size;
@@ -216,7 +216,7 @@ type ctxt =
216216
rcache: creader_cache,
217217
short_names_cache: hashmap<t, @str>,
218218
needs_drop_cache: hashmap<t, bool>,
219-
kind_cache: hashmap<t, ast::kind>,
219+
kind_cache: hashmap<t, kind>,
220220
ast_ty_to_ty_cache: hashmap<@ast::ty, option::t<t>>,
221221
tag_var_cache: hashmap<ast::def_id, @[variant_info]>,
222222
iface_method_cache: hashmap<def_id, @[method]>,
@@ -308,14 +308,14 @@ tag param_bound {
308308
bound_iface(t);
309309
}
310310

311-
fn param_bounds_to_kind(bounds: @[param_bound]) -> ast::kind {
312-
let kind = ast::kind_noncopyable;
311+
fn param_bounds_to_kind(bounds: @[param_bound]) -> kind {
312+
let kind = kind_noncopyable;
313313
for bound in *bounds {
314314
alt bound {
315315
bound_copy. {
316-
if kind != ast::kind_sendable { kind = ast::kind_copyable; }
316+
if kind != kind_sendable { kind = kind_copyable; }
317317
}
318-
bound_send. { kind = ast::kind_sendable; }
318+
bound_send. { kind = kind_sendable; }
319319
_ {}
320320
}
321321
}
@@ -847,7 +847,7 @@ fn type_is_structural(cx: ctxt, ty: t) -> bool {
847847
}
848848

849849
fn type_is_copyable(cx: ctxt, ty: t) -> bool {
850-
ret ast::kind_can_be_copied(type_kind(cx, ty));
850+
ret kind_can_be_copied(type_kind(cx, ty));
851851
}
852852

853853
fn type_is_sequence(cx: ctxt, ty: t) -> bool {
@@ -989,6 +989,36 @@ fn type_needs_drop(cx: ctxt, ty: t) -> bool {
989989
ret result;
990990
}
991991

992+
tag kind { kind_sendable; kind_copyable; kind_noncopyable; }
993+
994+
// Using these query functons is preferable to direct comparison or matching
995+
// against the kind constants, as we may modify the kind hierarchy in the
996+
// future.
997+
pure fn kind_can_be_copied(k: kind) -> bool {
998+
ret alt k {
999+
kind_sendable. { true }
1000+
kind_copyable. { true }
1001+
kind_noncopyable. { false }
1002+
};
1003+
}
1004+
1005+
pure fn kind_can_be_sent(k: kind) -> bool {
1006+
ret alt k {
1007+
kind_sendable. { true }
1008+
kind_copyable. { false }
1009+
kind_noncopyable. { false }
1010+
};
1011+
}
1012+
1013+
fn proto_kind(p: proto) -> kind {
1014+
alt p {
1015+
ast::proto_block. { kind_noncopyable }
1016+
ast::proto_shared(_) { kind_copyable }
1017+
ast::proto_send. { kind_sendable }
1018+
ast::proto_bare. { kind_sendable }
1019+
}
1020+
}
1021+
9921022
fn kind_lteq(a: kind, b: kind) -> bool {
9931023
alt a {
9941024
kind_noncopyable. { true }
@@ -1001,58 +1031,58 @@ fn lower_kind(a: kind, b: kind) -> kind {
10011031
if ty::kind_lteq(a, b) { a } else { b }
10021032
}
10031033

1004-
fn type_kind(cx: ctxt, ty: t) -> ast::kind {
1034+
fn type_kind(cx: ctxt, ty: t) -> kind {
10051035
alt cx.kind_cache.find(ty) {
10061036
some(result) { ret result; }
10071037
none. {/* fall through */ }
10081038
}
10091039

10101040
// Insert a default in case we loop back on self recursively.
1011-
cx.kind_cache.insert(ty, ast::kind_sendable);
1041+
cx.kind_cache.insert(ty, kind_sendable);
10121042

10131043
let result = alt struct(cx, ty) {
10141044
// Scalar and unique types are sendable
10151045
ty_nil. | ty_bot. | ty_bool. | ty_int(_) | ty_uint(_) | ty_float(_) |
10161046
ty_native(_) | ty_ptr(_) |
1017-
ty_send_type. | ty_str. | ty_native_fn(_, _) { ast::kind_sendable }
1047+
ty_send_type. | ty_str. | ty_native_fn(_, _) { kind_sendable }
10181048
ty_type. { kind_copyable }
10191049
// FIXME: obj is broken for now, since we aren't asserting
10201050
// anything about its fields.
10211051
ty_obj(_) { kind_copyable }
1022-
ty_fn(f) { ast::proto_kind(f.proto) }
1052+
ty_fn(f) { proto_kind(f.proto) }
10231053
ty_opaque_closure. { kind_noncopyable }
10241054
// Those with refcounts-to-inner raise pinned to shared,
10251055
// lower unique to shared. Therefore just set result to shared.
1026-
ty_box(_) | ty_iface(_, _) { ast::kind_copyable }
1056+
ty_box(_) | ty_iface(_, _) { kind_copyable }
10271057
// Boxes and unique pointers raise pinned to shared.
10281058
ty_vec(tm) | ty_uniq(tm) { type_kind(cx, tm.ty) }
10291059
// Records lower to the lowest of their members.
10301060
ty_rec(flds) {
1031-
let lowest = ast::kind_sendable;
1061+
let lowest = kind_sendable;
10321062
for f in flds { lowest = lower_kind(lowest, type_kind(cx, f.mt.ty)); }
10331063
lowest
10341064
}
10351065
// Tuples lower to the lowest of their members.
10361066
ty_tup(tys) {
1037-
let lowest = ast::kind_sendable;
1067+
let lowest = kind_sendable;
10381068
for ty in tys { lowest = lower_kind(lowest, type_kind(cx, ty)); }
10391069
lowest
10401070
}
10411071
// Tags lower to the lowest of their variants.
10421072
ty_tag(did, tps) {
1043-
let lowest = ast::kind_sendable;
1073+
let lowest = kind_sendable;
10441074
for variant in *tag_variants(cx, did) {
10451075
for aty in variant.args {
10461076
// Perform any type parameter substitutions.
10471077
let arg_ty = substitute_type_params(cx, tps, aty);
10481078
lowest = lower_kind(lowest, type_kind(cx, arg_ty));
1049-
if lowest == ast::kind_noncopyable { break; }
1079+
if lowest == kind_noncopyable { break; }
10501080
}
10511081
}
10521082
lowest
10531083
}
10541084
// Resources are always noncopyable.
1055-
ty_res(did, inner, tps) { ast::kind_noncopyable }
1085+
ty_res(did, inner, tps) { kind_noncopyable }
10561086
ty_param(_, bounds) { param_bounds_to_kind(bounds) }
10571087
ty_constr(t, _) { type_kind(cx, t) }
10581088
};
@@ -1143,7 +1173,7 @@ fn type_allows_implicit_copy(cx: ctxt, ty: t) -> bool {
11431173
}
11441174
_ { false }
11451175
};
1146-
}) && type_kind(cx, ty) != ast::kind_noncopyable;
1176+
}) && type_kind(cx, ty) != kind_noncopyable;
11471177
}
11481178

11491179
fn type_structurally_contains_uniques(cx: ctxt, ty: t) -> bool {

src/comp/syntax/ast.rs

-30
Original file line numberDiff line numberDiff line change
@@ -110,27 +110,6 @@ tag pat_ {
110110

111111
tag mutability { mut; imm; maybe_mut; }
112112

113-
tag kind { kind_sendable; kind_copyable; kind_noncopyable; }
114-
115-
// Using these query functons is preferable to direct comparison or matching
116-
// against the kind constants, as we may modify the kind hierarchy in the
117-
// future.
118-
pure fn kind_can_be_copied(k: kind) -> bool {
119-
ret alt k {
120-
kind_sendable. { true }
121-
kind_copyable. { true }
122-
kind_noncopyable. { false }
123-
};
124-
}
125-
126-
pure fn kind_can_be_sent(k: kind) -> bool {
127-
ret alt k {
128-
kind_sendable. { true }
129-
kind_copyable. { false }
130-
kind_noncopyable. { false }
131-
};
132-
}
133-
134113
tag proto_sugar {
135114
sugar_normal;
136115
sugar_sexy;
@@ -143,15 +122,6 @@ tag proto {
143122
proto_block;
144123
}
145124

146-
fn proto_kind(p: proto) -> kind {
147-
alt p {
148-
ast::proto_block. { ast::kind_noncopyable }
149-
ast::proto_shared(_) { ast::kind_copyable }
150-
ast::proto_send. { ast::kind_sendable }
151-
ast::proto_bare. { ast::kind_sendable }
152-
}
153-
}
154-
155125
tag binop {
156126
add;
157127
sub;

0 commit comments

Comments
 (0)