Skip to content

argument-less const fn do not get properly executed #1081

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

Closed
RalfJung opened this issue Nov 28, 2019 · 10 comments
Closed

argument-less const fn do not get properly executed #1081

RalfJung opened this issue Nov 28, 2019 · 10 comments
Labels
A-interpreter Area: affects the core interpreter C-bug Category: This is a bug. I-misses-UB Impact: makes Miri miss UB, i.e., a false negative (with default settings)

Comments

@RalfJung
Copy link
Member

With rust-lang/rust#66294 landed, argument-less const fn get memoized even when run in Miri. I am pretty sure that is wrong as they can (certainly through unsafe code, once that is allowed) have arbitrary side-effects.

Cc @davidhewitt @oli-obk

@RalfJung RalfJung added C-bug Category: This is a bug. A-interpreter Area: affects the core interpreter labels Nov 28, 2019
@RalfJung RalfJung changed the title const fn do not get properly executed argument-less const fn do not get properly executed Nov 28, 2019
@RalfJung RalfJung added the I-misses-UB Impact: makes Miri miss UB, i.e., a false negative (with default settings) label Nov 28, 2019
@oli-obk
Copy link
Contributor

oli-obk commented Nov 28, 2019

cc @Centril wrt side effects in const fn.

My stance is that it's UB to do side effects in const fn

@RalfJung
Copy link
Member Author

RalfJung commented Nov 28, 2019

Well right now, with "Miri unleashed", this bug means we miss UB. So whatever your stance is, we have to change something. If you don't like my proposal of restricting memoization to CTFE, please make another one.

@Centril
Copy link

Centril commented Nov 28, 2019

My stance is that it's UB to do side effects in const fn

I agree with that, at least until we say otherwise. :)

@RalfJung
Copy link
Member Author

My stance is that it's UB to do side effects in const fn

Given that Miri is all about detecting UB I don't see how that argument helps here at all?

The discussion of how to expand UB to incorporate const fn properties is a separate one, and IMO a serious proposal of that requires a demonstration that we can check this UB in Miri. But in no way can that be an argument for removing UB checks from Miri now before any decisions we even made.

@RalfJung
Copy link
Member Author

RalfJung commented Nov 28, 2019

My interpretation is that that PR landed because nobody realized that this would affect Miri as well, and we should revert its Miri effect ASAP before doing anything else. Then we can talk about expanding our UB and making Miri check it or whatever.

Is that not correct? If Miri behavior was deliberately changed by that PR I am surprised I did not get Cc'd. I'd prefer to be in the loop for such things.

@RalfJung RalfJung reopened this Nov 28, 2019
@oli-obk
Copy link
Contributor

oli-obk commented Nov 28, 2019

If Miri behavior was deliberately changed by that PR I am surprised I did not get Cc'd. I'd prefer to be in the loop for such things.

Sorry, I keep forgetting this. Not sure how to fix that except remind myself regularly of it. I'll strive to do better.

My interpretation is that that PR landed because nobody realized that this would affect Miri as well, and we should revert its Miri effect ASAP before doing anything else.

I now see that I did not realize

Given that Miri is all about detecting UB I don't see how that argument helps here at all?

The change is actually a language change now, because it only looks at the result of a const eval and not at the intermediate computation. For const eval that's not a problem, so I'll make a PR allowing miri to still run the function

@RalfJung
Copy link
Member Author

The change is actually a language change now, because it only looks at the result of a const eval and not at the intermediate computation.

A language change in Miri, you mean? Yes, that's why I raised this issue.
We don't also use the memoized result during codegen, do we? Certainly with function pointers that seems hard.

so I'll make a PR allowing miri to still run the function

Thanks!

@oli-obk
Copy link
Contributor

oli-obk commented Nov 28, 2019

We don't also use the memoized result during codegen, do we? Certainly with function pointers that seems hard.

No, but in the future MIR optimizations may optimize out such function calls and just put their result into the MIR

@RalfJung
Copy link
Member Author

in the future MIR optimizations may optimize out such function calls and just put their result into the MIR

That is a language change requiring some new UB though (at least when considering Rust with Miri unleashed) -- so I hope we don't do this before we can detect such UB.

@RalfJung
Copy link
Member Author

RalfJung commented Dec 6, 2019

Fixed by rust-lang/rust#66866

@RalfJung RalfJung closed this as completed Dec 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-interpreter Area: affects the core interpreter C-bug Category: This is a bug. I-misses-UB Impact: makes Miri miss UB, i.e., a false negative (with default settings)
Projects
None yet
Development

No branches or pull requests

3 participants