-
Notifications
You must be signed in to change notification settings - Fork 12.1k
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
Convert some macros from LegacyBang
to Bang
.
#125094
Conversation
Specifically: `cfg!`, `column!`, `file!`, `line!`, `module_path!`. This requires changing `BangProcMacro for F` to use the `ecx` and `span` arguments, instead of ignoring them.
I don't know if this is a good idea or not, but I was curious and I converted a few of the easiest ones. There are several more than look easy. There are also harder ones like |
F: Fn(TokenStream) -> TokenStream, | ||
F: Fn(&mut ExtCtxt<'_>, Span, TokenStream) -> TokenStream, | ||
{ | ||
fn expand<'cx>( | ||
&self, | ||
_ecx: &'cx mut ExtCtxt<'_>, | ||
_span: Span, | ||
ecx: &'cx mut ExtCtxt<'_>, | ||
span: Span, | ||
ts: TokenStream, | ||
) -> Result<TokenStream, ErrorGuaranteed> { | ||
// FIXME setup implicit context in TLS before calling self. | ||
Ok(self(ts)) | ||
Ok(self(ecx, span, ts)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can improve the return types here to handle ExpandResult::Retry(())
. e.g.
pub enum BangRetry {
Yes,
No,
}
impl<F> BangProcMacro for F
where
F: Fn(&mut ExtCtxt<'_>, Span, TokenStream) -> Result<TokenStream, BangRetry>,
{
fn expand<'cx>(
&self,
ecx: &'cx mut ExtCtxt<'_>,
span: Span,
ts: TokenStream,
) -> Result<TokenStream, (BangRetry, ErrorGuaranteed)> {
self(ecx, span, ts).map_err(|retry| (retry, ErrorGuaranteed(())))
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a good suggestion. But I'll wait for feedback from @petrochenkov about whether converting LegacyBang
to Bang
is a good idea in general before putting more effort in.
@petrochenkov, what do you think?
Right now built-in bang macros go through the next pipeline when expanding: "Legacy" in eager positions in built-in macros: produced | AST | consumed So currently we do not have any token-based eager expansion, we only ever consume AST, so we never need the token representation of builtin macros' outputs. When/if we have token-based eager expansions we will indeed need the built-in macro outputs in their token forms. Basically, I don't think we need to do this now. |
Very few macros are converted here, so I don't expect much perf difference, but let's try anyway. |
This comment has been minimized.
This comment has been minimized.
Convert some macros from `LegacyBang` to `Bang`. Specifically: `cfg!`, `column!`, `file!`, `line!`, `module_path!`. This requires changing `BangProcMacro for F` to use the `ecx` and `span` arguments, instead of ignoring them. r? `@petrochenkov`
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (38deb65): comparison URL. Overall result: ❌ regressions - no action neededBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. @bors rollup=never Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)Results (primary 2.5%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 673.262s -> 673.191s (-0.01%) |
Ok. My motivation was simple: I saw two ways of doing something, so I tried to take a step towards removing the one described as "legacy", to simplify things. Sounds like that's not appropriate. |
Sometimes things in the compiler are named "legacy" too soon. |
Specifically:
cfg!
,column!
,file!
,line!
,module_path!
.This requires changing
BangProcMacro for F
to use theecx
andspan
arguments, instead of ignoring them.r? @petrochenkov