-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
make decl literals work with single item pointers #21390
Conversation
Looks good, would you mind expanding the test cases to also test with a function call decl literal? |
d0de057
to
8c70230
Compare
src/Sema.zig
Outdated
@@ -8992,6 +8992,7 @@ fn zirDeclLiteral(sema: *Sema, block: *Block, inst: Zir.Inst.Index, do_coerce: b | |||
while (true) switch (ty.zigTypeTag(zcu)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't new to this PR, but since this is done in a loop it looks like you can wrap a type in an arbitrary level of error unions/optionals/pointers and still use them with decl literals.
In fact the master branch compiles the following just fine right now 🤔
const S = struct {
const init: anyerror!anyerror!????S = .{};
};
test {
const s: ????S = try try .init;
_ = s;
}
All 1 tests passed.
@mlugg Is this intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while it definitely allows some pretty silly stuff like your example i think its necessary, imagine something like fn init() !?*S {
, i dont see any reason this shouldnt work and limiting it would seem arbitrary and potentially pretty complex to get right
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be more fruitful to discuss it in the linked proposal, but as a suggestion I think restricting it to something like the following would make sense:
T
?T
*qual T
?*qual T
[*c]qual T
E!T
E!?T
E!*qual T
E!?*qual T
E![*c]qual T
All but the last 4 are supported as the first parameters in methods/member functions. If we could make the set of types that can participate in decl literals identical to the set that can participate in the method syntax it would make the rules nice and consistent and easy to reason about.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is intentional, and I don't think there's any reason to change it -- many RLS things (such as casting builtins) already strip error unions and optionals from types in a loop (i.e. const y: ???u32 = @intCast(@as(u64, 123))
is fine). Regardless, if you'd like to propose this, please discuss it either in the original proposal or in a new issue.
Looks like you're hitting CI failures from some self-hosted backends not liking these tests. They'll have to be skipped; see any other |
Line 4568 in b95e0e0
looks like wasm is only a TODO on zero sized types so we're good there |
guessing #21393 is gonna conflict, fine if i wait for that before pushing again? |
I'll fix the RISC-V backend TODO in an hour. |
8c70230
to
ba5ec67
Compare
da9b5fd
to
bc16143
Compare
@mlugg please feel free to merge this when you feel it is ready |
make decl literals work with single item pointers
closes #21387
also added test coverage for optionals