Skip to content

Commit c202448

Browse files
committed
Auto merge of rust-lang#129764 - veluca93:struct_tf, r=<try>
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
2 parents 784d444 + c38046b commit c202448

File tree

6 files changed

+38
-4
lines changed

6 files changed

+38
-4
lines changed

compiler/rustc_hir/src/def.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,10 @@ impl DefKind {
330330
/// Whether `query struct_target_features` should be used with this definition.
331331
pub fn has_struct_target_features(self) -> bool {
332332
match self {
333-
DefKind::Struct | DefKind::Union | DefKind::Enum => true,
333+
DefKind::Struct => true,
334334
DefKind::Fn
335+
| DefKind::Union
336+
| DefKind::Enum
335337
| DefKind::AssocFn
336338
| DefKind::Ctor(..)
337339
| DefKind::Closure

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ provide! { tcx, def_id, other, cdata,
224224
variances_of => { table }
225225
fn_sig => { table }
226226
codegen_fn_attrs => { table }
227-
struct_target_features => { table }
227+
struct_target_features => { table_defaulted_array }
228228
impl_trait_header => { table }
229229
const_param_default => { table }
230230
object_lifetime_default => { table }

compiler/rustc_metadata/src/rmeta/encoder.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1393,7 +1393,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
13931393
record!(self.tables.codegen_fn_attrs[def_id] <- self.tcx.codegen_fn_attrs(def_id));
13941394
}
13951395
if def_kind.has_struct_target_features() {
1396-
record_array!(self.tables.struct_target_features[def_id] <- self.tcx.struct_target_features(def_id));
1396+
let struct_target_features = self.tcx.struct_target_features(def_id);
1397+
if !struct_target_features.is_empty() {
1398+
record_defaulted_array!(self.tables.struct_target_features[def_id] <- struct_target_features);
1399+
}
13971400
}
13981401
if should_encode_visibility(def_kind) {
13991402
let vis =

compiler/rustc_metadata/src/rmeta/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ define_tables! {
402402
// individually instead of `DefId`s.
403403
module_children_reexports: Table<DefIndex, LazyArray<ModChild>>,
404404
cross_crate_inlinable: Table<DefIndex, bool>,
405+
struct_target_features: Table<DefIndex, LazyArray<TargetFeature>>,
405406

406407
- optional:
407408
attributes: Table<DefIndex, LazyArray<ast::Attribute>>,
@@ -427,7 +428,6 @@ define_tables! {
427428
variances_of: Table<DefIndex, LazyArray<ty::Variance>>,
428429
fn_sig: Table<DefIndex, LazyValue<ty::EarlyBinder<'static, ty::PolyFnSig<'static>>>>,
429430
codegen_fn_attrs: Table<DefIndex, LazyValue<CodegenFnAttrs>>,
430-
struct_target_features: Table<DefIndex, LazyArray<TargetFeature>>,
431431
impl_trait_header: Table<DefIndex, LazyValue<ty::ImplTraitHeader<'static>>>,
432432
const_param_default: Table<DefIndex, LazyValue<ty::EarlyBinder<'static, rustc_middle::ty::Const<'static>>>>,
433433
object_lifetime_default: Table<DefIndex, LazyValue<ObjectLifetimeDefault>>,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#![feature(struct_target_features)]
2+
3+
#[target_feature(enable = "avx")]
4+
pub struct Avx {}
5+
6+
pub struct NoFeatures {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//@ only-x86_64
2+
//@ aux-build: struct-target-features-crate-dep.rs
3+
//@ check-pass
4+
#![feature(target_feature_11)]
5+
6+
extern crate struct_target_features_crate_dep;
7+
8+
#[target_feature(enable = "avx")]
9+
fn avx() {}
10+
11+
fn f(_: struct_target_features_crate_dep::Avx) {
12+
avx();
13+
}
14+
15+
fn g(_: struct_target_features_crate_dep::NoFeatures) {}
16+
17+
fn main() {
18+
if is_x86_feature_detected!("avx") {
19+
let avx = unsafe { struct_target_features_crate_dep::Avx {} };
20+
f(avx);
21+
}
22+
g(struct_target_features_crate_dep::NoFeatures {});
23+
}

0 commit comments

Comments
 (0)