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

Apparent infinite loop in AST validation with nested extern crate declaration #37887

Closed
fweimer opened this issue Nov 19, 2016 · 2 comments
Closed
Labels
C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.

Comments

@fweimer
Copy link

fweimer commented Nov 19, 2016

This program

fn main() {
    extern crate libc;
    use libc::*;
}

seems to cause the compiler too loop endlessly in AST validation, allocating more and more memory:

$ rustc -Z time-passes oom.rs 
warning: the option `Z` is unstable and should only be used on the nightly compiler, but it is currently accepted for backwards compatibility; this will soon change, see issue #31847 for more details

time: 0.000; rss: 31MB  parsing
time: 0.000; rss: 31MB  recursion limit
time: 0.000; rss: 31MB  crate injection
time: 0.000; rss: 31MB  plugin loading
time: 0.000; rss: 31MB  plugin registration
time: 0.024; rss: 51MB  expansion
time: 0.000; rss: 51MB  maybe building test harness
time: 0.000; rss: 51MB  maybe creating a macro crate
time: 0.000; rss: 51MB  checking for inline asm in case the target doesn't support it
time: 0.000; rss: 51MB  complete gated feature checking
time: 0.000; rss: 51MB  collecting defs
time: 0.000; rss: 51MB  early lint checks
time: 0.000; rss: 51MB  AST validation
^C
$ rustc --version
rustc 1.13.0
@jseyfried
Copy link
Contributor

This is fixed in beta and nightly.

@jseyfried jseyfried added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Nov 20, 2016
@KalitaAlexey
Copy link
Contributor

On the latest nightly: rustc 1.15.0-nightly (daf8c1d 2016-12-05)
The code:

fn main() {
    extern crate libc;
    use libc::*;
}

doesn't compile:

rustc -Z time-passes main.rs 
time: 0.000; rss: 50MB	parsing
time: 0.000; rss: 50MB	recursion limit
time: 0.000; rss: 50MB	crate injection
time: 0.000; rss: 50MB	plugin loading
time: 0.000; rss: 50MB	plugin registration
time: 0.027; rss: 71MB	expansion
time: 0.000; rss: 71MB	maybe building test harness
time: 0.000; rss: 71MB	maybe creating a macro crate
time: 0.000; rss: 71MB	checking for inline asm in case the target doesn't support it
time: 0.000; rss: 71MB	complete gated feature checking
time: 0.000; rss: 71MB	early lint checks
time: 0.000; rss: 71MB	AST validation
error[E0432]: unresolved import `libc::*`
 --> main.rs:3:9
  |
3 |     use libc::*;
  |         ^^^^^^^^ Maybe a missing `extern crate libc;`?

