Repository navigation
Closed
Labels
C-bugCategory: This is a bug.Category: This is a bug.I-hangIssue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc.Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.Performance or correctness regression from stable to nightly.
Description
This malformed code (playground) hangs the compiler:
struct R { }
struct S {
x: [u8; RFound by fuzzing with a modified fuzz-rustc.
The bug's edges
Rmust be defined as a named-field struct (not a tuple struct or unit struct), although it can have 0 fields.Rmust be the last token to produce the hang:- No opening brace (note that braces are required for literals of named-field structs)
- No closing delimiters
- Not even a comment
Where it hangs
If I understand mj.sample.txt correctly, the hang occurs in LateResolutionVisitor, with try_lookup_name_relaxed never finishing (while calling various functions such as smart_resolve_context_dependent_help and span_to_snippet)
Additional example
This also hangs. I'm guessing it's the same bug.
struct R { }
fn f() {
RVersion
rustc --version --verbose:
rustc 1.66.0-nightly (6e95b6da8 2022-10-22)
binary: rustc
commit-hash: 6e95b6da885f42a4e1314595089fa4295e329d11
commit-date: 2022-10-22
host: x86_64-apple-darwin
release: 1.66.0-nightly
LLVM version: 15.0.2
Regression
Bisected with:
cargo-bisect-rustc --start=2022-10-03 --end=nightly-2022-10-23 --preserve --script=./timeout.shtimeout.sh
#!/bin/bash
# This script is wrong in several ways:
# - It will try to kill processes that might no longer exist
# - It may leave an orphan rustc process after the bisect (because it only kills the shell, not rustc)
# But it seems to be good enough for bisection to work
killall rustc
outershell=$$
(sleep 5; kill $outershell) &
rustc src/main.rs
true- regressed nightly: nightly-2022-10-21
- regressed commit: 53728ff (PR Fix the bug of next_point in source_map #103185)
@rustbot label +regression-from-stable-to-nightly +I-hang
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.I-hangIssue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc.Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.Performance or correctness regression from stable to nightly.
Activity
chenyukang commentedon Oct 24, 2022
@rustbot claim
chenyukang commentedon Oct 24, 2022
I can not reproduce it with latest code, did I missed anything?
chenyukang commentedon Oct 24, 2022
Great cactch @jruderman
Confirmed the error is only triggered by commit:
6e95b6da885f42a4e1314595089fa4295e329d11The root cause is I changed the edge corner case in
find_width_of_character_at_span:We think
next_pointwon't return a span which outside of source file, so0is a valid one, thennext_pointwill always return a valid span, and we getOk("")fromsm.span_to_snippetwhen reaching the end of source.So, there is a loop in previous
followed_by_brace, which will run infinitely loop:rust/compiler/rustc_resolve/src/late/diagnostics.rs
Line 1110 in 41a1cfd
Lucky, my another PR #101908 merged at last day, this PR refactored this function:
518d5eb#diff-2c81e6d8048a31a3ce43f30181aaa037e0ad0076e7aee67792ca993f28c75ac3L1108
jruderman commentedon Oct 24, 2022
Verif, I no longer get a hang after rollup 9be2f35
Do you want to add one or two of these as tests?
chenyukang commentedon Oct 24, 2022
Yes, we'd better add a testcase for it.
I'm thinking whether we sould
return 1infind_width_of_character_at_spanwhen reaching to the end of source, so thatsm.span_to_snippetmay get an error.chenyukang commentedon Oct 24, 2022
This testcase seems not easy to be added:
If so, the trigger point will do not exist, 😂
jruderman commentedon Oct 24, 2022
@rustbot label -I-prioritize
estebank commentedon Oct 24, 2022
There's an alternative kind of annotation for patterns that should work for this case:
// error-pattern:this file contains an unclosed delimiterRollup merge of rust-lang#103521 - chenyukang:yukang/fix-103451-avoid…
Rollup merge of rust-lang#103521 - chenyukang:yukang/fix-103451-avoid…
Rollup merge of rust-lang#103521 - chenyukang:yukang/fix-103451-avoid…
Rollup merge of rust-lang#103521 - chenyukang:yukang/fix-103451-avoid…
Rollup merge of rust-lang#103521 - chenyukang:yukang/fix-103451-avoid…
Rollup merge of rust-lang#103521 - chenyukang:yukang/fix-103451-avoid…
Rollup merge of rust-lang#103521 - chenyukang:yukang/fix-103451-avoid…
Rollup merge of rust-lang#103521 - chenyukang:yukang/fix-103451-avoid…
Rollup merge of rust-lang#103521 - chenyukang:yukang/fix-103451-avoid…