Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
46389159
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,发现更多精彩内容 >>
提交
46389159
编写于
5月 27, 2022
作者:
M
Michael Goulet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make TyCtxt implement Interner, make HashStable generic and move to rustc_type_ir
上级
f05a92d1
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
229 addition
and
248 deletion
+229
-248
compiler/rustc_macros/src/serialize.rs
compiler/rustc_macros/src/serialize.rs
+2
-2
compiler/rustc_metadata/src/rmeta/decoder.rs
compiler/rustc_metadata/src/rmeta/decoder.rs
+3
-3
compiler/rustc_metadata/src/rmeta/encoder.rs
compiler/rustc_metadata/src/rmeta/encoder.rs
+2
-2
compiler/rustc_middle/src/mir/interpret/mod.rs
compiler/rustc_middle/src/mir/interpret/mod.rs
+7
-7
compiler/rustc_middle/src/ty/codec.rs
compiler/rustc_middle/src/ty/codec.rs
+62
-67
compiler/rustc_middle/src/ty/context.rs
compiler/rustc_middle/src/ty/context.rs
+1
-10
compiler/rustc_middle/src/ty/mod.rs
compiler/rustc_middle/src/ty/mod.rs
+7
-20
compiler/rustc_middle/src/ty/sty.rs
compiler/rustc_middle/src/ty/sty.rs
+1
-1
compiler/rustc_middle/src/ty/subst.rs
compiler/rustc_middle/src/ty/subst.rs
+3
-3
compiler/rustc_mir_transform/src/coverage/tests.rs
compiler/rustc_mir_transform/src/coverage/tests.rs
+2
-2
compiler/rustc_query_impl/src/on_disk_cache.rs
compiler/rustc_query_impl/src/on_disk_cache.rs
+5
-5
compiler/rustc_query_system/src/ich/mod.rs
compiler/rustc_query_system/src/ich/mod.rs
+0
-122
compiler/rustc_type_ir/src/lib.rs
compiler/rustc_type_ir/src/lib.rs
+0
-1
compiler/rustc_type_ir/src/sty.rs
compiler/rustc_type_ir/src/sty.rs
+134
-1
compiler/rustc_typeck/src/check/op.rs
compiler/rustc_typeck/src/check/op.rs
+0
-2
未找到文件。
compiler/rustc_macros/src/serialize.rs
浏览文件 @
46389159
...
...
@@ -8,7 +8,7 @@ pub fn type_decodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2:
if
!
s
.ast
()
.generics
.lifetimes
()
.any
(|
lt
|
lt
.lifetime.ident
==
"tcx"
)
{
s
.add_impl_generic
(
parse_quote!
{
'tcx
});
}
s
.add_impl_generic
(
parse_quote!
{
#
decoder_ty
:
::
rustc_type_ir
::
codec
::
TyDecoder
<
I
=
::
rustc_middle
::
ty
::
Ty
Interner
<
'tcx
>>
});
s
.add_impl_generic
(
parse_quote!
{
#
decoder_ty
:
::
rustc_type_ir
::
codec
::
TyDecoder
<
I
=
::
rustc_middle
::
ty
::
Ty
Ctxt
<
'tcx
>>
});
s
.add_bounds
(
synstructure
::
AddBounds
::
Generics
);
decodable_body
(
s
,
decoder_ty
)
...
...
@@ -95,7 +95,7 @@ pub fn type_encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2:
s
.add_impl_generic
(
parse_quote!
{
'tcx
});
}
let
encoder_ty
=
quote!
{
__
E
};
s
.add_impl_generic
(
parse_quote!
{
#
encoder_ty
:
::
rustc_type_ir
::
codec
::
TyEncoder
<
I
=
::
rustc_middle
::
ty
::
Ty
Interner
<
'tcx
>>
});
s
.add_impl_generic
(
parse_quote!
{
#
encoder_ty
:
::
rustc_type_ir
::
codec
::
TyEncoder
<
I
=
::
rustc_middle
::
ty
::
Ty
Ctxt
<
'tcx
>>
});
s
.add_bounds
(
synstructure
::
AddBounds
::
Generics
);
encodable_body
(
s
,
encoder_ty
,
false
)
...
...
compiler/rustc_metadata/src/rmeta/decoder.rs
浏览文件 @
46389159
...
...
@@ -24,8 +24,8 @@
use
rustc_middle
::
thir
;
use
rustc_middle
::
ty
::
codec
::
TyDecoder
;
use
rustc_middle
::
ty
::
fast_reject
::
SimplifiedType
;
use
rustc_middle
::
ty
::
GeneratorDiagnosticData
;
use
rustc_middle
::
ty
::{
self
,
ParameterizedOverTcx
,
Ty
,
TyCtxt
,
Visibility
};
use
rustc_middle
::
ty
::{
GeneratorDiagnosticData
,
TyInterner
};
use
rustc_serialize
::{
opaque
,
Decodable
,
Decoder
};
use
rustc_session
::
cstore
::{
CrateSource
,
ExternCrate
,
ForeignModule
,
LinkagePreference
,
NativeLib
,
...
...
@@ -380,11 +380,11 @@ pub fn read_raw_bytes(&mut self, len: usize) -> &[u8] {
impl
<
'a
,
'tcx
>
TyDecoder
for
DecodeContext
<
'a
,
'tcx
>
{
const
CLEAR_CROSS_CRATE
:
bool
=
true
;
type
I
=
Ty
Interner
<
'tcx
>
;
type
I
=
Ty
Ctxt
<
'tcx
>
;
#[inline]
fn
interner
(
&
self
)
->
Self
::
I
{
TyInterner
{
tcx
:
self
.tcx
()
}
self
.tcx
()
}
#[inline]
...
...
compiler/rustc_metadata/src/rmeta/encoder.rs
浏览文件 @
46389159
...
...
@@ -26,7 +26,7 @@
use
rustc_middle
::
ty
::
codec
::
TyEncoder
;
use
rustc_middle
::
ty
::
fast_reject
::{
self
,
SimplifiedType
,
TreatParams
};
use
rustc_middle
::
ty
::
query
::
Providers
;
use
rustc_middle
::
ty
::{
self
,
SymbolName
,
Ty
,
TyCtxt
,
TyInterner
};
use
rustc_middle
::
ty
::{
self
,
SymbolName
,
Ty
,
TyCtxt
};
use
rustc_serialize
::{
opaque
,
Encodable
,
Encoder
};
use
rustc_session
::
config
::
CrateType
;
use
rustc_session
::
cstore
::{
ForeignModule
,
LinkagePreference
,
NativeLib
};
...
...
@@ -316,7 +316,7 @@ fn encode(&self, s: &mut EncodeContext<'a, 'tcx>) -> opaque::EncodeResult {
impl
<
'a
,
'tcx
>
TyEncoder
for
EncodeContext
<
'a
,
'tcx
>
{
const
CLEAR_CROSS_CRATE
:
bool
=
true
;
type
I
=
Ty
Interner
<
'tcx
>
;
type
I
=
Ty
Ctxt
<
'tcx
>
;
fn
position
(
&
self
)
->
usize
{
self
.opaque
.position
()
...
...
compiler/rustc_middle/src/mir/interpret/mod.rs
浏览文件 @
46389159
...
...
@@ -115,7 +115,7 @@
use
crate
::
mir
;
use
crate
::
ty
::
codec
::{
TyDecoder
,
TyEncoder
};
use
crate
::
ty
::
subst
::
GenericArgKind
;
use
crate
::
ty
::{
self
,
Instance
,
Ty
,
TyCtxt
,
TyInterner
};
use
crate
::
ty
::{
self
,
Instance
,
Ty
,
TyCtxt
};
pub
use
self
::
error
::{
struct_error
,
CheckInAllocMsg
,
ErrorHandled
,
EvalToAllocationRawResult
,
EvalToConstValueResult
,
...
...
@@ -203,7 +203,7 @@ enum AllocDiscriminant {
Static
,
}
pub
fn
specialized_encode_alloc_id
<
'tcx
,
E
:
TyEncoder
<
I
=
Ty
Interner
<
'tcx
>>>
(
pub
fn
specialized_encode_alloc_id
<
'tcx
,
E
:
TyEncoder
<
I
=
Ty
Ctxt
<
'tcx
>>>
(
encoder
:
&
mut
E
,
tcx
:
TyCtxt
<
'tcx
>
,
alloc_id
:
AllocId
,
...
...
@@ -277,7 +277,7 @@ impl<'s> AllocDecodingSession<'s> {
/// Decodes an `AllocId` in a thread-safe way.
pub
fn
decode_alloc_id
<
'tcx
,
D
>
(
&
self
,
decoder
:
&
mut
D
)
->
AllocId
where
D
:
TyDecoder
<
I
=
Ty
Interner
<
'tcx
>>
,
D
:
TyDecoder
<
I
=
Ty
Ctxt
<
'tcx
>>
,
{
// Read the index of the allocation.
let
idx
=
usize
::
try_from
(
decoder
.read_u32
())
.unwrap
();
...
...
@@ -305,7 +305,7 @@ pub fn decode_alloc_id<'tcx, D>(&self, decoder: &mut D) -> AllocId
AllocDiscriminant
::
Alloc
=>
{
// If this is an allocation, we need to reserve an
// `AllocId` so we can decode cyclic graphs.
let
alloc_id
=
decoder
.interner
()
.
tcx
.
reserve_alloc_id
();
let
alloc_id
=
decoder
.interner
()
.reserve_alloc_id
();
*
entry
=
State
::
InProgress
(
TinyList
::
new_single
(
self
.session_id
),
alloc_id
);
Some
(
alloc_id
)
...
...
@@ -349,7 +349,7 @@ pub fn decode_alloc_id<'tcx, D>(&self, decoder: &mut D) -> AllocId
// We already have a reserved `AllocId`.
let
alloc_id
=
alloc_id
.unwrap
();
trace!
(
"decoded alloc {:?}: {:#?}"
,
alloc_id
,
alloc
);
decoder
.interner
()
.
tcx
.
set_alloc_id_same_memory
(
alloc_id
,
alloc
);
decoder
.interner
()
.set_alloc_id_same_memory
(
alloc_id
,
alloc
);
alloc_id
}
AllocDiscriminant
::
Fn
=>
{
...
...
@@ -357,7 +357,7 @@ pub fn decode_alloc_id<'tcx, D>(&self, decoder: &mut D) -> AllocId
trace!
(
"creating fn alloc ID"
);
let
instance
=
ty
::
Instance
::
decode
(
decoder
);
trace!
(
"decoded fn alloc instance: {:?}"
,
instance
);
let
alloc_id
=
decoder
.interner
()
.
tcx
.
create_fn_alloc
(
instance
);
let
alloc_id
=
decoder
.interner
()
.create_fn_alloc
(
instance
);
alloc_id
}
AllocDiscriminant
::
Static
=>
{
...
...
@@ -365,7 +365,7 @@ pub fn decode_alloc_id<'tcx, D>(&self, decoder: &mut D) -> AllocId
trace!
(
"creating extern static alloc ID"
);
let
did
=
<
DefId
as
Decodable
<
D
>>
::
decode
(
decoder
);
trace!
(
"decoded static def-ID: {:?}"
,
did
);
let
alloc_id
=
decoder
.interner
()
.
tcx
.
create_static_alloc
(
did
);
let
alloc_id
=
decoder
.interner
()
.create_static_alloc
(
did
);
alloc_id
}
}
...
...
compiler/rustc_middle/src/ty/codec.rs
浏览文件 @
46389159
...
...
@@ -17,7 +17,7 @@
use
crate
::
ty
::
subst
::
SubstsRef
;
use
crate
::
ty
::{
self
,
AdtDef
,
Ty
};
use
rustc_data_structures
::
fx
::
FxHashMap
;
use
rustc_middle
::
ty
::
Ty
Interner
;
use
rustc_middle
::
ty
::
Ty
Ctxt
;
use
rustc_serialize
::{
Decodable
,
Encodable
};
use
rustc_span
::
Span
;
pub
use
rustc_type_ir
::{
TyDecoder
,
TyEncoder
};
...
...
@@ -36,7 +36,7 @@ pub trait EncodableWithShorthand<E: TyEncoder>: Copy + Eq + Hash {
}
#[allow(rustc::usage_of_ty_tykind)]
impl
<
'tcx
,
E
:
TyEncoder
<
I
=
Ty
Interner
<
'tcx
>>>
EncodableWithShorthand
<
E
>
for
Ty
<
'tcx
>
{
impl
<
'tcx
,
E
:
TyEncoder
<
I
=
Ty
Ctxt
<
'tcx
>>>
EncodableWithShorthand
<
E
>
for
Ty
<
'tcx
>
{
type
Variant
=
ty
::
TyKind
<
'tcx
>
;
#[inline]
...
...
@@ -45,9 +45,7 @@ fn variant(&self) -> &Self::Variant {
}
}
impl
<
'tcx
,
E
:
TyEncoder
<
I
=
TyInterner
<
'tcx
>>>
EncodableWithShorthand
<
E
>
for
ty
::
PredicateKind
<
'tcx
>
{
impl
<
'tcx
,
E
:
TyEncoder
<
I
=
TyCtxt
<
'tcx
>>>
EncodableWithShorthand
<
E
>
for
ty
::
PredicateKind
<
'tcx
>
{
type
Variant
=
ty
::
PredicateKind
<
'tcx
>
;
#[inline]
...
...
@@ -66,7 +64,7 @@ fn variant(&self) -> &Self::Variant {
///
/// `Decodable` can still be implemented in cases where `Decodable` is required
/// by a trait bound.
pub
trait
RefDecodable
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Interner
<
'tcx
>>>
{
pub
trait
RefDecodable
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Ctxt
<
'tcx
>>>
{
fn
decode
(
d
:
&
mut
D
)
->
&
'tcx
Self
;
}
...
...
@@ -77,7 +75,7 @@ pub fn encode_with_shorthand<'tcx, E, T, M>(
cache
:
M
,
)
->
Result
<
(),
E
::
Error
>
where
E
:
TyEncoder
<
I
=
Ty
Interner
<
'tcx
>>
,
E
:
TyEncoder
<
I
=
Ty
Ctxt
<
'tcx
>>
,
M
:
for
<
'b
>
Fn
(
&
'b
mut
E
)
->
&
'b
mut
FxHashMap
<
T
,
usize
>
,
T
:
EncodableWithShorthand
<
E
>
,
// The discriminant and shorthand must have the same size.
...
...
@@ -114,13 +112,13 @@ pub fn encode_with_shorthand<'tcx, E, T, M>(
Ok
(())
}
impl
<
'tcx
,
E
:
TyEncoder
<
I
=
Ty
Interner
<
'tcx
>>>
Encodable
<
E
>
for
Ty
<
'tcx
>
{
impl
<
'tcx
,
E
:
TyEncoder
<
I
=
Ty
Ctxt
<
'tcx
>>>
Encodable
<
E
>
for
Ty
<
'tcx
>
{
fn
encode
(
&
self
,
e
:
&
mut
E
)
->
Result
<
(),
E
::
Error
>
{
encode_with_shorthand
(
e
,
self
,
TyEncoder
::
type_shorthands
)
}
}
impl
<
'tcx
,
E
:
TyEncoder
<
I
=
Ty
Interner
<
'tcx
>>>
Encodable
<
E
>
impl
<
'tcx
,
E
:
TyEncoder
<
I
=
Ty
Ctxt
<
'tcx
>>>
Encodable
<
E
>
for
ty
::
Binder
<
'tcx
,
ty
::
PredicateKind
<
'tcx
>>
{
fn
encode
(
&
self
,
e
:
&
mut
E
)
->
Result
<
(),
E
::
Error
>
{
...
...
@@ -129,37 +127,37 @@ fn encode(&self, e: &mut E) -> Result<(), E::Error> {
}
}
impl
<
'tcx
,
E
:
TyEncoder
<
I
=
Ty
Interner
<
'tcx
>>>
Encodable
<
E
>
for
ty
::
Predicate
<
'tcx
>
{
impl
<
'tcx
,
E
:
TyEncoder
<
I
=
Ty
Ctxt
<
'tcx
>>>
Encodable
<
E
>
for
ty
::
Predicate
<
'tcx
>
{
fn
encode
(
&
self
,
e
:
&
mut
E
)
->
Result
<
(),
E
::
Error
>
{
self
.kind
()
.encode
(
e
)
}
}
impl
<
'tcx
,
E
:
TyEncoder
<
I
=
Ty
Interner
<
'tcx
>>>
Encodable
<
E
>
for
ty
::
Region
<
'tcx
>
{
impl
<
'tcx
,
E
:
TyEncoder
<
I
=
Ty
Ctxt
<
'tcx
>>>
Encodable
<
E
>
for
ty
::
Region
<
'tcx
>
{
fn
encode
(
&
self
,
e
:
&
mut
E
)
->
Result
<
(),
E
::
Error
>
{
self
.kind
()
.encode
(
e
)
}
}
impl
<
'tcx
,
E
:
TyEncoder
<
I
=
Ty
Interner
<
'tcx
>>>
Encodable
<
E
>
for
ty
::
Const
<
'tcx
>
{
impl
<
'tcx
,
E
:
TyEncoder
<
I
=
Ty
Ctxt
<
'tcx
>>>
Encodable
<
E
>
for
ty
::
Const
<
'tcx
>
{
fn
encode
(
&
self
,
e
:
&
mut
E
)
->
Result
<
(),
E
::
Error
>
{
self
.0.0
.encode
(
e
)
}
}
impl
<
'tcx
,
E
:
TyEncoder
<
I
=
Ty
Interner
<
'tcx
>>>
Encodable
<
E
>
for
ConstAllocation
<
'tcx
>
{
impl
<
'tcx
,
E
:
TyEncoder
<
I
=
Ty
Ctxt
<
'tcx
>>>
Encodable
<
E
>
for
ConstAllocation
<
'tcx
>
{
fn
encode
(
&
self
,
e
:
&
mut
E
)
->
Result
<
(),
E
::
Error
>
{
self
.inner
()
.encode
(
e
)
}
}
impl
<
'tcx
,
E
:
TyEncoder
<
I
=
Ty
Interner
<
'tcx
>>>
Encodable
<
E
>
for
AdtDef
<
'tcx
>
{
impl
<
'tcx
,
E
:
TyEncoder
<
I
=
Ty
Ctxt
<
'tcx
>>>
Encodable
<
E
>
for
AdtDef
<
'tcx
>
{
fn
encode
(
&
self
,
e
:
&
mut
E
)
->
Result
<
(),
E
::
Error
>
{
self
.0.0
.encode
(
e
)
}
}
impl
<
'tcx
,
E
:
TyEncoder
<
I
=
Ty
Interner
<
'tcx
>>>
Encodable
<
E
>
for
AllocId
{
impl
<
'tcx
,
E
:
TyEncoder
<
I
=
Ty
Ctxt
<
'tcx
>>>
Encodable
<
E
>
for
AllocId
{
fn
encode
(
&
self
,
e
:
&
mut
E
)
->
Result
<
(),
E
::
Error
>
{
e
.encode_alloc_id
(
self
)
}
...
...
@@ -168,7 +166,7 @@ fn encode(&self, e: &mut E) -> Result<(), E::Error> {
#[inline]
fn
decode_arena_allocable
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Interner
<
'tcx
>>
,
D
:
TyDecoder
<
I
=
Ty
Ctxt
<
'tcx
>>
,
T
:
ArenaAllocatable
<
'tcx
>
+
Decodable
<
D
>
,
>
(
decoder
:
&
mut
D
,
...
...
@@ -176,13 +174,13 @@ fn decode_arena_allocable<
where
D
:
TyDecoder
,
{
decoder
.interner
()
.
tcx.
arena
.alloc
(
Decodable
::
decode
(
decoder
))
decoder
.interner
()
.arena
.alloc
(
Decodable
::
decode
(
decoder
))
}
#[inline]
fn
decode_arena_allocable_slice
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Interner
<
'tcx
>>
,
D
:
TyDecoder
<
I
=
Ty
Ctxt
<
'tcx
>>
,
T
:
ArenaAllocatable
<
'tcx
>
+
Decodable
<
D
>
,
>
(
decoder
:
&
mut
D
,
...
...
@@ -190,10 +188,10 @@ fn decode_arena_allocable_slice<
where
D
:
TyDecoder
,
{
decoder
.interner
()
.
tcx.
arena
.alloc_from_iter
(
<
Vec
<
T
>
as
Decodable
<
D
>>
::
decode
(
decoder
))
decoder
.interner
()
.arena
.alloc_from_iter
(
<
Vec
<
T
>
as
Decodable
<
D
>>
::
decode
(
decoder
))
}
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Interner
<
'tcx
>>>
Decodable
<
D
>
for
Ty
<
'tcx
>
{
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Ctxt
<
'tcx
>>>
Decodable
<
D
>
for
Ty
<
'tcx
>
{
#[allow(rustc::usage_of_ty_tykind)]
fn
decode
(
decoder
:
&
mut
D
)
->
Ty
<
'tcx
>
{
// Handle shorthands first, if we have a usize > 0x80.
...
...
@@ -206,13 +204,13 @@ fn decode(decoder: &mut D) -> Ty<'tcx> {
decoder
.with_position
(
shorthand
,
Ty
::
decode
)
})
}
else
{
let
tcx
=
decoder
.interner
()
.tcx
;
let
tcx
=
decoder
.interner
();
tcx
.mk_ty
(
rustc_type_ir
::
TyKind
::
decode
(
decoder
))
}
}
}
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Interner
<
'tcx
>>>
Decodable
<
D
>
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Ctxt
<
'tcx
>>>
Decodable
<
D
>
for
ty
::
Binder
<
'tcx
,
ty
::
PredicateKind
<
'tcx
>>
{
fn
decode
(
decoder
:
&
mut
D
)
->
ty
::
Binder
<
'tcx
,
ty
::
PredicateKind
<
'tcx
>>
{
...
...
@@ -233,64 +231,64 @@ fn decode(decoder: &mut D) -> ty::Binder<'tcx, ty::PredicateKind<'tcx>> {
}
}
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Interner
<
'tcx
>>>
Decodable
<
D
>
for
ty
::
Predicate
<
'tcx
>
{
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Ctxt
<
'tcx
>>>
Decodable
<
D
>
for
ty
::
Predicate
<
'tcx
>
{
fn
decode
(
decoder
:
&
mut
D
)
->
ty
::
Predicate
<
'tcx
>
{
let
predicate_kind
=
Decodable
::
decode
(
decoder
);
decoder
.interner
()
.
tcx
.
mk_predicate
(
predicate_kind
)
decoder
.interner
()
.mk_predicate
(
predicate_kind
)
}
}
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Interner
<
'tcx
>>>
Decodable
<
D
>
for
SubstsRef
<
'tcx
>
{
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Ctxt
<
'tcx
>>>
Decodable
<
D
>
for
SubstsRef
<
'tcx
>
{
fn
decode
(
decoder
:
&
mut
D
)
->
Self
{
let
len
=
decoder
.read_usize
();
let
tcx
=
decoder
.interner
()
.tcx
;
let
tcx
=
decoder
.interner
();
tcx
.mk_substs
(
(
0
..
len
)
.map
::
<
ty
::
subst
::
GenericArg
<
'tcx
>
,
_
>
(|
_
|
Decodable
::
decode
(
decoder
)),
)
}
}
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Interner
<
'tcx
>>>
Decodable
<
D
>
for
mir
::
Place
<
'tcx
>
{
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Ctxt
<
'tcx
>>>
Decodable
<
D
>
for
mir
::
Place
<
'tcx
>
{
fn
decode
(
decoder
:
&
mut
D
)
->
Self
{
let
local
:
mir
::
Local
=
Decodable
::
decode
(
decoder
);
let
len
=
decoder
.read_usize
();
let
projection
=
decoder
.interner
()
.
tcx
.
mk_place_elems
(
let
projection
=
decoder
.interner
()
.mk_place_elems
(
(
0
..
len
)
.map
::
<
mir
::
PlaceElem
<
'tcx
>
,
_
>
(|
_
|
Decodable
::
decode
(
decoder
)),
);
mir
::
Place
{
local
,
projection
}
}
}
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Interner
<
'tcx
>>>
Decodable
<
D
>
for
ty
::
Region
<
'tcx
>
{
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Ctxt
<
'tcx
>>>
Decodable
<
D
>
for
ty
::
Region
<
'tcx
>
{
fn
decode
(
decoder
:
&
mut
D
)
->
Self
{
decoder
.interner
()
.
tcx
.
mk_region
(
Decodable
::
decode
(
decoder
))
decoder
.interner
()
.mk_region
(
Decodable
::
decode
(
decoder
))
}
}
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Interner
<
'tcx
>>>
Decodable
<
D
>
for
CanonicalVarInfos
<
'tcx
>
{
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Ctxt
<
'tcx
>>>
Decodable
<
D
>
for
CanonicalVarInfos
<
'tcx
>
{
fn
decode
(
decoder
:
&
mut
D
)
->
Self
{
let
len
=
decoder
.read_usize
();
let
interned
:
Vec
<
CanonicalVarInfo
<
'tcx
>>
=
(
0
..
len
)
.map
(|
_
|
Decodable
::
decode
(
decoder
))
.collect
();
decoder
.interner
()
.
tcx
.
intern_canonical_var_infos
(
interned
.as_slice
())
decoder
.interner
()
.intern_canonical_var_infos
(
interned
.as_slice
())
}
}
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Interner
<
'tcx
>>>
Decodable
<
D
>
for
AllocId
{
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Ctxt
<
'tcx
>>>
Decodable
<
D
>
for
AllocId
{
fn
decode
(
decoder
:
&
mut
D
)
->
Self
{
decoder
.decode_alloc_id
()
}
}
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Interner
<
'tcx
>>>
Decodable
<
D
>
for
ty
::
SymbolName
<
'tcx
>
{
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Ctxt
<
'tcx
>>>
Decodable
<
D
>
for
ty
::
SymbolName
<
'tcx
>
{
fn
decode
(
decoder
:
&
mut
D
)
->
Self
{
ty
::
SymbolName
::
new
(
decoder
.interner
()
.tcx
,
&
decoder
.read_str
())
ty
::
SymbolName
::
new
(
decoder
.interner
(),
&
decoder
.read_str
())
}
}
macro_rules!
impl_decodable_via_ref
{
(
$
(
$t:ty
),
+
)
=>
{
$
(
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Interner
<
'tcx
>>>
Decodable
<
D
>
for
$t
{
$
(
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Ctxt
<
'tcx
>>>
Decodable
<
D
>
for
$t
{
fn
decode
(
decoder
:
&
mut
D
)
->
Self
{
RefDecodable
::
decode
(
decoder
)
}
...
...
@@ -298,89 +296,86 @@ fn decode(decoder: &mut D) -> Self {
}
}
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Interner
<
'tcx
>>>
RefDecodable
<
'tcx
,
D
>
for
ty
::
List
<
Ty
<
'tcx
>>
{
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Ctxt
<
'tcx
>>>
RefDecodable
<
'tcx
,
D
>
for
ty
::
List
<
Ty
<
'tcx
>>
{
fn
decode
(
decoder
:
&
mut
D
)
->
&
'tcx
Self
{
let
len
=
decoder
.read_usize
();
decoder
.interner
()
.tcx
.mk_type_list
((
0
..
len
)
.map
::
<
Ty
<
'tcx
>
,
_
>
(|
_
|
Decodable
::
decode
(
decoder
)))
decoder
.interner
()
.mk_type_list
((
0
..
len
)
.map
::
<
Ty
<
'tcx
>
,
_
>
(|
_
|
Decodable
::
decode
(
decoder
)))
}
}
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Interner
<
'tcx
>>>
RefDecodable
<
'tcx
,
D
>
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Ctxt
<
'tcx
>>>
RefDecodable
<
'tcx
,
D
>
for
ty
::
List
<
ty
::
Binder
<
'tcx
,
ty
::
ExistentialPredicate
<
'tcx
>>>
{
fn
decode
(
decoder
:
&
mut
D
)
->
&
'tcx
Self
{
let
len
=
decoder
.read_usize
();
decoder
.interner
()
.
tcx
.
mk_poly_existential_predicates
(
decoder
.interner
()
.mk_poly_existential_predicates
(
(
0
..
len
)
.map
::
<
ty
::
Binder
<
'tcx
,
_
>
,
_
>
(|
_
|
Decodable
::
decode
(
decoder
)),
)
}
}
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Interner
<
'tcx
>>>
Decodable
<
D
>
for
ty
::
Const
<
'tcx
>
{
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Ctxt
<
'tcx
>>>
Decodable
<
D
>
for
ty
::
Const
<
'tcx
>
{
fn
decode
(
decoder
:
&
mut
D
)
->
Self
{
decoder
.interner
()
.
tcx
.
mk_const
(
Decodable
::
decode
(
decoder
))
decoder
.interner
()
.mk_const
(
Decodable
::
decode
(
decoder
))
}
}
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Interner
<
'tcx
>>>
RefDecodable
<
'tcx
,
D
>
for
[
ty
::
ValTree
<
'tcx
>
]
{
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Ctxt
<
'tcx
>>>
RefDecodable
<
'tcx
,
D
>
for
[
ty
::
ValTree
<
'tcx
>
]
{
fn
decode
(
decoder
:
&
mut
D
)
->
&
'tcx
Self
{
decoder
.interner
()
.
tcx.
arena
.alloc_from_iter
(
decoder
.interner
()
.arena
.alloc_from_iter
(
(
0
..
decoder
.read_usize
())
.map
(|
_
|
Decodable
::
decode
(
decoder
))
.collect
::
<
Vec
<
_
>>
(),
)
}
}
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Interner
<
'tcx
>>>
Decodable
<
D
>
for
ConstAllocation
<
'tcx
>
{
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Ctxt
<
'tcx
>>>
Decodable
<
D
>
for
ConstAllocation
<
'tcx
>
{
fn
decode
(
decoder
:
&
mut
D
)
->
Self
{
decoder
.interner
()
.
tcx
.
intern_const_alloc
(
Decodable
::
decode
(
decoder
))
decoder
.interner
()
.intern_const_alloc
(
Decodable
::
decode
(
decoder
))
}
}
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Interner
<
'tcx
>>>
Decodable
<
D
>
for
AdtDef
<
'tcx
>
{
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Ctxt
<
'tcx
>>>
Decodable
<
D
>
for
AdtDef
<
'tcx
>
{
fn
decode
(
decoder
:
&
mut
D
)
->
Self
{
decoder
.interner
()
.
tcx
.
intern_adt_def
(
Decodable
::
decode
(
decoder
))
decoder
.interner
()
.intern_adt_def
(
Decodable
::
decode
(
decoder
))
}
}
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Interner
<
'tcx
>>>
RefDecodable
<
'tcx
,
D
>
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Ctxt
<
'tcx
>>>
RefDecodable
<
'tcx
,
D
>
for
[(
ty
::
Predicate
<
'tcx
>
,
Span
)]
{
fn
decode
(
decoder
:
&
mut
D
)
->
&
'tcx
Self
{
decoder
.interner
()
.
tcx.
arena
.alloc_from_iter
(
decoder
.interner
()
.arena
.alloc_from_iter
(
(
0
..
decoder
.read_usize
())
.map
(|
_
|
Decodable
::
decode
(
decoder
))
.collect
::
<
Vec
<
_
>>
(),
)
}
}
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Interner
<
'tcx
>>>
RefDecodable
<
'tcx
,
D
>
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Ctxt
<
'tcx
>>>
RefDecodable
<
'tcx
,
D
>
for
[
thir
::
abstract_const
::
Node
<
'tcx
>
]
{
fn
decode
(
decoder
:
&
mut
D
)
->
&
'tcx
Self
{
decoder
.interner
()
.
tcx.
arena
.alloc_from_iter
(
decoder
.interner
()
.arena
.alloc_from_iter
(
(
0
..
decoder
.read_usize
())
.map
(|
_
|
Decodable
::
decode
(
decoder
))
.collect
::
<
Vec
<
_
>>
(),
)
}
}
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Interner
<
'tcx
>>>
RefDecodable
<
'tcx
,
D
>
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Ctxt
<
'tcx
>>>
RefDecodable
<
'tcx
,
D
>
for
[
thir
::
abstract_const
::
NodeId
]
{
fn
decode
(
decoder
:
&
mut
D
)
->
&
'tcx
Self
{
decoder
.interner
()
.
tcx.
arena
.alloc_from_iter
(
decoder
.interner
()
.arena
.alloc_from_iter
(
(
0
..
decoder
.read_usize
())
.map
(|
_
|
Decodable
::
decode
(
decoder
))
.collect
::
<
Vec
<
_
>>
(),
)
}
}
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Interner
<
'tcx
>>>
RefDecodable
<
'tcx
,
D
>
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Ctxt
<
'tcx
>>>
RefDecodable
<
'tcx
,
D
>
for
ty
::
List
<
ty
::
BoundVariableKind
>
{
fn
decode
(
decoder
:
&
mut
D
)
->
&
'tcx
Self
{
let
len
=
decoder
.read_usize
();
decoder
.interner
()
.
tcx
.
mk_bound_variable_kinds
(
decoder
.interner
()
.mk_bound_variable_kinds
(
(
0
..
len
)
.map
::
<
ty
::
BoundVariableKind
,
_
>
(|
_
|
Decodable
::
decode
(
decoder
)),
)
}
...
...
@@ -414,14 +409,14 @@ fn $name(&mut self) -> $ty {
([]
$args:tt
)
=>
{};
([
decode
$
(,
$attrs:ident
)
*
]
[
$name:ident
:
$ty:ty
])
=>
{
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Interner
<
'tcx
>>>
RefDecodable
<
'tcx
,
D
>
for
$ty
{
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Ctxt
<
'tcx
>>>
RefDecodable
<
'tcx
,
D
>
for
$ty
{
#[inline]
fn
decode
(
decoder
:
&
mut
D
)
->
&
'tcx
Self
{
decode_arena_allocable
(
decoder
)
}
}
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Interner
<
'tcx
>>>
RefDecodable
<
'tcx
,
D
>
for
[
$ty
]
{
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Ctxt
<
'tcx
>>>
RefDecodable
<
'tcx
,
D
>
for
[
$ty
]
{
#[inline]
fn
decode
(
decoder
:
&
mut
D
)
->
&
'tcx
Self
{
decode_arena_allocable_slice
(
decoder
)
...
...
@@ -443,17 +438,17 @@ fn decode(decoder: &mut D) -> &'tcx Self {
macro_rules!
impl_arena_copy_decoder
{
(
<
$tcx:tt
>
$
(
$ty:ty
,)
*
)
=>
{
$
(
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Interner
<
'tcx
>>>
RefDecodable
<
'tcx
,
D
>
for
$ty
{
$
(
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Ctxt
<
'tcx
>>>
RefDecodable
<
'tcx
,
D
>
for
$ty
{
#[inline]
fn
decode
(
decoder
:
&
mut
D
)
->
&
'tcx
Self
{
decoder
.interner
()
.
tcx.
arena
.alloc
(
Decodable
::
decode
(
decoder
))
decoder
.interner
()
.arena
.alloc
(
Decodable
::
decode
(
decoder
))
}
}
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Interner
<
'tcx
>>>
RefDecodable
<
'tcx
,
D
>
for
[
$ty
]
{
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Ctxt
<
'tcx
>>>
RefDecodable
<
'tcx
,
D
>
for
[
$ty
]
{
#[inline]
fn
decode
(
decoder
:
&
mut
D
)
->
&
'tcx
Self
{
decoder
.interner
()
.
tcx.
arena
.alloc_from_iter
(
<
Vec
<
_
>
as
Decodable
<
D
>>
::
decode
(
decoder
))
decoder
.interner
()
.arena
.alloc_from_iter
(
<
Vec
<
_
>
as
Decodable
<
D
>>
::
decode
(
decoder
))
}
})
*
};
...
...
@@ -512,13 +507,13 @@ fn read_raw_bytes(&mut self, len: usize) -> &[u8] {
macro_rules!
impl_binder_encode_decode
{
(
$
(
$t:ty
),
+
$
(,)
?
)
=>
{
$
(
impl
<
'tcx
,
E
:
TyEncoder
<
I
=
Ty
Interner
<
'tcx
>>>
Encodable
<
E
>
for
ty
::
Binder
<
'tcx
,
$t
>
{
impl
<
'tcx
,
E
:
TyEncoder
<
I
=
Ty
Ctxt
<
'tcx
>>>
Encodable
<
E
>
for
ty
::
Binder
<
'tcx
,
$t
>
{
fn
encode
(
&
self
,
e
:
&
mut
E
)
->
Result
<
(),
E
::
Error
>
{
self
.bound_vars
()
.encode
(
e
)
?
;
self
.as_ref
()
.skip_binder
()
.encode
(
e
)
}
}
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Interner
<
'tcx
>>>
Decodable
<
D
>
for
ty
::
Binder
<
'tcx
,
$t
>
{
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Ctxt
<
'tcx
>>>
Decodable
<
D
>
for
ty
::
Binder
<
'tcx
,
$t
>
{
fn
decode
(
decoder
:
&
mut
D
)
->
Self
{
let
bound_vars
=
Decodable
::
decode
(
decoder
);
ty
::
Binder
::
bind_with_vars
(
Decodable
::
decode
(
decoder
),
bound_vars
)
...
...
compiler/rustc_middle/src/ty/context.rs
浏览文件 @
46389159
...
...
@@ -90,12 +90,8 @@ fn new_empty(source_map: &'tcx SourceMap) -> Self
fn
serialize
(
&
self
,
tcx
:
TyCtxt
<
'tcx
>
,
encoder
:
&
mut
FileEncoder
)
->
FileEncodeResult
;
}
pub
struct
TyInterner
<
'tcx
>
{
pub
tcx
:
TyCtxt
<
'tcx
>
,
}
#[allow(rustc::usage_of_ty_tykind)]
impl
<
'tcx
>
Interner
for
Ty
Interner
<
'tcx
>
{
impl
<
'tcx
>
Interner
for
Ty
Ctxt
<
'tcx
>
{
type
AdtDef
=
ty
::
AdtDef
<
'tcx
>
;
type
SubstsRef
=
ty
::
SubstsRef
<
'tcx
>
;
type
DefId
=
DefId
;
...
...
@@ -1103,11 +1099,6 @@ pub struct GlobalCtxt<'tcx> {
}
impl
<
'tcx
>
TyCtxt
<
'tcx
>
{
#[inline]
pub
fn
interner
(
self
)
->
TyInterner
<
'tcx
>
{
TyInterner
{
tcx
:
self
}
}
/// Expects a body and returns its codegen attributes.
///
/// Unlike `codegen_fn_attrs`, this returns `CodegenFnAttrs::EMPTY` for
...
...
compiler/rustc_middle/src/ty/mod.rs
浏览文件 @
46389159
...
...
@@ -68,8 +68,8 @@
pub
use
self
::
context
::{
tls
,
CanonicalUserType
,
CanonicalUserTypeAnnotation
,
CanonicalUserTypeAnnotations
,
CtxtInterners
,
DelaySpanBugEmitted
,
FreeRegionInfo
,
GeneratorDiagnosticData
,
GeneratorInteriorTypeCause
,
GlobalCtxt
,
Lift
,
OnDiskCache
,
TyCtxt
,
Ty
Interner
,
TypeckResults
,
UserType
,
UserType
AnnotationIndex
,
GeneratorInteriorTypeCause
,
GlobalCtxt
,
Lift
,
OnDiskCache
,
TyCtxt
,
Ty
peckResults
,
UserType
,
UserTypeAnnotationIndex
,
};
pub
use
self
::
instance
::{
Instance
,
InstanceDef
};
pub
use
self
::
list
::
List
;
...
...
@@ -463,30 +463,17 @@ pub(crate) struct TyS<'tcx> {
#[rustc_pass_by_value]
pub
struct
Ty
<
'tcx
>
(
Interned
<
'tcx
,
WithStableHash
<
TyS
<
'tcx
>>>
);
static
LEAKED_BOOL_TY_ALREADY
:
std
::
sync
::
atomic
::
AtomicBool
=
std
::
sync
::
atomic
::
AtomicBool
::
new
(
false
);
/// "Static" bool only used for internal testing.
///
/// FIXME(rustc_type_ir): This really should be replaced with something that doesn't leak.
/// however, since it's used for testing, it's not _that_ bad.
pub
fn
leak_bool_ty_for_unit_testing
<
'tcx
>
()
->
Ty
<
'tcx
>
{
use
std
::
sync
::
atomic
::
*
;
if
LEAKED_BOOL_TY_ALREADY
.load
(
Ordering
::
Acquire
)
{
panic!
(
"Can only leak one bool type, since its equality depends on its address"
);
}
else
{
LEAKED_BOOL_TY_ALREADY
.store
(
true
,
Ordering
::
Release
);
}
Ty
(
Interned
::
new_unchecked
(
Box
::
leak
(
Box
::
new
(
WithStableHash
{
impl
<
'tcx
>
TyCtxt
<
'tcx
>
{
/// A "bool" type used in rustc_mir_transform unit tests when we
/// have not spun up a TyCtxt.
pub
const
BOOL_TY_FOR_UNIT_TESTING
:
Ty
<
'tcx
>
=
Ty
(
Interned
::
new_unchecked
(
&
WithStableHash
{
internee
:
TyS
{
kind
:
ty
::
Bool
,
flags
:
TypeFlags
::
empty
(),
outer_exclusive_binder
:
DebruijnIndex
::
from_usize
(
0
),
},
stable_hash
:
Fingerprint
::
ZERO
,
}))
))
}))
;
}
impl
<
'a
,
'tcx
>
HashStable
<
StableHashingContext
<
'a
>>
for
TyS
<
'tcx
>
{
...
...
compiler/rustc_middle/src/ty/sty.rs
浏览文件 @
46389159
...
...
@@ -32,7 +32,7 @@
// Re-export the `TyKind` from `rustc_type_ir` here for convenience
#[rustc_diagnostic_item
=
"TyKind"
]
pub
type
TyKind
<
'tcx
>
=
IrTyKind
<
ty
::
TyInterner
<
'tcx
>>
;
pub
type
TyKind
<
'tcx
>
=
IrTyKind
<
TyCtxt
<
'tcx
>>
;
#[derive(Clone,
Copy,
PartialEq,
Eq,
PartialOrd,
Ord,
Hash,
Debug,
TyEncodable,
TyDecodable)]
#[derive(HashStable,
TypeFoldable,
Lift)]
...
...
compiler/rustc_middle/src/ty/subst.rs
浏览文件 @
46389159
...
...
@@ -4,7 +4,7 @@
use
crate
::
ty
::
codec
::{
TyDecoder
,
TyEncoder
};
use
crate
::
ty
::
fold
::{
FallibleTypeFolder
,
TypeFoldable
,
TypeFolder
,
TypeVisitor
};
use
crate
::
ty
::
sty
::{
ClosureSubsts
,
GeneratorSubsts
,
InlineConstSubsts
};
use
crate
::
ty
::{
self
,
Lift
,
List
,
ParamConst
,
Ty
,
TyCtxt
,
TyInterner
};
use
crate
::
ty
::{
self
,
Lift
,
List
,
ParamConst
,
Ty
,
TyCtxt
};
use
rustc_data_structures
::
intern
::{
Interned
,
WithStableHash
};
use
rustc_hir
::
def_id
::
DefId
;
...
...
@@ -216,13 +216,13 @@ fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow
}
}
impl
<
'tcx
,
E
:
TyEncoder
<
I
=
Ty
Interner
<
'tcx
>>>
Encodable
<
E
>
for
GenericArg
<
'tcx
>
{
impl
<
'tcx
,
E
:
TyEncoder
<
I
=
Ty
Ctxt
<
'tcx
>>>
Encodable
<
E
>
for
GenericArg
<
'tcx
>
{
fn
encode
(
&
self
,
e
:
&
mut
E
)
->
Result
<
(),
E
::
Error
>
{
self
.unpack
()
.encode
(
e
)
}
}
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Interner
<
'tcx
>>>
Decodable
<
D
>
for
GenericArg
<
'tcx
>
{
impl
<
'tcx
,
D
:
TyDecoder
<
I
=
Ty
Ctxt
<
'tcx
>>>
Decodable
<
D
>
for
GenericArg
<
'tcx
>
{
fn
decode
(
d
:
&
mut
D
)
->
GenericArg
<
'tcx
>
{
GenericArgKind
::
decode
(
d
)
.pack
()
}
...
...
compiler/rustc_mir_transform/src/coverage/tests.rs
浏览文件 @
46389159
...
...
@@ -37,7 +37,7 @@
use
rustc_index
::
vec
::{
Idx
,
IndexVec
};
use
rustc_middle
::
mir
::
coverage
::
CoverageKind
;
use
rustc_middle
::
mir
::
*
;
use
rustc_middle
::
ty
::{
self
,
Ty
};
use
rustc_middle
::
ty
::{
self
,
Ty
,
TyCtxt
};
use
rustc_span
::{
self
,
BytePos
,
Pos
,
Span
,
DUMMY_SP
};
// All `TEMP_BLOCK` targets should be replaced before calling `to_body() -> mir::Body`.
...
...
@@ -56,7 +56,7 @@ fn new() -> Self {
blocks
:
IndexVec
::
new
(),
dummy_place
:
Place
{
local
:
RETURN_PLACE
,
projection
:
ty
::
List
::
empty
()
},
next_local
:
0
,
bool_ty
:
ty
::
leak_bool_ty_for_unit_testing
()
,
bool_ty
:
TyCtxt
::
BOOL_TY_FOR_UNIT_TESTING
,
}
}
...
...
compiler/rustc_query_impl/src/on_disk_cache.rs
浏览文件 @
46389159
...
...
@@ -11,7 +11,7 @@
use
rustc_middle
::
mir
::{
self
,
interpret
};
use
rustc_middle
::
thir
;
use
rustc_middle
::
ty
::
codec
::{
RefDecodable
,
TyDecoder
,
TyEncoder
};
use
rustc_middle
::
ty
::{
self
,
Ty
,
TyCtxt
,
TyInterner
};
use
rustc_middle
::
ty
::{
self
,
Ty
,
TyCtxt
};
use
rustc_query_system
::
dep_graph
::
DepContext
;
use
rustc_query_system
::
query
::{
QueryCache
,
QueryContext
,
QuerySideEffects
};
use
rustc_serialize
::{
...
...
@@ -548,12 +548,12 @@ fn decode_tagged<D, T, V>(decoder: &mut D, expected_tag: T) -> V
}
impl
<
'a
,
'tcx
>
TyDecoder
for
CacheDecoder
<
'a
,
'tcx
>
{
type
I
=
Ty
Interner
<
'tcx
>
;
type
I
=
Ty
Ctxt
<
'tcx
>
;
const
CLEAR_CROSS_CRATE
:
bool
=
false
;
#[inline]
fn
interner
(
&
self
)
->
Ty
Interner
<
'tcx
>
{
TyInterner
{
tcx
:
self
.tcx
}
fn
interner
(
&
self
)
->
Ty
Ctxt
<
'tcx
>
{
self
.tcx
}
#[inline]
...
...
@@ -932,7 +932,7 @@ impl<'a, 'tcx, E> TyEncoder for CacheEncoder<'a, 'tcx, E>
where
E
:
'a
+
OpaqueEncoder
,
{
type
I
=
Ty
Interner
<
'tcx
>
;
type
I
=
Ty
Ctxt
<
'tcx
>
;
const
CLEAR_CROSS_CRATE
:
bool
=
false
;
fn
position
(
&
self
)
->
usize
{
...
...
compiler/rustc_query_system/src/ich/mod.rs
浏览文件 @
46389159
//! ICH - Incremental Compilation Hash
pub
use
self
::
hcx
::
StableHashingContext
;
use
rustc_data_structures
::
stable_hasher
::
HashStable
;
use
rustc_span
::
symbol
::{
sym
,
Symbol
};
mod
hcx
;
...
...
@@ -18,124 +17,3 @@
sym
::
rustc_partition_codegened
,
sym
::
rustc_expected_cgu_reuse
,
];
#[allow(rustc::usage_of_ty_tykind)]
impl
<
'__ctx
,
I
:
rustc_type_ir
::
Interner
>
HashStable
<
StableHashingContext
<
'__ctx
>>
for
rustc_type_ir
::
TyKind
<
I
>
where
I
::
AdtDef
:
HashStable
<
StableHashingContext
<
'__ctx
>>
,
I
::
DefId
:
HashStable
<
StableHashingContext
<
'__ctx
>>
,
I
::
SubstsRef
:
HashStable
<
StableHashingContext
<
'__ctx
>>
,
I
::
Ty
:
HashStable
<
StableHashingContext
<
'__ctx
>>
,
I
::
Const
:
HashStable
<
StableHashingContext
<
'__ctx
>>
,
I
::
TypeAndMut
:
HashStable
<
StableHashingContext
<
'__ctx
>>
,
I
::
PolyFnSig
:
HashStable
<
StableHashingContext
<
'__ctx
>>
,
I
::
ListBinderExistentialPredicate
:
HashStable
<
StableHashingContext
<
'__ctx
>>
,
I
::
Region
:
HashStable
<
StableHashingContext
<
'__ctx
>>
,
I
::
Movability
:
HashStable
<
StableHashingContext
<
'__ctx
>>
,
I
::
Mutability
:
HashStable
<
StableHashingContext
<
'__ctx
>>
,
I
::
BinderListTy
:
HashStable
<
StableHashingContext
<
'__ctx
>>
,
I
::
ListTy
:
HashStable
<
StableHashingContext
<
'__ctx
>>
,
I
::
ProjectionTy
:
HashStable
<
StableHashingContext
<
'__ctx
>>
,
I
::
BoundTy
:
HashStable
<
StableHashingContext
<
'__ctx
>>
,
I
::
ParamTy
:
HashStable
<
StableHashingContext
<
'__ctx
>>
,
I
::
PlaceholderType
:
HashStable
<
StableHashingContext
<
'__ctx
>>
,
I
::
InferTy
:
HashStable
<
StableHashingContext
<
'__ctx
>>
,
I
::
DelaySpanBugEmitted
:
HashStable
<
StableHashingContext
<
'__ctx
>>
,
{
#[inline]
fn
hash_stable
(
&
self
,
__
hcx
:
&
mut
crate
::
ich
::
StableHashingContext
<
'__ctx
>
,
__
hasher
:
&
mut
rustc_data_structures
::
stable_hasher
::
StableHasher
,
)
{
std
::
mem
::
discriminant
(
self
)
.hash_stable
(
__
hcx
,
__
hasher
);
use
rustc_type_ir
::
TyKind
::
*
;
match
self
{
Bool
=>
{}
Char
=>
{}
Int
(
i
)
=>
{
i
.hash_stable
(
__
hcx
,
__
hasher
);
}
Uint
(
u
)
=>
{
u
.hash_stable
(
__
hcx
,
__
hasher
);
}
Float
(
f
)
=>
{
f
.hash_stable
(
__
hcx
,
__
hasher
);
}
Adt
(
adt
,
substs
)
=>
{
adt
.hash_stable
(
__
hcx
,
__
hasher
);
substs
.hash_stable
(
__
hcx
,
__
hasher
);
}
Foreign
(
def_id
)
=>
{
def_id
.hash_stable
(
__
hcx
,
__
hasher
);
}
Str
=>
{}
Array
(
t
,
c
)
=>
{
t
.hash_stable
(
__
hcx
,
__
hasher
);
c
.hash_stable
(
__
hcx
,
__
hasher
);
}
Slice
(
t
)
=>
{
t
.hash_stable
(
__
hcx
,
__
hasher
);
}
RawPtr
(
tam
)
=>
{
tam
.hash_stable
(
__
hcx
,
__
hasher
);
}
Ref
(
r
,
t
,
m
)
=>
{
r
.hash_stable
(
__
hcx
,
__
hasher
);
t
.hash_stable
(
__
hcx
,
__
hasher
);
m
.hash_stable
(
__
hcx
,
__
hasher
);
}
FnDef
(
def_id
,
substs
)
=>
{
def_id
.hash_stable
(
__
hcx
,
__
hasher
);
substs
.hash_stable
(
__
hcx
,
__
hasher
);
}
FnPtr
(
polyfnsig
)
=>
{
polyfnsig
.hash_stable
(
__
hcx
,
__
hasher
);
}
Dynamic
(
l
,
r
)
=>
{
l
.hash_stable
(
__
hcx
,
__
hasher
);
r
.hash_stable
(
__
hcx
,
__
hasher
);
}
Closure
(
def_id
,
substs
)
=>
{
def_id
.hash_stable
(
__
hcx
,
__
hasher
);
substs
.hash_stable
(
__
hcx
,
__
hasher
);
}
Generator
(
def_id
,
substs
,
m
)
=>
{
def_id
.hash_stable
(
__
hcx
,
__
hasher
);
substs
.hash_stable
(
__
hcx
,
__
hasher
);
m
.hash_stable
(
__
hcx
,
__
hasher
);
}
GeneratorWitness
(
b
)
=>
{
b
.hash_stable
(
__
hcx
,
__
hasher
);
}
Never
=>
{}
Tuple
(
substs
)
=>
{
substs
.hash_stable
(
__
hcx
,
__
hasher
);
}
Projection
(
p
)
=>
{
p
.hash_stable
(
__
hcx
,
__
hasher
);
}
Opaque
(
def_id
,
substs
)
=>
{
def_id
.hash_stable
(
__
hcx
,
__
hasher
);
substs
.hash_stable
(
__
hcx
,
__
hasher
);
}
Param
(
p
)
=>
{
p
.hash_stable
(
__
hcx
,
__
hasher
);
}
Bound
(
d
,
b
)
=>
{
d
.hash_stable
(
__
hcx
,
__
hasher
);
b
.hash_stable
(
__
hcx
,
__
hasher
);
}
Placeholder
(
p
)
=>
{
p
.hash_stable
(
__
hcx
,
__
hasher
);
}
Infer
(
i
)
=>
{
i
.hash_stable
(
__
hcx
,
__
hasher
);
}
Error
(
d
)
=>
{
d
.hash_stable
(
__
hcx
,
__
hasher
);
}
}
}
}
compiler/rustc_type_ir/src/lib.rs
浏览文件 @
46389159
...
...
@@ -8,7 +8,6 @@
use
rustc_data_structures
::
stable_hasher
::{
HashStable
,
StableHasher
};
use
rustc_data_structures
::
unify
::{
EqUnifyValue
,
UnifyKey
};
//use rustc_serialize::{Decodable, Encodable};
use
smallvec
::
SmallVec
;
use
std
::
fmt
;
use
std
::
fmt
::
Debug
;
...
...
compiler/rustc_type_ir/src/sty.rs
浏览文件 @
46389159
...
...
@@ -13,6 +13,7 @@
use
self
::
TyKind
::
*
;
use
rustc_data_structures
::
stable_hasher
::
HashStable
;
use
rustc_serialize
::{
Decodable
,
Encodable
};
/// Defines the kinds of types used by the type system.
...
...
@@ -198,7 +199,10 @@ pub fn is_primitive(&self) -> bool {
}
}
fn
discriminant
<
I
:
Interner
>
(
value
:
&
TyKind
<
I
>
)
->
usize
{
// This is manually implemented for `TyKind` because `std::mem::discriminant`
// returns an opaque value that is `PartialEq` but not `PartialOrd`
#[inline]
const
fn
discriminant
<
I
:
Interner
>
(
value
:
&
TyKind
<
I
>
)
->
usize
{
match
value
{
Bool
=>
0
,
Char
=>
1
,
...
...
@@ -230,6 +234,7 @@ fn discriminant<I: Interner>(value: &TyKind<I>) -> usize {
}
}
// This is manually implemented because a derive would require `I: Clone`
impl
<
I
:
Interner
>
Clone
for
TyKind
<
I
>
{
fn
clone
(
&
self
)
->
Self
{
match
self
{
...
...
@@ -264,6 +269,7 @@ fn clone(&self) -> Self {
}
}
// This is manually implemented because a derive would require `I: PartialEq`
impl
<
I
:
Interner
>
PartialEq
for
TyKind
<
I
>
{
#[inline]
fn
eq
(
&
self
,
other
:
&
TyKind
<
I
>
)
->
bool
{
...
...
@@ -324,8 +330,10 @@ fn eq(&self, other: &TyKind<I>) -> bool {
}
}
// This is manually implemented because a derive would require `I: Eq`
impl
<
I
:
Interner
>
Eq
for
TyKind
<
I
>
{}
// This is manually implemented because a derive would require `I: PartialOrd`
impl
<
I
:
Interner
>
PartialOrd
for
TyKind
<
I
>
{
#[inline]
fn
partial_cmp
(
&
self
,
other
:
&
TyKind
<
I
>
)
->
Option
<
Ordering
>
{
...
...
@@ -333,6 +341,7 @@ fn partial_cmp(&self, other: &TyKind<I>) -> Option<Ordering> {
}
}
// This is manually implemented because a derive would require `I: Ord`
impl
<
I
:
Interner
>
Ord
for
TyKind
<
I
>
{
#[inline]
fn
cmp
(
&
self
,
other
:
&
TyKind
<
I
>
)
->
Ordering
{
...
...
@@ -430,6 +439,7 @@ fn cmp(&self, other: &TyKind<I>) -> Ordering {
}
}
// This is manually implemented because a derive would require `I: Hash`
impl
<
I
:
Interner
>
hash
::
Hash
for
TyKind
<
I
>
{
fn
hash
<
__
H
:
hash
::
Hasher
>
(
&
self
,
state
:
&
mut
__
H
)
->
()
{
match
(
&*
self
,)
{
...
...
@@ -541,6 +551,7 @@ fn hash<__H: hash::Hasher>(&self, state: &mut __H) -> () {
}
}
// This is manually implemented because a derive would require `I: Debug`
impl
<
I
:
Interner
>
fmt
::
Debug
for
TyKind
<
I
>
{
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
<
'_
>
)
->
fmt
::
Result
{
match
(
&*
self
,)
{
...
...
@@ -678,6 +689,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
}
}
// This is manually implemented because a derive would require `I: Encodable`
impl
<
I
:
Interner
,
E
:
TyEncoder
>
Encodable
<
E
>
for
TyKind
<
I
>
where
I
::
DelaySpanBugEmitted
:
Encodable
<
E
>
,
...
...
@@ -819,6 +831,7 @@ fn encode(&self, e: &mut E) -> Result<(), <E as rustc_serialize::Encoder>::Error
}
}
// This is manually implemented because a derive would require `I: Decodable`
impl
<
I
:
Interner
,
D
:
TyDecoder
<
I
=
I
>>
Decodable
<
D
>
for
TyKind
<
I
>
where
I
::
DelaySpanBugEmitted
:
Decodable
<
D
>
,
...
...
@@ -905,3 +918,123 @@ fn decode(d: &mut D) -> Self {
}
}
}
// This is not a derived impl because a derive would require `I: HashStable`
#[allow(rustc::usage_of_ty_tykind)]
impl
<
CTX
,
I
:
Interner
>
HashStable
<
CTX
>
for
TyKind
<
I
>
where
I
::
AdtDef
:
HashStable
<
CTX
>
,
I
::
DefId
:
HashStable
<
CTX
>
,
I
::
SubstsRef
:
HashStable
<
CTX
>
,
I
::
Ty
:
HashStable
<
CTX
>
,
I
::
Const
:
HashStable
<
CTX
>
,
I
::
TypeAndMut
:
HashStable
<
CTX
>
,
I
::
PolyFnSig
:
HashStable
<
CTX
>
,
I
::
ListBinderExistentialPredicate
:
HashStable
<
CTX
>
,
I
::
Region
:
HashStable
<
CTX
>
,
I
::
Movability
:
HashStable
<
CTX
>
,
I
::
Mutability
:
HashStable
<
CTX
>
,
I
::
BinderListTy
:
HashStable
<
CTX
>
,
I
::
ListTy
:
HashStable
<
CTX
>
,
I
::
ProjectionTy
:
HashStable
<
CTX
>
,
I
::
BoundTy
:
HashStable
<
CTX
>
,
I
::
ParamTy
:
HashStable
<
CTX
>
,
I
::
PlaceholderType
:
HashStable
<
CTX
>
,
I
::
InferTy
:
HashStable
<
CTX
>
,
I
::
DelaySpanBugEmitted
:
HashStable
<
CTX
>
,
{
#[inline]
fn
hash_stable
(
&
self
,
__
hcx
:
&
mut
CTX
,
__
hasher
:
&
mut
rustc_data_structures
::
stable_hasher
::
StableHasher
,
)
{
std
::
mem
::
discriminant
(
self
)
.hash_stable
(
__
hcx
,
__
hasher
);
match
self
{
Bool
=>
{}
Char
=>
{}
Int
(
i
)
=>
{
i
.hash_stable
(
__
hcx
,
__
hasher
);
}
Uint
(
u
)
=>
{
u
.hash_stable
(
__
hcx
,
__
hasher
);
}
Float
(
f
)
=>
{
f
.hash_stable
(
__
hcx
,
__
hasher
);
}
Adt
(
adt
,
substs
)
=>
{
adt
.hash_stable
(
__
hcx
,
__
hasher
);
substs
.hash_stable
(
__
hcx
,
__
hasher
);
}
Foreign
(
def_id
)
=>
{
def_id
.hash_stable
(
__
hcx
,
__
hasher
);
}
Str
=>
{}
Array
(
t
,
c
)
=>
{
t
.hash_stable
(
__
hcx
,
__
hasher
);
c
.hash_stable
(
__
hcx
,
__
hasher
);
}
Slice
(
t
)
=>
{
t
.hash_stable
(
__
hcx
,
__
hasher
);
}
RawPtr
(
tam
)
=>
{
tam
.hash_stable
(
__
hcx
,
__
hasher
);
}
Ref
(
r
,
t
,
m
)
=>
{
r
.hash_stable
(
__
hcx
,
__
hasher
);
t
.hash_stable
(
__
hcx
,
__
hasher
);
m
.hash_stable
(
__
hcx
,
__
hasher
);
}
FnDef
(
def_id
,
substs
)
=>
{
def_id
.hash_stable
(
__
hcx
,
__
hasher
);
substs
.hash_stable
(
__
hcx
,
__
hasher
);
}
FnPtr
(
polyfnsig
)
=>
{
polyfnsig
.hash_stable
(
__
hcx
,
__
hasher
);
}
Dynamic
(
l
,
r
)
=>
{
l
.hash_stable
(
__
hcx
,
__
hasher
);
r
.hash_stable
(
__
hcx
,
__
hasher
);
}
Closure
(
def_id
,
substs
)
=>
{
def_id
.hash_stable
(
__
hcx
,
__
hasher
);
substs
.hash_stable
(
__
hcx
,
__
hasher
);
}
Generator
(
def_id
,
substs
,
m
)
=>
{
def_id
.hash_stable
(
__
hcx
,
__
hasher
);
substs
.hash_stable
(
__
hcx
,
__
hasher
);
m
.hash_stable
(
__
hcx
,
__
hasher
);
}
GeneratorWitness
(
b
)
=>
{
b
.hash_stable
(
__
hcx
,
__
hasher
);
}
Never
=>
{}
Tuple
(
substs
)
=>
{
substs
.hash_stable
(
__
hcx
,
__
hasher
);
}
Projection
(
p
)
=>
{
p
.hash_stable
(
__
hcx
,
__
hasher
);
}
Opaque
(
def_id
,
substs
)
=>
{
def_id
.hash_stable
(
__
hcx
,
__
hasher
);
substs
.hash_stable
(
__
hcx
,
__
hasher
);
}
Param
(
p
)
=>
{
p
.hash_stable
(
__
hcx
,
__
hasher
);
}
Bound
(
d
,
b
)
=>
{
d
.hash_stable
(
__
hcx
,
__
hasher
);
b
.hash_stable
(
__
hcx
,
__
hasher
);
}
Placeholder
(
p
)
=>
{
p
.hash_stable
(
__
hcx
,
__
hasher
);
}
Infer
(
i
)
=>
{
i
.hash_stable
(
__
hcx
,
__
hasher
);
}
Error
(
d
)
=>
{
d
.hash_stable
(
__
hcx
,
__
hasher
);
}
}
}
}
compiler/rustc_typeck/src/check/op.rs
浏览文件 @
46389159
...
...
@@ -677,8 +677,6 @@ pub fn check_user_unop(
operand_ty
:
Ty
<
'tcx
>
,
op
:
hir
::
UnOp
,
)
->
Ty
<
'tcx
>
{
use
rustc_type_ir
::
sty
::
TyKind
::
*
;
assert
!
(
op
.is_by_value
());
match
self
.lookup_op_method
(
operand_ty
,
None
,
None
,
Op
::
Unary
(
op
,
ex
.span
))
{
Ok
(
method
)
=>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录