Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
38b5ddd3
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,发现更多精彩内容 >>
未验证
提交
38b5ddd3
编写于
1月 16, 2018
作者:
O
Oliver Schneider
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add a variant to ConstVal for storing miri results
上级
cdcca786
变更
18
隐藏空白更改
内联
并排
Showing
18 changed file
with
165 addition
and
25 deletion
+165
-25
src/librustc/ich/impls_ty.rs
src/librustc/ich/impls_ty.rs
+24
-0
src/librustc/lib.rs
src/librustc/lib.rs
+1
-0
src/librustc/middle/const_val.rs
src/librustc/middle/const_val.rs
+3
-0
src/librustc/mir/interpret/mod.rs
src/librustc/mir/interpret/mod.rs
+7
-4
src/librustc/mir/interpret/value.rs
src/librustc/mir/interpret/value.rs
+4
-4
src/librustc/mir/mod.rs
src/librustc/mir/mod.rs
+2
-1
src/librustc/ty/context.rs
src/librustc/ty/context.rs
+19
-0
src/librustc/ty/flags.rs
src/librustc/ty/flags.rs
+1
-0
src/librustc/ty/instance.rs
src/librustc/ty/instance.rs
+2
-2
src/librustc/ty/layout.rs
src/librustc/ty/layout.rs
+1
-1
src/librustc/ty/structural_impls.rs
src/librustc/ty/structural_impls.rs
+2
-0
src/librustc/ty/walk.rs
src/librustc/ty/walk.rs
+1
-0
src/librustc/ty/wf.rs
src/librustc/ty/wf.rs
+1
-0
src/librustc_const_eval/pattern.rs
src/librustc_const_eval/pattern.rs
+1
-0
src/librustc_metadata/decoder.rs
src/librustc_metadata/decoder.rs
+45
-1
src/librustc_metadata/encoder.rs
src/librustc_metadata/encoder.rs
+38
-1
src/librustc_mir/interpret/eval_context.rs
src/librustc_mir/interpret/eval_context.rs
+12
-11
src/librustc_trans/mir/constant.rs
src/librustc_trans/mir/constant.rs
+1
-0
未找到文件。
src/librustc/ich/impls_ty.rs
浏览文件 @
38b5ddd3
...
...
@@ -21,6 +21,7 @@
use
middle
::
region
;
use
traits
;
use
ty
;
use
mir
;
impl
<
'gcx
,
T
>
HashStable
<
StableHashingContext
<
'gcx
>>
for
&
'gcx
ty
::
Slice
<
T
>
...
...
@@ -388,6 +389,9 @@ fn hash_stable<W: StableHasherResult>(&self,
def_id
.hash_stable
(
hcx
,
hasher
);
substs
.hash_stable
(
hcx
,
hasher
);
}
Value
(
ref
value
)
=>
{
value
.hash_stable
(
hcx
,
hasher
);
}
}
}
}
...
...
@@ -396,6 +400,26 @@ fn hash_stable<W: StableHasherResult>(&self,
data
});
impl_stable_hash_for!
(
enum
mir
::
interpret
::
Value
{
ByVal
(
v
),
ByValPair
(
a
,
b
),
ByRef
(
ptr
,
align
)
});
impl_stable_hash_for!
(
struct
mir
::
interpret
::
MemoryPointer
{
alloc_id
,
offset
});
impl_stable_hash_for!
(
tuple_struct
mir
::
interpret
::
AllocId
{
id
});
impl_stable_hash_for!
(
struct
mir
::
interpret
::
Pointer
{
primval
});
impl_stable_hash_for!
(
enum
mir
::
interpret
::
PrimVal
{
Bytes
(
b
),
Ptr
(
p
),
Undef
});
impl_stable_hash_for!
(
struct
ty
::
Const
<
'tcx
>
{
ty
,
val
...
...
src/librustc/lib.rs
浏览文件 @
38b5ddd3
...
...
@@ -49,6 +49,7 @@
#![feature(core_intrinsics)]
#![feature(drain_filter)]
#![feature(dyn_trait)]
#![feature(entry_or_default)]
#![feature(from_ref)]
#![feature(fs_read_write)]
#![feature(i128)]
...
...
src/librustc/middle/const_val.rs
浏览文件 @
38b5ddd3
...
...
@@ -14,6 +14,7 @@
use
ty
::{
self
,
TyCtxt
,
layout
};
use
ty
::
subst
::
Substs
;
use
rustc_const_math
::
*
;
use
mir
::
interpret
::
Value
;
use
graphviz
::
IntoCow
;
use
errors
::
DiagnosticBuilder
;
...
...
@@ -38,6 +39,8 @@ pub enum ConstVal<'tcx> {
Function
(
DefId
,
&
'tcx
Substs
<
'tcx
>
),
Aggregate
(
ConstAggregate
<
'tcx
>
),
Unevaluated
(
DefId
,
&
'tcx
Substs
<
'tcx
>
),
/// A miri value, currently only produced if old ctfe fails, but miri succeeds
Value
(
Value
),
}
#[derive(Copy,
Clone,
Debug,
Hash,
RustcEncodable,
Eq,
PartialEq)]
...
...
src/librustc/mir/interpret/mod.rs
浏览文件 @
38b5ddd3
...
...
@@ -41,7 +41,7 @@ pub enum AccessKind {
}
/// Uniquely identifies a specific constant or static.
#[derive(Copy,
Clone,
Debug,
Eq,
PartialEq,
Hash)]
#[derive(Copy,
Clone,
Debug,
Eq,
PartialEq,
Hash
,
RustcEncodable,
RustcDecodable
)]
pub
struct
GlobalId
<
'tcx
>
{
/// For a constant or static, the `Instance` of the item itself.
/// For a promoted global, the `Instance` of the function they belong to.
...
...
@@ -101,7 +101,7 @@ fn wrapping_signed_offset(self, val: u64, i: i64) -> u64 {
impl
<
T
:
layout
::
HasDataLayout
>
PointerArithmetic
for
T
{}
#[derive(Copy,
Clone,
Debug,
Eq,
PartialEq)]
#[derive(Copy,
Clone,
Debug,
Eq,
PartialEq
,
RustcEncodable,
RustcDecodable,
Hash
)]
pub
struct
MemoryPointer
{
pub
alloc_id
:
AllocId
,
pub
offset
:
u64
,
...
...
@@ -148,13 +148,16 @@ pub fn offset<C: HasDataLayout>(self, i: u64, cx: C) -> EvalResult<'tcx, Self> {
#[derive(Copy,
Clone,
Default,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
Debug)]
pub
struct
AllocId
(
pub
u64
);
impl
::
rustc_serialize
::
UseSpecializedEncodable
for
AllocId
{}
impl
::
rustc_serialize
::
UseSpecializedDecodable
for
AllocId
{}
impl
fmt
::
Display
for
AllocId
{
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
)
->
fmt
::
Result
{
write!
(
f
,
"{}"
,
self
.0
)
}
}
#[derive(Debug,
Eq,
PartialEq,
Hash)]
#[derive(Debug,
Eq,
PartialEq,
Hash
,
RustcEncodable,
RustcDecodable
)]
pub
struct
Allocation
{
/// The actual bytes of the allocation.
/// Note that the bytes of a pointer represent the offset of the pointer
...
...
@@ -188,7 +191,7 @@ pub fn from_bytes(slice: &[u8]) -> Self {
type
Block
=
u64
;
const
BLOCK_SIZE
:
u64
=
64
;
#[derive(Clone,
Debug,
Eq,
PartialEq,
Hash)]
#[derive(Clone,
Debug,
Eq,
PartialEq,
Hash
,
RustcEncodable,
RustcDecodable
)]
pub
struct
UndefMask
{
blocks
:
Vec
<
Block
>
,
len
:
u64
,
...
...
src/librustc/mir/interpret/value.rs
浏览文件 @
38b5ddd3
...
...
@@ -29,7 +29,7 @@ pub fn bytes_to_f64(bits: u128) -> ConstFloat {
/// For optimization of a few very common cases, there is also a representation for a pair of
/// primitive values (`ByValPair`). It allows Miri to avoid making allocations for checked binary
/// operations and fat pointers. This idea was taken from rustc's trans.
#[derive(Clone,
Copy,
Debug)]
#[derive(Clone,
Copy,
Debug
,
Eq,
PartialEq,
RustcEncodable,
RustcDecodable,
Hash
)]
pub
enum
Value
{
ByRef
(
Pointer
,
Align
),
ByVal
(
PrimVal
),
...
...
@@ -43,9 +43,9 @@ pub enum Value {
/// I (@oli-obk) believe it is less easy to mix up generic primvals and primvals that are just
/// the representation of pointers. Also all the sites that convert between primvals and pointers
/// are explicit now (and rare!)
#[derive(Clone,
Copy,
Debug)]
#[derive(Clone,
Copy,
Debug
,
Eq,
PartialEq,
RustcEncodable,
RustcDecodable,
Hash
)]
pub
struct
Pointer
{
primval
:
PrimVal
,
p
ub
p
rimval
:
PrimVal
,
}
impl
<
'tcx
>
Pointer
{
...
...
@@ -138,7 +138,7 @@ fn from(ptr: MemoryPointer) -> Self {
/// `memory::Allocation`. It is in many ways like a small chunk of a `Allocation`, up to 8 bytes in
/// size. Like a range of bytes in an `Allocation`, a `PrimVal` can either represent the raw bytes
/// of a simple value, a pointer into another `Allocation`, or be undefined.
#[derive(Clone,
Copy,
Debug)]
#[derive(Clone,
Copy,
Debug
,
Eq,
PartialEq,
RustcEncodable,
RustcDecodable,
Hash
)]
pub
enum
PrimVal
{
/// The raw bytes of a simple value.
Bytes
(
u128
),
...
...
src/librustc/mir/mod.rs
浏览文件 @
38b5ddd3
...
...
@@ -1881,7 +1881,8 @@ fn fmt_const_val<W: Write>(fmt: &mut W, const_val: &ConstVal) -> fmt::Result {
Variant
(
def_id
)
|
Function
(
def_id
,
_
)
=>
write!
(
fmt
,
"{}"
,
item_path_str
(
def_id
)),
Aggregate
(
_
)
=>
bug!
(
"`ConstVal::{:?}` should not be in MIR"
,
const_val
),
Unevaluated
(
..
)
=>
write!
(
fmt
,
"{:?}"
,
const_val
)
Unevaluated
(
..
)
=>
write!
(
fmt
,
"{:?}"
,
const_val
),
Value
(
val
)
=>
write!
(
fmt
,
"{:?}"
,
val
),
}
}
...
...
src/librustc/ty/context.rs
浏览文件 @
38b5ddd3
...
...
@@ -905,6 +905,11 @@ pub struct InterpretInterner<'tcx> {
/// Allows obtaining const allocs via a unique identifier
alloc_by_id
:
FxHashMap
<
interpret
::
AllocId
,
&
'tcx
interpret
::
Allocation
>
,
/// Reverse map of `alloc_cache`
///
/// Multiple globals may share the same memory
global_cache
:
FxHashMap
<
interpret
::
Pointer
,
Vec
<
interpret
::
GlobalId
<
'tcx
>>>
,
/// The AllocId to assign to the next new regular allocation.
/// Always incremented, never gets smaller.
next_id
:
interpret
::
AllocId
,
...
...
@@ -955,11 +960,25 @@ pub fn cache(
global_id
:
interpret
::
GlobalId
<
'tcx
>
,
ptr
:
interpret
::
AllocId
,
)
{
if
let
interpret
::
PrimVal
::
Ptr
(
ptr
)
=
ptr
.primval
{
assert
!
(
ptr
.offset
==
0
);
}
self
.global_cache
.entry
(
ptr
)
.or_default
()
.push
(
global_id
);
if
let
Some
(
old
)
=
self
.alloc_cache
.insert
(
global_id
,
ptr
)
{
bug!
(
"tried to cache {:?}, but was already existing as {:#?}"
,
global_id
,
old
);
}
}
pub
fn
get_globals
(
&
self
,
ptr
:
interpret
::
Pointer
,
)
->
&
[
interpret
::
GlobalId
<
'tcx
>
]
{
match
self
.global_cache
.get
(
&
ptr
)
{
Some
(
v
)
=>
v
,
None
=>
&
[],
}
}
pub
fn
intern_at_reserved
(
&
mut
self
,
id
:
interpret
::
AllocId
,
...
...
src/librustc/ty/flags.rs
浏览文件 @
38b5ddd3
...
...
@@ -224,6 +224,7 @@ fn add_const(&mut self, constant: &ty::Const) {
ConstVal
::
ByteStr
(
_
)
|
ConstVal
::
Bool
(
_
)
|
ConstVal
::
Char
(
_
)
|
ConstVal
::
Value
(
_
)
|
ConstVal
::
Variant
(
_
)
=>
{}
ConstVal
::
Function
(
_
,
substs
)
=>
{
self
.add_substs
(
substs
);
...
...
src/librustc/ty/instance.rs
浏览文件 @
38b5ddd3
...
...
@@ -17,13 +17,13 @@
use
std
::
fmt
;
#[derive(Copy,
Clone,
PartialEq,
Eq,
Hash,
Debug)]
#[derive(Copy,
Clone,
PartialEq,
Eq,
Hash,
Debug
,
RustcEncodable,
RustcDecodable
)]
pub
struct
Instance
<
'tcx
>
{
pub
def
:
InstanceDef
<
'tcx
>
,
pub
substs
:
&
'tcx
Substs
<
'tcx
>
,
}
#[derive(Copy,
Clone,
PartialEq,
Eq,
Hash,
Debug)]
#[derive(Copy,
Clone,
PartialEq,
Eq,
Hash,
Debug
,
RustcEncodable,
RustcDecodable
)]
pub
enum
InstanceDef
<
'tcx
>
{
Item
(
DefId
),
Intrinsic
(
DefId
),
...
...
src/librustc/ty/layout.rs
浏览文件 @
38b5ddd3
...
...
@@ -342,7 +342,7 @@ fn add_assign(&mut self, other: Size) {
/// Each field is a power of two, giving the alignment a maximum
/// value of 2<sup>(2<sup>8</sup> - 1)</sup>, which is limited by LLVM to a i32, with
/// a maximum capacity of 2<sup>31</sup> - 1 or 2147483647.
#[derive(Copy,
Clone,
PartialEq,
Eq,
Hash,
Debug)]
#[derive(Copy,
Clone,
PartialEq,
Eq,
Hash,
Debug
,
RustcEncodable,
RustcDecodable
)]
pub
struct
Align
{
abi
:
u8
,
pref
:
u8
,
...
...
src/librustc/ty/structural_impls.rs
浏览文件 @
38b5ddd3
...
...
@@ -1249,6 +1249,7 @@ fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F)
ConstVal
::
ByteStr
(
b
)
=>
ConstVal
::
ByteStr
(
b
),
ConstVal
::
Bool
(
b
)
=>
ConstVal
::
Bool
(
b
),
ConstVal
::
Char
(
c
)
=>
ConstVal
::
Char
(
c
),
ConstVal
::
Value
(
v
)
=>
ConstVal
::
Value
(
v
),
ConstVal
::
Variant
(
def_id
)
=>
ConstVal
::
Variant
(
def_id
),
ConstVal
::
Function
(
def_id
,
substs
)
=>
{
ConstVal
::
Function
(
def_id
,
substs
.fold_with
(
folder
))
...
...
@@ -1304,6 +1305,7 @@ fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
ConstVal
::
ByteStr
(
_
)
|
ConstVal
::
Bool
(
_
)
|
ConstVal
::
Char
(
_
)
|
ConstVal
::
Value
(
_
)
|
ConstVal
::
Variant
(
_
)
=>
false
,
ConstVal
::
Function
(
_
,
substs
)
=>
substs
.visit_with
(
visitor
),
ConstVal
::
Aggregate
(
ConstAggregate
::
Struct
(
fields
))
=>
{
...
...
src/librustc/ty/walk.rs
浏览文件 @
38b5ddd3
...
...
@@ -146,6 +146,7 @@ fn push_const<'tcx>(stack: &mut TypeWalkerStack<'tcx>, constant: &'tcx ty::Const
ConstVal
::
ByteStr
(
_
)
|
ConstVal
::
Bool
(
_
)
|
ConstVal
::
Char
(
_
)
|
ConstVal
::
Value
(
_
)
|
ConstVal
::
Variant
(
_
)
=>
{}
ConstVal
::
Function
(
_
,
substs
)
=>
{
stack
.extend
(
substs
.types
()
.rev
());
...
...
src/librustc/ty/wf.rs
浏览文件 @
38b5ddd3
...
...
@@ -224,6 +224,7 @@ fn compute_const(&mut self, constant: &'tcx ty::Const<'tcx>) {
ConstVal
::
Bool
(
_
)
|
ConstVal
::
Char
(
_
)
|
ConstVal
::
Variant
(
_
)
|
ConstVal
::
Value
(
_
)
|
ConstVal
::
Function
(
..
)
=>
{}
ConstVal
::
Aggregate
(
ConstAggregate
::
Struct
(
fields
))
=>
{
for
&
(
_
,
v
)
in
fields
{
...
...
src/librustc_const_eval/pattern.rs
浏览文件 @
38b5ddd3
...
...
@@ -121,6 +121,7 @@ fn print_const_val(value: &ConstVal, f: &mut fmt::Formatter) -> fmt::Result {
ConstVal
::
Variant
(
_
)
|
ConstVal
::
Function
(
..
)
|
ConstVal
::
Aggregate
(
_
)
|
ConstVal
::
Value
(
_
)
|
ConstVal
::
Unevaluated
(
..
)
=>
bug!
(
"{:?} not printable in a pattern"
,
value
)
}
}
...
...
src/librustc_metadata/decoder.rs
浏览文件 @
38b5ddd3
...
...
@@ -24,11 +24,12 @@
CRATE_DEF_INDEX
,
LOCAL_CRATE
};
use
rustc
::
ich
::
Fingerprint
;
use
rustc
::
middle
::
lang_items
;
use
rustc
::
mir
;
use
rustc
::
mir
::{
self
,
interpret
}
;
use
rustc
::
session
::
Session
;
use
rustc
::
ty
::{
self
,
Ty
,
TyCtxt
};
use
rustc
::
ty
::
codec
::
TyDecoder
;
use
rustc
::
mir
::
Mir
;
use
rustc
::
util
::
nodemap
::
FxHashMap
;
use
std
::
cell
::
Ref
;
use
std
::
collections
::
BTreeMap
;
...
...
@@ -54,6 +55,9 @@ pub struct DecodeContext<'a, 'tcx: 'a> {
last_filemap_index
:
usize
,
lazy_state
:
LazyState
,
// interpreter allocation cache
interpret_alloc_cache
:
FxHashMap
<
usize
,
interpret
::
AllocId
>
,
}
/// Abstract over the various ways one can create metadata decoders.
...
...
@@ -72,6 +76,7 @@ fn decoder(self, pos: usize) -> DecodeContext<'a, 'tcx> {
tcx
,
last_filemap_index
:
0
,
lazy_state
:
LazyState
::
NoNode
,
interpret_alloc_cache
:
FxHashMap
::
default
(),
}
}
}
...
...
@@ -268,6 +273,45 @@ fn specialized_decode(&mut self) -> Result<DefIndex, Self::Error> {
}
}
impl
<
'a
,
'tcx
>
SpecializedDecoder
<
interpret
::
AllocId
>
for
DecodeContext
<
'a
,
'tcx
>
{
fn
specialized_decode
(
&
mut
self
)
->
Result
<
interpret
::
AllocId
,
Self
::
Error
>
{
const
MAX1
:
usize
=
usize
::
max_value
()
-
1
;
let
mut
interpret_interner
=
self
.tcx
.unwrap
()
.interpret_interner
.borrow_mut
();
let
pos
=
self
.position
();
match
self
.read_usize
()
?
{
::
std
::
usize
::
MAX
=>
{
let
allocation
=
interpret
::
Allocation
::
decode
(
self
)
?
;
let
id
=
interpret_interner
.reserve
();
let
allocation
=
self
.tcx
.unwrap
()
.intern_const_alloc
(
allocation
);
interpret_interner
.intern_at_reserved
(
id
,
allocation
);
let
id
=
interpret
::
AllocId
(
id
);
self
.interpret_alloc_cache
.insert
(
pos
,
id
);
let
num
=
usize
::
decode
(
self
)
?
;
let
ptr
=
interpret
::
Pointer
{
primval
:
interpret
::
PrimVal
::
Ptr
(
interpret
::
MemoryPointer
{
alloc_id
:
id
,
offset
:
0
,
}),
};
for
_
in
0
..
num
{
let
glob
=
interpret
::
GlobalId
::
decode
(
self
)
?
;
interpret_interner
.cache
(
glob
,
ptr
);
}
Ok
(
id
)
},
MAX1
=>
{
let
instance
=
ty
::
Instance
::
decode
(
self
)
?
;
let
id
=
interpret
::
AllocId
(
interpret_interner
.create_fn_alloc
(
instance
));
self
.interpret_alloc_cache
.insert
(
pos
,
id
);
Ok
(
id
)
},
shorthand
=>
Ok
(
self
.interpret_alloc_cache
[
&
shorthand
]),
}
}
}
impl
<
'a
,
'tcx
>
SpecializedDecoder
<
Span
>
for
DecodeContext
<
'a
,
'tcx
>
{
fn
specialized_decode
(
&
mut
self
)
->
Result
<
Span
,
Self
::
Error
>
{
let
tag
=
u8
::
decode
(
self
)
?
;
...
...
src/librustc_metadata/encoder.rs
浏览文件 @
38b5ddd3
...
...
@@ -23,7 +23,7 @@
use
rustc
::
middle
::
exported_symbols
::{
ExportedSymbol
,
SymbolExportLevel
,
metadata_symbol_name
};
use
rustc
::
middle
::
lang_items
;
use
rustc
::
mir
;
use
rustc
::
mir
::{
self
,
interpret
}
;
use
rustc
::
traits
::
specialization_graph
;
use
rustc
::
ty
::{
self
,
Ty
,
TyCtxt
,
ReprOptions
,
SymbolName
};
use
rustc
::
ty
::
codec
::{
self
as
ty_codec
,
TyEncoder
};
...
...
@@ -59,6 +59,7 @@ pub struct EncodeContext<'a, 'tcx: 'a> {
lazy_state
:
LazyState
,
type_shorthands
:
FxHashMap
<
Ty
<
'tcx
>
,
usize
>
,
predicate_shorthands
:
FxHashMap
<
ty
::
Predicate
<
'tcx
>
,
usize
>
,
interpret_alloc_shorthands
:
FxHashMap
<
interpret
::
AllocId
,
usize
>
,
// This is used to speed up Span encoding.
filemap_cache
:
Lrc
<
FileMap
>
,
...
...
@@ -186,6 +187,41 @@ fn specialized_encode(&mut self, ty: &Ty<'tcx>) -> Result<(), Self::Error> {
}
}
impl
<
'a
,
'tcx
>
SpecializedEncoder
<
interpret
::
AllocId
>
for
EncodeContext
<
'a
,
'tcx
>
{
fn
specialized_encode
(
&
mut
self
,
alloc_id
:
&
interpret
::
AllocId
)
->
Result
<
(),
Self
::
Error
>
{
if
let
Some
(
shorthand
)
=
self
.interpret_alloc_shorthands
.get
(
alloc_id
)
.cloned
()
{
return
self
.emit_usize
(
shorthand
);
}
let
start
=
self
.position
();
let
interpret_interner
=
self
.tcx.interpret_interner
.borrow
();
if
let
Some
(
alloc
)
=
interpret_interner
.get_alloc
(
alloc_id
.0
)
{
usize
::
max_value
()
.encode
(
self
)
?
;
alloc
.encode
(
self
)
?
;
let
globals
=
interpret_interner
.get_globals
(
interpret
::
Pointer
{
primval
:
interpret
::
PrimVal
::
Ptr
(
interpret
::
MemoryPointer
{
alloc_id
:
*
alloc_id
,
offset
:
0
,
}),
});
globals
.len
()
.encode
(
self
)
?
;
for
glob
in
globals
{
glob
.encode
(
self
)
?
;
}
}
else
if
let
Some
(
fn_instance
)
=
interpret_interner
.get_fn
(
alloc_id
.0
)
{
(
usize
::
max_value
()
-
1
)
.encode
(
self
)
?
;
fn_instance
.encode
(
self
)
?
;
}
else
{
bug!
(
"alloc id without corresponding allocation: {}"
,
alloc_id
.0
);
}
let
len
=
self
.position
()
-
start
*
7
;
// Check that the shorthand is a not longer than the
// full encoding itself, i.e. it's an obvious win.
assert
!
(
len
>=
64
||
(
start
as
u64
)
<
(
1
<<
len
));
self
.interpret_alloc_shorthands
.insert
(
*
alloc_id
,
start
);
Ok
(())
}
}
impl
<
'a
,
'tcx
>
SpecializedEncoder
<
ty
::
GenericPredicates
<
'tcx
>>
for
EncodeContext
<
'a
,
'tcx
>
{
fn
specialized_encode
(
&
mut
self
,
predicates
:
&
ty
::
GenericPredicates
<
'tcx
>
)
...
...
@@ -1699,6 +1735,7 @@ pub fn encode_metadata<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
type_shorthands
:
Default
::
default
(),
predicate_shorthands
:
Default
::
default
(),
filemap_cache
:
tcx
.sess
.codemap
()
.files
()[
0
]
.clone
(),
interpret_alloc_shorthands
:
Default
::
default
(),
};
// Encode the rustc version string in a predictable location.
...
...
src/librustc_mir/interpret/eval_context.rs
浏览文件 @
38b5ddd3
...
...
@@ -241,24 +241,24 @@ pub fn str_to_value(&mut self, s: &str) -> EvalResult<'tcx, Value> {
}
pub
(
super
)
fn
const_to_value
(
&
mut
self
,
const_val
:
&
ConstVal
<
'tcx
>
,
ty
:
Ty
<
'tcx
>
)
->
EvalResult
<
'tcx
,
Value
>
{
use
rustc
::
middle
::
const_val
::
ConstVal
::
*
;
use
rustc
::
middle
::
const_val
::
ConstVal
;
let
primval
=
match
*
const_val
{
Integral
(
const_int
)
=>
PrimVal
::
Bytes
(
const_int
.to_u128_unchecked
()),
ConstVal
::
Integral
(
const_int
)
=>
PrimVal
::
Bytes
(
const_int
.to_u128_unchecked
()),
Float
(
val
)
=>
PrimVal
::
Bytes
(
val
.bits
),
ConstVal
::
Float
(
val
)
=>
PrimVal
::
Bytes
(
val
.bits
),
Bool
(
b
)
=>
PrimVal
::
from_bool
(
b
),
Char
(
c
)
=>
PrimVal
::
from_char
(
c
),
ConstVal
::
Bool
(
b
)
=>
PrimVal
::
from_bool
(
b
),
C
onstVal
::
C
har
(
c
)
=>
PrimVal
::
from_char
(
c
),
Str
(
ref
s
)
=>
return
self
.str_to_value
(
s
),
ConstVal
::
Str
(
ref
s
)
=>
return
self
.str_to_value
(
s
),
ByteStr
(
ref
bs
)
=>
{
ConstVal
::
ByteStr
(
ref
bs
)
=>
{
let
ptr
=
self
.memory
.allocate_cached
(
bs
.data
);
PrimVal
::
Ptr
(
ptr
)
}
Unevaluated
(
def_id
,
substs
)
=>
{
ConstVal
::
Unevaluated
(
def_id
,
substs
)
=>
{
let
instance
=
self
.resolve
(
def_id
,
substs
)
?
;
return
Ok
(
self
.read_global_as_value
(
GlobalId
{
instance
,
...
...
@@ -266,10 +266,11 @@ pub(super) fn const_to_value(&mut self, const_val: &ConstVal<'tcx>, ty: Ty<'tcx>
},
self
.layout_of
(
ty
)
?
));
}
Aggregate
(
..
)
|
Variant
(
_
)
=>
bug!
(
"should not have aggregate or variant constants in MIR"
),
ConstVal
::
Aggregate
(
..
)
|
ConstVal
::
Variant
(
_
)
=>
bug!
(
"should not have aggregate or variant constants in MIR"
),
// function items are zero sized and thus have no readable value
Function
(
..
)
=>
PrimVal
::
Undef
,
ConstVal
::
Function
(
..
)
=>
PrimVal
::
Undef
,
ConstVal
::
Value
(
val
)
=>
return
Ok
(
val
),
};
Ok
(
Value
::
ByVal
(
primval
))
...
...
src/librustc_trans/mir/constant.rs
浏览文件 @
38b5ddd3
...
...
@@ -108,6 +108,7 @@ pub fn from_constval(cx: &CodegenCx<'a, 'tcx>,
ConstVal
::
Unevaluated
(
..
)
=>
{
bug!
(
"MIR must not use `{:?}` (aggregates are expanded to MIR rvalues)"
,
cv
)
}
ConstVal
::
Value
(
_
)
=>
unimplemented!
(),
};
assert
!
(
!
ty
.has_erasable_regions
());
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录