Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
1dbc467f
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,发现更多精彩内容 >>
提交
1dbc467f
编写于
9月 30, 2013
作者:
B
bors
浏览文件
操作
浏览文件
下载
差异文件
auto merge of #9643 : thestinger/rust/immediate, r=alexcrichton
上级
bc6dd906
ab0a884a
变更
8
显示空白变更内容
内联
并排
Showing
8 changed file
with
84 addition
and
49 deletion
+84
-49
src/librustc/middle/trans/base.rs
src/librustc/middle/trans/base.rs
+2
-2
src/librustc/middle/trans/common.rs
src/librustc/middle/trans/common.rs
+23
-4
src/librustc/middle/trans/datum.rs
src/librustc/middle/trans/datum.rs
+3
-3
src/librustc/middle/trans/glue.rs
src/librustc/middle/trans/glue.rs
+3
-13
src/librustc/middle/trans/intrinsic.rs
src/librustc/middle/trans/intrinsic.rs
+3
-3
src/librustc/middle/trans/type_of.rs
src/librustc/middle/trans/type_of.rs
+2
-2
src/librustc/middle/ty.rs
src/librustc/middle/ty.rs
+10
-22
src/test/run-pass/issue-9446.rs
src/test/run-pass/issue-9446.rs
+38
-0
未找到文件。
src/librustc/middle/trans/base.rs
浏览文件 @
1dbc467f
...
...
@@ -1121,13 +1121,13 @@ pub fn do_spill_noroot(cx: @mut Block, v: ValueRef) -> ValueRef {
pub
fn
spill_if_immediate
(
cx
:
@
mut
Block
,
v
:
ValueRef
,
t
:
ty
::
t
)
->
ValueRef
{
let
_
icx
=
push_ctxt
(
"spill_if_immediate"
);
if
ty
::
ty
pe_is_immediate
(
cx
.tcx
(),
t
)
{
return
do_spill
(
cx
,
v
,
t
);
}
if
type_is_immediate
(
cx
.tcx
(),
t
)
{
return
do_spill
(
cx
,
v
,
t
);
}
return
v
;
}
pub
fn
load_if_immediate
(
cx
:
@
mut
Block
,
v
:
ValueRef
,
t
:
ty
::
t
)
->
ValueRef
{
let
_
icx
=
push_ctxt
(
"load_if_immediate"
);
if
ty
::
ty
pe_is_immediate
(
cx
.tcx
(),
t
)
{
return
Load
(
cx
,
v
);
}
if
type_is_immediate
(
cx
.tcx
(),
t
)
{
return
Load
(
cx
,
v
);
}
return
v
;
}
...
...
src/librustc/middle/trans/common.rs
浏览文件 @
1dbc467f
...
...
@@ -15,7 +15,7 @@
use
driver
::
session
::
Session
;
use
lib
::
llvm
::{
ValueRef
,
BasicBlockRef
,
BuilderRef
};
use
lib
::
llvm
::{
True
,
False
,
Bool
};
use
lib
::
llvm
::
{
llvm
}
;
use
lib
::
llvm
::
llvm
;
use
lib
;
use
middle
::
lang_items
::
LangItem
;
use
middle
::
trans
::
base
;
...
...
@@ -28,17 +28,17 @@
use
middle
::
ty
;
use
middle
::
typeck
;
use
middle
::
borrowck
::
root_map_key
;
use
util
::
ppaux
::
{
Repr
}
;
use
util
::
ppaux
::
Repr
;
use
middle
::
trans
::
type_
::
Type
;
use
std
::
c_str
::
ToCStr
;
use
std
::
cast
::
transmute
;
use
std
::
cast
;
use
std
::
hashmap
::
{
HashMap
}
;
use
std
::
hashmap
::
HashMap
;
use
std
::
libc
::{
c_uint
,
c_longlong
,
c_ulonglong
,
c_char
};
use
std
::
vec
;
use
syntax
::
ast
::{
Name
,
Ident
};
use
syntax
::
ast
::{
Name
,
Ident
};
use
syntax
::
ast_map
::{
path
,
path_elt
,
path_pretty_name
};
use
syntax
::
codemap
::
Span
;
use
syntax
::
parse
::
token
;
...
...
@@ -46,6 +46,25 @@
pub
use
middle
::
trans
::
context
::
CrateContext
;
fn
type_is_newtype_immediate
(
cx
:
ty
::
ctxt
,
ty
:
ty
::
t
)
->
bool
{
match
ty
::
get
(
ty
)
.sty
{
ty
::
ty_struct
(
def_id
,
ref
substs
)
=>
{
let
fields
=
ty
::
struct_fields
(
cx
,
def_id
,
substs
);
fields
.len
()
==
1
&&
fields
[
0
]
.ident.name
==
token
::
special_idents
::
unnamed_field
.name
&&
type_is_immediate
(
cx
,
fields
[
0
]
.mt.ty
)
}
_
=>
false
}
}
pub
fn
type_is_immediate
(
cx
:
ty
::
ctxt
,
ty
:
ty
::
t
)
->
bool
{
ty
::
type_is_scalar
(
ty
)
||
ty
::
type_is_boxed
(
ty
)
||
ty
::
type_is_unique
(
ty
)
||
ty
::
type_is_region_ptr
(
ty
)
||
type_is_newtype_immediate
(
cx
,
ty
)
||
ty
::
type_is_simd
(
cx
,
ty
)
}
pub
fn
gensym_name
(
name
:
&
str
)
->
(
Ident
,
path_elt
)
{
let
name
=
token
::
gensym
(
name
);
let
ident
=
Ident
::
new
(
name
);
...
...
src/librustc/middle/trans/datum.rs
浏览文件 @
1dbc467f
...
...
@@ -197,7 +197,7 @@ pub fn appropriate_mode(tcx: ty::ctxt, ty: ty::t) -> DatumMode {
if
ty
::
type_is_voidish
(
ty
)
{
ByValue
}
else
if
ty
::
ty
pe_is_immediate
(
tcx
,
ty
)
{
}
else
if
type_is_immediate
(
tcx
,
ty
)
{
ByValue
}
else
{
ByRef
(
RevokeClean
)
...
...
@@ -667,7 +667,7 @@ pub fn try_deref(&self,
ByValue
=>
{
// Actually, this case cannot happen right
// now, because enums are never immediate.
assert
!
(
ty
::
ty
pe_is_immediate
(
bcx
.tcx
(),
ty
));
assert
!
(
type_is_immediate
(
bcx
.tcx
(),
ty
));
(
Some
(
Datum
{
ty
:
ty
,
..*
self
}),
bcx
)
}
};
...
...
@@ -699,7 +699,7 @@ pub fn try_deref(&self,
)
}
ByValue
=>
{
assert
!
(
ty
::
ty
pe_is_immediate
(
bcx
.tcx
(),
ty
));
assert
!
(
type_is_immediate
(
bcx
.tcx
(),
ty
));
(
Some
(
Datum
{
val
:
ExtractValue
(
bcx
,
self
.val
,
0
),
...
...
src/librustc/middle/trans/glue.rs
浏览文件 @
1dbc467f
...
...
@@ -77,19 +77,9 @@ pub fn drop_ty(cx: @mut Block, v: ValueRef, t: ty::t) -> @mut Block {
pub
fn
drop_ty_immediate
(
bcx
:
@
mut
Block
,
v
:
ValueRef
,
t
:
ty
::
t
)
->
@
mut
Block
{
let
_
icx
=
push_ctxt
(
"drop_ty_immediate"
);
match
ty
::
get
(
t
)
.sty
{
ty
::
ty_uniq
(
_
)
|
ty
::
ty_evec
(
_
,
ty
::
vstore_uniq
)
|
ty
::
ty_estr
(
ty
::
vstore_uniq
)
=>
{
free_ty_immediate
(
bcx
,
v
,
t
)
}
ty
::
ty_box
(
_
)
|
ty
::
ty_opaque_box
|
ty
::
ty_evec
(
_
,
ty
::
vstore_box
)
|
ty
::
ty_estr
(
ty
::
vstore_box
)
=>
{
decr_refcnt_maybe_free
(
bcx
,
v
,
None
,
t
)
}
_
=>
bcx
.tcx
()
.sess
.bug
(
"drop_ty_immediate: non-box ty"
)
}
let
vp
=
alloca
(
bcx
,
type_of
(
bcx
.ccx
(),
t
),
""
);
Store
(
bcx
,
v
,
vp
);
drop_ty
(
bcx
,
vp
,
t
)
}
pub
fn
free_ty
(
cx
:
@
mut
Block
,
v
:
ValueRef
,
t
:
ty
::
t
)
->
@
mut
Block
{
...
...
src/librustc/middle/trans/intrinsic.rs
浏览文件 @
1dbc467f
...
...
@@ -278,7 +278,7 @@ fn count_zeros_intrinsic(bcx: @mut Block, name: &'static str) {
"uninit"
=>
{
// Do nothing, this is effectively a no-op
let
retty
=
substs
.tys
[
0
];
if
ty
::
ty
pe_is_immediate
(
ccx
.tcx
,
retty
)
&&
!
ty
::
type_is_nil
(
retty
)
{
if
type_is_immediate
(
ccx
.tcx
,
retty
)
&&
!
ty
::
type_is_nil
(
retty
)
{
unsafe
{
Ret
(
bcx
,
lib
::
llvm
::
llvm
::
LLVMGetUndef
(
type_of
(
ccx
,
retty
)
.to_ref
()));
}
...
...
@@ -316,7 +316,7 @@ fn count_zeros_intrinsic(bcx: @mut Block, name: &'static str) {
if
!
ty
::
type_is_voidish
(
out_type
)
{
let
llsrcval
=
get_param
(
decl
,
first_real_arg
);
if
ty
::
ty
pe_is_immediate
(
ccx
.tcx
,
in_type
)
{
if
type_is_immediate
(
ccx
.tcx
,
in_type
)
{
match
fcx
.llretptr
{
Some
(
llretptr
)
=>
{
Store
(
bcx
,
llsrcval
,
PointerCast
(
bcx
,
llretptr
,
llintype
.ptr_to
()));
...
...
@@ -335,7 +335,7 @@ fn count_zeros_intrinsic(bcx: @mut Block, name: &'static str) {
}
}
}
}
else
if
ty
::
ty
pe_is_immediate
(
ccx
.tcx
,
out_type
)
{
}
else
if
type_is_immediate
(
ccx
.tcx
,
out_type
)
{
let
llsrcptr
=
PointerCast
(
bcx
,
llsrcval
,
llouttype
.ptr_to
());
let
ll_load
=
Load
(
bcx
,
llsrcptr
);
Ret
(
bcx
,
ll_load
);
...
...
src/librustc/middle/trans/type_of.rs
浏览文件 @
1dbc467f
...
...
@@ -21,11 +21,11 @@
use
syntax
::
opt_vec
;
pub
fn
arg_is_indirect
(
ccx
:
&
CrateContext
,
arg_ty
:
ty
::
t
)
->
bool
{
!
ty
::
ty
pe_is_immediate
(
ccx
.tcx
,
arg_ty
)
!
type_is_immediate
(
ccx
.tcx
,
arg_ty
)
}
pub
fn
return_uses_outptr
(
tcx
:
ty
::
ctxt
,
ty
:
ty
::
t
)
->
bool
{
!
ty
::
ty
pe_is_immediate
(
tcx
,
ty
)
!
type_is_immediate
(
tcx
,
ty
)
}
pub
fn
type_of_explicit_arg
(
ccx
:
&
mut
CrateContext
,
arg_ty
:
ty
::
t
)
->
Type
{
...
...
src/librustc/middle/ty.rs
浏览文件 @
1dbc467f
...
...
@@ -1752,25 +1752,6 @@ pub fn type_is_scalar(ty: t) -> bool {
}
}
fn
type_is_newtype_immediate
(
cx
:
ctxt
,
ty
:
t
)
->
bool
{
match
get
(
ty
)
.sty
{
ty_struct
(
def_id
,
ref
substs
)
=>
{
let
fields
=
struct_fields
(
cx
,
def_id
,
substs
);
fields
.len
()
==
1
&&
fields
[
0
]
.ident.name
==
token
::
special_idents
::
unnamed_field
.name
&&
type_is_immediate
(
cx
,
fields
[
0
]
.mt.ty
)
}
_
=>
false
}
}
pub
fn
type_is_immediate
(
cx
:
ctxt
,
ty
:
t
)
->
bool
{
return
type_is_scalar
(
ty
)
||
type_is_boxed
(
ty
)
||
type_is_unique
(
ty
)
||
type_is_region_ptr
(
ty
)
||
type_is_newtype_immediate
(
cx
,
ty
)
||
type_is_simd
(
cx
,
ty
);
}
pub
fn
type_needs_drop
(
cx
:
ctxt
,
ty
:
t
)
->
bool
{
type_contents
(
cx
,
ty
)
.needs_drop
(
cx
)
}
...
...
@@ -2538,6 +2519,13 @@ pub fn type_structurally_contains_uniques(cx: ctxt, ty: t) -> bool {
});
}
pub
fn
type_is_trait
(
ty
:
t
)
->
bool
{
match
get
(
ty
)
.sty
{
ty_trait
(
*
)
=>
true
,
_
=>
false
}
}
pub
fn
type_is_integral
(
ty
:
t
)
->
bool
{
match
get
(
ty
)
.sty
{
ty_infer
(
IntVar
(
_
))
|
ty_int
(
_
)
|
ty_uint
(
_
)
=>
true
,
...
...
@@ -3289,10 +3277,10 @@ pub fn expr_kind(tcx: ctxt,
ast
::
ExprCast
(
*
)
=>
{
match
tcx
.node_types
.find
(
&
(
expr
.id
as
uint
))
{
Some
(
&
t
)
=>
{
if
ty
::
type_is_immediate
(
tcx
,
t
)
{
RvalueDatumExpr
}
else
{
if
type_is_trait
(
t
)
{
RvalueDpsExpr
}
else
{
RvalueDatumExpr
}
}
None
=>
{
...
...
src/test/run-pass/issue-9446.rs
0 → 100644
浏览文件 @
1dbc467f
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct
Wrapper
(
~
str
);
impl
Wrapper
{
pub
fn
new
(
wrapped
:
~
str
)
->
Wrapper
{
Wrapper
(
wrapped
)
}
pub
fn
say_hi
(
&
self
)
{
println
(
fmt!
(
"hello %s"
,
**
self
));
}
}
impl
Drop
for
Wrapper
{
fn
drop
(
&
mut
self
)
{}
}
pub
fn
main
()
{
{
// This runs without complaint.
let
x
=
Wrapper
::
new
(
~
"Bob"
);
x
.say_hi
();
}
{
// This fails to compile, circa 0.8-89-gc635fba.
// error: internal compiler error: drop_ty_immediate: non-box ty
Wrapper
::
new
(
~
"Bob"
)
.say_hi
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录