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

run non-const Display/Debug impls for const panic message #86364

Open
oli-obk opened this issue Jun 16, 2021 · 5 comments
Open

run non-const Display/Debug impls for const panic message #86364

oli-obk opened this issue Jun 16, 2021 · 5 comments
Labels
A-const-eval Area: constant evaluation (mir interpretation) A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@oli-obk
Copy link
Contributor

oli-obk commented Jun 16, 2021

Given that the CTFE core engine already supports the entire display machinery (demonstrated by the fact that it works in Miri), we might alternatively poke a small hole into the const checks that allows executing formatting machinery from panic_fmt only -- something like "miri unleashed", but more targeted.

Originally posted by @RalfJung in #78356 (comment)

Basically the same rationale as allowing -> _ return types in the parser, to get a better error later. In this case, when you use panic!() in CTFE, you are going to fail the build anyway, so we can just as well run something that may fail to get evaluated because it does something horribly unconst.

The only problem is that then const fn can execute non-const code at runtime during the panic machinery and before actually panicking, which may not be desirable.

@RalfJung
Copy link
Member

My thinking was that we'd still have some heavy checks on the code format_args! expands to inside const fn to ensure that it does not run user-defined Display/Debug -- basically, we can just have a list of types that are permitted here, and reject the rest.
So, Arguments::new_v1 would only be allowed under some very special conditions inside const fn.

(This can theoretically be side-stepped with transmute, but whoever does that really can't expect any kind of guarantees^^.)

@oli-obk oli-obk added A-const-eval Area: constant evaluation (mir interpretation) A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. A-diagnostics Area: Messages for errors, warnings, and lints labels Jun 16, 2021
@Aaron1011
Copy link
Member

In this case, when you use panic!() in CTFE, you are going to fail the build anyway, so we can just as well run something that may fail to get evaluated because it does something horribly unconst.

This is only true because we don't currently support const catch_unwind (and const unwinding is only implemented in Miri, not the CTFE). If we ever decided to support const catch_unwind, then we would need to make catching an 'unconst panic' into a hard error.

@oli-obk
Copy link
Contributor Author

oli-obk commented Jun 16, 2021

True, but I personally believe we should never support that. It's not really something that is useful in CTFE. Catching panics is solely there to prevent running across FFI boundaries or to create somewhat isolated units like threads or e.g. tabs or tasks in applications. CTFE is already perfectly isolated, and since there is no unwinding, there's no problem with FFI boundaries either. There's also no resources that need to be freed, as the entire evaluator is freed after every (successful or not) evaluation, including the entire virtual memory (modulo some things like vtables).

@Noratrieb Noratrieb added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 5, 2023
@oli-obk
Copy link
Contributor Author

oli-obk commented Sep 18, 2024

Almost finished impl that can probably be revived: #90488

@RalfJung
Copy link
Member

RalfJung commented Sep 18, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: constant evaluation (mir interpretation) A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants