Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
026214c8
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,发现更多精彩内容 >>
提交
026214c8
编写于
9月 21, 2017
作者:
E
Eduard-Mihai Burtescu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rustc: collapse Layout::FatPointer into Layout::Univariant.
上级
3fd6b000
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
47 addition
and
42 deletion
+47
-42
src/librustc/ty/layout.rs
src/librustc/ty/layout.rs
+47
-42
未找到文件。
src/librustc/ty/layout.rs
浏览文件 @
026214c8
...
...
@@ -849,9 +849,6 @@ pub enum Layout {
/// TyArray, TySlice or TyStr.
Array
,
/// TyRawPtr or TyRef with a !Sized pointee. The primitive is the metadata.
FatPointer
,
// Remaining variants are all ADTs such as structs, enums or tuples.
/// Single-case enums, and structs/tuples.
...
...
@@ -1132,7 +1129,7 @@ enum StructKind {
memory_index
:
vec!
[
0
,
1
]
};
Ok
(
tcx
.intern_layout
(
CachedLayout
{
layout
:
Layout
::
FatPointer
,
layout
:
Layout
::
Univariant
,
fields
,
abi
:
Abi
::
Aggregate
{
sized
:
true
,
...
...
@@ -1743,8 +1740,7 @@ fn record_layout_for_printing_outlined(tcx: TyCtxt<'a, 'tcx, 'tcx>,
// via representation tweaks) size info beyond total size.
Layout
::
Scalar
|
Layout
::
Vector
|
Layout
::
Array
|
Layout
::
FatPointer
{
..
}
=>
{
Layout
::
Array
=>
{
debug!
(
"print-type-size t: `{:?}` adt other"
,
ty
);
record
(
adt_kind
.into
(),
None
,
Vec
::
new
())
}
...
...
@@ -2047,9 +2043,23 @@ pub fn for_variant(&self, variant_index: usize) -> Self {
fn
field_type_unnormalized
(
&
self
,
tcx
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
,
i
:
usize
)
->
Ty
<
'tcx
>
{
let
ptr_field_type
=
|
pointee
:
Ty
<
'tcx
>
|
{
assert
!
(
i
<
2
);
let
mk_ptr
=
|
ty
:
Ty
<
'tcx
>
|
{
match
self
.ty.sty
{
ty
::
TyRef
(
r
,
ty
::
TypeAndMut
{
mutbl
,
..
})
=>
{
tcx
.mk_ref
(
r
,
ty
::
TypeAndMut
{
ty
,
mutbl
})
}
ty
::
TyRawPtr
(
ty
::
TypeAndMut
{
mutbl
,
..
})
=>
{
tcx
.mk_ptr
(
ty
::
TypeAndMut
{
ty
,
mutbl
})
}
ty
::
TyAdt
(
def
,
_
)
if
def
.is_box
()
=>
{
tcx
.mk_box
(
ty
)
}
_
=>
bug!
()
}
};
let
slice
=
|
element
:
Ty
<
'tcx
>
|
{
if
i
==
0
{
tcx
.mk_mut
_ptr
(
element
)
mk
_ptr
(
element
)
}
else
{
tcx
.types.usize
}
...
...
@@ -2057,7 +2067,13 @@ fn field_type_unnormalized(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, i: usize) -> Ty<'
match
tcx
.struct_tail
(
pointee
)
.sty
{
ty
::
TySlice
(
element
)
=>
slice
(
element
),
ty
::
TyStr
=>
slice
(
tcx
.types.u8
),
ty
::
TyDynamic
(
..
)
=>
Pointer
.to_ty
(
tcx
),
ty
::
TyDynamic
(
..
)
=>
{
if
i
==
0
{
mk_ptr
(
tcx
.mk_nil
())
}
else
{
Pointer
.to_ty
(
tcx
)
}
}
_
=>
bug!
(
"FullLayout::field_type({:?}): not applicable"
,
self
)
}
};
...
...
@@ -2187,9 +2203,16 @@ fn non_zero_field<C>(&self, cx: C)
{
let
tcx
=
cx
.tcx
();
match
(
self
.layout
,
self
.abi
,
&
self
.ty.sty
)
{
(
&
Layout
::
Scalar
,
Abi
::
Scalar
(
Pointer
),
_
)
if
!
self
.ty
.is_unsafe_ptr
()
=>
{
// FIXME(eddyb) check this via value ranges on scalars.
(
&
Layout
::
Scalar
,
Abi
::
Scalar
(
Pointer
),
&
ty
::
TyRef
(
..
))
|
(
&
Layout
::
Scalar
,
Abi
::
Scalar
(
Pointer
),
&
ty
::
TyFnPtr
(
..
))
=>
{
Ok
(
Some
((
Size
::
from_bytes
(
0
),
Pointer
)))
}
(
&
Layout
::
Scalar
,
Abi
::
Scalar
(
Pointer
),
&
ty
::
TyAdt
(
def
,
_
))
if
def
.is_box
()
=>
{
Ok
(
Some
((
Size
::
from_bytes
(
0
),
Pointer
)))
}
// FIXME(eddyb) check this via value ranges on scalars.
(
&
Layout
::
General
{
discr
,
..
},
_
,
&
ty
::
TyAdt
(
def
,
_
))
=>
{
if
def
.discriminants
(
tcx
)
.all
(|
d
|
d
.to_u128_unchecked
()
!=
0
)
{
Ok
(
Some
((
self
.fields
.offset
(
0
),
discr
)))
...
...
@@ -2198,28 +2221,28 @@ fn non_zero_field<C>(&self, cx: C)
}
}
(
&
Layout
::
FatPointer
,
_
,
_
)
if
!
self
.ty
.is_unsafe_ptr
()
=>
{
Ok
(
Some
((
self
.fields
.offset
(
FAT_PTR_ADDR
),
Pointer
)))
}
// Is this the NonZero lang item wrapping a pointer or integer type?
(
_
,
_
,
&
ty
::
TyAdt
(
def
,
_
))
if
Some
(
def
.did
)
==
tcx
.lang_items
()
.non_zero
()
=>
{
let
field
=
self
.field
(
cx
,
0
)
?
;
match
(
field
.layout
,
field
.abi
)
{
(
&
Layout
::
Scalar
,
Abi
::
Scalar
(
value
))
=>
{
Ok
(
Some
((
self
.fields
.offset
(
0
),
value
)))
}
(
&
Layout
::
FatPointer
,
_
)
=>
{
Ok
(
Some
((
self
.fields
.offset
(
0
)
+
field
.fields
.offset
(
FAT_PTR_ADDR
),
Pointer
)))
}
_
=>
Ok
(
None
)
let
offset
=
self
.fields
.offset
(
0
);
if
let
Abi
::
Scalar
(
value
)
=
field
.abi
{
Ok
(
Some
((
offset
,
value
)))
}
else
if
let
ty
::
TyRawPtr
(
_
)
=
field
.ty.sty
{
// If `NonZero` contains a non-scalar `*T`, it's
// a fat pointer, which starts with a thin pointer.
Ok
(
Some
((
offset
,
Pointer
)))
}
else
{
Ok
(
None
)
}
}
// Perhaps one of the fields is non-zero, let's recurse and find out.
(
&
Layout
::
Univariant
,
_
,
_
)
=>
{
_
=>
{
if
let
FieldPlacement
::
Array
{
count
,
..
}
=
*
self
.fields
{
if
count
>
0
{
return
self
.field
(
cx
,
0
)
?
.non_zero_field
(
cx
);
}
}
for
i
in
0
..
self
.fields
.count
()
{
let
r
=
self
.field
(
cx
,
i
)
?
.non_zero_field
(
cx
)
?
;
if
let
Some
((
offset
,
primitive
))
=
r
{
...
...
@@ -2228,23 +2251,6 @@ fn non_zero_field<C>(&self, cx: C)
}
Ok
(
None
)
}
// Is this a fixed-size array of something non-zero
// with at least one element?
(
_
,
_
,
&
ty
::
TyArray
(
ety
,
_
))
=>
{
if
self
.fields
.count
()
!=
0
{
cx
.layout_of
(
ety
)
?
.non_zero_field
(
cx
)
}
else
{
Ok
(
None
)
}
}
(
_
,
_
,
&
ty
::
TyProjection
(
_
))
|
(
_
,
_
,
&
ty
::
TyAnon
(
..
))
=>
{
bug!
(
"FullLayout::non_zero_field: {:#?} not normalized"
,
self
);
}
// Anything else is not a non-zero type.
_
=>
Ok
(
None
)
}
}
}
...
...
@@ -2260,7 +2266,6 @@ fn hash_stable<W: StableHasherResult>(&self,
Scalar
=>
{}
Vector
=>
{}
Array
=>
{}
FatPointer
=>
{}
Univariant
=>
{}
UntaggedUnion
=>
{}
General
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录