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

extern enums are unsafe #3991

Closed
LemonBoy opened this issue Dec 28, 2019 · 2 comments
Closed

extern enums are unsafe #3991

LemonBoy opened this issue Dec 28, 2019 · 2 comments
Labels
bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend.
Milestone

Comments

@LemonBoy
Copy link
Contributor

  • @intToEnum disables all the safety checks for extern unions, it should just de-duplicate the entries and validate the input data anyway.
  • @tagName produces invalid LLVM IR, eg:
broken LLVM module found: Duplicate integer as switch case
  switch i32 %0, label %BadValue [
    i32 1, label %Name
    i32 1, label %Name1
  ]
@andrewrk andrewrk added this to the 0.6.0 milestone Dec 31, 2019
@andrewrk andrewrk added bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend. labels Dec 31, 2019
@andrewrk
Copy link
Member

@intToEnum disables all the safety checks for extern unions, it should just de-duplicate the entries and validate the input data anyway.

One of the accepted proposals was to allow extern enums to contain values that don't map to any particular tags. Idea being that they are non-exhaustive, and have the ABI size of the underlying integer tag type. This allows using extern enums in an ABI, and adding items later while remaining backwards-compatible.

Happy to reconsider this if you are thinking of a potential issue with it?

The broken switch thing is clearly a bug. I propose to resolve it by having the first tag name in declaration order be the canonical name.

@s-ol
Copy link
Contributor

s-ol commented Jan 25, 2020

I'm suddenly hitting the error that leads to this issue, and there is no traceback so I'm not sure what I shouldn't be doing:

/usr/lib/zig/std/fmt.zig:372:31: error: TODO @tagName on non-exhaustive enum https://github.com/ziglang/zig/issues/3991
            return formatType(@tagName(value), "", options, context, Errors, output, max_depth);

(this being a TODO is okay I guess, but it would be great if it left a full stack trace at least)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants