Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
7504b9bb
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,发现更多精彩内容 >>
未验证
提交
7504b9bb
编写于
3月 25, 2021
作者:
A
Aaron Hill
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Avoid double-collection for expression nonterminals
上级
fe60f19f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
17 addition
and
17 deletion
+17
-17
compiler/rustc_parse/src/parser/expr.rs
compiler/rustc_parse/src/parser/expr.rs
+15
-0
compiler/rustc_parse/src/parser/mod.rs
compiler/rustc_parse/src/parser/mod.rs
+1
-1
compiler/rustc_parse/src/parser/nonterminal.rs
compiler/rustc_parse/src/parser/nonterminal.rs
+1
-16
未找到文件。
compiler/rustc_parse/src/parser/expr.rs
浏览文件 @
7504b9bb
...
...
@@ -92,6 +92,21 @@ pub fn parse_expr(&mut self) -> PResult<'a, P<Expr>> {
self
.parse_expr_res
(
Restrictions
::
empty
(),
None
)
}
/// Parses an expression, forcing tokens to be collected
pub
fn
parse_expr_force_collect
(
&
mut
self
)
->
PResult
<
'a
,
P
<
Expr
>>
{
// If we have outer attributes, then the call to `collect_tokens_trailing_token`
// will be made for us.
if
matches!
(
self
.token.kind
,
TokenKind
::
Pound
|
TokenKind
::
DocComment
(
..
))
{
self
.parse_expr
()
}
else
{
// If we don't have outer attributes, then we need to ensure
// that collection happens by using `collect_tokens_no_attrs`.
// Expression don't support custom inner attributes, so `parse_expr`
// will never try to collect tokens if we don't have outer attributes.
self
.collect_tokens_no_attrs
(|
this
|
this
.parse_expr
())
}
}
pub
(
super
)
fn
parse_anon_const_expr
(
&
mut
self
)
->
PResult
<
'a
,
AnonConst
>
{
self
.parse_expr
()
.map
(|
value
|
AnonConst
{
id
:
DUMMY_NODE_ID
,
value
})
}
...
...
compiler/rustc_parse/src/parser/mod.rs
浏览文件 @
7504b9bb
...
...
@@ -987,7 +987,7 @@ fn parse_mac_args_common(&mut self, delimited_only: bool) -> PResult<'a, MacArgs
}
// Collect tokens because they are used during lowering to HIR.
let
expr
=
self
.
collect_tokens_no_attrs
(|
this
|
this
.parse_expr
()
)
?
;
let
expr
=
self
.
parse_expr_force_collect
(
)
?
;
let
span
=
expr
.span
;
match
&
expr
.kind
{
...
...
compiler/rustc_parse/src/parser/nonterminal.rs
浏览文件 @
7504b9bb
...
...
@@ -128,22 +128,7 @@ pub fn parse_nonterminal(&mut self, kind: NonterminalKind) -> PResult<'a, Nonter
})
?
)
}
// If there are attributes present, then `parse_expr` will end up collecting tokens,
// turning the outer `collect_tokens_no_attrs` into a no-op due to the already present
// tokens. If there are *not* attributes present, then the outer
// `collect_tokens_no_attrs` will ensure that we will end up collecting tokens for the
// expressions.
//
// This is less efficient than it could be, since the outer `collect_tokens_no_attrs`
// still needs to snapshot the `TokenCursor` before calling `parse_expr`, even when
// `parse_expr` will end up collecting tokens. Ideally, this would work more like
// `parse_item`, and take in a `ForceCollect` parameter. However, this would require
// adding a `ForceCollect` parameter in a bunch of places in expression parsing
// for little gain. If the perf impact from this turns out to be noticeable, we should
// revisit this apporach.
NonterminalKind
::
Expr
=>
{
token
::
NtExpr
(
self
.collect_tokens_no_attrs
(|
this
|
this
.parse_expr
())
?
)
}
NonterminalKind
::
Expr
=>
token
::
NtExpr
(
self
.parse_expr_force_collect
()
?
),
NonterminalKind
::
Literal
=>
{
// The `:literal` matcher does not support attributes
token
::
NtLiteral
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录