Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
bc0156ba
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,发现更多精彩内容 >>
提交
bc0156ba
编写于
8月 02, 2021
作者:
L
lcnr
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
shrink `ty::PredicateKind` again
上级
283e0e67
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
68 addition
and
22 deletion
+68
-22
compiler/rustc_infer/src/infer/mod.rs
compiler/rustc_infer/src/infer/mod.rs
+2
-2
compiler/rustc_middle/src/query/mod.rs
compiler/rustc_middle/src/query/mod.rs
+1
-1
compiler/rustc_middle/src/ty/consts/kind.rs
compiler/rustc_middle/src/ty/consts/kind.rs
+24
-5
compiler/rustc_middle/src/ty/flags.rs
compiler/rustc_middle/src/ty/flags.rs
+1
-1
compiler/rustc_middle/src/ty/mod.rs
compiler/rustc_middle/src/ty/mod.rs
+2
-2
compiler/rustc_middle/src/ty/relate.rs
compiler/rustc_middle/src/ty/relate.rs
+1
-1
compiler/rustc_middle/src/ty/structural_impls.rs
compiler/rustc_middle/src/ty/structural_impls.rs
+25
-0
compiler/rustc_query_impl/src/keys.rs
compiler/rustc_query_impl/src/keys.rs
+1
-1
compiler/rustc_trait_selection/src/traits/const_evaluatable.rs
...ler/rustc_trait_selection/src/traits/const_evaluatable.rs
+5
-5
compiler/rustc_trait_selection/src/traits/fulfill.rs
compiler/rustc_trait_selection/src/traits/fulfill.rs
+1
-1
compiler/rustc_trait_selection/src/traits/select/mod.rs
compiler/rustc_trait_selection/src/traits/select/mod.rs
+1
-1
compiler/rustc_typeck/src/collect.rs
compiler/rustc_typeck/src/collect.rs
+4
-2
未找到文件。
compiler/rustc_infer/src/infer/mod.rs
浏览文件 @
bc0156ba
...
...
@@ -675,8 +675,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
/// canonicalizing the consts.
pub
fn
try_unify_abstract_consts
(
&
self
,
a
:
ty
::
Unevaluated
<
'tcx
>
,
b
:
ty
::
Unevaluated
<
'tcx
>
,
a
:
ty
::
Unevaluated
<
'tcx
,
()
>
,
b
:
ty
::
Unevaluated
<
'tcx
,
()
>
,
)
->
bool
{
let
canonical
=
self
.canonicalize_query
((
a
,
b
),
&
mut
OriginalQueryValues
::
default
());
debug!
(
"canonical consts: {:?}"
,
&
canonical
.value
);
...
...
compiler/rustc_middle/src/query/mod.rs
浏览文件 @
bc0156ba
...
...
@@ -303,7 +303,7 @@
}
query
try_unify_abstract_consts
(
key
:
(
ty
::
Unevaluated
<
'tcx
>
,
ty
::
Unevaluated
<
'tcx
>
ty
::
Unevaluated
<
'tcx
,
()
>
,
ty
::
Unevaluated
<
'tcx
,
()
>
))
->
bool
{
desc
{
|
tcx
|
"trying to unify the generic constants {} and {}"
,
...
...
compiler/rustc_middle/src/ty/consts/kind.rs
浏览文件 @
bc0156ba
use
std
::
convert
::
TryInto
;
use
std
::
fmt
;
use
crate
::
mir
::
interpret
::{
AllocId
,
ConstValue
,
Scalar
};
use
crate
::
mir
::
Promoted
;
...
...
@@ -20,20 +21,38 @@
/// so refer to that check for more info.
#[derive(Copy,
Clone,
Debug,
Eq,
PartialEq,
PartialOrd,
Ord,
TyEncodable,
TyDecodable,
Lift)]
#[derive(Hash,
HashStable)]
pub
struct
Unevaluated
<
'tcx
>
{
pub
struct
Unevaluated
<
'tcx
,
P
=
Option
<
Promoted
>
>
{
pub
def
:
ty
::
WithOptConstParam
<
DefId
>
,
pub
substs_
:
Option
<
SubstsRef
<
'tcx
>>
,
pub
promoted
:
Option
<
Promoted
>
,
pub
promoted
:
P
,
}
impl
<
'tcx
>
Unevaluated
<
'tcx
>
{
pub
fn
new
(
def
:
ty
::
WithOptConstParam
<
DefId
>
,
substs
:
SubstsRef
<
'tcx
>
)
->
Unevaluated
<
'tcx
>
{
Unevaluated
{
def
,
substs_
:
Some
(
substs
),
promoted
:
None
}
pub
fn
shrink
(
self
)
->
Unevaluated
<
'tcx
,
()
>
{
debug_assert_eq!
(
self
.promoted
,
None
);
Unevaluated
{
def
:
self
.def
,
substs_
:
self
.substs_
,
promoted
:
()
}
}
}
impl
<
'tcx
>
Unevaluated
<
'tcx
,
()
>
{
pub
fn
expand
(
self
)
->
Unevaluated
<
'tcx
>
{
Unevaluated
{
def
:
self
.def
,
substs_
:
self
.substs_
,
promoted
:
None
}
}
}
impl
<
'tcx
,
P
:
Default
>
Unevaluated
<
'tcx
,
P
>
{
pub
fn
new
(
def
:
ty
::
WithOptConstParam
<
DefId
>
,
substs
:
SubstsRef
<
'tcx
>
)
->
Unevaluated
<
'tcx
,
P
>
{
Unevaluated
{
def
,
substs_
:
Some
(
substs
),
promoted
:
Default
::
default
()
}
}
}
impl
<
'tcx
,
P
:
Default
+
PartialEq
+
fmt
::
Debug
>
Unevaluated
<
'tcx
,
P
>
{
pub
fn
substs
(
self
,
tcx
:
TyCtxt
<
'tcx
>
)
->
SubstsRef
<
'tcx
>
{
self
.substs_
.unwrap_or_else
(||
{
debug_assert_eq!
(
self
.promoted
,
None
);
// We must not use the parents default substs for promoted constants
// as that can result in incorrect substs and calls the `default_anon_const_substs`
// for something that might not actually be a constant.
debug_assert_eq!
(
self
.promoted
,
Default
::
default
());
tcx
.default_anon_const_substs
(
self
.def.did
)
})
}
...
...
compiler/rustc_middle/src/ty/flags.rs
浏览文件 @
bc0156ba
...
...
@@ -310,7 +310,7 @@ fn add_const(&mut self, c: &ty::Const<'_>) {
}
}
fn
add_unevaluated_const
(
&
mut
self
,
ct
:
ty
::
Unevaluated
<
'tcx
>
)
{
fn
add_unevaluated_const
<
P
>
(
&
mut
self
,
ct
:
ty
::
Unevaluated
<
'tcx
,
P
>
)
{
if
let
Some
(
substs
)
=
ct
.substs_
{
self
.add_substs
(
substs
);
}
else
{
...
...
compiler/rustc_middle/src/ty/mod.rs
浏览文件 @
bc0156ba
...
...
@@ -406,7 +406,7 @@ pub fn has_name(&self) -> bool {
}
#[cfg(all(target_arch
=
"x86_64"
,
target_pointer_width
=
"64"
))]
static_assert_size!
(
PredicateInner
<
'_
>
,
56
);
static_assert_size!
(
PredicateInner
<
'_
>
,
48
);
#[derive(Clone,
Copy,
Lift)]
pub
struct
Predicate
<
'tcx
>
{
...
...
@@ -502,7 +502,7 @@ pub enum PredicateKind<'tcx> {
Coerce
(
CoercePredicate
<
'tcx
>
),
/// Constant initializer must evaluate successfully.
ConstEvaluatable
(
ty
::
Unevaluated
<
'tcx
>
),
ConstEvaluatable
(
ty
::
Unevaluated
<
'tcx
,
()
>
),
/// Constants must be equal. The first component is the const that is expected.
ConstEquate
(
&
'tcx
Const
<
'tcx
>
,
&
'tcx
Const
<
'tcx
>
),
...
...
compiler/rustc_middle/src/ty/relate.rs
浏览文件 @
bc0156ba
...
...
@@ -579,7 +579,7 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
(
ty
::
ConstKind
::
Unevaluated
(
au
),
ty
::
ConstKind
::
Unevaluated
(
bu
))
if
tcx
.features
()
.const_evaluatable_checked
=>
{
tcx
.try_unify_abstract_consts
((
au
,
bu
))
tcx
.try_unify_abstract_consts
((
au
.shrink
(),
bu
.shrink
()
))
}
// While this is slightly incorrect, it shouldn't matter for `min_const_generics`
...
...
compiler/rustc_middle/src/ty/structural_impls.rs
浏览文件 @
bc0156ba
...
...
@@ -1105,3 +1105,28 @@ fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow
}
}
}
impl
<
'tcx
>
TypeFoldable
<
'tcx
>
for
ty
::
Unevaluated
<
'tcx
,
()
>
{
fn
super_fold_with
<
F
:
TypeFolder
<
'tcx
>>
(
self
,
folder
:
&
mut
F
)
->
Self
{
ty
::
Unevaluated
{
def
:
self
.def
,
substs_
:
Some
(
self
.substs
(
folder
.tcx
())
.fold_with
(
folder
)),
promoted
:
self
.promoted
,
}
}
fn
visit_with
<
V
:
TypeVisitor
<
'tcx
>>
(
&
self
,
visitor
:
&
mut
V
)
->
ControlFlow
<
V
::
BreakTy
>
{
visitor
.visit_unevaluated_const
(
self
.expand
())
}
fn
super_visit_with
<
V
:
TypeVisitor
<
'tcx
>>
(
&
self
,
visitor
:
&
mut
V
)
->
ControlFlow
<
V
::
BreakTy
>
{
if
let
Some
(
tcx
)
=
visitor
.tcx_for_anon_const_substs
()
{
self
.substs
(
tcx
)
.visit_with
(
visitor
)
}
else
if
let
Some
(
substs
)
=
self
.substs_
{
substs
.visit_with
(
visitor
)
}
else
{
debug!
(
"ignoring default substs of `{:?}`"
,
self
.def
);
ControlFlow
::
CONTINUE
}
}
}
compiler/rustc_query_impl/src/keys.rs
浏览文件 @
bc0156ba
...
...
@@ -217,7 +217,7 @@ fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
}
}
impl
<
'tcx
>
Key
for
(
ty
::
Unevaluated
<
'tcx
>
,
ty
::
Unevaluated
<
'tcx
>
)
{
impl
<
'tcx
>
Key
for
(
ty
::
Unevaluated
<
'tcx
,
()
>
,
ty
::
Unevaluated
<
'tcx
,
()
>
)
{
#[inline(always)]
fn
query_crate_is_local
(
&
self
)
->
bool
{
(
self
.0
)
.def.did.krate
==
LOCAL_CRATE
...
...
compiler/rustc_trait_selection/src/traits/const_evaluatable.rs
浏览文件 @
bc0156ba
...
...
@@ -29,7 +29,7 @@
/// Check if a given constant can be evaluated.
pub
fn
is_const_evaluatable
<
'cx
,
'tcx
>
(
infcx
:
&
InferCtxt
<
'cx
,
'tcx
>
,
uv
:
ty
::
Unevaluated
<
'tcx
>
,
uv
:
ty
::
Unevaluated
<
'tcx
,
()
>
,
param_env
:
ty
::
ParamEnv
<
'tcx
>
,
span
:
Span
,
)
->
Result
<
(),
NotConstEvaluatable
>
{
...
...
@@ -149,7 +149,7 @@ enum FailureKind {
// and hopefully soon change this to an error.
//
// See #74595 for more details about this.
let
concrete
=
infcx
.const_eval_resolve
(
param_env
,
uv
,
Some
(
span
));
let
concrete
=
infcx
.const_eval_resolve
(
param_env
,
uv
.expand
()
,
Some
(
span
));
if
concrete
.is_ok
()
&&
uv
.substs
(
infcx
.tcx
)
.has_param_types_or_consts
(
infcx
.tcx
)
{
match
infcx
.tcx
.def_kind
(
uv
.def.did
)
{
...
...
@@ -194,7 +194,7 @@ pub struct AbstractConst<'tcx> {
impl
<
'tcx
>
AbstractConst
<
'tcx
>
{
pub
fn
new
(
tcx
:
TyCtxt
<
'tcx
>
,
uv
:
ty
::
Unevaluated
<
'tcx
>
,
uv
:
ty
::
Unevaluated
<
'tcx
,
()
>
,
)
->
Result
<
Option
<
AbstractConst
<
'tcx
>>
,
ErrorReported
>
{
let
inner
=
tcx
.mir_abstract_const_opt_const_arg
(
uv
.def
)
?
;
debug!
(
"AbstractConst::new({:?}) = {:?}"
,
uv
,
inner
);
...
...
@@ -206,7 +206,7 @@ pub fn from_const(
ct
:
&
ty
::
Const
<
'tcx
>
,
)
->
Result
<
Option
<
AbstractConst
<
'tcx
>>
,
ErrorReported
>
{
match
ct
.val
{
ty
::
ConstKind
::
Unevaluated
(
uv
)
=>
AbstractConst
::
new
(
tcx
,
uv
),
ty
::
ConstKind
::
Unevaluated
(
uv
)
=>
AbstractConst
::
new
(
tcx
,
uv
.shrink
()
),
ty
::
ConstKind
::
Error
(
_
)
=>
Err
(
ErrorReported
),
_
=>
Ok
(
None
),
}
...
...
@@ -556,7 +556,7 @@ pub(super) fn mir_abstract_const<'tcx>(
pub
(
super
)
fn
try_unify_abstract_consts
<
'tcx
>
(
tcx
:
TyCtxt
<
'tcx
>
,
(
a
,
b
):
(
ty
::
Unevaluated
<
'tcx
>
,
ty
::
Unevaluated
<
'tcx
>
),
(
a
,
b
):
(
ty
::
Unevaluated
<
'tcx
,
()
>
,
ty
::
Unevaluated
<
'tcx
,
()
>
),
)
->
bool
{
(||
{
if
let
Some
(
a
)
=
AbstractConst
::
new
(
tcx
,
a
)
?
{
...
...
compiler/rustc_trait_selection/src/traits/fulfill.rs
浏览文件 @
bc0156ba
...
...
@@ -580,7 +580,7 @@ fn progress_changed_obligations(
if
let
(
ty
::
ConstKind
::
Unevaluated
(
a
),
ty
::
ConstKind
::
Unevaluated
(
b
))
=
(
c1
.val
,
c2
.val
)
{
if
infcx
.try_unify_abstract_consts
(
a
,
b
)
{
if
infcx
.try_unify_abstract_consts
(
a
.shrink
(),
b
.shrink
()
)
{
return
ProcessResult
::
Changed
(
vec!
[]);
}
}
...
...
compiler/rustc_trait_selection/src/traits/select/mod.rs
浏览文件 @
bc0156ba
...
...
@@ -623,7 +623,7 @@ fn evaluate_predicate_recursively<'o>(
if
let
(
ty
::
ConstKind
::
Unevaluated
(
a
),
ty
::
ConstKind
::
Unevaluated
(
b
))
=
(
c1
.val
,
c2
.val
)
{
if
self
.infcx
.try_unify_abstract_consts
(
a
,
b
)
{
if
self
.infcx
.try_unify_abstract_consts
(
a
.shrink
(),
b
.shrink
()
)
{
return
Ok
(
EvaluatedToOk
);
}
}
...
...
compiler/rustc_typeck/src/collect.rs
浏览文件 @
bc0156ba
...
...
@@ -2355,8 +2355,10 @@ fn visit_anon_const(&mut self, c: &'tcx hir::AnonConst) {
if
let
ty
::
ConstKind
::
Unevaluated
(
uv
)
=
ct
.val
{
assert_eq!
(
uv
.promoted
,
None
);
let
span
=
self
.tcx
.hir
()
.span
(
c
.hir_id
);
self
.preds
.insert
((
ty
::
PredicateKind
::
ConstEvaluatable
(
uv
)
.to_predicate
(
self
.tcx
),
span
));
self
.preds
.insert
((
ty
::
PredicateKind
::
ConstEvaluatable
(
uv
.shrink
())
.to_predicate
(
self
.tcx
),
span
,
));
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录