Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
d42a7d02
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,发现更多精彩内容 >>
提交
d42a7d02
编写于
11月 11, 2016
作者:
O
Oliver 'ker' Schneider
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix null optimizations for smaller than pointer enums
fixes #76
上级
1c40fb0d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
32 addition
and
17 deletion
+32
-17
src/interpreter/mod.rs
src/interpreter/mod.rs
+9
-11
src/interpreter/terminator/mod.rs
src/interpreter/terminator/mod.rs
+9
-6
tests/run-pass/small_enum_size_bug.rs
tests/run-pass/small_enum_size_bug.rs
+14
-0
未找到文件。
src/interpreter/mod.rs
浏览文件 @
d42a7d02
...
...
@@ -203,10 +203,6 @@ fn usize_primval(&self, n: u64) -> PrimVal {
PrimVal
::
from_uint_with_size
(
n
,
self
.memory
.pointer_size
())
}
fn
isize_primval
(
&
self
,
n
:
i64
)
->
PrimVal
{
PrimVal
::
from_int_with_size
(
n
,
self
.memory
.pointer_size
())
}
fn
str_to_value
(
&
mut
self
,
s
:
&
str
)
->
EvalResult
<
'tcx
,
Value
>
{
// FIXME: cache these allocs
let
ptr
=
self
.memory
.allocate
(
s
.len
(),
1
)
?
;
...
...
@@ -523,7 +519,8 @@ fn eval_rvalue_into_lvalue(
self
.write_value
(
value
,
dest
,
value_ty
)
?
;
}
else
{
assert_eq!
(
operands
.len
(),
0
);
let
zero
=
self
.isize_primval
(
0
);
let
value_size
=
self
.type_size
(
dest_ty
)
.expect
(
"pointer types are sized"
);
let
zero
=
PrimVal
::
from_int_with_size
(
0
,
value_size
);
self
.write_primval
(
dest
,
zero
)
?
;
}
}
else
{
...
...
@@ -541,13 +538,14 @@ fn eval_rvalue_into_lvalue(
let
operand_ty
=
self
.operand_ty
(
operand
);
assert_eq!
(
self
.type_size
(
operand_ty
),
Some
(
0
));
}
let
offset
=
self
.nonnull_offset
(
dest_ty
,
nndiscr
,
discrfield
)
?
;
let
(
offset
,
ty
)
=
self
.nonnull_offset_and_ty
(
dest_ty
,
nndiscr
,
discrfield
)
?
;
// FIXME(solson)
let
dest
=
self
.force_allocation
(
dest
)
?
.to_ptr
();
let
dest
=
dest
.offset
(
offset
.bytes
()
as
isize
);
try!
(
self
.memory
.write_isize
(
dest
,
0
));
let
dest_size
=
self
.type_size
(
ty
)
.unwrap_or
(
self
.memory
.pointer_size
());
try!
(
self
.memory
.write_int
(
dest
,
0
,
dest_size
));
}
}
else
{
bug!
(
"tried to assign {:?} to Layout::RawNullablePointer"
,
kind
);
...
...
@@ -694,7 +692,7 @@ fn type_is_fat_ptr(&self, ty: Ty<'tcx>) -> bool {
}
}
fn
nonnull_offset
(
&
self
,
ty
:
Ty
<
'tcx
>
,
nndiscr
:
u64
,
discrfield
:
&
[
u32
])
->
EvalResult
<
'tcx
,
Size
>
{
fn
nonnull_offset
_and_ty
(
&
self
,
ty
:
Ty
<
'tcx
>
,
nndiscr
:
u64
,
discrfield
:
&
[
u32
])
->
EvalResult
<
'tcx
,
(
Size
,
Ty
<
'tcx
>
)
>
{
// Skip the constant 0 at the start meant for LLVM GEP.
let
mut
path
=
discrfield
.iter
()
.skip
(
1
)
.map
(|
&
i
|
i
as
usize
);
...
...
@@ -709,10 +707,10 @@ fn nonnull_offset(&self, ty: Ty<'tcx>, nndiscr: u64, discrfield: &[u32]) -> Eval
_
=>
bug!
(
"non-enum for StructWrappedNullablePointer: {}"
,
ty
),
};
self
.field_path_offset
(
inner_ty
,
path
)
self
.field_path_offset
_and_ty
(
inner_ty
,
path
)
}
fn
field_path_offset
<
I
:
Iterator
<
Item
=
usize
>>
(
&
self
,
mut
ty
:
Ty
<
'tcx
>
,
path
:
I
)
->
EvalResult
<
'tcx
,
Size
>
{
fn
field_path_offset
_and_ty
<
I
:
Iterator
<
Item
=
usize
>>
(
&
self
,
mut
ty
:
Ty
<
'tcx
>
,
path
:
I
)
->
EvalResult
<
'tcx
,
(
Size
,
Ty
<
'tcx
>
)
>
{
let
mut
offset
=
Size
::
from_bytes
(
0
);
// Skip the initial 0 intended for LLVM GEP.
...
...
@@ -722,7 +720,7 @@ fn field_path_offset<I: Iterator<Item = usize>>(&self, mut ty: Ty<'tcx>, path: I
offset
=
offset
.checked_add
(
field_offset
,
&
self
.tcx.data_layout
)
.unwrap
();
}
Ok
(
offset
)
Ok
(
(
offset
,
ty
)
)
}
fn
get_field_ty
(
&
self
,
ty
:
Ty
<
'tcx
>
,
field_index
:
usize
)
->
EvalResult
<
'tcx
,
Ty
<
'tcx
>>
{
...
...
src/interpreter/terminator/mod.rs
浏览文件 @
d42a7d02
...
...
@@ -263,14 +263,17 @@ fn read_discriminant_value(&self, adt_ptr: Pointer, adt_ty: Ty<'tcx>) -> EvalRes
self
.memory
.read_int
(
adt_ptr
,
discr_size
as
usize
)
?
as
u64
}
RawNullablePointer
{
nndiscr
,
..
}
=>
{
self
.read_nonnull_discriminant_value
(
adt_ptr
,
nndiscr
)
?
RawNullablePointer
{
nndiscr
,
value
}
=>
{
let
discr_size
=
value
.size
(
&
self
.tcx.data_layout
)
.bytes
()
as
usize
;
self
.read_nonnull_discriminant_value
(
adt_ptr
,
nndiscr
,
discr_size
)
?
}
StructWrappedNullablePointer
{
nndiscr
,
ref
discrfield
,
..
}
=>
{
let
offset
=
self
.nonnull_offset
(
adt_ty
,
nndiscr
,
discrfield
)
?
;
let
(
offset
,
ty
)
=
self
.nonnull_offset_and_ty
(
adt_ty
,
nndiscr
,
discrfield
)
?
;
let
nonnull
=
adt_ptr
.offset
(
offset
.bytes
()
as
isize
);
self
.read_nonnull_discriminant_value
(
nonnull
,
nndiscr
)
?
// only the pointer part of a fat pointer is used for this space optimization
let
discr_size
=
self
.type_size
(
ty
)
.unwrap_or
(
self
.memory
.pointer_size
());
self
.read_nonnull_discriminant_value
(
nonnull
,
nndiscr
,
discr_size
)
?
}
// The discriminant_value intrinsic returns 0 for non-sum types.
...
...
@@ -281,8 +284,8 @@ fn read_discriminant_value(&self, adt_ptr: Pointer, adt_ty: Ty<'tcx>) -> EvalRes
Ok
(
discr_val
)
}
fn
read_nonnull_discriminant_value
(
&
self
,
ptr
:
Pointer
,
nndiscr
:
u64
)
->
EvalResult
<
'tcx
,
u64
>
{
let
not_null
=
match
self
.memory
.read_u
size
(
ptr
)
{
fn
read_nonnull_discriminant_value
(
&
self
,
ptr
:
Pointer
,
nndiscr
:
u64
,
discr_size
:
usize
)
->
EvalResult
<
'tcx
,
u64
>
{
let
not_null
=
match
self
.memory
.read_u
int
(
ptr
,
discr_size
)
{
Ok
(
0
)
=>
false
,
Ok
(
_
)
|
Err
(
EvalError
::
ReadPointerAsBytes
)
=>
true
,
Err
(
e
)
=>
return
Err
(
e
),
...
...
tests/run-pass/small_enum_size_bug.rs
0 → 100644
浏览文件 @
d42a7d02
#![allow(dead_code)]
enum
E
{
A
=
1
,
B
=
2
,
C
=
3
,
}
fn
main
()
{
let
enone
=
None
::
<
E
>
;
if
let
Some
(
..
)
=
enone
{
panic!
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录