Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
4faf701d
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,发现更多精彩内容 >>
提交
4faf701d
编写于
3月 27, 2020
作者:
C
Camille GILLOT
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove the QueryGetter trait.
上级
260cfaba
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
74 addition
and
91 deletion
+74
-91
src/librustc/ty/query/plumbing.rs
src/librustc/ty/query/plumbing.rs
+2
-2
src/librustc_macros/src/query.rs
src/librustc_macros/src/query.rs
+2
-1
src/librustc_query_system/query/plumbing.rs
src/librustc_query_system/query/plumbing.rs
+70
-88
未找到文件。
src/librustc/ty/query/plumbing.rs
浏览文件 @
4faf701d
...
...
@@ -381,7 +381,7 @@ impl TyCtxtEnsure<$tcx> {
$
(
$
(
#[
$
attr]
)
*
#[inline(always)]
pub
fn
$name
(
self
,
key
:
$K
)
{
self
.tcx.ensure_query
::
<
queries
::
$name
<
'_
>>
(
key
)
ensure_query
::
<
queries
::
$name
<
'_
>
,
_
>
(
self
.tcx
,
key
)
})
*
}
...
...
@@ -459,7 +459,7 @@ impl TyCtxtAt<$tcx> {
$
(
$
(
#[
$
attr]
)
*
#[inline(always)]
pub
fn
$name
(
self
,
key
:
$K
)
->
$V
{
self
.tcx.get_query
::
<
queries
::
$name
<
'_
>>
(
self
.span
,
key
)
get_query
::
<
queries
::
$name
<
'_
>
,
_
>
(
self
.tcx
,
self
.span
,
key
)
})
*
}
...
...
src/librustc_macros/src/query.rs
浏览文件 @
4faf701d
...
...
@@ -489,7 +489,8 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
::
rustc
::
dep_graph
::
DepKind
::
#
name
=>
{
if
<
#
arg
as
DepNodeParams
<
TyCtxt
<
'_
>>>
::
CAN_RECONSTRUCT_QUERY_KEY
{
if
let
Some
(
key
)
=
<
#
arg
as
DepNodeParams
<
TyCtxt
<
'_
>>>
::
recover
(
$
tcx
,
$
dep_node
)
{
$
tcx
.force_query
::
<
crate
::
ty
::
query
::
queries
::
#
name
<
'_
>>
(
force_query
::
<
crate
::
ty
::
query
::
queries
::
#
name
<
'_
>
,
_
>
(
$
tcx
,
key
,
DUMMY_SP
,
*
$
dep_node
...
...
src/librustc_query_system/query/plumbing.rs
浏览文件 @
4faf701d
...
...
@@ -606,105 +606,87 @@ fn force_query_with_job<Q, CTX>(
(
result
,
dep_node_index
)
}
pub
trait
QueryGetter
:
QueryContext
{
fn
get_query
<
Q
:
QueryDescription
<
Self
>>
(
self
,
span
:
Span
,
key
:
Q
::
Key
)
->
Q
::
Value
;
/// Ensure that either this query has all green inputs or been executed.
/// Executing `query::ensure(D)` is considered a read of the dep-node `D`.
///
/// This function is particularly useful when executing passes for their
/// side-effects -- e.g., in order to report errors for erroneous programs.
///
/// Note: The optimization is only available during incr. comp.
fn
ensure_query
<
Q
:
QueryDescription
<
Self
>>
(
self
,
key
:
Q
::
Key
);
#[inline(never)]
pub
fn
get_query
<
Q
,
CTX
>
(
tcx
:
CTX
,
span
:
Span
,
key
:
Q
::
Key
)
->
Q
::
Value
where
Q
:
QueryDescription
<
CTX
>
,
CTX
:
QueryContext
,
{
debug!
(
"ty::query::get_query<{}>(key={:?}, span={:?})"
,
Q
::
NAME
,
key
,
span
);
fn
force_query
<
Q
:
QueryDescription
<
Self
>>
(
self
,
key
:
Q
::
Key
,
span
:
Span
,
dep_node
:
DepNode
<
Self
::
DepKind
>
,
);
try_get_cached
(
tcx
,
Q
::
query_state
(
tcx
),
key
,
|
value
,
index
|
{
tcx
.dep_graph
()
.read_index
(
index
);
value
.clone
()
},
|
key
,
lookup
|
try_execute_query
::
<
Q
,
_
>
(
tcx
,
span
,
key
,
lookup
),
)
}
impl
<
CTX
>
QueryGetter
for
CTX
/// Ensure that either this query has all green inputs or been executed.
/// Executing `query::ensure(D)` is considered a read of the dep-node `D`.
///
/// This function is particularly useful when executing passes for their
/// side-effects -- e.g., in order to report errors for erroneous programs.
///
/// Note: The optimization is only available during incr. comp.
pub
fn
ensure_query
<
Q
,
CTX
>
(
tcx
:
CTX
,
key
:
Q
::
Key
)
where
Q
:
QueryDescription
<
CTX
>
,
CTX
:
QueryContext
,
{
#[inline(never)]
fn
get_query
<
Q
:
QueryDescription
<
Self
>>
(
self
,
span
:
Span
,
key
:
Q
::
Key
)
->
Q
::
Value
{
debug!
(
"ty::query::get_query<{}>(key={:?}, span={:?})"
,
Q
::
NAME
,
key
,
span
);
try_get_cached
(
self
,
Q
::
query_state
(
self
),
key
,
|
value
,
index
|
{
self
.dep_graph
()
.read_index
(
index
);
value
.clone
()
},
|
key
,
lookup
|
try_execute_query
::
<
Q
,
_
>
(
self
,
span
,
key
,
lookup
),
)
if
Q
::
EVAL_ALWAYS
{
let
_
=
get_query
::
<
Q
,
_
>
(
tcx
,
DUMMY_SP
,
key
);
return
;
}
/// Ensure that either this query has all green inputs or been executed.
/// Executing `query::ensure(D)` is considered a read of the dep-node `D`.
///
/// This function is particularly useful when executing passes for their
/// side-effects -- e.g., in order to report errors for erroneous programs.
///
/// Note: The optimization is only available during incr. comp.
fn
ensure_query
<
Q
:
QueryDescription
<
Self
>>
(
self
,
key
:
Q
::
Key
)
{
if
Q
::
EVAL_ALWAYS
{
let
_
=
self
.get_query
::
<
Q
>
(
DUMMY_SP
,
key
);
return
;
}
// Ensuring an anonymous query makes no sense
assert
!
(
!
Q
::
ANON
);
// Ensuring an anonymous query makes no sense
assert
!
(
!
Q
::
ANON
);
let
dep_node
=
Q
::
to_dep_node
(
self
,
&
key
);
let
dep_node
=
Q
::
to_dep_node
(
tcx
,
&
key
);
match
self
.dep_graph
()
.try_mark_green_and_read
(
self
,
&
dep_node
)
{
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.
// Either way, we can't call `dep_graph.read()` as we don't have the
// DepNodeIndex. We must invoke the query itself. The performance cost
// this introduces should be negligible as we'll immediately hit the
// in-memory cache, or another query down the line will.
let
_
=
self
.get_query
::
<
Q
>
(
DUMMY_SP
,
key
);
}
Some
((
_
,
dep_node_index
))
=>
{
self
.profiler
()
.query_cache_hit
(
dep_node_index
.into
());
}
match
tcx
.dep_graph
()
.try_mark_green_and_read
(
tcx
,
&
dep_node
)
{
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.
// Either way, we can't call `dep_graph.read()` as we don't have the
// DepNodeIndex. We must invoke the query itself. The performance cost
// this introduces should be negligible as we'll immediately hit the
// in-memory cache, or another query down the line will.
let
_
=
get_query
::
<
Q
,
_
>
(
tcx
,
DUMMY_SP
,
key
);
}
Some
((
_
,
dep_node_index
))
=>
{
tcx
.profiler
()
.query_cache_hit
(
dep_node_index
.into
());
}
}
}
fn
force_query
<
Q
:
QueryDescription
<
Self
>>
(
self
,
key
:
Q
::
Key
,
span
:
Span
,
dep_node
:
DepNode
<
Self
::
DepKind
>
,
)
{
// We may be concurrently trying both execute and force a query.
// Ensure that only one of them runs the query.
try_get_cached
(
self
,
Q
::
query_state
(
self
),
key
,
|
_
,
_
|
{
// Cache hit, do nothing
},
|
key
,
lookup
|
{
let
job
=
match
JobOwner
::
try_start
::
<
Q
>
(
self
,
span
,
&
key
,
lookup
)
{
TryGetJob
::
NotYetStarted
(
job
)
=>
job
,
TryGetJob
::
Cycle
(
_
)
=>
return
,
#[cfg(parallel_compiler)]
TryGetJob
::
JobCompleted
(
_
)
=>
return
,
};
force_query_with_job
::
<
Q
,
_
>
(
self
,
key
,
job
,
dep_node
);
},
);
}
pub
fn
force_query
<
Q
,
CTX
>
(
tcx
:
CTX
,
key
:
Q
::
Key
,
span
:
Span
,
dep_node
:
DepNode
<
CTX
::
DepKind
>
)
where
Q
:
QueryDescription
<
CTX
>
,
CTX
:
QueryContext
,
{
// We may be concurrently trying both execute and force a query.
// Ensure that only one of them runs the query.
try_get_cached
(
tcx
,
Q
::
query_state
(
tcx
),
key
,
|
_
,
_
|
{
// Cache hit, do nothing
},
|
key
,
lookup
|
{
let
job
=
match
JobOwner
::
try_start
::
<
Q
>
(
tcx
,
span
,
&
key
,
lookup
)
{
TryGetJob
::
NotYetStarted
(
job
)
=>
job
,
TryGetJob
::
Cycle
(
_
)
=>
return
,
#[cfg(parallel_compiler)]
TryGetJob
::
JobCompleted
(
_
)
=>
return
,
};
force_query_with_job
::
<
Q
,
_
>
(
tcx
,
key
,
job
,
dep_node
);
},
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录