Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
0347b32a
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,发现更多精彩内容 >>
提交
0347b32a
编写于
6月 04, 2018
作者:
S
scalexm
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor the chalkify lowering process
上级
6eafab06
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
234 addition
and
138 deletion
+234
-138
src/librustc/ich/impls_ty.rs
src/librustc/ich/impls_ty.rs
+35
-10
src/librustc/traits/mod.rs
src/librustc/traits/mod.rs
+29
-17
src/librustc/traits/structural_impls.rs
src/librustc/traits/structural_impls.rs
+73
-30
src/librustc_traits/chalk_context.rs
src/librustc_traits/chalk_context.rs
+25
-17
src/librustc_traits/lowering.rs
src/librustc_traits/lowering.rs
+72
-64
未找到文件。
src/librustc/ich/impls_ty.rs
浏览文件 @
0347b32a
...
...
@@ -1382,16 +1382,46 @@ impl<'tcx, R> for struct infer::canonical::QueryResult<'tcx, R> {
Proven
,
Ambiguous
});
impl
<
'a
,
'tcx
>
HashStable
<
StableHashingContext
<
'a
>>
for
traits
::
WhereClause
Atom
<
'tcx
>
{
impl
<
'a
,
'tcx
>
HashStable
<
StableHashingContext
<
'a
>>
for
traits
::
WhereClause
<
'tcx
>
{
fn
hash_stable
<
W
:
StableHasherResult
>
(
&
self
,
hcx
:
&
mut
StableHashingContext
<
'a
>
,
hasher
:
&
mut
StableHasher
<
W
>
)
{
use
traits
::
WhereClause
Atom
::
*
;
use
traits
::
WhereClause
::
*
;
mem
::
discriminant
(
self
)
.hash_stable
(
hcx
,
hasher
);
match
self
{
Implemented
(
trait_ref
)
=>
trait_ref
.hash_stable
(
hcx
,
hasher
),
ProjectionEq
(
projection
)
=>
projection
.hash_stable
(
hcx
,
hasher
),
TypeOutlives
(
ty_outlives
)
=>
ty_outlives
.hash_stable
(
hcx
,
hasher
),
RegionOutlives
(
region_outlives
)
=>
region_outlives
.hash_stable
(
hcx
,
hasher
),
}
}
}
impl
<
'a
,
'tcx
>
HashStable
<
StableHashingContext
<
'a
>>
for
traits
::
WellFormed
<
'tcx
>
{
fn
hash_stable
<
W
:
StableHasherResult
>
(
&
self
,
hcx
:
&
mut
StableHashingContext
<
'a
>
,
hasher
:
&
mut
StableHasher
<
W
>
)
{
use
traits
::
WellFormed
::
*
;
mem
::
discriminant
(
self
)
.hash_stable
(
hcx
,
hasher
);
match
self
{
Trait
(
trait_ref
)
=>
trait_ref
.hash_stable
(
hcx
,
hasher
),
Ty
(
ty
)
=>
ty
.hash_stable
(
hcx
,
hasher
),
}
}
}
impl
<
'a
,
'tcx
>
HashStable
<
StableHashingContext
<
'a
>>
for
traits
::
FromEnv
<
'tcx
>
{
fn
hash_stable
<
W
:
StableHasherResult
>
(
&
self
,
hcx
:
&
mut
StableHashingContext
<
'a
>
,
hasher
:
&
mut
StableHasher
<
W
>
)
{
use
traits
::
FromEnv
::
*
;
mem
::
discriminant
(
self
)
.hash_stable
(
hcx
,
hasher
);
match
self
{
Trait
(
trait_ref
)
=>
trait_ref
.hash_stable
(
hcx
,
hasher
),
Ty
(
ty
)
=>
ty
.hash_stable
(
hcx
,
hasher
),
}
}
}
...
...
@@ -1404,15 +1434,10 @@ fn hash_stable<W: StableHasherResult>(&self,
mem
::
discriminant
(
self
)
.hash_stable
(
hcx
,
hasher
);
match
self
{
Holds
(
where_clause
)
|
WellFormed
(
where_clause
)
|
FromEnv
(
where_clause
)
=>
where_clause
.hash_stable
(
hcx
,
hasher
),
WellFormedTy
(
ty
)
=>
ty
.hash_stable
(
hcx
,
hasher
),
Holds
(
wc
)
=>
wc
.hash_stable
(
hcx
,
hasher
),
WellFormed
(
wf
)
=>
wf
.hash_stable
(
hcx
,
hasher
),
FromEnv
(
from_env
)
=>
from_env
.hash_stable
(
hcx
,
hasher
),
Normalize
(
projection
)
=>
projection
.hash_stable
(
hcx
,
hasher
),
FromEnvTy
(
ty
)
=>
ty
.hash_stable
(
hcx
,
hasher
),
RegionOutlives
(
predicate
)
=>
predicate
.hash_stable
(
hcx
,
hasher
),
TypeOutlives
(
predicate
)
=>
predicate
.hash_stable
(
hcx
,
hasher
),
}
}
}
...
...
src/librustc/traits/mod.rs
浏览文件 @
0347b32a
...
...
@@ -269,7 +269,9 @@ pub struct DerivedObligationCause<'tcx> {
pub
type
TraitObligations
<
'tcx
>
=
Vec
<
TraitObligation
<
'tcx
>>
;
/// The following types:
/// * `WhereClauseAtom`
/// * `WhereClause`
/// * `WellFormed`
/// * `FromEnv`
/// * `DomainGoal`
/// * `Goal`
/// * `Clause`
...
...
@@ -277,21 +279,31 @@ pub struct DerivedObligationCause<'tcx> {
/// logic programming clauses. They are part of the interface
/// for the chalk SLG solver.
#[derive(Clone,
Copy,
PartialEq,
Eq,
Hash,
Debug)]
pub
enum
WhereClause
Atom
<
'tcx
>
{
pub
enum
WhereClause
<
'tcx
>
{
Implemented
(
ty
::
TraitPredicate
<
'tcx
>
),
ProjectionEq
(
ty
::
ProjectionPredicate
<
'tcx
>
),
RegionOutlives
(
ty
::
RegionOutlivesPredicate
<
'tcx
>
),
TypeOutlives
(
ty
::
TypeOutlivesPredicate
<
'tcx
>
),
}
#[derive(Clone,
Copy,
PartialEq,
Eq,
Hash,
Debug)]
pub
enum
WellFormed
<
'tcx
>
{
Trait
(
ty
::
TraitPredicate
<
'tcx
>
),
Ty
(
Ty
<
'tcx
>
),
}
#[derive(Clone,
Copy,
PartialEq,
Eq,
Hash,
Debug)]
pub
enum
FromEnv
<
'tcx
>
{
Trait
(
ty
::
TraitPredicate
<
'tcx
>
),
Ty
(
Ty
<
'tcx
>
),
}
#[derive(Clone,
Copy,
PartialEq,
Eq,
Hash,
Debug)]
pub
enum
DomainGoal
<
'tcx
>
{
Holds
(
WhereClauseAtom
<
'tcx
>
),
WellFormed
(
WhereClauseAtom
<
'tcx
>
),
FromEnv
(
WhereClauseAtom
<
'tcx
>
),
WellFormedTy
(
Ty
<
'tcx
>
),
Holds
(
WhereClause
<
'tcx
>
),
WellFormed
(
WellFormed
<
'tcx
>
),
FromEnv
(
FromEnv
<
'tcx
>
),
Normalize
(
ty
::
ProjectionPredicate
<
'tcx
>
),
FromEnvTy
(
Ty
<
'tcx
>
),
RegionOutlives
(
ty
::
RegionOutlivesPredicate
<
'tcx
>
),
TypeOutlives
(
ty
::
TypeOutlivesPredicate
<
'tcx
>
),
}
pub
type
PolyDomainGoal
<
'tcx
>
=
ty
::
Binder
<
DomainGoal
<
'tcx
>>
;
...
...
@@ -314,27 +326,27 @@ pub enum Goal<'tcx> {
pub
type
Goals
<
'tcx
>
=
&
'tcx
Slice
<
Goal
<
'tcx
>>
;
impl
<
'tcx
>
DomainGoal
<
'tcx
>
{
pub
fn
into_goal
(
self
)
->
Goal
<
'tcx
>
{
Goal
::
DomainGoal
(
self
)
}
}
impl
<
'tcx
>
Goal
<
'tcx
>
{
pub
fn
from_poly_domain_goal
<
'a
>
(
domain_goal
:
PolyDomainGoal
<
'tcx
>
,
tcx
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
,
)
->
Goal
<
'tcx
>
{
match
domain_goal
.no_late_bound_regions
()
{
Some
(
p
)
=>
p
.into
(),
Some
(
p
)
=>
p
.into
_goal
(),
None
=>
Goal
::
Quantified
(
QuantifierKind
::
Universal
,
domain_goal
.map_bound
(|
p
|
tcx
.mk_goal
(
Goal
::
from
(
p
)))
domain_goal
.map_bound
(|
p
|
tcx
.mk_goal
(
p
.into_goal
(
)))
),
}
}
}
impl
<
'tcx
>
From
<
DomainGoal
<
'tcx
>>
for
Goal
<
'tcx
>
{
fn
from
(
domain_goal
:
DomainGoal
<
'tcx
>
)
->
Self
{
Goal
::
DomainGoal
(
domain_goal
)
}
}
/// This matches the definition from Page 7 of "A Proof Procedure for the Logic of Hereditary
/// Harrop Formulas".
#[derive(Copy,
Clone,
PartialEq,
Eq,
Hash,
Debug)]
...
...
src/librustc/traits/structural_impls.rs
浏览文件 @
0347b32a
...
...
@@ -405,13 +405,37 @@ impl<'tcx, T> TypeFoldable<'tcx> for Normalized<'tcx, T> {
}
where
T
:
TypeFoldable
<
'tcx
>
}
impl
<
'tcx
>
fmt
::
Display
for
traits
::
WhereClause
Atom
<
'tcx
>
{
impl
<
'tcx
>
fmt
::
Display
for
traits
::
WhereClause
<
'tcx
>
{
fn
fmt
(
&
self
,
fmt
:
&
mut
fmt
::
Formatter
)
->
fmt
::
Result
{
use
traits
::
WhereClause
Atom
::
*
;
use
traits
::
WhereClause
::
*
;
match
self
{
Implemented
(
trait_ref
)
=>
write!
(
fmt
,
"Implemented({})"
,
trait_ref
),
ProjectionEq
(
projection
)
=>
write!
(
fmt
,
"ProjectionEq({})"
,
projection
),
RegionOutlives
(
predicate
)
=>
write!
(
fmt
,
"RegionOutlives({})"
,
predicate
),
TypeOutlives
(
predicate
)
=>
write!
(
fmt
,
"TypeOutlives({})"
,
predicate
),
}
}
}
impl
<
'tcx
>
fmt
::
Display
for
traits
::
WellFormed
<
'tcx
>
{
fn
fmt
(
&
self
,
fmt
:
&
mut
fmt
::
Formatter
)
->
fmt
::
Result
{
use
traits
::
WellFormed
::
*
;
match
self
{
Trait
(
trait_ref
)
=>
write!
(
fmt
,
"WellFormed({})"
,
trait_ref
),
Ty
(
ty
)
=>
write!
(
fmt
,
"WellFormed({})"
,
ty
),
}
}
}
impl
<
'tcx
>
fmt
::
Display
for
traits
::
FromEnv
<
'tcx
>
{
fn
fmt
(
&
self
,
fmt
:
&
mut
fmt
::
Formatter
)
->
fmt
::
Result
{
use
traits
::
FromEnv
::
*
;
match
self
{
Trait
(
trait_ref
)
=>
write!
(
fmt
,
"FromEnv({})"
,
trait_ref
),
Ty
(
ty
)
=>
write!
(
fmt
,
"FromEnv({})"
,
ty
),
}
}
}
...
...
@@ -419,19 +443,12 @@ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
impl
<
'tcx
>
fmt
::
Display
for
traits
::
DomainGoal
<
'tcx
>
{
fn
fmt
(
&
self
,
fmt
:
&
mut
fmt
::
Formatter
)
->
fmt
::
Result
{
use
traits
::
DomainGoal
::
*
;
use
traits
::
WhereClauseAtom
::
*
;
match
self
{
Holds
(
wc
)
=>
write!
(
fmt
,
"{}"
,
wc
),
WellFormed
(
Implemented
(
trait_ref
))
=>
write!
(
fmt
,
"WellFormed({})"
,
trait_ref
),
WellFormed
(
ProjectionEq
(
projection
))
=>
write!
(
fmt
,
"WellFormed({})"
,
projection
),
FromEnv
(
Implemented
(
trait_ref
))
=>
write!
(
fmt
,
"FromEnv({})"
,
trait_ref
),
FromEnv
(
ProjectionEq
(
projection
))
=>
write!
(
fmt
,
"FromEnv({})"
,
projection
),
WellFormedTy
(
ty
)
=>
write!
(
fmt
,
"WellFormed({})"
,
ty
),
WellFormed
(
wf
)
=>
write!
(
fmt
,
"{}"
,
wf
),
FromEnv
(
from_env
)
=>
write!
(
fmt
,
"{}"
,
from_env
),
Normalize
(
projection
)
=>
write!
(
fmt
,
"Normalize({})"
,
projection
),
FromEnvTy
(
ty
)
=>
write!
(
fmt
,
"FromEnv({})"
,
ty
),
RegionOutlives
(
predicate
)
=>
write!
(
fmt
,
"RegionOutlives({})"
,
predicate
),
TypeOutlives
(
predicate
)
=>
write!
(
fmt
,
"TypeOutlives({})"
,
predicate
),
}
}
}
...
...
@@ -506,30 +523,60 @@ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
}
EnumTypeFoldableImpl!
{
impl
<
'tcx
>
TypeFoldable
<
'tcx
>
for
traits
::
WhereClauseAtom
<
'tcx
>
{
(
traits
::
WhereClauseAtom
::
Implemented
)(
trait_ref
),
(
traits
::
WhereClauseAtom
::
ProjectionEq
)(
projection
),
impl
<
'tcx
>
TypeFoldable
<
'tcx
>
for
traits
::
WhereClause
<
'tcx
>
{
(
traits
::
WhereClause
::
Implemented
)(
trait_ref
),
(
traits
::
WhereClause
::
ProjectionEq
)(
projection
),
(
traits
::
WhereClause
::
TypeOutlives
)(
ty_outlives
),
(
traits
::
WhereClause
::
RegionOutlives
)(
region_outlives
),
}
}
EnumLiftImpl!
{
impl
<
'a
,
'tcx
>
Lift
<
'tcx
>
for
traits
::
WhereClause
<
'a
>
{
type
Lifted
=
traits
::
WhereClause
<
'tcx
>
;
(
traits
::
WhereClause
::
Implemented
)(
trait_ref
),
(
traits
::
WhereClause
::
ProjectionEq
)(
projection
),
(
traits
::
WhereClause
::
TypeOutlives
)(
ty_outlives
),
(
traits
::
WhereClause
::
RegionOutlives
)(
region_outlives
),
}
}
EnumTypeFoldableImpl!
{
impl
<
'tcx
>
TypeFoldable
<
'tcx
>
for
traits
::
WellFormed
<
'tcx
>
{
(
traits
::
WellFormed
::
Trait
)(
trait_ref
),
(
traits
::
WellFormed
::
Ty
)(
ty
),
}
}
EnumLiftImpl!
{
impl
<
'a
,
'tcx
>
Lift
<
'tcx
>
for
traits
::
WellFormed
<
'a
>
{
type
Lifted
=
traits
::
WellFormed
<
'tcx
>
;
(
traits
::
WellFormed
::
Trait
)(
trait_ref
),
(
traits
::
WellFormed
::
Ty
)(
ty
),
}
}
EnumTypeFoldableImpl!
{
impl
<
'tcx
>
TypeFoldable
<
'tcx
>
for
traits
::
FromEnv
<
'tcx
>
{
(
traits
::
FromEnv
::
Trait
)(
trait_ref
),
(
traits
::
FromEnv
::
Ty
)(
ty
),
}
}
EnumLiftImpl!
{
impl
<
'a
,
'tcx
>
Lift
<
'tcx
>
for
traits
::
WhereClauseAtom
<
'a
>
{
type
Lifted
=
traits
::
WhereClauseAtom
<
'tcx
>
;
(
traits
::
WhereClauseAtom
::
Implemented
)(
trait_ref
),
(
traits
::
WhereClauseAtom
::
ProjectionEq
)(
projection
),
impl
<
'a
,
'tcx
>
Lift
<
'tcx
>
for
traits
::
FromEnv
<
'a
>
{
type
Lifted
=
traits
::
FromEnv
<
'tcx
>
;
(
traits
::
FromEnv
::
Trait
)(
trait_ref
),
(
traits
::
FromEnv
::
Ty
)(
ty
),
}
}
EnumTypeFoldableImpl!
{
impl
<
'tcx
>
TypeFoldable
<
'tcx
>
for
traits
::
DomainGoal
<
'tcx
>
{
(
traits
::
DomainGoal
::
Holds
)(
wc
),
(
traits
::
DomainGoal
::
WellFormed
)(
wc
),
(
traits
::
DomainGoal
::
FromEnv
)(
wc
),
(
traits
::
DomainGoal
::
WellFormedTy
)(
ty
),
(
traits
::
DomainGoal
::
WellFormed
)(
wf
),
(
traits
::
DomainGoal
::
FromEnv
)(
from_env
),
(
traits
::
DomainGoal
::
Normalize
)(
projection
),
(
traits
::
DomainGoal
::
FromEnvTy
)(
ty
),
(
traits
::
DomainGoal
::
RegionOutlives
)(
predicate
),
(
traits
::
DomainGoal
::
TypeOutlives
)(
predicate
),
}
}
...
...
@@ -537,13 +584,9 @@ impl<'tcx> TypeFoldable<'tcx> for traits::DomainGoal<'tcx> {
impl
<
'a
,
'tcx
>
Lift
<
'tcx
>
for
traits
::
DomainGoal
<
'a
>
{
type
Lifted
=
traits
::
DomainGoal
<
'tcx
>
;
(
traits
::
DomainGoal
::
Holds
)(
wc
),
(
traits
::
DomainGoal
::
WellFormed
)(
wc
),
(
traits
::
DomainGoal
::
FromEnv
)(
wc
),
(
traits
::
DomainGoal
::
WellFormedTy
)(
ty
),
(
traits
::
DomainGoal
::
WellFormed
)(
wf
),
(
traits
::
DomainGoal
::
FromEnv
)(
from_env
),
(
traits
::
DomainGoal
::
Normalize
)(
projection
),
(
traits
::
DomainGoal
::
FromEnvTy
)(
ty
),
(
traits
::
DomainGoal
::
RegionOutlives
)(
predicate
),
(
traits
::
DomainGoal
::
TypeOutlives
)(
predicate
),
}
}
...
...
src/librustc_traits/chalk_context.rs
浏览文件 @
0347b32a
...
...
@@ -14,7 +14,16 @@
Canonical
,
CanonicalVarValues
,
Canonicalize
,
QueryRegionConstraint
,
QueryResult
,
};
use
rustc
::
infer
::{
InferCtxt
,
InferOk
,
LateBoundRegionConversionTime
};
use
rustc
::
traits
::{
DomainGoal
,
ExClauseFold
,
ExClauseLift
,
Goal
,
ProgramClause
,
QuantifierKind
};
use
rustc
::
traits
::{
WellFormed
,
FromEnv
,
DomainGoal
,
ExClauseFold
,
ExClauseLift
,
Goal
,
ProgramClause
,
QuantifierKind
};
use
rustc
::
ty
::
fold
::{
TypeFoldable
,
TypeFolder
,
TypeVisitor
};
use
rustc
::
ty
::
subst
::
Kind
;
use
rustc
::
ty
::{
self
,
TyCtxt
};
...
...
@@ -314,11 +323,10 @@ fn program_clauses(
_
environment
:
&
ty
::
ParamEnv
<
'tcx
>
,
goal
:
&
DomainGoal
<
'tcx
>
,
)
->
Vec
<
ProgramClause
<
'tcx
>>
{
use
rustc
::
traits
::
DomainGoal
::
*
;
use
rustc
::
traits
::
WhereClauseAtom
::
*
;
use
rustc
::
traits
::
WhereClause
::
*
;
match
goal
{
Holds
(
Implemented
(
_
trait_predicate
))
=>
{
DomainGoal
::
Holds
(
Implemented
(
_
trait_predicate
))
=>
{
// These come from:
//
// - Trait definitions (implied bounds)
...
...
@@ -326,31 +334,31 @@ fn program_clauses(
panic!
()
}
Holds
(
ProjectionEq
(
_
projection_predicate
))
=>
{
DomainGoal
::
Holds
(
ProjectionEq
(
_
projection_predicate
))
=>
{
// These come from:
panic!
()
}
WellFormed
(
Implemented
(
_
trait_predicate
))
=>
{
// These come from -- the trait decl.
DomainGoal
::
Holds
(
RegionOutlives
(
_
region_outlives
))
=>
{
panic!
()
}
WellFormed
(
ProjectionEq
(
_
projection_predicate
))
=>
panic!
(),
FromEnv
(
Implemented
(
_
trait_predicate
))
=>
panic!
(),
FromEnv
(
ProjectionEq
(
_
projection_predicate
))
=>
panic!
(),
DomainGoal
::
Holds
(
TypeOutlives
(
_
type_outlives
))
=>
{
panic!
()
}
WellFormedTy
(
_
ty
)
=>
panic!
(),
DomainGoal
::
WellFormed
(
WellFormed
::
Trait
(
_
trait_predicate
))
=>
{
// These come from -- the trait decl.
panic!
()
}
FromEnvTy
(
_
ty
)
=>
panic!
(),
DomainGoal
::
WellFormed
(
WellFormed
::
Ty
(
_
ty
)
)
=>
panic!
(),
RegionOutlives
(
_
region_outlives
)
=>
panic!
(),
DomainGoal
::
FromEnv
(
FromEnv
::
Trait
(
_
trait_predicate
)
)
=>
panic!
(),
TypeOutlives
(
_
type_outlives
)
=>
panic!
(),
DomainGoal
::
FromEnv
(
FromEnv
::
Ty
(
_
ty
)
)
=>
panic!
(),
Normalize
(
_
)
=>
panic!
(),
DomainGoal
::
Normalize
(
_
)
=>
panic!
(),
}
}
...
...
src/librustc_traits/lowering.rs
浏览文件 @
0347b32a
...
...
@@ -13,7 +13,7 @@
use
rustc
::
hir
::
map
::
definitions
::
DefPathData
;
use
rustc
::
hir
::{
self
,
ImplPolarity
};
use
rustc
::
traits
::{
Clause
,
Clauses
,
DomainGoal
,
Goal
,
PolyDomainGoal
,
ProgramClause
,
WhereClause
Atom
};
WhereClause
,
FromEnv
,
WellFormed
};
use
rustc
::
ty
::
subst
::
Substs
;
use
rustc
::
ty
::{
self
,
Slice
,
TyCtxt
};
use
rustc_data_structures
::
fx
::
FxHashSet
;
...
...
@@ -23,7 +23,7 @@
use
std
::
iter
;
crate
trait
Lower
<
T
>
{
/// Lower a rustc construct
ion
(e.g. `ty::TraitPredicate`) to a chalk-like type.
/// Lower a rustc construct (e.g. `ty::TraitPredicate`) to a chalk-like type.
fn
lower
(
&
self
)
->
T
;
}
...
...
@@ -36,36 +36,36 @@ fn lower(&self) -> Vec<U> {
}
}
impl
<
'tcx
>
Lower
<
WhereClause
Atom
<
'tcx
>>
for
ty
::
TraitPredicate
<
'tcx
>
{
fn
lower
(
&
self
)
->
WhereClause
Atom
<
'tcx
>
{
WhereClause
Atom
::
Implemented
(
*
self
)
impl
<
'tcx
>
Lower
<
WhereClause
<
'tcx
>>
for
ty
::
TraitPredicate
<
'tcx
>
{
fn
lower
(
&
self
)
->
WhereClause
<
'tcx
>
{
WhereClause
::
Implemented
(
*
self
)
}
}
impl
<
'tcx
>
Lower
<
WhereClause
Atom
<
'tcx
>>
for
ty
::
ProjectionPredicate
<
'tcx
>
{
fn
lower
(
&
self
)
->
WhereClause
Atom
<
'tcx
>
{
WhereClause
Atom
::
ProjectionEq
(
*
self
)
impl
<
'tcx
>
Lower
<
WhereClause
<
'tcx
>>
for
ty
::
ProjectionPredicate
<
'tcx
>
{
fn
lower
(
&
self
)
->
WhereClause
<
'tcx
>
{
WhereClause
::
ProjectionEq
(
*
self
)
}
}
impl
<
'tcx
,
T
>
Lower
<
DomainGoal
<
'tcx
>>
for
T
where
T
:
Lower
<
WhereClauseAtom
<
'tcx
>>
,
{
fn
lower
(
&
self
)
->
DomainGoal
<
'tcx
>
{
DomainGoal
::
Holds
(
self
.lower
())
impl
<
'tcx
>
Lower
<
WhereClause
<
'tcx
>>
for
ty
::
RegionOutlivesPredicate
<
'tcx
>
{
fn
lower
(
&
self
)
->
WhereClause
<
'tcx
>
{
WhereClause
::
RegionOutlives
(
*
self
)
}
}
impl
<
'tcx
>
Lower
<
DomainGoal
<
'tcx
>>
for
ty
::
Region
OutlivesPredicate
<
'tcx
>
{
fn
lower
(
&
self
)
->
DomainGoal
<
'tcx
>
{
DomainGoal
::
Region
Outlives
(
*
self
)
impl
<
'tcx
>
Lower
<
WhereClause
<
'tcx
>>
for
ty
::
Type
OutlivesPredicate
<
'tcx
>
{
fn
lower
(
&
self
)
->
WhereClause
<
'tcx
>
{
WhereClause
::
Type
Outlives
(
*
self
)
}
}
impl
<
'tcx
>
Lower
<
DomainGoal
<
'tcx
>>
for
ty
::
TypeOutlivesPredicate
<
'tcx
>
{
impl
<
'tcx
,
T
>
Lower
<
DomainGoal
<
'tcx
>>
for
T
where
T
:
Lower
<
WhereClause
<
'tcx
>>
,
{
fn
lower
(
&
self
)
->
DomainGoal
<
'tcx
>
{
DomainGoal
::
TypeOutlives
(
*
self
)
DomainGoal
::
Holds
(
self
.lower
()
)
}
}
...
...
@@ -86,15 +86,20 @@ fn lower(&self) -> PolyDomainGoal<'tcx> {
impl
<
'tcx
>
Lower
<
PolyDomainGoal
<
'tcx
>>
for
ty
::
Predicate
<
'tcx
>
{
fn
lower
(
&
self
)
->
PolyDomainGoal
<
'tcx
>
{
use
rustc
::
ty
::
Predicate
::
*
;
use
rustc
::
ty
::
Predicate
;
match
self
{
Trait
(
predicate
)
=>
predicate
.lower
(),
RegionOutlives
(
predicate
)
=>
predicate
.lower
(),
TypeOutlives
(
predicate
)
=>
predicate
.lower
(),
Projection
(
predicate
)
=>
predicate
.lower
(),
WellFormed
(
ty
)
=>
ty
::
Binder
::
dummy
(
DomainGoal
::
WellFormedTy
(
*
ty
)),
ObjectSafe
(
..
)
|
ClosureKind
(
..
)
|
Subtype
(
..
)
|
ConstEvaluatable
(
..
)
=>
{
Predicate
::
Trait
(
predicate
)
=>
predicate
.lower
(),
Predicate
::
RegionOutlives
(
predicate
)
=>
predicate
.lower
(),
Predicate
::
TypeOutlives
(
predicate
)
=>
predicate
.lower
(),
Predicate
::
Projection
(
predicate
)
=>
predicate
.lower
(),
Predicate
::
WellFormed
(
ty
)
=>
ty
::
Binder
::
dummy
(
DomainGoal
::
WellFormed
(
WellFormed
::
Ty
(
*
ty
))
),
Predicate
::
ObjectSafe
(
..
)
|
Predicate
::
ClosureKind
(
..
)
|
Predicate
::
Subtype
(
..
)
|
Predicate
::
ConstEvaluatable
(
..
)
=>
{
unimplemented!
()
}
}
...
...
@@ -110,11 +115,13 @@ trait IntoFromEnvGoal {
impl
<
'tcx
>
IntoFromEnvGoal
for
DomainGoal
<
'tcx
>
{
fn
into_from_env_goal
(
self
)
->
DomainGoal
<
'tcx
>
{
use
self
::
DomainGoal
::
*
;
use
self
::
WhereClause
::
*
;
match
self
{
Holds
(
wc_atom
)
=>
FromEnv
(
wc_atom
),
WellFormed
(
..
)
|
FromEnv
(
..
)
|
WellFormedTy
(
..
)
|
FromEnvTy
(
..
)
|
Normalize
(
..
)
|
RegionOutlives
(
..
)
|
TypeOutlives
(
..
)
=>
self
,
DomainGoal
::
Holds
(
Implemented
(
trait_ref
))
=>
DomainGoal
::
FromEnv
(
FromEnv
::
Trait
(
trait_ref
)
),
other
=>
other
,
}
}
}
...
...
@@ -212,16 +219,20 @@ fn program_clauses_for_trait<'a, 'tcx>(
substs
:
Substs
::
identity_for_item
(
tcx
,
def_id
),
},
};
// `FromEnv(Self: Trait<P1..Pn>)`
let
from_env
=
Goal
::
from
(
DomainGoal
::
FromEnv
(
trait_pred
.lower
()));
// `Implemented(Self: Trait<P1..Pn>)`
let
impl_trait
=
DomainGoal
::
Holds
(
WhereClauseAtom
::
Implemented
(
trait_pred
));
let
impl_trait
:
DomainGoal
=
trait_pred
.lower
();
// `FromEnv(Self: Trait<P1..Pn>)`
let
from_env
=
impl_trait
.into_from_env_goal
()
.into_goal
();
// `Implemented(Self: Trait<P1..Pn>) :- FromEnv(Self: Trait<P1..Pn>)`
let
hypotheses
=
tcx
.intern_goals
(
&
[
from_env
]);
let
implemented_from_env
=
ProgramClause
{
goal
:
impl_trait
,
hypotheses
:
tcx
.intern_goals
(
&
[
from_env
])
,
hypotheses
,
};
let
clauses
=
iter
::
once
(
Clause
::
ForAll
(
ty
::
Binder
::
dummy
(
implemented_from_env
)));
// Rule Implied-Bound-From-Trait
...
...
@@ -239,25 +250,17 @@ fn program_clauses_for_trait<'a, 'tcx>(
let
where_clauses
=
&
tcx
.predicates_of
(
def_id
)
.predicates
;
let
implied_bound_clauses
=
where_clauses
[
1
..
]
.into_iter
()
.map
(|
wc
|
implied_bound_from_trait
(
tcx
,
trait_pred
,
wc
));
.map
(|
wc
|
wc
.lower
())
tcx
.mk_clauses
(
clauses
.chain
(
implied_bound_clauses
))
}
// `FromEnv(WC) :- FromEnv(Self: Trait<P1..Pn>)`
.map
(|
wc
|
wc
.map_bound
(|
goal
|
ProgramClause
{
goal
:
goal
.into_from_env_goal
(),
hypotheses
,
}))
/// For a given `where_clause`, returns a clause `FromEnv(WC) :- FromEnv(Self: Trait<P1..Pn>)`.
fn
implied_bound_from_trait
<
'a
,
'tcx
>
(
tcx
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
,
trait_pred
:
ty
::
TraitPredicate
<
'tcx
>
,
where_clause
:
&
ty
::
Predicate
<
'tcx
>
,
)
->
Clause
<
'tcx
>
{
// `FromEnv(Self: Trait<P1..Pn>)`
let
impl_trait
=
DomainGoal
::
FromEnv
(
WhereClauseAtom
::
Implemented
(
trait_pred
));
// `FromEnv(WC) :- FromEnv(Self: Trait<P1..Pn>)`
Clause
::
ForAll
(
where_clause
.lower
()
.map_bound
(|
goal
|
ProgramClause
{
goal
:
goal
.into_from_env_goal
(),
hypotheses
:
tcx
.intern_goals
(
&
[
Goal
::
from
(
impl_trait
)]),
}))
.map
(
Clause
::
ForAll
);
tcx
.mk_clauses
(
clauses
.chain
(
implied_bound_clauses
))
}
fn
program_clauses_for_impl
<
'a
,
'tcx
>
(
tcx
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
,
def_id
:
DefId
)
->
Clauses
<
'tcx
>
{
...
...
@@ -275,9 +278,11 @@ fn program_clauses_for_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId
// }
// ```
let
trait_ref
=
tcx
.impl_trait_ref
(
def_id
)
.unwrap
();
let
trait_ref
=
tcx
.impl_trait_ref
(
def_id
)
.expect
(
"not an impl"
);
// `Implemented(A0: Trait<A1..An>)`
let
trait_pred
=
ty
::
TraitPredicate
{
trait_ref
}
.lower
();
// `WC`
let
where_clauses
=
tcx
.predicates_of
(
def_id
)
.predicates
.lower
();
...
...
@@ -301,45 +306,48 @@ pub fn program_clauses_for_associated_type_value<'a, 'tcx>(
//
// ```impl<P0..Pn> Trait<A1..An> for A0
// {
// type AssocType<Pn+1..Pm>
where WC
= T;
// type AssocType<Pn+1..Pm> = T;
// }```
//
// ```
// forall<P0..Pm> {
// forall<Pn+1..Pm> {
// Normalize(<A0 as Trait<A1..An>>::AssocType<Pn+1..Pm> -> T) :-
// Implemented(A0: Trait<A1..An>)
&& WC
// Implemented(A0: Trait<A1..An>)
// }
// }
// ```
let
item
=
tcx
.associated_item
(
item_id
);
debug_assert_eq!
(
item
.kind
,
ty
::
AssociatedKind
::
Type
);
let
impl_id
=
if
let
ty
::
AssociatedItemContainer
::
ImplContainer
(
impl_id
)
=
item
.container
{
impl_id
}
else
{
bug!
()
let
impl_id
=
match
item
.container
{
ty
::
AssociatedItemContainer
::
ImplContainer
(
impl_id
)
=>
impl_id
,
_
=>
bug!
(
"not an impl container"
),
};
// `A0 as Trait<A1..An>`
let
trait_ref
=
tcx
.impl_trait_ref
(
impl_id
)
.unwrap
();
// `T`
let
ty
=
tcx
.type_of
(
item_id
);
// `Implemented(A0: Trait<A1..An>)`
let
trait_implemented
=
ty
::
Binder
::
dummy
(
ty
::
TraitPredicate
{
trait_ref
}
.lower
());
// `WC`
let
item_where_clauses
=
tcx
.predicates_of
(
item_id
)
.predicates
.lower
();
// `Implemented(A0: Trait<A1..An>) && WC`
let
mut
where_clauses
=
vec!
[
trait_implemented
];
where_clauses
.extend
(
item_where_clauses
);
// `Implemented(A0: Trait<A1..An>)`
let
hypotheses
=
vec!
[
trait_implemented
];
// `<A0 as Trait<A1..An>>::AssocType<Pn+1..Pm>`
let
projection_ty
=
ty
::
ProjectionTy
::
from_ref_and_name
(
tcx
,
trait_ref
,
item
.name
);
// `Normalize(<A0 as Trait<A1..An>>::AssocType<Pn+1..Pm> -> T)`
let
normalize_goal
=
DomainGoal
::
Normalize
(
ty
::
ProjectionPredicate
{
projection_ty
,
ty
});
// `Normalize(... -> T) :- ...`
let
clause
=
ProgramClause
{
goal
:
normalize_goal
,
hypotheses
:
tcx
.mk_goals
(
where_clau
ses
hypothe
ses
.into_iter
()
.map
(|
wc
|
Goal
::
from_poly_domain_goal
(
wc
,
tcx
)),
),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录