Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
54c81ac9
R
Rust
项目概览
int
/
Rust
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
54c81ac9
编写于
8月 20, 2018
作者:
R
Ralf Jung
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
in a Use statement, exploit the fact that type and hence layout are the same for LHS and RHS
上级
8ad40479
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
44 addition
and
15 deletion
+44
-15
src/librustc_mir/interpret/operand.rs
src/librustc_mir/interpret/operand.rs
+37
-9
src/librustc_mir/interpret/step.rs
src/librustc_mir/interpret/step.rs
+5
-4
src/librustc_mir/interpret/terminator/mod.rs
src/librustc_mir/interpret/terminator/mod.rs
+2
-2
未找到文件。
src/librustc_mir/interpret/operand.rs
浏览文件 @
54c81ac9
...
...
@@ -189,6 +189,22 @@ pub fn from_scalar_value(val: Scalar, layout: TyLayout<'tcx>) -> Self {
}
}
// Use the existing layout if given (but sanity check in debug mode),
// or compute the layout.
#[inline(always)]
fn
from_known_layout
<
'tcx
>
(
layout
:
Option
<
TyLayout
<
'tcx
>>
,
compute
:
impl
FnOnce
()
->
EvalResult
<
'tcx
,
TyLayout
<
'tcx
>>
)
->
EvalResult
<
'tcx
,
TyLayout
<
'tcx
>>
{
match
layout
{
None
=>
compute
(),
Some
(
layout
)
=>
{
debug_assert_eq!
(
layout
.ty
,
compute
()
?
.ty
);
Ok
(
layout
)
}
}
}
impl
<
'a
,
'mir
,
'tcx
,
M
:
Machine
<
'mir
,
'tcx
>>
EvalContext
<
'a
,
'mir
,
'tcx
,
M
>
{
/// Try reading a value in memory; this is interesting particularily for ScalarPair.
/// Return None if the layout does not permit loading this as a value.
...
...
@@ -377,21 +393,25 @@ pub fn operand_projection(
}
// Evaluate a place with the goal of reading from it. This lets us sometimes
// avoid allocations.
// avoid allocations. If you already know the layout, you can pass it in
// to avoid looking it up again.
fn
eval_place_to_op
(
&
mut
self
,
mir_place
:
&
mir
::
Place
<
'tcx
>
,
layout
:
Option
<
TyLayout
<
'tcx
>>
,
)
->
EvalResult
<
'tcx
,
OpTy
<
'tcx
>>
{
use
rustc
::
mir
::
Place
::
*
;
Ok
(
match
*
mir_place
{
Local
(
mir
::
RETURN_PLACE
)
=>
return
err!
(
ReadFromReturnPointer
),
Local
(
local
)
=>
{
let
op
=
*
self
.frame
()
.locals
[
local
]
.access
()
?
;
OpTy
{
op
,
layout
:
self
.layout_of_local
(
self
.cur_frame
(),
local
)
?
}
let
layout
=
from_known_layout
(
layout
,
||
self
.layout_of_local
(
self
.cur_frame
(),
local
))
?
;
OpTy
{
op
,
layout
}
},
Projection
(
ref
proj
)
=>
{
let
op
=
self
.eval_place_to_op
(
&
proj
.base
)
?
;
let
op
=
self
.eval_place_to_op
(
&
proj
.base
,
None
)
?
;
self
.operand_projection
(
op
,
&
proj
.elem
)
?
}
...
...
@@ -406,17 +426,25 @@ fn eval_place_to_op(
}
/// Evaluate the operand, returning a place where you can then find the data.
pub
fn
eval_operand
(
&
mut
self
,
mir_op
:
&
mir
::
Operand
<
'tcx
>
)
->
EvalResult
<
'tcx
,
OpTy
<
'tcx
>>
{
/// if you already know the layout, you can save two some table lookups
/// by passing it in here.
pub
fn
eval_operand
(
&
mut
self
,
mir_op
:
&
mir
::
Operand
<
'tcx
>
,
layout
:
Option
<
TyLayout
<
'tcx
>>
,
)
->
EvalResult
<
'tcx
,
OpTy
<
'tcx
>>
{
use
rustc
::
mir
::
Operand
::
*
;
let
op
=
match
*
mir_op
{
// FIXME: do some more logic on `move` to invalidate the old location
Copy
(
ref
place
)
|
Move
(
ref
place
)
=>
self
.eval_place_to_op
(
place
)
?
,
self
.eval_place_to_op
(
place
,
layout
)
?
,
Constant
(
ref
constant
)
=>
{
let
ty
=
self
.monomorphize
(
mir_op
.ty
(
self
.mir
(),
*
self
.tcx
),
self
.substs
());
let
layout
=
self
.layout_of
(
ty
)
?
;
let
layout
=
from_known_layout
(
layout
,
||
{
let
ty
=
self
.monomorphize
(
mir_op
.ty
(
self
.mir
(),
*
self
.tcx
),
self
.substs
());
self
.layout_of
(
ty
)
})
?
;
let
op
=
self
.const_value_to_op
(
constant
.literal.val
)
?
;
OpTy
{
op
,
layout
}
}
...
...
@@ -431,7 +459,7 @@ pub(crate) fn eval_operands(
ops
:
&
[
mir
::
Operand
<
'tcx
>
],
)
->
EvalResult
<
'tcx
,
Vec
<
OpTy
<
'tcx
>>>
{
ops
.into_iter
()
.map
(|
op
|
self
.eval_operand
(
op
))
.map
(|
op
|
self
.eval_operand
(
op
,
None
))
.collect
()
}
...
...
@@ -473,7 +501,7 @@ pub fn eval_operand_and_read_valty(
&
mut
self
,
op
:
&
mir
::
Operand
<
'tcx
>
,
)
->
EvalResult
<
'tcx
,
ValTy
<
'tcx
>>
{
let
op
=
self
.eval_operand
(
op
)
?
;
let
op
=
self
.eval_operand
(
op
,
None
)
?
;
self
.read_value
(
op
)
}
pub
fn
eval_operand_and_read_scalar
(
...
...
src/librustc_mir/interpret/step.rs
浏览文件 @
54c81ac9
...
...
@@ -141,7 +141,8 @@ fn eval_rvalue_into_place(
use
rustc
::
mir
::
Rvalue
::
*
;
match
*
rvalue
{
Use
(
ref
operand
)
=>
{
let
op
=
self
.eval_operand
(
operand
)
?
;
// Avoid recomputing the layout
let
op
=
self
.eval_operand
(
operand
,
Some
(
dest
.layout
))
?
;
self
.copy_op
(
op
,
dest
)
?
;
}
...
...
@@ -187,7 +188,7 @@ fn eval_rvalue_into_place(
};
for
(
i
,
operand
)
in
operands
.iter
()
.enumerate
()
{
let
op
=
self
.eval_operand
(
operand
)
?
;
let
op
=
self
.eval_operand
(
operand
,
None
)
?
;
// Ignore zero-sized fields.
if
!
op
.layout
.is_zst
()
{
let
field_index
=
active_field_index
.unwrap_or
(
i
);
...
...
@@ -198,7 +199,7 @@ fn eval_rvalue_into_place(
}
Repeat
(
ref
operand
,
_
)
=>
{
let
op
=
self
.eval_operand
(
operand
)
?
;
let
op
=
self
.eval_operand
(
operand
,
None
)
?
;
let
dest
=
self
.force_allocation
(
dest
)
?
;
let
length
=
dest
.len
();
...
...
@@ -260,7 +261,7 @@ fn eval_rvalue_into_place(
Cast
(
kind
,
ref
operand
,
cast_ty
)
=>
{
debug_assert_eq!
(
self
.monomorphize
(
cast_ty
,
self
.substs
()),
dest
.layout.ty
);
let
src
=
self
.eval_operand
(
operand
)
?
;
let
src
=
self
.eval_operand
(
operand
,
None
)
?
;
self
.cast
(
src
,
kind
,
dest
)
?
;
}
...
...
src/librustc_mir/interpret/terminator/mod.rs
浏览文件 @
54c81ac9
...
...
@@ -36,7 +36,7 @@ pub(super) fn eval_terminator(
ref
targets
,
..
}
=>
{
let
discr_val
=
self
.eval_operand
(
discr
)
?
;
let
discr_val
=
self
.eval_operand
(
discr
,
None
)
?
;
let
discr
=
self
.read_value
(
discr_val
)
?
;
trace!
(
"SwitchInt({:?})"
,
*
discr
);
...
...
@@ -70,7 +70,7 @@ pub(super) fn eval_terminator(
None
=>
None
,
};
let
func
=
self
.eval_operand
(
func
)
?
;
let
func
=
self
.eval_operand
(
func
,
None
)
?
;
let
(
fn_def
,
sig
)
=
match
func
.layout.ty.sty
{
ty
::
TyFnPtr
(
sig
)
=>
{
let
fn_ptr
=
self
.read_scalar
(
func
)
?
.to_ptr
()
?
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录