Skip to content

Commit 7e7a5e3

Browse files
committed
auto merge of #13076 : FlaPer87/rust/remove-freeze, r=alexcrichton
This PR removes the `Freeze` kind and the `NoFreeze` marker completely. Fixes #12577 cc @nikomatsakis r?
2 parents 0e6f90e + a1cb2f5 commit 7e7a5e3

34 files changed

+72
-224
lines changed

src/doc/rust.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ never invoking this behaviour or exposing an API making it possible for it to oc
10191019

10201020
* Data races
10211021
* Dereferencing a null/dangling raw pointer
1022-
* Mutating an immutable value/reference, if it is not marked as non-`Freeze`
1022+
* Mutating an immutable value/reference
10231023
* Reads of [undef](http://llvm.org/docs/LangRef.html#undefined-values) (uninitialized) memory
10241024
* Breaking the [pointer aliasing rules](http://llvm.org/docs/LangRef.html#pointer-aliasing-rules)
10251025
with raw pointers (a subset of the rules used by C)
@@ -3434,10 +3434,6 @@ call to the method `make_string`.
34343434
Types in Rust are categorized into kinds, based on various properties of the components of the type.
34353435
The kinds are:
34363436

3437-
`Freeze`
3438-
: Types of this kind are deeply immutable;
3439-
they contain no mutable memory locations
3440-
directly or indirectly via pointers.
34413437
`Send`
34423438
: Types of this kind can be safely sent between tasks.
34433439
This kind includes scalars, owning pointers, owned closures, and

src/doc/tutorial.md

+5-9
Original file line numberDiff line numberDiff line change
@@ -2099,10 +2099,6 @@ unless they contain managed boxes, managed closures, or references.
20992099
These are types that are safe to be used across several threads with access to
21002100
a `&T` pointer. `MutexArc` is an example of a *sharable* type with internal mutable data.
21012101
2102-
* `Freeze` - Constant (immutable) types.
2103-
These are types that do not contain anything intrinsically mutable.
2104-
Intrinsically mutable values include `Cell` in the standard library.
2105-
21062102
* `'static` - Non-borrowed types.
21072103
These are types that do not contain any data whose lifetime is bound to
21082104
a particular stack frame. These are types that do not contain any
@@ -2152,7 +2148,7 @@ We say that the `Printable` trait _provides_ a `print` method with the
21522148
given signature. This means that we can call `print` on an argument
21532149
of any type that implements the `Printable` trait.
21542150
2155-
Rust's built-in `Send` and `Freeze` types are examples of traits that
2151+
Rust's built-in `Send` and `Share` types are examples of traits that
21562152
don't provide any methods.
21572153
21582154
Traits may be implemented for specific types with [impls]. An impl for
@@ -2444,15 +2440,15 @@ Consequently, the trait objects themselves automatically fulfill their
24442440
respective kind bounds. However, this default behavior can be overridden by
24452441
specifying a list of bounds on the trait type, for example, by writing `~Trait:`
24462442
(which indicates that the contents of the owned trait need not fulfill any
2447-
bounds), or by writing `~Trait:Send+Freeze`, which indicates that in addition
2448-
to fulfilling `Send`, contents must also fulfill `Freeze`, and as a consequence,
2449-
the trait itself fulfills `Freeze`.
2443+
bounds), or by writing `~Trait:Send+Share`, which indicates that in addition
2444+
to fulfilling `Send`, contents must also fulfill `Share`, and as a consequence,
2445+
the trait itself fulfills `Share`.
24502446
24512447
* `~Trait:Send` is equivalent to `~Trait`.
24522448
* `&Trait:` is equivalent to `&Trait`.
24532449
24542450
Builtin kind bounds can also be specified on closure types in the same way (for
2455-
example, by writing `fn:Freeze()`), and the default behaviours are the same as
2451+
example, by writing `fn:Send()`), and the default behaviours are the same as
24562452
for traits of the same storage class.
24572453
24582454
## Trait inheritance

src/libarena/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ use std::mem;
3737
use std::ptr::read;
3838
use std::cmp;
3939
use std::num;
40-
use std::kinds::marker;
4140
use std::rc::Rc;
4241
use std::rt::global_heap;
4342
use std::intrinsics::{TyDesc, get_tydesc};
@@ -90,7 +89,6 @@ pub struct Arena {
9089
priv head: Chunk,
9190
priv pod_head: Chunk,
9291
priv chunks: RefCell<@List<Chunk>>,
93-
priv no_freeze: marker::NoFreeze,
9492
}
9593

9694
impl Arena {
@@ -103,7 +101,6 @@ impl Arena {
103101
head: chunk(initial_size, false),
104102
pod_head: chunk(initial_size, true),
105103
chunks: RefCell::new(@Nil),
106-
no_freeze: marker::NoFreeze,
107104
}
108105
}
109106
}

src/librustc/metadata/tydecode.rs

-3
Original file line numberDiff line numberDiff line change
@@ -584,9 +584,6 @@ fn parse_bounds(st: &mut PState, conv: conv_did) -> ty::ParamBounds {
584584
'S' => {
585585
param_bounds.builtin_bounds.add(ty::BoundSend);
586586
}
587-
'K' => {
588-
param_bounds.builtin_bounds.add(ty::BoundFreeze);
589-
}
590587
'O' => {
591588
param_bounds.builtin_bounds.add(ty::BoundStatic);
592589
}

src/librustc/metadata/tyencode.rs

-1
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,6 @@ fn enc_bounds(w: &mut MemWriter, cx: &ctxt, bs: &ty::ParamBounds) {
392392
for bound in bs.builtin_bounds.iter() {
393393
match bound {
394394
ty::BoundSend => mywrite!(w, "S"),
395-
ty::BoundFreeze => mywrite!(w, "K"),
396395
ty::BoundStatic => mywrite!(w, "O"),
397396
ty::BoundSized => mywrite!(w, "Z"),
398397
ty::BoundPod => mywrite!(w, "P"),

src/librustc/middle/kind.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,14 @@ use syntax::visit::Visitor;
3030
// kind is noncopyable. The noncopyable kind can be extended with any number
3131
// of the following attributes.
3232
//
33-
// send: Things that can be sent on channels or included in spawned closures.
34-
// freeze: Things thare are deeply immutable. They are guaranteed never to
35-
// change, and can be safely shared without copying between tasks.
33+
// Send: Things that can be sent on channels or included in spawned closures. It
34+
// includes scalar types as well as classes and unique types containing only
35+
// sendable types.
3636
// 'static: Things that do not contain references.
3737
//
38-
// Send includes scalar types as well as classes and unique types containing
39-
// only sendable types.
40-
//
41-
// Freeze include scalar types, things without non-const fields, and pointers
42-
// to freezable things.
43-
//
4438
// This pass ensures that type parameters are only instantiated with types
4539
// whose kinds are equal or less general than the way the type parameter was
46-
// annotated (with the `Send` or `Freeze` bound).
40+
// annotated (with the `Send` bound).
4741
//
4842
// It also verifies that noncopyable kinds are not copied. Sendability is not
4943
// applied, since none of our language primitives send. Instead, the sending

src/librustc/middle/lang_items.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// Language items are items that represent concepts intrinsic to the language
1414
// itself. Examples are:
1515
//
16-
// * Traits that specify "kinds"; e.g. "Freeze", "Send".
16+
// * Traits that specify "kinds"; e.g. "Share", "Send".
1717
//
1818
// * Traits that represent operators; e.g. "Add", "Sub", "Index".
1919
//
@@ -82,9 +82,7 @@ impl LanguageItems {
8282
}
8383

8484
pub fn to_builtin_kind(&self, id: ast::DefId) -> Option<ty::BuiltinBound> {
85-
if Some(id) == self.freeze_trait() {
86-
Some(ty::BoundFreeze)
87-
} else if Some(id) == self.send_trait() {
85+
if Some(id) == self.send_trait() {
8886
Some(ty::BoundSend)
8987
} else if Some(id) == self.sized_trait() {
9088
Some(ty::BoundSized)
@@ -210,7 +208,6 @@ pub fn collect_language_items(krate: &ast::Crate,
210208

211209
lets_do_this! {
212210
// Variant name, Name, Method name;
213-
FreezeTraitLangItem, "freeze", freeze_trait;
214211
SendTraitLangItem, "send", send_trait;
215212
SizedTraitLangItem, "sized", sized_trait;
216213
PodTraitLangItem, "pod", pod_trait;
@@ -275,7 +272,6 @@ lets_do_this! {
275272
ContravariantLifetimeItem, "contravariant_lifetime", contravariant_lifetime;
276273
InvariantLifetimeItem, "invariant_lifetime", invariant_lifetime;
277274

278-
NoFreezeItem, "no_freeze_bound", no_freeze_bound;
279275
NoSendItem, "no_send_bound", no_send_bound;
280276
NoPodItem, "no_pod_bound", no_pod_bound;
281277
NoShareItem, "no_share_bound", no_share_bound;

src/librustc/middle/ty.rs

+2-19
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,6 @@ pub type BuiltinBounds = EnumSet<BuiltinBound>;
838838
pub enum BuiltinBound {
839839
BoundStatic,
840840
BoundSend,
841-
BoundFreeze,
842841
BoundSized,
843842
BoundPod,
844843
BoundShare,
@@ -852,7 +851,6 @@ pub fn AllBuiltinBounds() -> BuiltinBounds {
852851
let mut set = EnumSet::empty();
853852
set.add(BoundStatic);
854853
set.add(BoundSend);
855-
set.add(BoundFreeze);
856854
set.add(BoundSized);
857855
set.add(BoundShare);
858856
set
@@ -1892,9 +1890,6 @@ def_type_content_sets!(
18921890
// that it neither reaches nor owns a managed pointer.
18931891
Nonsendable = 0b0000_0111__0000_0100__0000,
18941892

1895-
// Things that prevent values from being considered freezable
1896-
Nonfreezable = 0b0000_1000__0000_0000__0000,
1897-
18981893
// Things that prevent values from being considered 'static
18991894
Nonstatic = 0b0000_0010__0000_0000__0000,
19001895

@@ -1929,7 +1924,6 @@ impl TypeContents {
19291924
pub fn meets_bound(&self, cx: &ctxt, bb: BuiltinBound) -> bool {
19301925
match bb {
19311926
BoundStatic => self.is_static(cx),
1932-
BoundFreeze => self.is_freezable(cx),
19331927
BoundSend => self.is_sendable(cx),
19341928
BoundSized => self.is_sized(cx),
19351929
BoundPod => self.is_pod(cx),
@@ -1965,10 +1959,6 @@ impl TypeContents {
19651959
self.intersects(TC::OwnsOwned)
19661960
}
19671961

1968-
pub fn is_freezable(&self, _: &ctxt) -> bool {
1969-
!self.intersects(TC::Nonfreezable)
1970-
}
1971-
19721962
pub fn is_sized(&self, _: &ctxt) -> bool {
19731963
!self.intersects(TC::Nonsized)
19741964
}
@@ -2073,10 +2063,6 @@ pub fn type_is_sendable(cx: &ctxt, t: ty::t) -> bool {
20732063
type_contents(cx, t).is_sendable(cx)
20742064
}
20752065

2076-
pub fn type_is_freezable(cx: &ctxt, t: ty::t) -> bool {
2077-
type_contents(cx, t).is_freezable(cx)
2078-
}
2079-
20802066
pub fn type_interior_is_unsafe(cx: &ctxt, t: ty::t) -> bool {
20812067
type_contents(cx, t).interior_unsafe()
20822068
}
@@ -2132,7 +2118,7 @@ pub fn type_contents(cx: &ctxt, ty: t) -> TypeContents {
21322118
cache.insert(ty_id, TC::None);
21332119

21342120
let result = match get(ty).sty {
2135-
// Scalar and unique types are sendable, freezable, and durable
2121+
// Scalar and unique types are sendable, and durable
21362122
ty_nil | ty_bot | ty_bool | ty_int(_) | ty_uint(_) | ty_float(_) |
21372123
ty_bare_fn(_) | ty::ty_char => {
21382124
TC::None
@@ -2270,9 +2256,7 @@ pub fn type_contents(cx: &ctxt, ty: t) -> TypeContents {
22702256
did: ast::DefId,
22712257
tc: TypeContents)
22722258
-> TypeContents {
2273-
if Some(did) == cx.lang_items.no_freeze_bound() {
2274-
tc | TC::ReachesMutable
2275-
} else if Some(did) == cx.lang_items.no_send_bound() {
2259+
if Some(did) == cx.lang_items.no_send_bound() {
22762260
tc | TC::ReachesNonsendAnnot
22772261
} else if Some(did) == cx.lang_items.managed_bound() {
22782262
tc | TC::Managed
@@ -2357,7 +2341,6 @@ pub fn type_contents(cx: &ctxt, ty: t) -> TypeContents {
23572341
tc = tc - match bound {
23582342
BoundStatic => TC::Nonstatic,
23592343
BoundSend => TC::Nonsendable,
2360-
BoundFreeze => TC::Nonfreezable,
23612344
BoundSized => TC::Nonsized,
23622345
BoundPod => TC::Nonpod,
23632346
BoundShare => TC::Nonsharable,

src/librustc/middle/typeck/collect.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -976,8 +976,7 @@ pub fn ty_generics(ccx: &CrateCtxt,
976976
* Translate the AST's notion of ty param bounds (which are an
977977
* enum consisting of a newtyped Ty or a region) to ty's
978978
* notion of ty param bounds, which can either be user-defined
979-
* traits, or one of the two built-in traits (formerly known
980-
* as kinds): Freeze and Send.
979+
* traits, or the built-in trait (formerly known as kind): Send.
981980
*/
982981

983982
let mut param_bounds = ty::ParamBounds {

src/librustc/util/ppaux.rs

-2
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,6 @@ impl Repr for ty::ParamBounds {
664664
res.push(match b {
665665
ty::BoundStatic => ~"'static",
666666
ty::BoundSend => ~"Send",
667-
ty::BoundFreeze => ~"Freeze",
668667
ty::BoundSized => ~"Sized",
669668
ty::BoundPod => ~"Pod",
670669
ty::BoundShare => ~"Share",
@@ -952,7 +951,6 @@ impl UserString for ty::BuiltinBound {
952951
match *self {
953952
ty::BoundStatic => ~"'static",
954953
ty::BoundSend => ~"Send",
955-
ty::BoundFreeze => ~"Freeze",
956954
ty::BoundSized => ~"Sized",
957955
ty::BoundPod => ~"Pod",
958956
ty::BoundShare => ~"Share",

src/librustdoc/html/render.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ pub enum Implementor {
116116
///
117117
/// This structure purposefully does not implement `Clone` because it's intended
118118
/// to be a fairly large and expensive structure to clone. Instead this adheres
119-
/// to both `Send` and `Freeze` so it may be stored in a `Arc` instance and
120-
/// shared among the various rendering tasks.
119+
/// to `Send` so it may be stored in a `Arc` instance and shared among the various
120+
/// rendering tasks.
121121
pub struct Cache {
122122
/// Mapping of typaram ids to the name of the type parameter. This is used
123123
/// when pretty-printing a type (so pretty printing doesn't have to

src/libstd/cell.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,15 @@ use ty::Unsafe;
2222
/// A mutable memory location that admits only `Pod` data.
2323
pub struct Cell<T> {
2424
priv value: Unsafe<T>,
25-
priv marker1: marker::NoFreeze,
26-
priv marker2: marker::NoShare,
25+
priv noshare: marker::NoShare,
2726
}
2827

2928
impl<T:Pod> Cell<T> {
3029
/// Creates a new `Cell` containing the given value.
3130
pub fn new(value: T) -> Cell<T> {
3231
Cell {
3332
value: Unsafe::new(value),
34-
marker1: marker::NoFreeze,
35-
marker2: marker::NoShare,
33+
noshare: marker::NoShare,
3634
}
3735
}
3836

@@ -73,9 +71,8 @@ impl<T: fmt::Show> fmt::Show for Cell<T> {
7371
pub struct RefCell<T> {
7472
priv value: Unsafe<T>,
7573
priv borrow: BorrowFlag,
76-
priv marker1: marker::NoFreeze,
77-
priv marker2: marker::NoPod,
78-
priv marker3: marker::NoShare,
74+
priv nopod: marker::NoPod,
75+
priv noshare: marker::NoShare,
7976
}
8077

8178
// Values [1, MAX-1] represent the number of `Ref` active
@@ -88,10 +85,9 @@ impl<T> RefCell<T> {
8885
/// Create a new `RefCell` containing `value`
8986
pub fn new(value: T) -> RefCell<T> {
9087
RefCell {
91-
marker1: marker::NoFreeze,
92-
marker2: marker::NoPod,
93-
marker3: marker::NoShare,
9488
value: Unsafe::new(value),
89+
nopod: marker::NoPod,
90+
noshare: marker::NoShare,
9591
borrow: UNUSED,
9692
}
9793
}

src/libstd/comm/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ pub struct Receiver<T> {
291291
priv inner: Flavor<T>,
292292
priv receives: Cell<uint>,
293293
// can't share in an arc
294-
priv marker: marker::NoFreeze,
294+
priv marker: marker::NoShare,
295295
}
296296

297297
/// An iterator over messages on a receiver, this iterator will block
@@ -307,7 +307,7 @@ pub struct Sender<T> {
307307
priv inner: Flavor<T>,
308308
priv sends: Cell<uint>,
309309
// can't share in an arc
310-
priv marker: marker::NoFreeze,
310+
priv marker: marker::NoShare,
311311
}
312312

313313
/// This enumeration is the list of the possible reasons that try_recv could not
@@ -340,7 +340,7 @@ pub fn channel<T: Send>() -> (Sender<T>, Receiver<T>) {
340340

341341
impl<T: Send> Sender<T> {
342342
fn my_new(inner: Flavor<T>) -> Sender<T> {
343-
Sender { inner: inner, sends: Cell::new(0), marker: marker::NoFreeze }
343+
Sender { inner: inner, sends: Cell::new(0), marker: marker::NoShare }
344344
}
345345

346346
/// Sends a value along this channel to be received by the corresponding
@@ -478,7 +478,7 @@ impl<T: Send> Drop for Sender<T> {
478478

479479
impl<T: Send> Receiver<T> {
480480
fn my_new(inner: Flavor<T>) -> Receiver<T> {
481-
Receiver { inner: inner, receives: Cell::new(0), marker: marker::NoFreeze }
481+
Receiver { inner: inner, receives: Cell::new(0), marker: marker::NoShare }
482482
}
483483

484484
/// Blocks waiting for a value on this receiver

src/libstd/comm/select.rs

-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ pub struct Select {
6666
priv tail: *mut Handle<'static, ()>,
6767
priv next_id: Cell<uint>,
6868
priv marker1: marker::NoSend,
69-
priv marker2: marker::NoFreeze,
7069
}
7170

7271
/// A handle to a receiver which is currently a member of a `Select` set of
@@ -105,7 +104,6 @@ impl Select {
105104
pub fn new() -> Select {
106105
Select {
107106
marker1: marker::NoSend,
108-
marker2: marker::NoFreeze,
109107
head: 0 as *mut Handle<'static, ()>,
110108
tail: 0 as *mut Handle<'static, ()>,
111109
next_id: Cell::new(1),

0 commit comments

Comments
 (0)