-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
introduce @FieldEnum
and use it for the operand type of builtins that accept a field name
#23618
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
Comments
Would this apply to |
Question: how does this apply to Also, just want to point out, with one of the main purposes of |
Wouldn't this disallow doing wacky things with constructing wanted field programmatically. |
#3839 proposes to split decl access into its own builtin The only 2 benefits I see to this proposal (assuming it only applies to builtins on
|
I assume that you would still be able to do |
Did a quick look through of code I've written checking usages of the proposed changed builtins for new problems, and noted only one concern: |
I think introducing |
The biggest benefit here is grepability. Consider finding all usages of field This argument requires an assumption that most meta usages don't construct field names by string concatenation, but rather specify it as a specific string at the call-site, and then thread through several abstraction layers: // Call site:
do_some_magic("foo");
// 6 functions down:
const field_value = @field(t, field_name); // field_name is "foo" here. But I think this is generally true, there seems to be Pareto-thing going on here --- 80% usages are non-meta, and among the meta usages, 80% does not do string concatenation. The second, minor, benefit here is that library abstractions already use field enums. In MultiArrayList, we write |
I think I understand your point, I've just never myself come into the situation you describe. My most common uses of Besides that, there are two types of uses that code wants to achieve, which the proposal doesn't fundamentally affect in any way:
The status-quo translation enum -> string is Actually, having a builtin |
std.meta.FieldEnum
already exists for this purpose.This proposal is to promote such functionality to a builtin and use it as the field parameter type for these functions rather than
[]const u8
:@field
@fieldParentPtr
@offsetOf
@bitOffsetOf
@unionInit
@FieldType
🔽
The text was updated successfully, but these errors were encountered: