Skip to content

Commit

Permalink
Auto merge of rust-lang#129764 - veluca93:struct_tf, r=<try>
Browse files Browse the repository at this point in the history
struct_target_features: reduce serialized rmeta

Reduce the amount of serialized information in rmeta. This should fix the binary size regression in rust-lang#127537 and *may* also fix the speed regression.

r? compiler-errors

Tracking issue: rust-lang#129107
  • Loading branch information
bors committed Aug 29, 2024
2 parents 784d444 + c38046b commit c202448
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 4 deletions.
4 changes: 3 additions & 1 deletion compiler/rustc_hir/src/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,10 @@ impl DefKind {
/// Whether `query struct_target_features` should be used with this definition.
pub fn has_struct_target_features(self) -> bool {
match self {
DefKind::Struct | DefKind::Union | DefKind::Enum => true,
DefKind::Struct => true,
DefKind::Fn
| DefKind::Union
| DefKind::Enum
| DefKind::AssocFn
| DefKind::Ctor(..)
| DefKind::Closure
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ provide! { tcx, def_id, other, cdata,
variances_of => { table }
fn_sig => { table }
codegen_fn_attrs => { table }
struct_target_features => { table }
struct_target_features => { table_defaulted_array }
impl_trait_header => { table }
const_param_default => { table }
object_lifetime_default => { table }
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1393,7 +1393,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
record!(self.tables.codegen_fn_attrs[def_id] <- self.tcx.codegen_fn_attrs(def_id));
}
if def_kind.has_struct_target_features() {
record_array!(self.tables.struct_target_features[def_id] <- self.tcx.struct_target_features(def_id));
let struct_target_features = self.tcx.struct_target_features(def_id);
if !struct_target_features.is_empty() {
record_defaulted_array!(self.tables.struct_target_features[def_id] <- struct_target_features);
}
}
if should_encode_visibility(def_kind) {
let vis =
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/rmeta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ define_tables! {
// individually instead of `DefId`s.
module_children_reexports: Table<DefIndex, LazyArray<ModChild>>,
cross_crate_inlinable: Table<DefIndex, bool>,
struct_target_features: Table<DefIndex, LazyArray<TargetFeature>>,

- optional:
attributes: Table<DefIndex, LazyArray<ast::Attribute>>,
Expand All @@ -427,7 +428,6 @@ define_tables! {
variances_of: Table<DefIndex, LazyArray<ty::Variance>>,
fn_sig: Table<DefIndex, LazyValue<ty::EarlyBinder<'static, ty::PolyFnSig<'static>>>>,
codegen_fn_attrs: Table<DefIndex, LazyValue<CodegenFnAttrs>>,
struct_target_features: Table<DefIndex, LazyArray<TargetFeature>>,
impl_trait_header: Table<DefIndex, LazyValue<ty::ImplTraitHeader<'static>>>,
const_param_default: Table<DefIndex, LazyValue<ty::EarlyBinder<'static, rustc_middle::ty::Const<'static>>>>,
object_lifetime_default: Table<DefIndex, LazyValue<ObjectLifetimeDefault>>,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#![feature(struct_target_features)]

#[target_feature(enable = "avx")]
pub struct Avx {}

pub struct NoFeatures {}
23 changes: 23 additions & 0 deletions tests/ui/target-feature/struct-target-features-crate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//@ only-x86_64
//@ aux-build: struct-target-features-crate-dep.rs
//@ check-pass
#![feature(target_feature_11)]

extern crate struct_target_features_crate_dep;

#[target_feature(enable = "avx")]
fn avx() {}

fn f(_: struct_target_features_crate_dep::Avx) {
avx();
}

fn g(_: struct_target_features_crate_dep::NoFeatures) {}

fn main() {
if is_x86_feature_detected!("avx") {
let avx = unsafe { struct_target_features_crate_dep::Avx {} };
f(avx);
}
g(struct_target_features_crate_dep::NoFeatures {});
}

0 comments on commit c202448

Please sign in to comment.