Skip to content

Static assert idiom compiles very slowly for certain values #77891

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

Closed
thomcc opened this issue Oct 13, 2020 · 2 comments
Closed

Static assert idiom compiles very slowly for certain values #77891

thomcc opened this issue Oct 13, 2020 · 2 comments
Labels
C-bug Category: This is a bug.

Comments

@thomcc
Copy link
Member

thomcc commented Oct 13, 2020

I wrote the following code in a small project to help assert constant integers are equivalent. There are other ways to write this test but this tells me the values on failure.

macro_rules! static_assert_ints_eq {
    ($a:expr, $b:expr) => {
        // todo: enforce that args are reasonable integers
        const _: [(); $a as usize] = [(); $b as usize];
    };
}

Later, I called it in a manner where the values were equal but negative. They were the result of a const function, but something like this is equivalent:

static_assert_ints_eq!(-1i32, -1i32);

I expected this to be relatively cheap for rustc — I was hoping that the const _: indicates that I'm just looking for a type check.

Unfortunately, I had to kill the compiler because it was taking too long. I imagine there's a bug somewhere for this but could not find it, but if not, this can be that bug.

Meta

rustc --version --verbose:

rustc 1.49.0-nightly (38d911dfc 2020-10-09)
binary: rustc
commit-hash: 38d911dfc55a7a1eea1c80139113ed2ff0151087
commit-date: 2020-10-09
host: x86_64-apple-darwin
release: 1.49.0-nightly
LLVM version: 11.0
@thomcc thomcc added the C-bug Category: This is a bug. label Oct 13, 2020
@thomcc
Copy link
Member Author

thomcc commented Oct 13, 2020

Note: I'm aware of several other ways to write this that are better along various metrics — that's not my point. My point is that this way (which is somewhat common) does poorly.

@jonas-schievink
Copy link
Contributor

Duplicate of #68010

@jonas-schievink jonas-schievink marked this as a duplicate of #68010 Oct 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants