Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
27adb31f
R
Rust
项目概览
int
/
Rust
接近 1 年 前同步成功
通知
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,发现更多精彩内容 >>
提交
27adb31f
编写于
4月 01, 2018
作者:
J
John Kåre Alsaker
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Combine Session.entry_fn and Session.entry_type and make them thread-safe
上级
7aa7198b
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
31 addition
and
38 deletion
+31
-38
src/librustc/middle/dead.rs
src/librustc/middle/dead.rs
+1
-1
src/librustc/middle/entry.rs
src/librustc/middle/entry.rs
+9
-10
src/librustc/session/config.rs
src/librustc/session/config.rs
+1
-3
src/librustc/session/mod.rs
src/librustc/session/mod.rs
+2
-4
src/librustc_mir/monomorphize/collector.rs
src/librustc_mir/monomorphize/collector.rs
+2
-2
src/librustc_mir/monomorphize/item.rs
src/librustc_mir/monomorphize/item.rs
+1
-1
src/librustc_trans/base.rs
src/librustc_trans/base.rs
+5
-5
src/librustc_trans/debuginfo/mod.rs
src/librustc_trans/debuginfo/mod.rs
+1
-1
src/librustc_trans_utils/lib.rs
src/librustc_trans_utils/lib.rs
+1
-1
src/librustc_typeck/check/mod.rs
src/librustc_typeck/check/mod.rs
+4
-4
src/librustc_typeck/lib.rs
src/librustc_typeck/lib.rs
+4
-6
未找到文件。
src/librustc/middle/dead.rs
浏览文件 @
27adb31f
...
...
@@ -408,7 +408,7 @@ fn create_and_seed_worklist<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
}
// Seed entry point
if
let
Some
((
id
,
_
))
=
*
tcx
.sess.entry_fn
.borrow
()
{
if
let
Some
((
id
,
_
,
_
))
=
*
tcx
.sess.entry_fn
.borrow
()
{
worklist
.push
(
id
);
}
...
...
src/librustc/middle/entry.rs
浏览文件 @
27adb31f
...
...
@@ -63,12 +63,13 @@ pub fn find_entry_point(session: &Session,
});
if
!
any_exe
{
// No need to find a main function
session
.entry_fn
.set
(
None
);
return
}
// If the user wants no main function at all, then stop here.
if
attr
::
contains_name
(
&
hir_map
.krate
()
.attrs
,
"no_main"
)
{
session
.entry_
type
.set
(
Some
(
config
::
EntryNone
)
);
session
.entry_
fn
.set
(
None
);
return
}
...
...
@@ -153,17 +154,15 @@ fn find_item(item: &Item, ctxt: &mut EntryContext, at_root: bool) {
}
fn
configure_main
(
this
:
&
mut
EntryContext
,
crate_name
:
&
str
)
{
if
this
.start_fn
.is_some
()
{
*
this
.session.entry_fn
.borrow_mut
()
=
this
.start_fn
;
this
.session.entry_type
.set
(
Some
(
config
::
EntryStart
));
}
else
if
this
.attr_main_fn
.is_some
()
{
*
this
.session.entry_fn
.borrow_mut
()
=
this
.attr_main_fn
;
this
.session.entry_type
.set
(
Some
(
config
::
EntryMain
));
}
else
if
this
.main_fn
.is_some
()
{
*
this
.session.entry_fn
.borrow_mut
()
=
this
.main_fn
;
this
.session.entry_type
.set
(
Some
(
config
::
EntryMain
));
if
let
Some
((
node_id
,
span
))
=
this
.start_fn
{
this
.session.entry_fn
.set
(
Some
((
node_id
,
span
,
config
::
EntryStart
)));
}
else
if
let
Some
((
node_id
,
span
))
=
this
.attr_main_fn
{
this
.session.entry_fn
.set
(
Some
((
node_id
,
span
,
config
::
EntryMain
)));
}
else
if
let
Some
((
node_id
,
span
))
=
this
.main_fn
{
this
.session.entry_fn
.set
(
Some
((
node_id
,
span
,
config
::
EntryMain
)));
}
else
{
// No main function
this
.session.entry_fn
.set
(
None
);
let
mut
err
=
struct_err!
(
this
.session
,
E0601
,
"`main` function not found in crate `{}`"
,
crate_name
);
if
!
this
.non_main_fns
.is_empty
()
{
...
...
src/librustc/session/config.rs
浏览文件 @
27adb31f
...
...
@@ -614,13 +614,11 @@ pub fn will_create_output_file(&self) -> bool {
// The type of entry function, so
// users can have their own entry
// functions that don't start a
// scheduler
// functions
#[derive(Copy,
Clone,
PartialEq)]
pub
enum
EntryFnType
{
EntryMain
,
EntryStart
,
EntryNone
,
}
#[derive(Copy,
PartialEq,
PartialOrd,
Clone,
Ord,
Eq,
Hash,
Debug)]
...
...
src/librustc/session/mod.rs
浏览文件 @
27adb31f
...
...
@@ -70,8 +70,7 @@ pub struct Session {
pub
opts
:
config
::
Options
,
pub
parse_sess
:
ParseSess
,
/// For a library crate, this is always none
pub
entry_fn
:
RefCell
<
Option
<
(
NodeId
,
Span
)
>>
,
pub
entry_type
:
Cell
<
Option
<
config
::
EntryFnType
>>
,
pub
entry_fn
:
Once
<
Option
<
(
NodeId
,
Span
,
config
::
EntryFnType
)
>>
,
pub
plugin_registrar_fn
:
Cell
<
Option
<
ast
::
NodeId
>>
,
pub
derive_registrar_fn
:
Cell
<
Option
<
ast
::
NodeId
>>
,
pub
default_sysroot
:
Option
<
PathBuf
>
,
...
...
@@ -1094,8 +1093,7 @@ pub fn build_session_(
opts
:
sopts
,
parse_sess
:
p_s
,
// For a library crate, this is always none
entry_fn
:
RefCell
::
new
(
None
),
entry_type
:
Cell
::
new
(
None
),
entry_fn
:
Once
::
new
(),
plugin_registrar_fn
:
Cell
::
new
(
None
),
derive_registrar_fn
:
Cell
::
new
(
None
),
default_sysroot
,
...
...
src/librustc_mir/monomorphize/collector.rs
浏览文件 @
27adb31f
...
...
@@ -325,7 +325,7 @@ fn collect_roots<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let
mut
roots
=
Vec
::
new
();
{
let
entry_fn
=
tcx
.sess.entry_fn
.borrow
()
.map
(|(
node_id
,
_
)|
{
let
entry_fn
=
tcx
.sess.entry_fn
.borrow
()
.map
(|(
node_id
,
_
,
_
)|
{
tcx
.hir
.local_def_id
(
node_id
)
});
...
...
@@ -1038,7 +1038,7 @@ fn push_if_root(&mut self, def_id: DefId) {
/// the return type of `main`. This is not needed when
/// the user writes their own `start` manually.
fn
push_extra_entry_roots
(
&
mut
self
)
{
if
self
.tcx.sess.entry_
type
.get
(
)
!=
Some
(
config
::
EntryMain
)
{
if
self
.tcx.sess.entry_
fn
.get
()
.map
(|
e
|
e
.2
)
!=
Some
(
config
::
EntryMain
)
{
return
}
...
...
src/librustc_mir/monomorphize/item.rs
浏览文件 @
27adb31f
...
...
@@ -92,7 +92,7 @@ fn instantiation_mode(&self,
match
*
self
.as_mono_item
()
{
MonoItem
::
Fn
(
ref
instance
)
=>
{
let
entry_def_id
=
tcx
.sess.entry_fn
.borrow
()
.map
(|(
id
,
_
)|
tcx
.hir
.local_def_id
(
id
));
tcx
.sess.entry_fn
.borrow
()
.map
(|(
id
,
_
,
_
)|
tcx
.hir
.local_def_id
(
id
));
// If this function isn't inlined or otherwise has explicit
// linkage, then we'll be creating a globally shared version.
if
self
.explicit_linkage
(
tcx
)
.is_some
()
||
...
...
src/librustc_trans/base.rs
浏览文件 @
27adb31f
...
...
@@ -517,7 +517,7 @@ pub fn set_link_section(cx: &CodegenCx,
/// users main function.
fn
maybe_create_entry_wrapper
(
cx
:
&
CodegenCx
)
{
let
(
main_def_id
,
span
)
=
match
*
cx
.sess
()
.entry_fn
.borrow
()
{
Some
((
id
,
span
))
=>
{
Some
((
id
,
span
,
_
))
=>
{
(
cx
.tcx.hir
.local_def_id
(
id
),
span
)
}
None
=>
return
,
...
...
@@ -533,11 +533,11 @@ fn maybe_create_entry_wrapper(cx: &CodegenCx) {
let
main_llfn
=
callee
::
get_fn
(
cx
,
instance
);
let
et
=
cx
.sess
()
.entry_
type
.get
()
.unwrap
(
);
let
et
=
cx
.sess
()
.entry_
fn
.get
()
.map
(|
e
|
e
.2
);
match
et
{
config
::
EntryMain
=>
create_entry_fn
(
cx
,
span
,
main_llfn
,
main_def_id
,
true
),
config
::
EntryStart
=>
create_entry_fn
(
cx
,
span
,
main_llfn
,
main_def_id
,
false
),
config
::
Entry
None
=>
{}
// Do nothing.
Some
(
config
::
EntryMain
)
=>
create_entry_fn
(
cx
,
span
,
main_llfn
,
main_def_id
,
true
),
Some
(
config
::
EntryStart
)
=>
create_entry_fn
(
cx
,
span
,
main_llfn
,
main_def_id
,
false
),
None
=>
{}
// Do nothing.
}
fn
create_entry_fn
<
'cx
>
(
cx
:
&
'cx
CodegenCx
,
...
...
src/librustc_trans/debuginfo/mod.rs
浏览文件 @
27adb31f
...
...
@@ -263,7 +263,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
let
local_id
=
cx
.tcx.hir
.as_local_node_id
(
def_id
);
match
*
cx
.sess
()
.entry_fn
.borrow
()
{
Some
((
id
,
_
))
=>
{
Some
((
id
,
_
,
_
))
=>
{
if
local_id
==
Some
(
id
)
{
flags
=
flags
|
DIFlags
::
FlagMainSubprogram
;
}
...
...
src/librustc_trans_utils/lib.rs
浏览文件 @
27adb31f
...
...
@@ -52,7 +52,7 @@
/// that actually test that compilation succeeds without
/// reporting an error.
pub
fn
check_for_rustc_errors_attr
(
tcx
:
TyCtxt
)
{
if
let
Some
((
id
,
span
))
=
*
tcx
.sess.entry_fn
.borrow
()
{
if
let
Some
((
id
,
span
,
_
))
=
*
tcx
.sess.entry_fn
.borrow
()
{
let
main_def_id
=
tcx
.hir
.local_def_id
(
id
);
if
tcx
.has_attr
(
main_def_id
,
"rustc_error"
)
{
...
...
src/librustc_typeck/check/mod.rs
浏览文件 @
27adb31f
...
...
@@ -1128,10 +1128,10 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
// Check that the main return type implements the termination trait.
if
let
Some
(
term_id
)
=
fcx
.tcx
.lang_items
()
.termination
()
{
if
let
Some
((
id
,
_
))
=
*
fcx
.tcx.sess.entry_fn
.borrow
()
{
if
let
Some
((
id
,
_
,
entry_type
))
=
*
fcx
.tcx.sess.entry_fn
.borrow
()
{
if
id
==
fn_id
{
match
fcx
.sess
()
.entry_type
.get
()
{
Some
(
config
::
EntryMain
)
=>
{
match
entry_type
{
config
::
EntryMain
=>
{
let
substs
=
fcx
.tcx
.mk_substs
(
iter
::
once
(
Kind
::
from
(
ret_ty
)));
let
trait_ref
=
ty
::
TraitRef
::
new
(
term_id
,
substs
);
let
return_ty_span
=
decl
.output
.span
();
...
...
@@ -1142,7 +1142,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
traits
::
Obligation
::
new
(
cause
,
param_env
,
trait_ref
.to_predicate
()));
},
_
=>
{},
config
::
EntryStart
=>
{},
}
}
}
...
...
src/librustc_typeck/lib.rs
浏览文件 @
27adb31f
...
...
@@ -289,12 +289,10 @@ fn check_start_fn_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
}
fn
check_for_entry_fn
<
'a
,
'tcx
>
(
tcx
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
)
{
if
let
Some
((
id
,
sp
))
=
*
tcx
.sess.entry_fn
.borrow
()
{
match
tcx
.sess.entry_type
.get
()
{
Some
(
config
::
EntryMain
)
=>
check_main_fn_ty
(
tcx
,
id
,
sp
),
Some
(
config
::
EntryStart
)
=>
check_start_fn_ty
(
tcx
,
id
,
sp
),
Some
(
config
::
EntryNone
)
=>
{}
None
=>
bug!
(
"entry function without a type"
)
if
let
Some
((
id
,
sp
,
entry_type
))
=
*
tcx
.sess.entry_fn
.borrow
()
{
match
entry_type
{
config
::
EntryMain
=>
check_main_fn_ty
(
tcx
,
id
,
sp
),
config
::
EntryStart
=>
check_start_fn_ty
(
tcx
,
id
,
sp
),
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录