Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
94a066e2
R
Rust
项目概览
int
/
Rust
12 个月 前同步成功
通知
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,发现更多精彩内容 >>
未验证
提交
94a066e2
编写于
6月 29, 2019
作者:
M
Mazdak Farrokhzad
提交者:
GitHub
6月 29, 2019
浏览文件
操作
浏览文件
下载
差异文件
Rollup merge of #62104 - Zoxc:query-info, r=eddyb
Inform the query system about properties of queries at compile time
上级
a4cf85e9
11221d12
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
61 addition
and
32 deletion
+61
-32
src/librustc/dep_graph/dep_node.rs
src/librustc/dep_graph/dep_node.rs
+0
-4
src/librustc/ty/query/config.rs
src/librustc/ty/query/config.rs
+6
-1
src/librustc/ty/query/mod.rs
src/librustc/ty/query/mod.rs
+1
-1
src/librustc/ty/query/plumbing.rs
src/librustc/ty/query/plumbing.rs
+45
-12
src/librustc_macros/src/query.rs
src/librustc_macros/src/query.rs
+6
-14
src/libsyntax_pos/symbol.rs
src/libsyntax_pos/symbol.rs
+3
-0
未找到文件。
src/librustc/dep_graph/dep_node.rs
浏览文件 @
94a066e2
...
...
@@ -142,9 +142,6 @@ pub fn can_reconstruct_query_key<$tcx>(&self) -> bool {
}
}
// FIXME: Make `is_anon`, `is_eval_always` and `has_params` properties
// of queries
#[inline(always)]
pub
fn
is_anon
(
&
self
)
->
bool
{
match
*
self
{
$
(
...
...
@@ -163,7 +160,6 @@ pub fn is_eval_always(&self) -> bool {
}
#[allow(unreachable_code)]
#[inline(always)]
pub
fn
has_params
(
&
self
)
->
bool
{
match
*
self
{
$
(
...
...
src/librustc/ty/query/config.rs
浏览文件 @
94a066e2
use
crate
::
dep_graph
::
SerializedDepNodeIndex
;
use
crate
::
dep_graph
::
DepNode
;
use
crate
::
dep_graph
::
{
DepKind
,
DepNode
}
;
use
crate
::
hir
::
def_id
::{
CrateNum
,
DefId
};
use
crate
::
ty
::
TyCtxt
;
use
crate
::
ty
::
query
::
queries
;
...
...
@@ -28,6 +28,9 @@ pub trait QueryConfig<'tcx> {
}
pub
(
crate
)
trait
QueryAccessors
<
'tcx
>
:
QueryConfig
<
'tcx
>
{
const
ANON
:
bool
;
const
EVAL_ALWAYS
:
bool
;
fn
query
(
key
:
Self
::
Key
)
->
Query
<
'tcx
>
;
// Don't use this method to access query results, instead use the methods on TyCtxt
...
...
@@ -35,6 +38,8 @@ pub(crate) trait QueryAccessors<'tcx>: QueryConfig<'tcx> {
fn
to_dep_node
(
tcx
:
TyCtxt
<
'tcx
>
,
key
:
&
Self
::
Key
)
->
DepNode
;
fn
dep_kind
()
->
DepKind
;
// Don't use this method to compute query results, instead use the methods on TyCtxt
fn
compute
(
tcx
:
TyCtxt
<
'tcx
>
,
key
:
Self
::
Key
)
->
Self
::
Value
;
...
...
src/librustc/ty/query/mod.rs
浏览文件 @
94a066e2
...
...
@@ -101,6 +101,6 @@
rustc_query_append!
{
[
define_queries!
][
<
'tcx
>
Other
{
/// Runs analysis passes on the crate.
[]
fn
analysis
:
Analysis
(
CrateNum
)
->
Result
<
(),
ErrorReported
>
,
[
eval_always
]
fn
analysis
:
Analysis
(
CrateNum
)
->
Result
<
(),
ErrorReported
>
,
},
]}
src/librustc/ty/query/plumbing.rs
浏览文件 @
94a066e2
...
...
@@ -376,15 +376,13 @@ pub(super) fn get_query<Q: QueryDescription<'tcx>>(self, span: Span, key: Q::Key
return
self
.force_query_with_job
::
<
Q
>
(
key
,
job
,
null_dep_node
)
.0
;
}
let
dep_node
=
Q
::
to_dep_node
(
self
,
&
key
);
if
dep_node
.kind
.is_anon
()
{
if
Q
::
ANON
{
profq_msg!
(
self
,
ProfileQueriesMsg
::
ProviderBegin
);
self
.sess
.profiler
(|
p
|
p
.start_query
(
Q
::
NAME
));
let
((
result
,
dep_node_index
),
diagnostics
)
=
with_diagnostics
(|
diagnostics
|
{
self
.start_query
(
job
.job
.clone
(),
diagnostics
,
|
tcx
|
{
tcx
.dep_graph
.with_anon_task
(
dep_node
.kind
,
||
{
tcx
.dep_graph
.with_anon_task
(
Q
::
dep_kind
()
,
||
{
Q
::
compute
(
tcx
.global_tcx
(),
key
)
})
})
...
...
@@ -405,7 +403,9 @@ pub(super) fn get_query<Q: QueryDescription<'tcx>>(self, span: Span, key: Q::Key
return
result
;
}
if
!
dep_node
.kind
.is_eval_always
()
{
let
dep_node
=
Q
::
to_dep_node
(
self
,
&
key
);
if
!
Q
::
EVAL_ALWAYS
{
// The diagnostics for this query will be
// promoted to the current session during
// try_mark_green(), so we can ignore them here.
...
...
@@ -546,7 +546,7 @@ fn force_query_with_job<Q: QueryDescription<'tcx>>(
let
((
result
,
dep_node_index
),
diagnostics
)
=
with_diagnostics
(|
diagnostics
|
{
self
.start_query
(
job
.job
.clone
(),
diagnostics
,
|
tcx
|
{
if
dep_node
.kind
.is_eval_always
()
{
if
Q
::
EVAL_ALWAYS
{
tcx
.dep_graph
.with_eval_always_task
(
dep_node
,
tcx
,
key
,
...
...
@@ -569,8 +569,8 @@ fn force_query_with_job<Q: QueryDescription<'tcx>>(
self
.dep_graph
.mark_loaded_from_cache
(
dep_node_index
,
false
);
}
if
dep_node
.kind
!=
crate
::
dep_graph
::
DepKind
::
Null
{
if
unlikely!
(
!
diagnostics
.is_empty
())
{
if
unlikely!
(
!
diagnostics
.is_empty
())
{
if
dep_node
.kind
!=
crate
::
dep_graph
::
DepKind
::
Null
{
self
.queries.on_disk_cache
.store_diagnostics
(
dep_node_index
,
diagnostics
);
}
...
...
@@ -589,15 +589,16 @@ fn force_query_with_job<Q: QueryDescription<'tcx>>(
///
/// Note: The optimization is only available during incr. comp.
pub
(
super
)
fn
ensure_query
<
Q
:
QueryDescription
<
'tcx
>>
(
self
,
key
:
Q
::
Key
)
->
()
{
let
dep_node
=
Q
::
to_dep_node
(
self
,
&
key
);
if
dep_node
.kind
.is_eval_always
()
{
if
Q
::
EVAL_ALWAYS
{
let
_
=
self
.get_query
::
<
Q
>
(
DUMMY_SP
,
key
);
return
;
}
// Ensuring an anonymous query makes no sense
assert
!
(
!
dep_node
.kind
.is_anon
());
assert
!
(
!
Q
::
ANON
);
let
dep_node
=
Q
::
to_dep_node
(
self
,
&
key
);
if
self
.dep_graph
.try_mark_green_and_read
(
self
,
&
dep_node
)
.is_none
()
{
// A None return from `try_mark_green_and_read` means that this is either
// a new dep node or that the dep node has already been marked red.
...
...
@@ -653,6 +654,30 @@ fn force_query<Q: QueryDescription<'tcx>>(self, key: Q::Key, span: Span, dep_nod
};
}
macro_rules!
is_anon
{
([])
=>
{{
false
}};
([
anon
$
(,
$modifiers:ident
)
*
])
=>
{{
true
}};
([
$other:ident$
(,
$modifiers:ident
)
*
])
=>
{
is_anon!
([
$
(
$modifiers
),
*
])
};
}
macro_rules!
is_eval_always
{
([])
=>
{{
false
}};
([
eval_always
$
(,
$modifiers:ident
)
*
])
=>
{{
true
}};
([
$other:ident$
(,
$modifiers:ident
)
*
])
=>
{
is_eval_always!
([
$
(
$modifiers
),
*
])
};
}
macro_rules!
hash_result
{
([][
$hcx:expr
,
$result:expr
])
=>
{{
dep_graph
::
hash_result
(
$hcx
,
&
$result
)
...
...
@@ -933,6 +958,9 @@ pub fn $name<F: FnOnce() -> R, R>(f: F) -> R {
}
impl
<
$tcx
>
QueryAccessors
<
$tcx
>
for
queries
::
$name
<
$tcx
>
{
const
ANON
:
bool
=
is_anon!
([
$
(
$modifiers
)
*
]);
const
EVAL_ALWAYS
:
bool
=
is_eval_always!
([
$
(
$modifiers
)
*
]);
#[inline(always)]
fn
query
(
key
:
Self
::
Key
)
->
Query
<
'tcx
>
{
Query
::
$name
(
key
)
...
...
@@ -951,6 +979,11 @@ fn to_dep_node(tcx: TyCtxt<$tcx>, key: &Self::Key) -> DepNode {
DepNode
::
new
(
tcx
,
$node
(
*
key
))
}
#[inline(always)]
fn
dep_kind
()
->
dep_graph
::
DepKind
{
dep_graph
::
DepKind
::
$node
}
#[inline]
fn
compute
(
tcx
:
TyCtxt
<
'tcx
>
,
key
:
Self
::
Key
)
->
Self
::
Value
{
__
query_compute
::
$name
(
move
||
{
...
...
src/librustc_macros/src/query.rs
浏览文件 @
94a066e2
...
...
@@ -423,20 +423,6 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
if
modifiers
.no_hash
{
attributes
.push
(
quote!
{
no_hash
});
};
let
mut
attribute_stream
=
quote!
{};
for
e
in
attributes
.into_iter
()
.intersperse
(
quote!
{,})
{
attribute_stream
.extend
(
e
);
}
// Add the query to the group
group_stream
.extend
(
quote!
{
[
#
attribute_stream
]
fn
#
name
:
#
name
(
#
arg
)
#
result
,
});
let
mut
attributes
=
Vec
::
new
();
// Pass on the anon modifier
if
modifiers
.anon
{
attributes
.push
(
quote!
{
anon
});
...
...
@@ -450,6 +436,12 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
for
e
in
attributes
.into_iter
()
.intersperse
(
quote!
{,})
{
attribute_stream
.extend
(
e
);
}
// Add the query to the group
group_stream
.extend
(
quote!
{
[
#
attribute_stream
]
fn
#
name
:
#
name
(
#
arg
)
#
result
,
});
// Create a dep node for the query
dep_node_def_stream
.extend
(
quote!
{
[
#
attribute_stream
]
#
name
(
#
arg
),
...
...
src/libsyntax_pos/symbol.rs
浏览文件 @
94a066e2
...
...
@@ -1132,6 +1132,7 @@ pub fn as_interned_str(self) -> InternedString {
}
}
#[inline]
pub
fn
get
(
&
self
)
->
&
str
{
// This returns a valid string since we ensure that `self` outlives the interner
// by creating the interner on a thread which outlives threads which can access it.
...
...
@@ -1145,6 +1146,7 @@ impl<U: ?Sized> std::convert::AsRef<U> for LocalInternedString
where
str
:
std
::
convert
::
AsRef
<
U
>
{
#[inline]
fn
as_ref
(
&
self
)
->
&
U
{
self
.string
.as_ref
()
}
...
...
@@ -1185,6 +1187,7 @@ impl !Sync for LocalInternedString {}
impl
std
::
ops
::
Deref
for
LocalInternedString
{
type
Target
=
str
;
#[inline]
fn
deref
(
&
self
)
->
&
str
{
self
.string
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录