Skip to content

Commit b5bcb9a

Browse files
committed
Merge branch 'incr_attr_queries' of https://github.com/wesleywiser/rust into update-cargo
2 parents 5a5e941 + e0f7527 commit b5bcb9a

File tree

27 files changed

+456
-394
lines changed

27 files changed

+456
-394
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@ define_dep_nodes!( <'tcx>
559559
[] IsReachableNonGeneric(DefId),
560560
[] IsMirAvailable(DefId),
561561
[] ItemAttrs(DefId),
562+
[] TransFnAttrs(DefId),
562563
[] FnArgNames(DefId),
563564
[] DylibDepFormats(CrateNum),
564565
[] IsPanicRuntime(CrateNum),
@@ -626,8 +627,6 @@ define_dep_nodes!( <'tcx>
626627
[input] AllCrateNums,
627628
[] ExportedSymbols(CrateNum),
628629
[eval_always] CollectAndPartitionTranslationItems,
629-
[] ExportName(DefId),
630-
[] ContainsExternIndicator(DefId),
631630
[] IsTranslatedItem(DefId),
632631
[] CodegenUnit(InternedString),
633632
[] CompileCodegenUnit(InternedString),
@@ -637,7 +636,6 @@ define_dep_nodes!( <'tcx>
637636
[] SubstituteNormalizeAndTestPredicates { key: (DefId, &'tcx Substs<'tcx>) },
638637

639638
[input] TargetFeaturesWhitelist,
640-
[] TargetFeaturesEnabled(DefId),
641639

642640
[] InstanceDefSizeEstimate { instance_def: InstanceDef<'tcx> },
643641

src/librustc/hir/check_attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ struct CheckAttrVisitor<'a, 'tcx: 'a> {
4747
impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
4848
/// Check any attribute.
4949
fn check_attributes(&self, item: &hir::Item, target: Target) {
50-
self.tcx.target_features_enabled(self.tcx.hir.local_def_id(item.id));
50+
self.tcx.trans_fn_attrs(self.tcx.hir.local_def_id(item.id));
5151

5252
for attr in &item.attrs {
5353
if let Some(name) = attr.name() {

src/librustc/hir/mod.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ pub use self::Visibility::{Public, Inherited};
3030
use hir::def::Def;
3131
use hir::def_id::{DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX};
3232
use util::nodemap::{NodeMap, FxHashSet};
33+
use mir::mono::Linkage;
3334

3435
use syntax_pos::{Span, DUMMY_SP};
3536
use syntax::codemap::{self, Spanned};
3637
use syntax::abi::Abi;
3738
use syntax::ast::{self, Name, NodeId, DUMMY_NODE_ID, AsmDialect};
3839
use syntax::ast::{Attribute, Lit, StrStyle, FloatTy, IntTy, UintTy, MetaItem};
40+
use syntax::attr::InlineAttr;
3941
use syntax::ext::hygiene::SyntaxContext;
4042
use syntax::ptr::P;
4143
use syntax::symbol::{Symbol, keywords};
@@ -2210,3 +2212,51 @@ pub type GlobMap = NodeMap<FxHashSet<Name>>;
22102212
pub fn provide(providers: &mut Providers) {
22112213
providers.describe_def = map::describe_def;
22122214
}
2215+
2216+
#[derive(Clone, RustcEncodable, RustcDecodable, Hash)]
2217+
pub struct TransFnAttrs {
2218+
pub flags: TransFnAttrFlags,
2219+
pub inline: InlineAttr,
2220+
pub export_name: Option<Symbol>,
2221+
pub target_features: Vec<Symbol>,
2222+
pub linkage: Option<Linkage>,
2223+
}
2224+
2225+
bitflags! {
2226+
#[derive(RustcEncodable, RustcDecodable)]
2227+
pub struct TransFnAttrFlags: u8 {
2228+
const COLD = 0b0000_0001;
2229+
const ALLOCATOR = 0b0000_0010;
2230+
const UNWIND = 0b0000_0100;
2231+
const RUSTC_ALLOCATOR_NOUNWIND = 0b0000_1000;
2232+
const NAKED = 0b0001_0000;
2233+
const NO_MANGLE = 0b0010_0000;
2234+
const RUSTC_STD_INTERNAL_SYMBOL = 0b0100_0000;
2235+
}
2236+
}
2237+
2238+
impl TransFnAttrs {
2239+
pub fn new() -> TransFnAttrs {
2240+
TransFnAttrs {
2241+
flags: TransFnAttrFlags::empty(),
2242+
inline: InlineAttr::None,
2243+
export_name: None,
2244+
target_features: vec![],
2245+
linkage: None,
2246+
}
2247+
}
2248+
2249+
/// True if `#[inline]` or `#[inline(always)]` is present.
2250+
pub fn requests_inline(&self) -> bool {
2251+
match self.inline {
2252+
InlineAttr::Hint | InlineAttr::Always => true,
2253+
InlineAttr::None | InlineAttr::Never => false,
2254+
}
2255+
}
2256+
2257+
/// True if `#[no_mangle]` or `#[export_name(...)]` is present.
2258+
pub fn contains_extern_indicator(&self) -> bool {
2259+
self.flags.contains(TransFnAttrFlags::NO_MANGLE) || self.export_name.is_some()
2260+
}
2261+
}
2262+

src/librustc/ich/impls_hir.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey,
1919
StableHasher, StableHasherResult};
2020
use std::mem;
2121
use syntax::ast;
22+
use syntax::attr;
2223

2324
impl<'gcx> HashStable<StableHashingContext<'gcx>> for DefId {
2425
#[inline]
@@ -1138,6 +1139,43 @@ impl<'gcx> ToStableHashKey<StableHashingContext<'gcx>> for hir::TraitCandidate {
11381139
}
11391140
}
11401141

1142+
impl<'hir> HashStable<StableHashingContext<'hir>> for hir::TransFnAttrs
1143+
{
1144+
fn hash_stable<W: StableHasherResult>(&self,
1145+
hcx: &mut StableHashingContext<'hir>,
1146+
hasher: &mut StableHasher<W>) {
1147+
let hir::TransFnAttrs {
1148+
flags,
1149+
inline,
1150+
export_name,
1151+
ref target_features,
1152+
linkage,
1153+
} = *self;
1154+
1155+
flags.hash_stable(hcx, hasher);
1156+
inline.hash_stable(hcx, hasher);
1157+
export_name.hash_stable(hcx, hasher);
1158+
target_features.hash_stable(hcx, hasher);
1159+
linkage.hash_stable(hcx, hasher);
1160+
}
1161+
}
1162+
1163+
impl<'hir> HashStable<StableHashingContext<'hir>> for hir::TransFnAttrFlags
1164+
{
1165+
fn hash_stable<W: StableHasherResult>(&self,
1166+
hcx: &mut StableHashingContext<'hir>,
1167+
hasher: &mut StableHasher<W>) {
1168+
self.bits().hash_stable(hcx, hasher);
1169+
}
1170+
}
1171+
1172+
impl<'hir> HashStable<StableHashingContext<'hir>> for attr::InlineAttr {
1173+
fn hash_stable<W: StableHasherResult>(&self,
1174+
hcx: &mut StableHashingContext<'hir>,
1175+
hasher: &mut StableHasher<W>) {
1176+
mem::discriminant(self).hash_stable(hcx, hasher);
1177+
}
1178+
}
11411179

11421180
impl_stable_hash_for!(struct hir::Freevar {
11431181
def,

src/librustc/middle/reachable.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// makes all other generics or inline functions that it references
1616
// reachable as well.
1717

18+
use hir::TransFnAttrs;
1819
use hir::map as hir_map;
1920
use hir::def::Def;
2021
use hir::def_id::{DefId, CrateNum};
@@ -43,8 +44,8 @@ fn generics_require_inlining(generics: &hir::Generics) -> bool {
4344
// Returns true if the given item must be inlined because it may be
4445
// monomorphized or it was marked with `#[inline]`. This will only return
4546
// true for functions.
46-
fn item_might_be_inlined(item: &hir::Item) -> bool {
47-
if attr::requests_inline(&item.attrs) {
47+
fn item_might_be_inlined(item: &hir::Item, attrs: TransFnAttrs) -> bool {
48+
if attrs.requests_inline() {
4849
return true
4950
}
5051

@@ -60,14 +61,15 @@ fn item_might_be_inlined(item: &hir::Item) -> bool {
6061
fn method_might_be_inlined<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
6162
impl_item: &hir::ImplItem,
6263
impl_src: DefId) -> bool {
63-
if attr::requests_inline(&impl_item.attrs) ||
64+
let trans_fn_attrs = tcx.trans_fn_attrs(impl_item.hir_id.owner_def_id());
65+
if trans_fn_attrs.requests_inline() ||
6466
generics_require_inlining(&impl_item.generics) {
6567
return true
6668
}
6769
if let Some(impl_node_id) = tcx.hir.as_local_node_id(impl_src) {
6870
match tcx.hir.find(impl_node_id) {
6971
Some(hir_map::NodeItem(item)) =>
70-
item_might_be_inlined(&item),
72+
item_might_be_inlined(&item, trans_fn_attrs),
7173
Some(..) | None =>
7274
span_bug!(impl_item.span, "impl did is not an item")
7375
}
@@ -160,7 +162,8 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
160162
match self.tcx.hir.find(node_id) {
161163
Some(hir_map::NodeItem(item)) => {
162164
match item.node {
163-
hir::ItemFn(..) => item_might_be_inlined(&item),
165+
hir::ItemFn(..) =>
166+
item_might_be_inlined(&item, self.tcx.trans_fn_attrs(def_id)),
164167
_ => false,
165168
}
166169
}
@@ -176,8 +179,9 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
176179
match impl_item.node {
177180
hir::ImplItemKind::Const(..) => true,
178181
hir::ImplItemKind::Method(..) => {
182+
let attrs = self.tcx.trans_fn_attrs(def_id);
179183
if generics_require_inlining(&impl_item.generics) ||
180-
attr::requests_inline(&impl_item.attrs) {
184+
attrs.requests_inline() {
181185
true
182186
} else {
183187
let impl_did = self.tcx
@@ -229,7 +233,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
229233
false
230234
};
231235
let def_id = self.tcx.hir.local_def_id(item.id);
232-
let is_extern = self.tcx.contains_extern_indicator(def_id);
236+
let is_extern = self.tcx.trans_fn_attrs(def_id).contains_extern_indicator();
233237
if reachable || is_extern {
234238
self.reachable_symbols.insert(search_item);
235239
}
@@ -246,7 +250,8 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
246250
hir_map::NodeItem(item) => {
247251
match item.node {
248252
hir::ItemFn(.., body) => {
249-
if item_might_be_inlined(&item) {
253+
let def_id = self.tcx.hir.local_def_id(item.id);
254+
if item_might_be_inlined(&item, self.tcx.trans_fn_attrs(def_id)) {
250255
self.visit_nested_body(body);
251256
}
252257
}

src/librustc/mir/mono.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub struct CodegenUnit<'tcx> {
7373
size_estimate: Option<usize>,
7474
}
7575

76-
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
76+
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)]
7777
pub enum Linkage {
7878
External,
7979
AvailableExternally,

src/librustc/ty/instance.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ impl<'tcx> InstanceDef<'tcx> {
9696
&self,
9797
tcx: TyCtxt<'a, 'tcx, 'tcx>
9898
) -> bool {
99-
use syntax::attr::requests_inline;
10099
if self.is_inline(tcx) {
101100
return true
102101
}
@@ -106,8 +105,8 @@ impl<'tcx> InstanceDef<'tcx> {
106105
// available to normal end-users.
107106
return true
108107
}
109-
requests_inline(&self.attrs(tcx)[..]) ||
110-
tcx.is_const_fn(self.def_id())
108+
let trans_fn_attrs = tcx.trans_fn_attrs(self.def_id());
109+
trans_fn_attrs.requests_inline() || tcx.is_const_fn(self.def_id())
111110
}
112111
}
113112

src/librustc/ty/maps/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,8 +687,8 @@ impl_disk_cacheable_query!(borrowck, |def_id| def_id.is_local());
687687
impl_disk_cacheable_query!(mir_borrowck, |def_id| def_id.is_local());
688688
impl_disk_cacheable_query!(mir_const_qualif, |def_id| def_id.is_local());
689689
impl_disk_cacheable_query!(check_match, |def_id| def_id.is_local());
690-
impl_disk_cacheable_query!(contains_extern_indicator, |_| true);
691690
impl_disk_cacheable_query!(def_symbol_name, |_| true);
692691
impl_disk_cacheable_query!(type_of, |def_id| def_id.is_local());
693692
impl_disk_cacheable_query!(predicates_of, |def_id| def_id.is_local());
694693
impl_disk_cacheable_query!(used_trait_imports, |def_id| def_id.is_local());
694+
impl_disk_cacheable_query!(trans_fn_attrs, |_| true);

src/librustc/ty/maps/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use dep_graph::{DepConstructor, DepNode};
1212
use errors::DiagnosticBuilder;
1313
use hir::def_id::{CrateNum, DefId, DefIndex};
1414
use hir::def::{Def, Export};
15-
use hir::{self, TraitCandidate, ItemLocalId};
15+
use hir::{self, TraitCandidate, ItemLocalId, TransFnAttrs};
1616
use hir::svh::Svh;
1717
use lint;
1818
use middle::borrowck::BorrowCheckResult;
@@ -235,6 +235,7 @@ define_maps! { <'tcx>
235235
[] fn lookup_stability: LookupStability(DefId) -> Option<&'tcx attr::Stability>,
236236
[] fn lookup_deprecation_entry: LookupDeprecationEntry(DefId) -> Option<DeprecationEntry>,
237237
[] fn item_attrs: ItemAttrs(DefId) -> Lrc<[ast::Attribute]>,
238+
[] fn trans_fn_attrs: trans_fn_attrs(DefId) -> TransFnAttrs,
238239
[] fn fn_arg_names: FnArgNames(DefId) -> Vec<ast::Name>,
239240
[] fn impl_parent: ImplParent(DefId) -> Option<DefId>,
240241
[] fn trait_of_item: TraitOfItem(DefId) -> Option<DefId>,
@@ -362,8 +363,6 @@ define_maps! { <'tcx>
362363
[] fn collect_and_partition_translation_items:
363364
collect_and_partition_translation_items_node(CrateNum)
364365
-> (Arc<DefIdSet>, Arc<Vec<Arc<CodegenUnit<'tcx>>>>),
365-
[] fn export_name: ExportName(DefId) -> Option<Symbol>,
366-
[] fn contains_extern_indicator: ContainsExternIndicator(DefId) -> bool,
367366
[] fn symbol_export_level: GetSymbolExportLevel(DefId) -> SymbolExportLevel,
368367
[] fn is_translated_item: IsTranslatedItem(DefId) -> bool,
369368
[] fn codegen_unit: CodegenUnit(InternedString) -> Arc<CodegenUnit<'tcx>>,
@@ -385,7 +384,6 @@ define_maps! { <'tcx>
385384

386385
[] fn target_features_whitelist:
387386
target_features_whitelist_node(CrateNum) -> Lrc<FxHashSet<String>>,
388-
[] fn target_features_enabled: TargetFeaturesEnabled(DefId) -> Lrc<Vec<String>>,
389387

390388
// Get an estimate of the size of an InstanceDef based on its MIR for CGU partitioning.
391389
[] fn instance_def_size_estimate: instance_def_size_estimate_dep_node(ty::InstanceDef<'tcx>)
@@ -403,6 +401,10 @@ fn features_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
403401
DepConstructor::Features
404402
}
405403

404+
fn trans_fn_attrs<'tcx>(id: DefId) -> DepConstructor<'tcx> {
405+
DepConstructor::TransFnAttrs { 0: id }
406+
}
407+
406408
fn erase_regions_ty<'tcx>(ty: Ty<'tcx>) -> DepConstructor<'tcx> {
407409
DepConstructor::EraseRegionsTy { ty }
408410
}

src/librustc/ty/maps/on_disk_cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,9 @@ impl<'sess> OnDiskCache<'sess> {
217217
encode_query_results::<mir_const_qualif, _>(tcx, enc, qri)?;
218218
encode_query_results::<def_symbol_name, _>(tcx, enc, qri)?;
219219
encode_query_results::<const_is_rvalue_promotable_to_static, _>(tcx, enc, qri)?;
220-
encode_query_results::<contains_extern_indicator, _>(tcx, enc, qri)?;
221220
encode_query_results::<symbol_name, _>(tcx, enc, qri)?;
222221
encode_query_results::<check_match, _>(tcx, enc, qri)?;
222+
encode_query_results::<trans_fn_attrs, _>(tcx, enc, qri)?;
223223
}
224224

225225
// Encode diagnostics

src/librustc/ty/maps/plumbing.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,7 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
854854
DepKind::IsReachableNonGeneric => { force!(is_reachable_non_generic, def_id!()); }
855855
DepKind::IsMirAvailable => { force!(is_mir_available, def_id!()); }
856856
DepKind::ItemAttrs => { force!(item_attrs, def_id!()); }
857+
DepKind::TransFnAttrs => { force!(trans_fn_attrs, def_id!()); }
857858
DepKind::FnArgNames => { force!(fn_arg_names, def_id!()); }
858859
DepKind::DylibDepFormats => { force!(dylib_dependency_formats, krate!()); }
859860
DepKind::IsPanicRuntime => { force!(is_panic_runtime, krate!()); }
@@ -925,15 +926,10 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
925926
DepKind::CollectAndPartitionTranslationItems => {
926927
force!(collect_and_partition_translation_items, LOCAL_CRATE);
927928
}
928-
DepKind::ExportName => { force!(export_name, def_id!()); }
929-
DepKind::ContainsExternIndicator => {
930-
force!(contains_extern_indicator, def_id!());
931-
}
932929
DepKind::IsTranslatedItem => { force!(is_translated_item, def_id!()); }
933930
DepKind::OutputFilenames => { force!(output_filenames, LOCAL_CRATE); }
934931

935932
DepKind::TargetFeaturesWhitelist => { force!(target_features_whitelist, LOCAL_CRATE); }
936-
DepKind::TargetFeaturesEnabled => { force!(target_features_enabled, def_id!()); }
937933

938934
DepKind::GetSymbolExportLevel => { force!(symbol_export_level, def_id!()); }
939935
DepKind::Features => { force!(features_query, LOCAL_CRATE); }
@@ -997,10 +993,10 @@ impl_load_from_cache!(
997993
MirConstQualif => mir_const_qualif,
998994
SymbolName => def_symbol_name,
999995
ConstIsRvaluePromotableToStatic => const_is_rvalue_promotable_to_static,
1000-
ContainsExternIndicator => contains_extern_indicator,
1001996
CheckMatch => check_match,
1002997
TypeOfItem => type_of,
1003998
GenericsOfItem => generics_of,
1004999
PredicatesOfItem => predicates_of,
10051000
UsedTraitImports => used_trait_imports,
1001+
TransFnAttrs => trans_fn_attrs,
10061002
);

src/librustc_metadata/encoder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
832832
} else if let hir::ImplItemKind::Method(ref sig, body) = ast_item.node {
833833
let generics = self.tcx.generics_of(def_id);
834834
let types = generics.parent_types as usize + generics.types.len();
835-
let needs_inline = types > 0 || attr::requests_inline(&ast_item.attrs);
835+
let needs_inline = types > 0 || tcx.trans_fn_attrs(def_id).requests_inline();
836836
let is_const_fn = sig.constness == hir::Constness::Const;
837837
let ast = if is_const_fn { Some(body) } else { None };
838838
let always_encode_mir = self.tcx.sess.opts.debugging_opts.always_encode_mir;
@@ -1123,7 +1123,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
11231123
hir::ItemConst(..) => self.encode_optimized_mir(def_id),
11241124
hir::ItemFn(_, _, constness, _, ref generics, _) => {
11251125
let has_tps = generics.ty_params().next().is_some();
1126-
let needs_inline = has_tps || attr::requests_inline(&item.attrs);
1126+
let needs_inline = has_tps || tcx.trans_fn_attrs(def_id).requests_inline();
11271127
let always_encode_mir = self.tcx.sess.opts.debugging_opts.always_encode_mir;
11281128
if needs_inline || constness == hir::Constness::Const || always_encode_mir {
11291129
self.encode_optimized_mir(def_id)

0 commit comments

Comments
 (0)