Skip to content

Commit 2c41a82

Browse files
committed
auto merge of #10924 : pcwalton/rust/pod, r=pcwalton
This will be used for the new `Cell`. r? @nikomatsakis
2 parents c2c2c4d + 8657017 commit 2c41a82

File tree

10 files changed

+311
-57
lines changed

10 files changed

+311
-57
lines changed

doc/rust.md

+6
Original file line numberDiff line numberDiff line change
@@ -3329,6 +3329,12 @@ The kinds are:
33293329
This kind includes scalars, owning pointers, owned closures, and
33303330
structural types containing only other owned types.
33313331
All `Send` types are `'static`.
3332+
`Pod`
3333+
: Types of this kind consist of "Plain Old Data"
3334+
which can be copied by simply moving bits.
3335+
All values of this kind can be implicitly copied.
3336+
This kind includes scalars and immutable references,
3337+
as well as structural types containing other `Pod` types.
33323338
`'static`
33333339
: Types of this kind do not contain any borrowed pointers;
33343340
this can be a useful guarantee for code

src/librustc/metadata/tyencode.rs

+1
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ fn enc_bounds(w: @mut MemWriter, cx: @ctxt, bs: &ty::ParamBounds) {
395395
ty::BoundFreeze => mywrite!(w, "K"),
396396
ty::BoundStatic => mywrite!(w, "O"),
397397
ty::BoundSized => mywrite!(w, "Z"),
398+
ty::BoundPod => mywrite!(w, "P"),
398399
}
399400
}
400401

src/librustc/middle/lang_items.rs

+52-48
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
use driver::session::Session;
2424
use metadata::csearch::each_lang_item;
2525
use metadata::cstore::iter_crate_data;
26-
use middle::ty::{BuiltinBound, BoundFreeze, BoundSend, BoundSized};
26+
use middle::ty::{BuiltinBound, BoundFreeze, BoundPod, BoundSend, BoundSized};
2727
use syntax::ast;
2828
use syntax::ast_util::local_def;
2929
use syntax::attr::AttrMetaMethods;
@@ -83,6 +83,8 @@ impl LanguageItems {
8383
Some(BoundSend)
8484
} else if Some(id) == self.sized_trait() {
8585
Some(BoundSized)
86+
} else if Some(id) == self.pod_trait() {
87+
Some(BoundPod)
8688
} else {
8789
None
8890
}
@@ -206,56 +208,58 @@ pub fn collect_language_items(crate: &ast::Crate,
206208
}
207209

208210
lets_do_this! {
209-
There are 41 lang items.
211+
There are 42 lang items.
210212

211213
// ID, Variant name, Name, Method name;
212214
0, FreezeTraitLangItem, "freeze", freeze_trait;
213215
1, SendTraitLangItem, "send", send_trait;
214216
2, SizedTraitLangItem, "sized", sized_trait;
215-
216-
3, DropTraitLangItem, "drop", drop_trait;
217-
218-
4, AddTraitLangItem, "add", add_trait;
219-
5, SubTraitLangItem, "sub", sub_trait;
220-
6, MulTraitLangItem, "mul", mul_trait;
221-
7, DivTraitLangItem, "div", div_trait;
222-
8, RemTraitLangItem, "rem", rem_trait;
223-
9, NegTraitLangItem, "neg", neg_trait;
224-
10, NotTraitLangItem, "not", not_trait;
225-
11, BitXorTraitLangItem, "bitxor", bitxor_trait;
226-
12, BitAndTraitLangItem, "bitand", bitand_trait;
227-
13, BitOrTraitLangItem, "bitor", bitor_trait;
228-
14, ShlTraitLangItem, "shl", shl_trait;
229-
15, ShrTraitLangItem, "shr", shr_trait;
230-
16, IndexTraitLangItem, "index", index_trait;
231-
232-
17, EqTraitLangItem, "eq", eq_trait;
233-
18, OrdTraitLangItem, "ord", ord_trait;
234-
235-
19, StrEqFnLangItem, "str_eq", str_eq_fn;
236-
20, UniqStrEqFnLangItem, "uniq_str_eq", uniq_str_eq_fn;
237-
21, FailFnLangItem, "fail_", fail_fn;
238-
22, FailBoundsCheckFnLangItem, "fail_bounds_check", fail_bounds_check_fn;
239-
23, ExchangeMallocFnLangItem, "exchange_malloc", exchange_malloc_fn;
240-
24, ClosureExchangeMallocFnLangItem, "closure_exchange_malloc", closure_exchange_malloc_fn;
241-
25, ExchangeFreeFnLangItem, "exchange_free", exchange_free_fn;
242-
26, MallocFnLangItem, "malloc", malloc_fn;
243-
27, FreeFnLangItem, "free", free_fn;
244-
28, BorrowAsImmFnLangItem, "borrow_as_imm", borrow_as_imm_fn;
245-
29, BorrowAsMutFnLangItem, "borrow_as_mut", borrow_as_mut_fn;
246-
30, ReturnToMutFnLangItem, "return_to_mut", return_to_mut_fn;
247-
31, CheckNotBorrowedFnLangItem, "check_not_borrowed", check_not_borrowed_fn;
248-
32, StrDupUniqFnLangItem, "strdup_uniq", strdup_uniq_fn;
249-
33, RecordBorrowFnLangItem, "record_borrow", record_borrow_fn;
250-
34, UnrecordBorrowFnLangItem, "unrecord_borrow", unrecord_borrow_fn;
251-
252-
35, StartFnLangItem, "start", start_fn;
253-
254-
36, TyDescStructLangItem, "ty_desc", ty_desc;
255-
37, TyVisitorTraitLangItem, "ty_visitor", ty_visitor;
256-
38, OpaqueStructLangItem, "opaque", opaque;
257-
258-
39, EventLoopFactoryLangItem, "event_loop_factory", event_loop_factory;
259-
260-
40, TypeIdLangItem, "type_id", type_id;
217+
3, PodTraitLangItem, "pod", pod_trait;
218+
219+
4, DropTraitLangItem, "drop", drop_trait;
220+
221+
5, AddTraitLangItem, "add", add_trait;
222+
6, SubTraitLangItem, "sub", sub_trait;
223+
7, MulTraitLangItem, "mul", mul_trait;
224+
8, DivTraitLangItem, "div", div_trait;
225+
9, RemTraitLangItem, "rem", rem_trait;
226+
10, NegTraitLangItem, "neg", neg_trait;
227+
11, NotTraitLangItem, "not", not_trait;
228+
12, BitXorTraitLangItem, "bitxor", bitxor_trait;
229+
13, BitAndTraitLangItem, "bitand", bitand_trait;
230+
14, BitOrTraitLangItem, "bitor", bitor_trait;
231+
15, ShlTraitLangItem, "shl", shl_trait;
232+
16, ShrTraitLangItem, "shr", shr_trait;
233+
17, IndexTraitLangItem, "index", index_trait;
234+
235+
18, EqTraitLangItem, "eq", eq_trait;
236+
19, OrdTraitLangItem, "ord", ord_trait;
237+
238+
20, StrEqFnLangItem, "str_eq", str_eq_fn;
239+
21, UniqStrEqFnLangItem, "uniq_str_eq", uniq_str_eq_fn;
240+
22, FailFnLangItem, "fail_", fail_fn;
241+
23, FailBoundsCheckFnLangItem, "fail_bounds_check", fail_bounds_check_fn;
242+
24, ExchangeMallocFnLangItem, "exchange_malloc", exchange_malloc_fn;
243+
25, ClosureExchangeMallocFnLangItem, "closure_exchange_malloc", closure_exchange_malloc_fn;
244+
26, ExchangeFreeFnLangItem, "exchange_free", exchange_free_fn;
245+
27, MallocFnLangItem, "malloc", malloc_fn;
246+
28, FreeFnLangItem, "free", free_fn;
247+
29, BorrowAsImmFnLangItem, "borrow_as_imm", borrow_as_imm_fn;
248+
30, BorrowAsMutFnLangItem, "borrow_as_mut", borrow_as_mut_fn;
249+
31, ReturnToMutFnLangItem, "return_to_mut", return_to_mut_fn;
250+
32, CheckNotBorrowedFnLangItem, "check_not_borrowed", check_not_borrowed_fn;
251+
33, StrDupUniqFnLangItem, "strdup_uniq", strdup_uniq_fn;
252+
34, RecordBorrowFnLangItem, "record_borrow", record_borrow_fn;
253+
35, UnrecordBorrowFnLangItem, "unrecord_borrow", unrecord_borrow_fn;
254+
255+
36, StartFnLangItem, "start", start_fn;
256+
257+
37, TyDescStructLangItem, "ty_desc", ty_desc;
258+
38, TyVisitorTraitLangItem, "ty_visitor", ty_visitor;
259+
39, OpaqueStructLangItem, "opaque", opaque;
260+
261+
40, EventLoopFactoryLangItem, "event_loop_factory", event_loop_factory;
262+
263+
41, TypeIdLangItem, "type_id", type_id;
261264
}
265+

src/librustc/middle/ty.rs

+36-9
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,7 @@ pub enum BuiltinBound {
737737
BoundSend,
738738
BoundFreeze,
739739
BoundSized,
740+
BoundPod,
740741
}
741742

742743
pub fn EmptyBuiltinBounds() -> BuiltinBounds {
@@ -1805,6 +1806,9 @@ def_type_content_sets!(
18051806
// Things that prevent values from being considered sized
18061807
Nonsized = 0b0000__00000000__0001,
18071808

1809+
// Things that make values considered not POD (same as `Moves`)
1810+
Nonpod = 0b0000__00001111__0000,
1811+
18081812
// Bits to set when a managed value is encountered
18091813
//
18101814
// [1] Do not set the bits TC::OwnsManaged or
@@ -1828,6 +1832,7 @@ impl TypeContents {
18281832
BoundFreeze => self.is_freezable(cx),
18291833
BoundSend => self.is_sendable(cx),
18301834
BoundSized => self.is_sized(cx),
1835+
BoundPod => self.is_pod(cx),
18311836
}
18321837
}
18331838

@@ -1859,6 +1864,10 @@ impl TypeContents {
18591864
!self.intersects(TC::Nonsized)
18601865
}
18611866

1867+
pub fn is_pod(&self, _: ctxt) -> bool {
1868+
!self.intersects(TC::Nonpod)
1869+
}
1870+
18621871
pub fn moves_by_default(&self, _: ctxt) -> bool {
18631872
self.intersects(TC::Moves)
18641873
}
@@ -1876,15 +1885,32 @@ impl TypeContents {
18761885
*self & (TC::OwnsAll | TC::ReachesAll))
18771886
}
18781887

1879-
pub fn other_pointer(&self, bits: TypeContents) -> TypeContents {
1888+
pub fn reference(&self, bits: TypeContents) -> TypeContents {
18801889
/*!
18811890
* Includes only those bits that still apply
1882-
* when indirected through a non-owning pointer (`&`, `@`)
1891+
* when indirected through a reference (`&`)
18831892
*/
18841893
bits | (
18851894
*self & TC::ReachesAll)
18861895
}
18871896

1897+
pub fn managed_pointer(&self) -> TypeContents {
1898+
/*!
1899+
* Includes only those bits that still apply
1900+
* when indirected through a managed pointer (`@`)
1901+
*/
1902+
TC::Managed | (
1903+
*self & TC::ReachesAll)
1904+
}
1905+
1906+
pub fn unsafe_pointer(&self) -> TypeContents {
1907+
/*!
1908+
* Includes only those bits that still apply
1909+
* when indirected through an unsafe pointer (`*`)
1910+
*/
1911+
*self & TC::ReachesAll
1912+
}
1913+
18881914
pub fn union<T>(v: &[T], f: |&T| -> TypeContents) -> TypeContents {
18891915
v.iter().fold(TC::None, |tc, t| tc | f(t))
18901916
}
@@ -1994,19 +2020,19 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
19942020
}
19952021

19962022
ty_box(mt) => {
1997-
tc_mt(cx, mt, cache).other_pointer(TC::Managed)
2023+
tc_mt(cx, mt, cache).managed_pointer()
19982024
}
19992025

20002026
ty_trait(_, _, store, mutbl, bounds) => {
20012027
object_contents(cx, store, mutbl, bounds)
20022028
}
20032029

20042030
ty_ptr(ref mt) => {
2005-
tc_ty(cx, mt.ty, cache).other_pointer(TC::None)
2031+
tc_ty(cx, mt.ty, cache).unsafe_pointer()
20062032
}
20072033

20082034
ty_rptr(r, ref mt) => {
2009-
tc_ty(cx, mt.ty, cache).other_pointer(
2035+
tc_ty(cx, mt.ty, cache).reference(
20102036
borrowed_contents(r, mt.mutbl))
20112037
}
20122038

@@ -2019,11 +2045,11 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
20192045
}
20202046

20212047
ty_evec(mt, vstore_box) => {
2022-
tc_mt(cx, mt, cache).other_pointer(TC::Managed)
2048+
tc_mt(cx, mt, cache).managed_pointer()
20232049
}
20242050

20252051
ty_evec(ref mt, vstore_slice(r)) => {
2026-
tc_ty(cx, mt.ty, cache).other_pointer(
2052+
tc_ty(cx, mt.ty, cache).reference(
20272053
borrowed_contents(r, mt.mutbl))
20282054
}
20292055

@@ -2193,10 +2219,10 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
21932219
contents.owned_pointer()
21942220
}
21952221
BoxTraitStore => {
2196-
contents.other_pointer(TC::Managed)
2222+
contents.managed_pointer()
21972223
}
21982224
RegionTraitStore(r) => {
2199-
contents.other_pointer(borrowed_contents(r, mutbl))
2225+
contents.reference(borrowed_contents(r, mutbl))
22002226
}
22012227
}
22022228
}
@@ -2213,6 +2239,7 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
22132239
BoundSend => TC::Nonsendable,
22142240
BoundFreeze => TC::Nonfreezable,
22152241
BoundSized => TC::Nonsized,
2242+
BoundPod => TC::Nonpod,
22162243
};
22172244
});
22182245
return tc;

src/librustc/util/ppaux.rs

+2
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,7 @@ impl Repr for ty::ParamBounds {
639639
ty::BoundSend => ~"Send",
640640
ty::BoundFreeze => ~"Freeze",
641641
ty::BoundSized => ~"Sized",
642+
ty::BoundPod => ~"Pod",
642643
});
643644
}
644645
for t in self.trait_bounds.iter() {
@@ -926,6 +927,7 @@ impl UserString for ty::BuiltinBound {
926927
ty::BoundSend => ~"Send",
927928
ty::BoundFreeze => ~"Freeze",
928929
ty::BoundSized => ~"Sized",
930+
ty::BoundPod => ~"Pod",
929931
}
930932
}
931933
}

0 commit comments

Comments
 (0)