Skip to content

Commit 1fb1e26

Browse files
committed
---
yaml --- r: 233463 b: refs/heads/beta c: 5889127 h: refs/heads/master i: 233461: 0b3fd11 233459: cc1ad3e 233455: f6ce0c7 v: v3
1 parent 60f3c00 commit 1fb1e26

File tree

5 files changed

+111
-13
lines changed

5 files changed

+111
-13
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2323
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
2424
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
26-
refs/heads/beta: cb1eb9d0c41739fc6abf4361c263013004463072
26+
refs/heads/beta: 58891278a322f5e09ea0b9da762e37b57fc39d1f
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
2828
refs/heads/tmp: 370fe2786109360f7c35b8ba552b83b773dd71d6
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/beta/mk/crates.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ DEPS_rustc_driver := arena flate getopts graphviz libc rustc rustc_back rustc_bo
7575

7676
DEPS_rustc_trans := arena flate getopts graphviz libc rustc rustc_back \
7777
log syntax serialize rustc_llvm rustc_platform_intrinsics
78-
DEPS_rustc_typeck := rustc syntax
78+
DEPS_rustc_typeck := rustc syntax rustc_platform_intrinsics
7979
DEPS_rustc_borrowck := rustc log graphviz syntax
8080
DEPS_rustc_resolve := rustc log syntax
8181
DEPS_rustc_privacy := rustc log syntax

branches/beta/src/librustc_platform_intrinsics/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub struct Intrinsic {
2828
pub definition: IntrinsicDef,
2929
}
3030

31-
#[derive(Clone)]
31+
#[derive(Clone, Hash, Eq, PartialEq)]
3232
pub enum Type {
3333
Integer(u8),
3434
Float(u8),

branches/beta/src/librustc_typeck/check/mod.rs

Lines changed: 107 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ use self::TupleArgumentsFlag::*;
8484
use astconv::{self, ast_region_to_region, ast_ty_to_ty, AstConv, PathParamMode};
8585
use check::_match::pat_ctxt;
8686
use fmt_macros::{Parser, Piece, Position};
87+
use intrinsics;
8788
use middle::astconv_util::{check_path_args, NO_TPS, NO_REGIONS};
8889
use middle::def;
8990
use middle::infer;
@@ -109,7 +110,7 @@ use util::nodemap::{DefIdMap, FnvHashMap, NodeMap};
109110
use util::lev_distance::lev_distance;
110111

111112
use std::cell::{Cell, Ref, RefCell};
112-
use std::collections::HashSet;
113+
use std::collections::{HashSet, HashMap};
113114
use std::iter;
114115
use std::mem::replace;
115116
use std::slice;
@@ -5386,16 +5387,18 @@ pub fn check_intrinsic_type(ccx: &CrateCtxt, it: &ast::ForeignItem) {
53865387
(0, vec![tcx.mk_fn(None, fn_ty), mut_u8], mut_u8)
53875388
}
53885389

5389-
name if name.starts_with("x86_") ||
5390-
name.starts_with("arm_") ||
5391-
name.starts_with("aarch64_") => {
5392-
// FIXME: skip checking these for now
5393-
return
5394-
}
53955390
ref other => {
5396-
span_err!(tcx.sess, it.span, E0093,
5397-
"unrecognized intrinsic function: `{}`", *other);
5398-
return;
5391+
match intrinsics::Intrinsic::find(tcx, other) {
5392+
Some(intr) => {
5393+
check_platform_intrinsic_type(ccx, intr, it);
5394+
return
5395+
}
5396+
None => {
5397+
span_err!(tcx.sess, it.span, E0093,
5398+
"unrecognized intrinsic function: `{}`", *other);
5399+
return;
5400+
}
5401+
}
53995402
}
54005403
};
54015404
(n_tps, inputs, ty::FnConverging(output))
@@ -5429,3 +5432,97 @@ pub fn check_intrinsic_type(ccx: &CrateCtxt, it: &ast::ForeignItem) {
54295432
});
54305433
}
54315434
}
5435+
5436+
fn check_platform_intrinsic_type(ccx: &CrateCtxt,
5437+
expected: intrinsics::Intrinsic, it: &ast::ForeignItem) {
5438+
let tcx = ccx.tcx;
5439+
let i_ty = tcx.lookup_item_type(local_def(it.id));
5440+
let i_n_tps = i_ty.generics.types.len(subst::FnSpace);
5441+
if i_n_tps != 0 {
5442+
tcx.sess.span_err(it.span,
5443+
&format!("intrinsic has wrong number of type parameters: \
5444+
found {}, expected 0",
5445+
i_n_tps));
5446+
return
5447+
}
5448+
5449+
let mut structural_to_nomimal = HashMap::new();
5450+
5451+
let sig = tcx.no_late_bound_regions(i_ty.ty.fn_sig()).unwrap();
5452+
for (i, (expected_arg, arg)) in expected.inputs.iter().zip(&sig.inputs).enumerate() {
5453+
match_types(tcx, &format!("argument {}", i + 1), it.span,
5454+
&mut structural_to_nomimal, expected_arg, arg);
5455+
}
5456+
match_types(tcx, "return value", it.span, &mut structural_to_nomimal,
5457+
&expected.output, sig.output.unwrap());
5458+
5459+
// walk the expected type and the actual type in lock step, checking they're
5460+
// the same, in a kinda-structural way, i.e. `Vector`s have to be simd structs with
5461+
// exactly the right element type
5462+
fn match_types<'tcx, 'a>(tcx: &ty::ctxt<'tcx>,
5463+
position: &str,
5464+
span: Span,
5465+
structural_to_nominal: &mut HashMap<&'a intrinsics::Type,
5466+
ty::Ty<'tcx>>,
5467+
expected: &'a intrinsics::Type, t: ty::Ty<'tcx>) {
5468+
use intrinsics::Type::*;
5469+
match *expected {
5470+
Integer(bits) => match (bits, &t.sty) {
5471+
(8, &ty::TyInt(ast::TyI8)) | (8, &ty::TyUint(ast::TyU8)) |
5472+
(16, &ty::TyInt(ast::TyI16)) | (16, &ty::TyUint(ast::TyU16)) |
5473+
(32, &ty::TyInt(ast::TyI32)) | (32, &ty::TyUint(ast::TyU32)) |
5474+
(64, &ty::TyInt(ast::TyI64)) | (64, &ty::TyUint(ast::TyU64)) => {},
5475+
_ => tcx.sess.span_err(span,
5476+
&format!("intrinsic {} has wrong type: found `{}`, \
5477+
expected `i{n}` or `u{n}`",
5478+
position,
5479+
t, n = bits)),
5480+
},
5481+
Float(bits) => match (bits, &t.sty) {
5482+
(32, &ty::TyFloat(ast::TyF32)) |
5483+
(64, &ty::TyFloat(ast::TyF64)) => {},
5484+
_ => tcx.sess.span_err(span,
5485+
&format!("intrinsic {} has wrong type: found `{}`, \
5486+
expected `f{n}`",
5487+
position,
5488+
t, n = bits)),
5489+
},
5490+
Pointer(_) => unimplemented!(),
5491+
Vector(ref inner_expected, len) => {
5492+
if t.is_simd(tcx) {
5493+
let t_len = t.simd_size(tcx);
5494+
if len as usize != t_len {
5495+
tcx.sess.span_err(span,
5496+
&format!("intrinsic {} has wrong type: found \
5497+
vector with length {}, expected length {}",
5498+
position,
5499+
t_len, len));
5500+
return;
5501+
}
5502+
let t_ty = t.simd_type(tcx);
5503+
{
5504+
let previous = structural_to_nominal.entry(expected).or_insert(t);
5505+
if *previous != t {
5506+
tcx.sess.span_err(span,
5507+
&format!("intrinsic {} has wrong type: found `{}`, \
5508+
but already seen this vector type as `{}`",
5509+
position, t, previous));
5510+
return;
5511+
}
5512+
}
5513+
match_types(tcx,
5514+
position,
5515+
span,
5516+
structural_to_nominal,
5517+
inner_expected,
5518+
t_ty)
5519+
} else {
5520+
tcx.sess.span_err(span,
5521+
&format!("intrinsic {} has wrong type: found non-simd type {}, \
5522+
expected simd type",
5523+
position, t));
5524+
}
5525+
}
5526+
}
5527+
}
5528+
}

branches/beta/src/librustc_typeck/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ This API is completely unstable and subject to change.
9696
extern crate arena;
9797
extern crate fmt_macros;
9898
extern crate rustc;
99+
extern crate rustc_platform_intrinsics as intrinsics;
99100

100101
pub use rustc::lint;
101102
pub use rustc::metadata;

0 commit comments

Comments
 (0)