Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
37154ca9
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,发现更多精彩内容 >>
提交
37154ca9
编写于
8月 17, 2016
作者:
J
Jeffrey Seyfried
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor `unresolved_imports` -> `indeterminate_imports`.
上级
c64cd86b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
47 addition
and
77 deletion
+47
-77
src/librustc_resolve/build_reduced_graph.rs
src/librustc_resolve/build_reduced_graph.rs
+0
-3
src/librustc_resolve/lib.rs
src/librustc_resolve/lib.rs
+3
-5
src/librustc_resolve/resolve_imports.rs
src/librustc_resolve/resolve_imports.rs
+44
-69
未找到文件。
src/librustc_resolve/build_reduced_graph.rs
浏览文件 @
37154ca9
...
...
@@ -131,7 +131,6 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, parent_ref: &mut Module<
let
subclass
=
ImportDirectiveSubclass
::
single
(
binding
.name
,
source_name
);
let
span
=
view_path
.span
;
self
.add_import_directive
(
module_path
,
subclass
,
span
,
item
.id
,
vis
);
self
.unresolved_imports
+=
1
;
}
ViewPathList
(
_
,
ref
source_items
)
=>
{
// Make sure there's at most one `mod` import in the list.
...
...
@@ -177,14 +176,12 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, parent_ref: &mut Module<
let
subclass
=
ImportDirectiveSubclass
::
single
(
rename
,
name
);
let
(
span
,
id
)
=
(
source_item
.span
,
source_item
.node
.id
());
self
.add_import_directive
(
module_path
,
subclass
,
span
,
id
,
vis
);
self
.unresolved_imports
+=
1
;
}
}
ViewPathGlob
(
_
)
=>
{
let
subclass
=
GlobImport
{
is_prelude
:
is_prelude
};
let
span
=
view_path
.span
;
self
.add_import_directive
(
module_path
,
subclass
,
span
,
item
.id
,
vis
);
self
.unresolved_imports
+=
1
;
}
}
}
...
...
src/librustc_resolve/lib.rs
浏览文件 @
37154ca9
...
...
@@ -752,7 +752,6 @@ pub struct ModuleS<'a> {
extern_crate_id
:
Option
<
NodeId
>
,
resolutions
:
RefCell
<
HashMap
<
(
Name
,
Namespace
),
&
'a
RefCell
<
NameResolution
<
'a
>>>>
,
unresolved_imports
:
RefCell
<
Vec
<&
'a
ImportDirective
<
'a
>>>
,
no_implicit_prelude
:
Cell
<
bool
>
,
...
...
@@ -782,7 +781,6 @@ fn new(parent_link: ParentLink<'a>,
def
:
def
,
extern_crate_id
:
None
,
resolutions
:
RefCell
::
new
(
HashMap
::
new
()),
unresolved_imports
:
RefCell
::
new
(
Vec
::
new
()),
no_implicit_prelude
:
Cell
::
new
(
false
),
glob_importers
:
RefCell
::
new
(
Vec
::
new
()),
globs
:
RefCell
::
new
((
Vec
::
new
())),
...
...
@@ -965,8 +963,8 @@ pub struct Resolver<'a> {
structs
:
FnvHashMap
<
DefId
,
Vec
<
Name
>>
,
//
The number of imports that are currently unresolved
.
unresolved_imports
:
usize
,
//
All indeterminate imports (i.e. imports not known to succeed or fail)
.
indeterminate_imports
:
Vec
<&
'a
ImportDirective
<
'a
>>
,
// The module that represents the current item scope.
current_module
:
Module
<
'a
>
,
...
...
@@ -1153,7 +1151,7 @@ pub fn new(session: &'a Session, make_glob_map: MakeGlobMap, arenas: &'a Resolve
trait_item_map
:
FnvHashMap
(),
structs
:
FnvHashMap
(),
unresolved_imports
:
0
,
indeterminate_imports
:
Vec
::
new
()
,
current_module
:
graph_root
,
value_ribs
:
vec!
[
Rib
::
new
(
ModuleRibKind
(
graph_root
))],
...
...
src/librustc_resolve/resolve_imports.rs
浏览文件 @
37154ca9
...
...
@@ -233,7 +233,7 @@ pub fn add_import_directive(&mut self,
vis
:
vis
,
});
self
.
current_module.unresolved_imports
.borrow_mut
()
.push
(
directive
);
self
.
indeterminate_imports
.push
(
directive
);
match
directive
.subclass
{
SingleImport
{
target
,
..
}
=>
{
for
&
ns
in
&
[
ValueNS
,
TypeNS
]
{
...
...
@@ -360,43 +360,52 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
/// point iteration.
fn
resolve_imports
(
&
mut
self
)
{
let
mut
i
=
0
;
let
mut
prev_
unresolved_imports
=
0
;
let
mut
prev_
num_indeterminates
=
self
.indeterminate_imports
.len
()
+
1
;
let
mut
errors
=
Vec
::
new
();
loop
{
debug!
(
"(resolving imports) iteration {}, {} imports left"
,
i
,
self
.unresolved_imports
);
// Attempt to resolve imports in all local modules.
for
module
in
self
.arenas
.local_modules
()
.iter
()
{
self
.current_module
=
module
;
self
.resolve_imports_in_current_module
(
&
mut
errors
);
}
if
self
.unresolved_imports
==
0
{
debug!
(
"(resolving imports) success"
);
for
module
in
self
.arenas
.local_modules
()
.iter
()
{
self
.finalize_resolutions_in
(
module
,
false
);
while
self
.indeterminate_imports
.len
()
<
prev_num_indeterminates
{
prev_num_indeterminates
=
self
.indeterminate_imports
.len
();
debug!
(
"(resolving imports) iteration {}, {} imports left"
,
i
,
prev_num_indeterminates
);
let
mut
imports
=
Vec
::
new
();
::
std
::
mem
::
swap
(
&
mut
imports
,
&
mut
self
.indeterminate_imports
);
for
import
in
imports
{
match
self
.resolve_import
(
&
import
)
{
Failed
(
err
)
=>
{
let
(
span
,
help
)
=
match
err
{
Some
((
span
,
msg
))
=>
(
span
,
format!
(
". {}"
,
msg
)),
None
=>
(
import
.span
,
String
::
new
()),
};
errors
.push
(
ImportResolvingError
{
import_directive
:
import
,
span
:
span
,
help
:
help
,
});
}
Indeterminate
=>
self
.indeterminate_imports
.push
(
import
),
Success
(())
=>
{}
}
break
;
}
i
f
self
.unresolved_imports
==
prev_unresolved_imports
{
// resolving failed
// Report unresolved imports only if no hard error was already reported
// to avoid generating multiple errors on the same import.
// Imports that are still indeterminate at this point are actually blocked
// by errored imports, so there is no point reporting them.
for
module
in
self
.arenas
.local_modules
()
.iter
()
{
self
.finalize_resolutions_in
(
module
,
errors
.len
()
==
0
);
}
for
e
in
errors
{
self
.import_resolving_error
(
e
)
}
break
;
i
+=
1
;
}
for
module
in
self
.arenas
.local_modules
()
.iter
()
{
self
.finalize_resolutions_in
(
module
);
}
// Report unresolved imports only if no hard error was already reported
// to avoid generating multiple errors on the same import.
if
errors
.len
()
==
0
{
if
let
Some
(
import
)
=
self
.indeterminate_imports
.iter
()
.next
()
{
let
error
=
ResolutionError
::
UnresolvedImport
(
None
);
resolve_error
(
self
.resolver
,
import
.span
,
error
)
;
}
}
i
+=
1
;
prev_unresolved_imports
=
self
.unresolved_imports
;
for
e
in
errors
{
self
.import_resolving_error
(
e
)
}
}
...
...
@@ -429,35 +438,6 @@ fn import_resolving_error(&mut self, e: ImportResolvingError<'b>) {
ResolutionError
::
UnresolvedImport
(
Some
((
&
path
,
&
e
.help
))));
}
/// Attempts to resolve imports for the given module only.
fn
resolve_imports_in_current_module
(
&
mut
self
,
errors
:
&
mut
Vec
<
ImportResolvingError
<
'b
>>
)
{
let
mut
imports
=
Vec
::
new
();
let
mut
unresolved_imports
=
self
.current_module.unresolved_imports
.borrow_mut
();
::
std
::
mem
::
swap
(
&
mut
imports
,
&
mut
unresolved_imports
);
for
import_directive
in
imports
{
match
self
.resolve_import
(
&
import_directive
)
{
Failed
(
err
)
=>
{
let
(
span
,
help
)
=
match
err
{
Some
((
span
,
msg
))
=>
(
span
,
format!
(
". {}"
,
msg
)),
None
=>
(
import_directive
.span
,
String
::
new
()),
};
errors
.push
(
ImportResolvingError
{
import_directive
:
import_directive
,
span
:
span
,
help
:
help
,
});
}
Indeterminate
=>
unresolved_imports
.push
(
import_directive
),
Success
(())
=>
{
// Decrement the count of unresolved imports.
assert
!
(
self
.unresolved_imports
>=
1
);
self
.unresolved_imports
-=
1
;
}
}
}
}
/// Attempts to resolve the given import. The return value indicates
/// failure if we're certain the name does not exist, indeterminate if we
/// don't know whether the name exists at the moment due to other
...
...
@@ -468,6 +448,9 @@ fn resolve_import(&mut self, directive: &'b ImportDirective<'b>) -> ResolveResul
names_to_string
(
&
directive
.module_path
),
module_to_string
(
self
.current_module
));
let
module
=
directive
.parent
;
self
.current_module
=
module
;
let
target_module
=
match
directive
.target_module
.get
()
{
Some
(
module
)
=>
module
,
_
=>
match
self
.resolve_module_path
(
&
directive
.module_path
,
...
...
@@ -490,7 +473,6 @@ fn resolve_import(&mut self, directive: &'b ImportDirective<'b>) -> ResolveResul
let
value_result
=
self
.resolve_name_in_module
(
target_module
,
source
,
ValueNS
,
false
,
true
);
let
type_result
=
self
.resolve_name_in_module
(
target_module
,
source
,
TypeNS
,
false
,
true
);
let
module
=
self
.current_module
;
let
mut
privacy_error
=
true
;
for
&
(
ns
,
result
,
determined
)
in
&
[(
ValueNS
,
&
value_result
,
value_determined
),
(
TypeNS
,
&
type_result
,
type_determined
)]
{
...
...
@@ -658,7 +640,7 @@ fn resolve_glob_import(&mut self, target_module: Module<'b>, directive: &'b Impo
// Miscellaneous post-processing, including recording reexports, reporting conflicts,
// reporting the PRIVATE_IN_PUBLIC lint, and reporting unresolved imports.
fn
finalize_resolutions_in
(
&
mut
self
,
module
:
Module
<
'b
>
,
report_unresolved_imports
:
bool
)
{
fn
finalize_resolutions_in
(
&
mut
self
,
module
:
Module
<
'b
>
)
{
// Since import resolution is finished, globs will not define any more names.
*
module
.globs
.borrow_mut
()
=
Vec
::
new
();
...
...
@@ -706,13 +688,6 @@ fn finalize_resolutions_in(&mut self, module: Module<'b>, report_unresolved_impo
self
.export_map
.insert
(
node_id
,
reexports
);
}
}
if
report_unresolved_imports
{
for
import
in
module
.unresolved_imports
.borrow
()
.iter
()
{
resolve_error
(
self
.resolver
,
import
.span
,
ResolutionError
::
UnresolvedImport
(
None
));
break
;
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录