Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
1064d41c
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,发现更多精彩内容 >>
提交
1064d41c
编写于
8月 17, 2019
作者:
V
Vadim Petrochenkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
resolve/expand: Rename some things for clarity
上级
d479ff2f
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
43 addition
and
41 deletion
+43
-41
src/librustc_resolve/build_reduced_graph.rs
src/librustc_resolve/build_reduced_graph.rs
+7
-7
src/librustc_resolve/lib.rs
src/librustc_resolve/lib.rs
+2
-2
src/librustc_resolve/macros.rs
src/librustc_resolve/macros.rs
+11
-11
src/librustc_resolve/resolve_imports.rs
src/librustc_resolve/resolve_imports.rs
+2
-2
src/libsyntax/ext/base.rs
src/libsyntax/ext/base.rs
+4
-4
src/libsyntax/ext/expand.rs
src/libsyntax/ext/expand.rs
+14
-11
src/libsyntax/ext/placeholders.rs
src/libsyntax/ext/placeholders.rs
+3
-4
未找到文件。
src/librustc_resolve/build_reduced_graph.rs
浏览文件 @
1064d41c
...
...
@@ -160,23 +160,23 @@ fn get_macro_by_def_id(&mut self, def_id: DefId) -> Option<Lrc<SyntaxExtension>>
Some
(
ext
)
}
// FIXME: `extra_placeholders` should be included into the `fragment` as regular placeholders.
crate
fn
build_reduced_graph
(
&
mut
self
,
fragment
:
&
AstFragment
,
extra_placeholders
:
&
[
Expn
Id
],
extra_placeholders
:
&
[
Node
Id
],
parent_scope
:
ParentScope
<
'a
>
,
)
->
LegacyScope
<
'a
>
{
let
mut
def_collector
=
DefCollector
::
new
(
&
mut
self
.definitions
,
parent_scope
.expansion
);
fragment
.visit_with
(
&
mut
def_collector
);
for
placeholder
in
extra_placeholders
{
def_collector
.visit_macro_invoc
(
NodeId
::
placeholder_from_expn_id
(
*
placeholder
)
);
def_collector
.visit_macro_invoc
(
*
placeholder
);
}
let
mut
visitor
=
BuildReducedGraphVisitor
{
r
:
self
,
parent_scope
};
fragment
.visit_with
(
&
mut
visitor
);
for
placeholder
in
extra_placeholders
{
visitor
.parent_scope.legacy
=
visitor
.visit_invoc
(
NodeId
::
placeholder_from_expn_id
(
*
placeholder
));
visitor
.parent_scope.legacy
=
visitor
.visit_invoc
(
*
placeholder
);
}
visitor
.parent_scope.legacy
...
...
@@ -884,7 +884,7 @@ fn build_reduced_graph_for_block(&mut self, block: &Block) {
}
/// Builds the reduced graph for a single item in an external crate.
fn
build_reduced_graph_for_external_crate_res
(
&
mut
self
,
child
:
Export
<
ast
::
NodeId
>
)
{
fn
build_reduced_graph_for_external_crate_res
(
&
mut
self
,
child
:
Export
<
NodeId
>
)
{
let
parent
=
self
.parent_scope.module
;
let
Export
{
ident
,
res
,
vis
,
span
}
=
child
;
// FIXME: We shouldn't create the gensym here, it should come from metadata,
...
...
@@ -1073,10 +1073,10 @@ fn contains_macro_use(&mut self, attrs: &[ast::Attribute]) -> bool {
false
}
fn
visit_invoc
(
&
mut
self
,
id
:
ast
::
NodeId
)
->
LegacyScope
<
'a
>
{
fn
visit_invoc
(
&
mut
self
,
id
:
NodeId
)
->
LegacyScope
<
'a
>
{
let
invoc_id
=
id
.placeholder_to_expn_id
();
self
.parent_scope.module.un
resolv
ed_invocations
.borrow_mut
()
.insert
(
invoc_id
);
self
.parent_scope.module.un
expand
ed_invocations
.borrow_mut
()
.insert
(
invoc_id
);
let
old_parent_scope
=
self
.r.invocation_parent_scopes
.insert
(
invoc_id
,
self
.parent_scope
);
assert
!
(
old_parent_scope
.is_none
(),
"invocation data is reset for an invocation"
);
...
...
src/librustc_resolve/lib.rs
浏览文件 @
1064d41c
...
...
@@ -448,7 +448,7 @@ pub struct ModuleData<'a> {
populate_on_access
:
Cell
<
bool
>
,
// Macro invocations that can expand into items in this module.
un
resolv
ed_invocations
:
RefCell
<
FxHashSet
<
ExpnId
>>
,
un
expand
ed_invocations
:
RefCell
<
FxHashSet
<
ExpnId
>>
,
no_implicit_prelude
:
bool
,
...
...
@@ -478,7 +478,7 @@ fn new(parent: Option<Module<'a>>,
normal_ancestor_id
,
lazy_resolutions
:
Default
::
default
(),
populate_on_access
:
Cell
::
new
(
!
normal_ancestor_id
.is_local
()),
un
resolv
ed_invocations
:
Default
::
default
(),
un
expand
ed_invocations
:
Default
::
default
(),
no_implicit_prelude
:
false
,
glob_importers
:
RefCell
::
new
(
Vec
::
new
()),
globs
:
RefCell
::
new
(
Vec
::
new
()),
...
...
src/librustc_resolve/macros.rs
浏览文件 @
1064d41c
...
...
@@ -10,7 +10,7 @@
use
rustc
::
hir
::
def
::{
self
,
DefKind
,
NonMacroAttrKind
};
use
rustc
::
middle
::
stability
;
use
rustc
::{
ty
,
lint
,
span_bug
};
use
syntax
::
ast
::{
self
,
Ident
};
use
syntax
::
ast
::{
self
,
NodeId
,
Ident
};
use
syntax
::
attr
::
StabilityLevel
;
use
syntax
::
edition
::
Edition
;
use
syntax
::
ext
::
base
::{
self
,
Indeterminate
,
SpecialDerives
};
...
...
@@ -26,7 +26,7 @@
use
std
::{
mem
,
ptr
};
use
rustc_data_structures
::
sync
::
Lrc
;
type
Res
=
def
::
Res
<
ast
::
NodeId
>
;
type
Res
=
def
::
Res
<
NodeId
>
;
/// Binding produced by a `macro_rules` item.
/// Not modularized, can shadow previous legacy bindings, etc.
...
...
@@ -91,11 +91,11 @@ fn fast_print_path(path: &ast::Path) -> Symbol {
}
impl
<
'a
>
base
::
Resolver
for
Resolver
<
'a
>
{
fn
next_node_id
(
&
mut
self
)
->
ast
::
NodeId
{
fn
next_node_id
(
&
mut
self
)
->
NodeId
{
self
.session
.next_node_id
()
}
fn
get_module_scope
(
&
mut
self
,
id
:
ast
::
NodeId
)
->
ExpnId
{
fn
get_module_scope
(
&
mut
self
,
id
:
NodeId
)
->
ExpnId
{
let
expn_id
=
ExpnId
::
fresh
(
Some
(
ExpnData
::
default
(
ExpnKind
::
Macro
(
MacroKind
::
Attr
,
sym
::
test_case
),
DUMMY_SP
,
self
.session
.edition
()
)));
...
...
@@ -115,18 +115,18 @@ fn resolve_dollar_crates(&mut self) {
});
}
// FIXME: `extra_placeholders` should be included into the `fragment` as regular placeholders.
fn
visit_ast_fragment_with_placeholders
(
&
mut
self
,
expansion
:
ExpnId
,
fragment
:
&
AstFragment
,
derives
:
&
[
Expn
Id
]
&
mut
self
,
expansion
:
ExpnId
,
fragment
:
&
AstFragment
,
extra_placeholders
:
&
[
Node
Id
]
)
{
// Integrate the new AST fragment into all the definition and module structures.
// We are inside the `expansion` now, but other parent scope components are still the same.
let
parent_scope
=
ParentScope
{
expansion
,
..
self
.invocation_parent_scopes
[
&
expansion
]
};
let
output_legacy_scope
=
self
.build_reduced_graph
(
fragment
,
derives
,
parent_scope
);
let
output_legacy_scope
=
self
.build_reduced_graph
(
fragment
,
extra_placeholders
,
parent_scope
);
self
.output_legacy_scopes
.insert
(
expansion
,
output_legacy_scope
);
parent_scope
.module.un
resolv
ed_invocations
.borrow_mut
()
.remove
(
&
expansion
);
parent_scope
.module.un
expand
ed_invocations
.borrow_mut
()
.remove
(
&
expansion
);
}
fn
register_builtin_macro
(
&
mut
self
,
ident
:
ast
::
Ident
,
ext
:
SyntaxExtension
)
{
...
...
@@ -480,7 +480,7 @@ struct Flags: u8 {
Scope
::
MacroUsePrelude
=>
match
this
.macro_use_prelude
.get
(
&
ident
.name
)
.cloned
()
{
Some
(
binding
)
=>
Ok
((
binding
,
Flags
::
PRELUDE
|
Flags
::
MISC_FROM_PRELUDE
)),
None
=>
Err
(
Determinacy
::
determined
(
this
.graph_root.un
resolv
ed_invocations
.borrow
()
.is_empty
()
this
.graph_root.un
expand
ed_invocations
.borrow
()
.is_empty
()
))
}
Scope
::
BuiltinAttrs
=>
if
is_builtin_attr_name
(
ident
.name
)
{
...
...
@@ -503,7 +503,7 @@ struct Flags: u8 {
Scope
::
ExternPrelude
=>
match
this
.extern_prelude_get
(
ident
,
!
record_used
)
{
Some
(
binding
)
=>
Ok
((
binding
,
Flags
::
PRELUDE
)),
None
=>
Err
(
Determinacy
::
determined
(
this
.graph_root.un
resolv
ed_invocations
.borrow
()
.is_empty
()
this
.graph_root.un
expand
ed_invocations
.borrow
()
.is_empty
()
)),
}
Scope
::
ToolPrelude
=>
if
KNOWN_TOOLS
.contains
(
&
ident
.name
)
{
...
...
src/librustc_resolve/resolve_imports.rs
浏览文件 @
1064d41c
...
...
@@ -202,7 +202,7 @@ impl<'a> Resolver<'a> {
Err
((
Determined
,
Weak
::
No
))
}
else
if
let
Some
(
binding
)
=
self
.extern_prelude_get
(
ident
,
!
record_used
)
{
Ok
(
binding
)
}
else
if
!
self
.graph_root.un
resolv
ed_invocations
.borrow
()
.is_empty
()
{
}
else
if
!
self
.graph_root.un
expand
ed_invocations
.borrow
()
.is_empty
()
{
// Macro-expanded `extern crate` items can add names to extern prelude.
Err
((
Undetermined
,
Weak
::
No
))
}
else
{
...
...
@@ -348,7 +348,7 @@ impl<'a> Resolver<'a> {
// progress, we have to ignore those potential unresolved invocations from other modules
// and prohibit access to macro-expanded `macro_export` macros instead (unless restricted
// shadowing is enabled, see `macro_expanded_macro_export_errors`).
let
unexpanded_macros
=
!
module
.un
resolv
ed_invocations
.borrow
()
.is_empty
();
let
unexpanded_macros
=
!
module
.un
expand
ed_invocations
.borrow
()
.is_empty
();
if
let
Some
(
binding
)
=
resolution
.binding
{
if
!
unexpanded_macros
||
ns
==
MacroNS
||
restricted_shadowing
{
return
check_usable
(
self
,
binding
);
...
...
src/libsyntax/ext/base.rs
浏览文件 @
1064d41c
use
crate
::
ast
::{
self
,
Attribute
,
Name
,
PatKind
};
use
crate
::
ast
::{
self
,
NodeId
,
Attribute
,
Name
,
PatKind
};
use
crate
::
attr
::{
HasAttrs
,
Stability
,
Deprecation
};
use
crate
::
source_map
::
SourceMap
;
use
crate
::
edition
::
Edition
;
...
...
@@ -671,13 +671,13 @@ pub struct SpecialDerives: u8 {
}
pub
trait
Resolver
{
fn
next_node_id
(
&
mut
self
)
->
ast
::
NodeId
;
fn
next_node_id
(
&
mut
self
)
->
NodeId
;
fn
get_module_scope
(
&
mut
self
,
id
:
ast
::
NodeId
)
->
ExpnId
;
fn
get_module_scope
(
&
mut
self
,
id
:
NodeId
)
->
ExpnId
;
fn
resolve_dollar_crates
(
&
mut
self
);
fn
visit_ast_fragment_with_placeholders
(
&
mut
self
,
expn_id
:
ExpnId
,
fragment
:
&
AstFragment
,
derives
:
&
[
Expn
Id
]);
extra_placeholders
:
&
[
Node
Id
]);
fn
register_builtin_macro
(
&
mut
self
,
ident
:
ast
::
Ident
,
ext
:
SyntaxExtension
);
fn
resolve_imports
(
&
mut
self
);
...
...
src/libsyntax/ext/expand.rs
浏览文件 @
1064d41c
...
...
@@ -291,7 +291,7 @@ pub fn fully_expand_fragment(&mut self, input_fragment: AstFragment) -> AstFragm
// Unresolved macros produce dummy outputs as a recovery measure.
invocations
.reverse
();
let
mut
expanded_fragments
=
Vec
::
new
();
let
mut
derive
s
:
FxHashMap
<
ExpnId
,
Vec
<
_
>>
=
FxHashMap
::
default
();
let
mut
all_derive_placeholder
s
:
FxHashMap
<
ExpnId
,
Vec
<
_
>>
=
FxHashMap
::
default
();
let
mut
undetermined_invocations
=
Vec
::
new
();
let
(
mut
progress
,
mut
force
)
=
(
false
,
!
self
.monotonic
);
loop
{
...
...
@@ -347,13 +347,14 @@ pub fn fully_expand_fragment(&mut self, input_fragment: AstFragment) -> AstFragm
let
mut
item
=
self
.fully_configure
(
item
);
item
.visit_attrs
(|
attrs
|
attrs
.retain
(|
a
|
a
.path
!=
sym
::
derive
));
let
derives
=
derives
.entry
(
invoc
.expansion_data.id
)
.or_default
();
let
derive_placeholders
=
all_derive_placeholders
.entry
(
invoc
.expansion_data.id
)
.or_default
();
derives
.reserve
(
traits
.len
());
derive
_placeholder
s
.reserve
(
traits
.len
());
invocations
.reserve
(
traits
.len
());
for
path
in
traits
{
let
expn_id
=
ExpnId
::
fresh
(
None
);
derive
s
.push
(
expn_id
);
derive
_placeholders
.push
(
NodeId
::
placeholder_from_expn_id
(
expn_id
)
);
invocations
.push
(
Invocation
{
kind
:
InvocationKind
::
Derive
{
path
,
item
:
item
.clone
()
},
fragment_kind
:
invoc
.fragment_kind
,
...
...
@@ -365,7 +366,7 @@ pub fn fully_expand_fragment(&mut self, input_fragment: AstFragment) -> AstFragm
}
let
fragment
=
invoc
.fragment_kind
.expect_from_annotatables
(::
std
::
iter
::
once
(
item
));
self
.collect_invocations
(
fragment
,
derives
)
self
.collect_invocations
(
fragment
,
derive
_placeholder
s
)
}
else
{
unreachable!
()
};
...
...
@@ -384,10 +385,11 @@ pub fn fully_expand_fragment(&mut self, input_fragment: AstFragment) -> AstFragm
// Finally incorporate all the expanded macros into the input AST fragment.
let
mut
placeholder_expander
=
PlaceholderExpander
::
new
(
self
.cx
,
self
.monotonic
);
while
let
Some
(
expanded_fragments
)
=
expanded_fragments
.pop
()
{
for
(
mark
,
expanded_fragment
)
in
expanded_fragments
.into_iter
()
.rev
()
{
let
derives
=
derives
.remove
(
&
mark
)
.unwrap_or_else
(
Vec
::
new
);
placeholder_expander
.add
(
NodeId
::
placeholder_from_expn_id
(
mark
),
expanded_fragment
,
derives
);
for
(
expn_id
,
expanded_fragment
)
in
expanded_fragments
.into_iter
()
.rev
()
{
let
derive_placeholders
=
all_derive_placeholders
.remove
(
&
expn_id
)
.unwrap_or_else
(
Vec
::
new
);
placeholder_expander
.add
(
NodeId
::
placeholder_from_expn_id
(
expn_id
),
expanded_fragment
,
derive_placeholders
);
}
}
fragment_with_placeholders
.mut_visit_with
(
&
mut
placeholder_expander
);
...
...
@@ -404,7 +406,7 @@ fn resolve_imports(&mut self) {
/// them with "placeholders" - dummy macro invocations with specially crafted `NodeId`s.
/// Then call into resolver that builds a skeleton ("reduced graph") of the fragment and
/// prepares data for resolving paths of macro invocations.
fn
collect_invocations
(
&
mut
self
,
mut
fragment
:
AstFragment
,
derives
:
&
[
Expn
Id
])
fn
collect_invocations
(
&
mut
self
,
mut
fragment
:
AstFragment
,
extra_placeholders
:
&
[
Node
Id
])
->
(
AstFragment
,
Vec
<
Invocation
>
)
{
// Resolve `$crate`s in the fragment for pretty-printing.
self
.cx.resolver
.resolve_dollar_crates
();
...
...
@@ -423,9 +425,10 @@ fn collect_invocations(&mut self, mut fragment: AstFragment, derives: &[ExpnId])
collector
.invocations
};
// FIXME: Merge `extra_placeholders` into the `fragment` as regular placeholders.
if
self
.monotonic
{
self
.cx.resolver
.visit_ast_fragment_with_placeholders
(
self
.cx.current_expansion.id
,
&
fragment
,
derive
s
);
self
.cx.current_expansion.id
,
&
fragment
,
extra_placeholder
s
);
}
(
fragment
,
invocations
)
...
...
src/libsyntax/ext/placeholders.rs
浏览文件 @
1064d41c
...
...
@@ -2,7 +2,6 @@
use
crate
::
source_map
::{
DUMMY_SP
,
dummy_spanned
};
use
crate
::
ext
::
base
::
ExtCtxt
;
use
crate
::
ext
::
expand
::{
AstFragment
,
AstFragmentKind
};
use
crate
::
ext
::
hygiene
::
ExpnId
;
use
crate
::
tokenstream
::
TokenStream
;
use
crate
::
mut_visit
::
*
;
use
crate
::
ptr
::
P
;
...
...
@@ -86,11 +85,11 @@ pub fn new(cx: &'a mut ExtCtxt<'b>, monotonic: bool) -> Self {
}
}
pub
fn
add
(
&
mut
self
,
id
:
ast
::
NodeId
,
mut
fragment
:
AstFragment
,
derives
:
Vec
<
Expn
Id
>
)
{
pub
fn
add
(
&
mut
self
,
id
:
ast
::
NodeId
,
mut
fragment
:
AstFragment
,
placeholders
:
Vec
<
Node
Id
>
)
{
fragment
.mut_visit_with
(
self
);
if
let
AstFragment
::
Items
(
mut
items
)
=
fragment
{
for
derive
in
derive
s
{
match
self
.remove
(
NodeId
::
placeholder_from_expn_id
(
derive
)
)
{
for
placeholder
in
placeholder
s
{
match
self
.remove
(
placeholder
)
{
AstFragment
::
Items
(
derived_items
)
=>
items
.extend
(
derived_items
),
_
=>
unreachable!
(),
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录