diff --git a/src/librustc_data_structures/sync.rs b/src/librustc_data_structures/sync.rs index 73247c1469efd..a7027ebaaee7d 100644 --- a/src/librustc_data_structures/sync.rs +++ b/src/librustc_data_structures/sync.rs @@ -517,7 +517,7 @@ impl Once { } #[derive(Debug)] -pub struct Lock(InnerLock); +pub struct Lock(pub InnerLock); impl Lock { #[inline(always)] diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index 0bbc7c5c4b223..f7fb4d12d1f55 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -715,6 +715,7 @@ impl Tester for Collector { ) }), }); + self.tests.clear(); } fn get_line(&self) -> usize { diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 9905b981395c0..b647a6cabe9e6 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -98,7 +98,18 @@ pub fn with_globals(f: F) -> R { let globals = Globals::new(); GLOBALS.set(&globals, || { - syntax_pos::GLOBALS.set(&globals.syntax_pos_globals, f) + syntax_pos::GLOBALS.set(&globals.syntax_pos_globals, || unsafe { + let init_backdoor = syntax_pos::SPAN_INTERNER_BACKDOOR.is_null(); + if init_backdoor { + syntax_pos::SPAN_INTERNER_BACKDOOR = + globals.syntax_pos_globals.span_interner.0.as_ptr(); + } + let res = f(); + if init_backdoor { + syntax_pos::SPAN_INTERNER_BACKDOOR = std::ptr::null_mut(); + } + res + }) }) } diff --git a/src/libsyntax_pos/hygiene.rs b/src/libsyntax_pos/hygiene.rs index 6331fe608868f..1ffecea44edf2 100644 --- a/src/libsyntax_pos/hygiene.rs +++ b/src/libsyntax_pos/hygiene.rs @@ -218,14 +218,17 @@ pub fn clear_markings() { } impl SyntaxContext { + #[inline] pub const fn empty() -> Self { SyntaxContext(0) } + #[inline] crate fn as_u32(self) -> u32 { self.0 } + #[inline] crate fn from_u32(raw: u32) -> SyntaxContext { SyntaxContext(raw) } diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index db1543ff13f7e..2bf9326fe60bb 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -18,6 +18,7 @@ #![feature(rustc_attrs)] #![feature(specialization)] #![feature(step_trait)] +#![feature(stmt_expr_attributes)] use serialize::{Encodable, Decodable, Encoder, Decoder}; @@ -29,7 +30,7 @@ pub mod hygiene; pub use hygiene::{Mark, SyntaxContext, ExpnInfo, ExpnFormat, CompilerDesugaringKind}; mod span_encoding; -pub use span_encoding::{Span, DUMMY_SP}; +pub use span_encoding::{Span, DUMMY_SP, SPAN_INTERNER_BACKDOOR}; pub mod symbol; @@ -48,7 +49,7 @@ use std::path::PathBuf; pub struct Globals { symbol_interner: Lock, - span_interner: Lock, + pub span_interner: Lock, hygiene_data: Lock, } diff --git a/src/libsyntax_pos/span_encoding.rs b/src/libsyntax_pos/span_encoding.rs index 743e61e3c2236..e1bb1f6ca924f 100644 --- a/src/libsyntax_pos/span_encoding.rs +++ b/src/libsyntax_pos/span_encoding.rs @@ -4,45 +4,19 @@ // The encoding format for inline spans were obtained by optimizing over crates in rustc/libstd. // See https://internals.rust-lang.org/t/rfc-compiler-refactoring-spans/1357/28 -use crate::GLOBALS; use crate::{BytePos, SpanData}; use crate::hygiene::SyntaxContext; use rustc_data_structures::fx::FxHashMap; -use std::hash::{Hash, Hasher}; /// A compressed span. /// Contains either fields of `SpanData` inline if they are small, or index into span interner. /// The primary goal of `Span` is to be as small as possible and fit into other structures /// (that's why it uses `packed` as well). Decoding speed is the second priority. /// See `SpanData` for the info on span fields in decoded representation. -#[repr(packed)] +#[derive(Clone, Copy, Eq, PartialEq, Hash)] pub struct Span(u32); -impl Copy for Span {} -impl Clone for Span { - #[inline] - fn clone(&self) -> Span { - *self - } -} -impl PartialEq for Span { - #[inline] - fn eq(&self, other: &Span) -> bool { - let a = self.0; - let b = other.0; - a == b - } -} -impl Eq for Span {} -impl Hash for Span { - #[inline] - fn hash(&self, state: &mut H) { - let a = self.0; - a.hash(state) - } -} - /// Dummy span, both position and length are zero, syntax context is zero as well. /// This span is kept inline and encoded with format 0. pub const DUMMY_SP: Span = Span(0); @@ -98,7 +72,7 @@ fn encode(sd: &SpanData) -> Span { (base << INLINE_OFFSETS[BASE_INDEX]) | (len << INLINE_OFFSETS[LEN_INDEX]) | (ctxt << INLINE_OFFSETS[CTXT_INDEX]) | TAG_INLINE } else { - let index = with_span_interner(|interner| interner.intern(sd)); + let index = unsafe { (*SPAN_INTERNER_BACKDOOR).intern(sd) }; (index << INTERNED_INDEX_OFFSET) | TAG_INTERNED }; Span(val) @@ -109,7 +83,7 @@ fn decode(span: Span) -> SpanData { let val = span.0; // Extract a field at position `pos` having size `size`. - let extract = |pos: u32, size: u32| { + let extract = #[inline] |pos: u32, size: u32| { let mask = ((!0u32) as u64 >> (32 - size)) as u32; // Can't shift u32 by 32 (val >> pos) & mask }; @@ -120,7 +94,7 @@ fn decode(span: Span) -> SpanData { extract(INLINE_OFFSETS[CTXT_INDEX], INLINE_SIZES[CTXT_INDEX]), )} else { let index = extract(INTERNED_INDEX_OFFSET, INTERNED_INDEX_SIZE); - return with_span_interner(|interner| *interner.get(index)); + return unsafe { *(*SPAN_INTERNER_BACKDOOR).get(index) }; }; SpanData { lo: BytePos(base), hi: BytePos(base + len), ctxt: SyntaxContext::from_u32(ctxt) } } @@ -149,8 +123,4 @@ impl SpanInterner { } } -// If an interner exists, return it. Otherwise, prepare a fresh one. -#[inline] -fn with_span_interner T>(f: F) -> T { - GLOBALS.with(|globals| f(&mut *globals.span_interner.lock())) -} +pub static mut SPAN_INTERNER_BACKDOOR: *mut SpanInterner = std::ptr::null_mut(); diff --git a/src/test/run-make-fulldeps/issue-22131/Makefile b/src/test/run-make-fulldeps/issue-22131/Makefile deleted file mode 100644 index d76aaf5c146db..0000000000000 --- a/src/test/run-make-fulldeps/issue-22131/Makefile +++ /dev/null @@ -1,7 +0,0 @@ --include ../tools.mk - -all: foo.rs - $(RUSTC) --cfg 'feature="bar"' --crate-type lib foo.rs - $(RUSTDOC) --test --cfg 'feature="bar"' \ - -L $(TMPDIR) foo.rs |\ - $(CGREP) 'foo.rs - foo (line 1) ... ok' diff --git a/src/test/run-make-fulldeps/issue-22131/foo.rs b/src/test/run-make-fulldeps/issue-22131/foo.rs deleted file mode 100644 index 33255d76879f3..0000000000000 --- a/src/test/run-make-fulldeps/issue-22131/foo.rs +++ /dev/null @@ -1,5 +0,0 @@ -/// ```rust -/// assert_eq!(foo::foo(), 1); -/// ``` -#[cfg(feature = "bar")] -pub fn foo() -> i32 { 1 } diff --git a/src/test/run-make-fulldeps/rustdoc-error-lines/Makefile b/src/test/run-make-fulldeps/rustdoc-error-lines/Makefile deleted file mode 100644 index e09343aa93790..0000000000000 --- a/src/test/run-make-fulldeps/rustdoc-error-lines/Makefile +++ /dev/null @@ -1,8 +0,0 @@ --include ../tools.mk - -# Test that hir-tree output doesn't crash and includes -# the string constant we would expect to see. - -all: - $(RUSTDOC) --test input.rs > $(TMPDIR)/output || true - $(CGREP) 'input.rs:7:15' < $(TMPDIR)/output diff --git a/src/test/run-make-fulldeps/rustdoc-error-lines/input.rs b/src/test/run-make-fulldeps/rustdoc-error-lines/input.rs deleted file mode 100644 index 7b07f38f25948..0000000000000 --- a/src/test/run-make-fulldeps/rustdoc-error-lines/input.rs +++ /dev/null @@ -1,11 +0,0 @@ -// Test for #45868 - -// random #![feature] to ensure that crate attrs -// do not offset things -/// ```rust -/// #![feature(nll)] -/// let x: char = 1; -/// ``` -pub fn foo() { - -} diff --git a/src/test/rustdoc-ui/failed-doctest-output.rs b/src/test/rustdoc-ui/failed-doctest-output.rs deleted file mode 100644 index 48f1424e6b23d..0000000000000 --- a/src/test/rustdoc-ui/failed-doctest-output.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Issue #51162: A failed doctest was not printing its stdout/stderr -// FIXME: if/when the output of the test harness can be tested on its own, this test should be -// adapted to use that, and that normalize line can go away - -// compile-flags:--test -// normalize-stdout-test: "src/test/rustdoc-ui" -> "$$DIR" -// failure-status: 101 -// rustc-env:RUST_BACKTRACE=0 - -// doctest fails at runtime -/// ``` -/// panic!("oh no"); -/// ``` -pub struct SomeStruct; - -// doctest fails at compile time -/// ``` -/// no -/// ``` -pub struct OtherStruct; diff --git a/src/test/rustdoc-ui/failed-doctest-output.stdout b/src/test/rustdoc-ui/failed-doctest-output.stdout deleted file mode 100644 index c9f59405ce012..0000000000000 --- a/src/test/rustdoc-ui/failed-doctest-output.stdout +++ /dev/null @@ -1,35 +0,0 @@ - -running 2 tests -test $DIR/failed-doctest-output.rs - OtherStruct (line 17) ... FAILED -test $DIR/failed-doctest-output.rs - SomeStruct (line 11) ... FAILED - -failures: - ----- $DIR/failed-doctest-output.rs - OtherStruct (line 17) stdout ---- -error[E0425]: cannot find value `no` in this scope - --> $DIR/failed-doctest-output.rs:18:1 - | -3 | no - | ^^ not found in this scope - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0425`. -thread '$DIR/failed-doctest-output.rs - OtherStruct (line 17)' panicked at 'couldn't compile the test', src/librustdoc/test.rs:310:13 -note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace. - ----- $DIR/failed-doctest-output.rs - SomeStruct (line 11) stdout ---- -thread '$DIR/failed-doctest-output.rs - SomeStruct (line 11)' panicked at 'test executable failed: - -thread 'main' panicked at 'oh no', $DIR/failed-doctest-output.rs:3:1 -note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace. - -', src/librustdoc/test.rs:332:17 - - -failures: - $DIR/failed-doctest-output.rs - OtherStruct (line 17) - $DIR/failed-doctest-output.rs - SomeStruct (line 11) - -test result: FAILED. 0 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out - diff --git a/src/test/rustdoc/doc-cfg-target-feature.rs b/src/test/rustdoc/doc-cfg-target-feature.rs deleted file mode 100644 index f1b000dc82362..0000000000000 --- a/src/test/rustdoc/doc-cfg-target-feature.rs +++ /dev/null @@ -1,21 +0,0 @@ -// only-x86_64 -// compile-flags:--test -// should-fail -// no-system-llvm - -// #49723: rustdoc didn't add target features when extracting or running doctests - -#![feature(doc_cfg)] - -/// Foo -/// -/// # Examples -/// -/// ``` -/// #![feature(cfg_target_feature)] -/// -/// #[cfg(target_feature = "sse")] -/// assert!(false); -/// ``` -#[doc(cfg(target_feature = "sse"))] -pub unsafe fn foo() {} diff --git a/src/test/rustdoc/force-target-feature.rs b/src/test/rustdoc/force-target-feature.rs deleted file mode 100644 index b6c10e8341b43..0000000000000 --- a/src/test/rustdoc/force-target-feature.rs +++ /dev/null @@ -1,11 +0,0 @@ -// only-x86_64 -// compile-flags:--test -C target-feature=+avx -// should-fail - -/// (written on a spider's web) Some Struct -/// -/// ``` -/// panic!("oh no"); -/// ``` -#[doc(cfg(target_feature = "avx"))] -pub struct SomeStruct; diff --git a/src/test/rustdoc/issue-38219.rs b/src/test/rustdoc/issue-38219.rs deleted file mode 100644 index fa57c58c76184..0000000000000 --- a/src/test/rustdoc/issue-38219.rs +++ /dev/null @@ -1,8 +0,0 @@ -// compile-flags:--test -// should-fail - -/// ``` -/// fail -/// ``` -#[macro_export] -macro_rules! foo { () => {} } diff --git a/src/test/rustdoc/no-run-still-checks-lints.rs b/src/test/rustdoc/no-run-still-checks-lints.rs deleted file mode 100644 index 9f7d1c8845dc7..0000000000000 --- a/src/test/rustdoc/no-run-still-checks-lints.rs +++ /dev/null @@ -1,9 +0,0 @@ -// compile-flags:--test -// should-fail - -#![doc(test(attr(deny(warnings))))] - -/// ```no_run -/// let a = 3; -/// ``` -pub fn foo() {} diff --git a/src/test/rustdoc/test_option_check/bar.rs b/src/test/rustdoc/test_option_check/bar.rs deleted file mode 100644 index 50a182cf7e049..0000000000000 --- a/src/test/rustdoc/test_option_check/bar.rs +++ /dev/null @@ -1,9 +0,0 @@ -// compile-flags: --test -// check-test-line-numbers-match - -/// This looks like another awesome test! -/// -/// ``` -/// println!("foo?"); -/// ``` -pub fn foooo() {} diff --git a/src/test/rustdoc/test_option_check/test.rs b/src/test/rustdoc/test_option_check/test.rs deleted file mode 100644 index 964e8e37ed581..0000000000000 --- a/src/test/rustdoc/test_option_check/test.rs +++ /dev/null @@ -1,18 +0,0 @@ -// compile-flags: --test -// check-test-line-numbers-match - -pub mod bar; - -/// This is a Foo; -/// -/// ``` -/// println!("baaaaaar"); -/// ``` -pub struct Foo; - -/// This is a Bar; -/// -/// ``` -/// println!("fooooo"); -/// ``` -pub struct Bar;