Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
c30c1be1
R
Rust
项目概览
int
/
Rust
12 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
c30c1be1
编写于
3月 15, 2021
作者:
O
Oli Scherer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
s/ConstantSource/ConstantKind/
上级
11ddd225
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
43 addition
and
51 deletion
+43
-51
compiler/rustc_codegen_cranelift/src/constant.rs
compiler/rustc_codegen_cranelift/src/constant.rs
+6
-6
compiler/rustc_codegen_ssa/src/mir/constant.rs
compiler/rustc_codegen_ssa/src/mir/constant.rs
+2
-2
compiler/rustc_middle/src/mir/interpret/value.rs
compiler/rustc_middle/src/mir/interpret/value.rs
+0
-8
compiler/rustc_middle/src/mir/mod.rs
compiler/rustc_middle/src/mir/mod.rs
+14
-14
compiler/rustc_middle/src/mir/type_foldable.rs
compiler/rustc_middle/src/mir/type_foldable.rs
+5
-5
compiler/rustc_middle/src/mir/visit.rs
compiler/rustc_middle/src/mir/visit.rs
+2
-2
compiler/rustc_mir/src/borrow_check/type_check/mod.rs
compiler/rustc_mir/src/borrow_check/type_check/mod.rs
+1
-1
compiler/rustc_mir/src/interpret/operand.rs
compiler/rustc_mir/src/interpret/operand.rs
+3
-3
compiler/rustc_mir/src/transform/const_prop.rs
compiler/rustc_mir/src/transform/const_prop.rs
+6
-6
compiler/rustc_mir/src/util/pretty.rs
compiler/rustc_mir/src/util/pretty.rs
+2
-2
compiler/rustc_trait_selection/src/traits/const_evaluatable.rs
...ler/rustc_trait_selection/src/traits/const_evaluatable.rs
+2
-2
未找到文件。
compiler/rustc_codegen_cranelift/src/constant.rs
浏览文件 @
c30c1be1
...
...
@@ -40,8 +40,8 @@ pub(crate) fn check_constants(fx: &mut FunctionCx<'_, '_, '_>) -> bool {
let
mut
all_constants_ok
=
true
;
for
constant
in
&
fx
.mir.required_consts
{
let
const_
=
match
fx
.monomorphize
(
constant
.literal
)
{
Constant
Source
::
Ty
(
ct
)
=>
ct
,
Constant
Source
::
Val
(
..
)
=>
continue
,
Constant
Kind
::
Ty
(
ct
)
=>
ct
,
Constant
Kind
::
Val
(
..
)
=>
continue
,
};
match
const_
.val
{
ConstKind
::
Value
(
_
)
=>
{}
...
...
@@ -117,8 +117,8 @@ pub(crate) fn codegen_constant<'tcx>(
constant
:
&
Constant
<
'tcx
>
,
)
->
CValue
<
'tcx
>
{
let
const_
=
match
fx
.monomorphize
(
constant
.literal
)
{
Constant
Source
::
Ty
(
ct
)
=>
ct
,
Constant
Source
::
Val
(
val
,
ty
)
=>
return
codegen_const_value
(
fx
,
val
,
ty
),
Constant
Kind
::
Ty
(
ct
)
=>
ct
,
Constant
Kind
::
Val
(
val
,
ty
)
=>
return
codegen_const_value
(
fx
,
val
,
ty
),
};
let
const_val
=
match
const_
.val
{
ConstKind
::
Value
(
const_val
)
=>
const_val
,
...
...
@@ -427,10 +427,10 @@ pub(crate) fn mir_operand_get_const_val<'tcx>(
match
operand
{
Operand
::
Copy
(
_
)
|
Operand
::
Move
(
_
)
=>
None
,
Operand
::
Constant
(
const_
)
=>
match
const_
.literal
{
Constant
Source
::
Ty
(
const_
)
=>
{
Constant
Kind
::
Ty
(
const_
)
=>
{
fx
.monomorphize
(
const_
)
.eval
(
fx
.tcx
,
ParamEnv
::
reveal_all
())
.val
.try_to_value
()
}
Constant
Source
::
Val
(
val
,
_
)
=>
Some
(
val
),
Constant
Kind
::
Val
(
val
,
_
)
=>
Some
(
val
),
},
}
}
compiler/rustc_codegen_ssa/src/mir/constant.rs
浏览文件 @
c30c1be1
...
...
@@ -26,8 +26,8 @@ pub fn eval_mir_constant(
)
->
Result
<
ConstValue
<
'tcx
>
,
ErrorHandled
>
{
let
ct
=
self
.monomorphize
(
constant
.literal
);
let
ct
=
match
ct
{
mir
::
Constant
Source
::
Ty
(
ct
)
=>
ct
,
mir
::
Constant
Source
::
Val
(
val
,
_
)
=>
return
Ok
(
val
),
mir
::
Constant
Kind
::
Ty
(
ct
)
=>
ct
,
mir
::
Constant
Kind
::
Val
(
val
,
_
)
=>
return
Ok
(
val
),
};
match
ct
.val
{
ty
::
ConstKind
::
Unevaluated
(
def
,
substs
,
promoted
)
=>
self
...
...
compiler/rustc_middle/src/mir/interpret/value.rs
浏览文件 @
c30c1be1
...
...
@@ -381,14 +381,6 @@ pub fn assert_bits(self, target_size: Size) -> u128 {
self
.to_bits
(
target_size
)
.expect
(
"expected Raw bits but got a Pointer"
)
}
#[inline]
pub
fn
to_int
(
self
)
->
InterpResult
<
'tcx
,
ScalarInt
>
{
match
self
{
Scalar
::
Ptr
(
_
)
=>
throw_unsup!
(
ReadPointerAsBytes
),
Scalar
::
Int
(
int
)
=>
Ok
(
int
),
}
}
#[inline]
pub
fn
assert_int
(
self
)
->
ScalarInt
{
self
.to_int
()
.expect
(
"expected an int but got an abstract pointer"
)
...
...
compiler/rustc_middle/src/mir/mod.rs
浏览文件 @
c30c1be1
...
...
@@ -2033,7 +2033,7 @@ pub fn function_handle(
Operand
::
Constant
(
box
Constant
{
span
,
user_ty
:
None
,
literal
:
Constant
Source
::
Ty
(
ty
::
Const
::
zero_sized
(
tcx
,
ty
)),
literal
:
Constant
Kind
::
Ty
(
ty
::
Const
::
zero_sized
(
tcx
,
ty
)),
})
}
...
...
@@ -2064,7 +2064,7 @@ pub fn const_from_scalar(
Operand
::
Constant
(
box
Constant
{
span
,
user_ty
:
None
,
literal
:
Constant
Source
::
Val
(
val
.into
(),
ty
),
literal
:
Constant
Kind
::
Val
(
val
.into
(),
ty
),
})
}
...
...
@@ -2406,11 +2406,11 @@ pub struct Constant<'tcx> {
/// Needed for NLL to impose user-given type constraints.
pub
user_ty
:
Option
<
UserTypeAnnotationIndex
>
,
pub
literal
:
Constant
Source
<
'tcx
>
,
pub
literal
:
Constant
Kind
<
'tcx
>
,
}
#[derive(Clone,
Copy,
PartialEq,
PartialOrd,
TyEncodable,
TyDecodable,
Hash,
HashStable,
Debug)]
pub
enum
Constant
Source
<
'tcx
>
{
pub
enum
Constant
Kind
<
'tcx
>
{
/// This constant came from the type system
Ty
(
&
'tcx
ty
::
Const
<
'tcx
>
),
/// This constant cannot go back into the type system, as it represents
...
...
@@ -2436,33 +2436,33 @@ pub fn ty(&self) -> Ty<'tcx> {
}
}
impl
From
<&
'tcx
ty
::
Const
<
'tcx
>>
for
Constant
Source
<
'tcx
>
{
impl
From
<&
'tcx
ty
::
Const
<
'tcx
>>
for
Constant
Kind
<
'tcx
>
{
fn
from
(
ct
:
&
'tcx
ty
::
Const
<
'tcx
>
)
->
Self
{
Self
::
Ty
(
ct
)
}
}
impl
Constant
Source
<
'tcx
>
{
impl
Constant
Kind
<
'tcx
>
{
/// Returns `None` if the constant is not trivially safe for use in the type system.
pub
fn
const_for_ty
(
&
self
)
->
Option
<&
'tcx
ty
::
Const
<
'tcx
>>
{
match
self
{
Constant
Source
::
Ty
(
c
)
=>
Some
(
c
),
Constant
Source
::
Val
(
..
)
=>
None
,
Constant
Kind
::
Ty
(
c
)
=>
Some
(
c
),
Constant
Kind
::
Val
(
..
)
=>
None
,
}
}
pub
fn
ty
(
&
self
)
->
Ty
<
'tcx
>
{
match
self
{
Constant
Source
::
Ty
(
c
)
=>
c
.ty
,
Constant
Source
::
Val
(
_
,
ty
)
=>
ty
,
Constant
Kind
::
Ty
(
c
)
=>
c
.ty
,
Constant
Kind
::
Val
(
_
,
ty
)
=>
ty
,
}
}
#[inline]
pub
fn
try_to_value
(
self
)
->
Option
<
interpret
::
ConstValue
<
'tcx
>>
{
match
self
{
Constant
Source
::
Ty
(
c
)
=>
c
.val
.try_to_value
(),
Constant
Source
::
Val
(
val
,
_
)
=>
Some
(
val
),
Constant
Kind
::
Ty
(
c
)
=>
c
.val
.try_to_value
(),
Constant
Kind
::
Val
(
val
,
_
)
=>
Some
(
val
),
}
}
...
...
@@ -2709,8 +2709,8 @@ fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
_
=>
write!
(
fmt
,
"const "
)
?
,
}
match
self
.literal
{
Constant
Source
::
Ty
(
c
)
=>
pretty_print_const
(
c
,
fmt
,
true
),
Constant
Source
::
Val
(
val
,
ty
)
=>
pretty_print_const_value
(
val
,
ty
,
fmt
,
true
),
Constant
Kind
::
Ty
(
c
)
=>
pretty_print_const
(
c
,
fmt
,
true
),
Constant
Kind
::
Val
(
val
,
ty
)
=>
pretty_print_const_value
(
val
,
ty
,
fmt
,
true
),
}
}
}
...
...
compiler/rustc_middle/src/mir/type_foldable.rs
浏览文件 @
c30c1be1
...
...
@@ -347,18 +347,18 @@ fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow
}
}
impl
<
'tcx
>
TypeFoldable
<
'tcx
>
for
Constant
Source
<
'tcx
>
{
impl
<
'tcx
>
TypeFoldable
<
'tcx
>
for
Constant
Kind
<
'tcx
>
{
fn
super_fold_with
<
F
:
TypeFolder
<
'tcx
>>
(
self
,
folder
:
&
mut
F
)
->
Self
{
match
self
{
Constant
Source
::
Ty
(
c
)
=>
ConstantSource
::
Ty
(
c
.fold_with
(
folder
)),
Constant
Source
::
Val
(
v
,
t
)
=>
ConstantSource
::
Val
(
v
,
t
.fold_with
(
folder
)),
Constant
Kind
::
Ty
(
c
)
=>
ConstantKind
::
Ty
(
c
.fold_with
(
folder
)),
Constant
Kind
::
Val
(
v
,
t
)
=>
ConstantKind
::
Val
(
v
,
t
.fold_with
(
folder
)),
}
}
fn
super_visit_with
<
V
:
TypeVisitor
<
'tcx
>>
(
&
self
,
visitor
:
&
mut
V
)
->
ControlFlow
<
V
::
BreakTy
>
{
match
*
self
{
Constant
Source
::
Ty
(
c
)
=>
c
.visit_with
(
visitor
),
Constant
Source
::
Val
(
_
,
t
)
=>
t
.visit_with
(
visitor
),
Constant
Kind
::
Ty
(
c
)
=>
c
.visit_with
(
visitor
),
Constant
Kind
::
Val
(
_
,
t
)
=>
t
.visit_with
(
visitor
),
}
}
}
compiler/rustc_middle/src/mir/visit.rs
浏览文件 @
c30c1be1
...
...
@@ -872,8 +872,8 @@ fn super_constant(&mut self,
self
.visit_span
(
span
);
drop
(
user_ty
);
// no visit method for this
match
literal
{
Constant
Source
::
Ty
(
ct
)
=>
self
.visit_const
(
ct
,
location
),
Constant
Source
::
Val
(
_
,
t
)
=>
self
.visit_ty
(
t
,
TyContext
::
Location
(
location
)),
Constant
Kind
::
Ty
(
ct
)
=>
self
.visit_const
(
ct
,
location
),
Constant
Kind
::
Val
(
_
,
t
)
=>
self
.visit_ty
(
t
,
TyContext
::
Location
(
location
)),
}
}
...
...
compiler/rustc_mir/src/borrow_check/type_check/mod.rs
浏览文件 @
c30c1be1
...
...
@@ -315,7 +315,7 @@ fn visit_constant(&mut self, constant: &Constant<'tcx>, location: Location) {
}
else
{
let
tcx
=
self
.tcx
();
let
maybe_uneval
=
match
constant
.literal
{
Constant
Source
::
Ty
(
ct
)
=>
match
ct
.val
{
Constant
Kind
::
Ty
(
ct
)
=>
match
ct
.val
{
ty
::
ConstKind
::
Unevaluated
(
def
,
substs
,
promoted
)
=>
{
Some
((
def
,
substs
,
promoted
))
}
...
...
compiler/rustc_mir/src/interpret/operand.rs
浏览文件 @
c30c1be1
...
...
@@ -573,12 +573,12 @@ pub(super) fn eval_operands(
crate
fn
mir_const_to_op
(
&
self
,
val
:
&
mir
::
Constant
Source
<
'tcx
>
,
val
:
&
mir
::
Constant
Kind
<
'tcx
>
,
layout
:
Option
<
TyAndLayout
<
'tcx
>>
,
)
->
InterpResult
<
'tcx
,
OpTy
<
'tcx
,
M
::
PointerTag
>>
{
match
val
{
mir
::
Constant
Source
::
Ty
(
ct
)
=>
self
.const_to_op
(
ct
,
layout
),
mir
::
Constant
Source
::
Val
(
val
,
ty
)
=>
self
.const_val_to_op
(
*
val
,
ty
,
None
),
mir
::
Constant
Kind
::
Ty
(
ct
)
=>
self
.const_to_op
(
ct
,
layout
),
mir
::
Constant
Kind
::
Val
(
val
,
ty
)
=>
self
.const_val_to_op
(
*
val
,
ty
,
None
),
}
}
...
...
compiler/rustc_mir/src/transform/const_prop.rs
浏览文件 @
c30c1be1
...
...
@@ -13,9 +13,9 @@
MutVisitor
,
MutatingUseContext
,
NonMutatingUseContext
,
PlaceContext
,
Visitor
,
};
use
rustc_middle
::
mir
::{
AssertKind
,
BasicBlock
,
BinOp
,
Body
,
ClearCrossCrate
,
Constant
,
Constant
Source
,
Loca
l
,
Local
Decl
,
LocalKind
,
Location
,
Operand
,
Place
,
Rvalue
,
SourceInfo
,
SourceScope
,
S
ourceScopeData
,
S
tatement
,
StatementKind
,
Terminator
,
TerminatorKind
,
UnOp
,
RETURN_PLACE
,
AssertKind
,
BasicBlock
,
BinOp
,
Body
,
ClearCrossCrate
,
Constant
,
Constant
Kind
,
Local
,
LocalDec
l
,
Local
Kind
,
Location
,
Operand
,
Place
,
Rvalue
,
SourceInfo
,
SourceScope
,
SourceScopeData
,
Statement
,
StatementKind
,
Terminator
,
TerminatorKind
,
UnOp
,
RETURN_PLACE
,
};
use
rustc_middle
::
ty
::
layout
::{
HasTyCtxt
,
LayoutError
,
TyAndLayout
};
use
rustc_middle
::
ty
::
subst
::{
InternalSubsts
,
Subst
};
...
...
@@ -489,14 +489,14 @@ fn eval_constant(&mut self, c: &Constant<'tcx>, source_info: SourceInfo) -> Opti
let
err
=
ConstEvalErr
::
new
(
&
self
.ecx
,
error
,
Some
(
c
.span
));
if
let
Some
(
lint_root
)
=
self
.lint_root
(
source_info
)
{
let
lint_only
=
match
c
.literal
{
Constant
Source
::
Ty
(
ct
)
=>
match
ct
.val
{
Constant
Kind
::
Ty
(
ct
)
=>
match
ct
.val
{
// Promoteds must lint and not error as the user didn't ask for them
ConstKind
::
Unevaluated
(
_
,
_
,
Some
(
_
))
=>
true
,
// Out of backwards compatibility we cannot report hard errors in unused
// generic functions using associated constants of the generic parameters.
_
=>
c
.literal
.needs_subst
(),
},
Constant
Source
::
Val
(
_
,
ty
)
=>
ty
.needs_subst
(),
Constant
Kind
::
Val
(
_
,
ty
)
=>
ty
.needs_subst
(),
};
if
lint_only
{
// Out of backwards compatibility we cannot report hard errors in unused
...
...
@@ -818,7 +818,7 @@ fn replace_with_const(
)
{
if
let
Rvalue
::
Use
(
Operand
::
Constant
(
c
))
=
rval
{
match
c
.literal
{
Constant
Source
::
Ty
(
c
)
if
matches!
(
c
.val
,
ConstKind
::
Unevaluated
(
..
))
=>
{}
Constant
Kind
::
Ty
(
c
)
if
matches!
(
c
.val
,
ConstKind
::
Unevaluated
(
..
))
=>
{}
_
=>
{
trace!
(
"skipping replace of Rvalue::Use({:?} because it is already a const"
,
c
);
return
;
...
...
compiler/rustc_mir/src/util/pretty.rs
浏览文件 @
c30c1be1
...
...
@@ -450,8 +450,8 @@ fn visit_constant(&mut self, constant: &Constant<'tcx>, location: Location) {
self
.push
(
&
format!
(
"+ user_ty: {:?}"
,
user_ty
));
}
match
literal
{
Constant
Source
::
Ty
(
literal
)
=>
self
.push
(
&
format!
(
"+ literal: {:?}"
,
literal
)),
Constant
Source
::
Val
(
val
,
ty
)
=>
{
Constant
Kind
::
Ty
(
literal
)
=>
self
.push
(
&
format!
(
"+ literal: {:?}"
,
literal
)),
Constant
Kind
::
Val
(
val
,
ty
)
=>
{
self
.push
(
&
format!
(
"+ literal: {:?}, {}"
,
val
,
ty
))
}
}
...
...
compiler/rustc_trait_selection/src/traits/const_evaluatable.rs
浏览文件 @
c30c1be1
...
...
@@ -378,8 +378,8 @@ fn operand_to_node(
Ok
(
self
.locals
[
local
])
}
mir
::
Operand
::
Constant
(
ct
)
=>
match
ct
.literal
{
mir
::
Constant
Source
::
Ty
(
ct
)
=>
Ok
(
self
.add_node
(
Node
::
Leaf
(
ct
),
span
)),
mir
::
Constant
Source
::
Val
(
..
)
=>
self
.error
(
Some
(
span
),
"unsupported constant"
)
?
,
mir
::
Constant
Kind
::
Ty
(
ct
)
=>
Ok
(
self
.add_node
(
Node
::
Leaf
(
ct
),
span
)),
mir
::
Constant
Kind
::
Val
(
..
)
=>
self
.error
(
Some
(
span
),
"unsupported constant"
)
?
,
},
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录