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

[intro.progress] Does p1 conditionally introduce a kind of undefined behavior? #5377

Closed
frederick-vs-ja opened this issue Apr 1, 2022 · 7 comments

Comments

@frederick-vs-ja
Copy link
Contributor

It's unspecified whether the implementation makes assumptions in [intro.progress]/1, and it seems that if the execution violates any of these assumptions, the behavior is undefined.

However, it's not clear whether the behavior is still undefined if the implementation chooses not to make such assumptions. IMO the current wording is a bit strange, as it doesn't directly specify a kind of UB, from which the allowance of assumptions can be deduced.

@jensmaurer
Copy link
Member

Looks like this should be phrased as "A thread that does not eventually do one of the following ... has undefined behavior."

@FrankHB
Copy link
Contributor

FrankHB commented Feb 10, 2023

It's underspecified that how can a permissive rule can lead to undefined behavior, but it should be clear that in current wording there is no UB in [intro.progress]/1, whether the permission of having such assumption is actually used by the implementation.

The wording looks bad because the process of reasoning is not clear, so there is room to improve, definitely. However, whether we need [intro.progress] to imply such UB is another question. Simply specifying it UB is too hurry, and it is definitely not editorial.

I don't like the idea of the the non-editorial change (to add UB here) for various reasons:

  • It turns a normatively well-defined case to undefined before it is widely adopted by implementations.
  • It is error-prone. It is quite unintuitive to prevent the UB in real programs for average users. Even if the loop elimination can be also unexpected, it is still far easier to debug (e.g. to locate the wrong code) compared to the cases like invoking unrelated code.
  • There are alternative manners to introduce the UB available to the optimizer, with better readability, e.g. by attributes.

So the change would just make the language less expressive (by reducing a well-defined way to get previously controllable unspecified behavior), and it will encourage non-idiomatic and fragmented coding styles to get chances of optimization in a way that difficult to use and difficult to teach. Such direction is quite suspicous, whatever the original intent of the current rules is.

@jfbastien
Copy link
Contributor

Im writing a paper to address this.

@frederick-vs-ja
Copy link
Contributor Author

frederick-vs-ja commented Mar 21, 2023

Im writing a paper to address this.

Oh... P2809R0 has addressed cases for trivial infinity loops. However, if I understood currectly, the paper hasn't address the issue whether [intro.progress]/1 introduces some kind of UB. When an infinity loop is non-trivial but doesn't contain an execution step, the original concern still exists.


There seems another issue:

Once a thread has done one of the operations in [intro.progress]/1 other than termination, can we claimed that the assumption has been met, and hence the validity of the rest of execution will no longer be affected by [intro.progress]/1?

If so, transformations of possibly infinity loops can only be performed in extremely restricted cases, which seems unintended.

@jensmaurer
Copy link
Member

P2809R0 has addressed cases for trivial infinity loops.

P2809R0 has not yet been approved by the committee, and it's not obvious its approach will achieve consensus.

@jfbastien
Copy link
Contributor

I recommend closing this issue in favor of cplusplus/papers#1496

@frederick-vs-ja
Copy link
Contributor Author

Well, P2809R2 still fails to whether clarify such allowance of assumption is specifying some kind of UB.

IIUC, the wording changes are still orthogonal to the original concerns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants