Skip to content
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

Rollup of 10 pull requests #82847

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
6a679ff
bypass auto_da_alloc for metadata files
the8472 Feb 12, 2021
9d25ccf
Change built-in kernel targets to be os = none throughout
Ericson2314 Oct 11, 2020
44c2794
Clean up error reporting for deprecated passes
jyn514 Mar 1, 2021
d5c300b
Report that `doc(plugins)` doesn't work using diagnostics instead of …
jyn514 Mar 1, 2021
d9d6921
Fix diagnostic suggests adding type `[type error]`
henryboisdequin Mar 3, 2021
5461ee0
rustc_target: add "unwind" payloads to `Abi`
Aug 27, 2020
9a007cf
implement unwinding abi's (RFC 2945)
Sep 10, 2020
0fd2fd9
add integration tests, unwind across FFI boundary
Dec 12, 2020
d8bfdc8
address pr review comments
Oct 23, 2020
b3c4e25
Don't require a `DocContext` for `report_diagnostic`
jyn514 Feb 22, 2021
675edd0
Remove RefCell around module_trait_cache
jyn514 Feb 22, 2021
bc18eb4
expand: Remove obsolete `DirectoryOwnership::UnownedViaMod`
petrochenkov Feb 22, 2021
39052c5
expand: Move module file path stack from global session to expansion …
petrochenkov Feb 21, 2021
5bdf81d
expand: Determine module directory path directly instead of relying o…
petrochenkov Feb 22, 2021
3d0b622
expand: Less path cloning during module loading
petrochenkov Feb 22, 2021
46b67aa
expand: Some more consistent naming in module loading
petrochenkov Feb 22, 2021
da3419e
rustc_interface: Hide some hacky details of early linting from expand
petrochenkov Feb 22, 2021
29a9ef2
expand: Align some code with the PR fixing inner attributes on out-of…
petrochenkov Feb 22, 2021
1e1d574
expand: Share some code between inline and out-of-line module treatment
petrochenkov Feb 22, 2021
1fe2eb8
expand: Introduce enum for module loading errors and make module load…
petrochenkov Feb 22, 2021
2371914
Prevent Zip specialization from calling __iterator_get_unchecked twic…
SkiFire13 Mar 3, 2021
c1bfb9a
Add relevant test
SkiFire13 Feb 19, 2021
7d3a6f1
address comments
henryboisdequin Mar 3, 2021
fbc1741
Improve transmute docs with further clarifications
Lonami Feb 27, 2021
79c2b75
Make some Option, Result methods unstably const
jhpratt Feb 15, 2021
c940b1d
Rollup merge of #76570 - cratelyn:implement-rfc-2945-c-unwind-abi, r=…
Dylan-DPC Mar 6, 2021
a9875b5
Rollup merge of #77916 - QuiltOS:kernel-code-targets-os-none, r=josht…
Dylan-DPC Mar 6, 2021
2b80d79
Rollup merge of #82047 - the8472:fast-rename, r=davidtwco
Dylan-DPC Mar 6, 2021
d25eccb
Rollup merge of #82130 - jhpratt:const-option-result, r=RalfJung
Dylan-DPC Mar 6, 2021
4c7e3ce
Rollup merge of #82292 - SkiFire13:fix-issue-82291, r=m-ou-se
Dylan-DPC Mar 6, 2021
17132ce
Rollup merge of #82402 - jyn514:module-cache-refcell, r=GuillaumeGomez
Dylan-DPC Mar 6, 2021
0005a16
Rollup merge of #82415 - petrochenkov:modin3, r=davidtwco
Dylan-DPC Mar 6, 2021
ad34174
Rollup merge of #82592 - Lonami:patch-1, r=RalfJung
Dylan-DPC Mar 6, 2021
44bd3de
Rollup merge of #82651 - jyn514:rustdoc-warnings, r=GuillaumeGomez
Dylan-DPC Mar 6, 2021
44cb131
Rollup merge of #82720 - henryboisdequin:fix-79040, r=oli-obk
Dylan-DPC Mar 6, 2021
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
8 changes: 4 additions & 4 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
},
ItemKind::ForeignMod(ref fm) => {
if fm.abi.is_none() {
self.maybe_lint_missing_abi(span, id, abi::Abi::C);
self.maybe_lint_missing_abi(span, id, abi::Abi::C { unwind: false });
}
hir::ItemKind::ForeignMod {
abi: fm.abi.map_or(abi::Abi::C, |abi| self.lower_abi(abi)),
abi: fm.abi.map_or(abi::Abi::C { unwind: false }, |abi| self.lower_abi(abi)),
items: self
.arena
.alloc_from_iter(fm.items.iter().map(|x| self.lower_foreign_item_ref(x))),
Expand Down Expand Up @@ -1322,8 +1322,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
match ext {
Extern::None => abi::Abi::Rust,
Extern::Implicit => {
self.maybe_lint_missing_abi(span, id, abi::Abi::C);
abi::Abi::C
self.maybe_lint_missing_abi(span, id, abi::Abi::C { unwind: false });
abi::Abi::C { unwind: false }
}
Extern::Explicit(abi) => self.lower_abi(abi),
}
Expand Down
32 changes: 32 additions & 0 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,38 @@ impl<'a> PostExpansionVisitor<'a> {
"C-cmse-nonsecure-call ABI is experimental and subject to change"
);
}
"C-unwind" => {
gate_feature_post!(
&self,
c_unwind,
span,
"C-unwind ABI is experimental and subject to change"
);
}
"stdcall-unwind" => {
gate_feature_post!(
&self,
c_unwind,
span,
"stdcall-unwind ABI is experimental and subject to change"
);
}
"system-unwind" => {
gate_feature_post!(
&self,
c_unwind,
span,
"system-unwind ABI is experimental and subject to change"
);
}
"thiscall-unwind" => {
gate_feature_post!(
&self,
c_unwind,
span,
"thiscall-unwind ABI is experimental and subject to change"
);
}
abi => self
.sess
.parse_sess
Expand Down
11 changes: 5 additions & 6 deletions compiler/rustc_builtin_macros/src/source_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rustc_ast::token;
use rustc_ast::tokenstream::TokenStream;
use rustc_ast_pretty::pprust;
use rustc_expand::base::{self, *};
use rustc_expand::module::DirectoryOwnership;
use rustc_expand::module::DirOwnership;
use rustc_parse::parser::{ForceCollect, Parser};
use rustc_parse::{self, new_parser_from_file};
use rustc_session::lint::builtin::INCOMPLETE_INCLUDE;
Expand Down Expand Up @@ -101,7 +101,7 @@ pub fn expand_include<'cx>(
None => return DummyResult::any(sp),
};
// The file will be added to the code map by the parser
let mut file = match cx.resolve_path(file, sp) {
let file = match cx.resolve_path(file, sp) {
Ok(f) => f,
Err(mut err) => {
err.emit();
Expand All @@ -114,10 +114,9 @@ pub fn expand_include<'cx>(
// then the path of `bar.rs` should be relative to the directory of `file`.
// See https://github.com/rust-lang/rust/pull/69838/files#r395217057 for a discussion.
// `MacroExpander::fully_expand_fragment` later restores, so "stack discipline" is maintained.
file.pop();
cx.current_expansion.directory_ownership = DirectoryOwnership::Owned { relative: None };
let mod_path = cx.current_expansion.module.mod_path.clone();
cx.current_expansion.module = Rc::new(ModuleData { mod_path, directory: file });
let dir_path = file.parent().unwrap_or(&file).to_owned();
cx.current_expansion.module = Rc::new(cx.current_expansion.module.with_dir_path(dir_path));
cx.current_expansion.dir_ownership = DirOwnership::Owned { relative: None };

struct ExpandResult<'a> {
p: Parser<'a>,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(

// FIXME find a cleaner way to support varargs
if fn_sig.c_variadic {
if fn_sig.abi != Abi::C {
if !matches!(fn_sig.abi, Abi::C { .. }) {
fx.tcx.sess.span_fatal(
span,
&format!("Variadic call for non-C abi {:?}", fn_sig.abi),
Expand Down
37 changes: 28 additions & 9 deletions compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::expand::{self, AstFragment, Invocation};
use crate::module::DirectoryOwnership;
use crate::module::DirOwnership;

use rustc_ast::ptr::P;
use rustc_ast::token::{self, Nonterminal};
use rustc_ast::tokenstream::{CanSynthesizeMissingTokens, LazyTokenStream, TokenStream};
use rustc_ast::visit::{AssocCtxt, Visitor};
use rustc_ast::{self as ast, AstLike, Attribute, NodeId, PatKind};
use rustc_ast::{self as ast, AstLike, Attribute, Item, NodeId, PatKind};
use rustc_attr::{self as attr, Deprecation, Stability};
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::sync::{self, Lrc};
Expand Down Expand Up @@ -900,21 +900,40 @@ pub trait ResolverExpand {
fn cfg_accessible(&mut self, expn_id: ExpnId, path: &ast::Path) -> Result<bool, Indeterminate>;
}

#[derive(Clone)]
#[derive(Clone, Default)]
pub struct ModuleData {
/// Path to the module starting from the crate name, like `my_crate::foo::bar`.
pub mod_path: Vec<Ident>,
pub directory: PathBuf,
/// Stack of paths to files loaded by out-of-line module items,
/// used to detect and report recursive module inclusions.
pub file_path_stack: Vec<PathBuf>,
/// Directory to search child module files in,
/// often (but not necessarily) the parent of the top file path on the `file_path_stack`.
pub dir_path: PathBuf,
}

impl ModuleData {
pub fn with_dir_path(&self, dir_path: PathBuf) -> ModuleData {
ModuleData {
mod_path: self.mod_path.clone(),
file_path_stack: self.file_path_stack.clone(),
dir_path,
}
}
}

#[derive(Clone)]
pub struct ExpansionData {
pub id: ExpnId,
pub depth: usize,
pub module: Rc<ModuleData>,
pub directory_ownership: DirectoryOwnership,
pub dir_ownership: DirOwnership,
pub prior_type_ascription: Option<(Span, bool)>,
}

type OnExternModLoaded<'a> =
Option<&'a dyn Fn(Ident, Vec<Attribute>, Vec<P<Item>>, Span) -> (Vec<Attribute>, Vec<P<Item>>)>;

/// One of these is made during expansion and incrementally updated as we go;
/// when a macro expansion occurs, the resulting nodes have the `backtrace()
/// -> expn_data` of their expansion context stored into their span.
Expand All @@ -932,15 +951,15 @@ pub struct ExtCtxt<'a> {
/// Called directly after having parsed an external `mod foo;` in expansion.
///
/// `Ident` is the module name.
pub(super) extern_mod_loaded: Option<&'a dyn Fn(&ast::Crate, Ident)>,
pub(super) extern_mod_loaded: OnExternModLoaded<'a>,
}

impl<'a> ExtCtxt<'a> {
pub fn new(
sess: &'a Session,
ecfg: expand::ExpansionConfig<'a>,
resolver: &'a mut dyn ResolverExpand,
extern_mod_loaded: Option<&'a dyn Fn(&ast::Crate, Ident)>,
extern_mod_loaded: OnExternModLoaded<'a>,
) -> ExtCtxt<'a> {
ExtCtxt {
sess,
Expand All @@ -952,8 +971,8 @@ impl<'a> ExtCtxt<'a> {
current_expansion: ExpansionData {
id: ExpnId::root(),
depth: 0,
module: Rc::new(ModuleData { mod_path: Vec::new(), directory: PathBuf::new() }),
directory_ownership: DirectoryOwnership::Owned { relative: None },
module: Default::default(),
dir_ownership: DirOwnership::Owned { relative: None },
prior_type_ascription: None,
},
force_mode: false,
Expand Down
114 changes: 65 additions & 49 deletions compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::config::StripUnconfigured;
use crate::configure;
use crate::hygiene::SyntaxContext;
use crate::mbe::macro_rules::annotate_err_with_kind;
use crate::module::{parse_external_mod, push_directory, Directory, DirectoryOwnership};
use crate::module::{mod_dir_path, parse_external_mod, DirOwnership, ParsedExternalMod};
use crate::placeholders::{placeholder, PlaceholderExpander};

use rustc_ast as ast;
Expand Down Expand Up @@ -355,16 +355,17 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
// FIXME: Avoid visiting the crate as a `Mod` item,
// make crate a first class expansion target instead.
pub fn expand_crate(&mut self, mut krate: ast::Crate) -> ast::Crate {
let mut module = ModuleData {
mod_path: vec![Ident::from_str(&self.cx.ecfg.crate_name)],
directory: match self.cx.source_map().span_to_unmapped_path(krate.span) {
FileName::Real(name) => name.into_local_path(),
other => PathBuf::from(other.to_string()),
},
let file_path = match self.cx.source_map().span_to_unmapped_path(krate.span) {
FileName::Real(name) => name.into_local_path(),
other => PathBuf::from(other.to_string()),
};
module.directory.pop();
self.cx.root_path = module.directory.clone();
self.cx.current_expansion.module = Rc::new(module);
let dir_path = file_path.parent().unwrap_or(&file_path).to_owned();
self.cx.root_path = dir_path.clone();
self.cx.current_expansion.module = Rc::new(ModuleData {
mod_path: vec![Ident::from_str(&self.cx.ecfg.crate_name)],
file_path_stack: vec![file_path],
dir_path,
});

let krate_item = AstFragment::Items(smallvec![P(ast::Item {
attrs: krate.attrs,
Expand Down Expand Up @@ -1245,10 +1246,12 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
}

fn visit_block(&mut self, block: &mut P<Block>) {
let old_directory_ownership = self.cx.current_expansion.directory_ownership;
self.cx.current_expansion.directory_ownership = DirectoryOwnership::UnownedViaBlock;
let orig_dir_ownership = mem::replace(
&mut self.cx.current_expansion.dir_ownership,
DirOwnership::UnownedViaBlock,
);
noop_visit_block(block, self);
self.cx.current_expansion.directory_ownership = old_directory_ownership;
self.cx.current_expansion.dir_ownership = orig_dir_ownership;
}

fn flat_map_item(&mut self, item: P<ast::Item>) -> SmallVec<[P<ast::Item>; 1]> {
Expand Down Expand Up @@ -1276,63 +1279,76 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
})
}
ast::ItemKind::Mod(_, ref mut mod_kind) if ident != Ident::invalid() => {
let sess = &self.cx.sess.parse_sess;
let orig_ownership = self.cx.current_expansion.directory_ownership;
let mut module = (*self.cx.current_expansion.module).clone();

let pushed = &mut false; // Record `parse_external_mod` pushing so we can pop.
let dir = Directory { ownership: orig_ownership, path: module.directory };
let Directory { ownership, path } = match mod_kind {
ModKind::Loaded(_, Inline::Yes, _) => {
let (file_path, dir_path, dir_ownership) = match mod_kind {
ModKind::Loaded(_, inline, _) => {
// Inline `mod foo { ... }`, but we still need to push directories.
assert!(
*inline == Inline::Yes,
"`mod` item is loaded from a file for the second time"
);
let (dir_path, dir_ownership) = mod_dir_path(
&self.cx.sess,
ident,
&attrs,
&self.cx.current_expansion.module,
self.cx.current_expansion.dir_ownership,
);
item.attrs = attrs;
push_directory(&self.cx.sess, ident, &item.attrs, dir)
}
ModKind::Loaded(_, Inline::No, _) => {
panic!("`mod` item is loaded from a file for the second time")
(None, dir_path, dir_ownership)
}
ModKind::Unloaded => {
// We have an outline `mod foo;` so we need to parse the file.
let (items, inner_span, dir) =
parse_external_mod(&self.cx.sess, ident, span, dir, &mut attrs, pushed);
let old_attrs_len = attrs.len();
let ParsedExternalMod {
mut items,
inner_span,
file_path,
dir_path,
dir_ownership,
} = parse_external_mod(
&self.cx.sess,
ident,
span,
&self.cx.current_expansion.module,
self.cx.current_expansion.dir_ownership,
&mut attrs,
);

let krate =
ast::Crate { attrs, items, span: inner_span, proc_macros: vec![] };
if let Some(extern_mod_loaded) = self.cx.extern_mod_loaded {
extern_mod_loaded(&krate, ident);
(attrs, items) = extern_mod_loaded(ident, attrs, items, inner_span);
}

*mod_kind = ModKind::Loaded(krate.items, Inline::No, inner_span);
item.attrs = krate.attrs;
// File can have inline attributes, e.g., `#![cfg(...)]` & co. => Reconfigure.
item = match self.configure(item) {
Some(node) => node,
None => {
if *pushed {
sess.included_mod_stack.borrow_mut().pop();
}
return Default::default();
}
};
dir
*mod_kind = ModKind::Loaded(items, Inline::No, inner_span);
item.attrs = attrs;
if item.attrs.len() > old_attrs_len {
// If we loaded an out-of-line module and added some inner attributes,
// then we need to re-configure it.
// FIXME: Attributes also need to be recollected
// for resolution and expansion.
item = configure!(self, item);
}
(Some(file_path), dir_path, dir_ownership)
}
};

// Set the module info before we flat map.
self.cx.current_expansion.directory_ownership = ownership;
module.directory = path;
let mut module = self.cx.current_expansion.module.with_dir_path(dir_path);
module.mod_path.push(ident);
if let Some(file_path) = file_path {
module.file_path_stack.push(file_path);
}

let orig_module =
mem::replace(&mut self.cx.current_expansion.module, Rc::new(module));
let orig_dir_ownership =
mem::replace(&mut self.cx.current_expansion.dir_ownership, dir_ownership);

let result = noop_flat_map_item(item, self);

// Restore the module info.
self.cx.current_expansion.dir_ownership = orig_dir_ownership;
self.cx.current_expansion.module = orig_module;
self.cx.current_expansion.directory_ownership = orig_ownership;
if *pushed {
sess.included_mod_stack.borrow_mut().pop();
}

result
}
_ => {
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_expand/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![feature(bool_to_option)]
#![feature(crate_visibility_modifier)]
#![feature(decl_macro)]
#![feature(destructuring_assignment)]
#![feature(or_patterns)]
#![feature(proc_macro_diagnostic)]
#![feature(proc_macro_internals)]
Expand Down
Loading