@@ -421,13 +421,13 @@ impl of vid for region_vid {
421
421
}
422
422
423
423
fn param_bounds_to_kind ( bounds : param_bounds ) -> kind {
424
- let mut kind = kind_noncopyable;
424
+ let mut kind = kind_noncopyable ( ) ;
425
425
for vec:: each( * bounds) { |bound|
426
426
alt bound {
427
427
bound_copy {
428
- if kind != kind_sendable { kind = kind_copyable; }
428
+ if kind != kind_sendable( ) { kind = kind_copyable( ) ; }
429
429
}
430
- bound_send { kind = kind_sendable; }
430
+ bound_send { kind = kind_sendable ( ) ; }
431
431
_ { }
432
432
}
433
433
}
@@ -1260,43 +1260,46 @@ fn type_needs_unwind_cleanup_(cx: ctxt, ty: t,
1260
1260
ret needs_unwind_cleanup;
1261
1261
}
1262
1262
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
+ }
1264
1279
1265
1280
// Using these query functons is preferable to direct comparison or matching
1266
1281
// against the kind constants, as we may modify the kind hierarchy in the
1267
1282
// future.
1268
1283
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
1274
1285
}
1275
1286
1276
1287
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
1282
1289
}
1283
1290
1284
1291
fn proto_kind( p: proto) -> kind {
1285
1292
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( ) }
1291
1298
}
1292
1299
}
1293
1300
1294
1301
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
1300
1303
}
1301
1304
1302
1305
fn lower_kind( a: kind, b: kind) -> kind {
@@ -1306,12 +1309,12 @@ fn lower_kind(a: kind, b: kind) -> kind {
1306
1309
#[ test]
1307
1310
fn test_kinds( ) {
1308
1311
// 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( ) ) ;
1315
1318
}
1316
1319
1317
1320
fn type_kind( cx: ctxt, ty: t) -> kind {
@@ -1321,44 +1324,44 @@ fn type_kind(cx: ctxt, ty: t) -> kind {
1321
1324
}
1322
1325
1323
1326
// 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( ) ) ;
1325
1328
1326
1329
let result = alt get( ty) . struct {
1327
1330
// Scalar and unique types are sendable
1328
1331
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( ) }
1331
1334
ty_fn( f) { proto_kind( f. proto) }
1332
1335
1333
1336
// 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( ) }
1337
1340
1338
1341
// Those with refcounts raise noncopyable to copyable,
1339
1342
// 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( ) }
1342
1345
1343
1346
// Unique boxes and vecs have the kind of their contained type.
1344
1347
ty_vec( tm) | ty_uniq( tm) { type_kind( cx, tm. ty) }
1345
1348
1346
1349
// Slice and refcounted evecs are copyable; uniques and interiors
1347
1350
// depend on the their contained type.
1348
1351
ty_evec( _, vstore_box) |
1349
- ty_evec( _, vstore_slice( _) ) { kind_copyable }
1352
+ ty_evec( _, vstore_slice( _) ) { kind_copyable( ) }
1350
1353
ty_evec( tm, vstore_uniq) |
1351
1354
ty_evec( tm, vstore_fixed( _) ) { type_kind( cx, tm. ty) }
1352
1355
1353
1356
// All estrs are copyable; uniques and interiors are sendable.
1354
1357
ty_estr( vstore_box) |
1355
- ty_estr( vstore_slice( _) ) { kind_copyable }
1358
+ ty_estr( vstore_slice( _) ) { kind_copyable( ) }
1356
1359
ty_estr( vstore_uniq) |
1357
- ty_estr( vstore_fixed( _) ) { kind_sendable }
1360
+ ty_estr( vstore_fixed( _) ) { kind_sendable( ) }
1358
1361
1359
1362
// Records lower to the lowest of their members.
1360
1363
ty_rec( flds) {
1361
- let mut lowest = kind_sendable;
1364
+ let mut lowest = kind_sendable( ) ;
1362
1365
for flds. each { |f|
1363
1366
lowest = lower_kind( lowest, type_kind( cx, f. mt. ty) ) ;
1364
1367
}
@@ -1368,7 +1371,7 @@ fn type_kind(cx: ctxt, ty: t) -> kind {
1368
1371
// sendable, but I'm just treating them like records (#1726)
1369
1372
ty_class( did, substs) {
1370
1373
// also factor out this code, copied from the records case
1371
- let mut lowest = kind_sendable;
1374
+ let mut lowest = kind_sendable( ) ;
1372
1375
let flds = class_items_as_fields( cx, did, substs) ;
1373
1376
for flds. each { |f|
1374
1377
lowest = lower_kind( lowest, type_kind( cx, f. mt. ty) ) ;
@@ -1377,34 +1380,34 @@ fn type_kind(cx: ctxt, ty: t) -> kind {
1377
1380
}
1378
1381
// Tuples lower to the lowest of their members.
1379
1382
ty_tup( tys) {
1380
- let mut lowest = kind_sendable;
1383
+ let mut lowest = kind_sendable( ) ;
1381
1384
for tys. each { |ty| lowest = lower_kind( lowest, type_kind( cx, ty) ) ; }
1382
1385
lowest
1383
1386
}
1384
1387
// Enums lower to the lowest of their variants.
1385
1388
ty_enum( did, substs) {
1386
- let mut lowest = kind_sendable;
1389
+ let mut lowest = kind_sendable( ) ;
1387
1390
let variants = enum_variants( cx, did) ;
1388
1391
if vec:: len( * variants) == 0 u {
1389
- lowest = kind_noncopyable;
1392
+ lowest = kind_noncopyable( ) ;
1390
1393
} else {
1391
1394
for vec:: each( * variants) { |variant|
1392
1395
for variant. args. each { |aty|
1393
1396
// Perform any type parameter substitutions.
1394
1397
let arg_ty = subst( cx, substs, aty) ;
1395
1398
lowest = lower_kind( lowest, type_kind( cx, arg_ty) ) ;
1396
- if lowest == kind_noncopyable { break ; }
1399
+ if lowest == kind_noncopyable( ) { break ; }
1397
1400
}
1398
1401
}
1399
1402
}
1400
1403
lowest
1401
1404
}
1402
- ty_res( did, inner, tps) { kind_noncopyable }
1405
+ ty_res( did, inner, tps) { kind_noncopyable( ) }
1403
1406
ty_param( _, did) {
1404
1407
param_bounds_to_kind( cx. ty_param_bounds. get( did. node) )
1405
1408
}
1406
1409
ty_constr( t, _) { type_kind( cx, t) }
1407
- ty_self { kind_noncopyable }
1410
+ ty_self { kind_noncopyable( ) }
1408
1411
1409
1412
ty_var( _) { cx. sess. bug( "Asked to compute kind of a type variable") ; }
1410
1413
} ;
@@ -1605,7 +1608,7 @@ fn type_allows_implicit_copy(cx: ctxt, ty: t) -> bool {
1605
1608
}
1606
1609
_ { false }
1607
1610
}
1608
- } ) && type_kind( cx, ty) != kind_noncopyable;
1611
+ } ) && type_kind( cx, ty) != kind_noncopyable( ) ;
1609
1612
}
1610
1613
1611
1614
fn type_structurally_contains_uniques( cx: ctxt, ty: t) -> bool {
0 commit comments