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
type foo = struct is unfamiliar #735
Comments
I don't think there are any downsides to this; it seems free. |
FWIW it's rather similar to |
Currently the only place a struct_decl may appear is as the right-hand-side of a type-alias. A couple of questions:
|
I don't think it's particularly important. How about this:
The usage of this, even in C code, is so rare, that I don't think this complexity is worth it. While we were working on WSL, one of the places where we benefitted from simplicity was the fact that all types were guaranteed by the grammar to be defined at the top level, so we didn't have to worry about scoping of types. All the types "lived forever" so we didn't have to do any magic when we inlined or outlined functions. I think, at least for now, the value of being able to do this in a compiler outweighs the value authors can (but rarely do!) get from anonymous structs.
Of course. |
How would anonymous structs go out of scope? Since they have no name, and names are what's scoped, anonymous structs have no scope. In order to be able to use anonymous types at all, you have to have a concept of type equivalence ("this |
Another thought: anonymous structs are actually useful in C. They're most frequently used in unions, I think, but also appear in nested structs: struct X {
int length;
struct {
int x;
int y;
} points[MAX_LENGTH];
}; |
All the member names were entered into the scope instead, and that's what will then go out of scope. Anonymous structs introduce complexities into tool chains, and possible ambiguities depending on name hiding rules:
Will you do hiding here or give an error? Like, does the "non-name" of the struct avoid the name collision or not? I think this is just sugar that adds complexity and recommend staying explicit. |
I didn't realize that would cause a collision, and I don't totally understand it. But I don't need to. In any case, definitely fine with me to leave anonymous structs out. |
Discussed at the 2020-06-02 meeting. |
Discussed at the 2020-06-09 meeting. |
Resolved: Accept the proposal |
This CL removes the requirement for a struct to be the RHS of a `type` statement and, instead, allows an IDENT to be provided in the struct declaration. The struct is still required to be defined in the module scope. The [[block]] attribute remains on the LHS of the struct_decl. ``` [[block]] struct A { [[offset 0]] b : f32; } ``` Fixes #735
We should consider changing
type foo = struct
tostruct foo
instead. This is just as expressive, but more familiar to authors.The text was updated successfully, but these errors were encountered: