diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-04-17 10:40:53 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-04-17 10:40:53 +0100 |
commit | 46105cdaba049239d2815489f4beeedfec5be9d7 (patch) | |
tree | 4d7889724d34ee56d472ee540e3b88adb995acf5 | |
parent | f8016b81940f27fc4794ce75d2e7670944ef1f97 (diff) | |
parent | 93fcf1c133f1a473ac598e4811e88ee91d979510 (diff) |
Merge #4004
4004: Use mmap for proc macro libs r=matklad a=lnicola
Fixes #4002.
Co-authored-by: Laurențiu Nicola <[email protected]>
-rw-r--r-- | Cargo.lock | 11 | ||||
-rw-r--r-- | crates/ra_proc_macro_srv/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_proc_macro_srv/src/dylib.rs | 7 |
3 files changed, 17 insertions, 2 deletions
diff --git a/Cargo.lock b/Cargo.lock index 89a734c9b..3826ae1c6 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -676,6 +676,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
676 | checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" | 676 | checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" |
677 | 677 | ||
678 | [[package]] | 678 | [[package]] |
679 | name = "memmap" | ||
680 | version = "0.7.0" | ||
681 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
682 | checksum = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b" | ||
683 | dependencies = [ | ||
684 | "libc", | ||
685 | "winapi 0.3.8", | ||
686 | ] | ||
687 | |||
688 | [[package]] | ||
679 | name = "memoffset" | 689 | name = "memoffset" |
680 | version = "0.5.4" | 690 | version = "0.5.4" |
681 | source = "registry+https://github.com/rust-lang/crates.io-index" | 691 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -1112,6 +1122,7 @@ dependencies = [ | |||
1112 | "difference", | 1122 | "difference", |
1113 | "goblin", | 1123 | "goblin", |
1114 | "libloading", | 1124 | "libloading", |
1125 | "memmap", | ||
1115 | "ra_mbe", | 1126 | "ra_mbe", |
1116 | "ra_proc_macro", | 1127 | "ra_proc_macro", |
1117 | "ra_tt", | 1128 | "ra_tt", |
diff --git a/crates/ra_proc_macro_srv/Cargo.toml b/crates/ra_proc_macro_srv/Cargo.toml index 1e0f50339..ac2d156dc 100644 --- a/crates/ra_proc_macro_srv/Cargo.toml +++ b/crates/ra_proc_macro_srv/Cargo.toml | |||
@@ -14,6 +14,7 @@ ra_mbe = { path = "../ra_mbe" } | |||
14 | ra_proc_macro = { path = "../ra_proc_macro" } | 14 | ra_proc_macro = { path = "../ra_proc_macro" } |
15 | goblin = "0.2.1" | 15 | goblin = "0.2.1" |
16 | libloading = "0.6.0" | 16 | libloading = "0.6.0" |
17 | memmap = "0.7" | ||
17 | test_utils = { path = "../test_utils" } | 18 | test_utils = { path = "../test_utils" } |
18 | 19 | ||
19 | [dev-dependencies] | 20 | [dev-dependencies] |
diff --git a/crates/ra_proc_macro_srv/src/dylib.rs b/crates/ra_proc_macro_srv/src/dylib.rs index 7d6e5d323..16bd7466e 100644 --- a/crates/ra_proc_macro_srv/src/dylib.rs +++ b/crates/ra_proc_macro_srv/src/dylib.rs | |||
@@ -1,10 +1,12 @@ | |||
1 | //! Handles dynamic library loading for proc macro | 1 | //! Handles dynamic library loading for proc macro |
2 | 2 | ||
3 | use crate::{proc_macro::bridge, rustc_server::TokenStream}; | 3 | use crate::{proc_macro::bridge, rustc_server::TokenStream}; |
4 | use std::fs::File; | ||
4 | use std::path::Path; | 5 | use std::path::Path; |
5 | 6 | ||
6 | use goblin::{mach::Mach, Object}; | 7 | use goblin::{mach::Mach, Object}; |
7 | use libloading::Library; | 8 | use libloading::Library; |
9 | use memmap::Mmap; | ||
8 | use ra_proc_macro::ProcMacroKind; | 10 | use ra_proc_macro::ProcMacroKind; |
9 | 11 | ||
10 | use std::io::Error as IoError; | 12 | use std::io::Error as IoError; |
@@ -21,7 +23,8 @@ fn is_derive_registrar_symbol(symbol: &str) -> bool { | |||
21 | } | 23 | } |
22 | 24 | ||
23 | fn find_registrar_symbol(file: &Path) -> Result<Option<String>, IoError> { | 25 | fn find_registrar_symbol(file: &Path) -> Result<Option<String>, IoError> { |
24 | let buffer = std::fs::read(file)?; | 26 | let file = File::open(file)?; |
27 | let buffer = unsafe { Mmap::map(&file)? }; | ||
25 | let object = Object::parse(&buffer).map_err(invalid_data_err)?; | 28 | let object = Object::parse(&buffer).map_err(invalid_data_err)?; |
26 | 29 | ||
27 | match object { | 30 | match object { |
@@ -55,7 +58,7 @@ fn find_registrar_symbol(file: &Path) -> Result<Option<String>, IoError> { | |||
55 | &s.name | 58 | &s.name |
56 | } | 59 | } |
57 | }) | 60 | }) |
58 | .find(|s| is_derive_registrar_symbol(&s)) | 61 | .find(|s| is_derive_registrar_symbol(s)) |
59 | .map(|s| s.to_string()); | 62 | .map(|s| s.to_string()); |
60 | Ok(name) | 63 | Ok(name) |
61 | } | 64 | } |