Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
e2496b3c
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,发现更多精彩内容 >>
提交
e2496b3c
编写于
3月 15, 2022
作者:
B
b-naber
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove thir::Visitor::visit_const
上级
f713b501
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
25 addition
and
34 deletion
+25
-34
compiler/rustc_middle/src/thir.rs
compiler/rustc_middle/src/thir.rs
+0
-1
compiler/rustc_middle/src/thir/visit.rs
compiler/rustc_middle/src/thir/visit.rs
+4
-11
compiler/rustc_mir_build/src/build/expr/as_constant.rs
compiler/rustc_mir_build/src/build/expr/as_constant.rs
+2
-13
compiler/rustc_mir_build/src/build/expr/as_temp.rs
compiler/rustc_mir_build/src/build/expr/as_temp.rs
+1
-0
compiler/rustc_mir_build/src/thir/cx/expr.rs
compiler/rustc_mir_build/src/thir/cx/expr.rs
+0
-1
compiler/rustc_trait_selection/src/traits/const_evaluatable.rs
...ler/rustc_trait_selection/src/traits/const_evaluatable.rs
+18
-8
未找到文件。
compiler/rustc_middle/src/thir.rs
浏览文件 @
e2496b3c
...
@@ -426,7 +426,6 @@ pub enum ExprKind<'tcx> {
...
@@ -426,7 +426,6 @@ pub enum ExprKind<'tcx> {
ConstParam
{
ConstParam
{
literal
:
ty
::
Const
<
'tcx
>
,
literal
:
ty
::
Const
<
'tcx
>
,
def_id
:
DefId
,
def_id
:
DefId
,
user_ty
:
Option
<
Canonical
<
'tcx
,
UserType
<
'tcx
>>>
,
},
},
// FIXME improve docs for `StaticRef` by distinguishing it from `NamedConst`
// FIXME improve docs for `StaticRef` by distinguishing it from `NamedConst`
/// A literal containing the address of a `static`.
/// A literal containing the address of a `static`.
...
...
compiler/rustc_middle/src/thir/visit.rs
浏览文件 @
e2496b3c
use
super
::{
use
super
::{
Arm
,
Block
,
Expr
,
ExprKind
,
Guard
,
InlineAsmOperand
,
Pat
,
PatKind
,
Stmt
,
StmtKind
,
Thir
,
Arm
,
Block
,
Expr
,
ExprKind
,
Guard
,
InlineAsmOperand
,
Pat
,
PatKind
,
Stmt
,
StmtKind
,
Thir
,
};
};
use
rustc_middle
::
ty
::
Const
;
pub
trait
Visitor
<
'a
,
'tcx
:
'a
>
:
Sized
{
pub
trait
Visitor
<
'a
,
'tcx
:
'a
>
:
Sized
{
fn
thir
(
&
self
)
->
&
'a
Thir
<
'tcx
>
;
fn
thir
(
&
self
)
->
&
'a
Thir
<
'tcx
>
;
...
@@ -25,8 +24,6 @@ fn visit_arm(&mut self, arm: &Arm<'tcx>) {
...
@@ -25,8 +24,6 @@ fn visit_arm(&mut self, arm: &Arm<'tcx>) {
fn
visit_pat
(
&
mut
self
,
pat
:
&
Pat
<
'tcx
>
)
{
fn
visit_pat
(
&
mut
self
,
pat
:
&
Pat
<
'tcx
>
)
{
walk_pat
(
self
,
pat
);
walk_pat
(
self
,
pat
);
}
}
fn
visit_const
(
&
mut
self
,
_
cnst
:
Const
<
'tcx
>
)
{}
}
}
pub
fn
walk_expr
<
'a
,
'tcx
:
'a
,
V
:
Visitor
<
'a
,
'tcx
>>
(
visitor
:
&
mut
V
,
expr
:
&
Expr
<
'tcx
>
)
{
pub
fn
walk_expr
<
'a
,
'tcx
:
'a
,
V
:
Visitor
<
'a
,
'tcx
>>
(
visitor
:
&
mut
V
,
expr
:
&
Expr
<
'tcx
>
)
{
...
@@ -94,9 +91,8 @@ pub fn walk_expr<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, expr: &Exp
...
@@ -94,9 +91,8 @@ pub fn walk_expr<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, expr: &Exp
}
}
}
}
ConstBlock
{
did
:
_
,
substs
:
_
}
=>
{}
ConstBlock
{
did
:
_
,
substs
:
_
}
=>
{}
Repeat
{
value
,
count
}
=>
{
Repeat
{
value
,
count
:
_
}
=>
{
visitor
.visit_expr
(
&
visitor
.thir
()[
value
]);
visitor
.visit_expr
(
&
visitor
.thir
()[
value
]);
visitor
.visit_const
(
count
);
}
}
Array
{
ref
fields
}
|
Tuple
{
ref
fields
}
=>
{
Array
{
ref
fields
}
|
Tuple
{
ref
fields
}
=>
{
for
&
field
in
&**
fields
{
for
&
field
in
&**
fields
{
...
@@ -125,7 +121,7 @@ pub fn walk_expr<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, expr: &Exp
...
@@ -125,7 +121,7 @@ pub fn walk_expr<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, expr: &Exp
Literal
{
lit
:
_
,
neg
:
_
}
=>
{}
Literal
{
lit
:
_
,
neg
:
_
}
=>
{}
ScalarLiteral
{
lit
:
_
,
user_ty
:
_
}
=>
{}
ScalarLiteral
{
lit
:
_
,
user_ty
:
_
}
=>
{}
NamedConst
{
def_id
:
_
,
substs
:
_
,
user_ty
:
_
}
=>
{}
NamedConst
{
def_id
:
_
,
substs
:
_
,
user_ty
:
_
}
=>
{}
ConstParam
{
literal
:
_
,
def_id
:
_
,
user_ty
:
_
}
=>
{}
ConstParam
{
literal
:
_
,
def_id
:
_
}
=>
{}
StaticRef
{
alloc_id
:
_
,
ty
:
_
,
def_id
:
_
}
=>
{}
StaticRef
{
alloc_id
:
_
,
ty
:
_
,
def_id
:
_
}
=>
{}
InlineAsm
{
ref
operands
,
template
:
_
,
options
:
_
,
line_spans
:
_
}
=>
{
InlineAsm
{
ref
operands
,
template
:
_
,
options
:
_
,
line_spans
:
_
}
=>
{
for
op
in
&**
operands
{
for
op
in
&**
operands
{
...
@@ -212,11 +208,8 @@ pub fn walk_pat<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, pat: &Pat<'
...
@@ -212,11 +208,8 @@ pub fn walk_pat<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, pat: &Pat<'
visitor
.visit_pat
(
&
subpattern
.pattern
);
visitor
.visit_pat
(
&
subpattern
.pattern
);
}
}
}
}
Constant
{
value
}
=>
visitor
.visit_const
(
*
value
),
Constant
{
value
:
_
}
=>
{}
Range
(
range
)
=>
{
Range
(
_
)
=>
{}
visitor
.visit_const
(
range
.lo
);
visitor
.visit_const
(
range
.hi
);
}
Slice
{
prefix
,
slice
,
suffix
}
|
Array
{
prefix
,
slice
,
suffix
}
=>
{
Slice
{
prefix
,
slice
,
suffix
}
|
Array
{
prefix
,
slice
,
suffix
}
=>
{
for
subpattern
in
prefix
{
for
subpattern
in
prefix
{
visitor
.visit_pat
(
&
subpattern
);
visitor
.visit_pat
(
&
subpattern
);
...
...
compiler/rustc_mir_build/src/build/expr/as_constant.rs
浏览文件 @
e2496b3c
...
@@ -17,10 +17,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
...
@@ -17,10 +17,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
/// Compile `expr`, yielding a compile-time constant. Assumes that
/// Compile `expr`, yielding a compile-time constant. Assumes that
/// `expr` is a valid compile-time constant!
/// `expr` is a valid compile-time constant!
crate
fn
as_constant
(
&
mut
self
,
expr
:
&
Expr
<
'tcx
>
)
->
Constant
<
'tcx
>
{
crate
fn
as_constant
(
&
mut
self
,
expr
:
&
Expr
<
'tcx
>
)
->
Constant
<
'tcx
>
{
debug!
(
"expr: {:#?}"
,
expr
);
// FIXME: Maybe we should try to evaluate here and only create an `Unevaluated`
// constant in case the evaluation fails. Need some evaluation function that
// allows normalization to fail.
let
create_uneval_from_def_id
=
let
create_uneval_from_def_id
=
|
tcx
:
TyCtxt
<
'tcx
>
,
def_id
:
DefId
,
ty
:
Ty
<
'tcx
>
,
substs
:
SubstsRef
<
'tcx
>
|
{
|
tcx
:
TyCtxt
<
'tcx
>
,
def_id
:
DefId
,
ty
:
Ty
<
'tcx
>
,
substs
:
SubstsRef
<
'tcx
>
|
{
let
uneval
=
ty
::
Unevaluated
::
new
(
ty
::
WithOptConstParam
::
unknown
(
def_id
),
substs
);
let
uneval
=
ty
::
Unevaluated
::
new
(
ty
::
WithOptConstParam
::
unknown
(
def_id
),
substs
);
...
@@ -74,17 +70,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
...
@@ -74,17 +70,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
Constant
{
user_ty
,
span
,
literal
}
Constant
{
user_ty
,
span
,
literal
}
}
}
ExprKind
::
ConstParam
{
literal
,
def_id
:
_
,
user_ty
}
=>
{
ExprKind
::
ConstParam
{
literal
,
def_id
:
_
}
=>
{
let
user_ty
=
user_ty
.map
(|
user_ty
|
{
this
.canonical_user_type_annotations
.push
(
CanonicalUserTypeAnnotation
{
span
,
user_ty
,
inferred_ty
:
ty
,
})
});
let
literal
=
ConstantKind
::
Ty
(
literal
);
let
literal
=
ConstantKind
::
Ty
(
literal
);
Constant
{
user_ty
:
user_ty
,
span
,
literal
}
Constant
{
user_ty
:
None
,
span
,
literal
}
}
}
ExprKind
::
ConstBlock
{
did
:
def_id
,
substs
}
=>
{
ExprKind
::
ConstBlock
{
did
:
def_id
,
substs
}
=>
{
let
literal
=
ConstantKind
::
Ty
(
create_uneval_from_def_id
(
tcx
,
def_id
,
ty
,
substs
));
let
literal
=
ConstantKind
::
Ty
(
create_uneval_from_def_id
(
tcx
,
def_id
,
ty
,
substs
));
...
...
compiler/rustc_mir_build/src/build/expr/as_temp.rs
浏览文件 @
e2496b3c
...
@@ -70,6 +70,7 @@ fn as_temp_inner(
...
@@ -70,6 +70,7 @@ fn as_temp_inner(
local_decl
.local_info
=
local_decl
.local_info
=
Some
(
Box
::
new
(
LocalInfo
::
StaticRef
{
def_id
,
is_thread_local
:
true
}));
Some
(
Box
::
new
(
LocalInfo
::
StaticRef
{
def_id
,
is_thread_local
:
true
}));
}
}
// FIXME Might have to include `ExprKind::ConstParam` here as well
ExprKind
::
NamedConst
{
def_id
,
..
}
=>
{
ExprKind
::
NamedConst
{
def_id
,
..
}
=>
{
local_decl
.local_info
=
Some
(
Box
::
new
(
LocalInfo
::
ConstRef
{
def_id
}));
local_decl
.local_info
=
Some
(
Box
::
new
(
LocalInfo
::
ConstRef
{
def_id
}));
}
}
...
...
compiler/rustc_mir_build/src/thir/cx/expr.rs
浏览文件 @
e2496b3c
...
@@ -876,7 +876,6 @@ fn convert_path_expr(&mut self, expr: &'tcx hir::Expr<'tcx>, res: Res) -> ExprKi
...
@@ -876,7 +876,6 @@ fn convert_path_expr(&mut self, expr: &'tcx hir::Expr<'tcx>, res: Res) -> ExprKi
val
,
val
,
ty
:
self
.typeck_results
()
.node_type
(
expr
.hir_id
),
ty
:
self
.typeck_results
()
.node_type
(
expr
.hir_id
),
}),
}),
user_ty
:
None
,
def_id
,
def_id
,
}
}
}
}
...
...
compiler/rustc_trait_selection/src/traits/const_evaluatable.rs
浏览文件 @
e2496b3c
...
@@ -39,7 +39,7 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
...
@@ -39,7 +39,7 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
)
->
Result
<
(),
NotConstEvaluatable
>
{
)
->
Result
<
(),
NotConstEvaluatable
>
{
let
tcx
=
infcx
.tcx
;
let
tcx
=
infcx
.tcx
;
if
infcx
.
tcx
.features
()
.generic_const_exprs
{
if
tcx
.features
()
.generic_const_exprs
{
match
AbstractConst
::
new
(
tcx
,
uv
)
?
{
match
AbstractConst
::
new
(
tcx
,
uv
)
?
{
// We are looking at a generic abstract constant.
// We are looking at a generic abstract constant.
Some
(
ct
)
=>
{
Some
(
ct
)
=>
{
...
@@ -342,7 +342,13 @@ fn thir(&self) -> &'a thir::Thir<'tcx> {
...
@@ -342,7 +342,13 @@ fn thir(&self) -> &'a thir::Thir<'tcx> {
fn
visit_expr
(
&
mut
self
,
expr
:
&
thir
::
Expr
<
'tcx
>
)
{
fn
visit_expr
(
&
mut
self
,
expr
:
&
thir
::
Expr
<
'tcx
>
)
{
self
.is_poly
|
=
self
.expr_is_poly
(
expr
);
self
.is_poly
|
=
self
.expr_is_poly
(
expr
);
if
!
self
.is_poly
{
if
!
self
.is_poly
{
visit
::
walk_expr
(
self
,
expr
)
match
expr
.kind
{
thir
::
ExprKind
::
Repeat
{
value
,
count
}
=>
{
self
.visit_expr
(
&
self
.thir
()[
value
]);
self
.is_poly
|
=
count
.has_param_types_or_consts
();
}
_
=>
visit
::
walk_expr
(
self
,
expr
),
}
}
}
}
}
...
@@ -350,14 +356,18 @@ fn visit_expr(&mut self, expr: &thir::Expr<'tcx>) {
...
@@ -350,14 +356,18 @@ fn visit_expr(&mut self, expr: &thir::Expr<'tcx>) {
fn
visit_pat
(
&
mut
self
,
pat
:
&
thir
::
Pat
<
'tcx
>
)
{
fn
visit_pat
(
&
mut
self
,
pat
:
&
thir
::
Pat
<
'tcx
>
)
{
self
.is_poly
|
=
pat
.ty
.has_param_types_or_consts
();
self
.is_poly
|
=
pat
.ty
.has_param_types_or_consts
();
if
!
self
.is_poly
{
if
!
self
.is_poly
{
visit
::
walk_pat
(
self
,
pat
);
match
pat
.kind
.as_ref
()
{
thir
::
PatKind
::
Constant
{
value
}
=>
{
self
.is_poly
|
=
value
.has_param_types_or_consts
();
}
thir
::
PatKind
::
Range
(
thir
::
PatRange
{
lo
,
hi
,
..
})
=>
{
self
.is_poly
|
=
lo
.has_param_types_or_consts
()
|
hi
.has_param_types_or_consts
();
}
_
=>
visit
::
walk_pat
(
self
,
pat
),
}
}
}
}
}
#[instrument(skip(self),
level
=
"debug"
)]
fn
visit_const
(
&
mut
self
,
ct
:
ty
::
Const
<
'tcx
>
)
{
self
.is_poly
|
=
ct
.has_param_types_or_consts
();
}
}
}
let
mut
is_poly_vis
=
IsThirPolymorphic
{
is_poly
:
false
,
thir
:
body
};
let
mut
is_poly_vis
=
IsThirPolymorphic
{
is_poly
:
false
,
thir
:
body
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录