Skip to content

Commit d7d951a

Browse files
committed
---
yaml --- r: 12928 b: refs/heads/master c: f213c1f h: refs/heads/master v: v3
1 parent bc1d0bb commit d7d951a

File tree

3 files changed

+59
-57
lines changed

3 files changed

+59
-57
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 8d7f3bd1ca622e6ddc03f4592eb8a451fbf850ab
2+
refs/heads/master: f213c1f3a817ba2c0a43c0b27215146b7a279f65
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/rustc/middle/kind.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import syntax::{visit, ast_util};
22
import syntax::ast::*;
33
import syntax::codemap::span;
4-
import ty::{kind, kind_copyable, kind_sendable, kind_noncopyable};
4+
import ty::{kind, kind_sendable, kind_copyable, kind_noncopyable };
55
import driver::session::session;
66
import std::map::hashmap;
77
import util::ppaux::{ty_to_str, tys_to_str};
@@ -24,11 +24,10 @@ import freevars::freevar_entry;
2424
// types.
2525

2626
fn kind_to_str(k: kind) -> str {
27-
alt k {
28-
kind_sendable { "sendable" }
29-
kind_copyable { "copyable" }
30-
kind_noncopyable { "noncopyable" }
31-
}
27+
if k == kind_sendable() { "sendable" }
28+
else if k == kind_copyable() { "copyable" }
29+
else if k == kind_noncopyable() { "noncopyable" }
30+
else { fail "unknown kind" }
3231
}
3332

3433
type rval_map = std::map::hashmap<node_id, ()>;

trunk/src/rustc/middle/ty.rs

Lines changed: 53 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -421,13 +421,13 @@ impl of vid for region_vid {
421421
}
422422

423423
fn param_bounds_to_kind(bounds: param_bounds) -> kind {
424-
let mut kind = kind_noncopyable;
424+
let mut kind = kind_noncopyable();
425425
for vec::each(*bounds) {|bound|
426426
alt bound {
427427
bound_copy {
428-
if kind != kind_sendable { kind = kind_copyable; }
428+
if kind != kind_sendable() { kind = kind_copyable(); }
429429
}
430-
bound_send { kind = kind_sendable; }
430+
bound_send { kind = kind_sendable(); }
431431
_ {}
432432
}
433433
}
@@ -1260,43 +1260,46 @@ fn type_needs_unwind_cleanup_(cx: ctxt, ty: t,
12601260
ret needs_unwind_cleanup;
12611261
}
12621262

1263-
enum kind { kind_sendable, kind_copyable, kind_noncopyable, }
1263+
enum kind { kind_(u32) }
1264+
1265+
const KIND_MASK_COPY : u32 = 0b00000000000000000000000000000001u32;
1266+
const KIND_MASK_SEND : u32 = 0b00000000000000000000000000000010u32;
1267+
1268+
fn kind_noncopyable() -> kind {
1269+
kind_(0u32)
1270+
}
1271+
1272+
fn kind_copyable() -> kind {
1273+
kind_(KIND_MASK_COPY)
1274+
}
1275+
1276+
fn kind_sendable() -> kind {
1277+
kind_(KIND_MASK_COPY | KIND_MASK_SEND)
1278+
}
12641279

12651280
// Using these query functons is preferable to direct comparison or matching
12661281
// against the kind constants, as we may modify the kind hierarchy in the
12671282
// future.
12681283
pure fn kind_can_be_copied(k: kind) -> bool {
1269-
ret alt k {
1270-
kind_sendable { true }
1271-
kind_copyable { true }
1272-
kind_noncopyable { false }
1273-
};
1284+
*k & KIND_MASK_COPY != 0u32
12741285
}
12751286

12761287
pure fn kind_can_be_sent(k: kind) -> bool {
1277-
ret alt k {
1278-
kind_sendable { true }
1279-
kind_copyable { false }
1280-
kind_noncopyable { false }
1281-
};
1288+
*k & KIND_MASK_SEND != 0u32
12821289
}
12831290

12841291
fn proto_kind(p: proto) -> kind {
12851292
alt p {
1286-
ast::proto_any { kind_noncopyable }
1287-
ast::proto_block { kind_noncopyable }
1288-
ast::proto_box { kind_copyable }
1289-
ast::proto_uniq { kind_sendable }
1290-
ast::proto_bare { kind_sendable }
1293+
ast::proto_any { kind_noncopyable() }
1294+
ast::proto_block { kind_noncopyable() }
1295+
ast::proto_box { kind_copyable() }
1296+
ast::proto_uniq { kind_sendable() }
1297+
ast::proto_bare { kind_sendable() }
12911298
}
12921299
}
12931300

12941301
fn kind_lteq(a: kind, b: kind) -> bool {
1295-
alt a {
1296-
kind_noncopyable { true }
1297-
kind_copyable { b != kind_noncopyable }
1298-
kind_sendable { b == kind_sendable }
1299-
}
1302+
*a & *b == *a
13001303
}
13011304

13021305
fn lower_kind(a: kind, b: kind) -> kind {
@@ -1306,12 +1309,12 @@ fn lower_kind(a: kind, b: kind) -> kind {
13061309
#[test]
13071310
fn test_kinds() {
13081311
// The kind "lattice" is nocopy <= copy <= send
1309-
assert kind_lteq(kind_sendable, kind_sendable);
1310-
assert kind_lteq(kind_copyable, kind_sendable);
1311-
assert kind_lteq(kind_copyable, kind_copyable);
1312-
assert kind_lteq(kind_noncopyable, kind_sendable);
1313-
assert kind_lteq(kind_noncopyable, kind_copyable);
1314-
assert kind_lteq(kind_noncopyable, kind_noncopyable);
1312+
assert kind_lteq(kind_sendable(), kind_sendable());
1313+
assert kind_lteq(kind_copyable(), kind_sendable());
1314+
assert kind_lteq(kind_copyable(), kind_copyable());
1315+
assert kind_lteq(kind_noncopyable(), kind_sendable());
1316+
assert kind_lteq(kind_noncopyable(), kind_copyable());
1317+
assert kind_lteq(kind_noncopyable(), kind_noncopyable());
13151318
}
13161319

13171320
fn type_kind(cx: ctxt, ty: t) -> kind {
@@ -1321,44 +1324,44 @@ fn type_kind(cx: ctxt, ty: t) -> kind {
13211324
}
13221325

13231326
// Insert a default in case we loop back on self recursively.
1324-
cx.kind_cache.insert(ty, kind_sendable);
1327+
cx.kind_cache.insert(ty, kind_sendable());
13251328

13261329
let result = alt get(ty).struct {
13271330
// Scalar and unique types are sendable
13281331
ty_nil | ty_bot | ty_bool | ty_int(_) | ty_uint(_) | ty_float(_) |
1329-
ty_ptr(_) | ty_str { kind_sendable }
1330-
ty_type { kind_copyable }
1332+
ty_ptr(_) | ty_str { kind_sendable() }
1333+
ty_type { kind_copyable() }
13311334
ty_fn(f) { proto_kind(f.proto) }
13321335

13331336
// Closures have kind determined by capture mode
1334-
ty_opaque_closure_ptr(ck_block) { kind_noncopyable }
1335-
ty_opaque_closure_ptr(ck_box) { kind_copyable }
1336-
ty_opaque_closure_ptr(ck_uniq) { kind_sendable }
1337+
ty_opaque_closure_ptr(ck_block) { kind_noncopyable() }
1338+
ty_opaque_closure_ptr(ck_box) { kind_copyable() }
1339+
ty_opaque_closure_ptr(ck_uniq) { kind_sendable() }
13371340

13381341
// Those with refcounts raise noncopyable to copyable,
13391342
// lower sendable to copyable. Therefore just set result to copyable.
1340-
ty_box(_) | ty_iface(_, _) | ty_opaque_box { kind_copyable }
1341-
ty_rptr(_, _) { kind_copyable }
1343+
ty_box(_) | ty_iface(_, _) | ty_opaque_box { kind_copyable() }
1344+
ty_rptr(_, _) { kind_copyable() }
13421345

13431346
// Unique boxes and vecs have the kind of their contained type.
13441347
ty_vec(tm) | ty_uniq(tm) { type_kind(cx, tm.ty) }
13451348

13461349
// Slice and refcounted evecs are copyable; uniques and interiors
13471350
// depend on the their contained type.
13481351
ty_evec(_, vstore_box) |
1349-
ty_evec(_, vstore_slice(_)) { kind_copyable }
1352+
ty_evec(_, vstore_slice(_)) { kind_copyable() }
13501353
ty_evec(tm, vstore_uniq) |
13511354
ty_evec(tm, vstore_fixed(_)) { type_kind(cx, tm.ty) }
13521355

13531356
// All estrs are copyable; uniques and interiors are sendable.
13541357
ty_estr(vstore_box) |
1355-
ty_estr(vstore_slice(_)) { kind_copyable }
1358+
ty_estr(vstore_slice(_)) { kind_copyable() }
13561359
ty_estr(vstore_uniq) |
1357-
ty_estr(vstore_fixed(_)) { kind_sendable }
1360+
ty_estr(vstore_fixed(_)) { kind_sendable() }
13581361

13591362
// Records lower to the lowest of their members.
13601363
ty_rec(flds) {
1361-
let mut lowest = kind_sendable;
1364+
let mut lowest = kind_sendable();
13621365
for flds.each {|f|
13631366
lowest = lower_kind(lowest, type_kind(cx, f.mt.ty));
13641367
}
@@ -1368,7 +1371,7 @@ fn type_kind(cx: ctxt, ty: t) -> kind {
13681371
// sendable, but I'm just treating them like records (#1726)
13691372
ty_class(did, substs) {
13701373
// also factor out this code, copied from the records case
1371-
let mut lowest = kind_sendable;
1374+
let mut lowest = kind_sendable();
13721375
let flds = class_items_as_fields(cx, did, substs);
13731376
for flds.each {|f|
13741377
lowest = lower_kind(lowest, type_kind(cx, f.mt.ty));
@@ -1377,34 +1380,34 @@ fn type_kind(cx: ctxt, ty: t) -> kind {
13771380
}
13781381
// Tuples lower to the lowest of their members.
13791382
ty_tup(tys) {
1380-
let mut lowest = kind_sendable;
1383+
let mut lowest = kind_sendable();
13811384
for tys.each {|ty| lowest = lower_kind(lowest, type_kind(cx, ty)); }
13821385
lowest
13831386
}
13841387
// Enums lower to the lowest of their variants.
13851388
ty_enum(did, substs) {
1386-
let mut lowest = kind_sendable;
1389+
let mut lowest = kind_sendable();
13871390
let variants = enum_variants(cx, did);
13881391
if vec::len(*variants) == 0u {
1389-
lowest = kind_noncopyable;
1392+
lowest = kind_noncopyable();
13901393
} else {
13911394
for vec::each(*variants) {|variant|
13921395
for variant.args.each {|aty|
13931396
// Perform any type parameter substitutions.
13941397
let arg_ty = subst(cx, substs, aty);
13951398
lowest = lower_kind(lowest, type_kind(cx, arg_ty));
1396-
if lowest == kind_noncopyable { break; }
1399+
if lowest == kind_noncopyable() { break; }
13971400
}
13981401
}
13991402
}
14001403
lowest
14011404
}
1402-
ty_res(did, inner, tps) { kind_noncopyable }
1405+
ty_res(did, inner, tps) { kind_noncopyable() }
14031406
ty_param(_, did) {
14041407
param_bounds_to_kind(cx.ty_param_bounds.get(did.node))
14051408
}
14061409
ty_constr(t, _) { type_kind(cx, t) }
1407-
ty_self { kind_noncopyable }
1410+
ty_self { kind_noncopyable() }
14081411

14091412
ty_var(_) { cx.sess.bug("Asked to compute kind of a type variable"); }
14101413
};
@@ -1605,7 +1608,7 @@ fn type_allows_implicit_copy(cx: ctxt, ty: t) -> bool {
16051608
}
16061609
_ { false }
16071610
}
1608-
}) && type_kind(cx, ty) != kind_noncopyable;
1611+
}) && type_kind(cx, ty) != kind_noncopyable();
16091612
}
16101613

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

0 commit comments

Comments
 (0)