Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
07890c5c
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,发现更多精彩内容 >>
提交
07890c5c
编写于
2月 27, 2018
作者:
W
Wesley Wiser
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add target_features to TransFnAttrs
Part of #47320
上级
39f9d23b
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
101 addition
and
101 deletion
+101
-101
src/librustc/dep_graph/dep_node.rs
src/librustc/dep_graph/dep_node.rs
+0
-1
src/librustc/hir/check_attr.rs
src/librustc/hir/check_attr.rs
+1
-1
src/librustc/hir/mod.rs
src/librustc/hir/mod.rs
+2
-0
src/librustc/ich/impls_hir.rs
src/librustc/ich/impls_hir.rs
+2
-0
src/librustc/ty/maps/mod.rs
src/librustc/ty/maps/mod.rs
+0
-1
src/librustc/ty/maps/plumbing.rs
src/librustc/ty/maps/plumbing.rs
+0
-1
src/librustc_trans/attributes.rs
src/librustc_trans/attributes.rs
+12
-93
src/librustc_trans_utils/trans_crate.rs
src/librustc_trans_utils/trans_crate.rs
+4
-2
src/librustc_typeck/collect.rs
src/librustc_typeck/collect.rs
+80
-2
未找到文件。
src/librustc/dep_graph/dep_node.rs
浏览文件 @
07890c5c
...
...
@@ -636,7 +636,6 @@ pub fn fingerprint_needed_for_crate_hash(self) -> bool {
[]
SubstituteNormalizeAndTestPredicates
{
key
:
(
DefId
,
&
'tcx
Substs
<
'tcx
>
)
},
[
input
]
TargetFeaturesWhitelist
,
[]
TargetFeaturesEnabled
(
DefId
),
[]
InstanceDefSizeEstimate
{
instance_def
:
InstanceDef
<
'tcx
>
},
...
...
src/librustc/hir/check_attr.rs
浏览文件 @
07890c5c
...
...
@@ -47,7 +47,7 @@ struct CheckAttrVisitor<'a, 'tcx: 'a> {
impl
<
'a
,
'tcx
>
CheckAttrVisitor
<
'a
,
'tcx
>
{
/// Check any attribute.
fn
check_attributes
(
&
self
,
item
:
&
hir
::
Item
,
target
:
Target
)
{
self
.tcx
.t
arget_features_enabled
(
self
.tcx.hir
.local_def_id
(
item
.id
));
self
.tcx
.t
rans_fn_attrs
(
self
.tcx.hir
.local_def_id
(
item
.id
));
for
attr
in
&
item
.attrs
{
if
let
Some
(
name
)
=
attr
.name
()
{
...
...
src/librustc/hir/mod.rs
浏览文件 @
07890c5c
...
...
@@ -2217,6 +2217,7 @@ pub struct TransFnAttrs {
pub
flags
:
TransFnAttrFlags
,
pub
inline
:
InlineAttr
,
pub
export_name
:
Option
<
Symbol
>
,
pub
target_features
:
Vec
<
Symbol
>
,
}
bitflags!
{
...
...
@@ -2238,6 +2239,7 @@ pub fn new() -> TransFnAttrs {
flags
:
TransFnAttrFlags
::
empty
(),
inline
:
InlineAttr
::
None
,
export_name
:
None
,
target_features
:
vec!
[],
}
}
...
...
src/librustc/ich/impls_hir.rs
浏览文件 @
07890c5c
...
...
@@ -1148,11 +1148,13 @@ fn hash_stable<W: StableHasherResult>(&self,
flags
,
inline
,
export_name
,
ref
target_features
,
}
=
*
self
;
flags
.hash_stable
(
hcx
,
hasher
);
inline
.hash_stable
(
hcx
,
hasher
);
export_name
.hash_stable
(
hcx
,
hasher
);
target_features
.hash_stable
(
hcx
,
hasher
);
}
}
...
...
src/librustc/ty/maps/mod.rs
浏览文件 @
07890c5c
...
...
@@ -384,7 +384,6 @@
[]
fn
target_features_whitelist
:
target_features_whitelist_node
(
CrateNum
)
->
Lrc
<
FxHashSet
<
String
>>
,
[]
fn
target_features_enabled
:
TargetFeaturesEnabled
(
DefId
)
->
Lrc
<
Vec
<
String
>>
,
// Get an estimate of the size of an InstanceDef based on its MIR for CGU partitioning.
[]
fn
instance_def_size_estimate
:
instance_def_size_estimate_dep_node
(
ty
::
InstanceDef
<
'tcx
>
)
...
...
src/librustc/ty/maps/plumbing.rs
浏览文件 @
07890c5c
...
...
@@ -930,7 +930,6 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
DepKind
::
OutputFilenames
=>
{
force!
(
output_filenames
,
LOCAL_CRATE
);
}
DepKind
::
TargetFeaturesWhitelist
=>
{
force!
(
target_features_whitelist
,
LOCAL_CRATE
);
}
DepKind
::
TargetFeaturesEnabled
=>
{
force!
(
target_features_enabled
,
def_id!
());
}
DepKind
::
GetSymbolExportLevel
=>
{
force!
(
symbol_export_level
,
def_id!
());
}
DepKind
::
Features
=>
{
force!
(
features_query
,
LOCAL_CRATE
);
}
...
...
src/librustc_trans/attributes.rs
浏览文件 @
07890c5c
...
...
@@ -12,19 +12,15 @@
use
std
::
ffi
::{
CStr
,
CString
};
use
rustc
::
hir
::
TransFnAttrFlags
;
use
rustc
::
hir
::
Unsafety
;
use
rustc
::
hir
::
def_id
::{
DefId
,
LOCAL_CRATE
};
use
rustc
::
session
::
config
::
Sanitizer
;
use
rustc
::
ty
::
TyCtxt
;
use
rustc
::
ty
::
maps
::
Providers
;
use
rustc_data_structures
::
fx
::
FxHashSet
;
use
rustc_data_structures
::
sync
::
Lrc
;
use
llvm
::{
self
,
Attribute
,
ValueRef
};
use
llvm
::
AttributePlace
::
Function
;
use
llvm_util
;
pub
use
syntax
::
attr
::{
self
,
InlineAttr
};
use
syntax
::
ast
;
use
context
::
CodegenCx
;
/// Mark LLVM function to use provided inline heuristic.
...
...
@@ -127,10 +123,18 @@ pub fn from_fn_attrs(cx: &CodegenCx, llfn: ValueRef, id: DefId) {
unwind
(
llfn
,
false
);
}
let
target_features
=
cx
.tcx
.target_features_enabled
(
id
);
if
!
target_features
.is_empty
()
{
let
val
=
CString
::
new
(
target_features
.join
(
","
))
.unwrap
();
let
features
=
trans_fn_attrs
.target_features
.iter
()
.map
(|
f
|
{
let
feature
=
&*
f
.as_str
();
format!
(
"+{}"
,
llvm_util
::
to_llvm_feature
(
cx
.tcx.sess
,
feature
))
})
.collect
::
<
Vec
<
String
>>
()
.join
(
","
);
if
!
features
.is_empty
()
{
let
val
=
CString
::
new
(
features
)
.unwrap
();
llvm
::
AddFunctionAttrStringValue
(
llfn
,
llvm
::
AttributePlace
::
Function
,
cstr
(
"target-features
\0
"
),
&
val
);
...
...
@@ -149,89 +153,4 @@ pub fn provide(providers: &mut Providers) {
.map
(|
c
|
c
.to_string
())
.collect
())
};
providers
.target_features_enabled
=
|
tcx
,
id
|
{
let
whitelist
=
tcx
.target_features_whitelist
(
LOCAL_CRATE
);
let
mut
target_features
=
Vec
::
new
();
for
attr
in
tcx
.get_attrs
(
id
)
.iter
()
{
if
!
attr
.check_name
(
"target_feature"
)
{
continue
}
if
let
Some
(
val
)
=
attr
.value_str
()
{
for
feat
in
val
.as_str
()
.split
(
","
)
.map
(|
f
|
f
.trim
())
{
if
!
feat
.is_empty
()
&&
!
feat
.contains
(
'\0'
)
{
target_features
.push
(
feat
.to_string
());
}
}
let
msg
=
"#[target_feature =
\"
..
\"
] is deprecated and will
\
eventually be removed, use
\
#[target_feature(enable =
\"
..
\"
)] instead"
;
tcx
.sess
.span_warn
(
attr
.span
,
&
msg
);
continue
}
if
tcx
.fn_sig
(
id
)
.unsafety
()
==
Unsafety
::
Normal
{
let
msg
=
"#[target_feature(..)] can only be applied to
\
`unsafe` function"
;
tcx
.sess
.span_err
(
attr
.span
,
msg
);
}
from_target_feature
(
tcx
,
attr
,
&
whitelist
,
&
mut
target_features
);
}
Lrc
::
new
(
target_features
)
};
}
fn
from_target_feature
(
tcx
:
TyCtxt
,
attr
:
&
ast
::
Attribute
,
whitelist
:
&
FxHashSet
<
String
>
,
target_features
:
&
mut
Vec
<
String
>
,
)
{
let
list
=
match
attr
.meta_item_list
()
{
Some
(
list
)
=>
list
,
None
=>
{
let
msg
=
"#[target_feature] attribute must be of the form
\
#[target_feature(..)]"
;
tcx
.sess
.span_err
(
attr
.span
,
&
msg
);
return
}
};
for
item
in
list
{
if
!
item
.check_name
(
"enable"
)
{
let
msg
=
"#[target_feature(..)] only accepts sub-keys of `enable`
\
currently"
;
tcx
.sess
.span_err
(
item
.span
,
&
msg
);
continue
}
let
value
=
match
item
.value_str
()
{
Some
(
list
)
=>
list
,
None
=>
{
let
msg
=
"#[target_feature] attribute must be of the form
\
#[target_feature(enable =
\"
..
\"
)]"
;
tcx
.sess
.span_err
(
item
.span
,
&
msg
);
continue
}
};
let
value
=
value
.as_str
();
for
feature
in
value
.split
(
','
)
{
if
whitelist
.contains
(
feature
)
{
let
llvm_feature
=
llvm_util
::
to_llvm_feature
(
&
tcx
.sess
,
feature
);
target_features
.push
(
format!
(
"+{}"
,
llvm_feature
));
continue
}
let
msg
=
format!
(
"the feature named `{}` is not valid for
\
this target"
,
feature
);
let
mut
err
=
tcx
.sess
.struct_span_err
(
item
.span
,
&
msg
);
if
feature
.starts_with
(
"+"
)
{
let
valid
=
whitelist
.contains
(
&
feature
[
1
..
]);
if
valid
{
err
.help
(
"consider removing the leading `+` in the feature name"
);
}
}
err
.emit
();
}
}
}
src/librustc_trans_utils/trans_crate.rs
浏览文件 @
07890c5c
...
...
@@ -44,6 +44,7 @@
use
rustc
::
middle
::
cstore
::
MetadataLoader
;
use
rustc
::
dep_graph
::
DepGraph
;
use
rustc_back
::
target
::
Target
;
use
rustc_data_structures
::
fx
::
FxHashSet
;
use
rustc_mir
::
monomorphize
::
collector
;
use
link
::{
build_link_meta
,
out_filename
};
...
...
@@ -198,8 +199,9 @@ fn metadata_loader(&self) -> Box<MetadataLoader> {
fn
provide
(
&
self
,
providers
:
&
mut
Providers
)
{
::
symbol_names
::
provide
(
providers
);
providers
.target_features_enabled
=
|
_
tcx
,
_
id
|
{
Lrc
::
new
(
Vec
::
new
())
// Just a dummy
providers
.target_features_whitelist
=
|
_
tcx
,
_
cnum
|
{
Lrc
::
new
(
FxHashSet
())
// Just a dummy
};
}
fn
provide_extern
(
&
self
,
_
providers
:
&
mut
Providers
)
{}
...
...
src/librustc_typeck/collect.rs
浏览文件 @
07890c5c
...
...
@@ -36,6 +36,7 @@
use
rustc
::
ty
::{
self
,
AdtKind
,
ToPolyTraitRef
,
Ty
,
TyCtxt
};
use
rustc
::
ty
::
maps
::
Providers
;
use
rustc
::
ty
::
util
::
IntTypeExt
;
use
rustc
::
util
::
nodemap
::
FxHashSet
;
use
util
::
nodemap
::
FxHashMap
;
use
rustc_const_math
::
ConstInt
;
...
...
@@ -47,10 +48,10 @@
use
syntax
::
symbol
::{
Symbol
,
keywords
};
use
syntax_pos
::{
Span
,
DUMMY_SP
};
use
rustc
::
hir
::{
self
,
map
as
hir_map
,
TransFnAttrs
,
TransFnAttrFlags
};
use
rustc
::
hir
::{
self
,
map
as
hir_map
,
TransFnAttrs
,
TransFnAttrFlags
,
Unsafety
};
use
rustc
::
hir
::
intravisit
::{
self
,
Visitor
,
NestedVisitorMap
};
use
rustc
::
hir
::
def
::{
Def
,
CtorKind
};
use
rustc
::
hir
::
def_id
::
DefId
;
use
rustc
::
hir
::
def_id
::
{
DefId
,
LOCAL_CRATE
}
;
///////////////////////////////////////////////////////////////////////////
// Main entry point
...
...
@@ -1727,11 +1728,68 @@ fn is_foreign_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
}
}
fn
from_target_feature
(
tcx
:
TyCtxt
,
attr
:
&
ast
::
Attribute
,
whitelist
:
&
FxHashSet
<
String
>
,
target_features
:
&
mut
Vec
<
Symbol
>
,
)
{
let
list
=
match
attr
.meta_item_list
()
{
Some
(
list
)
=>
list
,
None
=>
{
let
msg
=
"#[target_feature] attribute must be of the form
\
#[target_feature(..)]"
;
tcx
.sess
.span_err
(
attr
.span
,
&
msg
);
return
}
};
for
item
in
list
{
if
!
item
.check_name
(
"enable"
)
{
let
msg
=
"#[target_feature(..)] only accepts sub-keys of `enable`
\
currently"
;
tcx
.sess
.span_err
(
item
.span
,
&
msg
);
continue
}
let
value
=
match
item
.value_str
()
{
Some
(
list
)
=>
list
,
None
=>
{
let
msg
=
"#[target_feature] attribute must be of the form
\
#[target_feature(enable =
\"
..
\"
)]"
;
tcx
.sess
.span_err
(
item
.span
,
&
msg
);
continue
}
};
let
value
=
value
.as_str
();
for
feature
in
value
.split
(
','
)
{
if
whitelist
.contains
(
feature
)
{
target_features
.push
(
Symbol
::
intern
(
feature
));
continue
}
let
msg
=
format!
(
"the feature named `{}` is not valid for
\
this target"
,
feature
);
let
mut
err
=
tcx
.sess
.struct_span_err
(
item
.span
,
&
msg
);
if
feature
.starts_with
(
"+"
)
{
let
valid
=
whitelist
.contains
(
&
feature
[
1
..
]);
if
valid
{
err
.help
(
"consider removing the leading `+` in the feature name"
);
}
}
err
.emit
();
}
}
}
fn
trans_fn_attrs
<
'a
,
'tcx
>
(
tcx
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
,
id
:
DefId
)
->
TransFnAttrs
{
let
attrs
=
tcx
.get_attrs
(
id
);
let
mut
trans_fn_attrs
=
TransFnAttrs
::
new
();
let
whitelist
=
tcx
.target_features_whitelist
(
LOCAL_CRATE
);
for
attr
in
attrs
.iter
()
{
if
attr
.check_name
(
"cold"
)
{
trans_fn_attrs
.flags
|
=
TransFnAttrFlags
::
COLD
;
...
...
@@ -1790,6 +1848,26 @@ fn trans_fn_attrs<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: DefId) -> TransFnAt
.span_label
(
attr
.span
,
"did you mean #[export_name=
\"
*
\"
]?"
)
.emit
();
}
}
else
if
attr
.check_name
(
"target_feature"
)
{
if
let
Some
(
val
)
=
attr
.value_str
()
{
for
feat
in
val
.as_str
()
.split
(
","
)
.map
(|
f
|
f
.trim
())
{
if
!
feat
.is_empty
()
&&
!
feat
.contains
(
'\0'
)
{
trans_fn_attrs
.target_features
.push
(
Symbol
::
intern
(
feat
));
}
}
let
msg
=
"#[target_feature =
\"
..
\"
] is deprecated and will
\
eventually be removed, use
\
#[target_feature(enable =
\"
..
\"
)] instead"
;
tcx
.sess
.span_warn
(
attr
.span
,
&
msg
);
continue
}
if
tcx
.fn_sig
(
id
)
.unsafety
()
==
Unsafety
::
Normal
{
let
msg
=
"#[target_feature(..)] can only be applied to
\
`unsafe` function"
;
tcx
.sess
.span_err
(
attr
.span
,
msg
);
}
from_target_feature
(
tcx
,
attr
,
&
whitelist
,
&
mut
trans_fn_attrs
.target_features
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录