-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Expansion-driven outline module parsing #69838
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
Changes from all commits
bc75cba
2899a58
185c1d3
2db5d49
803de31
7108b7f
dfcefa4
ca098b1
53a633f
98e71cd
b9e1b26
8bab88f
463995f
59bf8a0
83a757a
f1ca996
ddcc8ec
3796fae
31ee8e0
a6cb04f
7d0e5bb
fe71342
41a0b3e
5ee4f6f
e301291
8caf688
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ use rustc_ast::tokenstream::TokenStream; | |
use rustc_ast_pretty::pprust; | ||
use rustc_expand::base::{self, *}; | ||
use rustc_expand::panictry; | ||
use rustc_parse::{self, new_sub_parser_from_file, parser::Parser, DirectoryOwnership}; | ||
use rustc_parse::{self, new_sub_parser_from_file, parser::Parser}; | ||
use rustc_session::lint::builtin::INCOMPLETE_INCLUDE; | ||
use rustc_span::symbol::Symbol; | ||
use rustc_span::{self, Pos, Span}; | ||
|
@@ -108,8 +108,7 @@ pub fn expand_include<'cx>( | |
return DummyResult::any(sp); | ||
} | ||
}; | ||
let directory_ownership = DirectoryOwnership::Owned { relative: None }; | ||
let p = new_sub_parser_from_file(cx.parse_sess(), &file, directory_ownership, None, sp); | ||
let p = new_sub_parser_from_file(cx.parse_sess(), &file, None, sp); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This apparently broke Servo's IIUC, this can't be fixed locally either, because the EDIT: adjusted example to fit @Mark-Simulacrum's reproduction. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a minimal reproduction:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've just recalled a related issue - #58818. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
FWIW, we have Perhaps using these data we can hack up something reproducing the old behavior. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can only detect (The proper fix is a flag in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @petrochenkov So I tried two different approaches to set fn is_current_expansion_macro_named(&self, sym: Symbol) -> bool {
let mut curr = self.cx.current_expansion.id;
loop {
let expn_data = curr.expn_data();
if expn_data.kind == ExpnKind::Macro(MacroKind::Bang, sym) {
// Stop going up the backtrace once `sym` is encountered.
return true;
}
if expn_data.is_root() {
// Reached root, need to bail to ensure termination.
return false;
}
curr = expn_data.call_site.ctxt().outer_expn();
}
} and then using it in let pushed = &mut false; // Record `parse_external_mod` pushing so we can pop.
let mut dir = Directory { ownership: orig_ownership, path: module.directory };
if self.is_current_expansion_macro_named(sym::include) {
log::debug!("flat_map_item, is_current_expansion_macro_named = true");
dir.ownership = DirectoryOwnership::Owned { relative: None };
} The log message here does trigger on @Mark-Simulacrum's regression test, but this doesn't fix the issue. I also tweaked let (expanded_fragment, new_invocations) = match res {
InvocationRes::Single(ext) => match self.expand_invoc(invoc, &ext.kind) {
ExpandResult::Ready(fragment) => {
if ext.foobar {
self.cx.current_expansion.directory_ownership =
DirectoryOwnership::Owned { relative: None };
log::debug!("fully_expand_fragment, using foobar");
}
self.collect_invocations(fragment, &[]) and which is set in if result.is_builtin {
// The macro was marked with `#[rustc_builtin_macro]`.
if let Some(ext) = self.builtin_macros.remove(&item.ident.name) {
// The macro is a built-in, replace its expander function
// while still taking everything else from the source code.
result.kind = ext.kind;
if item.ident.name == sym::include {
result.foobar = true;
log::debug!("compile_macro, setting foobar");
} The log message also triggers here, but also does nothing to fix the issue, as the approach is the same as the other mechanism. I'm not sure why it doesn't work. :( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Found a fix, PR up at #70184. |
||
|
||
struct ExpandResult<'a> { | ||
p: Parser<'a>, | ||
|
Uh oh!
There was an error while loading. Please reload this page.