Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
2960a6cf
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,发现更多精彩内容 >>
提交
2960a6cf
编写于
4月 01, 2020
作者:
V
Vytautas Astrauskas
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Clarify the comments explaining the purpose of resolve_maybe_global_alloc.
上级
7e6dbd2b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
23 addition
and
4 deletion
+23
-4
src/librustc_mir/interpret/machine.rs
src/librustc_mir/interpret/machine.rs
+9
-4
src/librustc_mir/interpret/memory.rs
src/librustc_mir/interpret/memory.rs
+14
-0
未找到文件。
src/librustc_mir/interpret/machine.rs
浏览文件 @
2960a6cf
...
...
@@ -243,8 +243,11 @@ fn before_access_global(
/// locals in Miri is that in the internals of the compiler they look as
/// normal statics, except that they have the `thread_local` attribute.
/// However, in Miri we want to have a property that each allocation has
/// a unique id and, therefore, for these thread locals we generate a
/// fresh allocation id for each thread.
/// a unique id. Therefore, for these thread locals in
/// `canonical_alloc_id` we reserve fresh allocation ids for each
/// thread. Please note that `canonical_alloc_id` only reserves the
/// allocation ids, the actual allocation for the thread local statics
/// is done in the same way as for regular statics.
///
/// This function must be idempotent.
#[inline]
...
...
@@ -255,8 +258,10 @@ fn canonical_alloc_id(_mem: &Memory<'mir, 'tcx, Self>, id: AllocId) -> AllocId {
/// Called to obtain the `GlobalAlloc` associated with the allocation id.
///
/// Miri uses this callback to resolve the information about the original
/// thread local static for which `canonical_alloc_id` generated a fresh
/// allocation id.
/// thread local static for which `canonical_alloc_id` reserved a fresh
/// allocation id. Since `canonical_alloc_id` does not create the actual
/// allocation and the reserved allocation id has no reference to its
/// parent, we need to ask Miri to retrieve information for us.
#[inline(always)]
fn
resolve_maybe_global_alloc
(
tcx
:
TyCtxtAt
<
'tcx
>
,
...
...
src/librustc_mir/interpret/memory.rs
浏览文件 @
2960a6cf
...
...
@@ -429,6 +429,14 @@ fn get_global_alloc(
id
:
AllocId
,
is_write
:
bool
,
)
->
InterpResult
<
'tcx
,
Cow
<
'tcx
,
Allocation
<
M
::
PointerTag
,
M
::
AllocExtra
>>>
{
// The call to `resolve_maybe_global_alloc` is needed to enable Miri to
// support thread local statics. In `M::canonical_alloc_id`, for a
// thread local static, Miri reserves a fresh allocation id, but the
// actual allocation is left to the code that handles statics which
// calls this function (`get_global_alloc`). Since the allocation id is
// fresh, it has no information about the original static. The call to
// `resolve_maybe_global_alloc` allows Miri to retrieve this information
// for us.
let
(
alloc
,
def_id
)
=
match
M
::
resolve_maybe_global_alloc
(
tcx
,
memory_extra
,
id
)
{
Some
(
GlobalAlloc
::
Memory
(
mem
))
=>
{
// Memory of a constant or promoted or anonymous memory referenced by a static.
...
...
@@ -589,6 +597,12 @@ pub fn get_size_and_align(
}
// # Statics
// The call to `resolve_maybe_global_alloc` is needed here because Miri
// via the call to `canonical_alloc_id` above reserves fresh allocation
// ids for thread local statics. However, the actual allocation is done
// not in `canonical_alloc_id`, but in `get_raw` and `get_raw_mut`.
// Since this function may get called before `get_raw`, we need to allow
// Miri to retrieve the information about the static for us.
match
M
::
resolve_maybe_global_alloc
(
self
.tcx
,
&
self
.extra
,
id
)
{
Some
(
GlobalAlloc
::
Static
(
did
))
=>
{
// Use size and align of the type.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录