Skip to content

replace @Type with individual type-creating builtins #23733

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

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

Conversation

alichraghi
Copy link
Contributor

@alichraghi alichraghi commented Apr 30, 2025

Closes #10710

I updated zig1.wasm in first commit to ensure the CI is passing. once ready, one of the core team members can handle updating it.

I also didn't add @Array because as @Hejsil pointed out, it can be implemented in a single line of user-land code.

if (sentinel) |sen| [size:sen]T else [size]T

Same goes for @Float. std.meta.Float() is no longer a wrapper of @Type.

@alichraghi alichraghi force-pushed the bp branch 2 times, most recently from 687062e to c7bb559 Compare April 30, 2025 18:03
@SoundOfScooting
Copy link

Although it was not listed in the issue, would it be reasonable to add @Fn as well?

@nitrogenez
Copy link

Seems like a good change. I like it. Though, is it necessary to remove @Type altogether? Can't these builtins co-exist? Or is there some deep technical reason they can't?

@linusg
Copy link
Collaborator

linusg commented May 6, 2025

Though, is it necessary to remove @Type altogether?

"Only one obvious way to do things."

@nitrogenez
Copy link

"Only one obvious way to do things."

Oh, yeah. That makes sense. Thanks. Then, I don't see why this change can't be accepted. Seems pretty useful and straightforward.

@tauoverpi
Copy link
Contributor

Does @Struct(..), @Union(..), and @Enum(..) really need to use the Type.{Struct, Union, Enum} types or is this for it being easier to use with the result of @typeInfo(..)?

Each of the fields of those are of different types thus @Struct(.@"extern", fields, .@"struct") would better match what the use is today (I've omitted the .decl field as it's always empty anyway) or just @Struct(.@"extern", fields) and @Tuple(fields) as even if they share syntax and representation in the compiler they aren't the same from the user's view of the language. The same applies to @Union(.@"auto", E, fields)/@Union(.@"extern", null, fields) and @Enum(fields, .sparse)/@Enum(fields, .exhaustive).

It's not possible to pass the wrong type for any of those and if the bools were instead changed to enum it would communicate what the parameters are sufficiently enough not to need the Type.{..} struct.

@mlugg
Copy link
Member

mlugg commented Jun 3, 2025

Someone asked me about the status of this PR, so just commenting to say that I'm aware of it, and appreciate the effort that went into it -- I'd definitely like to avoid letting this work rot. I'll hopefully get to it soon, but we have some huge changes currently in the pipeline, so the team's all a little busy right now, and it's not a great time to merge big breaking PRs. I'm hoping I'll be able to have a look at this once the reader/writer changes, and codegen pipeline changes, are all in, and everything's settling down a little.

No need to worry about rebasing or anything, I will probably be happy to resolve conflicts when I get around to reviewing this.

One note: I am firmly of the opinion that there should be an @EnumLiteral(), rather than relying on @TypeOf(.enum_literal). That said, I can make that change on top of this PR myself fairly easily when I review it.

By the way, @alichraghi: were the usages of @Type all updated by hand, or did you semi-automate the process? Knowing this will probably help the review process when the time comes.

@alichraghi
Copy link
Contributor Author

Yeah i figured that this is gonna take long and im fine with handling conflicts myself. was mostly waiting for writergate branch to be merged.

were the usages of @Type all updated by hand, or did you semi-automate the process? Knowing this will probably help the review process when the time comes.

They are updated by hand but it wasn't painful because most new builtins accept the same std.builtin.Type parameters.

@alichraghi alichraghi force-pushed the bp branch 2 times, most recently from 3d17739 to 9a324c7 Compare June 15, 2025 09:06
@mlugg mlugg added breaking Implementing this issue could cause existing code to no longer compile or have different behavior. release notes This PR should be mentioned in the release notes. labels Jul 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Implementing this issue could cause existing code to no longer compile or have different behavior. release notes This PR should be mentioned in the release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

remove @Type from the language, replacing it with individual type-creating builtins
6 participants