Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
2ec959fc
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,发现更多精彩内容 >>
提交
2ec959fc
编写于
11月 22, 2017
作者:
N
Niko Matsakis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
extend MIR dump with detailed, extra information
上级
e5dc4ba2
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
104 addition
and
24 deletion
+104
-24
src/librustc_mir/util/pretty.rs
src/librustc_mir/util/pretty.rs
+96
-21
src/tools/compiletest/src/runtest.rs
src/tools/compiletest/src/runtest.rs
+8
-3
未找到文件。
src/librustc_mir/util/pretty.rs
浏览文件 @
2ec959fc
...
@@ -11,7 +11,8 @@
...
@@ -11,7 +11,8 @@
use
rustc
::
hir
;
use
rustc
::
hir
;
use
rustc
::
hir
::
def_id
::{
DefId
,
LOCAL_CRATE
};
use
rustc
::
hir
::
def_id
::{
DefId
,
LOCAL_CRATE
};
use
rustc
::
mir
::
*
;
use
rustc
::
mir
::
*
;
use
rustc
::
ty
::
TyCtxt
;
use
rustc
::
mir
::
visit
::
Visitor
;
use
rustc
::
ty
::{
self
,
TyCtxt
};
use
rustc
::
ty
::
item_path
;
use
rustc
::
ty
::
item_path
;
use
rustc_data_structures
::
fx
::
FxHashMap
;
use
rustc_data_structures
::
fx
::
FxHashMap
;
use
rustc_data_structures
::
indexed_vec
::
Idx
;
use
rustc_data_structures
::
indexed_vec
::
Idx
;
...
@@ -125,14 +126,7 @@ fn dump_matched_mir_node<'a, 'gcx, 'tcx, F>(
...
@@ -125,14 +126,7 @@ fn dump_matched_mir_node<'a, 'gcx, 'tcx, F>(
F
:
FnMut
(
PassWhere
,
&
mut
Write
)
->
io
::
Result
<
()
>
,
F
:
FnMut
(
PassWhere
,
&
mut
Write
)
->
io
::
Result
<
()
>
,
{
{
let
_
:
io
::
Result
<
()
>
=
do
catch
{
let
_
:
io
::
Result
<
()
>
=
do
catch
{
let
mut
file
=
create_dump_file
(
let
mut
file
=
create_dump_file
(
tcx
,
"mir"
,
pass_num
,
pass_name
,
disambiguator
,
source
)
?
;
tcx
,
"mir"
,
pass_num
,
pass_name
,
disambiguator
,
source
,
)
?
;
writeln!
(
file
,
"// MIR for `{}`"
,
node_path
)
?
;
writeln!
(
file
,
"// MIR for `{}`"
,
node_path
)
?
;
writeln!
(
file
,
"// source = {:?}"
,
source
)
?
;
writeln!
(
file
,
"// source = {:?}"
,
source
)
?
;
writeln!
(
file
,
"// pass_name = {}"
,
pass_name
)
?
;
writeln!
(
file
,
"// pass_name = {}"
,
pass_name
)
?
;
...
@@ -148,15 +142,9 @@ fn dump_matched_mir_node<'a, 'gcx, 'tcx, F>(
...
@@ -148,15 +142,9 @@ fn dump_matched_mir_node<'a, 'gcx, 'tcx, F>(
};
};
if
tcx
.sess.opts.debugging_opts.dump_mir_graphviz
{
if
tcx
.sess.opts.debugging_opts.dump_mir_graphviz
{
let
_
:
io
::
Result
<
()
>
=
do
catch
{
let
_
:
io
::
Result
<
()
>
=
do
catch
{
let
mut
file
=
create_dump_file
(
let
mut
file
=
tcx
,
create_dump_file
(
tcx
,
"dot"
,
pass_num
,
pass_name
,
disambiguator
,
source
)
?
;
"dot"
,
pass_num
,
pass_name
,
disambiguator
,
source
,
)
?
;
write_mir_fn_graphviz
(
tcx
,
source
.def_id
,
mir
,
&
mut
file
)
?
;
write_mir_fn_graphviz
(
tcx
,
source
.def_id
,
mir
,
&
mut
file
)
?
;
Ok
(())
Ok
(())
};
};
...
@@ -297,10 +285,10 @@ pub fn write_mir_fn<'a, 'gcx, 'tcx, F>(
...
@@ -297,10 +285,10 @@ pub fn write_mir_fn<'a, 'gcx, 'tcx, F>(
}
}
/// Write out a human-readable textual representation for the given basic block.
/// Write out a human-readable textual representation for the given basic block.
pub
fn
write_basic_block
<
F
>
(
pub
fn
write_basic_block
<
'cx
,
'gcx
,
'tcx
,
F
>
(
tcx
:
TyCtxt
,
tcx
:
TyCtxt
<
'cx
,
'gcx
,
'tcx
>
,
block
:
BasicBlock
,
block
:
BasicBlock
,
mir
:
&
Mir
,
mir
:
&
Mir
<
'tcx
>
,
extra_data
:
&
mut
F
,
extra_data
:
&
mut
F
,
w
:
&
mut
Write
,
w
:
&
mut
Write
,
)
->
io
::
Result
<
()
>
)
->
io
::
Result
<
()
>
...
@@ -330,6 +318,11 @@ pub fn write_basic_block<F>(
...
@@ -330,6 +318,11 @@ pub fn write_basic_block<F>(
comment
(
tcx
,
statement
.source_info
),
comment
(
tcx
,
statement
.source_info
),
A
=
ALIGN
,
A
=
ALIGN
,
)
?
;
)
?
;
write_extra
(
tcx
,
w
,
|
visitor
|
{
visitor
.visit_statement
(
current_location
.block
,
statement
,
current_location
);
})
?
;
extra_data
(
PassWhere
::
AfterLocation
(
current_location
),
w
)
?
;
extra_data
(
PassWhere
::
AfterLocation
(
current_location
),
w
)
?
;
current_location
.statement_index
+=
1
;
current_location
.statement_index
+=
1
;
...
@@ -346,11 +339,93 @@ pub fn write_basic_block<F>(
...
@@ -346,11 +339,93 @@ pub fn write_basic_block<F>(
comment
(
tcx
,
data
.terminator
()
.source_info
),
comment
(
tcx
,
data
.terminator
()
.source_info
),
A
=
ALIGN
,
A
=
ALIGN
,
)
?
;
)
?
;
write_extra
(
tcx
,
w
,
|
visitor
|
{
visitor
.visit_terminator
(
current_location
.block
,
data
.terminator
(),
current_location
);
})
?
;
extra_data
(
PassWhere
::
AfterLocation
(
current_location
),
w
)
?
;
extra_data
(
PassWhere
::
AfterLocation
(
current_location
),
w
)
?
;
writeln!
(
w
,
"{}}}"
,
INDENT
)
writeln!
(
w
,
"{}}}"
,
INDENT
)
}
}
/// After we print the main statement, we sometimes dump extra
/// information. There's often a lot of little things "nuzzled up" in
/// a statement.
fn
write_extra
<
'cx
,
'gcx
,
'tcx
,
F
>
(
tcx
:
TyCtxt
<
'cx
,
'gcx
,
'tcx
>
,
write
:
&
mut
Write
,
mut
visit_op
:
F
,
)
->
io
::
Result
<
()
>
where
F
:
FnMut
(
&
mut
ExtraComments
<
'cx
,
'gcx
,
'tcx
>
)
{
let
mut
extra_comments
=
ExtraComments
{
_
tcx
:
tcx
,
comments
:
vec!
[],
};
visit_op
(
&
mut
extra_comments
);
for
comment
in
extra_comments
.comments
{
writeln!
(
write
,
"{:A$} // {}"
,
""
,
comment
,
A
=
ALIGN
)
?
;
}
Ok
(())
}
struct
ExtraComments
<
'cx
,
'gcx
:
'tcx
,
'tcx
:
'cx
>
{
_
tcx
:
TyCtxt
<
'cx
,
'gcx
,
'tcx
>
,
// don't need it now, but bet we will soon
comments
:
Vec
<
String
>
,
}
impl
<
'cx
,
'gcx
,
'tcx
>
ExtraComments
<
'cx
,
'gcx
,
'tcx
>
{
fn
push
(
&
mut
self
,
lines
:
&
str
)
{
for
line
in
lines
.split
(
"
\n
"
)
{
self
.comments
.push
(
line
.to_string
());
}
}
}
impl
<
'cx
,
'gcx
,
'tcx
>
Visitor
<
'tcx
>
for
ExtraComments
<
'cx
,
'gcx
,
'tcx
>
{
fn
visit_constant
(
&
mut
self
,
constant
:
&
Constant
<
'tcx
>
,
location
:
Location
)
{
self
.super_constant
(
constant
,
location
);
let
Constant
{
span
,
ty
,
literal
}
=
constant
;
self
.push
(
&
format!
(
"mir::Constant"
));
self
.push
(
&
format!
(
"└ span: {:?}"
,
span
));
self
.push
(
&
format!
(
"└ ty: {:?}"
,
ty
));
self
.push
(
&
format!
(
"└ literal: {:?}"
,
literal
));
}
fn
visit_const
(
&
mut
self
,
constant
:
&&
'tcx
ty
::
Const
<
'tcx
>
,
_
:
Location
)
{
self
.super_const
(
constant
);
let
ty
::
Const
{
ty
,
val
}
=
constant
;
self
.push
(
&
format!
(
"ty::Const"
));
self
.push
(
&
format!
(
"└ ty: {:?}"
,
ty
));
self
.push
(
&
format!
(
"└ val: {:?}"
,
val
));
}
fn
visit_rvalue
(
&
mut
self
,
rvalue
:
&
Rvalue
<
'tcx
>
,
location
:
Location
)
{
self
.super_rvalue
(
rvalue
,
location
);
match
rvalue
{
Rvalue
::
Aggregate
(
kind
,
_
)
=>
match
**
kind
{
AggregateKind
::
Closure
(
def_id
,
substs
)
=>
{
self
.push
(
&
format!
(
"closure"
));
self
.push
(
&
format!
(
"└ def_id: {:?}"
,
def_id
));
self
.push
(
&
format!
(
"└ substs: {:#?}"
,
substs
));
}
AggregateKind
::
Generator
(
def_id
,
substs
,
interior
)
=>
{
self
.push
(
&
format!
(
"generator"
));
self
.push
(
&
format!
(
"└ def_id: {:?}"
,
def_id
));
self
.push
(
&
format!
(
"└ substs: {:#?}"
,
substs
));
self
.push
(
&
format!
(
"└ interior: {:?}"
,
interior
));
}
_
=>
{}
},
_
=>
{}
}
}
}
fn
comment
(
tcx
:
TyCtxt
,
SourceInfo
{
span
,
scope
}:
SourceInfo
)
->
String
{
fn
comment
(
tcx
:
TyCtxt
,
SourceInfo
{
span
,
scope
}:
SourceInfo
)
->
String
{
format!
(
format!
(
"scope {} at {}"
,
"scope {} at {}"
,
...
...
src/tools/compiletest/src/runtest.rs
浏览文件 @
2ec959fc
...
@@ -2535,7 +2535,10 @@ fn compare_mir_test_output(&self, test_name: &str, expected_content: &[ExpectedL
...
@@ -2535,7 +2535,10 @@ fn compare_mir_test_output(&self, test_name: &str, expected_content: &[ExpectedL
let
mut
dumped_file
=
fs
::
File
::
open
(
output_file
.clone
())
.unwrap
();
let
mut
dumped_file
=
fs
::
File
::
open
(
output_file
.clone
())
.unwrap
();
let
mut
dumped_string
=
String
::
new
();
let
mut
dumped_string
=
String
::
new
();
dumped_file
.read_to_string
(
&
mut
dumped_string
)
.unwrap
();
dumped_file
.read_to_string
(
&
mut
dumped_string
)
.unwrap
();
let
mut
dumped_lines
=
dumped_string
.lines
()
.filter
(|
l
|
!
l
.is_empty
());
let
mut
dumped_lines
=
dumped_string
.lines
()
.map
(|
l
|
nocomment_mir_line
(
l
))
.filter
(|
l
|
!
l
.is_empty
());
let
mut
expected_lines
=
expected_content
let
mut
expected_lines
=
expected_content
.iter
()
.iter
()
.filter
(|
&
l
|
{
.filter
(|
&
l
|
{
...
@@ -2573,7 +2576,7 @@ fn compare_mir_test_output(&self, test_name: &str, expected_content: &[ExpectedL
...
@@ -2573,7 +2576,7 @@ fn compare_mir_test_output(&self, test_name: &str, expected_content: &[ExpectedL
.join
(
"
\n
"
);
.join
(
"
\n
"
);
panic!
(
panic!
(
"Did not find expected line, error: {}
\n
\
"Did not find expected line, error: {}
\n
\
Actual
Line: {:?}
\n
\
Expected
Line: {:?}
\n
\
Expected:
\n
{}
\n
\
Expected:
\n
{}
\n
\
Actual:
\n
{}"
,
Actual:
\n
{}"
,
extra_msg
,
extra_msg
,
...
@@ -2599,7 +2602,9 @@ fn compare_mir_test_output(&self, test_name: &str, expected_content: &[ExpectedL
...
@@ -2599,7 +2602,9 @@ fn compare_mir_test_output(&self, test_name: &str, expected_content: &[ExpectedL
error
(
error
(
expected_line
,
expected_line
,
format!
(
format!
(
"Mismatch in lines
\n
Currnt block: {}
\n
Expected Line: {:?}"
,
"Mismatch in lines
\n
\
Current block: {}
\n
\
Actual Line: {:?}"
,
start_block_line
.unwrap_or
(
"None"
),
start_block_line
.unwrap_or
(
"None"
),
dumped_line
dumped_line
),
),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录