Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
d92df974
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,发现更多精彩内容 >>
提交
d92df974
编写于
3月 07, 2022
作者:
B
b-naber
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
treat literals in ExprKind::StaticRef as mir::ConstantKind::Val
上级
1b14fd3b
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
30 addition
and
21 deletion
+30
-21
compiler/rustc_middle/src/mir/mod.rs
compiler/rustc_middle/src/mir/mod.rs
+1
-1
compiler/rustc_middle/src/mir/pretty.rs
compiler/rustc_middle/src/mir/pretty.rs
+16
-6
compiler/rustc_middle/src/thir.rs
compiler/rustc_middle/src/thir.rs
+3
-1
compiler/rustc_middle/src/thir/visit.rs
compiler/rustc_middle/src/thir/visit.rs
+1
-1
compiler/rustc_mir_build/src/build/expr/as_constant.rs
compiler/rustc_mir_build/src/build/expr/as_constant.rs
+7
-2
compiler/rustc_mir_build/src/thir/cx/expr.rs
compiler/rustc_mir_build/src/thir/cx/expr.rs
+2
-10
未找到文件。
compiler/rustc_middle/src/mir/mod.rs
浏览文件 @
d92df974
...
...
@@ -2534,7 +2534,7 @@ pub enum ConstantKind<'tcx> {
impl
<
'tcx
>
Constant
<
'tcx
>
{
pub
fn
check_static_ptr
(
&
self
,
tcx
:
TyCtxt
<
'_
>
)
->
Option
<
DefId
>
{
match
self
.literal
.
const_for_ty
()
?
.val
()
.
try_to_scalar
()
{
match
self
.literal
.try_to_scalar
()
{
Some
(
Scalar
::
Ptr
(
ptr
,
_
size
))
=>
match
tcx
.global_alloc
(
ptr
.provenance
)
{
GlobalAlloc
::
Static
(
def_id
)
=>
{
assert
!
(
!
tcx
.is_thread_local_static
(
def_id
));
...
...
compiler/rustc_middle/src/mir/pretty.rs
浏览文件 @
d92df974
...
...
@@ -17,9 +17,8 @@
use
rustc_middle
::
mir
::
visit
::
Visitor
;
use
rustc_middle
::
mir
::
MirSource
;
use
rustc_middle
::
mir
::
*
;
use
rustc_middle
::
ty
::{
self
,
TyCtxt
,
TypeFoldable
,
TypeVisitor
};
use
rustc_middle
::
ty
::{
self
,
TyCtxt
};
use
rustc_target
::
abi
::
Size
;
use
std
::
ops
::
ControlFlow
;
const
INDENT
:
&
str
=
" "
;
/// Alignment for lining up comments following MIR statements
...
...
@@ -669,16 +668,27 @@ fn alloc_ids_from_const(val: ConstValue<'_>) -> impl Iterator<Item = AllocId> +
}
}
struct
CollectAllocIds
(
BTreeSet
<
AllocId
>
);
impl
<
'tcx
>
TypeVisitor
<
'tcx
>
for
CollectAllocIds
{
fn
visit_const
(
&
mut
self
,
c
:
ty
::
Const
<
'tcx
>
)
->
ControlFlow
<
Self
::
BreakTy
>
{
impl
<
'tcx
>
Visitor
<
'tcx
>
for
CollectAllocIds
{
fn
visit_const
(
&
mut
self
,
c
:
ty
::
Const
<
'tcx
>
,
_
loc
:
Location
)
{
if
let
ty
::
ConstKind
::
Value
(
val
)
=
c
.val
()
{
self
.0
.extend
(
alloc_ids_from_const
(
val
));
}
c
.super_visit_with
(
self
)
}
fn
visit_constant
(
&
mut
self
,
c
:
&
Constant
<
'tcx
>
,
loc
:
Location
)
{
match
c
.literal
{
ConstantKind
::
Ty
(
c
)
=>
self
.visit_const
(
c
,
loc
),
ConstantKind
::
Val
(
val
,
_
)
=>
{
self
.0
.extend
(
alloc_ids_from_const
(
val
));
}
}
}
}
let
mut
visitor
=
CollectAllocIds
(
Default
::
default
());
body
.visit_with
(
&
mut
visitor
);
visitor
.visit_body
(
body
);
// `seen` contains all seen allocations, including the ones we have *not* printed yet.
// The protocol is to first `insert` into `seen`, and only if that returns `true`
// then push to `todo`.
...
...
compiler/rustc_middle/src/thir.rs
浏览文件 @
d92df974
...
...
@@ -17,6 +17,7 @@
use
rustc_index
::
vec
::
IndexVec
;
use
rustc_middle
::
infer
::
canonical
::
Canonical
;
use
rustc_middle
::
middle
::
region
;
use
rustc_middle
::
mir
::
interpret
::
AllocId
;
use
rustc_middle
::
mir
::{
BinOp
,
BorrowKind
,
FakeReadCause
,
Field
,
Mutability
,
UnOp
,
UserTypeProjection
,
};
...
...
@@ -419,7 +420,8 @@ pub enum ExprKind<'tcx> {
/// This is only distinguished from `Literal` so that we can register some
/// info for diagnostics.
StaticRef
{
literal
:
Const
<
'tcx
>
,
alloc_id
:
AllocId
,
ty
:
Ty
<
'tcx
>
,
def_id
:
DefId
,
},
/// Inline assembly, i.e. `asm!()`.
...
...
compiler/rustc_middle/src/thir/visit.rs
浏览文件 @
d92df974
...
...
@@ -123,7 +123,7 @@ pub fn walk_expr<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, expr: &Exp
}
Closure
{
closure_id
:
_
,
substs
:
_
,
upvars
:
_
,
movability
:
_
,
fake_reads
:
_
}
=>
{}
Literal
{
literal
,
user_ty
:
_
,
const_id
:
_
}
=>
visitor
.visit_const
(
literal
),
StaticRef
{
literal
,
def_id
:
_
}
=>
visitor
.visit_const
(
literal
),
StaticRef
{
..
}
=>
{}
InlineAsm
{
ref
operands
,
template
:
_
,
options
:
_
,
line_spans
:
_
}
=>
{
for
op
in
&**
operands
{
use
InlineAsmOperand
::
*
;
...
...
compiler/rustc_mir_build/src/build/expr/as_constant.rs
浏览文件 @
d92df974
//! See docs in build/expr/mod.rs
use
crate
::
build
::
Builder
;
use
rustc_middle
::
mir
::
interpret
::{
ConstValue
,
Scalar
};
use
rustc_middle
::
mir
::
*
;
use
rustc_middle
::
thir
::
*
;
use
rustc_middle
::
ty
::
CanonicalUserTypeAnnotation
;
...
...
@@ -26,8 +27,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
assert_eq!
(
literal
.ty
(),
ty
);
Constant
{
span
,
user_ty
,
literal
:
literal
.into
()
}
}
ExprKind
::
StaticRef
{
literal
,
..
}
=>
{
Constant
{
span
,
user_ty
:
None
,
literal
:
literal
.into
()
}
ExprKind
::
StaticRef
{
alloc_id
,
ty
,
..
}
=>
{
let
const_val
=
ConstValue
::
Scalar
(
Scalar
::
from_pointer
(
alloc_id
.into
(),
&
this
.tcx
));
let
literal
=
ConstantKind
::
Val
(
const_val
,
ty
);
Constant
{
span
,
user_ty
:
None
,
literal
}
}
ExprKind
::
ConstBlock
{
value
}
=>
{
Constant
{
span
:
span
,
user_ty
:
None
,
literal
:
value
.into
()
}
...
...
compiler/rustc_mir_build/src/thir/cx/expr.rs
浏览文件 @
d92df974
...
...
@@ -8,7 +8,6 @@
use
rustc_middle
::
hir
::
place
::
PlaceBase
as
HirPlaceBase
;
use
rustc_middle
::
hir
::
place
::
ProjectionKind
as
HirProjectionKind
;
use
rustc_middle
::
middle
::
region
;
use
rustc_middle
::
mir
::
interpret
::
Scalar
;
use
rustc_middle
::
mir
::{
BinOp
,
BorrowKind
,
Field
,
UnOp
};
use
rustc_middle
::
thir
::
*
;
use
rustc_middle
::
ty
::
adjustment
::{
...
...
@@ -941,15 +940,8 @@ fn convert_path_expr(&mut self, expr: &'tcx hir::Expr<'tcx>, res: Res) -> ExprKi
let
kind
=
if
self
.tcx
.is_thread_local_static
(
id
)
{
ExprKind
::
ThreadLocalRef
(
id
)
}
else
{
let
ptr
=
self
.tcx
.create_static_alloc
(
id
);
ExprKind
::
StaticRef
{
literal
:
ty
::
Const
::
from_scalar
(
self
.tcx
,
Scalar
::
from_pointer
(
ptr
.into
(),
&
self
.tcx
),
ty
,
),
def_id
:
id
,
}
let
alloc_id
=
self
.tcx
.create_static_alloc
(
id
);
ExprKind
::
StaticRef
{
alloc_id
,
ty
,
def_id
:
id
}
};
ExprKind
::
Deref
{
arg
:
self
.thir.exprs
.push
(
Expr
{
ty
,
temp_lifetime
,
span
:
expr
.span
,
kind
}),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录