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

terminology update: use the phrase "detectable illegal behavior" rather than "safety-checked undefined behavior" #2402

Open
andrewrk opened this issue May 1, 2019 · 3 comments
Labels
accepted This proposal is planned. docs proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
Milestone

Comments

@andrewrk
Copy link
Member

andrewrk commented May 1, 2019

The language reference makes use of the phrase "safety-checked undefined behavior" to mean "that which is undefined behavior in ReleaseFast and ReleaseSmall modes but will panic in Debug and ReleaseSafe modes".

This is a bit problematic because in the safe build modes, it's actually completely well-defined behavior. It will call the panic handler. Further, it will cause confusion because many people see "undefined behavior" and think it's a weakness of the language, when really it's the opposite - e.g. catching integer overflow bugs wouldn't be possible if it were always defined to be two's complement wraparound arithmetic.

I think a better phrase would be "illegal behavior". Illegal Behavior is always Undefined Behavior in the unsafe build modes. Illegal behavior at compile time is always a compile error. In safe build modes, runtime safety checks attempt to detect illegal behavior, but not all kinds of illegal behavior can be detected. Detected illegal behavior is well-defined and calls the panic handler. Undetected illegal behavior is undefined behavior, even in the safe build modes.

Instead of "safety-checked undefined behavior" the docs would say "detectable illegal behavior".

Related: #1966 #2301

@andrewrk andrewrk added proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. docs labels May 1, 2019
@andrewrk andrewrk added this to the 0.5.0 milestone May 1, 2019
@andrewrk andrewrk added the accepted This proposal is planned. label May 3, 2019
@Paul-Andre
Copy link

I'd use some other word instead of behavior to distinguish what you're asking the program to do and what it actually does. Perhaps "illegal operation" (an illegal operation causes undefined behavior).

@matklad
Copy link
Contributor

matklad commented Apr 3, 2023

Another language lawering argument for this: even if a hypothetical future alternative implementation of Zig defines some of these behaviors, we still want to declare them to be incorrect, and any program making use of them buggy.

@andrewrk andrewrk modified the milestones: 0.11.0, 0.12.0 Apr 9, 2023
@matklad
Copy link
Contributor

matklad commented Jun 5, 2023

the docs would say "detectable illegal behavior".

This is splitting hairs and I am not at all feeling strongly, but maybe just "checked illegal behavior"?

  • It is simple
  • It is more precise. detectable leaves the possibility open that the behavior isn't actually detected, while checked implies that it is always defined to trap (in release safe).

@andrewrk andrewrk modified the milestones: 0.13.0, 0.12.0 Jun 29, 2023
andrewrk added a commit that referenced this issue Jan 19, 2024
andrewrk added a commit that referenced this issue Jan 19, 2024
bilaliscarioth pushed a commit to bilaliscarioth/zig that referenced this issue Jan 27, 2024
Rexicon226 pushed a commit to Rexicon226/zig that referenced this issue Apr 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted This proposal is planned. docs proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
Safety
  
To do
Development

No branches or pull requests

3 participants