Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
72675d82
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,发现更多精彩内容 >>
提交
72675d82
编写于
11月 06, 2017
作者:
N
Niko Matsakis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
replace `RegionIndex` with `RegionVid` (which now impls Idx)
上级
89c1b600
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
44 addition
and
54 deletion
+44
-54
src/librustc_mir/dataflow/impls/borrows.rs
src/librustc_mir/dataflow/impls/borrows.rs
+2
-2
src/librustc_mir/transform/nll/constraint_generation.rs
src/librustc_mir/transform/nll/constraint_generation.rs
+6
-6
src/librustc_mir/transform/nll/free_regions.rs
src/librustc_mir/transform/nll/free_regions.rs
+4
-6
src/librustc_mir/transform/nll/mod.rs
src/librustc_mir/transform/nll/mod.rs
+10
-15
src/librustc_mir/transform/nll/region_infer.rs
src/librustc_mir/transform/nll/region_infer.rs
+15
-16
src/librustc_mir/transform/nll/renumber.rs
src/librustc_mir/transform/nll/renumber.rs
+1
-2
src/librustc_mir/transform/nll/subtype.rs
src/librustc_mir/transform/nll/subtype.rs
+6
-7
未找到文件。
src/librustc_mir/dataflow/impls/borrows.rs
浏览文件 @
72675d82
...
...
@@ -22,7 +22,7 @@
use
dataflow
::{
BitDenotation
,
BlockSets
,
DataflowOperator
};
pub
use
dataflow
::
indexes
::
BorrowIndex
;
use
transform
::
nll
::
region_infer
::
RegionInferenceContext
;
use
transform
::
nll
::
ToRegion
Index
;
use
transform
::
nll
::
ToRegion
Vid
;
use
syntax_pos
::
Span
;
...
...
@@ -145,7 +145,7 @@ fn kill_loans_out_of_scope_at_location(&self,
location
:
Location
)
{
if
let
Some
(
regioncx
)
=
self
.nonlexical_regioncx
{
for
(
borrow_index
,
borrow_data
)
in
self
.borrows
.iter_enumerated
()
{
let
borrow_region
=
borrow_data
.region
.to_region_
index
();
let
borrow_region
=
borrow_data
.region
.to_region_
vid
();
if
!
regioncx
.region_contains_point
(
borrow_region
,
location
)
{
// The region checker really considers the borrow
// to start at the point **after** the location of
...
...
src/librustc_mir/transform/nll/constraint_generation.rs
浏览文件 @
72675d82
...
...
@@ -23,7 +23,7 @@
use
super
::
subtype
;
use
super
::
LivenessResults
;
use
super
::
ToRegion
Index
;
use
super
::
ToRegion
Vid
;
use
super
::
region_infer
::
RegionInferenceContext
;
pub
(
super
)
fn
generate_constraints
<
'a
,
'gcx
,
'tcx
>
(
...
...
@@ -102,7 +102,7 @@ fn add_regular_live_constraint<T>(&mut self, live_ty: T, location: Location)
self
.infcx
.tcx
.for_each_free_region
(
&
live_ty
,
|
live_region
|
{
let
vid
=
live_region
.to_region_
index
();
let
vid
=
live_region
.to_region_
vid
();
self
.regioncx
.add_live_point
(
vid
,
location
);
});
}
...
...
@@ -197,8 +197,8 @@ fn add_borrow_constraint(
};
self
.regioncx
.add_outlives
(
span
,
borrow_region
.to_region_
index
(),
destination_region
.to_region_
index
(),
borrow_region
.to_region_
vid
(),
destination_region
.to_region_
vid
(),
location
.successor_within_block
());
}
...
...
@@ -227,8 +227,8 @@ fn add_reborrow_constraint(
let
span
=
self
.mir
.source_info
(
location
)
.span
;
self
.regioncx
.add_outlives
(
span
,
base_region
.to_region_
index
(),
borrow_region
.to_region_
index
(),
base_region
.to_region_
vid
(),
borrow_region
.to_region_
vid
(),
location
.successor_within_block
());
}
}
...
...
src/librustc_mir/transform/nll/free_regions.rs
浏览文件 @
72675d82
...
...
@@ -25,20 +25,18 @@
use
rustc
::
hir
::
def_id
::
DefId
;
use
rustc
::
infer
::
InferCtxt
;
use
rustc
::
middle
::
free_region
::
FreeRegionMap
;
use
rustc
::
ty
;
use
rustc
::
ty
::{
self
,
RegionVid
}
;
use
rustc
::
ty
::
subst
::
Substs
;
use
rustc
::
util
::
nodemap
::
FxHashMap
;
use
rustc_data_structures
::
indexed_vec
::
Idx
;
use
super
::
RegionIndex
;
#[derive(Debug)]
pub
struct
FreeRegions
<
'tcx
>
{
/// Given a free region defined on this function (either early- or
/// late-bound), this maps it to its internal region index. When
/// the region context is created, the first N variables will be
/// created based on these indices.
pub
indices
:
FxHashMap
<
ty
::
Region
<
'tcx
>
,
Region
Index
>
,
pub
indices
:
FxHashMap
<
ty
::
Region
<
'tcx
>
,
Region
Vid
>
,
/// The map from the typeck tables telling us how to relate free regions.
pub
free_region_map
:
&
'tcx
FreeRegionMap
<
'tcx
>
,
...
...
@@ -81,9 +79,9 @@ pub fn free_regions<'a, 'gcx, 'tcx>(
}
fn
insert_free_region
<
'tcx
>
(
free_regions
:
&
mut
FxHashMap
<
ty
::
Region
<
'tcx
>
,
Region
Index
>
,
free_regions
:
&
mut
FxHashMap
<
ty
::
Region
<
'tcx
>
,
Region
Vid
>
,
region
:
ty
::
Region
<
'tcx
>
,
)
{
let
next
=
Region
Index
::
new
(
free_regions
.len
());
let
next
=
Region
Vid
::
new
(
free_regions
.len
());
free_regions
.entry
(
region
)
.or_insert
(
next
);
}
src/librustc_mir/transform/nll/mod.rs
浏览文件 @
72675d82
...
...
@@ -11,9 +11,8 @@
use
rustc
::
hir
::
def_id
::
DefId
;
use
rustc
::
mir
::
Mir
;
use
rustc
::
infer
::
InferCtxt
;
use
rustc
::
ty
::{
self
,
RegionKind
};
use
rustc
::
ty
::{
self
,
RegionKind
,
RegionVid
};
use
rustc
::
util
::
nodemap
::
FxHashMap
;
use
rustc_data_structures
::
indexed_vec
::
Idx
;
use
std
::
collections
::
BTreeSet
;
use
transform
::
MirSource
;
use
util
::
liveness
::{
self
,
LivenessMode
,
LivenessResult
,
LocalSet
};
...
...
@@ -152,23 +151,19 @@ fn dump_mir_results<'a, 'gcx, 'tcx>(
});
}
newtype_index!
(
RegionIndex
{
DEBUG_FORMAT
=
"'_#{}r"
,
});
/// Right now, we piggy back on the `ReVar` to store our NLL inference
/// regions. These are indexed with `Region
Index
`. This method will
/// assert that the region is a `ReVar` and
convert the internal index
///
into a `RegionIndex`. This is reasonable because in our MIR we
///
replace all free regions
with inference variables.
pub
trait
ToRegion
Index
{
fn
to_region_
index
(
&
self
)
->
RegionIndex
;
/// regions. These are indexed with `Region
Vid
`. This method will
/// assert that the region is a `ReVar` and
extract its interal index.
///
This is reasonable because in our MIR we replace all free regions
/// with inference variables.
pub
trait
ToRegion
Vid
{
fn
to_region_
vid
(
&
self
)
->
RegionVid
;
}
impl
ToRegion
Index
for
RegionKind
{
fn
to_region_
index
(
&
self
)
->
RegionIndex
{
impl
ToRegion
Vid
for
RegionKind
{
fn
to_region_
vid
(
&
self
)
->
RegionVid
{
if
let
&
ty
::
ReVar
(
vid
)
=
self
{
RegionIndex
::
new
(
vid
.index
as
usize
)
vid
}
else
{
bug!
(
"region is not an ReVar: {:?}"
,
self
)
}
...
...
src/librustc_mir/transform/nll/region_infer.rs
浏览文件 @
72675d82
...
...
@@ -8,11 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use
super
::
RegionIndex
;
use
super
::
free_regions
::
FreeRegions
;
use
rustc
::
infer
::
InferCtxt
;
use
rustc
::
mir
::{
Location
,
Mir
};
use
rustc
::
ty
;
use
rustc
::
ty
::{
self
,
RegionVid
}
;
use
rustc_data_structures
::
indexed_vec
::
IndexVec
;
use
rustc_data_structures
::
fx
::
FxHashSet
;
use
std
::
collections
::
BTreeSet
;
...
...
@@ -21,10 +20,10 @@
pub
struct
RegionInferenceContext
<
'tcx
>
{
/// Contains the definition for every region variable. Region
/// variables are identified by their index (`Region
Index
`). The
/// variables are identified by their index (`Region
Vid
`). The
/// definition contains information about where the region came
/// from as well as its final inferred value.
definitions
:
IndexVec
<
Region
Index
,
RegionDefinition
<
'tcx
>>
,
definitions
:
IndexVec
<
Region
Vid
,
RegionDefinition
<
'tcx
>>
,
/// The indices of all "free regions" in scope. These are the
/// lifetime parameters (anonymous and named) declared in the
...
...
@@ -35,7 +34,7 @@ pub struct RegionInferenceContext<'tcx> {
///
/// These indices will be from 0..N, as it happens, but we collect
/// them into a vector for convenience.
free_regions
:
Vec
<
Region
Index
>
,
free_regions
:
Vec
<
Region
Vid
>
,
/// The constraints we have accumulated and used during solving.
constraints
:
Vec
<
Constraint
>
,
...
...
@@ -66,7 +65,7 @@ struct RegionDefinition<'tcx> {
#[derive(Clone,
Default,
PartialEq,
Eq)]
struct
Region
{
points
:
BTreeSet
<
Location
>
,
free_regions
:
BTreeSet
<
Region
Index
>
,
free_regions
:
BTreeSet
<
Region
Vid
>
,
}
impl
fmt
::
Debug
for
Region
{
...
...
@@ -84,7 +83,7 @@ fn add_point(&mut self, point: Location) -> bool {
self
.points
.insert
(
point
)
}
fn
add_free_region
(
&
mut
self
,
region
:
Region
Index
)
->
bool
{
fn
add_free_region
(
&
mut
self
,
region
:
Region
Vid
)
->
bool
{
self
.free_regions
.insert
(
region
)
}
...
...
@@ -99,10 +98,10 @@ pub struct Constraint {
span
:
Span
,
/// The region SUP must outlive SUB...
sup
:
Region
Index
,
sup
:
Region
Vid
,
/// Region that must be outlived.
sub
:
Region
Index
,
sub
:
Region
Vid
,
/// At this location.
point
:
Location
,
...
...
@@ -198,24 +197,24 @@ fn init_free_regions(&mut self, free_regions: &FreeRegions<'tcx>, mir: &Mir<'tcx
}
/// Returns an iterator over all the region indices.
pub
fn
regions
(
&
self
)
->
impl
Iterator
<
Item
=
Region
Index
>
{
pub
fn
regions
(
&
self
)
->
impl
Iterator
<
Item
=
Region
Vid
>
{
self
.definitions
.indices
()
}
/// Returns true if the region `r` contains the point `p`.
///
/// Until `solve()` executes, this value is not particularly meaningful.
pub
fn
region_contains_point
(
&
self
,
r
:
Region
Index
,
p
:
Location
)
->
bool
{
pub
fn
region_contains_point
(
&
self
,
r
:
Region
Vid
,
p
:
Location
)
->
bool
{
self
.definitions
[
r
]
.value
.contains_point
(
p
)
}
/// Returns access to the value of `r` for debugging purposes.
pub
(
super
)
fn
region_value
(
&
self
,
r
:
Region
Index
)
->
&
fmt
::
Debug
{
pub
(
super
)
fn
region_value
(
&
self
,
r
:
Region
Vid
)
->
&
fmt
::
Debug
{
&
self
.definitions
[
r
]
.value
}
/// Indicates that the region variable `v` is live at the point `point`.
pub
(
super
)
fn
add_live_point
(
&
mut
self
,
v
:
Region
Index
,
point
:
Location
)
{
pub
(
super
)
fn
add_live_point
(
&
mut
self
,
v
:
Region
Vid
,
point
:
Location
)
{
debug!
(
"add_live_point({:?}, {:?})"
,
v
,
point
);
let
definition
=
&
mut
self
.definitions
[
v
];
if
!
definition
.constant
{
...
...
@@ -231,8 +230,8 @@ pub(super) fn add_live_point(&mut self, v: RegionIndex, point: Location) {
pub
(
super
)
fn
add_outlives
(
&
mut
self
,
span
:
Span
,
sup
:
Region
Index
,
sub
:
Region
Index
,
sup
:
Region
Vid
,
sub
:
Region
Vid
,
point
:
Location
,
)
{
debug!
(
"add_outlives({:?}: {:?} @ {:?}"
,
sup
,
sub
,
point
);
...
...
@@ -268,7 +267,7 @@ pub(super) fn solve(&mut self, infcx: &InferCtxt<'a, 'gcx, 'tcx>, mir: &Mir<'tcx
fn
propagate_constraints
(
&
mut
self
,
mir
:
&
Mir
<
'tcx
>
,
)
->
Vec
<
(
Region
Index
,
Span
,
RegionIndex
)
>
{
)
->
Vec
<
(
Region
Vid
,
Span
,
RegionVid
)
>
{
let
mut
changed
=
true
;
let
mut
dfs
=
Dfs
::
new
(
mir
);
let
mut
error_regions
=
FxHashSet
();
...
...
src/librustc_mir/transform/nll/renumber.rs
浏览文件 @
72675d82
...
...
@@ -17,7 +17,6 @@
use
syntax_pos
::
DUMMY_SP
;
use
std
::
collections
::
HashMap
;
use
super
::
RegionIndex
;
use
super
::
free_regions
::
FreeRegions
;
/// Replaces all free regions appearing in the MIR with fresh
...
...
@@ -52,7 +51,7 @@ struct NLLVisitor<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
num_region_variables
:
usize
,
infcx
:
&
'a
InferCtxt
<
'a
,
'gcx
,
'tcx
>
,
free_regions
:
&
'a
FreeRegions
<
'tcx
>
,
free_region_inference_vars
:
IndexVec
<
Region
Index
,
ty
::
Region
<
'tcx
>>
,
free_region_inference_vars
:
IndexVec
<
Region
Vid
,
ty
::
Region
<
'tcx
>>
,
arg_count
:
usize
,
}
...
...
src/librustc_mir/transform/nll/subtype.rs
浏览文件 @
72675d82
...
...
@@ -8,15 +8,14 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use
super
::
RegionIndex
;
use
transform
::
nll
::
ToRegionIndex
;
use
rustc
::
ty
::{
self
,
Ty
,
TyCtxt
};
use
transform
::
nll
::
ToRegionVid
;
use
rustc
::
ty
::{
self
,
Ty
,
TyCtxt
,
RegionVid
};
use
rustc
::
ty
::
relate
::{
self
,
Relate
,
RelateResult
,
TypeRelation
};
pub
fn
outlives_pairs
<
'a
,
'gcx
,
'tcx
>
(
tcx
:
TyCtxt
<
'a
,
'gcx
,
'tcx
>
,
a
:
Ty
<
'tcx
>
,
b
:
Ty
<
'tcx
>
)
->
Vec
<
(
Region
Index
,
RegionIndex
)
>
->
Vec
<
(
Region
Vid
,
RegionVid
)
>
{
let
mut
subtype
=
Subtype
::
new
(
tcx
);
match
subtype
.relate
(
&
a
,
&
b
)
{
...
...
@@ -28,7 +27,7 @@ pub fn outlives_pairs<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
struct
Subtype
<
'a
,
'gcx
:
'a
+
'tcx
,
'tcx
:
'a
>
{
tcx
:
TyCtxt
<
'a
,
'gcx
,
'tcx
>
,
outlives_pairs
:
Vec
<
(
Region
Index
,
RegionIndex
)
>
,
outlives_pairs
:
Vec
<
(
Region
Vid
,
RegionVid
)
>
,
ambient_variance
:
ty
::
Variance
,
}
...
...
@@ -67,8 +66,8 @@ fn tys(&mut self, t: Ty<'tcx>, t2: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
fn
regions
(
&
mut
self
,
r_a
:
ty
::
Region
<
'tcx
>
,
r_b
:
ty
::
Region
<
'tcx
>
)
->
RelateResult
<
'tcx
,
ty
::
Region
<
'tcx
>>
{
let
a
=
r_a
.to_region_
index
();
let
b
=
r_b
.to_region_
index
();
let
a
=
r_a
.to_region_
vid
();
let
b
=
r_b
.to_region_
vid
();
match
self
.ambient_variance
{
ty
::
Covariant
=>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录