Skip to content

Commit

Permalink
Auto merge of rust-lang#112784 - lnicola:sync-from-ra, r=lnicola
Browse files Browse the repository at this point in the history
⬆️ rust-analyzer

r? `@ghost`
  • Loading branch information
bors committed Jun 19, 2023
2 parents 8d1fa47 + 4004f5a commit 3c9e070
Show file tree
Hide file tree
Showing 114 changed files with 3,891 additions and 1,250 deletions.
4 changes: 2 additions & 2 deletions src/tools/rust-analyzer/.github/workflows/autopublish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Publish Crates
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
PATCH: ${{ github.run_number }}
RUN_NUMBER: ${{ github.run_number }}
shell: bash
run: |
git config --global user.email "[email protected]"
Expand All @@ -53,4 +53,4 @@ jobs:
# Remove library crates from the workspaces so we don't auto-publish them as well
sed -i 's/ "lib\/\*",//' ./Cargo.toml
find crates/rust-analyzer -type f -name '*.rs' -exec sed -i 's/rust_analyzer/ra_ap_rust_analyzer/g' {} +
cargo workspaces publish --yes --force '*' --exact --no-git-commit --allow-dirty --skip-published custom 0.0.$PATCH
cargo workspaces publish --yes --force '*' --exact --no-git-commit --allow-dirty --skip-published custom 0.0.$(($RUN_NUMBER + 133))
8 changes: 5 additions & 3 deletions src/tools/rust-analyzer/.github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
pull-requests: read
outputs:
typescript: ${{ steps.filter.outputs.typescript }}
proc_macros: ${{ steps.filter.outputs.proc_macros }}
steps:
- uses: actions/checkout@v3
- uses: dorny/paths-filter@4067d885736b84de7c414f582ac45897079b0a78
Expand All @@ -45,8 +46,8 @@ jobs:
runs-on: ${{ matrix.os }}
env:
CC: deny_c
RUST_CHANNEL: "${{ needs.changes.outputs.proc_macros == 'true' && 'nightly' || 'stable'}}"
USE_SYSROOT_ABI: "${{ needs.changes.outputs.proc_macros == 'true' && '--features sysroot-abi' || ''}}"
RUST_CHANNEL: "${{ needs.changes.outputs.proc_macros == 'true' && 'nightly' || 'stable' }}"
USE_SYSROOT_ABI: "${{ needs.changes.outputs.proc_macros == 'true' && '--features sysroot-abi' || '' }}"

strategy:
fail-fast: false
Expand All @@ -62,7 +63,8 @@ jobs:
- name: Install Rust toolchain
run: |
rustup update --no-self-update ${{ env.RUST_CHANNEL }}
rustup component add rustfmt rust-src
rustup component add --toolchain ${{ env.RUST_CHANNEL }} rustfmt rust-src
rustup default ${{ env.RUST_CHANNEL }}
- name: Cache Dependencies
uses: Swatinem/rust-cache@988c164c3d0e93c4dbab36aaf5bbeb77425b2894
Expand Down
48 changes: 29 additions & 19 deletions src/tools/rust-analyzer/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -177,21 +177,21 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"

[[package]]
name = "chalk-derive"
version = "0.89.0"
version = "0.91.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea176c50987dc4765961aa165001e8eb5a722a26308c5797a47303ea91686aab"
checksum = "c59178fded594fe78c47b841520e5a4399d00fe15fffee19b945958a878cd02d"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.15",
"synstructure",
]

[[package]]
name = "chalk-ir"
version = "0.89.0"
version = "0.91.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "473b480241695428c14e8f84f1c9a47ef232450a50faf3a4041e5c9dc11e0a3b"
checksum = "8824be92876823b828d551bb792f79eb1f69c69d1948abf69fccbf84e448e57b"
dependencies = [
"bitflags 1.3.2",
"chalk-derive",
Expand All @@ -200,9 +200,9 @@ dependencies = [

[[package]]
name = "chalk-recursive"
version = "0.89.0"
version = "0.91.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6764b4fe67cac3a3758185084efbfbd39bf0352795824ba849ddd2b64cd4bb28"
checksum = "1e110d1260809c238072d1c8ef84060e39983e8ea9d4c6f74b19b0ebbf8904dc"
dependencies = [
"chalk-derive",
"chalk-ir",
Expand All @@ -213,9 +213,9 @@ dependencies = [

[[package]]
name = "chalk-solve"
version = "0.89.0"
version = "0.91.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55a7e6160966eceb6e7dcc2f479a2af4c477aaf5bccbc640d82515995ab1a6cc"
checksum = "12200b19abf4b0633095f7bd099f3ef609d314754b6adb358c68cc04d10589e5"
dependencies = [
"chalk-derive",
"chalk-ir",
Expand Down Expand Up @@ -327,7 +327,7 @@ checksum = "f3cdeb9ec472d588e539a818b2dee436825730da08ad0017c4b1a17676bdc8b7"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 1.0.109",
]

[[package]]
Expand Down Expand Up @@ -1505,7 +1505,6 @@ dependencies = [
"parking_lot 0.12.1",
"parking_lot_core 0.9.6",
"proc-macro-api",
"proc-macro-srv-cli",
"profile",
"project-model",
"rayon",
Expand Down Expand Up @@ -1578,7 +1577,7 @@ dependencies = [
"heck",
"proc-macro2",
"quote",
"syn",
"syn 1.0.109",
]

[[package]]
Expand Down Expand Up @@ -1637,7 +1636,7 @@ checksum = "d7e29c4601e36bcec74a223228dce795f4cd3616341a4af93520ca1a837c087d"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 1.0.109",
]

[[package]]
Expand All @@ -1660,7 +1659,7 @@ checksum = "395627de918015623b32e7669714206363a7fc00382bf477e72c1f7533e8eafc"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 1.0.109",
]

[[package]]
Expand Down Expand Up @@ -1730,15 +1729,26 @@ dependencies = [
"unicode-ident",
]

[[package]]
name = "syn"
version = "2.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]

[[package]]
name = "synstructure"
version = "0.12.6"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f"
checksum = "285ba80e733fac80aa4270fbcdf83772a79b80aa35c97075320abfee4a915b06"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.15",
"unicode-xid",
]

Expand Down Expand Up @@ -1811,7 +1821,7 @@ checksum = "5420d42e90af0c38c3290abcca25b9b3bdf379fc9f55c528f53a269d9c9a267e"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 1.0.109",
]

[[package]]
Expand Down Expand Up @@ -1913,7 +1923,7 @@ checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 1.0.109",
]

