}
}
+pub fn type_is_machine(ty: t) -> bool {
+ match get(ty).sty {
+ ty_int(ast::ty_i) | ty_uint(ast::ty_u) | ty_float(ast::ty_f) => false,
+ ty_int(*) | ty_uint(*) | ty_float(*) => true,
+ _ => false
+ }
+}
+
// Whether a type is Plain Old Data -- meaning it does not contain pointers
// that the cycle collector might care about.
pub fn type_is_pod(cx: ctxt, ty: t) -> bool {
attrs: ref attrs,
_
}, _)) => attr::attrs_contains_name(*attrs, attr),
- _ => tcx.sess.bug(fmt!("lookup_packed: %? is not an item",
+ _ => tcx.sess.bug(fmt!("has_attr: %? is not an item",
did))
}
} else {
}
}
-/// Determine whether an item is annotated with `#[packed]` or not
+/// Determine whether an item is annotated with `#[packed]`
pub fn lookup_packed(tcx: ctxt, did: def_id) -> bool {
has_attr(tcx, did, "packed")
}
+/// Determine whether an item is annotated with `#[simd]`
+pub fn lookup_simd(tcx: ctxt, did: def_id) -> bool {
+ has_attr(tcx, did, "simd")
+}
+
// Look up a field ID, whether or not it's local
// Takes a list of type substs in case the struct is generic
pub fn lookup_field_type(tcx: ctxt,
}
pub fn check_struct(ccx: @mut CrateCtxt, id: ast::node_id, span: span) {
+ let tcx = ccx.tcx;
+
// Check that the class is instantiable
- check_instantiable(ccx.tcx, span, id);
+ check_instantiable(tcx, span, id);
+
+ if ty::lookup_simd(tcx, local_def(id)) {
+ check_simd(tcx, span, id);
+ }
}
pub fn check_item(ccx: @mut CrateCtxt, it: @ast::item) {
}
}
+pub fn check_simd(tcx: ty::ctxt, sp: span, id: ast::node_id) {
+ let t = ty::node_id_to_type(tcx, id);
+ if ty::type_needs_subst(t) {
+ tcx.sess.span_err(sp, "SIMD vector cannot be generic");
+ return;
+ }
+ match ty::get(t).sty {
+ ty::ty_struct(did, ref substs) => {
+ let fields = ty::lookup_struct_fields(tcx, did);
+ if fields.is_empty() {
+ tcx.sess.span_err(sp, "SIMD vector cannot be empty");
+ return;
+ }
+ let e = ty::lookup_field_type(tcx, did, fields[0].id, substs);
+ if !vec::all(fields,
+ |f| ty::lookup_field_type(tcx, did, f.id, substs) == e) {
+ tcx.sess.span_err(sp, "SIMD vector should be homogeneous");
+ return;
+ }
+ if !ty::type_is_machine(e) {
+ tcx.sess.span_err(sp, "SIMD vector element type should be \
+ machine type");
+ return;
+ }
+ }
+ _ => ()
+ }
+}
+
pub fn check_enum_variants(ccx: @mut CrateCtxt,
sp: span,
vs: &[ast::variant],