Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
4ffcb959
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,发现更多精彩内容 >>
提交
4ffcb959
编写于
3月 09, 2012
作者:
P
Patrick Walton
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rustc: Perform region inference
上级
7f55e7d0
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
154 addition
and
2 deletion
+154
-2
src/rustc/driver/driver.rs
src/rustc/driver/driver.rs
+4
-1
src/rustc/middle/region.rs
src/rustc/middle/region.rs
+145
-0
src/rustc/middle/ty.rs
src/rustc/middle/ty.rs
+4
-1
src/rustc/rustc.rc
src/rustc/rustc.rc
+1
-0
未找到文件。
src/rustc/driver/driver.rs
浏览文件 @
4ffcb959
...
...
@@ -140,7 +140,10 @@ fn compile_upto(sess: session, cfg: ast::crate_cfg,
let
freevars
=
time
(
time_passes
,
"freevar finding"
,
bind
freevars
::
annotate_freevars
(
def_map
,
crate
));
let
ty_cx
=
ty
::
mk_ctxt
(
sess
,
def_map
,
ast_map
,
freevars
);
let
region_map
=
time
(
time_passes
,
"region resolution"
,
bind
middle
::
region
::
resolve_crate
(
sess
,
crate
));
let
ty_cx
=
ty
::
mk_ctxt
(
sess
,
def_map
,
ast_map
,
freevars
,
region_map
);
let
(
method_map
,
dict_map
)
=
time
(
time_passes
,
"typechecking"
,
bind
typeck
::
check_crate
(
ty_cx
,
impl_map
,
crate
));
...
...
src/rustc/middle/region.rs
0 → 100644
浏览文件 @
4ffcb959
/*
* Region resolution. This pass runs before typechecking and resolves region
* names to the appropriate block.
*/
import
driver
::
session
::
session
;
import
middle
::
ty
;
import
syntax
::{
ast
,
visit
};
import
std
::
map
;
import
std
::
map
::
hashmap
;
type
region_map
=
{
parent_blocks
:
hashmap
<
ast
::
node_id
,
ast
::
node_id
>
,
ast_type_to_region
:
hashmap
<
ast
::
node_id
,
ty
::
region
>
};
enum
parent
{
pa_item
(
ast
::
node_id
),
pa_block
(
ast
::
node_id
),
pa_crate
}
type
ctxt
=
{
sess
:
session
,
region_map
:
@
region_map
,
names_in_scope
:
hashmap
<
str
,
ast
::
def_id
>
,
parent
:
parent
};
fn
resolve_ty
(
ty
:
@
ast
::
ty
,
cx
:
ctxt
,
visitor
:
visit
::
vt
<
ctxt
>
)
{
alt
ty
.node
{
ast
::
ty_rptr
({
id
:
region_id
,
node
:
node
},
_
)
{
let
region
;
alt
node
{
ast
::
re_inferred
{
// We infer to the caller region if we're at item scope
// and to the block region if we're at block scope.
alt
cx
.parent
{
pa_item
(
item_id
)
{
let
def_id
=
{
crate
:
ast
::
local_crate
,
node
:
item_id
};
region
=
ty
::
re_caller
(
def_id
);
}
pa_block
(
block_id
)
{
region
=
ty
::
re_block
(
block_id
);
}
pa_crate
{
cx
.sess
.span_bug
(
ty
.span
,
"region type outside item"
);
}
}
}
ast
::
re_named
(
ident
)
{
// If at item scope, introduce or reuse a binding. If at
// block scope, require that the binding be introduced.
alt
cx
.names_in_scope
.find
(
ident
)
{
some
(
def_id
)
{
region
=
ty
::
re_named
(
def_id
);
}
none
{
alt
cx
.parent
{
pa_item
(
_
)
{
/* ok; fall through */
}
pa_block
(
_
)
{
cx
.sess
.span_err
(
ty
.span
,
"unknown region `"
+
ident
+
"`"
);
}
pa_crate
{
cx
.sess
.span_bug
(
ty
.span
,
"named region at "
+
"crate scope?!"
);
}
}
let
def_id
=
{
crate
:
ast
::
local_crate
,
node
:
region_id
};
cx
.names_in_scope
.insert
(
ident
,
def_id
);
region
=
ty
::
re_named
(
def_id
);
}
}
}
ast
::
re_self
{
// For blocks, "self" means "the current block".
alt
cx
.parent
{
pa_item
(
_
)
{
cx
.sess
.span_unimpl
(
ty
.span
,
"'self' region for items"
);
}
pa_block
(
block_id
)
{
region
=
ty
::
re_block
(
block_id
);
}
pa_crate
{
cx
.sess
.span_bug
(
ty
.span
,
"region type outside item"
);
}
}
}
}
cx
.region_map.ast_type_to_region
.insert
(
region_id
,
region
);
}
_
{
/* nothing to do */
}
}
visit
::
visit_ty
(
ty
,
cx
,
visitor
);
}
fn
resolve_block
(
blk
:
ast
::
blk
,
cx
:
ctxt
,
visitor
:
visit
::
vt
<
ctxt
>
)
{
alt
cx
.parent
{
pa_item
(
_
)
{
/* no-op */
}
pa_block
(
parent_block_id
)
{
cx
.region_map.parent_blocks
.insert
(
blk
.node.id
,
parent_block_id
);
}
pa_crate
{
cx
.sess
.span_bug
(
blk
.span
,
"block outside item?!"
);
}
}
let
new_cx
:
ctxt
=
{
parent
:
pa_block
(
blk
.node.id
)
with
cx
};
visit
::
visit_block
(
blk
,
new_cx
,
visitor
);
}
fn
resolve_item
(
item
:
@
ast
::
item
,
cx
:
ctxt
,
visitor
:
visit
::
vt
<
ctxt
>
)
{
// Items create a new outer block scope as far as we're concerned.
let
new_cx
:
ctxt
=
{
names_in_scope
:
map
::
new_str_hash
(),
parent
:
pa_item
(
item
.id
)
with
cx
};
visit
::
visit_item
(
item
,
new_cx
,
visitor
);
}
fn
resolve_crate
(
sess
:
session
,
crate
:
@
ast
::
crate
)
->
@
region_map
{
let
cx
:
ctxt
=
{
sess
:
sess
,
region_map
:
@
{
parent_blocks
:
map
::
new_int_hash
(),
ast_type_to_region
:
map
::
new_int_hash
()},
names_in_scope
:
map
::
new_str_hash
(),
parent
:
pa_crate
};
let
visitor
=
visit
::
mk_vt
(
@
{
visit_block
:
resolve_block
,
visit_item
:
resolve_item
,
visit_ty
:
resolve_ty
with
*
visit
::
default_visitor
()
});
visit
::
visit_crate
(
*
crate
,
cx
,
visitor
);
ret
cx
.region_map
;
}
src/rustc/middle/ty.rs
浏览文件 @
4ffcb959
...
...
@@ -167,6 +167,7 @@
mutable
next_id
:
uint
,
sess
:
session
::
session
,
def_map
:
resolve
::
def_map
,
region_map
:
@
middle
::
region
::
region_map
,
node_types
:
node_type_table
,
node_type_substs
:
hashmap
<
node_id
,
[
t
]
>
,
items
:
ast_map
::
map
,
...
...
@@ -327,7 +328,8 @@ fn new_ty_hash<V: copy>() -> map::hashmap<t, V> {
}
fn
mk_ctxt
(
s
:
session
::
session
,
dm
:
resolve
::
def_map
,
amap
:
ast_map
::
map
,
freevars
:
freevars
::
freevar_map
)
->
ctxt
{
freevars
:
freevars
::
freevar_map
,
region_map
:
@
middle
::
region
::
region_map
)
->
ctxt
{
let
interner
=
map
::
mk_hashmap
({|
&&
k
:
intern_key
|
hash_type_structure
(
k
.struct
)
+
option
::
maybe
(
0u
,
k
.o_def_id
,
ast_util
::
hash_def_id
)
...
...
@@ -336,6 +338,7 @@ fn mk_ctxt(s: session::session, dm: resolve::def_map, amap: ast_map::map,
mutable
next_id
:
0u
,
sess
:
s
,
def_map
:
dm
,
region_map
:
region_map
,
node_types
:
@
smallintmap
::
mk
(),
node_type_substs
:
map
::
new_int_hash
(),
items
:
amap
,
...
...
src/rustc/rustc.rc
浏览文件 @
4ffcb959
...
...
@@ -44,6 +44,7 @@ mod middle {
mod
freevars
;
mod
capture
;
mod
pat_util
;
mod
region
;
mod
tstate
{
mod
ck
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录