Skip to content

Update definition of UB in the glossary #203

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
wants to merge 9 commits into from
Closed

Update definition of UB in the glossary #203

wants to merge 9 commits into from

Conversation

gnzlbg
Copy link
Contributor

@gnzlbg gnzlbg commented Sep 11, 2019

Partially addresses #202 .

@gnzlbg gnzlbg requested a review from RalfJung September 11, 2019 19:00
@hanna-kruppe
Copy link

I don't understand why you rewrote the entire glossary entry. Most of the diff isn't relevant to #202 nor otherwise a clear improvement (in some ways it's actually worse than the current wording, I think). The only real additions seems to be concentrated the last two paragraph (UB not being forever and the more expansive description of what a compiler may do with a program that has UB). So, why not just add those points to the existing text instead of rewriting everything?

@gnzlbg
Copy link
Contributor Author

gnzlbg commented Sep 12, 2019

So, why not just add those points to the existing text instead of rewriting everything?

I tried, but I wasn't able to add the clarification to the current definition because it does not precisely say what undefined behavior is.


A list of behavior considered undefined is available in the [Rust Language Reference](https://doc.rust-lang.org/reference/behavior-considered-undefined.html).

> **Note:** In practice, UB is a contract between the Rust source code and the implementation.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation of what? I think this is your C++ standard mode showing. ;)

I find "compiler" much more understandable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe. Is it only the compiler ? It is also a contract with the implementation of the abstract machine (e.g. miri, the hardware, etc.).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so far in the UCG documents we have always talked about "the compiler"?
I agree the proper spec might have to be more careful with terminology. But we should be consistent at least. So probably best to keep saying "the compiler" and file an issue to maybe s/compiler/Rust implementation/ or so?


Rust requires that *safe* Rust is not able to exhibit *undefined behavior* (see [soundness][soundness]). It is up to the implementation and `unsafe` Rust code to ensure that this is the case.

A list of behavior considered undefined is available in the [Rust Language Reference](https://doc.rust-lang.org/reference/behavior-considered-undefined.html).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep the Nomicon link, I think it is useful to read this in both styles.

As long as both lists exist, I think we should link them both here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently the Nomicon link is way outdated. I'll keep both links, but maybe the nomicon should be updated to just refer to the language reference at some point.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just (over the last few weeks) updated both of them, and the lists should actually be in sync. Why do you say it is outdated?

maybe the nomicon should be updated to just refer to the language reference at some point.

Agreed, but for now this is the situation we got.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just (over the last few weeks) updated both of them, and the lists should actually be in sync. Why do you say it is outdated?

I didn't realize that the nomicon PR was already merged.

> It can also do something different every time.
>
> It is backward compatible to change the specification from making no guarantees (UB) to guaranteeing something (not UB).
> That is, Rust source code is not allowed to rely on UB being UB forever.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is that part just a "note"?

@gnzlbg
Copy link
Contributor Author

gnzlbg commented Oct 17, 2019

@rkruppe @RalfJung is this better ?

@RalfJung
Copy link
Member

RalfJung commented Oct 18, 2019 via email

@gnzlbg
Copy link
Contributor Author

gnzlbg commented Oct 18, 2019

No, i'm going to try to come up with a way to explain the two different types of UB that are discussed there.

@RalfJung
Copy link
Member

While thinking about this I came up with the following introduction, which I think is a nice starting point:

The Rust compiler guarantees correct compilation only under certain assumptions that must be satisfied by the programmer. Any violation of these assumptions is called Undefined Behavior.

@RalfJung
Copy link
Member

RalfJung commented Jul 7, 2022

Closing due to inactivity, though updating this definition along the lines of #202 (comment) is probably still a good idea.

@RalfJung RalfJung closed this Jul 7, 2022
@RalfJung RalfJung deleted the ub0 branch August 19, 2023 21:33
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

Successfully merging this pull request may close these issues.

3 participants