diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/hir_def/src/path.rs | 2 | ||||
-rw-r--r-- | crates/hir_expand/src/hygiene.rs | 2 | ||||
-rw-r--r-- | crates/ide/src/references.rs | 20 | ||||
-rw-r--r-- | crates/mbe/src/syntax_bridge.rs | 4 | ||||
-rw-r--r-- | crates/proc_macro_srv/src/tests/fixtures/test_serialize_proc_macro.txt | 8 | ||||
-rw-r--r-- | crates/profile/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/profile/src/memory_usage.rs | 7 | ||||
-rw-r--r-- | crates/rust-analyzer/Cargo.toml | 6 | ||||
-rw-r--r-- | crates/rust-analyzer/src/bin/main.rs | 4 |
9 files changed, 48 insertions, 7 deletions
diff --git a/crates/hir_def/src/path.rs b/crates/hir_def/src/path.rs index 3dd7c3cbb..e34cd7f2f 100644 --- a/crates/hir_def/src/path.rs +++ b/crates/hir_def/src/path.rs | |||
@@ -87,7 +87,7 @@ impl ModPath { | |||
87 | 87 | ||
88 | /// If this path is a single identifier, like `foo`, return its name. | 88 | /// If this path is a single identifier, like `foo`, return its name. |
89 | pub fn as_ident(&self) -> Option<&Name> { | 89 | pub fn as_ident(&self) -> Option<&Name> { |
90 | if self.kind != PathKind::Plain || self.segments.len() > 1 { | 90 | if !self.is_ident() { |
91 | return None; | 91 | return None; |
92 | } | 92 | } |
93 | self.segments.first() | 93 | self.segments.first() |
diff --git a/crates/hir_expand/src/hygiene.rs b/crates/hir_expand/src/hygiene.rs index 8db581b77..c8ea81210 100644 --- a/crates/hir_expand/src/hygiene.rs +++ b/crates/hir_expand/src/hygiene.rs | |||
@@ -76,6 +76,8 @@ pub struct HygieneFrame { | |||
76 | 76 | ||
77 | impl HygieneFrames { | 77 | impl HygieneFrames { |
78 | fn new(db: &dyn AstDatabase, file_id: HirFileId) -> Self { | 78 | fn new(db: &dyn AstDatabase, file_id: HirFileId) -> Self { |
79 | // Note that this intentionally avoids the `hygiene_frame` query to avoid blowing up memory | ||
80 | // usage. The query is only helpful for nested `HygieneFrame`s as it avoids redundant work. | ||
79 | HygieneFrames(Arc::new(HygieneFrame::new(db, file_id))) | 81 | HygieneFrames(Arc::new(HygieneFrame::new(db, file_id))) |
80 | } | 82 | } |
81 | 83 | ||
diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs index 51a2f4327..df9c31aef 100644 --- a/crates/ide/src/references.rs +++ b/crates/ide/src/references.rs | |||
@@ -930,6 +930,26 @@ impl Foo { | |||
930 | ); | 930 | ); |
931 | } | 931 | } |
932 | 932 | ||
933 | #[test] | ||
934 | fn test_find_self_refs_decl() { | ||
935 | check( | ||
936 | r#" | ||
937 | struct Foo { bar: i32 } | ||
938 | |||
939 | impl Foo { | ||
940 | fn foo(self$0) { | ||
941 | self; | ||
942 | } | ||
943 | } | ||
944 | "#, | ||
945 | expect![[r#" | ||
946 | self SelfParam FileId(0) 47..51 47..51 SelfParam | ||
947 | |||
948 | FileId(0) 63..67 Other Read | ||
949 | "#]], | ||
950 | ); | ||
951 | } | ||
952 | |||
933 | fn check(ra_fixture: &str, expect: Expect) { | 953 | fn check(ra_fixture: &str, expect: Expect) { |
934 | check_with_scope(ra_fixture, None, expect) | 954 | check_with_scope(ra_fixture, None, expect) |
935 | } | 955 | } |
diff --git a/crates/mbe/src/syntax_bridge.rs b/crates/mbe/src/syntax_bridge.rs index e648519f9..2a41d8167 100644 --- a/crates/mbe/src/syntax_bridge.rs +++ b/crates/mbe/src/syntax_bridge.rs | |||
@@ -51,6 +51,7 @@ pub fn syntax_node_to_token_tree(node: &SyntaxNode) -> Option<(tt::Subtree, Toke | |||
51 | let global_offset = node.text_range().start(); | 51 | let global_offset = node.text_range().start(); |
52 | let mut c = Convertor::new(node, global_offset); | 52 | let mut c = Convertor::new(node, global_offset); |
53 | let subtree = c.go()?; | 53 | let subtree = c.go()?; |
54 | c.id_alloc.map.entries.shrink_to_fit(); | ||
54 | Some((subtree, c.id_alloc.map)) | 55 | Some((subtree, c.id_alloc.map)) |
55 | } | 56 | } |
56 | 57 | ||
@@ -593,7 +594,8 @@ impl<'a> TtTreeSink<'a> { | |||
593 | } | 594 | } |
594 | } | 595 | } |
595 | 596 | ||
596 | fn finish(self) -> (Parse<SyntaxNode>, TokenMap) { | 597 | fn finish(mut self) -> (Parse<SyntaxNode>, TokenMap) { |
598 | self.token_map.entries.shrink_to_fit(); | ||
597 | (self.inner.finish(), self.token_map) | 599 | (self.inner.finish(), self.token_map) |
598 | } | 600 | } |
599 | } | 601 | } |
diff --git a/crates/proc_macro_srv/src/tests/fixtures/test_serialize_proc_macro.txt b/crates/proc_macro_srv/src/tests/fixtures/test_serialize_proc_macro.txt index e6fd21610..ea34e688f 100644 --- a/crates/proc_macro_srv/src/tests/fixtures/test_serialize_proc_macro.txt +++ b/crates/proc_macro_srv/src/tests/fixtures/test_serialize_proc_macro.txt | |||
@@ -59,7 +59,7 @@ SUBTREE $ | |||
59 | IDENT _serde 4294967295 | 59 | IDENT _serde 4294967295 |
60 | PUNCH : [joint] 4294967295 | 60 | PUNCH : [joint] 4294967295 |
61 | PUNCH : [alone] 4294967295 | 61 | PUNCH : [alone] 4294967295 |
62 | IDENT export 4294967295 | 62 | IDENT __private 4294967295 |
63 | PUNCH : [joint] 4294967295 | 63 | PUNCH : [joint] 4294967295 |
64 | PUNCH : [alone] 4294967295 | 64 | PUNCH : [alone] 4294967295 |
65 | IDENT Ok 4294967295 | 65 | IDENT Ok 4294967295 |
@@ -72,7 +72,7 @@ SUBTREE $ | |||
72 | IDENT _serde 4294967295 | 72 | IDENT _serde 4294967295 |
73 | PUNCH : [joint] 4294967295 | 73 | PUNCH : [joint] 4294967295 |
74 | PUNCH : [alone] 4294967295 | 74 | PUNCH : [alone] 4294967295 |
75 | IDENT export 4294967295 | 75 | IDENT __private 4294967295 |
76 | PUNCH : [joint] 4294967295 | 76 | PUNCH : [joint] 4294967295 |
77 | PUNCH : [alone] 4294967295 | 77 | PUNCH : [alone] 4294967295 |
78 | IDENT Err 4294967295 | 78 | IDENT Err 4294967295 |
@@ -85,7 +85,7 @@ SUBTREE $ | |||
85 | IDENT _serde 4294967295 | 85 | IDENT _serde 4294967295 |
86 | PUNCH : [joint] 4294967295 | 86 | PUNCH : [joint] 4294967295 |
87 | PUNCH : [alone] 4294967295 | 87 | PUNCH : [alone] 4294967295 |
88 | IDENT export 4294967295 | 88 | IDENT __private 4294967295 |
89 | PUNCH : [joint] 4294967295 | 89 | PUNCH : [joint] 4294967295 |
90 | PUNCH : [alone] 4294967295 | 90 | PUNCH : [alone] 4294967295 |
91 | IDENT Err 4294967295 | 91 | IDENT Err 4294967295 |
@@ -120,7 +120,7 @@ SUBTREE $ | |||
120 | IDENT _serde 4294967295 | 120 | IDENT _serde 4294967295 |
121 | PUNCH : [joint] 4294967295 | 121 | PUNCH : [joint] 4294967295 |
122 | PUNCH : [alone] 4294967295 | 122 | PUNCH : [alone] 4294967295 |
123 | IDENT export 4294967295 | 123 | IDENT __private 4294967295 |
124 | PUNCH : [joint] 4294967295 | 124 | PUNCH : [joint] 4294967295 |
125 | PUNCH : [alone] 4294967295 | 125 | PUNCH : [alone] 4294967295 |
126 | IDENT Result 4294967295 | 126 | IDENT Result 4294967295 |
diff --git a/crates/profile/Cargo.toml b/crates/profile/Cargo.toml index 9c7ce26be..f7231c2b8 100644 --- a/crates/profile/Cargo.toml +++ b/crates/profile/Cargo.toml | |||
@@ -14,12 +14,14 @@ once_cell = "1.3.1" | |||
14 | cfg-if = "1" | 14 | cfg-if = "1" |
15 | libc = "0.2.73" | 15 | libc = "0.2.73" |
16 | la-arena = { version = "0.2.0", path = "../../lib/arena" } | 16 | la-arena = { version = "0.2.0", path = "../../lib/arena" } |
17 | jemalloc-ctl = { version = "0.3.3", optional = true } | ||
17 | 18 | ||
18 | [target.'cfg(target_os = "linux")'.dependencies] | 19 | [target.'cfg(target_os = "linux")'.dependencies] |
19 | perf-event = "0.4" | 20 | perf-event = "0.4" |
20 | 21 | ||
21 | [features] | 22 | [features] |
22 | cpu_profiler = [] | 23 | cpu_profiler = [] |
24 | jemalloc = ["jemalloc-ctl"] | ||
23 | 25 | ||
24 | # Uncomment to enable for the whole crate graph | 26 | # Uncomment to enable for the whole crate graph |
25 | # default = [ "cpu_profiler" ] | 27 | # default = [ "cpu_profiler" ] |
diff --git a/crates/profile/src/memory_usage.rs b/crates/profile/src/memory_usage.rs index 83390212a..cb4e54447 100644 --- a/crates/profile/src/memory_usage.rs +++ b/crates/profile/src/memory_usage.rs | |||
@@ -24,7 +24,12 @@ impl std::ops::Sub for MemoryUsage { | |||
24 | impl MemoryUsage { | 24 | impl MemoryUsage { |
25 | pub fn current() -> MemoryUsage { | 25 | pub fn current() -> MemoryUsage { |
26 | cfg_if! { | 26 | cfg_if! { |
27 | if #[cfg(all(target_os = "linux", target_env = "gnu"))] { | 27 | if #[cfg(all(feature = "jemalloc", not(target_env = "msvc")))] { |
28 | jemalloc_ctl::epoch::advance().unwrap(); | ||
29 | MemoryUsage { | ||
30 | allocated: Bytes(jemalloc_ctl::stats::allocated::read().unwrap() as isize), | ||
31 | } | ||
32 | } else if #[cfg(all(target_os = "linux", target_env = "gnu"))] { | ||
28 | // Note: This is incredibly slow. | 33 | // Note: This is incredibly slow. |
29 | let alloc = unsafe { libc::mallinfo() }.uordblks as isize; | 34 | let alloc = unsafe { libc::mallinfo() }.uordblks as isize; |
30 | MemoryUsage { allocated: Bytes(alloc) } | 35 | MemoryUsage { allocated: Bytes(alloc) } |
diff --git a/crates/rust-analyzer/Cargo.toml b/crates/rust-analyzer/Cargo.toml index af7b86ead..3cb45b030 100644 --- a/crates/rust-analyzer/Cargo.toml +++ b/crates/rust-analyzer/Cargo.toml | |||
@@ -61,8 +61,14 @@ proc_macro_srv = { path = "../proc_macro_srv", version = "0.0.0" } | |||
61 | [target.'cfg(windows)'.dependencies] | 61 | [target.'cfg(windows)'.dependencies] |
62 | winapi = "0.3.8" | 62 | winapi = "0.3.8" |
63 | 63 | ||
64 | [target.'cfg(not(target_env = "msvc"))'.dependencies] | ||
65 | jemallocator = { version = "0.3.2", optional = true } | ||
66 | |||
64 | [dev-dependencies] | 67 | [dev-dependencies] |
65 | expect-test = "1.1" | 68 | expect-test = "1.1" |
66 | test_utils = { path = "../test_utils" } | 69 | test_utils = { path = "../test_utils" } |
67 | mbe = { path = "../mbe" } | 70 | mbe = { path = "../mbe" } |
68 | tt = { path = "../tt" } | 71 | tt = { path = "../tt" } |
72 | |||
73 | [features] | ||
74 | jemalloc = ["jemallocator", "profile/jemalloc"] | ||
diff --git a/crates/rust-analyzer/src/bin/main.rs b/crates/rust-analyzer/src/bin/main.rs index bf42654a8..2f7f94a39 100644 --- a/crates/rust-analyzer/src/bin/main.rs +++ b/crates/rust-analyzer/src/bin/main.rs | |||
@@ -15,6 +15,10 @@ use vfs::AbsPathBuf; | |||
15 | #[global_allocator] | 15 | #[global_allocator] |
16 | static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc; | 16 | static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc; |
17 | 17 | ||
18 | #[cfg(all(feature = "jemalloc", not(target_env = "msvc")))] | ||
19 | #[global_allocator] | ||
20 | static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; | ||
21 | |||
18 | fn main() { | 22 | fn main() { |
19 | if let Err(err) = try_main() { | 23 | if let Err(err) = try_main() { |
20 | eprintln!("{}", err); | 24 | eprintln!("{}", err); |