time: 0.002; rss: 71MB	name resolution
time: 0.000; rss: 71MB	lowering ast -> hir
time: 0.000; rss: 71MB	indexing hir
time: 0.000; rss: 71MB	attribute checking
time: 0.000; rss: 71MB	language item collection
time: 0.000; rss: 71MB	lifetime resolution
time: 0.000; rss: 71MB	looking for entry point
time: 0.000; rss: 71MB	looking for plugin registrar
time: 0.000; rss: 71MB	region resolution
time: 0.000; rss: 71MB	loop checking
time: 0.000; rss: 71MB	static item recursion checking
time: 0.000; rss: 76MB	compute_incremental_hashes_map
time: 0.000; rss: 76MB	load_dep_graph
time: 0.000; rss: 76MB	stability index
error: use of unstable library feature 'libc': use `libc` from crates.io (see issue #27783)
 --> main.rs:2:5
  |
2 |     extern crate libc;
  |     ^^^^^^^^^^^^^^^^^^
  |
  = help: add #![feature(libc)] to the crate attributes to enable

time: 0.001; rss: 76MB	stability checking
time: 0.000; rss: 76MB	type collecting
time: 0.000; rss: 76MB	variance inference
time: 0.000; rss: 76MB	impl wf inference
time: 0.008; rss: 76MB	coherence checking
time: 0.000; rss: 76MB	wf checking
time: 0.000; rss: 76MB	item-types checking
time: 0.000; rss: 76MB	item-bodies checking
time: 0.000; rss: 76MB	drop-impl checking
error: aborting due to 2 previous errors

The code:

#![feature(libc)]

fn main() {
    extern crate libc;
    use libc::*;
}

doesn't compile:

rustc -Z time-passes main.rs 
time: 0.001; rss: 46MB	parsing
time: 0.000; rss: 51MB	recursion limit
time: 0.000; rss: 51MB	crate injection
time: 0.000; rss: 51MB	plugin loading
time: 0.000; rss: 51MB	plugin registration
time: 0.039; rss: 68MB	expansion
time: 0.000; rss: 68MB	maybe building test harness
time: 0.000; rss: 68MB	maybe creating a macro crate
time: 0.000; rss: 68MB	checking for inline asm in case the target doesn't support it
time: 0.000; rss: 68MB	complete gated feature checking
time: 0.000; rss: 68MB	early lint checks
time: 0.000; rss: 68MB	AST validation
error[E0432]: unresolved import `libc::*`
 --> main.rs:5:9
  |
5 |     use libc::*;
  |         ^^^^^^^^ Maybe a missing `extern crate libc;`?

time: 0.003; rss: 68MB	name resolution
time: 0.000; rss: 68MB	lowering ast -> hir
time: 0.000; rss: 68MB	indexing hir
time: 0.000; rss: 68MB	attribute checking
time: 0.000; rss: 68MB	language item collection
time: 0.000; rss: 68MB	lifetime resolution
time: 0.000; rss: 68MB	looking for entry point
time: 0.000; rss: 68MB	looking for plugin registrar
time: 0.000; rss: 68MB	region resolution
time: 0.000; rss: 68MB	loop checking
time: 0.000; rss: 68MB	static item recursion checking
time: 0.000; rss: 68MB	compute_incremental_hashes_map
time: 0.000; rss: 68MB	load_dep_graph
time: 0.000; rss: 68MB	stability index
time: 0.000; rss: 68MB	stability checking
time: 0.000; rss: 73MB	type collecting
time: 0.000; rss: 73MB	variance inference
time: 0.000; rss: 73MB	impl wf inference
time: 0.008; rss: 73MB	coherence checking
time: 0.000; rss: 73MB	wf checking
time: 0.000; rss: 73MB	item-types checking
time: 0.000; rss: 73MB	item-bodies checking
time: 0.000; rss: 73MB	drop-impl checking
error: aborting due to previous error

The code:

#![feature(libc)]

extern crate libc;

fn main() {
    use libc::*;
}

compiles:

rustc -Z time-passes main.rs 
time: 0.000; rss: 46MB	parsing
time: 0.000; rss: 51MB	recursion limit
time: 0.000; rss: 51MB	crate injection
time: 0.000; rss: 51MB	plugin loading
time: 0.000; rss: 51MB	plugin registration
time: 0.038; rss: 68MB	expansion
time: 0.000; rss: 68MB	maybe building test harness
time: 0.000; rss: 68MB	maybe creating a macro crate
time: 0.000; rss: 68MB	checking for inline asm in case the target doesn't support it
time: 0.000; rss: 68MB	complete gated feature checking
time: 0.000; rss: 68MB	early lint checks
time: 0.000; rss: 68MB	AST validation
time: 0.005; rss: 68MB	name resolution
time: 0.000; rss: 68MB	lowering ast -> hir
time: 0.000; rss: 68MB	indexing hir
time: 0.000; rss: 68MB	attribute checking
time: 0.000; rss: 68MB	language item collection
time: 0.000; rss: 68MB	lifetime resolution
time: 0.000; rss: 68MB	looking for entry point
time: 0.000; rss: 68MB	looking for plugin registrar
time: 0.000; rss: 68MB	region resolution
time: 0.000; rss: 68MB	loop checking
time: 0.000; rss: 68MB	static item recursion checking
time: 0.000; rss: 68MB	compute_incremental_hashes_map
time: 0.000; rss: 72MB	load_dep_graph
time: 0.000; rss: 72MB	stability index
time: 0.000; rss: 72MB	stability checking
time: 0.000; rss: 72MB	type collecting
time: 0.000; rss: 72MB	variance inference
time: 0.000; rss: 72MB	impl wf inference
time: 0.008; rss: 72MB	coherence checking
time: 0.000; rss: 72MB	wf checking
time: 0.000; rss: 72MB	item-types checking
time: 0.000; rss: 72MB	item-bodies checking
time: 0.000; rss: 72MB	drop-impl checking
time: 0.000; rss: 72MB	const checking
time: 0.000; rss: 72MB	privacy checking
time: 0.000; rss: 72MB	intrinsic checking
time: 0.000; rss: 72MB	effect checking
time: 0.000; rss: 72MB	match checking
time: 0.000; rss: 72MB	liveness checking
time: 0.000; rss: 72MB	rvalue checking
time: 0.000; rss: 72MB	MIR dump
  time: 0.000; rss: 72MB	SimplifyCfg
  time: 0.000; rss: 72MB	QualifyAndPromoteConstants
  time: 0.000; rss: 72MB	TypeckMir
  time: 0.000; rss: 72MB	SimplifyBranches
  time: 0.000; rss: 72MB	SimplifyCfg
time: 0.000; rss: 72MB	MIR cleanup and validation
time: 0.000; rss: 72MB	borrow checking
time: 0.000; rss: 72MB	reachability checking
time: 0.000; rss: 72MB	death checking
time: 0.000; rss: 72MB	unused lib feature checking
warning: unused import: `libc::*;`, #[warn(unused_imports)] on by default
 --> main.rs:6:9
  |
6 |     use libc::*;
  |         ^^^^^^^^

time: 0.008; rss: 72MB	lint checking
time: 0.002; rss: 72MB	resolving dependency formats
  time: 0.000; rss: 72MB	NoLandingPads
  time: 0.000; rss: 72MB	SimplifyCfg
  time: 0.000; rss: 72MB	EraseRegions
  time: 0.000; rss: 72MB	AddCallGuards
  time: 0.000; rss: 72MB	ElaborateDrops
  time: 0.000; rss: 72MB	NoLandingPads
  time: 0.000; rss: 72MB	SimplifyCfg
  time: 0.000; rss: 72MB	InstCombine
  time: 0.000; rss: 72MB	Deaggregator
  time: 0.000; rss: 72MB	CopyPropagation
  time: 0.000; rss: 72MB	SimplifyLocals
  time: 0.000; rss: 72MB	AddCallGuards
  time: 0.000; rss: 72MB	PreTrans
time: 0.000; rss: 72MB	MIR optimisations
  time: 0.000; rss: 72MB	write metadata
  time: 0.000; rss: 72MB	translation item collection
  time: 0.000; rss: 72MB	codegen unit partitioning
  time: 0.000; rss: 79MB	internalize symbols
time: 0.096; rss: 79MB	translation
time: 0.000; rss: 79MB	assert dep graph
time: 0.000; rss: 79MB	serialize dep graph
  time: 0.000; rss: 79MB	llvm function passes [0]
  time: 0.000; rss: 79MB	llvm module passes [0]
  time: 0.003; rss: 79MB	codegen passes [0]
  time: 0.000; rss: 79MB	codegen passes [0]
time: 0.006; rss: 79MB	LLVM passes
time: 0.000; rss: 79MB	serialize work products
  time: 0.197; rss: 79MB	running linker
time: 0.198; rss: 79MB	linking

So I think the problem is fixed.

@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 26, 2017
MaloJaffre added a commit to MaloJaffre/rust that referenced this issue Oct 4, 2017
Also ignore `attr-on-trait` test on stage-1 to keep `./x.py test --stage 1` successful.

Fixes rust-lang#30355.
Fixes rust-lang#33241.
Fixes rust-lang#36400.
Fixes rust-lang#37887.
Fixes rust-lang#44578.
bors added a commit that referenced this issue Oct 8, 2017
Fix some E-needstest issues.

Also ignore `attr-on-trait` test on stage-1 to keep `./x.py test --stage 1` successful.

Fixes #30355.
Fixes #33241.
Fixes #36400.
Fixes #37887.
Fixes #44578.
Noratrieb added a commit to Noratrieb/rust that referenced this issue Aug 2, 2023
Add regression test for resolving `--extern libc=test.rlib`

Closes rust-lang#26043

I could not find a test for this particular use case. The closest I got was [`tests/ui/imports/issue-37887.rs`](https://github.com/rust-lang/rust/blob/master/tests/ui/imports/issue-37887.rs), but that is a regression test for a different use case (see rust-lang#37887).
Noratrieb added a commit to Noratrieb/rust that referenced this issue Aug 2, 2023
Add regression test for resolving `--extern libc=test.rlib`

Closes rust-lang#26043

I could not find a test for this particular use case. The closest I got was [`tests/ui/imports/issue-37887.rs`](https://github.com/rust-lang/rust/blob/master/tests/ui/imports/issue-37887.rs), but that is a regression test for a different use case (see rust-lang#37887).
github-actions bot pushed a commit to rust-lang/miri that referenced this issue Aug 3, 2023
Add regression test for resolving `--extern libc=test.rlib`

Closes #26043

I could not find a test for this particular use case. The closest I got was [`tests/ui/imports/issue-37887.rs`](https://github.com/rust-lang/rust/blob/master/tests/ui/imports/issue-37887.rs), but that is a regression test for a different use case (see rust-lang/rust#37887).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Projects
None yet
Development

No branches or pull requests

4 participants