Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
81f6ce5c
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,发现更多精彩内容 >>
提交
81f6ce5c
编写于
10月 26, 2017
作者:
N
Niko Matsakis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rename `Lookup` to `TyContext` and pass more info when visiting tys
上级
2379faa9
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
61 addition
and
44 deletion
+61
-44
src/librustc/mir/visit.rs
src/librustc/mir/visit.rs
+34
-17
src/librustc_mir/build/mod.rs
src/librustc_mir/build/mod.rs
+2
-2
src/librustc_mir/transform/clean_end_regions.rs
src/librustc_mir/transform/clean_end_regions.rs
+2
-2
src/librustc_mir/transform/erase_regions.rs
src/librustc_mir/transform/erase_regions.rs
+2
-2
src/librustc_mir/transform/nll/region_infer.rs
src/librustc_mir/transform/nll/region_infer.rs
+0
-1
src/librustc_mir/transform/nll/renumber.rs
src/librustc_mir/transform/nll/renumber.rs
+16
-16
src/librustc_mir/transform/type_check.rs
src/librustc_mir/transform/type_check.rs
+2
-2
src/librustc_passes/mir_stats.rs
src/librustc_passes/mir_stats.rs
+3
-2
未找到文件。
src/librustc/mir/visit.rs
浏览文件 @
81f6ce5c
...
...
@@ -209,7 +209,7 @@ fn visit_source_info(&mut self,
fn
visit_ty
(
&
mut
self
,
ty
:
&
$
(
$mutability
)
*
Ty
<
'tcx
>
,
_
:
Lookup
)
{
_
:
TyContext
)
{
self
.super_ty
(
ty
);
}
...
...
@@ -256,8 +256,9 @@ fn visit_const_usize(&mut self,
}
fn
visit_local_decl
(
&
mut
self
,
local
:
Local
,
local_decl
:
&
$
(
$mutability
)
*
LocalDecl
<
'tcx
>
)
{
self
.super_local_decl
(
local_decl
);
self
.super_local_decl
(
local
,
local
_decl
);
}
fn
visit_local
(
&
mut
self
,
...
...
@@ -291,14 +292,14 @@ fn super_mir(&mut self,
self
.visit_visibility_scope_data
(
scope
);
}
let
lookup
=
Lookup
::
Src
(
SourceInfo
{
let
lookup
=
TyContext
::
SourceInfo
(
SourceInfo
{
span
:
mir
.span
,
scope
:
ARGUMENT_VISIBILITY_SCOPE
,
});
self
.visit_ty
(
&
$
(
$mutability
)
*
mir
.return_ty
,
lookup
);
for
local
_decl
in
&
$
(
$mutability
)
*
mir
.local_decls
{
self
.visit_local_decl
(
local
_decl
);
for
local
in
mir
.local_decls
.indices
()
{
self
.visit_local_decl
(
local
,
&
$
(
$mutability
)
*
mir
.local_decls
[
local
]
);
}
self
.visit_span
(
&
$
(
$mutability
)
*
mir
.span
);
...
...
@@ -359,7 +360,8 @@ fn super_statement(&mut self,
for
operand
in
lvalues
{
self
.visit_lvalue
(
&
$
(
$mutability
)
*
operand
.lval
,
LvalueContext
::
Validate
,
location
);
self
.visit_ty
(
&
$
(
$mutability
)
*
operand
.ty
,
Lookup
::
Loc
(
location
));
self
.visit_ty
(
&
$
(
$mutability
)
*
operand
.ty
,
TyContext
::
Location
(
location
));
}
}
StatementKind
::
SetDiscriminant
{
ref
$
(
$mutability
)
*
lvalue
,
..
}
=>
{
...
...
@@ -421,7 +423,7 @@ fn super_terminator_kind(&mut self,
ref
values
,
ref
targets
}
=>
{
self
.visit_operand
(
discr
,
source_location
);
self
.visit_ty
(
switch_ty
,
Lookup
::
Loc
(
source_location
));
self
.visit_ty
(
switch_ty
,
TyContext
::
Location
(
source_location
));
for
value
in
&
values
[
..
]
{
self
.visit_const_int
(
value
,
source_location
);
}
...
...
@@ -538,7 +540,7 @@ fn super_rvalue(&mut self,
ref
$
(
$mutability
)
*
operand
,
ref
$
(
$mutability
)
*
ty
)
=>
{
self
.visit_operand
(
operand
,
location
);
self
.visit_ty
(
ty
,
Lookup
::
Loc
(
location
));
self
.visit_ty
(
ty
,
TyContext
::
Location
(
location
));
}
Rvalue
::
BinaryOp
(
_
bin_op
,
...
...
@@ -560,7 +562,7 @@ fn super_rvalue(&mut self,
}
Rvalue
::
NullaryOp
(
_
op
,
ref
$
(
$mutability
)
*
ty
)
=>
{
self
.visit_ty
(
ty
,
Lookup
::
Loc
(
location
));
self
.visit_ty
(
ty
,
TyContext
::
Location
(
location
));
}
Rvalue
::
Aggregate
(
ref
$
(
$mutability
)
*
kind
,
...
...
@@ -568,7 +570,7 @@ fn super_rvalue(&mut self,
let
kind
=
&
$
(
$mutability
)
*
**
kind
;
match
*
kind
{
AggregateKind
::
Array
(
ref
$
(
$mutability
)
*
ty
)
=>
{
self
.visit_ty
(
ty
,
Lookup
::
Loc
(
location
));
self
.visit_ty
(
ty
,
TyContext
::
Location
(
location
));
}
AggregateKind
::
Tuple
=>
{
}
...
...
@@ -638,7 +640,7 @@ fn super_static(&mut self,
ref
$
(
$mutability
)
*
ty
,
}
=
*
static_
;
self
.visit_def_id
(
def_id
,
location
);
self
.visit_ty
(
ty
,
Lookup
::
Loc
(
location
));
self
.visit_ty
(
ty
,
TyContext
::
Location
(
location
));
}
fn
super_projection
(
&
mut
self
,
...
...
@@ -668,7 +670,7 @@ fn super_projection_elem(&mut self,
ProjectionElem
::
Subslice
{
from
:
_
,
to
:
_
}
=>
{
}
ProjectionElem
::
Field
(
_
field
,
ref
$
(
$mutability
)
*
ty
)
=>
{
self
.visit_ty
(
ty
,
Lookup
::
Loc
(
location
));
self
.visit_ty
(
ty
,
TyContext
::
Location
(
location
));
}
ProjectionElem
::
Index
(
ref
$
(
$mutability
)
*
local
)
=>
{
self
.visit_local
(
local
,
LvalueContext
::
Consume
,
location
);
...
...
@@ -683,6 +685,7 @@ fn super_projection_elem(&mut self,
}
fn
super_local_decl
(
&
mut
self
,
local
:
Local
,
local_decl
:
&
$
(
$mutability
)
*
LocalDecl
<
'tcx
>
)
{
let
LocalDecl
{
mutability
:
_
,
...
...
@@ -694,7 +697,10 @@ fn super_local_decl(&mut self,
is_user_variable
:
_
,
}
=
*
local_decl
;
self
.visit_ty
(
ty
,
Lookup
::
Src
(
*
source_info
));
self
.visit_ty
(
ty
,
TyContext
::
LocalDecl
{
local
,
source_info
:
*
source_info
,
});
self
.visit_source_info
(
source_info
);
self
.visit_visibility_scope
(
lexical_scope
);
}
...
...
@@ -718,7 +724,7 @@ fn super_constant(&mut self,
}
=
*
constant
;
self
.visit_span
(
span
);
self
.visit_ty
(
ty
,
Lookup
::
Loc
(
location
));
self
.visit_ty
(
ty
,
TyContext
::
Location
(
location
));
self
.visit_literal
(
literal
,
location
);
}
...
...
@@ -796,10 +802,21 @@ fn visit_location(&mut self, mir: & $($mutability)* Mir<'tcx>, location: Locatio
make_mir_visitor!
(
Visitor
,);
make_mir_visitor!
(
MutVisitor
,
mut
);
/// Extra information passed to `visit_ty` and friends to give context
/// about where the type etc appears.
#[derive(Copy,
Clone,
Debug)]
pub
enum
Lookup
{
Loc
(
Location
),
Src
(
SourceInfo
),
pub
enum
TyContext
{
LocalDecl
{
/// The index of the local variable we are visiting.
local
:
Local
,
/// The source location where this local variable was declared.
source_info
:
SourceInfo
,
},
Location
(
Location
),
SourceInfo
(
SourceInfo
),
}
#[derive(Copy,
Clone,
Debug,
PartialEq,
Eq)]
...
...
src/librustc_mir/build/mod.rs
浏览文件 @
81f6ce5c
...
...
@@ -17,7 +17,7 @@
use
rustc
::
middle
::
region
;
use
rustc
::
mir
::
*
;
use
rustc
::
mir
::
transform
::
MirSource
;
use
rustc
::
mir
::
visit
::{
MutVisitor
,
Lookup
};
use
rustc
::
mir
::
visit
::{
MutVisitor
,
TyContext
};
use
rustc
::
ty
::{
self
,
Ty
,
TyCtxt
};
use
rustc
::
ty
::
subst
::
Substs
;
use
rustc
::
util
::
nodemap
::
NodeMap
;
...
...
@@ -165,7 +165,7 @@ struct GlobalizeMir<'a, 'gcx: 'a> {
}
impl
<
'a
,
'gcx
:
'tcx
,
'tcx
>
MutVisitor
<
'tcx
>
for
GlobalizeMir
<
'a
,
'gcx
>
{
fn
visit_ty
(
&
mut
self
,
ty
:
&
mut
Ty
<
'tcx
>
,
_
:
Lookup
)
{
fn
visit_ty
(
&
mut
self
,
ty
:
&
mut
Ty
<
'tcx
>
,
_
:
TyContext
)
{
if
let
Some
(
lifted
)
=
self
.tcx
.lift
(
ty
)
{
*
ty
=
lifted
;
}
else
{
...
...
src/librustc_mir/transform/clean_end_regions.rs
浏览文件 @
81f6ce5c
...
...
@@ -24,7 +24,7 @@
use
rustc
::
middle
::
region
;
use
rustc
::
mir
::
transform
::{
MirPass
,
MirSource
};
use
rustc
::
mir
::{
BasicBlock
,
Location
,
Mir
,
Rvalue
,
Statement
,
StatementKind
};
use
rustc
::
mir
::
visit
::{
MutVisitor
,
Visitor
,
Lookup
};
use
rustc
::
mir
::
visit
::{
MutVisitor
,
Visitor
,
TyContext
};
use
rustc
::
ty
::{
Ty
,
RegionKind
,
TyCtxt
};
pub
struct
CleanEndRegions
;
...
...
@@ -67,7 +67,7 @@ fn visit_rvalue(&mut self,
self
.super_rvalue
(
rvalue
,
location
);
}
fn
visit_ty
(
&
mut
self
,
ty
:
&
Ty
<
'tcx
>
,
_
:
Lookup
)
{
fn
visit_ty
(
&
mut
self
,
ty
:
&
Ty
<
'tcx
>
,
_
:
TyContext
)
{
// Gather regions that occur in types
for
re
in
ty
.walk
()
.flat_map
(|
t
|
t
.regions
())
{
match
*
re
{
...
...
src/librustc_mir/transform/erase_regions.rs
浏览文件 @
81f6ce5c
...
...
@@ -17,7 +17,7 @@
use
rustc
::
ty
::
subst
::
Substs
;
use
rustc
::
ty
::{
self
,
Ty
,
TyCtxt
};
use
rustc
::
mir
::
*
;
use
rustc
::
mir
::
visit
::{
MutVisitor
,
Lookup
};
use
rustc
::
mir
::
visit
::{
MutVisitor
,
TyContext
};
use
rustc
::
mir
::
transform
::{
MirPass
,
MirSource
};
struct
EraseRegionsVisitor
<
'a
,
'tcx
:
'a
>
{
...
...
@@ -35,7 +35,7 @@ pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Self {
}
impl
<
'a
,
'tcx
>
MutVisitor
<
'tcx
>
for
EraseRegionsVisitor
<
'a
,
'tcx
>
{
fn
visit_ty
(
&
mut
self
,
ty
:
&
mut
Ty
<
'tcx
>
,
_
:
Lookup
)
{
fn
visit_ty
(
&
mut
self
,
ty
:
&
mut
Ty
<
'tcx
>
,
_
:
TyContext
)
{
if
!
self
.in_validation_statement
{
*
ty
=
self
.tcx
.erase_regions
(
ty
);
}
...
...
src/librustc_mir/transform/nll/region_infer.rs
浏览文件 @
81f6ce5c
...
...
@@ -60,7 +60,6 @@ pub fn new(num_region_variables: usize) -> Self {
}
}
/// Returns an iterator over all the region indices.
pub
fn
regions
(
&
self
)
->
impl
Iterator
<
Item
=
RegionIndex
>
{
self
.definitions
.indices
()
...
...
src/librustc_mir/transform/nll/renumber.rs
浏览文件 @
81f6ce5c
...
...
@@ -12,7 +12,7 @@
use
rustc
::
ty
::
subst
::{
Kind
,
Substs
};
use
rustc
::
ty
::{
Ty
,
ClosureSubsts
,
RegionVid
,
RegionKind
};
use
rustc
::
mir
::{
Mir
,
Location
,
Rvalue
,
BasicBlock
,
Statement
,
StatementKind
};
use
rustc
::
mir
::
visit
::{
MutVisitor
,
Lookup
};
use
rustc
::
mir
::
visit
::{
MutVisitor
,
TyContext
};
use
rustc
::
infer
::{
self
as
rustc_infer
,
InferCtxt
};
use
syntax_pos
::
DUMMY_SP
;
use
std
::
collections
::
HashMap
;
...
...
@@ -29,7 +29,7 @@ pub fn renumber_mir<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
}
struct
NLLVisitor
<
'a
,
'gcx
:
'a
+
'tcx
,
'tcx
:
'a
>
{
lookup_map
:
HashMap
<
RegionVid
,
Lookup
>
,
lookup_map
:
HashMap
<
RegionVid
,
TyContext
>
,
num_region_variables
:
usize
,
infcx
:
&
'a
InferCtxt
<
'a
,
'gcx
,
'tcx
>
,
}
...
...
@@ -50,39 +50,39 @@ fn renumber_regions<T>(&mut self, value: &T) -> T where T: TypeFoldable<'tcx> {
})
}
fn
store_region
(
&
mut
self
,
region
:
&
RegionKind
,
lookup
:
Lookup
)
{
fn
store_region
(
&
mut
self
,
region
:
&
RegionKind
,
lookup
:
TyContext
)
{
if
let
RegionKind
::
ReVar
(
rid
)
=
*
region
{
self
.lookup_map
.entry
(
rid
)
.or_insert
(
lookup
);
}
}
fn
store_ty_regions
(
&
mut
self
,
ty
:
&
Ty
<
'tcx
>
,
lookup
:
Lookup
)
{
fn
store_ty_regions
(
&
mut
self
,
ty
:
&
Ty
<
'tcx
>
,
ty_context
:
TyContext
)
{
for
region
in
ty
.regions
()
{
self
.store_region
(
region
,
lookup
);
self
.store_region
(
region
,
ty_context
);
}
}
fn
store_kind_regions
(
&
mut
self
,
kind
:
&
'tcx
Kind
,
lookup
:
Lookup
)
{
fn
store_kind_regions
(
&
mut
self
,
kind
:
&
'tcx
Kind
,
ty_context
:
TyContext
)
{
if
let
Some
(
ty
)
=
kind
.as_type
()
{
self
.store_ty_regions
(
&
ty
,
lookup
);
self
.store_ty_regions
(
&
ty
,
ty_context
);
}
else
if
let
Some
(
region
)
=
kind
.as_region
()
{
self
.store_region
(
region
,
lookup
);
self
.store_region
(
region
,
ty_context
);
}
}
}
impl
<
'a
,
'gcx
,
'tcx
>
MutVisitor
<
'tcx
>
for
NLLVisitor
<
'a
,
'gcx
,
'tcx
>
{
fn
visit_ty
(
&
mut
self
,
ty
:
&
mut
Ty
<
'tcx
>
,
lookup
:
Lookup
)
{
fn
visit_ty
(
&
mut
self
,
ty
:
&
mut
Ty
<
'tcx
>
,
ty_context
:
TyContext
)
{
let
old_ty
=
*
ty
;
*
ty
=
self
.renumber_regions
(
&
old_ty
);
self
.store_ty_regions
(
ty
,
lookup
);
self
.store_ty_regions
(
ty
,
ty_context
);
}
fn
visit_substs
(
&
mut
self
,
substs
:
&
mut
&
'tcx
Substs
<
'tcx
>
,
location
:
Location
)
{
*
substs
=
self
.renumber_regions
(
&
{
*
substs
});
let
lookup
=
Lookup
::
Loc
(
location
);
let
ty_context
=
TyContext
::
Location
(
location
);
for
kind
in
*
substs
{
self
.store_kind_regions
(
kind
,
lookup
);
self
.store_kind_regions
(
kind
,
ty_context
);
}
}
...
...
@@ -91,8 +91,8 @@ fn visit_rvalue(&mut self, rvalue: &mut Rvalue<'tcx>, location: Location) {
Rvalue
::
Ref
(
ref
mut
r
,
_
,
_
)
=>
{
let
old_r
=
*
r
;
*
r
=
self
.renumber_regions
(
&
old_r
);
let
lookup
=
Lookup
::
Loc
(
location
);
self
.store_region
(
r
,
lookup
);
let
ty_context
=
TyContext
::
Location
(
location
);
self
.store_region
(
r
,
ty_context
);
}
Rvalue
::
Use
(
..
)
|
Rvalue
::
Repeat
(
..
)
|
...
...
@@ -114,9 +114,9 @@ fn visit_closure_substs(&mut self,
substs
:
&
mut
ClosureSubsts
<
'tcx
>
,
location
:
Location
)
{
*
substs
=
self
.renumber_regions
(
substs
);
let
lookup
=
Lookup
::
Loc
(
location
);
let
ty_context
=
TyContext
::
Location
(
location
);
for
kind
in
substs
.substs
{
self
.store_kind_regions
(
kind
,
lookup
);
self
.store_kind_regions
(
kind
,
ty_context
);
}
}
...
...
src/librustc_mir/transform/type_check.rs
浏览文件 @
81f6ce5c
...
...
@@ -92,8 +92,8 @@ fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) {
self
.sanitize_type
(
rvalue
,
rval_ty
);
}
fn
visit_local_decl
(
&
mut
self
,
local_decl
:
&
LocalDecl
<
'tcx
>
)
{
self
.super_local_decl
(
local_decl
);
fn
visit_local_decl
(
&
mut
self
,
local
:
Local
,
local
_decl
:
&
LocalDecl
<
'tcx
>
)
{
self
.super_local_decl
(
local
,
local
_decl
);
self
.sanitize_type
(
local_decl
,
local_decl
.ty
);
}
...
...
src/librustc_passes/mir_stats.rs
浏览文件 @
81f6ce5c
...
...
@@ -14,7 +14,7 @@
use
rustc_const_math
::{
ConstUsize
};
use
rustc
::
mir
::{
AggregateKind
,
AssertMessage
,
BasicBlock
,
BasicBlockData
};
use
rustc
::
mir
::{
Constant
,
Literal
,
Location
,
LocalDecl
};
use
rustc
::
mir
::{
Constant
,
Literal
,
Location
,
Local
,
Local
Decl
};
use
rustc
::
mir
::{
Lvalue
,
LvalueElem
,
LvalueProjection
};
use
rustc
::
mir
::{
Mir
,
Operand
,
ProjectionElem
};
use
rustc
::
mir
::{
Rvalue
,
SourceInfo
,
Statement
,
StatementKind
};
...
...
@@ -269,9 +269,10 @@ fn visit_const_usize(&mut self,
}
fn
visit_local_decl
(
&
mut
self
,
local
:
Local
,
local_decl
:
&
LocalDecl
<
'tcx
>
)
{
self
.record
(
"LocalDecl"
,
local_decl
);
self
.super_local_decl
(
local_decl
);
self
.super_local_decl
(
local
,
local
_decl
);
}
fn
visit_visibility_scope
(
&
mut
self
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录