提交 b6f92956 编写于 作者: B bors

auto merge of #6317 : brson/rust/durable, r=z0w0

#6312
......@@ -72,7 +72,7 @@ they contained the following prologue:
/* Reexported core operators */
pub use kinds::{Const, Copy, Owned, Durable};
pub use kinds::{Const, Copy, Owned};
pub use ops::{Drop};
pub use ops::{Add, Sub, Mul, Div, Rem, Neg, Not};
pub use ops::{BitAnd, BitOr, BitXor};
......
......@@ -30,8 +30,6 @@
* Const - types that are deeply immutable. Const types are used for
freezable data structures.
* Durable - types that do not contain borrowed pointers.
`Copy` types include both implicitly copyable types that the compiler
will copy automatically and non-implicitly copyable types that require
the `copy` keyword to copy. Types that do not implement `Copy` may
......@@ -55,6 +53,7 @@ pub trait Const {
}
#[lang="durable"]
#[cfg(stage0)]
pub trait Durable {
// Empty.
}
......@@ -13,7 +13,7 @@
/* Reexported core operators */
pub use either::{Either, Left, Right};
pub use kinds::{Const, Copy, Owned, Durable};
pub use kinds::{Const, Copy, Owned};
pub use ops::{Add, Sub, Mul, Div, Rem, Neg, Not};
pub use ops::{BitAnd, BitOr, BitXor};
pub use ops::{Drop};
......
......@@ -49,7 +49,7 @@
* Remove a task-local data value from the table, returning the
* reference that was originally created to insert it.
*/
pub unsafe fn local_data_pop<T:Durable>(
pub unsafe fn local_data_pop<T: 'static>(
key: LocalDataKey<T>) -> Option<@T> {
local_pop(Handle::new(), key)
......@@ -58,7 +58,7 @@ pub unsafe fn local_data_pop<T:Durable>(
* Retrieve a task-local data value. It will also be kept alive in the
* table until explicitly removed.
*/
pub unsafe fn local_data_get<T:Durable>(
pub unsafe fn local_data_get<T: 'static>(
key: LocalDataKey<T>) -> Option<@T> {
local_get(Handle::new(), key)
......@@ -67,7 +67,7 @@ pub unsafe fn local_data_get<T:Durable>(
* Store a value in task-local data. If this key already has a value,
* that value is overwritten (and its destructor is run).
*/
pub unsafe fn local_data_set<T:Durable>(
pub unsafe fn local_data_set<T: 'static>(
key: LocalDataKey<T>, data: @T) {
local_set(Handle::new(), key, data)
......@@ -76,7 +76,7 @@ pub unsafe fn local_data_set<T:Durable>(
* Modify a task-local data value. If the function returns 'None', the
* data is removed (and its reference dropped).
*/
pub unsafe fn local_data_modify<T:Durable>(
pub unsafe fn local_data_modify<T: 'static>(
key: LocalDataKey<T>,
modify_fn: &fn(Option<@T>) -> Option<@T>) {
......@@ -215,3 +215,12 @@ fn int_key(_x: @int) { }
fail!();
}
}
#[test]
fn test_static_pointer() {
unsafe {
fn key(_x: @&'static int) { }
static VALUE: int = 0;
local_data_set(key, @&VALUE);
}
}
\ No newline at end of file
......@@ -44,7 +44,7 @@ pub fn new() -> Handle {
}
pub trait LocalData { }
impl<T:Durable> LocalData for @T { }
impl<T: 'static> LocalData for @T { }
impl Eq for @LocalData {
fn eq(&self, other: &@LocalData) -> bool {
......@@ -131,7 +131,7 @@ unsafe fn get_newsched_local_map(local: *mut LocalStorage) -> TaskLocalMap {
}
}
unsafe fn key_to_key_value<T:Durable>(key: LocalDataKey<T>) -> *libc::c_void {
unsafe fn key_to_key_value<T: 'static>(key: LocalDataKey<T>) -> *libc::c_void {
// Keys are closures, which are (fnptr,envptr) pairs. Use fnptr.
// Use reintepret_cast -- transmute would leak (forget) the closure.
let pair: (*libc::c_void, *libc::c_void) = cast::transmute_copy(&key);
......@@ -139,7 +139,7 @@ unsafe fn key_to_key_value<T:Durable>(key: LocalDataKey<T>) -> *libc::c_void {
}
// If returning Some(..), returns with @T with the map's reference. Careful!
unsafe fn local_data_lookup<T:Durable>(
unsafe fn local_data_lookup<T: 'static>(
map: TaskLocalMap, key: LocalDataKey<T>)
-> Option<(uint, *libc::c_void)> {
......@@ -157,7 +157,7 @@ unsafe fn local_data_lookup<T:Durable>(
}
}
unsafe fn local_get_helper<T:Durable>(
unsafe fn local_get_helper<T: 'static>(
handle: Handle, key: LocalDataKey<T>,
do_pop: bool) -> Option<@T> {
......@@ -179,21 +179,21 @@ unsafe fn local_get_helper<T:Durable>(
}
pub unsafe fn local_pop<T:Durable>(
pub unsafe fn local_pop<T: 'static>(
handle: Handle,
key: LocalDataKey<T>) -> Option<@T> {
local_get_helper(handle, key, true)
}
pub unsafe fn local_get<T:Durable>(
pub unsafe fn local_get<T: 'static>(
handle: Handle,
key: LocalDataKey<T>) -> Option<@T> {
local_get_helper(handle, key, false)
}
pub unsafe fn local_set<T:Durable>(
pub unsafe fn local_set<T: 'static>(
handle: Handle, key: LocalDataKey<T>, data: @T) {
let map = get_local_map(handle);
......@@ -225,7 +225,7 @@ pub unsafe fn local_set<T:Durable>(
}
}
pub unsafe fn local_modify<T:Durable>(
pub unsafe fn local_modify<T: 'static>(
handle: Handle, key: LocalDataKey<T>,
modify_fn: &fn(Option<@T>) -> Option<@T>) {
......
......@@ -34,56 +34,55 @@ pub enum LangItem {
ConstTraitLangItem, // 0
CopyTraitLangItem, // 1
OwnedTraitLangItem, // 2
DurableTraitLangItem, // 3
DropTraitLangItem, // 4
AddTraitLangItem, // 5
SubTraitLangItem, // 6
MulTraitLangItem, // 7
DivTraitLangItem, // 8
RemTraitLangItem, // 9
NegTraitLangItem, // 10
NotTraitLangItem, // 11
BitXorTraitLangItem, // 12
BitAndTraitLangItem, // 13
BitOrTraitLangItem, // 14
ShlTraitLangItem, // 15
ShrTraitLangItem, // 16
IndexTraitLangItem, // 17
EqTraitLangItem, // 18
OrdTraitLangItem, // 19
StrEqFnLangItem, // 20
UniqStrEqFnLangItem, // 21
AnnihilateFnLangItem, // 22
LogTypeFnLangItem, // 23
FailFnLangItem, // 24
FailBoundsCheckFnLangItem, // 25
ExchangeMallocFnLangItem, // 26
ExchangeFreeFnLangItem, // 27
MallocFnLangItem, // 28
FreeFnLangItem, // 29
BorrowAsImmFnLangItem, // 30
BorrowAsMutFnLangItem, // 31
ReturnToMutFnLangItem, // 32
CheckNotBorrowedFnLangItem, // 33
StrDupUniqFnLangItem, // 34
RecordBorrowFnLangItem, // 35
UnrecordBorrowFnLangItem, // 36
StartFnLangItem, // 37
DropTraitLangItem, // 3
AddTraitLangItem, // 4
SubTraitLangItem, // 5
MulTraitLangItem, // 6
DivTraitLangItem, // 7
RemTraitLangItem, // 8
NegTraitLangItem, // 9
NotTraitLangItem, // 10
BitXorTraitLangItem, // 11
BitAndTraitLangItem, // 12
BitOrTraitLangItem, // 13
ShlTraitLangItem, // 14
ShrTraitLangItem, // 15
IndexTraitLangItem, // 16
EqTraitLangItem, // 17
OrdTraitLangItem, // 18
StrEqFnLangItem, // 19
UniqStrEqFnLangItem, // 20
AnnihilateFnLangItem, // 21
LogTypeFnLangItem, // 22
FailFnLangItem, // 23
FailBoundsCheckFnLangItem, // 24
ExchangeMallocFnLangItem, // 25
ExchangeFreeFnLangItem, // 26
MallocFnLangItem, // 27
FreeFnLangItem, // 28
BorrowAsImmFnLangItem, // 29
BorrowAsMutFnLangItem, // 30
ReturnToMutFnLangItem, // 31
CheckNotBorrowedFnLangItem, // 32
StrDupUniqFnLangItem, // 33
RecordBorrowFnLangItem, // 34
UnrecordBorrowFnLangItem, // 35
StartFnLangItem, // 36
}
pub struct LanguageItems {
items: [Option<def_id>, ..38]
items: [Option<def_id>, ..37]
}
pub impl LanguageItems {
pub fn new() -> LanguageItems {
LanguageItems {
items: [ None, ..38 ]
items: [ None, ..37 ]
}
}
......@@ -100,45 +99,44 @@ pub fn item_name(index: uint) -> &'static str {
0 => "const",
1 => "copy",
2 => "owned",
3 => "durable",
4 => "drop",
5 => "add",
6 => "sub",
7 => "mul",
8 => "div",
9 => "rem",
10 => "neg",
11 => "not",
12 => "bitxor",
13 => "bitand",
14 => "bitor",
15 => "shl",
16 => "shr",
17 => "index",
18 => "eq",
19 => "ord",
20 => "str_eq",
21 => "uniq_str_eq",
22 => "annihilate",
23 => "log_type",
24 => "fail_",
25 => "fail_bounds_check",
26 => "exchange_malloc",
27 => "exchange_free",
28 => "malloc",
29 => "free",
30 => "borrow_as_imm",
31 => "borrow_as_mut",
32 => "return_to_mut",
33 => "check_not_borrowed",
34 => "strdup_uniq",
35 => "record_borrow",
36 => "unrecord_borrow",
37 => "start",
3 => "drop",
4 => "add",
5 => "sub",
6 => "mul",
7 => "div",
8 => "rem",
9 => "neg",
10 => "not",
11 => "bitxor",
12 => "bitand",
13 => "bitor",
14 => "shl",
15 => "shr",
16 => "index",
17 => "eq",
18 => "ord",
19 => "str_eq",
20 => "uniq_str_eq",
21 => "annihilate",
22 => "log_type",
23 => "fail_",
24 => "fail_bounds_check",
25 => "exchange_malloc",
26 => "exchange_free",
27 => "malloc",
28 => "free",
29 => "borrow_as_imm",
30 => "borrow_as_mut",
31 => "return_to_mut",
32 => "check_not_borrowed",
33 => "strdup_uniq",
34 => "record_borrow",
35 => "unrecord_borrow",
36 => "start",
_ => "???"
}
......@@ -155,9 +153,6 @@ pub fn copy_trait(&const self) -> def_id {
pub fn owned_trait(&const self) -> def_id {
self.items[OwnedTraitLangItem as uint].get()
}
pub fn durable_trait(&const self) -> def_id {
self.items[DurableTraitLangItem as uint].get()
}
pub fn drop_trait(&const self) -> def_id {
self.items[DropTraitLangItem as uint].get()
......@@ -274,7 +269,6 @@ fn LanguageItemCollector(crate: @crate,
item_refs.insert(@~"const", ConstTraitLangItem as uint);
item_refs.insert(@~"copy", CopyTraitLangItem as uint);
item_refs.insert(@~"owned", OwnedTraitLangItem as uint);
item_refs.insert(@~"durable", DurableTraitLangItem as uint);
item_refs.insert(@~"drop", DropTraitLangItem as uint);
......
......@@ -101,7 +101,7 @@ pub fn get_region_reporting_err(
}
}
pub fn ast_region_to_region<AC:AstConv,RS:region_scope + Copy + Durable>(
pub fn ast_region_to_region<AC:AstConv,RS:region_scope + Copy + 'static>(
self: &AC,
rscope: &RS,
default_span: span,
......@@ -126,7 +126,7 @@ pub fn ast_region_to_region<AC:AstConv,RS:region_scope + Copy + Durable>(
get_region_reporting_err(self.tcx(), span, opt_lifetime, res)
}
fn ast_path_substs<AC:AstConv,RS:region_scope + Copy + Durable>(
fn ast_path_substs<AC:AstConv,RS:region_scope + Copy + 'static>(
self: &AC,
rscope: &RS,
def_id: ast::def_id,
......@@ -180,7 +180,7 @@ fn ast_path_substs<AC:AstConv,RS:region_scope + Copy + Durable>(
substs {self_r:self_r, self_ty:self_ty, tps:tps}
}
pub fn ast_path_to_substs_and_ty<AC:AstConv,RS:region_scope + Copy + Durable>(
pub fn ast_path_to_substs_and_ty<AC:AstConv,RS:region_scope + Copy + 'static>(
self: &AC,
rscope: &RS,
did: ast::def_id,
......@@ -197,7 +197,7 @@ pub fn ast_path_to_substs_and_ty<AC:AstConv,RS:region_scope + Copy + Durable>(
ty_param_substs_and_ty { substs: substs, ty: ty }
}
pub fn ast_path_to_trait_ref<AC:AstConv,RS:region_scope + Copy + Durable>(
pub fn ast_path_to_trait_ref<AC:AstConv,RS:region_scope + Copy + 'static>(
self: &AC,
rscope: &RS,
trait_def_id: ast::def_id,
......@@ -221,7 +221,7 @@ pub fn ast_path_to_trait_ref<AC:AstConv,RS:region_scope + Copy + Durable>(
}
pub fn ast_path_to_ty<AC:AstConv,RS:region_scope + Copy + Durable>(
pub fn ast_path_to_ty<AC:AstConv,RS:region_scope + Copy + 'static>(
self: &AC,
rscope: &RS,
did: ast::def_id,
......@@ -243,10 +243,10 @@ pub fn ast_path_to_ty<AC:AstConv,RS:region_scope + Copy + Durable>(
// Parses the programmer's textual representation of a type into our
// internal notion of a type. `getter` is a function that returns the type
// corresponding to a definition ID:
pub fn ast_ty_to_ty<AC:AstConv, RS:region_scope + Copy + Durable>(
pub fn ast_ty_to_ty<AC:AstConv, RS:region_scope + Copy + 'static>(
self: &AC, rscope: &RS, ast_ty: @ast::Ty) -> ty::t {
fn ast_mt_to_mt<AC:AstConv, RS:region_scope + Copy + Durable>(
fn ast_mt_to_mt<AC:AstConv, RS:region_scope + Copy + 'static>(
self: &AC, rscope: &RS, mt: &ast::mt) -> ty::mt {
ty::mt {ty: ast_ty_to_ty(self, rscope, mt.ty), mutbl: mt.mutbl}
......@@ -255,7 +255,7 @@ fn ast_mt_to_mt<AC:AstConv, RS:region_scope + Copy + Durable>(
// Handle @, ~, and & being able to mean estrs and evecs.
// If a_seq_ty is a str or a vec, make it an estr/evec.
// Also handle first-class trait types.
fn mk_pointer<AC:AstConv,RS:region_scope + Copy + Durable>(
fn mk_pointer<AC:AstConv,RS:region_scope + Copy + 'static>(
self: &AC,
rscope: &RS,
a_seq_ty: &ast::mt,
......@@ -497,7 +497,7 @@ fn check_path_args(tcx: ty::ctxt,
}
pub fn ty_of_arg<AC:AstConv,
RS:region_scope + Copy + Durable>(
RS:region_scope + Copy + 'static>(
self: &AC,
rscope: &RS,
a: ast::arg,
......@@ -549,7 +549,7 @@ struct SelfInfo {
self_transform: ast::self_ty
}
pub fn ty_of_method<AC:AstConv,RS:region_scope + Copy + Durable>(
pub fn ty_of_method<AC:AstConv,RS:region_scope + Copy + 'static>(
self: &AC,
rscope: &RS,
purity: ast::purity,
......@@ -567,7 +567,7 @@ pub fn ty_of_method<AC:AstConv,RS:region_scope + Copy + Durable>(
(a.get(), b)
}
pub fn ty_of_bare_fn<AC:AstConv,RS:region_scope + Copy + Durable>(
pub fn ty_of_bare_fn<AC:AstConv,RS:region_scope + Copy + 'static>(
self: &AC,
rscope: &RS,
purity: ast::purity,
......@@ -580,7 +580,7 @@ pub fn ty_of_bare_fn<AC:AstConv,RS:region_scope + Copy + Durable>(
b
}
fn ty_of_method_or_bare_fn<AC:AstConv,RS:region_scope + Copy + Durable>(
fn ty_of_method_or_bare_fn<AC:AstConv,RS:region_scope + Copy + 'static>(
self: &AC,
rscope: &RS,
purity: ast::purity,
......@@ -616,7 +616,7 @@ fn ty_of_method_or_bare_fn<AC:AstConv,RS:region_scope + Copy + Durable>(
output: output_ty}
});
fn transform_self_ty<AC:AstConv,RS:region_scope + Copy + Durable>(
fn transform_self_ty<AC:AstConv,RS:region_scope + Copy + 'static>(
self: &AC,
rscope: &RS,
self_info: &SelfInfo) -> Option<ty::t>
......@@ -649,7 +649,7 @@ fn transform_self_ty<AC:AstConv,RS:region_scope + Copy + Durable>(
}
}
pub fn ty_of_closure<AC:AstConv,RS:region_scope + Copy + Durable>(
pub fn ty_of_closure<AC:AstConv,RS:region_scope + Copy + 'static>(
self: &AC,
rscope: &RS,
sigil: ast::Sigil,
......
......@@ -116,7 +116,7 @@ pub fn collect_item_types(ccx: @mut CrateCtxt, crate: @ast::crate) {
}
impl CrateCtxt {
fn to_ty<RS:region_scope + Copy + Durable>(
fn to_ty<RS:region_scope + Copy + 'static>(
&self, rs: &RS, ast_ty: @ast::Ty) -> ty::t
{
ast_ty_to_ty(self, rs, ast_ty)
......@@ -1179,7 +1179,7 @@ fn compute_bounds(
* enum consisting of a newtyped Ty or a region) to ty's
* notion of ty param bounds, which can either be user-defined
* traits, or one of the four built-in traits (formerly known
* as kinds): Const, Copy, Durable, and Send.
* as kinds): Const, Copy, and Send.
*/
@ast_bounds.flat_map_to_vec(|b| {
......@@ -1194,8 +1194,6 @@ fn compute_bounds(
~[ty::bound_copy]
} else if trait_ref.def_id == li.const_trait() {
~[ty::bound_const]
} else if trait_ref.def_id == li.durable_trait() {
~[ty::bound_durable]
} else {
// Must be a user-defined trait
~[ty::bound_trait(trait_ref)]
......
......@@ -266,7 +266,7 @@ pub struct binding_rscope {
region_param_names: RegionParamNames,
}
pub fn in_binding_rscope<RS:region_scope + Copy + Durable>(
pub fn in_binding_rscope<RS:region_scope + Copy + 'static>(
self: &RS,
region_param_names: RegionParamNames)
-> binding_rscope {
......
......@@ -148,7 +148,7 @@ fn get<'r, T>(elts: &'r [Option<T>], i: uint) -> &'r T {
mod tests {
use super::*;
use core::cmp::Eq;
use core::kinds::{Durable, Copy};
use core::kinds::Copy;
#[test]
fn test_simple() {
......@@ -232,7 +232,7 @@ fn test_boxes() {
}
#[cfg(test)]
fn test_parameterized<T:Copy + Eq + Durable>(a: T, b: T, c: T, d: T) {
fn test_parameterized<T:Copy + Eq>(a: T, b: T, c: T, d: T) {
let mut deq = Deque::new();
assert!(deq.len() == 0);
deq.add_front(a);
......
......@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
pub fn to_closure<A:Durable + Copy>(x: A) -> @fn() -> A {
pub fn to_closure<A:'static + Copy>(x: A) -> @fn() -> A {
let result: @fn() -> A = || copy x;
result
}
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Testing that we can't store a borrowed pointer it task-local storage
use core::task::local_data::*;
fn key(_x: @&int) { }
fn main() {
unsafe {
local_data_set(key, @&0); //~ ERROR does not fulfill `'static`
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册