Skip to content

Commit b3dc1de

Browse files
Rollup merge of rust-lang#145108 - LorrensP-2158466:batched-import-resolution, r=petrochenkov
Resolver: Batched Import Resolution *[View all comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust/pull/145108)* Transforms the current algorithm for resolving imports to a batched algorithm. Every import in the `indeterminate_imports` set is resolved in isolation. This is the only real difference from the current algorithm. r? petrochenkov
2 parents 570439c + fe7c7a1 commit b3dc1de

19 files changed

Lines changed: 326 additions & 313 deletions

File tree

compiler/rustc_resolve/src/imports.rs

Lines changed: 231 additions & 124 deletions
Large diffs are not rendered by default.

compiler/rustc_resolve/src/lib.rs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2868,16 +2868,10 @@ mod ref_mut {
28682868
#[track_caller]
28692869
pub(crate) fn get_mut(&mut self) -> &mut T {
28702870
match self.mutable {
2871-
false => panic!("Can't mutably borrow speculative resolver"),
2871+
false => panic!("can't mutably borrow speculative resolver"),
28722872
true => self.p,
28732873
}
28742874
}
2875-
2876-
/// Returns a mutable reference to the inner value without checking if
2877-
/// it's in a mutable state.
2878-
pub(crate) fn get_mut_unchecked(&mut self) -> &mut T {
2879-
self.p
2880-
}
28812875
}
28822876

28832877
/// A wrapper around a [`Cell`] that only allows mutation based on a condition in the resolver.
@@ -2901,12 +2895,12 @@ mod ref_mut {
29012895
self.0.get()
29022896
}
29032897

2904-
pub(crate) fn update_unchecked(&self, f: impl FnOnce(T) -> T)
2898+
pub(crate) fn update<'ra, 'tcx>(&self, r: &Resolver<'ra, 'tcx>, f: impl FnOnce(T) -> T)
29052899
where
29062900
T: Copy,
29072901
{
29082902
let old = self.get();
2909-
self.set_unchecked(f(old));
2903+
self.set(f(old), r);
29102904
}
29112905
}
29122906

@@ -2915,7 +2909,10 @@ mod ref_mut {
29152909
CmCell(Cell::new(value))
29162910
}
29172911

2918-
pub(crate) fn set_unchecked(&self, val: T) {
2912+
pub(crate) fn set<'ra, 'tcx>(&self, val: T, r: &Resolver<'ra, 'tcx>) {
2913+
if r.assert_speculative {
2914+
panic!("not allowed to mutate a `CmCell` during speculative resolution")
2915+
}
29192916
self.0.set(val);
29202917
}
29212918

@@ -2941,16 +2938,26 @@ mod ref_mut {
29412938
#[track_caller]
29422939
pub(crate) fn borrow_mut<'ra, 'tcx>(&self, r: &Resolver<'ra, 'tcx>) -> RefMut<'_, T> {
29432940
if r.assert_speculative {
2944-
panic!("Not allowed to mutably borrow a CmRefCell during speculative resolution");
2941+
panic!("not allowed to mutably borrow a `CmRefCell` during speculative resolution");
29452942
}
2946-
self.borrow_mut_unchecked()
2943+
self.0.borrow_mut()
29472944
}
29482945

2949-
#[track_caller]
29502946
pub(crate) fn try_borrow_mut_unchecked(&self) -> Result<RefMut<'_, T>, BorrowMutError> {
29512947
self.0.try_borrow_mut()
29522948
}
29532949

