Skip to content

Bug: stream() causes random behavior / internal compiler error #6878

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
honzasp opened this issue Jun 1, 2013 · 3 comments
Closed

Bug: stream() causes random behavior / internal compiler error #6878

honzasp opened this issue Jun 1, 2013 · 3 comments

Comments

@honzasp
Copy link

honzasp commented Jun 1, 2013

Updated bug report

fn sum_halves1() -> u64 {
    let mut buf: u64 = 0;
    for i in range(0u64, 50_000_000) {
        buf = buf + (i / 2);
    }
    buf
}

#[cfg(variant1)]
fn sum_halves2() -> u64 {
    use std::comm::{stream};

    let (_port,_chan): (Port<u64>,Chan<u64>) = stream();

    let mut buf: u64 = 0;
    for j in range(0u64, 50_000_000) {
        buf = buf + (j / 2);
    }

    println(fmt!("buf  %s", buf.to_str()));
    println(fmt!("buf  %s", buf.to_str()));
    println(fmt!("buf  %s", buf.to_str()));

    buf
}

#[cfg(variant2)]
fn sum_halves2() -> u64 {
    use std::comm::{stream};

    let (_port,_chan) = stream();

    let mut buf: u64 = 0;
    for j in range(0u64, 50_000_000) {
        buf = buf + (j / 2);
    }

    println(fmt!("buf  %s", buf.to_str()));
    println(fmt!("buf  %s", buf.to_str()));
    println(fmt!("buf  %s", buf.to_str()));

    buf
}

#[cfg(variant3)]
fn sum_halves2() -> u64 {
    use std::comm::{stream};

    let mut buf: u64 = 0;
    for j in range(0u64, 50_000_000) {
        buf = buf + (j / 2);
    }

    println(fmt!("buf  %s", buf.to_str()));
    println(fmt!("buf  %s", buf.to_str()));
    println(fmt!("buf  %s", buf.to_str()));

    buf
}

fn main() {
    do 1.times {
        println(fmt!("res1 %s", sum_halves1().to_str()));
        let res = sum_halves2();
        println(fmt!("res2 %s", res.to_str()));
        println(fmt!("res2 %s", res.to_str()));
    }
}

Invoke via rustc --cfg variant1 /tmp/sum.rs && /tmp/sum for (or variant2 or variant3).

Original bug report

Hi,

I found a strange behavior of the compiler, which seems to modify a variable by random. The inputs and outputs are here: https://gist.github.com/honzasp/5689535.

The program sum_halvesA.rs computes a correct value in sum_halves1() and prints it, then it computes the same value in sum_halves2(), but this value is mysterously modified somewhere between the caller and callee.

A small change (removing stream() or some println) makes it work as expected.

If I remove the type signature for (port,chan), as in sum_halvesB.rs, rustc fails with internal compiler error.

Original reported output

~/prog/benchrust $ rustc sum.rs -o sum_rust -O && ./sum_rust
sum.rs:12:7: 12:11 warning: unused variable: `port` [-W unused_variable]
sum.rs:12 let (port,chan): (Port<u64>,Chan<u64>) = stream();
^~~~
sum.rs:12:12: 12:16 warning: unused variable: `chan` [-W unused_variable]
sum.rs:12 let (port,chan): (Port<u64>,Chan<u64>) = stream();
^~~~
res1 624999975000000
buf 624999975000000
buf 624999975000000
buf 624999975000000
res2 593020068061681600
res2 593020068061681600
@catamorphism
Copy link
Contributor

The fact that inserting/deleting unrelated code changes behavior makes me think of #4127. I wonder if there's another type_use bug.

@pnkfelix
Copy link
Member

Visiting for triage, email from 2013-08-05

  • I had to update the code in various ways (we've changed our iterator protocol, the range method lives elsewhere, etc). I'll post the updated version in the description shortly.
  • The change in behavior over time seems to have gone away.
  • The ICE has been replaced with the following sensible error from rustc:
/tmp/sum.rs:13:8: 13:32 error: cannot determine a type for this local variable: unconstrained type
/tmp/sum.rs:13     let (_port,_chan) = stream();
                       ^~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error

@pnkfelix
Copy link
Member

I cannot reproduce the problem.

flip1995 pushed a commit to flip1995/rust that referenced this issue Mar 11, 2021
Set Clippy authors to "The Rust Clippy Developers"

Clippy has grown enough, that putting specific people in the "authors"
field isn't warranted anymore.

As a heads-up: `@Manishearth` `@llogiq` `@birkenfeld` `@mcarton` `@oli-obk` `@phansch` `@matthiaskrgr` your names will be removed from one or more of the `Cargo.toml` files of Clippy. This of course does not mean that we value your previous work on Clippy any less ❤️

As per our discussion in today's meeting: https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/Meeting.202021-03-09/near/229502514

changelog: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants