Skip to content

Commit 642e52c

Browse files
committed
---
yaml --- r: 60051 b: refs/heads/master c: f3217a5 h: refs/heads/master i: 60049: 203faee 60047: 868bb47 v: v3
1 parent 304e1a1 commit 642e52c

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 8e0c6fa5b693e90498045e582a5f66f6a78d67d0
2+
refs/heads/master: f3217a5c9c2e838cacaf68fe9d54230be7faca6c
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 2d28d645422c1617be58c8ca7ad9a457264ca850
55
refs/heads/try: c50a9d5b664478e533ba1d1d353213d70c8ad589

trunk/src/librustc/middle/ty.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2381,6 +2381,14 @@ pub fn type_is_signed(ty: t) -> bool {
23812381
}
23822382
}
23832383
2384+
pub fn type_is_machine(ty: t) -> bool {
2385+
match get(ty).sty {
2386+
ty_int(ast::ty_i) | ty_uint(ast::ty_u) | ty_float(ast::ty_f) => false,
2387+
ty_int(*) | ty_uint(*) | ty_float(*) => true,
2388+
_ => false
2389+
}
2390+
}
2391+
23842392
// Whether a type is Plain Old Data -- meaning it does not contain pointers
23852393
// that the cycle collector might care about.
23862394
pub fn type_is_pod(cx: ctxt, ty: t) -> bool {
@@ -3896,7 +3904,7 @@ pub fn has_attr(tcx: ctxt, did: def_id, attr: &str) -> bool {
38963904
attrs: ref attrs,
38973905
_
38983906
}, _)) => attr::attrs_contains_name(*attrs, attr),
3899-
_ => tcx.sess.bug(fmt!("lookup_packed: %? is not an item",
3907+
_ => tcx.sess.bug(fmt!("has_attr: %? is not an item",
39003908
did))
39013909
}
39023910
} else {
@@ -3908,11 +3916,16 @@ pub fn has_attr(tcx: ctxt, did: def_id, attr: &str) -> bool {
39083916
}
39093917
}
39103918
3911-
/// Determine whether an item is annotated with `#[packed]` or not
3919+
/// Determine whether an item is annotated with `#[packed]`
39123920
pub fn lookup_packed(tcx: ctxt, did: def_id) -> bool {
39133921
has_attr(tcx, did, "packed")
39143922
}
39153923
3924+
/// Determine whether an item is annotated with `#[simd]`
3925+
pub fn lookup_simd(tcx: ctxt, did: def_id) -> bool {
3926+
has_attr(tcx, did, "simd")
3927+
}
3928+
39163929
// Look up a field ID, whether or not it's local
39173930
// Takes a list of type substs in case the struct is generic
39183931
pub fn lookup_field_type(tcx: ctxt,

trunk/src/librustc/middle/typeck/check/mod.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,14 @@ pub fn check_no_duplicate_fields(tcx: ty::ctxt,
561561
}
562562

563563
pub fn check_struct(ccx: @mut CrateCtxt, id: ast::node_id, span: span) {
564+
let tcx = ccx.tcx;
565+
564566
// Check that the class is instantiable
565-
check_instantiable(ccx.tcx, span, id);
567+
check_instantiable(tcx, span, id);
568+
569+
if ty::lookup_simd(tcx, local_def(id)) {
570+
check_simd(tcx, span, id);
571+
}
566572
}
567573

568574
pub fn check_item(ccx: @mut CrateCtxt, it: @ast::item) {
@@ -3047,6 +3053,35 @@ pub fn check_instantiable(tcx: ty::ctxt,
30473053
}
30483054
}
30493055

3056+
pub fn check_simd(tcx: ty::ctxt, sp: span, id: ast::node_id) {
3057+
let t = ty::node_id_to_type(tcx, id);
3058+
if ty::type_needs_subst(t) {
3059+
tcx.sess.span_err(sp, "SIMD vector cannot be generic");
3060+
return;
3061+
}
3062+
match ty::get(t).sty {
3063+
ty::ty_struct(did, ref substs) => {
3064+
let fields = ty::lookup_struct_fields(tcx, did);
3065+
if fields.is_empty() {
3066+
tcx.sess.span_err(sp, "SIMD vector cannot be empty");
3067+
return;
3068+
}
3069+
let e = ty::lookup_field_type(tcx, did, fields[0].id, substs);
3070+
if !vec::all(fields,
3071+
|f| ty::lookup_field_type(tcx, did, f.id, substs) == e) {
3072+
tcx.sess.span_err(sp, "SIMD vector should be homogeneous");
3073+
return;
3074+
}
3075+
if !ty::type_is_machine(e) {
3076+
tcx.sess.span_err(sp, "SIMD vector element type should be \
3077+
machine type");
3078+
return;
3079+
}
3080+
}
3081+
_ => ()
3082+
}
3083+
}
3084+
30503085
pub fn check_enum_variants(ccx: @mut CrateCtxt,
30513086
sp: span,
30523087
vs: &[ast::variant],

0 commit comments

Comments
 (0)