Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 9 pull requests #94567

Closed
wants to merge 25 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
55f938b
update docs for `simplify_type`
lcnr Feb 21, 2022
ba2e0ca
typo
lcnr Feb 21, 2022
bac5523
Use cgroup quotas for calculating `available_parallelism`
the8472 Jan 9, 2022
af6d2ed
hardcode /sys/fs/cgroup instead of doing a lookup via mountinfo
the8472 Mar 2, 2022
e18abbf
update available_parallelism docs since cgroups and sched_getaffinity…
the8472 Mar 2, 2022
37c1eb0
Doc: Fix use of quote instead of backstick in Adapter::map.
darnuria Mar 3, 2022
e3f04de
Add test for higher kinded functions generated by macros
GuillaumeGomez Mar 3, 2022
11c565f
Improve if/else formatting in macro_parser.rs.
nnethercote Mar 3, 2022
b9fabc3
Add a static size assertion for `MatcherPos`.
nnethercote Mar 3, 2022
643ba50
Introduce `MatcherPosRepetition`.
nnethercote Mar 3, 2022
e5f3fd6
Use a better return type for `inner_parse_loop`.
nnethercote Mar 3, 2022
97eb1b4
Change `initial_matcher_pos()` into `MatcherPos::new()`.
nnethercote Mar 3, 2022
5164884
Fix invalid lint_node_id being put on a removed stmt
Urgau Mar 3, 2022
188ae00
add tests for #94502
lcnr Mar 3, 2022
00fffdd
all: fix some typos
cuishuang Mar 3, 2022
ff19c05
remove a unnecessary `..` pattern
TaKO8Ki Mar 3, 2022
f776177
Rollup merge of #92697 - the8472:cgroups, r=joshtriplett
matthiaskrgr Mar 3, 2022
55ddf7d
Rollup merge of #94057 - lcnr:simplify_type-uwu, r=nikomatsakis
matthiaskrgr Mar 3, 2022
c1cac49
Rollup merge of #94547 - nnethercote:parse_tt-cleanups, r=petrochenkov
matthiaskrgr Mar 3, 2022
770a7ec
Rollup merge of #94550 - GuillaumeGomez:HKF-macros, r=notriddle
matthiaskrgr Mar 3, 2022
0c14a12
Rollup merge of #94551 - darnuria:doc-map-backstick, r=dtolnay
matthiaskrgr Mar 3, 2022
aaac4f9
Rollup merge of #94553 - lcnr:add-tests, r=Dylan-DPC
matthiaskrgr Mar 3, 2022
7ea81d6
Rollup merge of #94554 - Urgau:stmt-node-id-ice, r=petrochenkov
matthiaskrgr Mar 3, 2022
bb8a82e
Rollup merge of #94555 - cuishuang:master, r=oli-obk
matthiaskrgr Mar 3, 2022
2894281
Rollup merge of #94563 - TaKO8Ki:remove-unnecessary-patten-for-ignori…
matthiaskrgr Mar 3, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use a better return type for inner_parse_loop.
Because `inner_parse_loop` has only one way to not succeed, not three.
  • Loading branch information
nnethercote committed Mar 3, 2022
commit e5f3fd625022c22f0f415e9c11ca84e1f2be5771
60 changes: 35 additions & 25 deletions compiler/rustc_expand/src/mbe/macro_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,12 @@ impl<'root, 'tt> DerefMut for MatcherPosHandle<'root, 'tt> {
}
}

enum EofItems<'root, 'tt> {
None,
One(MatcherPosHandle<'root, 'tt>),
Multiple,
}

/// Represents the possible results of an attempted parse.
crate enum ParseResult<T> {
/// Parsed successfully.
Expand Down Expand Up @@ -449,10 +455,10 @@ fn inner_parse_loop<'root, 'tt>(
sess: &ParseSess,
cur_items: &mut SmallVec<[MatcherPosHandle<'root, 'tt>; 1]>,
next_items: &mut Vec<MatcherPosHandle<'root, 'tt>>,
eof_items: &mut SmallVec<[MatcherPosHandle<'root, 'tt>; 1]>,
bb_items: &mut SmallVec<[MatcherPosHandle<'root, 'tt>; 1]>,
eof_items: &mut EofItems<'root, 'tt>,
token: &Token,
) -> ParseResult<()> {
) -> Result<(), (rustc_span::Span, String)> {
// Pop items from `cur_items` until it is empty.
while let Some(mut item) = cur_items.pop() {
// When unzipped trees end, remove them. This corresponds to backtracking out of a
Expand Down Expand Up @@ -522,7 +528,10 @@ fn inner_parse_loop<'root, 'tt>(
} else {
// If we are not in a repetition, then being at the end of a matcher means that we
// have reached the potential end of the input.
eof_items.push(item);
*eof_items = match eof_items {
EofItems::None => EofItems::One(item),
EofItems::One(_) | EofItems::Multiple => EofItems::Multiple,
}
}
} else {
// We are in the middle of a matcher. Look at what token in the matcher we are trying
Expand Down Expand Up @@ -567,7 +576,7 @@ fn inner_parse_loop<'root, 'tt>(
// We need to match a metavar (but the identifier is invalid)... this is an error
TokenTree::MetaVarDecl(span, _, None) => {
if sess.missing_fragment_specifiers.borrow_mut().remove(&span).is_some() {
return Error(span, "missing fragment specifier".to_string());
return Err((span, "missing fragment specifier".to_string()));
}
}

Expand Down Expand Up @@ -615,7 +624,7 @@ fn inner_parse_loop<'root, 'tt>(
}

// Yay a successful parse (so far)!
Success(())
Ok(())
}

/// Use the given sequence of token trees (`ms`) as a matcher. Match the token
Expand All @@ -638,12 +647,13 @@ pub(super) fn parse_tt(
let mut next_items = Vec::new();

loop {
assert!(next_items.is_empty());

// Matcher positions black-box parsed by parser.rs (`parser`)
let mut bb_items = SmallVec::new();

// Matcher positions that would be valid if the macro invocation was over now
let mut eof_items = SmallVec::new();
assert!(next_items.is_empty());
let mut eof_items = EofItems::None;

// Process `cur_items` until either we have finished the input or we need to get some
// parsing from the black-box parser done. The result is that `next_items` will contain a
Expand All @@ -652,34 +662,34 @@ pub(super) fn parse_tt(
parser.sess,
&mut cur_items,
&mut next_items,
&mut eof_items,
&mut bb_items,
&mut eof_items,
&parser.token,
) {
Success(_) => {}
Failure(token, msg) => return Failure(token, msg),
Error(sp, msg) => return Error(sp, msg),
ErrorReported => return ErrorReported,
Ok(()) => {}
Err((sp, msg)) => return Error(sp, msg),
}

// inner parse loop handled all cur_items, so it's empty
assert!(cur_items.is_empty());

// We need to do some post processing after the `inner_parser_loop`.
// We need to do some post processing after the `inner_parse_loop`.
//
// Error messages here could be improved with links to original rules.

// If we reached the EOF, check that there is EXACTLY ONE possible matcher. Otherwise,
// either the parse is ambiguous (which should never happen) or there is a syntax error.
if parser.token == token::Eof {
return if eof_items.len() == 1 {
let matches =
eof_items[0].matches.iter_mut().map(|dv| Lrc::make_mut(dv).pop().unwrap());
nameize(parser.sess, ms, matches)
} else if eof_items.len() > 1 {
Error(parser.token.span, "ambiguity: multiple successful parses".to_string())
} else {
Failure(
return match eof_items {
EofItems::One(mut eof_item) => {
let matches =
eof_item.matches.iter_mut().map(|dv| Lrc::make_mut(dv).pop().unwrap());
nameize(parser.sess, ms, matches)
}
EofItems::Multiple => {
Error(parser.token.span, "ambiguity: multiple successful parses".to_string())
}
EofItems::None => Failure(
Token::new(
token::Eof,
if parser.token.span.is_dummy() {
Expand All @@ -689,12 +699,12 @@ pub(super) fn parse_tt(
},
),
"missing tokens in macro arguments",
)
),
};
}
// Performance hack: eof_items may share matchers via Rc with other things that we want
// to modify. Dropping eof_items now may drop these refcounts to 1, preventing an
// unnecessary implicit clone later in Rc::make_mut.
// Performance hack: `eof_items` may share matchers via `Rc` with other things that we want
// to modify. Dropping `eof_items` now may drop these refcounts to 1, preventing an
// unnecessary implicit clone later in `Rc::make_mut`.
drop(eof_items);

// If there are no possible next positions AND we aren't waiting for the black-box parser,
Expand Down