Skip to content

Bootstrapped compiler is deterministic in a way that the released compiler is not #144715

@HackAttack

Description

@HackAttack

Summary

When building a particular crate normally, the generated bitcode is nondeterministic, but when using a bootstrapped rustc it is not.

Command used

##############################
# Demonstrate nondeterminism #
##############################
git clone https://github.com/apache/datafusion.git --depth 1 -b 36.0.0
cd datafusion
cargo update -p chrono --precise 0.4.39
cargo build --release -p datafusion-expr
cp target/release/libdatafusion_expr.rlib 1.rlib
cp 1.rlib 2.rlib

# Will terminate when it detects nondeterminism, usually within 10 iterations
i=0
while diff -q 1.rlib 2.rlib; do
  ((i++))
  rm -rf target/release/deps/libdatafusion_* target/release/libdatafusion_expr.*
  cargo build --release -p datafusion-expr
  cp target/release/libdatafusion_expr.rlib 2.rlib
done
echo after $i iterations

#########################################################################
# Building from source solves the nondeterminism, even with no patches! #
#########################################################################
git clone https://github.com/rust-lang/rust --depth 1 -b 1.88.0 ../rust
cd ../rust
./x build library  # using --set llvm.download-ci-llvm=false gives the same result
cd ../datafusion
export RUSTC=../rust/build/host/stage1/bin/rustc
cargo build --release -p datafusion-expr
cp target/release/libdatafusion_expr.rlib 1.rlib
cp 1.rlib 2.rlib

# Will run forever since the outputs are now deterministic
i=0
while diff -q 1.rlib 2.rlib; do
  ((i++))
  rm -rf target/release/deps/libdatafusion_* target/release/libdatafusion_expr.*
  cargo build --release -p datafusion-expr
  cp target/release/libdatafusion_expr.rlib 2.rlib
done
echo after $i iterations

Expected behaviour

There may be two separate bugs here.

  • The generated bitcode should be deterministic
  • The bootstrapped rustc should behave the same as the released version

Actual behaviour

The released compiler generates nondeterministic bitcode, but switching to the bootstrapped compiler makes it deterministic.

Bootstrap configuration (bootstrap.toml)

Default

Operating system

Ubuntu 20.04

HEAD

6b00bc3

Additional context

I originally thought the nondeterminism was due to a bug in LLVM. The details of what exactly is nondeterministic can be found at llvm/llvm-project#151006.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-reproducibilityArea: Reproducible / deterministic buildsC-bugCategory: This is a bug.T-bootstrapRelevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions