aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock133
-rw-r--r--crates/hir_def/src/path.rs2
-rw-r--r--crates/hir_expand/src/hygiene.rs2
-rw-r--r--crates/ide/src/references.rs20
-rw-r--r--crates/mbe/src/syntax_bridge.rs4
-rw-r--r--crates/proc_macro_srv/src/tests/fixtures/test_serialize_proc_macro.txt8
-rw-r--r--crates/profile/Cargo.toml2
-rw-r--r--crates/profile/src/memory_usage.rs7
-rw-r--r--crates/rust-analyzer/Cargo.toml6
-rw-r--r--crates/rust-analyzer/src/bin/main.rs4
-rw-r--r--xtask/src/install.rs2
-rw-r--r--xtask/src/main.rs12
12 files changed, 158 insertions, 44 deletions
diff --git a/Cargo.lock b/Cargo.lock
index aac473191..35713a0c4 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -26,9 +26,9 @@ dependencies = [
26 26
27[[package]] 27[[package]]
28name = "anyhow" 28name = "anyhow"
29version = "1.0.37" 29version = "1.0.38"
30source = "registry+https://github.com/rust-lang/crates.io-index" 30source = "registry+https://github.com/rust-lang/crates.io-index"
31checksum = "ee67c11feeac938fae061b232e38e0b6d94f97a9df10e6271319325ac4c56a86" 31checksum = "afddf7f520a80dbf76e6f50a35bca42a2331ef227a28b3b6dc5c2e2338d114b1"
32 32
33[[package]] 33[[package]]
34name = "anymap" 34name = "anymap"
@@ -118,9 +118,9 @@ checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
118 118
119[[package]] 119[[package]]
120name = "byteorder" 120name = "byteorder"
121version = "1.3.4" 121version = "1.4.2"
122source = "registry+https://github.com/rust-lang/crates.io-index" 122source = "registry+https://github.com/rust-lang/crates.io-index"
123checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" 123checksum = "ae44d1a3d5a19df61dd0c8beb138458ac2a53a7ac09eba97d55592540004306b"
124 124
125[[package]] 125[[package]]
126name = "cargo-platform" 126name = "cargo-platform"
@@ -133,9 +133,9 @@ dependencies = [
133 133
134[[package]] 134[[package]]
135name = "cargo_metadata" 135name = "cargo_metadata"
136version = "0.12.2" 136version = "0.12.3"
137source = "registry+https://github.com/rust-lang/crates.io-index" 137source = "registry+https://github.com/rust-lang/crates.io-index"
138checksum = "11a47b6286279a9998588ef7050d1ebc2500c69892a557c90fe5d071c64415dc" 138checksum = "7714a157da7991e23d90686b9524b9e12e0407a108647f52e9328f4b3d51ac7f"
139dependencies = [ 139dependencies = [
140 "cargo-platform", 140 "cargo-platform",
141 "semver", 141 "semver",
@@ -269,9 +269,9 @@ dependencies = [
269 269
270[[package]] 270[[package]]
271name = "const_fn" 271name = "const_fn"
272version = "0.4.4" 272version = "0.4.5"
273source = "registry+https://github.com/rust-lang/crates.io-index" 273source = "registry+https://github.com/rust-lang/crates.io-index"
274checksum = "cd51eab21ab4fd6a3bf889e2d0958c0a6e3a61ad04260325e919e652a2a62826" 274checksum = "28b9d6de7f49e22cf97ad17fc4036ece69300032f45f78f30b4a4482cdc3f4a6"
275 275
276[[package]] 276[[package]]
277name = "crc32fast" 277name = "crc32fast"
@@ -449,6 +449,12 @@ dependencies = [
449] 449]
450 450
451[[package]] 451[[package]]
452name = "fs_extra"
453version = "1.2.0"
454source = "registry+https://github.com/rust-lang/crates.io-index"
455checksum = "2022715d62ab30faffd124d40b76f4134a550a87792276512b18d63272333394"
456
457[[package]]
452name = "fsevent" 458name = "fsevent"
453version = "2.0.2" 459version = "2.0.2"
454source = "registry+https://github.com/rust-lang/crates.io-index" 460source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -518,9 +524,9 @@ dependencies = [
518 524
519[[package]] 525[[package]]
520name = "hermit-abi" 526name = "hermit-abi"
521version = "0.1.17" 527version = "0.1.18"
522source = "registry+https://github.com/rust-lang/crates.io-index" 528source = "registry+https://github.com/rust-lang/crates.io-index"
523checksum = "5aca5565f760fb5b220e499d72710ed156fdb74e631659e99377d9ebfbd13ae8" 529checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c"
524dependencies = [ 530dependencies = [
525 "libc", 531 "libc",
526] 532]
@@ -708,9 +714,9 @@ dependencies = [
708 714
709[[package]] 715[[package]]
710name = "inotify-sys" 716name = "inotify-sys"
711version = "0.1.4" 717version = "0.1.5"
712source = "registry+https://github.com/rust-lang/crates.io-index" 718source = "registry+https://github.com/rust-lang/crates.io-index"
713checksum = "c4563555856585ab3180a5bf0b2f9f8d301a728462afffc8195b3f5394229c55" 719checksum = "e05c02b5e89bff3b946cedeca278abc628fe811e604f027c45a8aa3cf793d0eb"
714dependencies = [ 720dependencies = [
715 "libc", 721 "libc",
716] 722]
@@ -758,6 +764,38 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
758checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" 764checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736"
759 765
760[[package]] 766[[package]]
767name = "jemalloc-ctl"
768version = "0.3.3"
769source = "registry+https://github.com/rust-lang/crates.io-index"
770checksum = "c502a5ff9dd2924f1ed32ba96e3b65735d837b4bfd978d3161b1702e66aca4b7"
771dependencies = [
772 "jemalloc-sys",
773 "libc",
774 "paste",
775]
776
777[[package]]
778name = "jemalloc-sys"
779version = "0.3.2"
780source = "registry+https://github.com/rust-lang/crates.io-index"
781checksum = "0d3b9f3f5c9b31aa0f5ed3260385ac205db665baa41d49bb8338008ae94ede45"
782dependencies = [
783 "cc",
784 "fs_extra",
785 "libc",
786]
787
788[[package]]
789name = "jemallocator"
790version = "0.3.2"
791source = "registry+https://github.com/rust-lang/crates.io-index"
792checksum = "43ae63fcfc45e99ab3d1b29a46782ad679e98436c3169d15a167a1108a724b69"
793dependencies = [
794 "jemalloc-sys",
795 "libc",
796]
797
798[[package]]
761name = "jod-thread" 799name = "jod-thread"
762version = "0.1.2" 800version = "0.1.2"
763source = "registry+https://github.com/rust-lang/crates.io-index" 801source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -791,15 +829,15 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
791 829
792[[package]] 830[[package]]
793name = "libc" 831name = "libc"
794version = "0.2.81" 832version = "0.2.82"
795source = "registry+https://github.com/rust-lang/crates.io-index" 833source = "registry+https://github.com/rust-lang/crates.io-index"
796checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb" 834checksum = "89203f3fba0a3795506acaad8ebce3c80c0af93f994d5a1d7a0b1eeb23271929"
797 835
798[[package]] 836[[package]]
799name = "libloading" 837name = "libloading"
800version = "0.6.6" 838version = "0.6.7"
801source = "registry+https://github.com/rust-lang/crates.io-index" 839source = "registry+https://github.com/rust-lang/crates.io-index"
802checksum = "e9367bdfa836b7e3cf895867f7a570283444da90562980ec2263d6e1569b16bc" 840checksum = "351a32417a12d5f7e82c368a66781e307834dae04c6ce0cd4456d52989229883"
803dependencies = [ 841dependencies = [
804 "cfg-if 1.0.0", 842 "cfg-if 1.0.0",
805 "winapi 0.3.9", 843 "winapi 0.3.9",
@@ -825,9 +863,9 @@ dependencies = [
825 863
826[[package]] 864[[package]]
827name = "log" 865name = "log"
828version = "0.4.11" 866version = "0.4.13"
829source = "registry+https://github.com/rust-lang/crates.io-index" 867source = "registry+https://github.com/rust-lang/crates.io-index"
830checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" 868checksum = "fcf3805d4480bb5b86070dcfeb9e2cb2ebc148adb753c5cca5f884d1d65a42b2"
831dependencies = [ 869dependencies = [
832 "cfg-if 0.1.10", 870 "cfg-if 0.1.10",
833] 871]
@@ -1105,6 +1143,25 @@ dependencies = [
1105] 1143]
1106 1144
1107[[package]] 1145[[package]]
1146name = "paste"
1147version = "0.1.18"
1148source = "registry+https://github.com/rust-lang/crates.io-index"
1149checksum = "45ca20c77d80be666aef2b45486da86238fabe33e38306bd3118fe4af33fa880"
1150dependencies = [
1151 "paste-impl",
1152 "proc-macro-hack",
1153]
1154
1155[[package]]
1156name = "paste-impl"
1157version = "0.1.18"
1158source = "registry+https://github.com/rust-lang/crates.io-index"
1159checksum = "d95a7db200b97ef370c8e6de0088252f7e0dfff7d047a28528e47456c0fc98b6"
1160dependencies = [
1161 "proc-macro-hack",
1162]
1163
1164[[package]]
1108name = "paths" 1165name = "paths"
1109version = "0.0.0" 1166version = "0.0.0"
1110 1167
@@ -1160,9 +1217,15 @@ checksum = "28b9b4df73455c861d7cbf8be42f01d3b373ed7f02e378d55fa84eafc6f638b1"
1160 1217
1161[[package]] 1218[[package]]
1162name = "pin-project-lite" 1219name = "pin-project-lite"
1163version = "0.2.0" 1220version = "0.2.4"
1164source = "registry+https://github.com/rust-lang/crates.io-index" 1221source = "registry+https://github.com/rust-lang/crates.io-index"
1165checksum = "6b063f57ec186e6140e2b8b6921e5f1bd89c7356dda5b33acc5401203ca6131c" 1222checksum = "439697af366c49a6d0a010c56a0d97685bc140ce0d377b13a2ea2aa42d64a827"
1223
1224[[package]]
1225name = "proc-macro-hack"
1226version = "0.5.19"
1227source = "registry+https://github.com/rust-lang/crates.io-index"
1228checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5"
1166 1229
1167[[package]] 1230[[package]]
1168name = "proc-macro2" 1231name = "proc-macro2"
@@ -1212,6 +1275,7 @@ name = "profile"
1212version = "0.0.0" 1275version = "0.0.0"
1213dependencies = [ 1276dependencies = [
1214 "cfg-if 1.0.0", 1277 "cfg-if 1.0.0",
1278 "jemalloc-ctl",
1215 "la-arena", 1279 "la-arena",
1216 "libc", 1280 "libc",
1217 "once_cell", 1281 "once_cell",
@@ -1301,9 +1365,9 @@ checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce"
1301 1365
1302[[package]] 1366[[package]]
1303name = "regex" 1367name = "regex"
1304version = "1.4.2" 1368version = "1.4.3"
1305source = "registry+https://github.com/rust-lang/crates.io-index" 1369source = "registry+https://github.com/rust-lang/crates.io-index"
1306checksum = "38cf2c13ed4745de91a5eb834e11c00bcc3709e773173b2ce4c56c9fbde04b9c" 1370checksum = "d9251239e129e16308e70d853559389de218ac275b515068abc96829d05b948a"
1307dependencies = [ 1371dependencies = [
1308 "regex-syntax", 1372 "regex-syntax",
1309] 1373]
@@ -1320,9 +1384,9 @@ dependencies = [
1320 1384
1321[[package]] 1385[[package]]
1322name = "regex-syntax" 1386name = "regex-syntax"
1323version = "0.6.21" 1387version = "0.6.22"
1324source = "registry+https://github.com/rust-lang/crates.io-index" 1388source = "registry+https://github.com/rust-lang/crates.io-index"
1325checksum = "3b181ba2dcf07aaccad5448e8ead58db5b742cf85dfe035e2227f137a539a189" 1389checksum = "b5eb417147ba9860a96cfe72a0b93bf88fee1744b5636ec99ab20c1aa9376581"
1326 1390
1327[[package]] 1391[[package]]
1328name = "rowan" 1392name = "rowan"
@@ -1354,6 +1418,7 @@ dependencies = [
1354 "ide", 1418 "ide",
1355 "ide_db", 1419 "ide_db",
1356 "itertools 0.10.0", 1420 "itertools 0.10.0",
1421 "jemallocator",
1357 "jod-thread", 1422 "jod-thread",
1358 "log", 1423 "log",
1359 "lsp-server", 1424 "lsp-server",
@@ -1485,18 +1550,18 @@ dependencies = [
1485 1550
1486[[package]] 1551[[package]]
1487name = "serde" 1552name = "serde"
1488version = "1.0.118" 1553version = "1.0.119"
1489source = "registry+https://github.com/rust-lang/crates.io-index" 1554source = "registry+https://github.com/rust-lang/crates.io-index"
1490checksum = "06c64263859d87aa2eb554587e2d23183398d617427327cf2b3d0ed8c69e4800" 1555checksum = "9bdd36f49e35b61d49efd8aa7fc068fd295961fd2286d0b2ee9a4c7a14e99cc3"
1491dependencies = [ 1556dependencies = [
1492 "serde_derive", 1557 "serde_derive",
1493] 1558]
1494 1559
1495[[package]] 1560[[package]]
1496name = "serde_derive" 1561name = "serde_derive"
1497version = "1.0.118" 1562version = "1.0.119"
1498source = "registry+https://github.com/rust-lang/crates.io-index" 1563source = "registry+https://github.com/rust-lang/crates.io-index"
1499checksum = "c84d3526699cd55261af4b941e4e725444df67aa4f9e6a3564f18030d12672df" 1564checksum = "552954ce79a059ddd5fd68c271592374bd15cab2274970380c000118aeffe1cd"
1500dependencies = [ 1565dependencies = [
1501 "proc-macro2", 1566 "proc-macro2",
1502 "quote", 1567 "quote",
@@ -1552,9 +1617,9 @@ checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
1552 1617
1553[[package]] 1618[[package]]
1554name = "smallvec" 1619name = "smallvec"
1555version = "1.6.0" 1620version = "1.6.1"
1556source = "registry+https://github.com/rust-lang/crates.io-index" 1621source = "registry+https://github.com/rust-lang/crates.io-index"
1557checksum = "1a55ca5f3b68e41c979bf8c46a6f1da892ca4db8f94023ce0bd32407573b1ac0" 1622checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e"
1558 1623
1559[[package]] 1624[[package]]
1560name = "smol_str" 1625name = "smol_str"
@@ -1594,9 +1659,9 @@ dependencies = [
1594 1659
1595[[package]] 1660[[package]]
1596name = "syn" 1661name = "syn"
1597version = "1.0.57" 1662version = "1.0.58"
1598source = "registry+https://github.com/rust-lang/crates.io-index" 1663source = "registry+https://github.com/rust-lang/crates.io-index"
1599checksum = "4211ce9909eb971f111059df92c45640aad50a619cf55cd76476be803c4c68e6" 1664checksum = "cc60a3d73ea6594cd712d830cc1f0390fd71542d8c8cd24e70cc54cdfd5e05d5"
1600dependencies = [ 1665dependencies = [
1601 "proc-macro2", 1666 "proc-macro2",
1602 "quote", 1667 "quote",
@@ -1673,9 +1738,9 @@ dependencies = [
1673 1738
1674[[package]] 1739[[package]]
1675name = "thread_local" 1740name = "thread_local"
1676version = "1.0.1" 1741version = "1.1.0"
1677source = "registry+https://github.com/rust-lang/crates.io-index" 1742source = "registry+https://github.com/rust-lang/crates.io-index"
1678checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" 1743checksum = "bb9bc092d0d51e76b2b19d9d85534ffc9ec2db959a2523cdae0697e2972cd447"
1679dependencies = [ 1744dependencies = [
1680 "lazy_static", 1745 "lazy_static",
1681] 1746]
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
77impl HygieneFrames { 77impl 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#"
937struct Foo { bar: i32 }
938
939impl 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"
14cfg-if = "1" 14cfg-if = "1"
15libc = "0.2.73" 15libc = "0.2.73"
16la-arena = { version = "0.2.0", path = "../../lib/arena" } 16la-arena = { version = "0.2.0", path = "../../lib/arena" }
17jemalloc-ctl = { version = "0.3.3", optional = true }
17 18
18[target.'cfg(target_os = "linux")'.dependencies] 19[target.'cfg(target_os = "linux")'.dependencies]
19perf-event = "0.4" 20perf-event = "0.4"
20 21
21[features] 22[features]
22cpu_profiler = [] 23cpu_profiler = []
24jemalloc = ["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 {
24impl MemoryUsage { 24impl 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]
62winapi = "0.3.8" 62winapi = "0.3.8"
63 63
64[target.'cfg(not(target_env = "msvc"))'.dependencies]
65jemallocator = { version = "0.3.2", optional = true }
66
64[dev-dependencies] 67[dev-dependencies]
65expect-test = "1.1" 68expect-test = "1.1"
66test_utils = { path = "../test_utils" } 69test_utils = { path = "../test_utils" }
67mbe = { path = "../mbe" } 70mbe = { path = "../mbe" }
68tt = { path = "../tt" } 71tt = { path = "../tt" }
72
73[features]
74jemalloc = ["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]
16static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc; 16static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;
17 17
18#[cfg(all(feature = "jemalloc", not(target_env = "msvc")))]
19#[global_allocator]
20static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
21
18fn main() { 22fn main() {
19 if let Err(err) = try_main() { 23 if let Err(err) = try_main() {
20 eprintln!("{}", err); 24 eprintln!("{}", err);
diff --git a/xtask/src/install.rs b/xtask/src/install.rs
index 12962bcfa..202c74426 100644
--- a/xtask/src/install.rs
+++ b/xtask/src/install.rs
@@ -67,6 +67,7 @@ pub struct ServerOpt {
67pub enum Malloc { 67pub enum Malloc {
68 System, 68 System,
69 Mimalloc, 69 Mimalloc,
70 Jemalloc,
70} 71}
71 72
72impl InstallCmd { 73impl InstallCmd {
@@ -176,6 +177,7 @@ fn install_server(opts: ServerOpt) -> Result<()> {
176 let features = match opts.malloc { 177 let features = match opts.malloc {
177 Malloc::System => &[][..], 178 Malloc::System => &[][..],
178 Malloc::Mimalloc => &["--features", "mimalloc"], 179 Malloc::Mimalloc => &["--features", "mimalloc"],
180 Malloc::Jemalloc => &["--features", "jemalloc"],
179 }; 181 };
180 182
181 let cmd = cmd!("cargo install --path crates/rust-analyzer --locked --force {features...}"); 183 let cmd = cmd!("cargo install --path crates/rust-analyzer --locked --force {features...}");
diff --git a/xtask/src/main.rs b/xtask/src/main.rs
index dec48629c..c3e5c7326 100644
--- a/xtask/src/main.rs
+++ b/xtask/src/main.rs
@@ -49,7 +49,8 @@ FLAGS:
49 --client[=CLIENT] Install only VS Code plugin. 49 --client[=CLIENT] Install only VS Code plugin.
50 CLIENT is one of 'code', 'code-exploration', 'code-insiders', 'codium', or 'code-oss' 50 CLIENT is one of 'code', 'code-exploration', 'code-insiders', 'codium', or 'code-oss'
51 --server Install only the language server 51 --server Install only the language server
52 --mimalloc Use mimalloc for server 52 --mimalloc Use mimalloc allocator for server
53 --jemalloc Use jemalloc allocator for server
53 -h, --help Prints help information 54 -h, --help Prints help information
54 " 55 "
55 ); 56 );
@@ -65,8 +66,13 @@ FLAGS:
65 return Ok(()); 66 return Ok(());
66 } 67 }
67 68
68 let malloc = 69 let malloc = if args.contains("--mimalloc") {
69 if args.contains("--mimalloc") { Malloc::Mimalloc } else { Malloc::System }; 70 Malloc::Mimalloc
71 } else if args.contains("--jemalloc") {
72 Malloc::Jemalloc
73 } else {
74 Malloc::System
75 };
70 76
71 let client_opt = args.opt_value_from_str("--client")?; 77 let client_opt = args.opt_value_from_str("--client")?;
72 78