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

@tagName handles specified enum values incorrectly #976

Closed
andrewrk opened this Issue May 3, 2018 · 2 comments

Comments

Projects
None yet
3 participants
@andrewrk
Member

andrewrk commented May 3, 2018

const std = @import("std");

const Foo = enum {
    A = 1,
    B = 0,
};
test "aoeu" {
    var b = Foo.B;
    std.debug.assert(std.mem.eql(u8, @tagName(b), "B")); // assertion failure
}

If you run the test at comptime it (correctly) passes.

This asks the question, what should we do for sparse values? If A = 0 and B = 999999 then it does not really make sense to do a table lookup for the tag name. But if A = 0 and B = 2 then it probably does. I suppose a heuristic is needed to determine whether a table or sparse set (with if-else checks), or some combination of both is best for the implementation of @tagName.

@eduardosm

This comment has been minimized.

Contributor

eduardosm commented May 21, 2018

Why not implement it as a switch and let LLVM optimize it?

@Hejsil

This comment has been minimized.

Member

Hejsil commented May 25, 2018

It seems clang 6.0.0 optimizes switches and nested ifs into table lookups.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment