Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
eb5bbab3
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,发现更多精彩内容 >>
提交
eb5bbab3
编写于
8月 17, 2021
作者:
L
lcnr
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
optimize `HasTypeFlagsVisitor`
上级
97712459
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
81 addition
and
33 deletion
+81
-33
compiler/rustc_middle/src/ty/fold.rs
compiler/rustc_middle/src/ty/fold.rs
+81
-33
未找到文件。
compiler/rustc_middle/src/ty/fold.rs
浏览文件 @
eb5bbab3
...
...
@@ -1128,26 +1128,20 @@ struct HasTypeFlagsVisitor<'tcx> {
impl
<
'tcx
>
TypeVisitor
<
'tcx
>
for
HasTypeFlagsVisitor
<
'tcx
>
{
type
BreakTy
=
FoundFlags
;
fn
tcx_for_anon_const_substs
(
&
self
)
->
Option
<
TyCtxt
<
'tcx
>>
{
self
.tcx
bug!
(
"we shouldn't call this method as we manually look at ct substs"
);
}
#[inline]
fn
visit_ty
(
&
mut
self
,
t
:
Ty
<
'tcx
>
)
->
ControlFlow
<
Self
::
BreakTy
>
{
debug!
(
"HasTypeFlagsVisitor: t={:?} t.flags={:?} self.flags={:?}"
,
t
,
t
.flags
(),
self
.flags
);
if
t
.flags
()
.intersects
(
self
.flags
)
{
let
flags
=
t
.flags
();
debug!
(
"HasTypeFlagsVisitor: t={:?} flags={:?} self.flags={:?}"
,
t
,
flags
,
self
.flags
);
if
flags
.intersects
(
self
.flags
)
{
ControlFlow
::
Break
(
FoundFlags
)
}
else
if
t
.flags
()
.intersects
(
TypeFlags
::
HAS_UNKNOWN_DEFAULT_CONST_SUBSTS
)
&&
self
.flags
.intersects
(
TypeFlags
::
MAY_NEED_DEFAULT_CONST_SUBSTS
)
&&
self
.tcx
.is_some
()
{
t
.super_visit_with
(
self
)
}
else
{
ControlFlow
::
CONTINUE
match
flags
.intersects
(
TypeFlags
::
HAS_UNKNOWN_DEFAULT_CONST_SUBSTS
)
{
true
if
self
.tcx
.is_some
()
=>
UnknownConstSubstsVisitor
::
search
(
&
self
,
t
),
_
=>
ControlFlow
::
CONTINUE
,
}
}
}
...
...
@@ -1168,13 +1162,11 @@ fn visit_const(&mut self, c: &'tcx ty::Const<'tcx>) -> ControlFlow<Self::BreakTy
debug!
(
"HasTypeFlagsVisitor: c={:?} c.flags={:?} self.flags={:?}"
,
c
,
flags
,
self
.flags
);
if
flags
.intersects
(
self
.flags
)
{
ControlFlow
::
Break
(
FoundFlags
)
}
else
if
flags
.intersects
(
TypeFlags
::
HAS_UNKNOWN_DEFAULT_CONST_SUBSTS
)
&&
self
.flags
.intersects
(
TypeFlags
::
MAY_NEED_DEFAULT_CONST_SUBSTS
)
&&
self
.tcx
.is_some
()
{
c
.super_visit_with
(
self
)
}
else
{
ControlFlow
::
CONTINUE
match
flags
.intersects
(
TypeFlags
::
HAS_UNKNOWN_DEFAULT_CONST_SUBSTS
)
{
true
if
self
.tcx
.is_some
()
=>
UnknownConstSubstsVisitor
::
search
(
&
self
,
c
),
_
=>
ControlFlow
::
CONTINUE
,
}
}
}
...
...
@@ -1184,28 +1176,84 @@ fn visit_unevaluated_const(&mut self, uv: ty::Unevaluated<'tcx>) -> ControlFlow<
debug!
(
"HasTypeFlagsVisitor: uv={:?} uv.flags={:?} self.flags={:?}"
,
uv
,
flags
,
self
.flags
);
if
flags
.intersects
(
self
.flags
)
{
ControlFlow
::
Break
(
FoundFlags
)
}
else
if
flags
.intersects
(
TypeFlags
::
HAS_UNKNOWN_DEFAULT_CONST_SUBSTS
)
&&
self
.flags
.intersects
(
TypeFlags
::
MAY_NEED_DEFAULT_CONST_SUBSTS
)
&&
self
.tcx
.is_some
()
{
uv
.super_visit_with
(
self
)
}
else
{
ControlFlow
::
CONTINUE
match
flags
.intersects
(
TypeFlags
::
HAS_UNKNOWN_DEFAULT_CONST_SUBSTS
)
{
true
if
self
.tcx
.is_some
()
=>
UnknownConstSubstsVisitor
::
search
(
&
self
,
uv
),
_
=>
ControlFlow
::
CONTINUE
,
}
}
}
#[inline]
fn
visit_predicate
(
&
mut
self
,
predicate
:
ty
::
Predicate
<
'tcx
>
)
->
ControlFlow
<
Self
::
BreakTy
>
{
let
flags
=
predicate
.inner.flags
;
debug!
(
"HasTypeFlagsVisitor: predicate={:?}
predicate.
flags={:?} self.flags={:?}"
,
predicate
,
predicate
.inner.
flags
,
self
.flags
"HasTypeFlagsVisitor: predicate={:?} flags={:?} self.flags={:?}"
,
predicate
,
flags
,
self
.flags
);
if
predicate
.inner.
flags
.intersects
(
self
.flags
)
{
if
flags
.intersects
(
self
.flags
)
{
ControlFlow
::
Break
(
FoundFlags
)
}
else
if
predicate
.inner.flags
.intersects
(
TypeFlags
::
HAS_UNKNOWN_DEFAULT_CONST_SUBSTS
)
&&
self
.flags
.intersects
(
TypeFlags
::
MAY_NEED_DEFAULT_CONST_SUBSTS
)
&&
self
.tcx
.is_some
()
{
}
else
{
match
flags
.intersects
(
TypeFlags
::
HAS_UNKNOWN_DEFAULT_CONST_SUBSTS
)
{
true
if
self
.tcx
.is_some
()
=>
UnknownConstSubstsVisitor
::
search
(
&
self
,
predicate
),
_
=>
ControlFlow
::
CONTINUE
,
}
}
}
}
struct
UnknownConstSubstsVisitor
<
'tcx
>
{
tcx
:
TyCtxt
<
'tcx
>
,
flags
:
ty
::
TypeFlags
,
}
impl
<
'tcx
>
UnknownConstSubstsVisitor
<
'tcx
>
{
/// This is fairly cold and we don't want to
/// bloat the size of the `HasTypeFlagsVisitor`.
#[inline(never)]
pub
fn
search
<
T
:
TypeFoldable
<
'tcx
>>
(
visitor
:
&
HasTypeFlagsVisitor
<
'tcx
>
,
v
:
T
,
)
->
ControlFlow
<
FoundFlags
>
{
if
visitor
.flags
.intersects
(
TypeFlags
::
MAY_NEED_DEFAULT_CONST_SUBSTS
)
{
v
.super_visit_with
(
&
mut
UnknownConstSubstsVisitor
{
tcx
:
visitor
.tcx
.unwrap
(),
flags
:
visitor
.flags
,
})
}
else
{
ControlFlow
::
CONTINUE
}
}
}
impl
<
'tcx
>
TypeVisitor
<
'tcx
>
for
UnknownConstSubstsVisitor
<
'tcx
>
{
type
BreakTy
=
FoundFlags
;
fn
tcx_for_anon_const_substs
(
&
self
)
->
Option
<
TyCtxt
<
'tcx
>>
{
bug!
(
"we shouldn't call this method as we manually look at ct substs"
);
}
fn
visit_ty
(
&
mut
self
,
t
:
Ty
<
'tcx
>
)
->
ControlFlow
<
Self
::
BreakTy
>
{
if
t
.flags
()
.intersects
(
TypeFlags
::
HAS_UNKNOWN_DEFAULT_CONST_SUBSTS
)
{
t
.super_visit_with
(
self
)
}
else
{
ControlFlow
::
CONTINUE
}
}
#[inline]
fn
visit_unevaluated_const
(
&
mut
self
,
uv
:
ty
::
Unevaluated
<
'tcx
>
)
->
ControlFlow
<
Self
::
BreakTy
>
{
if
uv
.substs_
.is_none
()
{
self
.tcx
.default_anon_const_substs
(
uv
.def.did
)
.visit_with
(
&
mut
HasTypeFlagsVisitor
{
tcx
:
Some
(
self
.tcx
),
flags
:
self
.flags
})
}
else
{
ControlFlow
::
CONTINUE
}
}
#[inline]
fn
visit_predicate
(
&
mut
self
,
predicate
:
ty
::
Predicate
<
'tcx
>
)
->
ControlFlow
<
Self
::
BreakTy
>
{
if
predicate
.inner.flags
.intersects
(
TypeFlags
::
HAS_UNKNOWN_DEFAULT_CONST_SUBSTS
)
{
predicate
.super_visit_with
(
self
)
}
else
{
ControlFlow
::
CONTINUE
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录