Skip to content

Commit dedf9d3

Browse files
authored
Rollup merge of #40554 - nrc:rls-data, r=alexcrichton
Use rls-data crate This basically pulls out a bunch of data structures used by save-analysis for serialization into an external crate, and pulls that crate in using Rustbuild. The RLS can then share these data structures with the compiler which in some cases will allow more efficient communication between the compiler and the RLS (i.e., without serialisation). Along the way, I have to pull in rls-span, which is the RLS's way of defining spans (more type-safe than the compiler's built-in way). This is basically just to convert from compiler spans to RLS spans. I also pull in the crates.io version of rustc-serialize, which is a bit annoying, but seems to be the only way to have serialisable data in an external crate. To make this work, all of the save-analysis crate has to use this version too (cc #40527). Finally I pull in a line from #40347 to make the unstable crate checking stuff working. There are a lot of changes to save-analysis but they are all mechanical and trivial - changing from using `From` to `Into` (because of orphan rules) being the main thing. r? @alexcrichton
2 parents 7471d97 + 1d93a6c commit dedf9d3

File tree

12 files changed

+558
-813
lines changed

12 files changed

+558
-813
lines changed

src/Cargo.lock

Lines changed: 61 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bootstrap/bin/rustc.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ fn main() {
9494
cmd.arg("-Cprefer-dynamic");
9595
}
9696

97+
// Pass the `rustbuild` feature flag to crates which rustbuild is
98+
// building. See the comment in bootstrap/lib.rs where this env var is
99+
// set for more details.
100+
if env::var_os("RUSTBUILD_UNSTABLE").is_some() {
101+
cmd.arg("--cfg").arg("rustbuild");
102+
}
103+
97104
// Help the libc crate compile by assisting it in finding the MUSL
98105
// native libraries.
99106
if let Some(s) = env::var_os("MUSL_ROOT") {

src/bootstrap/lib.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ struct Crate {
180180
///
181181
/// These entries currently correspond to the various output directories of the
182182
/// build system, with each mod generating output in a different directory.
183-
#[derive(Clone, Copy)]
183+
#[derive(Clone, Copy, PartialEq, Eq)]
184184
pub enum Mode {
185185
/// This cargo is going to build the standard library, placing output in the
186186
/// "stageN-std" directory.
@@ -491,14 +491,35 @@ impl Build {
491491
// For other crates, however, we know that we've already got a standard
492492
// library up and running, so we can use the normal compiler to compile
493493
// build scripts in that situation.
494-
if let Mode::Libstd = mode {
494+
if mode == Mode::Libstd {
495495
cargo.env("RUSTC_SNAPSHOT", &self.rustc)
496496
.env("RUSTC_SNAPSHOT_LIBDIR", self.rustc_snapshot_libdir());
497497
} else {
498498
cargo.env("RUSTC_SNAPSHOT", self.compiler_path(compiler))
499499
.env("RUSTC_SNAPSHOT_LIBDIR", self.rustc_libdir(compiler));
500500
}
501501

502+
// There are two invariants we try must maintain:
503+
// * stable crates cannot depend on unstable crates (general Rust rule),
504+
// * crates that end up in the sysroot must be unstable (rustbuild rule).
505+
//
506+
// In order to do enforce the latter, we pass the env var
507+
// `RUSTBUILD_UNSTABLE` down the line for any crates which will end up
508+
// in the sysroot. We read this in bootstrap/bin/rustc.rs and if it is
509+
// set, then we pass the `rustbuild` feature to rustc when building the
510+
// the crate.
511+
//
512+
// In turn, crates that can be used here should recognise the `rustbuild`
513+
// feature and opt-in to `rustc_private`.
514+
//
515+
// We can't always pass `rustbuild` because crates which are outside of
516+
// the comipiler, libs, and tests are stable and we don't want to make
517+
// their deps unstable (since this would break the first invariant
518+
// above).
519+
if mode != Mode::Tool {
520+
cargo.env("RUSTBUILD_UNSTABLE", "1");
521+
}
522+
502523
// Ignore incremental modes except for stage0, since we're
503524
// not guaranteeing correctness acros builds if the compiler
504525
// is changing under your feet.`

src/librustc_save_analysis/Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@ crate-type = ["dylib"]
1212
log = { path = "../liblog" }
1313
rustc = { path = "../librustc" }
1414
syntax = { path = "../libsyntax" }
15-
serialize = { path = "../libserialize" }
16-
syntax_pos = { path = "../libsyntax_pos" }
15+
syntax_pos = { path = "../libsyntax_pos" }
16+
rls-data = "0.1"
17+
rls-span = "0.1"
18+
# FIXME(#40527) should move rustc serialize out of tree
19+
rustc-serialize = "0.3"

src/librustc_save_analysis/csv_dumper.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ use std::io::Write;
1313
use super::external_data::*;
1414
use super::dump::Dump;
1515

16+
use rls_data::{SpanData, CratePreludeData};
17+
1618
pub struct CsvDumper<'b, W: 'b> {
1719
output: &'b mut W
1820
}
@@ -429,6 +431,6 @@ fn make_values_str(pairs: &[(&'static str, &str)]) -> String {
429431
fn span_extent_str(span: SpanData) -> String {
430432
format!("file_name,\"{}\",file_line,{},file_col,{},byte_start,{},\
431433
file_line_end,{},file_col_end,{},byte_end,{}",
432-
span.file_name, span.line_start, span.column_start, span.byte_start,
433-
span.line_end, span.column_end, span.byte_end)
434+
span.file_name.to_str().unwrap(), span.line_start.0, span.column_start.0,
435+
span.byte_start, span.line_end.0, span.column_end.0, span.byte_end)
434436
}

0 commit comments

Comments
 (0)