Skip to content

Commit c8b6d5b

Browse files
committed
Implement repr(simd) as an alias for #[simd].
1 parent e822a18 commit c8b6d5b

File tree

7 files changed

+48
-4
lines changed

7 files changed

+48
-4
lines changed

src/librustc/middle/ty.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -3312,10 +3312,10 @@ impl<'tcx, 'container> AdtDefData<'tcx, 'container> {
33123312
variants: Vec<VariantDefData<'tcx, 'container>>) -> Self {
33133313
let mut flags = AdtFlags::NO_ADT_FLAGS;
33143314
let attrs = tcx.get_attrs(did);
3315-
if attrs.iter().any(|item| item.check_name("fundamental")) {
3315+
if attr::contains_name(&attrs, "fundamental") {
33163316
flags = flags | AdtFlags::IS_FUNDAMENTAL;
33173317
}
3318-
if attrs.iter().any(|item| item.check_name("simd")) {
3318+
if tcx.lookup_simd(did) {
33193319
flags = flags | AdtFlags::IS_SIMD;
33203320
}
33213321
if Some(did) == tcx.lang_items.phantom_data() {
@@ -6116,6 +6116,7 @@ impl<'tcx> ctxt<'tcx> {
61166116
/// Determine whether an item is annotated with `#[simd]`
61176117
pub fn lookup_simd(&self, did: DefId) -> bool {
61186118
self.has_attr(did, "simd")
6119+
|| self.lookup_repr_hints(did).contains(&attr::ReprSimd)
61196120
}
61206121

61216122
/// Obtain the representation annotation for a struct definition.

src/librustc_trans/trans/adt.rs

+3
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,9 @@ fn range_to_inttype(cx: &CrateContext, hint: Hint, bounds: &IntBounds) -> IntTyp
615615
attr::ReprPacked => {
616616
cx.tcx().sess.bug("range_to_inttype: found ReprPacked on an enum");
617617
}
618+
attr::ReprSimd => {
619+
cx.tcx().sess.bug("range_to_inttype: found ReprSimd on an enum");
620+
}
618621
}
619622
for &ity in attempts {
620623
if bounds_usable(cx, ity, bounds) {

src/librustc_typeck/check/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -4421,6 +4421,9 @@ pub fn check_enum_variants<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
44214421
"discriminant type specified here");
44224422
}
44234423
}
4424+
attr::ReprSimd => {
4425+
ccx.tcx.sess.bug("range_to_inttype: found ReprSimd on an enum");
4426+
}
44244427
attr::ReprPacked => {
44254428
ccx.tcx.sess.bug("range_to_inttype: found ReprPacked on an enum");
44264429
}

src/libsyntax/attr.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,7 @@ pub fn find_repr_attrs(diagnostic: &SpanHandler, attr: &Attribute) -> Vec<ReprAt
579579
// Can't use "extern" because it's not a lexical identifier.
580580
"C" => Some(ReprExtern),
581581
"packed" => Some(ReprPacked),
582+
"simd" => Some(ReprSimd),
582583
_ => match int_type_of_word(&word) {
583584
Some(ity) => Some(ReprInt(item.span, ity)),
584585
None => {
@@ -628,6 +629,7 @@ pub enum ReprAttr {
628629
ReprInt(Span, IntType),
629630
ReprExtern,
630631
ReprPacked,
632+
ReprSimd,
631633
}
632634

633635
impl ReprAttr {
@@ -636,7 +638,8 @@ impl ReprAttr {
636638
ReprAny => false,
637639
ReprInt(_sp, ity) => ity.is_ffi_safe(),
638640
ReprExtern => true,
639-
ReprPacked => false
641+
ReprPacked => false,
642+
ReprSimd => true,
640643
}
641644
}
642645
}

src/libsyntax/ext/deriving/generic/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ fn find_repr_type_name(diagnostic: &SpanHandler,
739739
for a in type_attrs {
740740
for r in &attr::find_repr_attrs(diagnostic, a) {
741741
repr_type_name = match *r {
742-
attr::ReprAny | attr::ReprPacked => continue,
742+
attr::ReprAny | attr::ReprPacked | attr::ReprSimd => continue,
743743
attr::ReprExtern => "i32",
744744

745745
attr::ReprInt(_, attr::SignedInt(ast::TyIs)) => "isize",

src/libsyntax/feature_gate.rs

+20
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ const KNOWN_FEATURES: &'static [(&'static str, &'static str, Status)] = &[
177177
// Allows macros to appear in the type position.
178178

179179
("type_macros", "1.3.0", Active),
180+
181+
// allow `repr(simd)`, and importing the various simd intrinsics
182+
("simd_basics", "1.3.0", Active),
180183
];
181184
// (changing above list without updating src/doc/reference.md makes @cmr sad)
182185

@@ -359,6 +362,7 @@ pub struct Features {
359362
pub allow_box: bool,
360363
pub allow_pushpop_unsafe: bool,
361364
pub simd_ffi: bool,
365+
pub simd_basics: bool,
362366
pub unmarked_api: bool,
363367
pub negate_unsigned: bool,
364368
/// spans of #![feature] attrs for stable language features. for error reporting
@@ -388,6 +392,7 @@ impl Features {
388392
allow_box: false,
389393
allow_pushpop_unsafe: false,
390394
simd_ffi: false,
395+
simd_basics: false,
391396
unmarked_api: false,
392397
negate_unsigned: false,
393398
declared_stable_lang_features: Vec::new(),
@@ -660,6 +665,20 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
660665
if attr::contains_name(&i.attrs[..], "simd") {
661666
self.gate_feature("simd", i.span,
662667
"SIMD types are experimental and possibly buggy");
668+
self.context.span_handler.span_warn(i.span,
669+
"the `#[simd]` attribute is deprecated, \
670+
use `#[repr(simd)]` instead");
671+
}
672+
for attr in &i.attrs {
673+
if attr.name() == "repr" {
674+
for item in attr.meta_item_list().unwrap_or(&[]) {
675+
if item.name() == "simd" {
676+
self.gate_feature("simd_basics", i.span,
677+
"SIMD types are experimental and possibly buggy");
678+
679+
}
680+
}
681+
}
663682
}
664683
}
665684

@@ -892,6 +911,7 @@ fn check_crate_inner<F>(cm: &CodeMap, span_handler: &SpanHandler,
892911
allow_box: cx.has_feature("box_syntax"),
893912
allow_pushpop_unsafe: cx.has_feature("pushpop_unsafe"),
894913
simd_ffi: cx.has_feature("simd_ffi"),
914+
simd_basics: cx.has_feature("simd_basics"),
895915
unmarked_api: cx.has_feature("unmarked_api"),
896916
negate_unsigned: cx.has_feature("negate_unsigned"),
897917
declared_stable_lang_features: accepted_features,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#[repr(simd)]
12+
struct Foo(u64, u64); //~ error: SIMD types are experimental
13+
14+
fn main() {}

0 commit comments

Comments
 (0)