Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
f7f62452
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,发现更多精彩内容 >>
提交
f7f62452
编写于
4月 28, 2020
作者:
M
Markus Westerlind
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: Replace probe_fudge by an explict call for the lengths
上级
4a2a6bcf
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
23 addition
and
59 deletion
+23
-59
src/librustc_infer/infer/fudge.rs
src/librustc_infer/infer/fudge.rs
+18
-36
src/librustc_infer/infer/region_constraints/mod.rs
src/librustc_infer/infer/region_constraints/mod.rs
+3
-7
src/librustc_infer/infer/type_variable.rs
src/librustc_infer/infer/type_variable.rs
+2
-16
未找到文件。
src/librustc_infer/infer/fudge.rs
浏览文件 @
f7f62452
use
rustc_middle
::
ty
::
fold
::{
TypeFoldable
,
TypeFolder
};
use
rustc_middle
::
ty
::{
self
,
ConstVid
,
FloatVid
,
IntVid
,
RegionVid
,
Ty
,
TyCtxt
,
TyVid
};
use
super
::
region_constraints
::
RegionSnapshot
;
use
super
::
type_variable
::{
self
,
TypeVariableOrigin
};
use
super
::
type_variable
::
TypeVariableOrigin
;
use
super
::
InferCtxt
;
use
super
::{
Co
mbinedSnapshot
,
Co
nstVariableOrigin
,
RegionVariableOrigin
,
UnificationTable
};
use
super
::{
ConstVariableOrigin
,
RegionVariableOrigin
,
UnificationTable
};
use
rustc_data_structures
::
snapshot_vec
as
sv
;
use
rustc_data_structures
::
unify
as
ut
;
...
...
@@ -14,13 +13,13 @@
fn
vars_since_snapshot
<
'tcx
,
T
>
(
table
:
&
mut
UnificationTable
<
'_
,
'tcx
,
T
>
,
snapshot
:
usize
,
snapshot
_var_len
:
usize
,
)
->
Range
<
T
>
where
T
:
UnifyKey
,
super
::
UndoLog
<
'tcx
>
:
From
<
sv
::
UndoLog
<
ut
::
Delegate
<
T
>>>
,
{
T
::
from_index
(
snapshot
as
u32
)
..
T
::
from_index
(
table
.len
()
as
u32
)
T
::
from_index
(
snapshot
_var_len
as
u32
)
..
T
::
from_index
(
table
.len
()
as
u32
)
}
fn
const_vars_since_snapshot
<
'tcx
>
(
...
...
@@ -36,41 +35,23 @@ fn const_vars_since_snapshot<'tcx>(
)
}
/// Extends `CombinedSnapshot` by tracking which variables were added in the snapshot
#[must_use
=
"once you start a snapshot, you should always consume it"
]
struct
FudgeSnapshot
<
'a
,
'tcx
>
{
snapshot
:
CombinedSnapshot
<
'a
,
'tcx
>
,
region_constraints_snapshot
:
RegionSnapshot
,
type_snapshot
:
type_variable
::
Snapshot
<
'tcx
>
,
struct
VariableLengths
{
type_var_len
:
usize
,
const_var_len
:
usize
,
int_var_len
:
usize
,
float_var_len
:
usize
,
region_constraints_len
:
usize
,
}
impl
<
'a
,
'tcx
>
InferCtxt
<
'a
,
'tcx
>
{
/// Like `probe` but provides information about which variables were created in the snapshot,
/// allowing for inference fudging
fn
probe_fudge
<
R
,
F
>
(
&
self
,
f
:
F
)
->
R
where
F
:
FnOnce
(
&
FudgeSnapshot
<
'a
,
'tcx
>
)
->
R
,
{
debug!
(
"probe()"
);
let
snapshot
=
self
.start_fudge_snapshot
();
let
r
=
f
(
&
snapshot
);
self
.rollback_to
(
"probe"
,
snapshot
.snapshot
);
r
}
fn
start_fudge_snapshot
(
&
self
)
->
FudgeSnapshot
<
'a
,
'tcx
>
{
let
snapshot
=
self
.start_snapshot
();
fn
variable_lengths
(
&
self
)
->
VariableLengths
{
let
mut
inner
=
self
.inner
.borrow_mut
();
FudgeSnapshot
{
snapshot
,
type_snapshot
:
inner
.type_variables
()
.snapshot
(),
VariableLengths
{
type_var_len
:
inner
.type_variables
()
.num_vars
(),
const_var_len
:
inner
.const_unification_table
()
.len
(),
int_var_len
:
inner
.int_unification_table
()
.len
(),
float_var_len
:
inner
.float_unification_table
()
.len
(),
region_constraints_
snapshot
:
inner
.unwrap_region_constraints
()
.start_snapshot
(),
region_constraints_
len
:
inner
.unwrap_region_constraints
()
.num_region_vars
(),
}
}
...
...
@@ -120,7 +101,8 @@ pub fn fudge_inference_if_ok<T, E, F>(&self, f: F) -> Result<T, E>
{
debug!
(
"fudge_inference_if_ok()"
);
let
(
mut
fudger
,
value
)
=
self
.probe_fudge
(|
snapshot
|
{
let
variable_lengths
=
self
.variable_lengths
();
let
(
mut
fudger
,
value
)
=
self
.probe
(|
_
|
{
match
f
()
{
Ok
(
value
)
=>
{
let
value
=
self
.resolve_vars_if_possible
(
&
value
);
...
...
@@ -133,21 +115,21 @@ pub fn fudge_inference_if_ok<T, E, F>(&self, f: F) -> Result<T, E>
let
mut
inner
=
self
.inner
.borrow_mut
();
let
type_vars
=
inner
.type_variables
()
.vars_since_snapshot
(
&
snapshot
.type_snapshot
);
inner
.type_variables
()
.vars_since_snapshot
(
variable_lengths
.type_var_len
);
let
int_vars
=
vars_since_snapshot
(
&
mut
inner
.int_unification_table
(),
snapshot
.int_var_len
,
variable_lengths
.int_var_len
,
);
let
float_vars
=
vars_since_snapshot
(
&
mut
inner
.float_unification_table
(),
snapshot
.float_var_len
,
variable_lengths
.float_var_len
,
);
let
region_vars
=
inner
.unwrap_region_constraints
()
.vars_since_snapshot
(
&
snapshot
.region_constraints_snapshot
);
.vars_since_snapshot
(
variable_lengths
.region_constraints_len
);
let
const_vars
=
const_vars_since_snapshot
(
&
mut
inner
.const_unification_table
(),
snapshot
.const_var_len
,
variable_lengths
.const_var_len
,
);
let
fudger
=
InferenceFudger
{
...
...
src/librustc_infer/infer/region_constraints/mod.rs
浏览文件 @
f7f62452
...
...
@@ -312,7 +312,6 @@ pub struct RegionVariableInfo {
}
pub
struct
RegionSnapshot
{
value_count
:
usize
,
any_unifications
:
bool
,
}
...
...
@@ -454,10 +453,7 @@ pub fn data(&self) -> &RegionConstraintData<'tcx> {
pub
fn
start_snapshot
(
&
mut
self
)
->
RegionSnapshot
{
debug!
(
"RegionConstraintCollector: start_snapshot"
);
RegionSnapshot
{
value_count
:
self
.unification_table
.len
(),
any_unifications
:
self
.any_unifications
,
}
RegionSnapshot
{
any_unifications
:
self
.any_unifications
}
}
pub
fn
rollback_to
(
&
mut
self
,
snapshot
:
RegionSnapshot
)
{
...
...
@@ -776,9 +772,9 @@ pub fn universe(&self, region: Region<'tcx>) -> ty::UniverseIndex {
pub
fn
vars_since_snapshot
(
&
self
,
mark
:
&
RegionSnapshot
,
value_count
:
usize
,
)
->
(
Range
<
RegionVid
>
,
Vec
<
RegionVariableOrigin
>
)
{
let
range
=
RegionVid
::
from_index
(
mark
.
value_count
as
u32
)
let
range
=
RegionVid
::
from_index
(
value_count
as
u32
)
..
RegionVid
::
from_index
(
self
.unification_table
.len
()
as
u32
);
(
range
.clone
(),
...
...
src/librustc_infer/infer/type_variable.rs
浏览文件 @
f7f62452
...
...
@@ -150,11 +150,6 @@ pub fn is_unknown(&self) -> bool {
}
}
pub
struct
Snapshot
<
'tcx
>
{
value_count
:
u32
,
_
marker
:
PhantomData
<&
'tcx
()
>
,
}
pub
(
crate
)
struct
Instantiate
{
vid
:
ty
::
TyVid
,
}
...
...
@@ -324,14 +319,6 @@ pub fn replace_if_possible(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
}
}
/// Creates a snapshot of the type variable state. This snapshot
/// must later be committed (`commit()`) or rolled back
/// (`rollback_to()`). Nested snapshots are permitted, but must
/// be processed in a stack-like fashion.
pub
fn
snapshot
(
&
mut
self
)
->
Snapshot
<
'tcx
>
{
Snapshot
{
value_count
:
self
.eq_relations
()
.len
()
as
u32
,
_
marker
:
PhantomData
}
}
fn
values
(
&
mut
self
,
)
->
sv
::
SnapshotVec
<
Delegate
,
&
mut
Vec
<
TypeVariableData
>
,
&
mut
InferCtxtUndoLogs
<
'tcx
>>
{
...
...
@@ -349,10 +336,9 @@ fn sub_relations(&mut self) -> super::UnificationTable<'_, 'tcx, ty::TyVid> {
/// Returns a range of the type variables created during the snapshot.
pub
fn
vars_since_snapshot
(
&
mut
self
,
s
:
&
Snapshot
<
'tcx
>
,
value_count
:
usize
,
)
->
(
Range
<
TyVid
>
,
Vec
<
TypeVariableOrigin
>
)
{
let
range
=
TyVid
{
index
:
s
.value_count
}
..
TyVid
{
index
:
self
.eq_relations
()
.len
()
as
u32
};
let
range
=
TyVid
{
index
:
value_count
as
u32
}
..
TyVid
{
index
:
self
.num_vars
()
as
u32
};
(
range
.start
..
range
.end
,
(
range
.start.index
..
range
.end.index
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录