Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
1f57f8b9
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,发现更多精彩内容 >>
提交
1f57f8b9
编写于
9月 07, 2021
作者:
E
Ellen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove `WorkNode`
上级
4cbcb093
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
10 addition
and
51 deletion
+10
-51
compiler/rustc_trait_selection/src/traits/const_evaluatable.rs
...ler/rustc_trait_selection/src/traits/const_evaluatable.rs
+10
-51
未找到文件。
compiler/rustc_trait_selection/src/traits/const_evaluatable.rs
浏览文件 @
1f57f8b9
...
...
@@ -224,24 +224,13 @@ pub fn root(self) -> Node<'tcx> {
}
}
#[derive(Debug,
Clone,
Copy,
PartialEq,
Eq)]
struct
WorkNode
<
'tcx
>
{
node
:
Node
<
'tcx
>
,
span
:
Span
,
used
:
bool
,
}
struct
AbstractConstBuilder
<
'a
,
'tcx
>
{
tcx
:
TyCtxt
<
'tcx
>
,
body_id
:
thir
::
ExprId
,
/// `Lrc` is used to avoid borrowck difficulties in `recurse_build`
body
:
Lrc
<&
'a
thir
::
Thir
<
'tcx
>>
,
/// The current WIP node tree.
///
/// We require all nodes to be used in the final abstract const,
/// so we store this here. Note that we also consider nodes as used
/// if they are mentioned in an assert, so some used nodes are never
/// actually reachable by walking the [`AbstractConst`].
nodes
:
IndexVec
<
NodeId
,
WorkNode
<
'tcx
>>
,
nodes
:
IndexVec
<
NodeId
,
Node
<
'tcx
>>
,
}
impl
<
'a
,
'tcx
>
AbstractConstBuilder
<
'a
,
'tcx
>
{
...
...
@@ -301,30 +290,6 @@ fn visit_const(&mut self, ct: &'tcx ty::Const<'tcx>) {
Ok
(
Some
(
builder
))
}
fn
add_node
(
&
mut
self
,
node
:
Node
<
'tcx
>
,
span
:
Span
)
->
NodeId
{
// Mark used nodes.
match
node
{
Node
::
Leaf
(
_
)
=>
(),
Node
::
Binop
(
_
,
lhs
,
rhs
)
=>
{
self
.nodes
[
lhs
]
.used
=
true
;
self
.nodes
[
rhs
]
.used
=
true
;
}
Node
::
UnaryOp
(
_
,
input
)
=>
{
self
.nodes
[
input
]
.used
=
true
;
}
Node
::
FunctionCall
(
func
,
nodes
)
=>
{
self
.nodes
[
func
]
.used
=
true
;
nodes
.iter
()
.for_each
(|
&
n
|
self
.nodes
[
n
]
.used
=
true
);
}
Node
::
Cast
(
operand
,
_
)
=>
{
self
.nodes
[
operand
]
.used
=
true
;
}
}
// Nodes start as unused.
self
.nodes
.push
(
WorkNode
{
node
,
span
,
used
:
false
})
}
/// We do not allow all binary operations in abstract consts, so filter disallowed ones.
fn
check_binop
(
op
:
mir
::
BinOp
)
->
bool
{
use
mir
::
BinOp
::
*
;
...
...
@@ -348,23 +313,17 @@ fn check_unop(op: mir::UnOp) -> bool {
/// encountering an unspported operation.
fn
build
(
mut
self
)
->
Result
<&
'tcx
[
Node
<
'tcx
>
],
ErrorReported
>
{
debug!
(
"Abstractconstbuilder::build: body={:?}"
,
&*
self
.body
);
let
last
=
self
.recurse_build
(
self
.body_id
)
?
;
self
.nodes
[
last
]
.used
=
true
;
self
.recurse_build
(
self
.body_id
)
?
;
for
n
in
self
.nodes
.iter
()
{
if
let
Node
::
Leaf
(
ty
::
Const
{
val
:
ty
::
ConstKind
::
Unevaluated
(
ct
),
ty
:
_
})
=
n
.node
{
if
let
Node
::
Leaf
(
ty
::
Const
{
val
:
ty
::
ConstKind
::
Unevaluated
(
ct
),
ty
:
_
})
=
n
{
// `AbstractConst`s should not contain any promoteds as they require references which
// are not allowed.
assert_eq!
(
ct
.promoted
,
None
);
}
}
// FIXME I dont even think we can get unused nodes anymore with thir abstract const
if
let
Some
(
&
unused
)
=
self
.nodes
.iter
()
.find
(|
n
|
!
n
.used
)
{
self
.error
(
Some
(
unused
.span
),
"dead code"
)
?
;
}
Ok
(
self
.tcx.arena
.alloc_from_iter
(
self
.nodes
.into_iter
()
.map
(|
n
|
n
.node
)))
Ok
(
self
.tcx.arena
.alloc_from_iter
(
self
.nodes
.into_iter
()))
}
fn
recurse_build
(
&
mut
self
,
node
:
thir
::
ExprId
)
->
Result
<
NodeId
,
ErrorReported
>
{
...
...
@@ -380,7 +339,7 @@ fn recurse_build(&mut self, node: thir::ExprId) -> Result<NodeId, ErrorReported>
// subtle: associated consts are literals this arm handles
// `<T as Trait>::ASSOC` as well as `12`
&
ExprKind
::
Literal
{
literal
,
..
}
|
&
ExprKind
::
StaticRef
{
literal
,
..
}
=>
self
.
add_node
(
Node
::
Leaf
(
literal
),
node
.span
),
|
&
ExprKind
::
StaticRef
{
literal
,
..
}
=>
self
.
nodes
.push
(
Node
::
Leaf
(
literal
)
),
// FIXME(generic_const_exprs) handle `from_hir_call` field
ExprKind
::
Call
{
fun
,
args
,
..
}
=>
{
...
...
@@ -391,16 +350,16 @@ fn recurse_build(&mut self, node: thir::ExprId) -> Result<NodeId, ErrorReported>
new_args
.push
(
self
.recurse_build
(
id
)
?
);
}
let
new_args
=
self
.tcx.arena
.alloc_slice
(
&
new_args
);
self
.
add_node
(
Node
::
FunctionCall
(
fun
,
new_args
),
node
.span
)
self
.
nodes
.push
(
Node
::
FunctionCall
(
fun
,
new_args
)
)
},
&
ExprKind
::
Binary
{
op
,
lhs
,
rhs
}
if
Self
::
check_binop
(
op
)
=>
{
let
lhs
=
self
.recurse_build
(
lhs
)
?
;
let
rhs
=
self
.recurse_build
(
rhs
)
?
;
self
.
add_node
(
Node
::
Binop
(
op
,
lhs
,
rhs
),
node
.span
)
self
.
nodes
.push
(
Node
::
Binop
(
op
,
lhs
,
rhs
)
)
}
&
ExprKind
::
Unary
{
op
,
arg
}
if
Self
::
check_unop
(
op
)
=>
{
let
arg
=
self
.recurse_build
(
arg
)
?
;
self
.
add_node
(
Node
::
UnaryOp
(
op
,
arg
),
node
.span
)
self
.
nodes
.push
(
Node
::
UnaryOp
(
op
,
arg
)
)
},
// this is necessary so that the following compiles:
//
...
...
@@ -416,7 +375,7 @@ fn recurse_build(&mut self, node: thir::ExprId) -> Result<NodeId, ErrorReported>
&
ExprKind
::
Use
{
source
}
|
&
ExprKind
::
Cast
{
source
}
=>
{
let
arg
=
self
.recurse_build
(
source
)
?
;
self
.
add_node
(
Node
::
Cast
(
arg
,
node
.ty
),
node
.span
)
self
.
nodes
.push
(
Node
::
Cast
(
arg
,
node
.ty
)
)
},
// FIXME(generic_const_exprs) we want to support these
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录