Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
6a679ff
bypass auto_da_alloc for metadata files
the8472 Feb 12, 2021
6e52b23
Fix jemalloc usage on OSX
sfackler Feb 28, 2021
920e2d8
Add natvis for Result, NonNull, CString, CStr, and Cow
rylev Feb 26, 2021
c8a0e8d
Refactor confirm_builtin_call, remove partial if
osa1 Mar 4, 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
1b4860a
Update compiler/rustc/src/main.rs
sfackler Mar 5, 2021
6f49aad
Disable destination propagation on all mir-opt-levels
tmiasko Mar 6, 2021
069e612
rustc_ast: Replace `AstLike::finalize_tokens` with a getter `tokens_mut`
petrochenkov Mar 6, 2021
5dad6c2
Implement built-in attribute macro `#[cfg_eval]`
petrochenkov Mar 6, 2021
cf52469
Remove Item::kind, use tagged enum. Rename variants to match
CraftSpider Feb 28, 2021
ca48d15
Add roundtrip testing and bump format version
CraftSpider Mar 4, 2021
83cece4
Move tests to own file
CraftSpider Mar 5, 2021
70c9b37
x.py fmt
CraftSpider Mar 5, 2021
18841ec
Revert fmt version, add rustdoc-json-types to bootstrap tests
CraftSpider Mar 6, 2021
f9019b7
Move full configuration logic from `rustc_expand` to `rustc_builtin_m…
petrochenkov Mar 6, 2021
10ed08f
cfg_eval: Configure everything through mutable visitor methods
petrochenkov Mar 6, 2021
5d27728
rustc_builtin_macros: Share some more logic between `derive` and `cfg…
petrochenkov Mar 6, 2021
6b2eb0e
Edit ructc_ast_lowering docs
pierwill Mar 7, 2021
ab8995b
Generalize Write impl for Vec<u8> to Vec<u8, A>
athre0z Mar 7, 2021
3bcbd70
Rollup merge of #82047 - the8472:fast-rename, r=davidtwco
Dylan-DPC Mar 8, 2021
20bff26
Rollup merge of #82415 - petrochenkov:modin3, r=davidtwco
Dylan-DPC Mar 8, 2021
4073aa9
Rollup merge of #82557 - rylev:natvis-improvements, r=varkor
Dylan-DPC Mar 8, 2021
24c5dd0
Rollup merge of #82613 - CraftSpider:fix-de, r=aDotInTheVoid
Dylan-DPC Mar 8, 2021
9564b97
Rollup merge of #82642 - sfackler:jemalloc-zone, r=pnkfelix
Dylan-DPC Mar 8, 2021
fb90dbf
Rollup merge of #82682 - petrochenkov:cfgeval, r=Aaron1011
Dylan-DPC Mar 8, 2021
be3a58b
Rollup merge of #82684 - tmiasko:dest-prop, r=jonas-schievink
Dylan-DPC Mar 8, 2021
cb41fc6
Rollup merge of #82755 - osa1:confirm_builtin_call_refactor, r=petroc…
Dylan-DPC Mar 8, 2021
e65090e
Rollup merge of #82857 - pierwill:edit-ast-lowering-lib, r=Dylan-DPC
Dylan-DPC Mar 8, 2021
2389278
Rollup merge of #82862 - athre0z:generalize-vec-write-impl, r=TimDiek…
Dylan-DPC Mar 8, 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
Prev Previous commit
Next Next commit
rustc_builtin_macros: Share some more logic between derive and `cfg…
…_eval`
  • Loading branch information
petrochenkov committed Mar 6, 2021
commit 5d27728141beed69bf64212de1eb504b6b2ac0f0
19 changes: 11 additions & 8 deletions compiler/rustc_builtin_macros/src/cfg_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,41 @@ crate fn expand(
ecx: &mut ExtCtxt<'_>,
_span: Span,
meta_item: &ast::MetaItem,
item: Annotatable,
annotatable: Annotatable,
) -> Vec<Annotatable> {
check_builtin_macro_attribute(ecx, meta_item, sym::cfg_eval);
cfg_eval(ecx, annotatable)
}

crate fn cfg_eval(ecx: &ExtCtxt<'_>, annotatable: Annotatable) -> Vec<Annotatable> {
let mut visitor = CfgEval {
cfg: StripUnconfigured { sess: ecx.sess, features: ecx.ecfg.features, modified: false },
};
let mut item = visitor.fully_configure(item);
let mut annotatable = visitor.configure_annotatable(annotatable);
if visitor.cfg.modified {
// Erase the tokens if cfg-stripping modified the item
// This will cause us to synthesize fake tokens
// when `nt_to_tokenstream` is called on this item.
if let Some(tokens) = item.tokens_mut() {
if let Some(tokens) = annotatable.tokens_mut() {
*tokens = None;
}
}
vec![item]
vec![annotatable]
}

crate struct CfgEval<'a> {
pub cfg: StripUnconfigured<'a>,
struct CfgEval<'a> {
cfg: StripUnconfigured<'a>,
}

impl CfgEval<'_> {
fn configure<T: AstLike>(&mut self, node: T) -> Option<T> {
self.cfg.configure(node)
}

crate fn fully_configure(&mut self, item: Annotatable) -> Annotatable {
fn configure_annotatable(&mut self, annotatable: Annotatable) -> Annotatable {
// Since the item itself has already been configured by the InvocationCollector,
// we know that fold result vector will contain exactly one element
match item {
match annotatable {
Annotatable::Item(item) => Annotatable::Item(self.flat_map_item(item).pop().unwrap()),
Annotatable::TraitItem(item) => {
Annotatable::TraitItem(self.flat_map_trait_item(item).pop().unwrap())
Expand Down
21 changes: 3 additions & 18 deletions compiler/rustc_builtin_macros/src/derive.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::cfg_eval::CfgEval;
use crate::cfg_eval::cfg_eval;

use rustc_ast::{self as ast, token, AstLike, ItemKind, MetaItemKind, NestedMetaItem, StmtKind};
use rustc_ast::{self as ast, token, ItemKind, MetaItemKind, NestedMetaItem, StmtKind};
use rustc_errors::{struct_span_err, Applicability};
use rustc_expand::base::{Annotatable, ExpandResult, ExtCtxt, Indeterminate, MultiItemModifier};
use rustc_expand::config::StripUnconfigured;
use rustc_feature::AttributeTemplate;
use rustc_parse::validate_attr;
use rustc_session::Session;
Expand Down Expand Up @@ -53,21 +52,7 @@ impl MultiItemModifier for Expander {

// FIXME: Try to cache intermediate results to avoid collecting same paths multiple times.
match ecx.resolver.resolve_derives(ecx.current_expansion.id, derives, ecx.force_mode) {
Ok(()) => {
let mut visitor = CfgEval {
cfg: StripUnconfigured { sess, features: ecx.ecfg.features, modified: false },
};
let mut item = visitor.fully_configure(item);
if visitor.cfg.modified {
// Erase the tokens if cfg-stripping modified the item
// This will cause us to synthesize fake tokens
// when `nt_to_tokenstream` is called on this item.
if let Some(tokens) = item.tokens_mut() {
*tokens = None;
}
}
ExpandResult::Ready(vec![item])
}
Ok(()) => ExpandResult::Ready(cfg_eval(ecx, item)),
Err(Indeterminate) => ExpandResult::Retry(item),
}
}
Expand Down