Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
8dd1f6a0
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,发现更多精彩内容 >>
提交
8dd1f6a0
编写于
12月 29, 2014
作者:
E
Eduard Burtescu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rustc: remove the vestigial "const marking" pass.
上级
c5db290b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
1 addition
and
169 deletion
+1
-169
src/librustc/middle/check_static.rs
src/librustc/middle/check_static.rs
+1
-0
src/librustc/middle/const_eval.rs
src/librustc/middle/const_eval.rs
+0
-165
src/librustc_driver/driver.rs
src/librustc_driver/driver.rs
+0
-4
未找到文件。
src/librustc/middle/check_static.rs
浏览文件 @
8dd1f6a0
...
...
@@ -79,6 +79,7 @@ pub fn check_crate(tcx: &ty::ctxt) {
mode
:
InNothing
,
checker
:
&
mut
checker
,
},
tcx
.map
.krate
());
tcx
.sess
.abort_if_errors
();
}
impl
<
'a
,
'tcx
>
CheckStaticVisitor
<
'a
,
'tcx
>
{
...
...
src/librustc/middle/const_eval.rs
浏览文件 @
8dd1f6a0
...
...
@@ -12,80 +12,22 @@
#![allow(unsigned_negation)]
pub
use
self
::
const_val
::
*
;
pub
use
self
::
constness
::
*
;
use
metadata
::
csearch
;
use
middle
::{
astencode
,
def
};
use
middle
::
pat_util
::
def_to_path
;
use
middle
::
ty
::{
self
};
use
middle
::
astconv_util
::{
ast_ty_to_prim_ty
};
use
util
::
nodemap
::
DefIdMap
;
use
syntax
::
ast
::{
self
,
Expr
};
use
syntax
::
codemap
::
Span
;
use
syntax
::
parse
::
token
::
InternedString
;
use
syntax
::
ptr
::
P
;
use
syntax
::
visit
::{
self
,
Visitor
};
use
syntax
::{
ast_map
,
ast_util
,
codemap
};
use
std
::
collections
::
hash_map
::
Entry
::
Vacant
;
use
std
::
rc
::
Rc
;
//
// This pass classifies expressions by their constant-ness.
//
// Constant-ness comes in 3 flavours:
//
// - Integer-constants: can be evaluated by the frontend all the way down
// to their actual value. They are used in a few places (enum
// discriminants, switch arms) and are a subset of
// general-constants. They cover all the integer and integer-ish
// literals (nil, bool, int, uint, char, iNN, uNN) and all integer
// operators and copies applied to them.
//
// - General-constants: can be evaluated by LLVM but not necessarily by
// the frontend; usually due to reliance on target-specific stuff such
// as "where in memory the value goes" or "what floating point mode the
// target uses". This _includes_ integer-constants, plus the following
// constructors:
//
// fixed-size vectors and strings: [] and ""/_
// vector and string slices: &[] and &""
// tuples: (,)
// enums: foo(...)
// floating point literals and operators
// & and * pointers
// copies of general constants
//
// (in theory, probably not at first: if/match on integer-const
// conditions / discriminants)
//
// - Non-constants: everything else.
//
#[derive(Copy)]
pub
enum
constness
{
integral_const
,
general_const
,
non_const
}
type
constness_cache
=
DefIdMap
<
constness
>
;
pub
fn
join
(
a
:
constness
,
b
:
constness
)
->
constness
{
match
(
a
,
b
)
{
(
integral_const
,
integral_const
)
=>
integral_const
,
(
integral_const
,
general_const
)
|
(
general_const
,
integral_const
)
|
(
general_const
,
general_const
)
=>
general_const
,
_
=>
non_const
}
}
pub
fn
join_all
<
It
:
Iterator
<
Item
=
constness
>>
(
cs
:
It
)
->
constness
{
cs
.fold
(
integral_const
,
|
a
,
b
|
join
(
a
,
b
))
}
fn
lookup_const
<
'a
>
(
tcx
:
&
'a
ty
::
ctxt
,
e
:
&
Expr
)
->
Option
<&
'a
Expr
>
{
let
opt_def
=
tcx
.def_map
.borrow
()
.get
(
&
e
.id
)
.cloned
();
match
opt_def
{
...
...
@@ -186,113 +128,6 @@ pub fn lookup_const_by_id<'a>(tcx: &'a ty::ctxt, def_id: ast::DefId)
}
}
struct
ConstEvalVisitor
<
'a
,
'tcx
:
'a
>
{
tcx
:
&
'a
ty
::
ctxt
<
'tcx
>
,
ccache
:
constness_cache
,
}
impl
<
'a
,
'tcx
>
ConstEvalVisitor
<
'a
,
'tcx
>
{
fn
classify
(
&
mut
self
,
e
:
&
Expr
)
->
constness
{
let
did
=
ast_util
::
local_def
(
e
.id
);
match
self
.ccache
.get
(
&
did
)
{
Some
(
&
x
)
=>
return
x
,
None
=>
{}
}
let
cn
=
match
e
.node
{
ast
::
ExprLit
(
ref
lit
)
=>
{
match
lit
.node
{
ast
::
LitStr
(
..
)
|
ast
::
LitFloat
(
..
)
=>
general_const
,
_
=>
integral_const
}
}
ast
::
ExprUnary
(
_
,
ref
inner
)
|
ast
::
ExprParen
(
ref
inner
)
=>
self
.classify
(
&**
inner
),
ast
::
ExprBinary
(
_
,
ref
a
,
ref
b
)
=>
join
(
self
.classify
(
&**
a
),
self
.classify
(
&**
b
)),
ast
::
ExprTup
(
ref
es
)
|
ast
::
ExprVec
(
ref
es
)
=>
join_all
(
es
.iter
()
.map
(|
e
|
self
.classify
(
&**
e
))),
ast
::
ExprStruct
(
_
,
ref
fs
,
None
)
=>
{
let
cs
=
fs
.iter
()
.map
(|
f
|
self
.classify
(
&*
f
.expr
));
join_all
(
cs
)
}
ast
::
ExprCast
(
ref
base
,
_
)
=>
{
let
ty
=
ty
::
expr_ty
(
self
.tcx
,
e
);
let
base
=
self
.classify
(
&**
base
);
if
ty
::
type_is_integral
(
ty
)
{
join
(
integral_const
,
base
)
}
else
if
ty
::
type_is_fp
(
ty
)
{
join
(
general_const
,
base
)
}
else
{
non_const
}
}
ast
::
ExprField
(
ref
base
,
_
)
=>
self
.classify
(
&**
base
),
ast
::
ExprTupField
(
ref
base
,
_
)
=>
self
.classify
(
&**
base
),
ast
::
ExprIndex
(
ref
base
,
ref
idx
)
=>
join
(
self
.classify
(
&**
base
),
self
.classify
(
&**
idx
)),
ast
::
ExprAddrOf
(
ast
::
MutImmutable
,
ref
base
)
=>
self
.classify
(
&**
base
),
// FIXME: (#3728) we can probably do something CCI-ish
// surrounding nonlocal constants. But we don't yet.
ast
::
ExprPath
(
_
)
|
ast
::
ExprQPath
(
_
)
=>
self
.lookup_constness
(
e
),
ast
::
ExprRepeat
(
..
)
=>
general_const
,
ast
::
ExprBlock
(
ref
block
)
=>
{
match
block
.expr
{
Some
(
ref
e
)
=>
self
.classify
(
&**
e
),
None
=>
integral_const
}
}
_
=>
non_const
};
self
.ccache
.insert
(
did
,
cn
);
cn
}
fn
lookup_constness
(
&
self
,
e
:
&
Expr
)
->
constness
{
match
lookup_const
(
self
.tcx
,
e
)
{
Some
(
rhs
)
=>
{
let
ty
=
ty
::
expr_ty
(
self
.tcx
,
&*
rhs
);
if
ty
::
type_is_integral
(
ty
)
{
integral_const
}
else
{
general_const
}
}
None
=>
non_const
}
}
}
impl
<
'a
,
'tcx
,
'v
>
Visitor
<
'v
>
for
ConstEvalVisitor
<
'a
,
'tcx
>
{
fn
visit_expr_post
(
&
mut
self
,
e
:
&
Expr
)
{
self
.classify
(
e
);
}
}
pub
fn
process_crate
(
tcx
:
&
ty
::
ctxt
)
{
visit
::
walk_crate
(
&
mut
ConstEvalVisitor
{
tcx
:
tcx
,
ccache
:
DefIdMap
(),
},
tcx
.map
.krate
());
tcx
.sess
.abort_if_errors
();
}
// FIXME (#33): this doesn't handle big integer/float literals correctly
// (nor does the rest of our literal handling).
#[derive(Clone,
PartialEq)]
...
...
src/librustc_driver/driver.rs
浏览文件 @
8dd1f6a0
...
...
@@ -614,10 +614,6 @@ pub fn phase_3_run_analysis_passes<'tcx>(sess: Session,
time
(
time_passes
,
"check static items"
,
(),
|
_
|
middle
::
check_static
::
check_crate
(
&
ty_cx
));
// These next two const passes can probably be merged
time
(
time_passes
,
"const marking"
,
(),
|
_
|
middle
::
const_eval
::
process_crate
(
&
ty_cx
));
time
(
time_passes
,
"const checking"
,
(),
|
_
|
middle
::
check_const
::
check_crate
(
&
ty_cx
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录