Skip to content

Commit

Permalink
Auto merge of #82896 - Dylan-DPC:rollup-9setmme, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 10 pull requests

Successful merges:

 - #82047 (bypass auto_da_alloc for metadata files)
 - #82415 (expand: Refactor module loading)
 - #82557 (Add natvis for Result, NonNull, CString, CStr, and Cow)
 - #82613 (Remove Item::kind, use tagged enum. Rename variants to match)
 - #82642 (Fix jemalloc usage on OSX)
 - #82682 (Implement built-in attribute macro `#[cfg_eval]` + some refactoring)
 - #82684 (Disable destination propagation on all mir-opt-levels)
 - #82755 (Refactor confirm_builtin_call, remove partial if)
 - #82857 (Edit ructc_ast_lowering docs)
 - #82862 (Generalize Write impl for Vec<u8> to Vec<u8, A>)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Mar 8, 2021
2 parents 1d6b0f6 + 3b0a02a commit 8f349be
Show file tree
Hide file tree
Showing 62 changed files with 1,365 additions and 858 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4568,6 +4568,7 @@ name = "rustdoc-json-types"
version = "0.1.0"
dependencies = [
"serde",
"serde_json",
]

[[package]]
Expand Down
14 changes: 14 additions & 0 deletions compiler/rustc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ fn main() {
static _F5: unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void = jemalloc_sys::realloc;
#[used]
static _F6: unsafe extern "C" fn(*mut c_void) = jemalloc_sys::free;

// On OSX, jemalloc doesn't directly override malloc/free, but instead
// registers itself with the allocator's zone APIs in a ctor. However,
// the linker doesn't seem to consider ctors as "used" when statically
// linking, so we need to explicitly depend on the function.
#[cfg(target_os = "macos")]
{
extern "C" {
fn _rjem_je_zone_register();
}

#[used]
static _F7: unsafe extern "C" fn() = _rjem_je_zone_register;
}
}

rustc_driver::set_sigpipe_handler();
Expand Down
10 changes: 0 additions & 10 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -915,16 +915,6 @@ impl Stmt {
}
}

pub fn tokens_mut(&mut self) -> Option<&mut LazyTokenStream> {
match self.kind {
StmtKind::Local(ref mut local) => local.tokens.as_mut(),
StmtKind::Item(ref mut item) => item.tokens.as_mut(),
StmtKind::Expr(ref mut expr) | StmtKind::Semi(ref mut expr) => expr.tokens.as_mut(),
StmtKind::Empty => None,
StmtKind::MacCall(ref mut mac) => mac.tokens.as_mut(),
}
}

pub fn has_trailing_semicolon(&self) -> bool {
match &self.kind {
StmtKind::Semi(_) => true,
Expand Down
88 changes: 34 additions & 54 deletions compiler/rustc_ast/src/ast_like.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,7 @@ use super::{AttrVec, Attribute, Stmt, StmtKind};
pub trait AstLike: Sized {
fn attrs(&self) -> &[Attribute];
fn visit_attrs(&mut self, f: impl FnOnce(&mut Vec<Attribute>));
/// Called by `Parser::collect_tokens` to store the collected
/// tokens inside an AST node
fn finalize_tokens(&mut self, _tokens: LazyTokenStream) {
// This default impl makes this trait easier to implement
// in tools like `rust-analyzer`
panic!("`finalize_tokens` is not supported!")
}
fn tokens_mut(&mut self) -> Option<&mut Option<LazyTokenStream>>;
}

impl<T: AstLike + 'static> AstLike for P<T> {
Expand All @@ -27,8 +21,8 @@ impl<T: AstLike + 'static> AstLike for P<T> {
fn visit_attrs(&mut self, f: impl FnOnce(&mut Vec<Attribute>)) {
(**self).visit_attrs(f);
}
fn finalize_tokens(&mut self, tokens: LazyTokenStream) {
(**self).finalize_tokens(tokens)
fn tokens_mut(&mut self) -> Option<&mut Option<LazyTokenStream>> {
(**self).tokens_mut()
}
}

Expand All @@ -42,12 +36,12 @@ fn visit_attrvec(attrs: &mut AttrVec, f: impl FnOnce(&mut Vec<Attribute>)) {

impl AstLike for StmtKind {
fn attrs(&self) -> &[Attribute] {
match *self {
StmtKind::Local(ref local) => local.attrs(),
StmtKind::Expr(ref expr) | StmtKind::Semi(ref expr) => expr.attrs(),
StmtKind::Item(ref item) => item.attrs(),
match self {
StmtKind::Local(local) => local.attrs(),
StmtKind::Expr(expr) | StmtKind::Semi(expr) => expr.attrs(),
StmtKind::Item(item) => item.attrs(),
StmtKind::Empty => &[],
StmtKind::MacCall(ref mac) => &*mac.attrs,
StmtKind::MacCall(mac) => &mac.attrs,
}
}

Expand All @@ -60,17 +54,14 @@ impl AstLike for StmtKind {
StmtKind::MacCall(mac) => visit_attrvec(&mut mac.attrs, f),
}
}
fn finalize_tokens(&mut self, tokens: LazyTokenStream) {
let stmt_tokens = match self {
StmtKind::Local(ref mut local) => &mut local.tokens,
StmtKind::Item(ref mut item) => &mut item.tokens,
StmtKind::Expr(ref mut expr) | StmtKind::Semi(ref mut expr) => &mut expr.tokens,
StmtKind::Empty => return,
StmtKind::MacCall(ref mut mac) => &mut mac.tokens,
};
if stmt_tokens.is_none() {
*stmt_tokens = Some(tokens);
}
fn tokens_mut(&mut self) -> Option<&mut Option<LazyTokenStream>> {
Some(match self {
StmtKind::Local(local) => &mut local.tokens,
StmtKind::Item(item) => &mut item.tokens,
StmtKind::Expr(expr) | StmtKind::Semi(expr) => &mut expr.tokens,
StmtKind::Empty => return None,
StmtKind::MacCall(mac) => &mut mac.tokens,
})
}
}

Expand All @@ -82,8 +73,8 @@ impl AstLike for Stmt {
fn visit_attrs(&mut self, f: impl FnOnce(&mut Vec<Attribute>)) {
self.kind.visit_attrs(f);
}
fn finalize_tokens(&mut self, tokens: LazyTokenStream) {
self.kind.finalize_tokens(tokens)
fn tokens_mut(&mut self) -> Option<&mut Option<LazyTokenStream>> {
self.kind.tokens_mut()
}
}

Expand All @@ -92,17 +83,13 @@ impl AstLike for Attribute {
&[]
}
fn visit_attrs(&mut self, _f: impl FnOnce(&mut Vec<Attribute>)) {}
fn finalize_tokens(&mut self, tokens: LazyTokenStream) {
match &mut self.kind {
AttrKind::Normal(_, attr_tokens) => {
if attr_tokens.is_none() {
*attr_tokens = Some(tokens);
}
fn tokens_mut(&mut self) -> Option<&mut Option<LazyTokenStream>> {
Some(match &mut self.kind {
AttrKind::Normal(_, tokens) => tokens,
kind @ AttrKind::DocComment(..) => {
panic!("Called tokens_mut on doc comment attr {:?}", kind)
}
AttrKind::DocComment(..) => {
panic!("Called finalize_tokens on doc comment attr {:?}", self)
}
}
})
}
}

Expand All @@ -115,10 +102,8 @@ impl<T: AstLike> AstLike for Option<T> {
inner.visit_attrs(f);
}
}
fn finalize_tokens(&mut self, tokens: LazyTokenStream) {
if let Some(inner) = self {
inner.finalize_tokens(tokens);
}
fn tokens_mut(&mut self) -> Option<&mut Option<LazyTokenStream>> {
self.as_mut().and_then(|inner| inner.tokens_mut())
}
}

Expand Down Expand Up @@ -152,11 +137,8 @@ macro_rules! derive_has_tokens_and_attrs {
VecOrAttrVec::visit(&mut self.attrs, f)
}

fn finalize_tokens(&mut self, tokens: LazyTokenStream) {
if self.tokens.is_none() {
self.tokens = Some(tokens);
}

fn tokens_mut(&mut self) -> Option<&mut Option<LazyTokenStream>> {
Some(&mut self.tokens)
}
}
)* }
Expand All @@ -173,7 +155,9 @@ macro_rules! derive_has_attrs_no_tokens {
VecOrAttrVec::visit(&mut self.attrs, f)
}

fn finalize_tokens(&mut self, _tokens: LazyTokenStream) {}
fn tokens_mut(&mut self) -> Option<&mut Option<LazyTokenStream>> {
None
}
}
)* }
}
Expand All @@ -185,14 +169,10 @@ macro_rules! derive_has_tokens_no_attrs {
&[]
}

fn visit_attrs(&mut self, _f: impl FnOnce(&mut Vec<Attribute>)) {
}

fn finalize_tokens(&mut self, tokens: LazyTokenStream) {
if self.tokens.is_none() {
self.tokens = Some(tokens);
}
fn visit_attrs(&mut self, _f: impl FnOnce(&mut Vec<Attribute>)) {}

fn tokens_mut(&mut self) -> Option<&mut Option<LazyTokenStream>> {
Some(&mut self.tokens)
}
}
)* }
Expand Down
16 changes: 9 additions & 7 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
//! For the simpler lowering steps, IDs and spans should be preserved. Unlike
//! expansion we do not preserve the process of lowering in the spans, so spans
//! should not be modified here. When creating a new node (as opposed to
//! 'folding' an existing one), then you create a new ID using `next_id()`.
//! "folding" an existing one), create a new ID using `next_id()`.
//!
//! You must ensure that IDs are unique. That means that you should only use the
//! ID from an AST node in a single HIR node (you can assume that AST node-IDs
Expand All @@ -26,7 +26,7 @@
//! span and spans don't need to be kept in order, etc. Where code is preserved
//! by lowering, it should have the same span as in the AST. Where HIR nodes are
//! new it is probably best to give a span for the whole AST node being lowered.
//! All nodes should have real spans, don't use dummy spans. Tools are likely to
//! All nodes should have real spans; don't use dummy spans. Tools are likely to
//! get confused if the spans from leaf AST nodes occur in multiple places
//! in the HIR, especially for multiple identifiers.

Expand Down Expand Up @@ -95,7 +95,7 @@ struct LoweringContext<'a, 'hir: 'a> {
/// librustc_middle is independent of the parser, we use dynamic dispatch here.
nt_to_tokenstream: NtToTokenstream,

/// Used to allocate HIR nodes
/// Used to allocate HIR nodes.
arena: &'hir Arena<'hir>,

/// The items being lowered are collected here.
Expand Down Expand Up @@ -128,7 +128,7 @@ struct LoweringContext<'a, 'hir: 'a> {
is_in_trait_impl: bool,
is_in_dyn_type: bool,

/// What to do when we encounter either an "anonymous lifetime
/// What to do when we encounter an "anonymous lifetime
/// reference". The term "anonymous" is meant to encompass both
/// `'_` lifetimes as well as fully elided cases where nothing is
/// written at all (e.g., `&T` or `std::cell::Ref<T>`).
Expand Down Expand Up @@ -238,11 +238,13 @@ enum ImplTraitContext<'b, 'a> {
OtherOpaqueTy {
/// Set of lifetimes that this opaque type can capture, if it uses
/// them. This includes lifetimes bound since we entered this context.
/// For example, in
/// For example:
///
/// ```
/// type A<'b> = impl for<'a> Trait<'a, Out = impl Sized + 'a>;
/// ```
///
/// the inner opaque type captures `'a` because it uses it. It doesn't
/// Here the inner opaque type captures `'a` because it uses it. It doesn't
/// need to capture `'b` because it already inherits the lifetime
/// parameter from `A`.
// FIXME(impl_trait): but `required_region_bounds` will ICE later
Expand Down Expand Up @@ -2110,7 +2112,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
hir::FnRetTy::Return(self.arena.alloc(opaque_ty))
}

/// Transforms `-> T` into `Future<Output = T>`
/// Transforms `-> T` into `Future<Output = T>`.
fn lower_async_fn_output_type_to_future_bound(
&mut self,
output: &FnRetTy,
Expand Down
Loading

0 comments on commit 8f349be

Please sign in to comment.