2950+
#[track_caller]
2951+
pub(crate) fn try_borrow_mut<'ra, 'tcx>(
2952+
&self,
2953+
r: &Resolver<'ra, 'tcx>,
2954+
) -> Result<RefMut<'_, T>, BorrowMutError> {
2955+
if r.assert_speculative {
2956+
panic!("not allowed to mutably borrow a `CmRefCell` during speculative resolution");
2957+
}
2958+
self.0.try_borrow_mut()
2959+
}
2960+
29542961
#[track_caller]
29552962
pub(crate) fn borrow(&self) -> Ref<'_, T> {
29562963
self.0.borrow()
@@ -2960,7 +2967,7 @@ mod ref_mut {
29602967
impl<T: Default> CmRefCell<T> {
29612968
pub(crate) fn take<'ra, 'tcx>(&self, r: &Resolver<'ra, 'tcx>) -> T {
29622969
if r.assert_speculative {
2963-
panic!("Not allowed to mutate a CmRefCell during speculative resolution");
2970+
panic!("not allowed to mutate a CmRefCell during speculative resolution");
29642971
}
29652972
self.0.take()
29662973
}

compiler/rustc_span/src/symbol.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ symbols! {
294294
ResumeTy,
295295
Reverse,
296296
Rust,
297+
// Temporary name for the rust_embed hack introduced in #145108
298+
RustEmbed,
297299
RustaceansAreAwesome,
298300
RwLock,
299301
RwLockReadGuard,

library/stdarch/crates/core_arch/src/aarch64/sve/generated.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use stdarch_test::assert_instr;
1212

1313
use super::*;
1414
use crate::core_arch::arch::aarch64::*;
15+
use super::{AsSigned, AsUnsigned};
1516

1617
#[doc = "Absolute difference"]
1718
#[doc = "[Arm's documentation](https://developer.arm.com/architectures/instruction-sets/intrinsics/svabd[_f32]_m)"]

library/stdarch/crates/stdarch-gen-arm/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ use super::*;{uses_neon}
166166
167167
"#,
168168
uses_neon = if generated_input.ctx.uses_neon_types {
169-
"\nuse crate::core_arch::arch::aarch64::*;"
169+
"\nuse crate::core_arch::arch::aarch64::*;\nuse super::{AsSigned, AsUnsigned};"
170170
} else {
171171
""
172172
},

src/tools/rust-analyzer/crates/hir-ty/src/mir/lower/as_place.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! MIR lowering for places
22
33
use hir_def::FunctionId;
4-
use rustc_type_ir::inherent::{Region as _, Ty as _};
4+
use rustc_type_ir::inherent::Region as _;
55

66
use super::*;
77
use crate::{

tests/ui/imports/ambiguous-14.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,4 @@ mod g {
2222
fn main() {
2323
g::foo();
2424
//~^ ERROR `foo` is ambiguous
25-
//~| WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
2625
}
Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,23 @@
1-
error: `foo` is ambiguous
1+
error[E0659]: `foo` is ambiguous
22
--> $DIR/ambiguous-14.rs:23:8
33
|
44
LL | g::foo();
55
| ^^^ ambiguous name
66
|
77
= note: ambiguous because of multiple glob imports of a name in the same module
88
note: `foo` could refer to the function imported here
9-
--> $DIR/ambiguous-14.rs:18:13
9+
--> $DIR/ambiguous-14.rs:13:13
1010
|
1111
LL | pub use a::*;
1212
| ^^^^
1313
= help: consider adding an explicit import of `foo` to disambiguate
1414
note: `foo` could also refer to the function imported here
15-
--> $DIR/ambiguous-14.rs:19:13
15+
--> $DIR/ambiguous-14.rs:14:13
1616
|
17-
LL | pub use f::*;
17+
LL | pub use b::*;
1818
| ^^^^
1919
= help: consider adding an explicit import of `foo` to disambiguate
20-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
21-
= note: for more information, see issue #114095 <https://github.com/rust-lang/rust/issues/114095>
22-
= note: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(future_incompatible)]`) on by default
2320

2421
error: aborting due to 1 previous error
2522

26-
Future incompatibility report: Future breakage diagnostic:
27-
error: `foo` is ambiguous
28-
--> $DIR/ambiguous-14.rs:23:8
29-
|
30-
LL | g::foo();
31-
| ^^^ ambiguous name
32-
|
33-
= note: ambiguous because of multiple glob imports of a name in the same module
34-
note: `foo` could refer to the function imported here
35-
--> $DIR/ambiguous-14.rs:18:13
36-
|
37-
LL | pub use a::*;
38-
| ^^^^
39-
= help: consider adding an explicit import of `foo` to disambiguate
40-
note: `foo` could also refer to the function imported here
41-
--> $DIR/ambiguous-14.rs:19:13
42-
|
43-
LL | pub use f::*;
44-
| ^^^^
45-
= help: consider adding an explicit import of `foo` to disambiguate
46-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
47-
= note: for more information, see issue #114095 <https://github.com/rust-lang/rust/issues/114095>
48-
= note: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(future_incompatible)]`) on by default
49-
23+
For more information about this error, try `rustc --explain E0659`.

tests/ui/imports/ambiguous-9.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ pub mod dsl {
44
mod range {
55
pub fn date_range() {}
66
}
7-
pub use self::range::*; //~ WARNING ambiguous glob re-exports
7+
pub use self::range::*;
88
use super::prelude::*;
99
}
1010

1111
pub mod prelude {
1212
mod t {
13-
pub fn date_range() {}
13+
pub fn date_range() {}
1414
}
15-
pub use self::t::*; //~ WARNING ambiguous glob re-exports
16-
pub use super::dsl::*;
15+
pub use self::t::*;
16+
pub use super::dsl::*; //~ WARNING ambiguous glob re-exports
1717
}
1818

1919
use dsl::*;
@@ -22,5 +22,4 @@ use prelude::*;
2222
fn main() {
2323
date_range();
2424
//~^ ERROR `date_range` is ambiguous
25-
//~| ERROR `date_range` is ambiguous
2625
}

tests/ui/imports/ambiguous-9.stderr

Lines changed: 12 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,56 +6,28 @@ LL | date_range();
66
|
77
= note: ambiguous because of multiple glob imports of a name in the same module
88
note: `date_range` could refer to the function imported here
9-
--> $DIR/ambiguous-9.rs:19:5
9+
--> $DIR/ambiguous-9.rs:16:13
1010
|
11-
LL | use dsl::*;
12-
| ^^^^^^
13-
= help: consider adding an explicit import of `date_range` to disambiguate
14-
note: `date_range` could also refer to the function imported here
15-
--> $DIR/ambiguous-9.rs:20:5
16-
|
17-
LL | use prelude::*;
18-
| ^^^^^^^^^^
19-
= help: consider adding an explicit import of `date_range` to disambiguate
20-
21-
error[E0659]: `date_range` is ambiguous
22-
--> $DIR/ambiguous-9.rs:23:5
23-
|
24-
LL | date_range();
25-
| ^^^^^^^^^^ ambiguous name
26-
|
27-
= note: ambiguous because of multiple glob imports of a name in the same module
28-
note: `date_range` could refer to the function imported here
29-
--> $DIR/ambiguous-9.rs:7:13
30-
|
31-
LL | pub use self::range::*;
32-
| ^^^^^^^^^^^^^^
11+
LL | pub use super::dsl::*;
12+
| ^^^^^^^^^^^^^
3313
= help: consider adding an explicit import of `date_range` to disambiguate
3414
note: `date_range` could also refer to the function imported here
35-
--> $DIR/ambiguous-9.rs:8:9
15+
--> $DIR/ambiguous-9.rs:15:13
3616
|
37-
LL | use super::prelude::*;
38-
| ^^^^^^^^^^^^^^^^^
17+
LL | pub use self::t::*;
18+
| ^^^^^^^^^^
3919
= help: consider adding an explicit import of `date_range` to disambiguate
4020

4121
warning: ambiguous glob re-exports
42-
--> $DIR/ambiguous-9.rs:7:13
43-
|
44-
LL | pub use self::range::*;
45-
| ^^^^^^^^^^^^^^ the name `date_range` in the value namespace is first re-exported here
46-
LL | use super::prelude::*;
47-
| ----------------- but the name `date_range` in the value namespace is also re-exported here
48-
|
49-
= note: `#[warn(ambiguous_glob_reexports)]` on by default
50-
51-
warning: ambiguous glob re-exports
52-
--> $DIR/ambiguous-9.rs:15:13
22+
--> $DIR/ambiguous-9.rs:16:13
5323
|
5424
LL | pub use self::t::*;
55-
| ^^^^^^^^^^ the name `date_range` in the value namespace is first re-exported here
25+
| ---------- but the name `date_range` in the value namespace is also re-exported here
5626
LL | pub use super::dsl::*;
57-
| ------------- but the name `date_range` in the value namespace is also re-exported here
27+
| ^^^^^^^^^^^^^ the name `date_range` in the value namespace is first re-exported here
28+
|
29+
= note: `#[warn(ambiguous_glob_reexports)]` on by default
5830

59-
error: aborting due to 2 previous errors; 2 warnings emitted
31+
error: aborting due to 1 previous error; 1 warning emitted
6032

6133
For more information about this error, try `rustc --explain E0659`.

0 commit comments

Comments
 (0)