[[package]]
Expand Down
6 changes: 3 additions & 3 deletions src/tools/rust-analyzer/crates/base-db/src/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ impl ChangeFixture {
None,
default_cfg,
Default::default(),
Env::default(),
Env::new_for_test_fixture(),
false,
CrateOrigin::Local { repo: None, name: None },
default_target_data_layout
Expand Down Expand Up @@ -259,7 +259,7 @@ impl ChangeFixture {
None,
Default::default(),
Default::default(),
Env::default(),
Env::new_for_test_fixture(),
false,
CrateOrigin::Lang(LangCrateOrigin::Core),
target_layout.clone(),
Expand Down Expand Up @@ -298,7 +298,7 @@ impl ChangeFixture {
None,
Default::default(),
Default::default(),
Env::default(),
Env::new_for_test_fixture(),
true,
CrateOrigin::Local { repo: None, name: None },
target_layout,
Expand Down
23 changes: 23 additions & 0 deletions src/tools/rust-analyzer/crates/base-db/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ pub enum CrateOrigin {
Lang(LangCrateOrigin),
}

impl CrateOrigin {
pub fn is_local(&self) -> bool {
matches!(self, CrateOrigin::Local { .. })
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum LangCrateOrigin {
Alloc,
Expand Down Expand Up @@ -333,6 +339,17 @@ pub struct Env {
entries: FxHashMap<String, String>,
}

impl Env {
pub fn new_for_test_fixture() -> Self {
Env {
entries: FxHashMap::from_iter([(
String::from("__ra_is_test_fixture"),
String::from("__ra_is_test_fixture"),
)]),
}
}
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Dependency {
pub crate_id: CrateId,
Expand Down Expand Up @@ -456,6 +473,12 @@ impl CrateGraph {
self.arena.iter().map(|(idx, _)| idx)
}

// FIXME: used for `handle_hack_cargo_workspace`, should be removed later
#[doc(hidden)]
pub fn iter_mut(&mut self) -> impl Iterator<Item = (CrateId, &mut CrateData)> + '_ {
self.arena.iter_mut()
}

/// Returns an iterator over all transitive dependencies of the given crate,
/// including the crate itself.
pub fn transitive_deps(&self, of: CrateId) -> impl Iterator<Item = CrateId> {
Expand Down
50 changes: 36 additions & 14 deletions src/tools/rust-analyzer/crates/hir-def/src/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ pub struct Body {
pub pats: Arena<Pat>,
pub bindings: Arena<Binding>,
pub labels: Arena<Label>,
/// Id of the closure/generator that owns the corresponding binding. If a binding is owned by the
/// top level expression, it will not be listed in here.
pub binding_owners: FxHashMap<BindingId, ExprId>,
/// The patterns for the function's parameters. While the parameter types are
/// part of the function signature, the patterns are not (they don't change
/// the external type of the function).
Expand Down Expand Up @@ -118,7 +121,8 @@ impl Body {
let _p = profile::span("body_with_source_map_query");
let mut params = None;

let (file_id, module, body, is_async_fn) = {
let mut is_async_fn = false;
let InFile { file_id, value: body } = {
match def {
DefWithBodyId::FunctionId(f) => {
let data = db.function_data(f);
Expand All @@ -138,31 +142,27 @@ impl Body {
}),
)
});
(
src.file_id,
f.module(db),
src.value.body().map(ast::Expr::from),
data.has_async_kw(),
)
is_async_fn = data.has_async_kw();
src.map(|it| it.body().map(ast::Expr::from))
}
DefWithBodyId::ConstId(c) => {
let c = c.lookup(db);
let src = c.source(db);
(src.file_id, c.module(db), src.value.body(), false)
src.map(|it| it.body())
}
DefWithBodyId::StaticId(s) => {
let s = s.lookup(db);
let src = s.source(db);
(src.file_id, s.module(db), src.value.body(), false)
src.map(|it| it.body())
}
DefWithBodyId::VariantId(v) => {
let e = v.parent.lookup(db);
let src = v.parent.child_source(db);
let variant = &src.value[v.local_id];
(src.file_id, e.container, variant.expr(), false)
src.map(|it| it[v.local_id].expr())
}
DefWithBodyId::InTypeConstId(c) => c.lookup(db).id.map(|_| c.source(db).expr()),
}
};
let module = def.module(db);
let expander = Expander::new(db, file_id, module);
let (mut body, source_map) =
Body::new(db, def, expander, params, body, module.krate, is_async_fn);
Expand Down Expand Up @@ -209,14 +209,24 @@ impl Body {
}

fn shrink_to_fit(&mut self) {
let Self { _c: _, body_expr: _, block_scopes, exprs, labels, params, pats, bindings } =
self;
let Self {
_c: _,
body_expr: _,
block_scopes,
exprs,
labels,
params,
pats,
bindings,
binding_owners,
} = self;
block_scopes.shrink_to_fit();
exprs.shrink_to_fit();
labels.shrink_to_fit();
params.shrink_to_fit();
pats.shrink_to_fit();
bindings.shrink_to_fit();
binding_owners.shrink_to_fit();
}

pub fn walk_bindings_in_pat(&self, pat_id: PatId, mut f: impl FnMut(BindingId)) {
Expand Down Expand Up @@ -260,6 +270,17 @@ impl Body {
f(pat_id);
self.walk_pats_shallow(pat_id, |p| self.walk_pats(p, f));
}

pub fn is_binding_upvar(&self, binding: BindingId, relative_to: ExprId) -> bool {
match self.binding_owners.get(&binding) {
Some(x) => {
// We assign expression ids in a way that outer closures will receive
// a lower id
x.into_raw() < relative_to.into_raw()
}
None => true,
}
}
}

impl Default for Body {
Expand All @@ -272,6 +293,7 @@ impl Default for Body {
labels: Default::default(),
params: Default::default(),
block_scopes: Default::default(),
binding_owners: Default::default(),
_c: Default::default(),
}
}
Expand Down
Loading

0 comments on commit 3c9e070

Please sign in to comment.