Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
e00bec2d
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,发现更多精彩内容 >>
提交
e00bec2d
编写于
6月 30, 2017
作者:
M
Michael Woerister
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Allow 'tcx in define_dep_nodes! and deduplicate some DepNodes.
上级
9808661b
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
58 addition
and
72 deletion
+58
-72
src/librustc/dep_graph/dep_node.rs
src/librustc/dep_graph/dep_node.rs
+17
-15
src/librustc/ty/instance.rs
src/librustc/ty/instance.rs
+0
-22
src/librustc/ty/maps.rs
src/librustc/ty/maps.rs
+39
-33
src/librustc_metadata/cstore_impl.rs
src/librustc_metadata/cstore_impl.rs
+2
-2
未找到文件。
src/librustc/dep_graph/dep_node.rs
浏览文件 @
e00bec2d
...
...
@@ -64,7 +64,8 @@
use
hir
::
map
::
DefPathHash
;
use
ich
::
Fingerprint
;
use
ty
::
TyCtxt
;
use
ty
::
fast_reject
::
SimplifiedType
;
use
ty
::{
TyCtxt
,
Instance
,
InstanceDef
};
use
rustc_data_structures
::
stable_hasher
::{
StableHasher
,
HashStable
};
use
ich
::
StableHashingContext
;
use
std
::
fmt
;
...
...
@@ -78,7 +79,8 @@
}
macro_rules!
define_dep_nodes
{
(
$
(
(
<
$tcx:tt
>
$
(
$variant:ident
$
((
$
(
$tuple_arg:tt
),
*
))
*
$
({
$
(
$struct_arg_name:ident
:
$struct_arg_ty:ty
),
*
})
*
,)
*
...
...
@@ -92,7 +94,7 @@ pub enum DepKind {
impl
DepKind
{
#[allow(unreachable_code)]
#[inline]
pub
fn
can_reconstruct_query_key
(
&
self
)
->
bool
{
pub
fn
can_reconstruct_query_key
<
$tcx
>
(
&
self
)
->
bool
{
match
*
self
{
$
(
DepKind
::
$variant
=>
{
...
...
@@ -139,7 +141,7 @@ pub fn has_params(&self) -> bool {
}
}
pub
enum
DepConstructor
{
pub
enum
DepConstructor
<
$tcx
>
{
$
(
$variant
$
((
$
(
$tuple_arg
),
*
))
*
$
({
$
(
$struct_arg_name
:
$struct_arg_ty
),
*
})
*
...
...
@@ -155,7 +157,7 @@ pub struct DepNode {
impl
DepNode
{
#[allow(unreachable_code,
non_snake_case)]
pub
fn
new
(
tcx
:
TyCtxt
,
dep
:
DepConstructor
)
->
DepNode
{
pub
fn
new
<
'a
,
'gcx
:
'a
+
'tcx
,
'tcx
:
'a
>
(
tcx
:
TyCtxt
<
'a
,
'gcx
,
'tcx
>
,
dep
:
DepConstructor
<
'gcx
>
)
->
DepNode
{
match
dep
{
$
(
DepConstructor
::
$variant
$
((
$
(
$tuple_arg
),
*
))
*
...
...
@@ -336,7 +338,7 @@ pub fn to_dep_node(self, tcx: TyCtxt, kind: DepKind) -> DepNode {
}
}
define_dep_nodes!
(
define_dep_nodes!
(
<
'tcx
>
// Represents the `Krate` as a whole (the `hir::Krate` value) (as
// distinct from the krate module). This is basically a hash of
// the entire krate, so if you read from `Krate` (e.g., by calling
...
...
@@ -374,8 +376,11 @@ pub fn to_dep_node(self, tcx: TyCtxt, kind: DepKind) -> DepNode {
// Represents the MIR for a fn; also used as the task node for
// things read/modify that MIR.
Mir
(
DefId
),
MirShim
(
DefIdList
),
MirConstQualif
(
DefId
),
MirConst
(
DefId
),
MirValidated
(
DefId
),
MirOptimized
(
DefId
),
MirShim
{
instance_def
:
InstanceDef
<
'tcx
>
},
BorrowCheckKrate
,
BorrowCheck
(
DefId
),
...
...
@@ -414,8 +419,10 @@ pub fn to_dep_node(self, tcx: TyCtxt, kind: DepKind) -> DepNode {
InherentImpls
(
DefId
),
TypeckBodiesKrate
,
TypeckTables
(
DefId
),
HasTypeckTables
(
DefId
),
ConstEval
(
DefId
),
SymbolName
(
DefId
),
InstanceSymbolName
{
instance
:
Instance
<
'tcx
>
},
SpecializationGraph
(
DefId
),
ObjectSafety
(
DefId
),
IsCopy
(
DefId
),
...
...
@@ -424,14 +431,9 @@ pub fn to_dep_node(self, tcx: TyCtxt, kind: DepKind) -> DepNode {
NeedsDrop
(
DefId
),
Layout
(
DefId
),
// The set of impls for a given trait. Ultimately, it would be
// nice to get more fine-grained here (e.g., to include a
// simplified type), but we can't do that until we restructure the
// HIR to distinguish the *header* of an impl from its body. This
// is because changes to the header may change the self-type of
// the impl and hence would require us to be more conservative
// than changes in the impl body.
// The set of impls for a given trait.
TraitImpls
(
DefId
),
RelevantTraitImpls
(
DefId
,
SimplifiedType
),
AllLocalTraitImpls
,
...
...
src/librustc/ty/instance.rs
浏览文件 @
e00bec2d
...
...
@@ -8,7 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use
dep_graph
::
DepConstructor
;
use
hir
::
def_id
::
DefId
;
use
ty
::{
self
,
Ty
,
TypeFoldable
,
Substs
};
use
util
::
ppaux
;
...
...
@@ -59,27 +58,6 @@ pub fn def_ty<'a>(&self, tcx: ty::TyCtxt<'a, 'tcx, 'tcx>) -> Ty<'tcx> {
pub
fn
attrs
<
'a
>
(
&
self
,
tcx
:
ty
::
TyCtxt
<
'a
,
'tcx
,
'tcx
>
)
->
ty
::
Attributes
<
'tcx
>
{
tcx
.get_attrs
(
self
.def_id
())
}
pub
//(crate)
fn
dep_node
(
&
self
)
->
DepConstructor
{
// HACK: def-id binning, project-style; someone replace this with
// real on-demand.
let
ty
=
match
self
{
&
InstanceDef
::
FnPtrShim
(
_
,
ty
)
=>
Some
(
ty
),
&
InstanceDef
::
DropGlue
(
_
,
ty
)
=>
ty
,
_
=>
None
}
.into_iter
();
DepConstructor
::
MirShim
(
Some
(
self
.def_id
())
.into_iter
()
.chain
(
ty
.flat_map
(|
t
|
t
.walk
())
.flat_map
(|
t
|
match
t
.sty
{
ty
::
TyAdt
(
adt_def
,
_
)
=>
Some
(
adt_def
.did
),
ty
::
TyProjection
(
ref
proj
)
=>
Some
(
proj
.trait_ref.def_id
),
_
=>
None
,
})
)
.collect
()
)
}
}
impl
<
'tcx
>
fmt
::
Display
for
Instance
<
'tcx
>
{
...
...
src/librustc/ty/maps.rs
浏览文件 @
e00bec2d
...
...
@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use
dep_graph
::{
DepConstructor
,
DepNode
,
DepTrackingMapConfig
};
use
dep_graph
::{
DepConstructor
,
DepNode
};
use
hir
::
def_id
::{
CrateNum
,
CRATE_DEF_INDEX
,
DefId
,
LOCAL_CRATE
};
use
hir
::
def
::
Def
;
use
hir
;
...
...
@@ -261,11 +261,16 @@ fn cycle_check<F, R>(self, span: Span, query: Query<'gcx>, compute: F)
}
}
trait
QueryDescription
:
DepTrackingMapConfig
{
pub
trait
QueryConfig
{
type
Key
:
Eq
+
Hash
+
Clone
;
type
Value
;
}
trait
QueryDescription
:
QueryConfig
{
fn
describe
(
tcx
:
TyCtxt
,
key
:
Self
::
Key
)
->
String
;
}
impl
<
M
:
DepTrackingMap
Config
<
Key
=
DefId
>>
QueryDescription
for
M
{
impl
<
M
:
Query
Config
<
Key
=
DefId
>>
QueryDescription
for
M
{
default
fn
describe
(
tcx
:
TyCtxt
,
def_id
:
DefId
)
->
String
{
format!
(
"processing `{}`"
,
tcx
.item_path_str
(
def_id
))
}
...
...
@@ -550,18 +555,19 @@ pub struct $name<$tcx> {
})
*
}
$
(
impl
<
$tcx
>
DepTrackingMap
Config
for
queries
::
$name
<
$tcx
>
{
$
(
impl
<
$tcx
>
Query
Config
for
queries
::
$name
<
$tcx
>
{
type
Key
=
$K
;
type
Value
=
$V
;
}
impl
<
'a
,
$tcx
,
'lcx
>
queries
::
$name
<
$tcx
>
{
#[allow(unused)]
fn
to_dep_node
(
tcx
:
TyCtxt
,
key
:
&
$K
)
->
DepNode
{
fn
to_dep_node
(
tcx
:
TyCtxt
<
'a
,
$tcx
,
'lcx
>
,
key
:
&
$K
)
->
DepNode
{
use
dep_graph
::
DepConstructor
::
*
;
DepNode
::
new
(
tcx
,
$node
(
*
key
))
}
}
impl
<
'a
,
$tcx
,
'lcx
>
queries
::
$name
<
$tcx
>
{
fn
try_get_with
<
F
,
R
>
(
tcx
:
TyCtxt
<
'a
,
$tcx
,
'lcx
>
,
mut
span
:
Span
,
key
:
$K
,
...
...
@@ -861,19 +867,19 @@ fn default() -> Self {
/// Maps DefId's that have an associated Mir to the result
/// of the MIR qualify_consts pass. The actual meaning of
/// the value isn't known except to the pass itself.
[]
mir_const_qualif
:
Mir
(
DefId
)
->
u8
,
[]
mir_const_qualif
:
Mir
ConstQualif
(
DefId
)
->
u8
,
/// Fetch the MIR for a given def-id up till the point where it is
/// ready for const evaluation.
///
/// See the README for the `mir` module for details.
[]
mir_const
:
Mir
(
DefId
)
->
&
'tcx
Steal
<
mir
::
Mir
<
'tcx
>>
,
[]
mir_const
:
Mir
Const
(
DefId
)
->
&
'tcx
Steal
<
mir
::
Mir
<
'tcx
>>
,
[]
mir_validated
:
Mir
(
DefId
)
->
&
'tcx
Steal
<
mir
::
Mir
<
'tcx
>>
,
[]
mir_validated
:
Mir
Validated
(
DefId
)
->
&
'tcx
Steal
<
mir
::
Mir
<
'tcx
>>
,
/// MIR after our optimization passes have run. This is MIR that is ready
/// for trans. This is also the only query that can fetch non-local MIR, at present.
[]
optimized_mir
:
Mir
(
DefId
)
->
&
'tcx
mir
::
Mir
<
'tcx
>
,
[]
optimized_mir
:
Mir
Optimized
(
DefId
)
->
&
'tcx
mir
::
Mir
<
'tcx
>
,
/// Type of each closure. The def ID is the ID of the
/// expression defining the closure.
...
...
@@ -890,7 +896,7 @@ fn default() -> Self {
[]
typeck_tables_of
:
TypeckTables
(
DefId
)
->
&
'tcx
ty
::
TypeckTables
<
'tcx
>
,
[]
has_typeck_tables
:
TypeckTables
(
DefId
)
->
bool
,
[]
has_typeck_tables
:
Has
TypeckTables
(
DefId
)
->
bool
,
[]
coherent_trait
:
coherent_trait_dep_node
((
CrateNum
,
DefId
))
->
(),
...
...
@@ -972,80 +978,80 @@ fn default() -> Self {
[]
extern_crate
:
ExternCrate
(
DefId
)
->
Rc
<
Option
<
ExternCrate
>>
,
}
fn
type_param_predicates
((
item_id
,
param_id
):
(
DefId
,
DefId
))
->
DepConstructor
{
fn
type_param_predicates
<
'tcx
>
((
item_id
,
param_id
):
(
DefId
,
DefId
))
->
DepConstructor
<
'tcx
>
{
DepConstructor
::
TypeParamPredicates
{
item_id
,
param_id
}
}
fn
coherent_trait_dep_node
((
_
,
def_id
):
(
CrateNum
,
DefId
))
->
DepConstructor
{
fn
coherent_trait_dep_node
<
'tcx
>
((
_
,
def_id
):
(
CrateNum
,
DefId
))
->
DepConstructor
<
'tcx
>
{
DepConstructor
::
CoherenceCheckTrait
(
def_id
)
}
fn
crate_inherent_impls_dep_node
(
_
:
CrateNum
)
->
DepConstructor
{
fn
crate_inherent_impls_dep_node
<
'tcx
>
(
_
:
CrateNum
)
->
DepConstructor
<
'tcx
>
{
DepConstructor
::
Coherence
}
fn
reachability_dep_node
(
_
:
CrateNum
)
->
DepConstructor
{
fn
reachability_dep_node
<
'tcx
>
(
_
:
CrateNum
)
->
DepConstructor
<
'tcx
>
{
DepConstructor
::
Reachability
}
fn
mir_shim_dep_node
(
instance
:
ty
::
InstanceDef
)
->
DepConstructor
{
instance
.dep_node
()
fn
mir_shim_dep_node
<
'tcx
>
(
instance_def
:
ty
::
InstanceDef
<
'tcx
>
)
->
DepConstructor
<
'tcx
>
{
DepConstructor
::
MirShim
{
instance_def
}
}
fn
symbol_name_dep_node
(
instance
:
ty
::
Instance
)
->
DepConstructor
{
// symbol_name uses the substs only to traverse them to find the
// hash, and that does not create any new dep-nodes.
DepConstructor
::
SymbolName
(
instance
.def
.def_id
())
fn
symbol_name_dep_node
<
'tcx
>
(
instance
:
ty
::
Instance
<
'tcx
>
)
->
DepConstructor
<
'tcx
>
{
DepConstructor
::
InstanceSymbolName
{
instance
}
}
fn
typeck_item_bodies_dep_node
(
_
:
CrateNum
)
->
DepConstructor
{
fn
typeck_item_bodies_dep_node
<
'tcx
>
(
_
:
CrateNum
)
->
DepConstructor
<
'tcx
>
{
DepConstructor
::
TypeckBodiesKrate
}
fn
const_eval_dep_node
((
def_id
,
_
):
(
DefId
,
&
Substs
))
->
DepConstructor
{
fn
const_eval_dep_node
<
'tcx
>
((
def_id
,
_
):
(
DefId
,
&
Substs
))
->
DepConstructor
<
'tcx
>
{
DepConstructor
::
ConstEval
(
def_id
)
}
fn
mir_keys
(
_
:
CrateNum
)
->
DepConstructor
{
fn
mir_keys
<
'tcx
>
(
_
:
CrateNum
)
->
DepConstructor
<
'tcx
>
{
DepConstructor
::
MirKeys
}
fn
crate_variances
(
_
:
CrateNum
)
->
DepConstructor
{
fn
crate_variances
<
'tcx
>
(
_
:
CrateNum
)
->
DepConstructor
<
'tcx
>
{
DepConstructor
::
CrateVariances
}
fn
relevant_trait_impls_for
((
def_id
,
_
):
(
DefId
,
SimplifiedType
))
->
DepConstructor
{
DepConstructor
::
TraitImpls
(
def_id
)
fn
relevant_trait_impls_for
<
'tcx
>
((
def_id
,
t
):
(
DefId
,
SimplifiedType
))
->
DepConstructor
<
'tcx
>
{
DepConstructor
::
RelevantTraitImpls
(
def_id
,
t
)
}
fn
is_copy_dep_node
<
'tcx
>
(
key
:
ty
::
ParamEnvAnd
<
'tcx
,
Ty
<
'tcx
>>
)
->
DepConstructor
{
fn
is_copy_dep_node
<
'tcx
>
(
key
:
ty
::
ParamEnvAnd
<
'tcx
,
Ty
<
'tcx
>>
)
->
DepConstructor
<
'tcx
>
{
let
def_id
=
ty
::
item_path
::
characteristic_def_id_of_type
(
key
.value
)
.unwrap_or
(
DefId
::
local
(
CRATE_DEF_INDEX
));
DepConstructor
::
IsCopy
(
def_id
)
}
fn
is_sized_dep_node
<
'tcx
>
(
key
:
ty
::
ParamEnvAnd
<
'tcx
,
Ty
<
'tcx
>>
)
->
DepConstructor
{
fn
is_sized_dep_node
<
'tcx
>
(
key
:
ty
::
ParamEnvAnd
<
'tcx
,
Ty
<
'tcx
>>
)
->
DepConstructor
<
'tcx
>
{
let
def_id
=
ty
::
item_path
::
characteristic_def_id_of_type
(
key
.value
)
.unwrap_or
(
DefId
::
local
(
CRATE_DEF_INDEX
));
DepConstructor
::
IsSized
(
def_id
)
}
fn
is_freeze_dep_node
<
'tcx
>
(
key
:
ty
::
ParamEnvAnd
<
'tcx
,
Ty
<
'tcx
>>
)
->
DepConstructor
{
fn
is_freeze_dep_node
<
'tcx
>
(
key
:
ty
::
ParamEnvAnd
<
'tcx
,
Ty
<
'tcx
>>
)
->
DepConstructor
<
'tcx
>
{
let
def_id
=
ty
::
item_path
::
characteristic_def_id_of_type
(
key
.value
)
.unwrap_or
(
DefId
::
local
(
CRATE_DEF_INDEX
));
DepConstructor
::
IsFreeze
(
def_id
)
}
fn
needs_drop_dep_node
<
'tcx
>
(
key
:
ty
::
ParamEnvAnd
<
'tcx
,
Ty
<
'tcx
>>
)
->
DepConstructor
{
fn
needs_drop_dep_node
<
'tcx
>
(
key
:
ty
::
ParamEnvAnd
<
'tcx
,
Ty
<
'tcx
>>
)
->
DepConstructor
<
'tcx
>
{
let
def_id
=
ty
::
item_path
::
characteristic_def_id_of_type
(
key
.value
)
.unwrap_or
(
DefId
::
local
(
CRATE_DEF_INDEX
));
DepConstructor
::
NeedsDrop
(
def_id
)
}
fn
layout_dep_node
<
'tcx
>
(
key
:
ty
::
ParamEnvAnd
<
'tcx
,
Ty
<
'tcx
>>
)
->
DepConstructor
{
fn
layout_dep_node
<
'tcx
>
(
key
:
ty
::
ParamEnvAnd
<
'tcx
,
Ty
<
'tcx
>>
)
->
DepConstructor
<
'tcx
>
{
let
def_id
=
ty
::
item_path
::
characteristic_def_id_of_type
(
key
.value
)
.unwrap_or
(
DefId
::
local
(
CRATE_DEF_INDEX
));
DepConstructor
::
Layout
(
def_id
)
...
...
src/librustc_metadata/cstore_impl.rs
浏览文件 @
e00bec2d
...
...
@@ -12,7 +12,7 @@
use
encoder
;
use
schema
;
use
rustc
::
dep_graph
::
DepTrackingMap
Config
;
use
rustc
::
ty
::
maps
::
Query
Config
;
use
rustc
::
middle
::
cstore
::{
CrateStore
,
CrateSource
,
LibSource
,
DepKind
,
NativeLibrary
,
MetadataLoader
,
LinkMeta
,
LinkagePreference
,
LoadedMacro
,
EncodedMetadata
};
...
...
@@ -45,7 +45,7 @@
pub
fn
provide
<
$lt
>
(
providers
:
&
mut
Providers
<
$lt
>
)
{
$
(
fn
$name
<
'a
,
$lt
:
$lt
>
(
$tcx
:
TyCtxt
<
'a
,
$lt
,
$lt
>
,
$def_id
:
DefId
)
->
<
ty
::
queries
::
$name
<
$lt
>
as
DepTrackingMap
Config
>
::
Value
{
Query
Config
>
::
Value
{
assert!
(
!
$def_id
.is_local
());
let
def_path_hash
=
$tcx
.def_path_hash
(
$def_id
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录