-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
add const_eval_select macro to reduce redundancy #132571
Conversation
3d607ed
to
37455d2
Compare
In many cases, const_eval_select is actually the entire body of the surrounding function. The current macro generates an expression as that seemed most natural, but an alternative worth considering is having a macro that basically generates a function with two bodies -- a const-body and a runtime-body. Conceptually I prefer the expression-based version, but the function version would be easier to make "look good" in the macro. |
This comment has been minimized.
This comment has been minimized.
37455d2
to
9456d5c
Compare
This comment has been minimized.
This comment has been minimized.
fe2aab4
to
03f1224
Compare
This comment has been minimized.
This comment has been minimized.
03f1224
to
6e70d4d
Compare
The function based version does seem less redundant, but is a bit annoying when there is a shared section of the function, as you'd then have to use a nested function again. Maybe closure syntax can be reused here for the args and return type? |
Sure that is easy to do... it's an immediately invoked closure though, so it'll still be syntactically strange. |
It may make more sense to do it a bit like the Miri @capture {
arg1: i32 = arg1_val,
arg2: T = arg2_val,
} -> ReturnType:
if const {
// ...
} else {
// ...
} |
Hmm right. Would be neat if we could use closures in general (before this PR) and just have them not capture anything like when converting them to function pointers. Then we wouldn't need to specify types at all. So this is an improvement over the status, so let's go with it and separately think about other things |
Does
With the |
71ddbc4
to
d731552
Compare
I do not believe so
Without, I think that style only makes sense if there are multiple such things like in miri callbacks |
d731552
to
1bf3269
Compare
There are multiple things though, namely the two arms of the I think I like the |
1bf3269
to
54bb987
Compare
The return type on capture logic seems odd... maybe have a separate Since the The |
Or maybe
I originally was going for perfectly matching the existing code, including the exact attributes. But I can also add
I considered that, but I like |
54bb987
to
5c39b29
Compare
I did the |
This comment has been minimized.
This comment has been minimized.
@bors try |
This comment was marked as outdated.
This comment was marked as outdated.
…<try> add const_eval_select macro to reduce redundancy I played around a bit with a macro to make const_eval_select invocations look a bit nicer and avoid repeating the argument lists. Here's what I got. What do you think? I didn't apply this everywhere yet because I wanted to gather feedback first. The second commit moves the macros from rust-lang#132542 into a more sensible place. It didn't seem worth its own PR and would conflict with this PR if done separately. Cc `@oli-obk` `@saethlin` `@tgross35` try-job: dist-aarch64-msvc
@saethlin was suggesting the compiler could just automatically |
On ARM64EC, a lot of stuff has to generate thunks, @dpaoliello explained it here: #131781 (comment) |
Yeah, but it's a pretty bad bug in that target if that means we have to add
We should only do that for this broken target though, since it could also have quite negative effects. |
Cranelift also needs it, and there are a handful of other targets that LLVM crashes on https://github.com/rust-lang/compiler-builtins/blob/e34429548a0d6a186264dd74fbfc24bd3dbef667/configure.rs#L63-L76. But yeah, it's not ideal. |
Okay so support for these types generally is still pretty poor in LLVM, not just for that one target. In other words, it's f16/f128 causing externalities here. In that case I agree, we should add some hacks to the compiler to make this more smooth for unrelated rustc development. |
08f5449
to
0f374e4
Compare
But also, why does this function even get codegen'd? It is const-only! Maybe we should just always make the const arm of const_eval_select |
also move internal const_panic helpers to a better location
0f374e4
to
613f53e
Compare
@bors try |
…<try> add const_eval_select macro to reduce redundancy I played around a bit with a macro to make const_eval_select invocations look a bit nicer and avoid repeating the argument lists. Here's what I got. What do you think? I didn't apply this everywhere yet because I wanted to gather feedback first. The second commit moves the macros from rust-lang#132542 into a more sensible place. It didn't seem worth its own PR and would conflict with this PR if done separately. Cc `@oli-obk` `@saethlin` `@tgross35` try-job: dist-aarch64-msvc
// so the end-to-end behavior is the same at compiletime and runtime. | ||
const_eval_select((v,), compiletime, runtime) | ||
}; | ||
); |
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.
This one makes me particularly happy. :) This is much nicer with the macro.
☀️ Try build successful - checks-actions |
All right, looks like this helped. :) @bors r=oli-obk |
I don't remember suggesting this, but all you'd need to do is add a check below this point:
tcx.types.f16 or tcx.types.f128 .
|
…r=oli-obk add const_eval_select macro to reduce redundancy I played around a bit with a macro to make const_eval_select invocations look a bit nicer and avoid repeating the argument lists. Here's what I got. What do you think? I didn't apply this everywhere yet because I wanted to gather feedback first. The second commit moves the macros from rust-lang#132542 into a more sensible place. It didn't seem worth its own PR and would conflict with this PR if done separately. Cc `@oli-obk` `@saethlin` `@tgross35` try-job: dist-aarch64-msvc
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#132259 (rustc_codegen_llvm: Add a new 'pc' option to branch-protection) - rust-lang#132409 (CI: switch 7 linux jobs to free runners) - rust-lang#132498 (Suggest fixing typos and let bindings at the same time) - rust-lang#132524 (chore(style): sync submodule exclusion list between tidy and rustfmt) - rust-lang#132567 (Properly suggest `E::assoc` when we encounter `E::Variant::assoc`) - rust-lang#132571 (add const_eval_select macro to reduce redundancy) - rust-lang#132637 (Do not filter empty lint passes & re-do CTFE pass) - rust-lang#132642 (Add documentation on `ast::Attribute`) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#132571 - RalfJung:const_eval_select_macro, r=oli-obk add const_eval_select macro to reduce redundancy I played around a bit with a macro to make const_eval_select invocations look a bit nicer and avoid repeating the argument lists. Here's what I got. What do you think? I didn't apply this everywhere yet because I wanted to gather feedback first. The second commit moves the macros from rust-lang#132542 into a more sensible place. It didn't seem worth its own PR and would conflict with this PR if done separately. Cc ``@oli-obk`` ``@saethlin`` ``@tgross35`` try-job: dist-aarch64-msvc
I played around a bit with a macro to make const_eval_select invocations look a bit nicer and avoid repeating the argument lists. Here's what I got. What do you think?
I didn't apply this everywhere yet because I wanted to gather feedback first.
The second commit moves the macros from #132542 into a more sensible place. It didn't seem worth its own PR and would conflict with this PR if done separately.
Cc @oli-obk @saethlin @tgross35
try-job: dist-aarch64-msvc