]> git.lizzy.rs Git - rust.git/commitdiff
Implement `repr(simd)` as an alias for `#[simd]`.
authorHuon Wilson <dbau.pp+github@gmail.com>
Mon, 13 Jul 2015 18:35:00 +0000 (11:35 -0700)
committerHuon Wilson <dbau.pp+github@gmail.com>
Mon, 17 Aug 2015 17:57:18 +0000 (10:57 -0700)
src/librustc/middle/ty.rs
src/librustc_trans/trans/adt.rs
src/librustc_typeck/check/mod.rs
src/libsyntax/attr.rs
src/libsyntax/ext/deriving/generic/mod.rs
src/libsyntax/feature_gate.rs
src/test/compile-fail/feature-gate-repr-simd.rs [new file with mode: 0644]

index 967eb3ff74f49f20b0a2adc64d1e2948deae973e..d7a58f4cdd08c80bfaa34a2757cc1e11f6ec1971 100644 (file)
@@ -3312,10 +3312,10 @@ fn new(tcx: &ctxt<'tcx>,
            variants: Vec<VariantDefData<'tcx, 'container>>) -> Self {
         let mut flags = AdtFlags::NO_ADT_FLAGS;
         let attrs = tcx.get_attrs(did);
-        if attrs.iter().any(|item| item.check_name("fundamental")) {
+        if attr::contains_name(&attrs, "fundamental") {
             flags = flags | AdtFlags::IS_FUNDAMENTAL;
         }
-        if attrs.iter().any(|item| item.check_name("simd")) {
+        if tcx.lookup_simd(did) {
             flags = flags | AdtFlags::IS_SIMD;
         }
         if Some(did) == tcx.lang_items.phantom_data() {
@@ -6116,6 +6116,7 @@ pub fn lookup_packed(&self, did: DefId) -> bool {
     /// Determine whether an item is annotated with `#[simd]`
     pub fn lookup_simd(&self, did: DefId) -> bool {
         self.has_attr(did, "simd")
+            || self.lookup_repr_hints(did).contains(&attr::ReprSimd)
     }
 
     /// Obtain the representation annotation for a struct definition.
index 326d1e2361e6d3ad631a626a5ba5a8fc598130e4..0d34cce919a64993b5208924be3b5366f80be141 100644 (file)
@@ -615,6 +615,9 @@ fn range_to_inttype(cx: &CrateContext, hint: Hint, bounds: &IntBounds) -> IntTyp
         attr::ReprPacked => {
             cx.tcx().sess.bug("range_to_inttype: found ReprPacked on an enum");
         }
+        attr::ReprSimd => {
+            cx.tcx().sess.bug("range_to_inttype: found ReprSimd on an enum");
+        }
     }
     for &ity in attempts {
         if bounds_usable(cx, ity, bounds) {
index bf5d1373d0bf56a961aaa081518dbea6db4a141d..e32964db7486a51d4612e617c01050325179d982 100644 (file)
@@ -4421,6 +4421,9 @@ fn do_check<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
                             "discriminant type specified here");
                     }
                 }
+                attr::ReprSimd => {
+                    ccx.tcx.sess.bug("range_to_inttype: found ReprSimd on an enum");
+                }
                 attr::ReprPacked => {
                     ccx.tcx.sess.bug("range_to_inttype: found ReprPacked on an enum");
                 }
index 5e16465b4d4bfa330dda2b4d364d48b915d9a620..3de9ba5197489931eb64de491f651ad9387c4b33 100644 (file)
@@ -579,6 +579,7 @@ pub fn find_repr_attrs(diagnostic: &SpanHandler, attr: &Attribute) -> Vec<ReprAt
                             // Can't use "extern" because it's not a lexical identifier.
                             "C" => Some(ReprExtern),
                             "packed" => Some(ReprPacked),
+                            "simd" => Some(ReprSimd),
                             _ => match int_type_of_word(&word) {
                                 Some(ity) => Some(ReprInt(item.span, ity)),
                                 None => {
@@ -628,6 +629,7 @@ pub enum ReprAttr {
     ReprInt(Span, IntType),
     ReprExtern,
     ReprPacked,
+    ReprSimd,
 }
 
 impl ReprAttr {
@@ -636,7 +638,8 @@ pub fn is_ffi_safe(&self) -> bool {
             ReprAny => false,
             ReprInt(_sp, ity) => ity.is_ffi_safe(),
             ReprExtern => true,
-            ReprPacked => false
+            ReprPacked => false,
+            ReprSimd => true,
         }
     }
 }
index 1f4860b7ec11ead5d270eadc61c7d91dfb757e3e..f8f63e94ee574b04472e1e69af9476ff9f9d0a14 100644 (file)
@@ -739,7 +739,7 @@ fn find_repr_type_name(diagnostic: &SpanHandler,
     for a in type_attrs {
         for r in &attr::find_repr_attrs(diagnostic, a) {
             repr_type_name = match *r {
-                attr::ReprAny | attr::ReprPacked => continue,
+                attr::ReprAny | attr::ReprPacked | attr::ReprSimd => continue,
                 attr::ReprExtern => "i32",
 
                 attr::ReprInt(_, attr::SignedInt(ast::TyIs)) => "isize",
index 694a1a43f593d9940f5f2334034bb7adf967eb4f..a12291161f74f657d2bacc5288cabdab42cc6cc5 100644 (file)
     // Allows macros to appear in the type position.
 
     ("type_macros", "1.3.0", Active),
+
+    // allow `repr(simd)`, and importing the various simd intrinsics
+    ("simd_basics", "1.3.0", Active),
 ];
 // (changing above list without updating src/doc/reference.md makes @cmr sad)
 
@@ -359,6 +362,7 @@ pub struct Features {
     pub allow_box: bool,
     pub allow_pushpop_unsafe: bool,
     pub simd_ffi: bool,
+    pub simd_basics: bool,
     pub unmarked_api: bool,
     pub negate_unsigned: bool,
     /// spans of #![feature] attrs for stable language features. for error reporting
@@ -388,6 +392,7 @@ pub fn new() -> Features {
             allow_box: false,
             allow_pushpop_unsafe: false,
             simd_ffi: false,
+            simd_basics: false,
             unmarked_api: false,
             negate_unsigned: false,
             declared_stable_lang_features: Vec::new(),
@@ -660,6 +665,20 @@ fn visit_item(&mut self, i: &ast::Item) {
                 if attr::contains_name(&i.attrs[..], "simd") {
                     self.gate_feature("simd", i.span,
                                       "SIMD types are experimental and possibly buggy");
+                    self.context.span_handler.span_warn(i.span,
+                                                        "the `#[simd]` attribute is deprecated, \
+                                                         use `#[repr(simd)]` instead");
+                }
+                for attr in &i.attrs {
+                    if attr.name() == "repr" {
+                        for item in attr.meta_item_list().unwrap_or(&[]) {
+                            if item.name() == "simd" {
+                                self.gate_feature("simd_basics", i.span,
+                                                  "SIMD types are experimental and possibly buggy");
+
+                            }
+                        }
+                    }
                 }
             }
 
@@ -892,6 +911,7 @@ fn check_crate_inner<F>(cm: &CodeMap, span_handler: &SpanHandler,
         allow_box: cx.has_feature("box_syntax"),
         allow_pushpop_unsafe: cx.has_feature("pushpop_unsafe"),
         simd_ffi: cx.has_feature("simd_ffi"),
+        simd_basics: cx.has_feature("simd_basics"),
         unmarked_api: cx.has_feature("unmarked_api"),
         negate_unsigned: cx.has_feature("negate_unsigned"),
         declared_stable_lang_features: accepted_features,
diff --git a/src/test/compile-fail/feature-gate-repr-simd.rs b/src/test/compile-fail/feature-gate-repr-simd.rs
new file mode 100644 (file)
index 0000000..fdafb2a
--- /dev/null
@@ -0,0 +1,14 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#[repr(simd)]
+struct Foo(u64, u64); //~ error: SIMD types are experimental
+
+fn main() {}