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

Both operands to ICmp instruction are not of the same type! #2149

Closed
jruderman opened this issue Apr 7, 2012 · 4 comments
Closed

Both operands to ICmp instruction are not of the same type! #2149

jruderman opened this issue Apr 7, 2012 · 4 comments
Labels
A-codegen Area: Code generation

Comments

@jruderman
Copy link
Contributor

iface monad<A> {
    fn bind<B>(fn(A) -> self<B>);
}
impl monad<A> of monad<A> for [A] {
    fn bind<B>(f: fn(A) -> [B]) {
        let mut r = fail;
        for self.each {|elt| r += f(elt); }
    }
}
fn main() {
    ["hi"].bind {|x| [x] };
}

rustc fails with:

Assertion failed: (getOperand(0)->getType() == getOperand(1)->getType() && "Both operands to ICmp instruction are not of the same type!"), function ICmpInst, file /Users/jruderman/code/rust/src/llvm/include/llvm/Instructions.h, line 958.
@nikomatsakis
Copy link
Contributor

I suspect that this, #2150, and #2151 are all a result of a (perhaps poor) decision I made to resolve unconstrained types to bottom. I think I will revert that choice. It means that some nonsensical programs (like these) will not compile but also that something like "let x = none;" where there is no further constraint on the type of x will fail, because it will not know what sort of "none" x is (e.g., option<int> etc). The latter is how things used to be and is tolerable in practice...I only put in the "unresolved types become bot" rule because some programs that used to work (which contained unconstrained types) now failed, but they were all nonsensical (generated by the fuzzer) to begin with.

@jruderman
Copy link
Contributor Author

Could allow let x = none; to compile as if x were option<()> while still rejecting let x = fail;?

@nikomatsakis
Copy link
Contributor

Hmm, I could be wrong in my theory, actually. I'm not 100% sure why r += f(elt) compiles. I would expect that to error out right now, since the type of r is completely unknown at that point.

@nikomatsakis
Copy link
Contributor

@jruderman well one possible fix along those lines, which I just implemented, is to refuse to consider the "bottom" type as "resolved"---this causes this test (and the others) to result in a compile error, because a resolved type is required in order to process a binary operator. (resolved types are required wherever the resulting type of an expression is overloaded based on an input type; this occurs for binary operators because of overloaded operators and because not all types are addable and so forth) I am not sure if this is the best fix---it may leave other weird paths through the compiler---but I guess I will institute it for now.

bors added a commit to rust-lang-ci/rust that referenced this issue Sep 22, 2022
move some compile-fail tests to a more appropriate location

These are testing validity invariants, after all.
celinval added a commit to celinval/rust-dev that referenced this issue Jun 4, 2024
Upgrade our toolchain to `nightly-2023-01-23`. The changes here are related to the following changes:
- rust-lang#104986
- rust-lang#105657
- rust-lang#105603
- rust-lang#105613
- rust-lang#105977
- rust-lang#104645
Kobzol pushed a commit to Kobzol/rust that referenced this issue Dec 30, 2024
bors pushed a commit to rust-lang-ci/rust that referenced this issue Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation
Projects
None yet
Development

No branches or pull requests

2 participants