@@ -145,8 +145,8 @@ export ty_fn_args;
145
145
export type_constr;
146
146
export type_contains_params;
147
147
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;
150
150
export type_err;
151
151
export type_err_to_str;
152
152
export type_has_dynamic_size;
@@ -216,7 +216,7 @@ type ctxt =
216
216
rcache : creader_cache ,
217
217
short_names_cache : hashmap < t , @str > ,
218
218
needs_drop_cache : hashmap < t , bool > ,
219
- kind_cache : hashmap < t , ast :: kind > ,
219
+ kind_cache : hashmap < t , kind > ,
220
220
ast_ty_to_ty_cache : hashmap < @ast:: ty , option:: t < t > > ,
221
221
tag_var_cache : hashmap < ast:: def_id , @[ variant_info ] > ,
222
222
iface_method_cache : hashmap < def_id , @[ method ] > ,
@@ -308,14 +308,14 @@ tag param_bound {
308
308
bound_iface ( t) ;
309
309
}
310
310
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;
313
313
for bound in * bounds {
314
314
alt bound {
315
315
bound_copy. {
316
- if kind != ast :: kind_sendable { kind = ast :: kind_copyable; }
316
+ if kind != kind_sendable { kind = kind_copyable; }
317
317
}
318
- bound_send. { kind = ast :: kind_sendable; }
318
+ bound_send. { kind = kind_sendable; }
319
319
_ { }
320
320
}
321
321
}
@@ -847,7 +847,7 @@ fn type_is_structural(cx: ctxt, ty: t) -> bool {
847
847
}
848
848
849
849
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) ) ;
851
851
}
852
852
853
853
fn type_is_sequence ( cx : ctxt , ty : t ) -> bool {
@@ -989,6 +989,36 @@ fn type_needs_drop(cx: ctxt, ty: t) -> bool {
989
989
ret result;
990
990
}
991
991
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
+
992
1022
fn kind_lteq ( a : kind , b : kind ) -> bool {
993
1023
alt a {
994
1024
kind_noncopyable. { true }
@@ -1001,58 +1031,58 @@ fn lower_kind(a: kind, b: kind) -> kind {
1001
1031
if ty:: kind_lteq( a, b) { a } else { b }
1002
1032
}
1003
1033
1004
- fn type_kind( cx: ctxt, ty: t) -> ast :: kind {
1034
+ fn type_kind( cx: ctxt, ty: t) -> kind {
1005
1035
alt cx. kind_cache . find ( ty) {
1006
1036
some ( result) { ret result; }
1007
1037
none. { /* fall through */ }
1008
1038
}
1009
1039
1010
1040
// 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) ;
1012
1042
1013
1043
let result = alt struct ( cx, ty) {
1014
1044
// Scalar and unique types are sendable
1015
1045
ty_nil. | ty_bot . | ty_bool . | ty_int ( _) | ty_uint ( _) | ty_float ( _) |
1016
1046
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 }
1018
1048
ty_type. { kind_copyable }
1019
1049
// FIXME: obj is broken for now, since we aren't asserting
1020
1050
// anything about its fields.
1021
1051
ty_obj ( _) { kind_copyable }
1022
- ty_fn ( f) { ast :: proto_kind ( f. proto ) }
1052
+ ty_fn ( f) { proto_kind ( f. proto ) }
1023
1053
ty_opaque_closure. { kind_noncopyable }
1024
1054
// Those with refcounts-to-inner raise pinned to shared,
1025
1055
// 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 }
1027
1057
// Boxes and unique pointers raise pinned to shared.
1028
1058
ty_vec ( tm) | ty_uniq ( tm) { type_kind ( cx, tm. ty ) }
1029
1059
// Records lower to the lowest of their members.
1030
1060
ty_rec ( flds) {
1031
- let lowest = ast :: kind_sendable;
1061
+ let lowest = kind_sendable;
1032
1062
for f in flds { lowest = lower_kind ( lowest, type_kind ( cx, f. mt . ty ) ) ; }
1033
1063
lowest
1034
1064
}
1035
1065
// Tuples lower to the lowest of their members.
1036
1066
ty_tup ( tys) {
1037
- let lowest = ast :: kind_sendable;
1067
+ let lowest = kind_sendable;
1038
1068
for ty in tys { lowest = lower_kind ( lowest, type_kind ( cx, ty) ) ; }
1039
1069
lowest
1040
1070
}
1041
1071
// Tags lower to the lowest of their variants.
1042
1072
ty_tag ( did, tps) {
1043
- let lowest = ast :: kind_sendable;
1073
+ let lowest = kind_sendable;
1044
1074
for variant in * tag_variants ( cx, did) {
1045
1075
for aty in variant. args {
1046
1076
// Perform any type parameter substitutions.
1047
1077
let arg_ty = substitute_type_params ( cx, tps, aty) ;
1048
1078
lowest = lower_kind ( lowest, type_kind ( cx, arg_ty) ) ;
1049
- if lowest == ast :: kind_noncopyable { break ; }
1079
+ if lowest == kind_noncopyable { break ; }
1050
1080
}
1051
1081
}
1052
1082
lowest
1053
1083
}
1054
1084
// Resources are always noncopyable.
1055
- ty_res ( did, inner, tps) { ast :: kind_noncopyable }
1085
+ ty_res ( did, inner, tps) { kind_noncopyable }
1056
1086
ty_param ( _, bounds) { param_bounds_to_kind ( bounds) }
1057
1087
ty_constr ( t, _) { type_kind ( cx, t) }
1058
1088
} ;
@@ -1143,7 +1173,7 @@ fn type_allows_implicit_copy(cx: ctxt, ty: t) -> bool {
1143
1173
}
1144
1174
_ { false }
1145
1175
} ;
1146
- } ) && type_kind ( cx, ty) != ast :: kind_noncopyable;
1176
+ } ) && type_kind ( cx, ty) != kind_noncopyable;
1147
1177
}
1148
1178
1149
1179
fn type_structurally_contains_uniques ( cx : ctxt , ty : t ) -> bool {
0 commit comments