Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
01530010
R
Rust
项目概览
int
/
Rust
11 个月 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
01530010
编写于
8月 06, 2015
作者:
A
Ariel Ben-Yehuda
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cache Ty::is_simd
上级
612760be
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
45 addition
and
36 deletion
+45
-36
src/librustc/middle/ty.rs
src/librustc/middle/ty.rs
+19
-9
src/librustc_trans/trans/base.rs
src/librustc_trans/trans/base.rs
+1
-1
src/librustc_trans/trans/common.rs
src/librustc_trans/trans/common.rs
+1
-1
src/librustc_trans/trans/consts.rs
src/librustc_trans/trans/consts.rs
+3
-3
src/librustc_trans/trans/debuginfo/metadata.rs
src/librustc_trans/trans/debuginfo/metadata.rs
+1
-1
src/librustc_trans/trans/expr.rs
src/librustc_trans/trans/expr.rs
+3
-3
src/librustc_trans/trans/foreign.rs
src/librustc_trans/trans/foreign.rs
+1
-1
src/librustc_trans/trans/glue.rs
src/librustc_trans/trans/glue.rs
+1
-1
src/librustc_trans/trans/type_of.rs
src/librustc_trans/trans/type_of.rs
+3
-3
src/librustc_typeck/check/op.rs
src/librustc_typeck/check/op.rs
+12
-13
未找到文件。
src/librustc/middle/ty.rs
浏览文件 @
01530010
...
...
@@ -3179,11 +3179,12 @@ pub fn for_each_relevant_impl<F: FnMut(DefId)>(&self,
bitflags!
{
flags
ADTFlags
:
u32
{
const
NO_ADT_FLAGS
=
0
,
const
IS_FUNDAMENTAL
=
1
<<
0
,
const
IS_PHANTOM_DATA
=
1
<<
1
,
const
IS_DTORCK
=
1
<<
2
,
// is this a dtorck type?
const
IS_DTORCK_VALID
=
1
<<
3
,
const
IS_ENUM
=
1
<<
4
const
IS_ENUM
=
1
<<
0
,
const
IS_DTORCK
=
1
<<
1
,
// is this a dtorck type?
const
IS_DTORCK_VALID
=
1
<<
2
,
const
IS_PHANTOM_DATA
=
1
<<
3
,
const
IS_SIMD
=
1
<<
4
,
const
IS_FUNDAMENTAL
=
1
<<
5
,
}
}
...
...
@@ -3244,9 +3245,13 @@ fn new(tcx: &ctxt<'tcx>,
kind
:
ADTKind
,
variants
:
Vec
<
VariantDef_
<
'tcx
,
'lt
>>
)
->
Self
{
let
mut
flags
=
ADTFlags
::
NO_ADT_FLAGS
;
if
tcx
.has_attr
(
did
,
"fundamental"
)
{
let
attrs
=
tcx
.get_attrs
(
did
);
if
attrs
.iter
()
.any
(|
item
|
item
.check_name
(
"fundamental"
))
{
flags
=
flags
|
ADTFlags
::
IS_FUNDAMENTAL
;
}
if
attrs
.iter
()
.any
(|
item
|
item
.check_name
(
"simd"
))
{
flags
=
flags
|
ADTFlags
::
IS_SIMD
;
}
if
Some
(
did
)
==
tcx
.lang_items
.phantom_data
()
{
flags
=
flags
|
ADTFlags
::
IS_PHANTOM_DATA
;
}
...
...
@@ -3289,6 +3294,11 @@ pub fn is_fundamental(&self) -> bool {
self
.flags
.get
()
.intersects
(
ADTFlags
::
IS_FUNDAMENTAL
)
}
#[inline]
pub
fn
is_simd
(
&
self
)
->
bool
{
self
.flags
.get
()
.intersects
(
ADTFlags
::
IS_SIMD
)
}
#[inline]
pub
fn
is_phantom_data
(
&
self
)
->
bool
{
self
.flags
.get
()
.intersects
(
ADTFlags
::
IS_PHANTOM_DATA
)
...
...
@@ -4203,9 +4213,10 @@ pub fn is_structural(&self) -> bool {
}
}
pub
fn
is_simd
(
&
self
,
cx
:
&
ctxt
)
->
bool
{
#[inline]
pub
fn
is_simd
(
&
self
)
->
bool
{
match
self
.sty
{
TyStruct
(
def
,
_
)
=>
cx
.lookup_simd
(
def
.did
),
TyStruct
(
def
,
_
)
=>
def
.is_simd
(
),
_
=>
false
}
}
...
...
@@ -5979,7 +5990,6 @@ pub fn lookup_simd(&self, did: DefId) -> bool {
/// Obtain the representation annotation for a struct definition.
pub
fn
lookup_repr_hints
(
&
self
,
did
:
DefId
)
->
Rc
<
Vec
<
attr
::
ReprAttr
>>
{
// TODO: remove
memoized
(
&
self
.repr_hint_cache
,
did
,
|
did
:
DefId
|
{
Rc
::
new
(
if
did
.krate
==
LOCAL_CRATE
{
self
.get_attrs
(
did
)
.iter
()
.flat_map
(|
meta
|
{
...
...
src/librustc_trans/trans/base.rs
浏览文件 @
01530010
...
...
@@ -621,7 +621,7 @@ pub fn fail_if_zero_or_overflows<'blk, 'tcx>(
let
zero
=
C_integral
(
Type
::
uint_from_ty
(
cx
.ccx
(),
t
),
0
,
false
);
(
ICmp
(
cx
,
llvm
::
IntEQ
,
rhs
,
zero
,
debug_loc
),
false
)
}
ty
::
TyStruct
(
_
,
_
)
if
rhs_t
.is_simd
(
cx
.tcx
()
)
=>
{
ty
::
TyStruct
(
def
,
_
)
if
def
.is_simd
(
)
=>
{
let
mut
res
=
C_bool
(
cx
.ccx
(),
false
);
for
i
in
0
..
rhs_t
.simd_size
(
cx
.tcx
())
{
res
=
Or
(
cx
,
res
,
...
...
src/librustc_trans/trans/common.rs
浏览文件 @
01530010
...
...
@@ -192,7 +192,7 @@ pub fn type_is_immediate<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>) -
let
simple
=
ty
.is_scalar
()
||
ty
.is_unique
()
||
ty
.is_region_ptr
()
||
type_is_newtype_immediate
(
ccx
,
ty
)
||
ty
.is_simd
(
tcx
);
ty
.is_simd
();
if
simple
&&
!
type_is_fat_ptr
(
tcx
,
ty
)
{
return
true
;
}
...
...
src/librustc_trans/trans/consts.rs
浏览文件 @
01530010
...
...
@@ -500,7 +500,7 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
debug!
(
"const_expr_unadjusted: te1={}, ty={:?}"
,
cx
.tn
()
.val_to_string
(
te1
),
ty
);
let
is_simd
=
ty
.is_simd
(
cx
.tcx
()
);
let
is_simd
=
ty
.is_simd
();
let
intype
=
if
is_simd
{
ty
.simd_type
(
cx
.tcx
())
}
else
{
...
...
@@ -754,7 +754,7 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
(
_
,
None
)
=>
cx
.sess
()
.span_bug
(
e
.span
,
"missing struct field"
),
}
})
.collect
::
<
Vec
<
_
>>
();
if
ety
.is_simd
(
cx
.tcx
()
)
{
if
ety
.is_simd
()
{
C_vector
(
&
cs
[
..
])
}
else
{
adt
::
trans_const
(
cx
,
&*
repr
,
discr
,
&
cs
[
..
])
...
...
@@ -850,7 +850,7 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
const_fn_call
(
cx
,
ExprId
(
callee
.id
),
did
,
&
arg_vals
,
param_substs
)
}
def
::
DefStruct
(
_
)
=>
{
if
ety
.is_simd
(
cx
.tcx
()
)
{
if
ety
.is_simd
()
{
C_vector
(
&
arg_vals
[
..
])
}
else
{
let
repr
=
adt
::
represent_type
(
cx
,
ety
);
...
...
src/librustc_trans/trans/debuginfo/metadata.rs
浏览文件 @
01530010
...
...
@@ -1175,7 +1175,7 @@ fn prepare_struct_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
StructMDF
(
StructMemberDescriptionFactory
{
variant
:
variant
,
substs
:
substs
,
is_simd
:
struct_type
.is_simd
(
cx
.tcx
()
),
is_simd
:
struct_type
.is_simd
(),
span
:
span
,
})
)
...
...
src/librustc_trans/trans/expr.rs
浏览文件 @
01530010
...
...
@@ -1453,7 +1453,7 @@ pub fn trans_adt<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
// panic occur before the ADT as a whole is ready.
let
custom_cleanup_scope
=
fcx
.push_custom_cleanup_scope
();
if
ty
.is_simd
(
bcx
.tcx
()
)
{
if
ty
.is_simd
()
{
// Issue 23112: The original logic appeared vulnerable to same
// order-of-eval bug. But, SIMD values are tuple-structs;
// i.e. functional record update (FRU) syntax is unavailable.
...
...
@@ -1697,7 +1697,7 @@ fn trans_eager_binop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
let
_
icx
=
push_ctxt
(
"trans_eager_binop"
);
let
tcx
=
bcx
.tcx
();
let
is_simd
=
lhs_t
.is_simd
(
tcx
);
let
is_simd
=
lhs_t
.is_simd
();
let
intype
=
if
is_simd
{
lhs_t
.simd_type
(
tcx
)
}
else
{
...
...
@@ -2502,7 +2502,7 @@ fn build_unchecked_rshift<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
// #1877, #10183: Ensure that input is always valid
let
rhs
=
shift_mask_rhs
(
bcx
,
rhs
,
binop_debug_loc
);
let
tcx
=
bcx
.tcx
();
let
is_simd
=
lhs_t
.is_simd
(
tcx
);
let
is_simd
=
lhs_t
.is_simd
();
let
intype
=
if
is_simd
{
lhs_t
.simd_type
(
tcx
)
}
else
{
...
...
src/librustc_trans/trans/foreign.rs
浏览文件 @
01530010
...
...
@@ -449,7 +449,7 @@ pub fn trans_native_call<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
fn
gate_simd_ffi
(
tcx
:
&
ty
::
ctxt
,
decl
:
&
ast
::
FnDecl
,
ty
:
&
ty
::
BareFnTy
)
{
if
!
tcx
.sess.features
.borrow
()
.simd_ffi
{
let
check
=
|
ast_ty
:
&
ast
::
Ty
,
ty
:
ty
::
Ty
|
{
if
ty
.is_simd
(
tcx
)
{
if
ty
.is_simd
()
{
tcx
.sess
.span_err
(
ast_ty
.span
,
&
format!
(
"use of SIMD type `{}` in FFI is highly experimental and
\
may result in invalid code"
,
...
...
src/librustc_trans/trans/glue.rs
浏览文件 @
01530010
...
...
@@ -419,7 +419,7 @@ pub fn size_and_align_of_dst<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, t: Ty<'tcx>, in
let
ccx
=
bcx
.ccx
();
// First get the size of all statically known fields.
// Don't use type_of::sizing_type_of because that expects t to be sized.
assert
!
(
!
t
.is_simd
(
bcx
.tcx
()
));
assert
!
(
!
t
.is_simd
());
let
repr
=
adt
::
represent_type
(
ccx
,
t
);
let
sizing_type
=
adt
::
sizing_type_context_of
(
ccx
,
&*
repr
,
true
);
debug!
(
"DST {} sizing_type: {}"
,
t
,
sizing_type
.to_string
());
...
...
src/librustc_trans/trans/type_of.rs
浏览文件 @
01530010
...
...
@@ -222,7 +222,7 @@ pub fn sizing_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) -> Typ
}
ty
::
TyStruct
(
..
)
=>
{
if
t
.is_simd
(
cx
.tcx
()
)
{
if
t
.is_simd
()
{
let
llet
=
type_of
(
cx
,
t
.simd_type
(
cx
.tcx
()));
let
n
=
t
.simd_size
(
cx
.tcx
())
as
u64
;
ensure_array_fits_in_address_space
(
cx
,
llet
,
n
,
t
);
...
...
@@ -404,7 +404,7 @@ pub fn in_memory_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) ->
adt
::
type_of
(
cx
,
&*
repr
)
}
ty
::
TyStruct
(
def
,
ref
substs
)
=>
{
if
t
.is_simd
(
cx
.tcx
()
)
{
if
t
.is_simd
()
{
let
llet
=
in_memory_type_of
(
cx
,
t
.simd_type
(
cx
.tcx
()));
let
n
=
t
.simd_size
(
cx
.tcx
())
as
u64
;
ensure_array_fits_in_address_space
(
cx
,
llet
,
n
,
t
);
...
...
@@ -436,7 +436,7 @@ pub fn in_memory_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) ->
// If this was an enum or struct, fill in the type now.
match
t
.sty
{
ty
::
TyEnum
(
..
)
|
ty
::
TyStruct
(
..
)
|
ty
::
TyClosure
(
..
)
if
!
t
.is_simd
(
cx
.tcx
()
)
=>
{
if
!
t
.is_simd
()
=>
{
let
repr
=
adt
::
represent_type
(
cx
,
t
);
adt
::
finish_type_of
(
cx
,
&*
repr
,
&
mut
llty
);
}
...
...
src/librustc_typeck/check/op.rs
浏览文件 @
01530010
...
...
@@ -21,7 +21,7 @@
structurally_resolved_type
,
};
use
middle
::
traits
;
use
middle
::
ty
::{
self
,
Ty
,
HasTypeFlags
};
use
middle
::
ty
::{
Ty
,
HasTypeFlags
};
use
syntax
::
ast
;
use
syntax
::
ast_util
;
use
syntax
::
parse
::
token
;
...
...
@@ -41,7 +41,7 @@ pub fn check_binop_assign<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
let
lhs_ty
=
structurally_resolved_type
(
fcx
,
lhs_expr
.span
,
fcx
.expr_ty
(
lhs_expr
));
let
rhs_ty
=
structurally_resolved_type
(
fcx
,
rhs_expr
.span
,
fcx
.expr_ty
(
rhs_expr
));
if
is_builtin_binop
(
fcx
.tcx
(),
lhs_ty
,
rhs_ty
,
op
)
{
if
is_builtin_binop
(
lhs_ty
,
rhs_ty
,
op
)
{
enforce_builtin_binop_types
(
fcx
,
lhs_expr
,
lhs_ty
,
rhs_expr
,
rhs_ty
,
op
);
fcx
.write_nil
(
expr
.id
);
}
else
{
...
...
@@ -86,7 +86,7 @@ pub fn check_binop<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
// traits, because their return type is not bool. Perhaps this
// should change, but for now if LHS is SIMD we go down a
// different path that bypassess all traits.
if
lhs_ty
.is_simd
(
fcx
.tcx
()
)
{
if
lhs_ty
.is_simd
()
{
check_expr_coercable_to_type
(
fcx
,
rhs_expr
,
lhs_ty
);
let
rhs_ty
=
fcx
.resolve_type_vars_if_possible
(
fcx
.expr_ty
(
lhs_expr
));
let
return_ty
=
enforce_builtin_binop_types
(
fcx
,
lhs_expr
,
lhs_ty
,
rhs_expr
,
rhs_ty
,
op
);
...
...
@@ -123,7 +123,7 @@ pub fn check_binop<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
let
rhs_ty
=
fcx
.resolve_type_vars_if_possible
(
rhs_ty
);
if
!
lhs_ty
.is_ty_var
()
&&
!
rhs_ty
.is_ty_var
()
&&
is_builtin_binop
(
fcx
.tcx
(),
lhs_ty
,
rhs_ty
,
op
)
is_builtin_binop
(
lhs_ty
,
rhs_ty
,
op
)
{
let
builtin_return_ty
=
enforce_builtin_binop_types
(
fcx
,
lhs_expr
,
lhs_ty
,
rhs_expr
,
rhs_ty
,
op
);
...
...
@@ -143,7 +143,7 @@ fn enforce_builtin_binop_types<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
op
:
ast
::
BinOp
)
->
Ty
<
'tcx
>
{
debug_assert!
(
is_builtin_binop
(
fcx
.tcx
(),
lhs_ty
,
rhs_ty
,
op
));
debug_assert!
(
is_builtin_binop
(
lhs_ty
,
rhs_ty
,
op
));
let
tcx
=
fcx
.tcx
();
match
BinOpCategory
::
from
(
op
)
{
...
...
@@ -156,7 +156,7 @@ fn enforce_builtin_binop_types<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
BinOpCategory
::
Shift
=>
{
// For integers, the shift amount can be of any integral
// type. For simd, the type must match exactly.
if
lhs_ty
.is_simd
(
tcx
)
{
if
lhs_ty
.is_simd
()
{
demand
::
suptype
(
fcx
,
rhs_expr
.span
,
lhs_ty
,
rhs_ty
);
}
...
...
@@ -176,7 +176,7 @@ fn enforce_builtin_binop_types<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
demand
::
suptype
(
fcx
,
rhs_expr
.span
,
lhs_ty
,
rhs_ty
);
// if this is simd, result is same as lhs, else bool
if
lhs_ty
.is_simd
(
tcx
)
{
if
lhs_ty
.is_simd
()
{
let
unit_ty
=
lhs_ty
.simd_type
(
tcx
);
debug!
(
"enforce_builtin_binop_types: lhs_ty={:?} unit_ty={:?}"
,
lhs_ty
,
...
...
@@ -415,8 +415,7 @@ fn from(op: ast::BinOp) -> BinOpCategory {
/// Reason #2 is the killer. I tried for a while to always use
/// overloaded logic and just check the types in constants/trans after
/// the fact, and it worked fine, except for SIMD types. -nmatsakis
fn
is_builtin_binop
<
'tcx
>
(
cx
:
&
ty
::
ctxt
<
'tcx
>
,
lhs
:
Ty
<
'tcx
>
,
fn
is_builtin_binop
<
'tcx
>
(
lhs
:
Ty
<
'tcx
>
,
rhs
:
Ty
<
'tcx
>
,
op
:
ast
::
BinOp
)
->
bool
...
...
@@ -429,28 +428,28 @@ fn is_builtin_binop<'tcx>(cx: &ty::ctxt<'tcx>,
BinOpCategory
::
Shift
=>
{
lhs
.references_error
()
||
rhs
.references_error
()
||
lhs
.is_integral
()
&&
rhs
.is_integral
()
||
lhs
.is_simd
(
cx
)
&&
rhs
.is_simd
(
cx
)
lhs
.is_simd
(
)
&&
rhs
.is_simd
(
)
}
BinOpCategory
::
Math
=>
{
lhs
.references_error
()
||
rhs
.references_error
()
||
lhs
.is_integral
()
&&
rhs
.is_integral
()
||
lhs
.is_floating_point
()
&&
rhs
.is_floating_point
()
||
lhs
.is_simd
(
cx
)
&&
rhs
.is_simd
(
cx
)
lhs
.is_simd
(
)
&&
rhs
.is_simd
(
)
}
BinOpCategory
::
Bitwise
=>
{
lhs
.references_error
()
||
rhs
.references_error
()
||
lhs
.is_integral
()
&&
rhs
.is_integral
()
||
lhs
.is_floating_point
()
&&
rhs
.is_floating_point
()
||
lhs
.is_simd
(
cx
)
&&
rhs
.is_simd
(
cx
)
||
lhs
.is_simd
(
)
&&
rhs
.is_simd
(
)
||
lhs
.is_bool
()
&&
rhs
.is_bool
()
}
BinOpCategory
::
Comparison
=>
{
lhs
.references_error
()
||
rhs
.references_error
()
||
lhs
.is_scalar
()
&&
rhs
.is_scalar
()
||
lhs
.is_simd
(
cx
)
&&
rhs
.is_simd
(
cx
)
lhs
.is_simd
(
)
&&
rhs
.is_simd
(
)
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录