Skip to content

Rollup of 5 pull requests #63936

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/libproc_macro/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@

#![feature(nll)]
#![feature(staged_api)]
#![feature(allow_internal_unstable)]
#![feature(const_fn)]
#![feature(decl_macro)]
#![feature(extern_types)]
#![feature(in_band_lifetimes)]
#![feature(optin_builtin_traits)]
#![feature(mem_take)]
#![feature(non_exhaustive)]
#![feature(rustc_attrs)]
#![feature(specialization)]

#![recursion_limit="256"]
Expand Down Expand Up @@ -222,11 +225,10 @@ pub mod token_stream {
///
/// Unquoting is done with `$`, and works by taking the single next ident as the unquoted term.
/// To quote `$` itself, use `$$`.
///
/// This is a dummy macro, the actual implementation is in `quote::quote`.`
#[unstable(feature = "proc_macro_quote", issue = "54722")]
#[macro_export]
macro_rules! quote { () => {} }
#[allow_internal_unstable(proc_macro_def_site)]
#[cfg_attr(not(bootstrap), rustc_builtin_macro)]
pub macro quote ($($t:tt)*) { /* compiler built-in */ }

#[unstable(feature = "proc_macro_internals", issue = "27812")]
#[doc(hidden)]
Expand Down
4 changes: 2 additions & 2 deletions src/libproc_macro/quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ macro_rules! quote {
}

/// Quote a `TokenStream` into a `TokenStream`.
/// This is the actual `quote!()` proc macro.
/// This is the actual implementation of the `quote!()` proc macro.
///
/// It is manually loaded in `CStore::load_macro_untracked`.
/// It is loaded by the compiler in `register_builtin_macros`.
#[unstable(feature = "proc_macro_quote", issue = "54722")]
pub fn quote(stream: TokenStream) -> TokenStream {
if stream.is_empty() {
Expand Down
25 changes: 23 additions & 2 deletions src/librustc/ty/query/on_disk_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use rustc_data_structures::thin_vec::ThinVec;
use rustc_data_structures::sync::{Lrc, Lock, HashMapExt, Once};
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
use std::mem;
use syntax::ast::NodeId;
use syntax::ast::{Ident, NodeId};
use syntax::source_map::{SourceMap, StableSourceFileId};
use syntax_pos::{BytePos, Span, DUMMY_SP, SourceFile};
use syntax_pos::hygiene::{ExpnId, SyntaxContext};
Expand Down Expand Up @@ -591,7 +591,8 @@ impl<'a, 'tcx> SpecializedDecoder<Span> for CacheDecoder<'a, 'tcx> {
// FIXME(mw): This method does not restore `ExpnData::parent` or
// `SyntaxContextData::prev_ctxt` or `SyntaxContextData::opaque`. These things
// don't seem to be used after HIR lowering, so everything should be fine
// as long as incremental compilation does not kick in before that.
// until we want incremental compilation to serialize Spans that we need
// full hygiene information for.
let location = || Span::with_root_ctxt(lo, hi);
let recover_from_expn_data = |this: &Self, expn_data, transparency, pos| {
let span = location().fresh_expansion_with_transparency(expn_data, transparency);
Expand Down Expand Up @@ -626,6 +627,13 @@ impl<'a, 'tcx> SpecializedDecoder<Span> for CacheDecoder<'a, 'tcx> {
}
}

impl<'a, 'tcx> SpecializedDecoder<Ident> for CacheDecoder<'a, 'tcx> {
fn specialized_decode(&mut self) -> Result<Ident, Self::Error> {
// FIXME: Handle hygiene in incremental
bug!("Trying to decode Ident for incremental");
}
}

// This impl makes sure that we get a runtime error when we try decode a
// DefIndex that is not contained in a DefId. Such a case would be problematic
// because we would not know how to transform the DefIndex to the current
Expand Down Expand Up @@ -833,6 +841,19 @@ where
}
}

impl<'a, 'tcx, E> SpecializedEncoder<Ident> for CacheEncoder<'a, 'tcx, E>
where
E: 'a + ty_codec::TyEncoder,
{
fn specialized_encode(&mut self, _: &Ident) -> Result<(), Self::Error> {
// We don't currently encode enough information to ensure hygiene works
// with incremental, so panic rather than risk incremental bugs.

// FIXME: Handle hygiene in incremental
bug!("Trying to encode Ident for incremental")
}
}

impl<'a, 'tcx, E> ty_codec::TyEncoder for CacheEncoder<'a, 'tcx, E>
where
E: 'a + ty_codec::TyEncoder,
Expand Down
7 changes: 1 addition & 6 deletions src/librustc_metadata/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,6 @@ pub struct CrateMetadata {
pub raw_proc_macros: Option<&'static [ProcMacro]>,
}

pub struct FullProcMacro {
pub name: ast::Name,
pub ext: Lrc<SyntaxExtension>
}

pub struct CStore {
metas: RwLock<IndexVec<CrateNum, Option<Lrc<CrateMetadata>>>>,
/// Map from NodeId's of local extern crate statements to crate numbers
Expand All @@ -109,7 +104,7 @@ pub struct CStore {

pub enum LoadedMacro {
MacroDef(ast::Item),
ProcMacro(Lrc<SyntaxExtension>),
ProcMacro(SyntaxExtension),
}

impl CStore {
Expand Down
14 changes: 2 additions & 12 deletions src/librustc_metadata/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ use syntax::ast;
use syntax::attr;
use syntax::source_map;
use syntax::edition::Edition;
use syntax::ext::base::{SyntaxExtension, SyntaxExtensionKind};
use syntax::ext::proc_macro::BangProcMacro;
use syntax::parse::source_file_to_stream;
use syntax::parse::parser::emit_unclosed_delims;
use syntax::symbol::{Symbol, sym};
use syntax::symbol::Symbol;
use syntax_pos::{Span, FileName};
use rustc_data_structures::bit_set::BitSet;

Expand Down Expand Up @@ -436,15 +434,7 @@ impl cstore::CStore {
pub fn load_macro_untracked(&self, id: DefId, sess: &Session) -> LoadedMacro {
let data = self.get_crate_data(id.krate);
if data.is_proc_macro_crate() {
return LoadedMacro::ProcMacro(data.get_proc_macro(id.index, sess).ext);
} else if data.name == sym::proc_macro && data.item_name(id.index) == sym::quote {
let client = proc_macro::bridge::client::Client::expand1(proc_macro::quote);
let kind = SyntaxExtensionKind::Bang(Box::new(BangProcMacro { client }));
let ext = SyntaxExtension {
allow_internal_unstable: Some([sym::proc_macro_def_site][..].into()),
..SyntaxExtension::default(kind, data.root.edition)
};
return LoadedMacro::ProcMacro(Lrc::new(ext));
return LoadedMacro::ProcMacro(data.load_proc_macro(id.index, sess));
}

let def = data.get_macro(id.index);
Expand Down
49 changes: 17 additions & 32 deletions src/librustc_metadata/decoder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Decoding metadata from a single crate's metadata

use crate::cstore::{self, CrateMetadata, MetadataBlob, NativeLibrary, ForeignModule, FullProcMacro};
use crate::cstore::{self, CrateMetadata, MetadataBlob, NativeLibrary, ForeignModule};
use crate::schema::*;

use rustc_data_structures::indexed_vec::IndexVec;
Expand Down Expand Up @@ -512,27 +512,8 @@ impl<'a, 'tcx> CrateMetadata {
self.entry(index).span.decode((self, sess))
}


pub fn get_proc_macro(&self, id: DefIndex, sess: &Session) -> FullProcMacro {
if sess.opts.debugging_opts.dual_proc_macros {
let host_lib = self.host_lib.as_ref().unwrap();
self.load_proc_macro(
&host_lib.metadata.get_root(),
id,
sess
)
} else {
self.load_proc_macro(&self.root, id, sess)
}
}

fn load_proc_macro(&self, root: &CrateRoot<'_>,
id: DefIndex,
sess: &Session)
-> FullProcMacro {

let raw_macro = self.raw_proc_macro(id);
let (name, kind, helper_attrs) = match *raw_macro {
crate fn load_proc_macro(&self, id: DefIndex, sess: &Session) -> SyntaxExtension {
let (name, kind, helper_attrs) = match *self.raw_proc_macro(id) {
ProcMacro::CustomDerive { trait_name, attributes, client } => {
let helper_attrs =
attributes.iter().cloned().map(Symbol::intern).collect::<Vec<_>>();
Expand All @@ -551,17 +532,21 @@ impl<'a, 'tcx> CrateMetadata {
name, SyntaxExtensionKind::Bang(Box::new(BangProcMacro { client })), Vec::new()
)
};
let edition = if sess.opts.debugging_opts.dual_proc_macros {
self.host_lib.as_ref().unwrap().metadata.get_root().edition
} else {
self.root.edition
};

let span = self.get_span(id, sess);

FullProcMacro {
name: Symbol::intern(name),
ext: Lrc::new(SyntaxExtension {
span,
helper_attrs,
..SyntaxExtension::default(kind, root.edition)
})
}
SyntaxExtension::new(
&sess.parse_sess,
kind,
self.get_span(id, sess),
helper_attrs,
edition,
Symbol::intern(name),
&self.get_attributes(&self.entry(id), sess),
)
}

pub fn get_trait_def(&self, item_id: DefIndex, sess: &Session) -> ty::TraitDef {
Expand Down
12 changes: 6 additions & 6 deletions src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ impl<'a> Resolver<'a> {
return Some(ext.clone());
}

let macro_def = match self.cstore.load_macro_untracked(def_id, &self.session) {
LoadedMacro::MacroDef(macro_def) => macro_def,
LoadedMacro::ProcMacro(ext) => return Some(ext),
};
let ext = Lrc::new(match self.cstore.load_macro_untracked(def_id, &self.session) {
LoadedMacro::MacroDef(item) =>
self.compile_macro(&item, self.cstore.crate_edition_untracked(def_id.krate)),
LoadedMacro::ProcMacro(ext) => ext,
});

let ext = self.compile_macro(&macro_def, self.cstore.crate_edition_untracked(def_id.krate));
self.macro_map.insert(def_id, ext.clone());
Some(ext)
}
Expand Down Expand Up @@ -1104,7 +1104,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
let expansion = parent_scope.expansion;
let (ext, ident, span, is_legacy) = match &item.node {
ItemKind::MacroDef(def) => {
let ext = self.r.compile_macro(item, self.r.session.edition());
let ext = Lrc::new(self.r.compile_macro(item, self.r.session.edition()));
(ext, item.ident, item.span, def.legacy)
}
ItemKind::Fn(..) => match Self::proc_macro_stub(item) {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_resolve/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ impl<'a> Resolver<'a> {

/// Compile the macro into a `SyntaxExtension` and possibly replace it with a pre-defined
/// extension partially or entirely for built-in macros and legacy plugin macros.
crate fn compile_macro(&mut self, item: &ast::Item, edition: Edition) -> Lrc<SyntaxExtension> {
crate fn compile_macro(&mut self, item: &ast::Item, edition: Edition) -> SyntaxExtension {
let mut result = macro_rules::compile(
&self.session.parse_sess, self.session.features_untracked(), item, edition
);
Expand All @@ -822,6 +822,6 @@ impl<'a> Resolver<'a> {
}
}

Lrc::new(result)
result
}
}
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use super::{check_fn, Expectation, FnCtxt, GeneratorTypes};

use crate::astconv::AstConv;
use crate::middle::region;
use crate::middle::{lang_items, region};
use rustc::hir::def_id::DefId;
use rustc::infer::{InferOk, InferResult};
use rustc::infer::LateBoundRegionConversionTime;
Expand Down Expand Up @@ -266,7 +266,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let trait_ref = projection.to_poly_trait_ref(tcx);

let is_fn = tcx.lang_items().fn_trait_kind(trait_ref.def_id()).is_some();
let gen_trait = tcx.lang_items().gen_trait().unwrap();
let gen_trait = tcx.require_lang_item(lang_items::GeneratorTraitLangItem);
let is_gen = gen_trait == trait_ref.def_id();
if !is_fn && !is_gen {
debug!("deduce_sig_from_projection: not fn or generator");
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,6 @@ pub fn test(mut options: Options, diag: &errors::Handler) -> i32 {

options.test_args.insert(0, "rustdoctest".to_string());
testing::test_main(&options.test_args, collector.tests,
testing::Options::new().display_output(options.display_warnings));
Some(testing::Options::new().display_output(options.display_warnings)));
0
}
2 changes: 1 addition & 1 deletion src/librustdoc/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ pub fn run(options: Options) -> i32 {
testing::test_main(
&test_args,
tests,
testing::Options::new().display_output(display_warnings)
Some(testing::Options::new().display_output(display_warnings))
);

0
Expand Down
10 changes: 6 additions & 4 deletions src/libstd/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ impl f32 {
if self == NEG_INFINITY {
NEG_INFINITY
} else {
(self + ((self * self) + 1.0).sqrt()).ln()
(self + ((self * self) + 1.0).sqrt()).ln().copysign(self)
}
}

Expand All @@ -931,9 +931,10 @@ impl f32 {
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn acosh(self) -> f32 {
match self {
x if x < 1.0 => crate::f32::NAN,
x => (x + ((x * x) - 1.0).sqrt()).ln(),
if self < 1.0 {
crate::f32::NAN
} else {
(self + ((self * self) - 1.0).sqrt()).ln()
}
}

Expand Down Expand Up @@ -1487,6 +1488,7 @@ mod tests {
assert_eq!(inf.asinh(), inf);
assert_eq!(neg_inf.asinh(), neg_inf);
assert!(nan.asinh().is_nan());
assert!((-0.0f32).asinh().is_sign_negative()); // issue 63271
assert_approx_eq!(2.0f32.asinh(), 1.443635475178810342493276740273105f32);
assert_approx_eq!((-2.0f32).asinh(), -1.443635475178810342493276740273105f32);
}
Expand Down
Loading