Implement repr(simd)
as an alias for #[simd]
.
This commit is contained in:
parent
e822a18ae7
commit
c8b6d5b23c
7 changed files with 48 additions and 4 deletions
|
@ -3312,10 +3312,10 @@ impl<'tcx, 'container> AdtDefData<'tcx, 'container> {
|
||||||
variants: Vec<VariantDefData<'tcx, 'container>>) -> Self {
|
variants: Vec<VariantDefData<'tcx, 'container>>) -> Self {
|
||||||
let mut flags = AdtFlags::NO_ADT_FLAGS;
|
let mut flags = AdtFlags::NO_ADT_FLAGS;
|
||||||
let attrs = tcx.get_attrs(did);
|
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;
|
flags = flags | AdtFlags::IS_FUNDAMENTAL;
|
||||||
}
|
}
|
||||||
if attrs.iter().any(|item| item.check_name("simd")) {
|
if tcx.lookup_simd(did) {
|
||||||
flags = flags | AdtFlags::IS_SIMD;
|
flags = flags | AdtFlags::IS_SIMD;
|
||||||
}
|
}
|
||||||
if Some(did) == tcx.lang_items.phantom_data() {
|
if Some(did) == tcx.lang_items.phantom_data() {
|
||||||
|
@ -6116,6 +6116,7 @@ impl<'tcx> ctxt<'tcx> {
|
||||||
/// Determine whether an item is annotated with `#[simd]`
|
/// Determine whether an item is annotated with `#[simd]`
|
||||||
pub fn lookup_simd(&self, did: DefId) -> bool {
|
pub fn lookup_simd(&self, did: DefId) -> bool {
|
||||||
self.has_attr(did, "simd")
|
self.has_attr(did, "simd")
|
||||||
|
|| self.lookup_repr_hints(did).contains(&attr::ReprSimd)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Obtain the representation annotation for a struct definition.
|
/// Obtain the representation annotation for a struct definition.
|
||||||
|
|
|
@ -615,6 +615,9 @@ fn range_to_inttype(cx: &CrateContext, hint: Hint, bounds: &IntBounds) -> IntTyp
|
||||||
attr::ReprPacked => {
|
attr::ReprPacked => {
|
||||||
cx.tcx().sess.bug("range_to_inttype: found ReprPacked on an enum");
|
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 {
|
for &ity in attempts {
|
||||||
if bounds_usable(cx, ity, bounds) {
|
if bounds_usable(cx, ity, bounds) {
|
||||||
|
|
|
@ -4421,6 +4421,9 @@ pub fn check_enum_variants<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
|
||||||
"discriminant type specified here");
|
"discriminant type specified here");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
attr::ReprSimd => {
|
||||||
|
ccx.tcx.sess.bug("range_to_inttype: found ReprSimd on an enum");
|
||||||
|
}
|
||||||
attr::ReprPacked => {
|
attr::ReprPacked => {
|
||||||
ccx.tcx.sess.bug("range_to_inttype: found ReprPacked on an enum");
|
ccx.tcx.sess.bug("range_to_inttype: found ReprPacked on an enum");
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.
|
// Can't use "extern" because it's not a lexical identifier.
|
||||||
"C" => Some(ReprExtern),
|
"C" => Some(ReprExtern),
|
||||||
"packed" => Some(ReprPacked),
|
"packed" => Some(ReprPacked),
|
||||||
|
"simd" => Some(ReprSimd),
|
||||||
_ => match int_type_of_word(&word) {
|
_ => match int_type_of_word(&word) {
|
||||||
Some(ity) => Some(ReprInt(item.span, ity)),
|
Some(ity) => Some(ReprInt(item.span, ity)),
|
||||||
None => {
|
None => {
|
||||||
|
@ -628,6 +629,7 @@ pub enum ReprAttr {
|
||||||
ReprInt(Span, IntType),
|
ReprInt(Span, IntType),
|
||||||
ReprExtern,
|
ReprExtern,
|
||||||
ReprPacked,
|
ReprPacked,
|
||||||
|
ReprSimd,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ReprAttr {
|
impl ReprAttr {
|
||||||
|
@ -636,7 +638,8 @@ impl ReprAttr {
|
||||||
ReprAny => false,
|
ReprAny => false,
|
||||||
ReprInt(_sp, ity) => ity.is_ffi_safe(),
|
ReprInt(_sp, ity) => ity.is_ffi_safe(),
|
||||||
ReprExtern => true,
|
ReprExtern => true,
|
||||||
ReprPacked => false
|
ReprPacked => false,
|
||||||
|
ReprSimd => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -739,7 +739,7 @@ fn find_repr_type_name(diagnostic: &SpanHandler,
|
||||||
for a in type_attrs {
|
for a in type_attrs {
|
||||||
for r in &attr::find_repr_attrs(diagnostic, a) {
|
for r in &attr::find_repr_attrs(diagnostic, a) {
|
||||||
repr_type_name = match *r {
|
repr_type_name = match *r {
|
||||||
attr::ReprAny | attr::ReprPacked => continue,
|
attr::ReprAny | attr::ReprPacked | attr::ReprSimd => continue,
|
||||||
attr::ReprExtern => "i32",
|
attr::ReprExtern => "i32",
|
||||||
|
|
||||||
attr::ReprInt(_, attr::SignedInt(ast::TyIs)) => "isize",
|
attr::ReprInt(_, attr::SignedInt(ast::TyIs)) => "isize",
|
||||||
|
|
|
@ -177,6 +177,9 @@ const KNOWN_FEATURES: &'static [(&'static str, &'static str, Status)] = &[
|
||||||
// Allows macros to appear in the type position.
|
// Allows macros to appear in the type position.
|
||||||
|
|
||||||
("type_macros", "1.3.0", Active),
|
("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)
|
// (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_box: bool,
|
||||||
pub allow_pushpop_unsafe: bool,
|
pub allow_pushpop_unsafe: bool,
|
||||||
pub simd_ffi: bool,
|
pub simd_ffi: bool,
|
||||||
|
pub simd_basics: bool,
|
||||||
pub unmarked_api: bool,
|
pub unmarked_api: bool,
|
||||||
pub negate_unsigned: bool,
|
pub negate_unsigned: bool,
|
||||||
/// spans of #![feature] attrs for stable language features. for error reporting
|
/// spans of #![feature] attrs for stable language features. for error reporting
|
||||||
|
@ -388,6 +392,7 @@ impl Features {
|
||||||
allow_box: false,
|
allow_box: false,
|
||||||
allow_pushpop_unsafe: false,
|
allow_pushpop_unsafe: false,
|
||||||
simd_ffi: false,
|
simd_ffi: false,
|
||||||
|
simd_basics: false,
|
||||||
unmarked_api: false,
|
unmarked_api: false,
|
||||||
negate_unsigned: false,
|
negate_unsigned: false,
|
||||||
declared_stable_lang_features: Vec::new(),
|
declared_stable_lang_features: Vec::new(),
|
||||||
|
@ -660,6 +665,20 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
|
||||||
if attr::contains_name(&i.attrs[..], "simd") {
|
if attr::contains_name(&i.attrs[..], "simd") {
|
||||||
self.gate_feature("simd", i.span,
|
self.gate_feature("simd", i.span,
|
||||||
"SIMD types are experimental and possibly buggy");
|
"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_box: cx.has_feature("box_syntax"),
|
||||||
allow_pushpop_unsafe: cx.has_feature("pushpop_unsafe"),
|
allow_pushpop_unsafe: cx.has_feature("pushpop_unsafe"),
|
||||||
simd_ffi: cx.has_feature("simd_ffi"),
|
simd_ffi: cx.has_feature("simd_ffi"),
|
||||||
|
simd_basics: cx.has_feature("simd_basics"),
|
||||||
unmarked_api: cx.has_feature("unmarked_api"),
|
unmarked_api: cx.has_feature("unmarked_api"),
|
||||||
negate_unsigned: cx.has_feature("negate_unsigned"),
|
negate_unsigned: cx.has_feature("negate_unsigned"),
|
||||||
declared_stable_lang_features: accepted_features,
|
declared_stable_lang_features: accepted_features,
|
||||||
|
|
14
src/test/compile-fail/feature-gate-repr-simd.rs
Normal file
14
src/test/compile-fail/feature-gate-repr-simd.rs
Normal file
|
@ -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() {}
|
Loading…
Add table
Add a link
Reference in a new issue