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

Unify and fix the checks for zirDiv*() #22776

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

tau-dev
Copy link
Contributor

@tau-dev tau-dev commented Feb 5, 2025

Close #22749, close #22748, close #21198, complete the "if the RHS is one, return the LHS directly" TODOs, fix a crash on intvec{undefined} / intvec{-1} and fix some compile errors:

  • @divExact should not cause a compile error for integer undefined lhs and runtime-known rhs, because execution is completely legal when rhs == 1, and the policy on other operations has so far been to only have a compile error when illegal behavior is guaranteed to happen.
  • Compile errors for float division by zero make little sense given that they are perfectly well-defined IEEE operations. The comments suggest that this was possibly made illegal intentionally, maybe in service of explicitness / "only way to do things" (so you have to use math.inf / math.nan) or as a step towards Disallow NaN and inf for comptime_float #21205. But in general, it that behavior would contradict the principle that comptime operations behave like runtime, and would add annoying special-cases to some comptime calculations. The @...Div() intrins allowed only floating-point zero divided by zero, which should be, if anything, more ill-defined than any other division by zero, and probably shouldn't result in zero.

Close ziglang#22749, close ziglang#22748, complete the "if the RHS is one, return the
LHS directly" TODOs, fix a crash on `intvec{undefined} / intvec{-1}` and
fix some compile errors:

* @divExact should not cause a compile error for integer undefined lhs
  and runtime-known rhs, because execution is completely legal when
  rhs == 1, and the policy on other operations has so far been to only
  error if illegal behavior is guaranteed to happen.
* Compile errors for float division by zero make little sense given that
  they are perfectly well-defined IEEE operations. The comments suggest
  that this was possibly made illegal intentionally, maybe in service of
  explicitness / "only way to do things" (so you have to use math.inf /
  math.nan), but that would contradict the general principle that
  comptime operations behave like runtime, and would add annoying
  special-cases to some comptime calculations.
  The @...Div() intrins allowed only *floating-point zero divided by
  zero*, which should be, if anything, *more* ill-defined any other
  division by zero, and probably shouldn't result in zero.
@tau-dev tau-dev changed the title Unify and fix the checks for @zirDiv*() Unify and fix the checks for zirDiv*() Feb 5, 2025
comptime_floats shall not be inf or nan.
They don't even reproduce on the build machine.
@tau-dev
Copy link
Contributor Author

tau-dev commented Feb 8, 2025

I also have a patch to implement the rest of #21205 (comment), should I add that here or make a separate PR?

@mlugg
Copy link
Member

mlugg commented Feb 20, 2025

I'm in the process of a big overhaul to arithmetic handling which will supersede this PR and probably a few others; sorry.

@tau-dev
Copy link
Contributor Author

tau-dev commented Feb 21, 2025

I'm in the process of a big overhaul to arithmetic handling which will supersede this PR and probably a few others; sorry.

How can contributors avoid this kind of situation?

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