Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
08520a16
R
Rust
项目概览
int
/
Rust
12 个月 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
08520a16
编写于
6月 04, 2012
作者:
N
Niko Matsakis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
move borrowck to dvec, insert a few minor copies
上级
d9db4f02
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
22 addition
and
18 deletion
+22
-18
src/rustc/middle/borrowck.rs
src/rustc/middle/borrowck.rs
+2
-1
src/rustc/middle/borrowck/check_loans.rs
src/rustc/middle/borrowck/check_loans.rs
+10
-8
src/rustc/middle/borrowck/gather_loans.rs
src/rustc/middle/borrowck/gather_loans.rs
+4
-3
src/rustc/middle/borrowck/loan.rs
src/rustc/middle/borrowck/loan.rs
+6
-6
未找到文件。
src/rustc/middle/borrowck.rs
浏览文件 @
08520a16
...
@@ -164,6 +164,7 @@
...
@@ -164,6 +164,7 @@
import
ast_util
::
op_expr_callee_id
;
import
ast_util
::
op_expr_callee_id
;
import
ty
::
to_str
;
import
ty
::
to_str
;
import
driver
::
session
::
session
;
import
driver
::
session
::
session
;
import
dvec
::{
dvec
,
extensions
};
export
check_crate
,
root_map
,
mutbl_map
;
export
check_crate
,
root_map
,
mutbl_map
;
...
@@ -298,7 +299,7 @@ enum loan_path {
...
@@ -298,7 +299,7 @@ enum loan_path {
// maps computed by `gather_loans` that are then used by `check_loans`
// maps computed by `gather_loans` that are then used by `check_loans`
type
req_maps
=
{
type
req_maps
=
{
req_loan_map
:
hashmap
<
ast
::
node_id
,
@
mut
[
@
const
[
loan
]]
>
,
req_loan_map
:
hashmap
<
ast
::
node_id
,
@
dvec
<@
dvec
<
loan
>>
>
,
pure_map
:
hashmap
<
ast
::
node_id
,
bckerr
>
pure_map
:
hashmap
<
ast
::
node_id
,
bckerr
>
};
};
...
...
src/rustc/middle/borrowck/check_loans.rs
浏览文件 @
08520a16
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
// 3. assignments do not affect things loaned out as immutable
// 3. assignments do not affect things loaned out as immutable
// 4. moves to dnot affect things loaned out in any way
// 4. moves to dnot affect things loaned out in any way
import
dvec
::{
dvec
,
extensions
};
import
categorization
::
public_methods
;
import
categorization
::
public_methods
;
export
check_loans
;
export
check_loans
;
...
@@ -22,7 +23,7 @@ enum check_loan_ctxt = @{
...
@@ -22,7 +23,7 @@ enum check_loan_ctxt = @{
// we are in a ctor, we track the self id
// we are in a ctor, we track the self id
mut
in_ctor
:
bool
,
mut
in_ctor
:
bool
,
mut
declared_purity
:
ast
::
purity
,
mut
declared_purity
:
ast
::
purity
,
mut
fn_args
:
[
ast
::
node_id
]
mut
fn_args
:
@
[
ast
::
node_id
]
};
};
// if we are enforcing purity, why are we doing so?
// if we are enforcing purity, why are we doing so?
...
@@ -44,7 +45,7 @@ fn check_loans(bccx: borrowck_ctxt,
...
@@ -44,7 +45,7 @@ fn check_loans(bccx: borrowck_ctxt,
reported
:
int_hash
(),
reported
:
int_hash
(),
mut
in_ctor
:
false
,
mut
in_ctor
:
false
,
mut
declared_purity
:
ast
::
impure_fn
,
mut
declared_purity
:
ast
::
impure_fn
,
mut
fn_args
:
[]});
mut
fn_args
:
@
[]});
let
vt
=
visit
::
mk_vt
(
@
{
visit_expr
:
check_loans_in_expr
,
let
vt
=
visit
::
mk_vt
(
@
{
visit_expr
:
check_loans_in_expr
,
visit_block
:
check_loans_in_block
,
visit_block
:
check_loans_in_block
,
visit_fn
:
check_loans_in_fn
visit_fn
:
check_loans_in_fn
...
@@ -179,7 +180,7 @@ fn check_pure_callee_or_arg(pc: purity_cause,
...
@@ -179,7 +180,7 @@ fn check_pure_callee_or_arg(pc: purity_cause,
let
did
=
ast_util
::
def_id_of_def
(
def
);
let
did
=
ast_util
::
def_id_of_def
(
def
);
let
is_fn_arg
=
let
is_fn_arg
=
did
.crate
==
ast
::
local_crate
&&
did
.crate
==
ast
::
local_crate
&&
self
.fn_args
.contains
(
did
.node
);
(
*
self
.fn_args
)
.contains
(
did
.node
);
if
is_fn_arg
{
ret
;
}
// case (a) above
if
is_fn_arg
{
ret
;
}
// case (a) above
}
}
ast
::
expr_fn_block
(
*
)
|
ast
::
expr_fn
(
*
)
|
ast
::
expr_fn_block
(
*
)
|
ast
::
expr_fn
(
*
)
|
...
@@ -225,7 +226,8 @@ fn is_allowed_pure_arg(expr: @ast::expr) -> bool {
...
@@ -225,7 +226,8 @@ fn is_allowed_pure_arg(expr: @ast::expr) -> bool {
ast
::
expr_path
(
_
)
{
ast
::
expr_path
(
_
)
{
let
def
=
self
.tcx
()
.def_map
.get
(
expr
.id
);
let
def
=
self
.tcx
()
.def_map
.get
(
expr
.id
);
let
did
=
ast_util
::
def_id_of_def
(
def
);
let
did
=
ast_util
::
def_id_of_def
(
def
);
did
.crate
==
ast
::
local_crate
&&
self
.fn_args
.contains
(
did
.node
)
did
.crate
==
ast
::
local_crate
&&
(
*
self
.fn_args
)
.contains
(
did
.node
)
}
}
ast
::
expr_fn_block
(
*
)
|
ast
::
expr_fn
(
*
)
{
ast
::
expr_fn_block
(
*
)
|
ast
::
expr_fn
(
*
)
{
self
.is_stack_closure
(
expr
.id
)
self
.is_stack_closure
(
expr
.id
)
...
@@ -484,7 +486,7 @@ fn check_loans_in_fn(fk: visit::fn_kind, decl: ast::fn_decl, body: ast::blk,
...
@@ -484,7 +486,7 @@ fn check_loans_in_fn(fk: visit::fn_kind, decl: ast::fn_decl, body: ast::blk,
sp
:
span
,
id
:
ast
::
node_id
,
&&
self
:
check_loan_ctxt
,
sp
:
span
,
id
:
ast
::
node_id
,
&&
self
:
check_loan_ctxt
,
visitor
:
visit
::
vt
<
check_loan_ctxt
>
)
{
visitor
:
visit
::
vt
<
check_loan_ctxt
>
)
{
#
debug
[
"purity on entry=%?"
,
self
.declared_purity
];
#
debug
[
"purity on entry=%?"
,
copy
self
.declared_purity
];
save_and_restore
(
self
.in_ctor
)
{||
save_and_restore
(
self
.in_ctor
)
{||
save_and_restore
(
self
.declared_purity
)
{||
save_and_restore
(
self
.declared_purity
)
{||
save_and_restore
(
self
.fn_args
)
{||
save_and_restore
(
self
.fn_args
)
{||
...
@@ -500,7 +502,7 @@ fn check_loans_in_fn(fk: visit::fn_kind, decl: ast::fn_decl, body: ast::blk,
...
@@ -500,7 +502,7 @@ fn check_loans_in_fn(fk: visit::fn_kind, decl: ast::fn_decl, body: ast::blk,
visit
::
fk_ctor
(
*
)
{
visit
::
fk_ctor
(
*
)
{
self
.in_ctor
=
true
;
self
.in_ctor
=
true
;
self
.declared_purity
=
decl
.purity
;
self
.declared_purity
=
decl
.purity
;
self
.fn_args
=
decl
.inputs
.map
({|
i
|
i
.id
});
self
.fn_args
=
@
decl
.inputs
.map
({|
i
|
i
.id
});
}
}
visit
::
fk_anon
(
*
)
|
visit
::
fk_anon
(
*
)
|
visit
::
fk_fn_block
(
*
)
if
is_stack_closure
{
visit
::
fk_fn_block
(
*
)
if
is_stack_closure
{
...
@@ -512,7 +514,7 @@ fn check_loans_in_fn(fk: visit::fn_kind, decl: ast::fn_decl, body: ast::blk,
...
@@ -512,7 +514,7 @@ fn check_loans_in_fn(fk: visit::fn_kind, decl: ast::fn_decl, body: ast::blk,
visit
::
fk_res
(
*
)
|
visit
::
fk_dtor
(
*
)
{
visit
::
fk_res
(
*
)
|
visit
::
fk_dtor
(
*
)
{
self
.in_ctor
=
false
;
self
.in_ctor
=
false
;
self
.declared_purity
=
decl
.purity
;
self
.declared_purity
=
decl
.purity
;
self
.fn_args
=
decl
.inputs
.map
({|
i
|
i
.id
});
self
.fn_args
=
@
decl
.inputs
.map
({|
i
|
i
.id
});
}
}
}
}
...
@@ -520,7 +522,7 @@ fn check_loans_in_fn(fk: visit::fn_kind, decl: ast::fn_decl, body: ast::blk,
...
@@ -520,7 +522,7 @@ fn check_loans_in_fn(fk: visit::fn_kind, decl: ast::fn_decl, body: ast::blk,
}
}
}
}
}
}
#
debug
[
"purity on exit=%?"
,
self
.declared_purity
];
#
debug
[
"purity on exit=%?"
,
copy
self
.declared_purity
];
}
}
fn
check_loans_in_expr
(
expr
:
@
ast
::
expr
,
fn
check_loans_in_expr
(
expr
:
@
ast
::
expr
,
...
...
src/rustc/middle/borrowck/gather_loans.rs
浏览文件 @
08520a16
...
@@ -273,13 +273,14 @@ fn check_mutbl(req_mutbl: ast::mutability,
...
@@ -273,13 +273,14 @@ fn check_mutbl(req_mutbl: ast::mutability,
}
}
}
}
fn
add_loans
(
scope_id
:
ast
::
node_id
,
loans
:
@
const
[
loan
]
)
{
fn
add_loans
(
scope_id
:
ast
::
node_id
,
loans
:
@
dvec
<
loan
>
)
{
alt
self
.req_maps.req_loan_map
.find
(
scope_id
)
{
alt
self
.req_maps.req_loan_map
.find
(
scope_id
)
{
some
(
l
)
{
some
(
l
)
{
*
l
+=
[
loans
]
;
(
*
l
)
.push
(
loans
)
;
}
}
none
{
none
{
self
.req_maps.req_loan_map
.insert
(
scope_id
,
@
mut
[
loans
]);
self
.req_maps.req_loan_map
.insert
(
scope_id
,
@
dvec
::
from_vec
([
mut
loans
]));
}
}
}
}
}
}
...
...
src/rustc/middle/borrowck/loan.rs
浏览文件 @
08520a16
...
@@ -5,8 +5,8 @@
...
@@ -5,8 +5,8 @@
export
public_methods
;
export
public_methods
;
impl
public_methods
for
borrowck_ctxt
{
impl
public_methods
for
borrowck_ctxt
{
fn
loan
(
cmt
:
cmt
,
mutbl
:
ast
::
mutability
)
->
@
const
[
loan
]
{
fn
loan
(
cmt
:
cmt
,
mutbl
:
ast
::
mutability
)
->
@
dvec
<
loan
>
{
let
lc
=
@
{
bccx
:
self
,
loans
:
@
mut
[]
};
let
lc
=
@
{
bccx
:
self
,
loans
:
@
dvec
()
};
lc
.loan
(
cmt
,
mutbl
);
lc
.loan
(
cmt
,
mutbl
);
ret
lc
.loans
;
ret
lc
.loans
;
}
}
...
@@ -14,7 +14,7 @@ fn loan(cmt: cmt, mutbl: ast::mutability) -> @const [loan] {
...
@@ -14,7 +14,7 @@ fn loan(cmt: cmt, mutbl: ast::mutability) -> @const [loan] {
type
loan_ctxt
=
@
{
type
loan_ctxt
=
@
{
bccx
:
borrowck_ctxt
,
bccx
:
borrowck_ctxt
,
loans
:
@
mut
[
loan
]
loans
:
@
dvec
<
loan
>
};
};
impl
loan_methods
for
loan_ctxt
{
impl
loan_methods
for
loan_ctxt
{
...
@@ -23,9 +23,9 @@ fn ok_with_loan_of(cmt: cmt,
...
@@ -23,9 +23,9 @@ fn ok_with_loan_of(cmt: cmt,
// Note: all cmt's that we deal with will have a non-none lp, because
// Note: all cmt's that we deal with will have a non-none lp, because
// the entry point into this routine, `borrowck_ctxt::loan()`, rejects
// the entry point into this routine, `borrowck_ctxt::loan()`, rejects
// any cmt with a none-lp.
// any cmt with a none-lp.
*
self
.loans
+=
[
{
lp
:
option
::
get
(
cmt
.lp
),
(
*
self
.loans
)
.push
(
{
lp
:
option
::
get
(
cmt
.lp
),
cmt
:
cmt
,
cmt
:
cmt
,
mutbl
:
mutbl
}]
;
mutbl
:
mutbl
})
;
}
}
fn
loan
(
cmt
:
cmt
,
req_mutbl
:
ast
::
mutability
)
{
fn
loan
(
cmt
:
cmt
,
req_mutbl
:
ast
::
mutability
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录