Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
2f3e36f5
R
Rust
项目概览
int
/
Rust
接近 1 年 前同步成功
通知
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,发现更多精彩内容 >>
提交
2f3e36f5
编写于
7月 16, 2019
作者:
L
lqd
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polonius: generate `killed` facts for assignments to projections
上级
823ab42e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
75 addition
and
14 deletion
+75
-14
src/librustc_mir/borrow_check/nll/constraint_generation.rs
src/librustc_mir/borrow_check/nll/constraint_generation.rs
+75
-14
未找到文件。
src/librustc_mir/borrow_check/nll/constraint_generation.rs
浏览文件 @
2f3e36f5
...
...
@@ -3,12 +3,15 @@
use
crate
::
borrow_check
::
nll
::
ToRegionVid
;
use
crate
::
borrow_check
::
nll
::
facts
::
AllFacts
;
use
crate
::
borrow_check
::
nll
::
region_infer
::
values
::
LivenessValues
;
use
crate
::
borrow_check
::
places_conflict
;
use
rustc
::
infer
::
InferCtxt
;
use
rustc
::
mir
::
visit
::
TyContext
;
use
rustc
::
mir
::
visit
::
Visitor
;
use
rustc
::
mir
::{
BasicBlock
,
BasicBlockData
,
Location
,
Body
,
Place
,
PlaceBase
,
Rvalue
,
TerminatorKind
};
use
rustc
::
mir
::{
Local
,
SourceInfo
,
Statement
,
StatementKind
,
Terminator
};
use
rustc
::
mir
::
UserTypeProjection
;
use
rustc
::
mir
::{
BasicBlock
,
BasicBlockData
,
Body
,
Local
,
Location
,
Place
,
PlaceBase
,
Projection
,
ProjectionElem
,
Rvalue
,
SourceInfo
,
Statement
,
StatementKind
,
Terminator
,
TerminatorKind
,
UserTypeProjection
,
};
use
rustc
::
ty
::
fold
::
TypeFoldable
;
use
rustc
::
ty
::{
self
,
ClosureSubsts
,
GeneratorSubsts
,
RegionVid
,
Ty
};
use
rustc
::
ty
::
subst
::
SubstsRef
;
...
...
@@ -27,6 +30,7 @@ pub(super) fn generate_constraints<'cx, 'tcx>(
liveness_constraints
,
location_table
,
all_facts
,
body
,
};
for
(
bb
,
data
)
in
body
.basic_blocks
()
.iter_enumerated
()
{
...
...
@@ -41,6 +45,7 @@ struct ConstraintGeneration<'cg, 'cx, 'tcx> {
location_table
:
&
'cg
LocationTable
,
liveness_constraints
:
&
'cg
mut
LivenessValues
<
RegionVid
>
,
borrow_set
:
&
'cg
BorrowSet
<
'tcx
>
,
body
:
&
'cg
Body
<
'tcx
>
,
}
impl
<
'cg
,
'cx
,
'tcx
>
Visitor
<
'tcx
>
for
ConstraintGeneration
<
'cg
,
'cx
,
'tcx
>
{
...
...
@@ -212,17 +217,73 @@ fn add_regular_live_constraint<T>(&mut self, live_ty: T, location: Location)
/// as `killed`. For example, when assigning to a local, or on a call's return destination.
fn
record_killed_borrows_for_place
(
&
mut
self
,
place
:
&
Place
<
'tcx
>
,
location
:
Location
)
{
if
let
Some
(
all_facts
)
=
self
.all_facts
{
if
let
Place
{
base
:
PlaceBase
::
Local
(
local
),
projection
:
None
,
}
=
place
{
record_killed_borrows_for_local
(
all_facts
,
self
.borrow_set
,
self
.location_table
,
local
,
location
,
);
// Depending on the `Place` we're killing:
// - if it's a local, or a single deref of a local,
// we kill all the borrows on the local.
// - if it's a deeper projection, we have to filter which
// of the borrows are killed: the ones whose `borrowed_place`
// conflicts with the `place`.
match
place
{
Place
{
base
:
PlaceBase
::
Local
(
local
),
projection
:
None
,
}
|
Place
{
base
:
PlaceBase
::
Local
(
local
),
projection
:
Some
(
box
Projection
{
base
:
None
,
elem
:
ProjectionElem
::
Deref
,
}),
}
=>
{
debug!
(
"Recording `killed` facts for borrows of local={:?} at location={:?}"
,
local
,
location
);
record_killed_borrows_for_local
(
all_facts
,
self
.borrow_set
,
self
.location_table
,
local
,
location
,
);
}
Place
{
base
:
PlaceBase
::
Static
(
_
),
..
}
=>
{
// Ignore kills of static or static mut variables.
}
Place
{
base
:
PlaceBase
::
Local
(
local
),
projection
:
Some
(
_
),
}
=>
{
// Kill conflicting borrows of the innermost local.
debug!
(
"Recording `killed` facts for borrows of
\
innermost projected local={:?} at location={:?}"
,
local
,
location
);
if
let
Some
(
borrow_indices
)
=
self
.borrow_set.local_map
.get
(
local
)
{
for
&
borrow_index
in
borrow_indices
{
let
places_conflict
=
places_conflict
::
places_conflict
(
self
.infcx.tcx
,
self
.body
,
&
self
.borrow_set.borrows
[
borrow_index
]
.borrowed_place
,
place
,
places_conflict
::
PlaceConflictBias
::
NoOverlap
,
);
if
places_conflict
{
let
location_index
=
self
.location_table
.mid_index
(
location
);
all_facts
.killed
.push
((
borrow_index
,
location_index
));
}
}
}
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录