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

Renaming @xtoy to @YfromX #16046

Merged
merged 3 commits into from
Jun 20, 2023
Merged

Renaming @xtoy to @YfromX #16046

merged 3 commits into from
Jun 20, 2023

Conversation

BratishkaErik
Copy link
Contributor

@BratishkaErik BratishkaErik commented Jun 15, 2023

I apologize in advance for such huge breaking changes.
"zig fmt" automatically renames @xToY to @yFromX, but you can also invoke simple sed stuff like:

sed -i 's/@ptrToInt/@intFromPtr/g' whatever.zig

Also renames std.meta.intToEnum to std.meta.enumFromInt, for simmetry. See also #15580 dropped on @andrewrk 's request.
Closes #6128.

@BratishkaErik
Copy link
Contributor Author

BratishkaErik commented Jun 15, 2023

eh new conflict right before

@matu3ba
Copy link
Contributor

matu3ba commented Jun 15, 2023

eh new conflict right before

Yeah, such things are abit of a bummer: #14186 #14726.

@BratishkaErik
Copy link
Contributor Author

It's green! And second conflict

Copy link
Member

@andrewrk andrewrk left a comment

Choose a reason for hiding this comment

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

Also renames std.meta.intToEnum to std.meta.enumFromInt, for simmetry. See also #15580.

Can you please omit this change from the patch? This way, this will be a breaking change, but one that can be completely migrated using zig fmt. Let's handle intToEnum separately please (same logic from the linked issue applies here with regards to 1 break and not 2).

Other than this, I think this is a good time to make this breaking change. Thanks!

@BratishkaErik
Copy link
Contributor Author

BratishkaErik commented Jun 18, 2023

Thinking about it:

  1. IMHO it makes source code skimming and reading easier due to:
    • reasons from original issue
    • fact that "most of the builtins starting with a name of type returns this type": @intFrom* and @intCast all returns some integer, @ptrFromInt and @ptrCast both returns some pointer etc. (except @err* since it has @errorName which returns a string representation):
// It is a strange example but anyway.
const suitable_universe = (@intFromEnum(player1.universe) +| 2) == (@intFromEnum(player2.universe) -| 3);
// No need to read full line, at this point already know that "a" and b are some float
// const a = @float???
// const b = @float???
//           ^^^^^^
const a = @floatFromInt(f32, @intFromBool(suitable_universe));
const b = @floatCast(f64, a * 2);

// Old version:
const a = @intToFloat(f32, @boolToInt(suitable_universe));
const b = @floatCast(f64, a * 2);
  1. But it makes writing this code harder:
// Previously, you could've start writing your code by doing smth like this:
// const a = @intTo???(!!!, 1024);
// const a = @intTo
// It gives you some time to warmup and to think "what type do I want to get?",
// also, editor (most? of them) helps you to choose from auto-completion list.

// Now, you need to choose "output" type right at the beginning,
// and this action slows you down a bit.
// IDK if editors help you to auto-complete function from the end,
// I never used that option.
// Same when you edit this line to change "output" type again.
const a = @floatFromInt(f32, 1024);

// This does not affect "@intCast" and similar builtins,
// since one chooses them when both types are of same "family".

@andrewrk
Copy link
Member

Please note also #5909 which is accepted and affects your examples above.

Regarding reading vs writing, the Zig language is all about reading and not writing, so there is an easy answer to this question. Reading wins.

However, if you are not personally in favor of this change, then please don't force yourself to do it.

@BratishkaErik
Copy link
Contributor Author

Please note also #5909 which is accepted and affects your examples above.

Regarding reading vs writing, the Zig language is all about reading and not writing, so there is an easy answer to this question. Reading wins.

However, if you are not personally in favor of this change, then please don't force yourself to do it.

Well, I am in favor of this change, it was just "for your information" to see if you'd change your mind (and I would not mind, it was a little effort with rename-and-test), and I'm looking ahead for merging :)

@andrewrk andrewrk enabled auto-merge June 19, 2023 05:08
@andrewrk
Copy link
Member

andrewrk commented Jun 19, 2023

Thwarted again! Let's try another run.

(I am taking care of it)

Note from Andrew: I re-ran update-zig1 on my pc and replaced this
commit.

Signed-off-by: Eric Joldasov <[email protected]>
Signed-off-by: Andrew Kelley <[email protected]>
@andrewrk andrewrk merged commit a72d634 into ziglang:master Jun 20, 2023
10 checks passed
@BratishkaErik BratishkaErik deleted the issue-6128 branch June 20, 2023 08:59
@BratishkaErik
Copy link
Contributor Author

Thwarted again! Let's try another run.

(I am taking care of it)

Thanks again! Was it because of security reasons (zig1.wasm update that is initiated by non-core team member)?

@andrewrk
Copy link
Member

It was yet another conflict that occurred while the CI was running

linusg added a commit to linusg/zig-libgc that referenced this pull request Jun 22, 2023
joachimschmidt557 pushed a commit to joachimschmidt557/linenoize that referenced this pull request Jun 27, 2023
* Update renamed builtins

See: ziglang/zig#16046

* Update builtins to infer target type

See: ziglang/zig#16163
Spadi0 added a commit to Spadi0/zig-toml that referenced this pull request Jul 3, 2023
The relevant changes are in these two PRs: ziglang/zig#16046 and
ziglang/zig#16163. They change the cast builtins to infer the result
type and change the order of the conversion builtins to `@xFromY`
instead of `@yToX`.
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.

Ergonomics: Rename various XtoY functions to YfromX
3 participants