Kobzol / cargo-remark

Cargo subcommand for viewing LLVM optimization remarks.
MIT License
161 stars 2 forks source link

Build hangs for some build scripts #13

Open aldanor opened 11 months ago

aldanor commented 11 months ago

For larger projects, chances are there's always going to be some proc-macro dependencies involved, seems like cargo remark build just hangs; here's the simplest example (taken from paste docs):

use paste::paste; // add `paste = "1.0"` to deps

paste! { const [<Q R S T>]: &str = "success!"; }

fn main() {
    assert_eq!(paste! { [<Q R S T>].len() }, 8);
}

which results in hanging forever here:

❯ cargo +nightly remark build
[2023-10-11T15:19:31Z INFO  cargo_remark::cargo] Optimization remarks will be stored into target/remarks/yaml.
   Compiling paste v1.0.14
    Building [====>                        ] 1/5: paste(build.rs)

Edit: not sure if it's proc-macro-related, or if it's something to do with paste. Or dependencies that have a custom build.rs perhaps?

aldanor commented 11 months ago

Update, tracked it down to a single line in paste's build.rs; minimal example that seems to hang is this: add build.rs with

fn main() {
    _ = "".split('.'); // <-- ???
}

This causes it to hang forever:

❯ cargo +nightly remark build
   Compiling test-remark v0.1.0 (test-remark)
    Building [                             ] 0/3: test-remark(build.rs)
aldanor commented 11 months ago

Looking into it a bit further, just running

RUSTFLAGS="-Cremark=all -Cdebuginfo=1" cargo +nightly build --release

causes

note: /rustc/59edd67056919c83c59001a8b4f2d8749359377a/library/core/src/char/methods.rs:1767:0 asm-printer (analysis): 179 instructions in function

note: /rustc/59edd67056919c83c59001a8b4f2d8749359377a/library/core/src/str/pattern.rs:544:32 gisel-irtranslator-memsize (analysis): Call to memset. Memory operation size: 4 bytes.
       Written Variables: <unknown> (4 bytes).

note: /rustc/59edd67056919c83c59001a8b4f2d8749359377a/library/core/src/str/pattern.rs:543:0 size-info (analysis): IRTranslator: Function: _ZN52_$LT$char$u20$as$u20$core..str..pattern..Pattern$GT$13into_searcher17h80469adc07d8dc57E: MI Instruction count changed from 0 to 43; Delta: 43

note: /rustc/59edd67056919c83c59001a8b4f2d8749359377a/library/core/src/str/pattern.rs:543:0 size-info (analysis): AArch64O0PreLegalizerCombiner: Function: _ZN52_$LT$char$u20$as$u20$core..str..pattern..Pattern$GT$13into_searcher17h80469adc07d8dc57E: MI Instruction count changed from 43 to 40; Delta: -3

note: /rustc/59edd67056919c83c59001a8b4f2d8749359377a/library/core/src/str/pattern.rs:546:9 gisel-legalize (missed): unable to legalize instruction: G_STORE %26:_(<4 x s8>), %25:_(p0) :: (store (<4 x s8>) into %ir.18, align 8)

error: could not compile `test-remark` (build script)

So,

Perhaps related: https://github.com/rust-lang/cargo/issues/6375 (re: not passing RUSTFLAGS down to build scripts which can cause all sorts of problems like here)

Kobzol commented 11 months ago

Hi, thanks for investigating this! To be clear, you were able to reproduce this with an empty Cargo project containing the mentioned build script? I can't reproduce the build script error on such an empty project with a build script.

aldanor commented 11 months ago

Yes, the following hangs:

cargo new --bin foo
cd foo
echo 'fn main() { _ = "".split(\'.\'); }' > build.rs
cargo +nightly remark build

(to clarify, this is on M1 macOS, things may behave different on x64/linux I think)

rustc version: rustc 1.75.0-nightly (59edd6705 2023-10-09)

Kobzol commented 11 months ago

I see. This works for me on Linux, so it's hard for me to reproduce :sweat_smile: I think that the fact that it errors out for you (not the cargo remark hang, but the -Cremark=all error) should be reported to rust-lang/rust as a bug.