Skip to content

Commit ab5472a

Browse files
committed
auto merge of #5307 : nikomatsakis/rust/remove-by-val, r=nikomatsakis
This is done in two steps: First, we make foreign functions not consider modes at all. This is because previously ++ mode was the only way to pass structs to foreign functions and so forth. We also add a lint mode warning if you use `&&` mode in a foreign function, since the semantics of that change (it used to pass a pointer to the C function, now it doesn't). Then, we remove by value and make it equivalent to `+` mode. At the same time, we stop parsing `-` mode and convert all uses of it to `+` mode (it was already being parsed to `+` mode anyhow). This obsoletes pull request #5298. r? @brson
2 parents 67b0f3d + 852619d commit ab5472a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+579
-303
lines changed

src/libcore/cast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub mod rusti {
1212
#[abi = "rust-intrinsic"]
1313
#[link_name = "rusti"]
1414
pub extern {
15-
fn forget<T>(-x: T);
15+
fn forget<T>(+x: T);
1616
fn reinterpret_cast<T, U>(&&e: T) -> U;
1717
}
1818
}

src/libcore/rt/thread.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct Thread {
2222
impl Thread {
2323
static fn start(main: ~fn()) -> Thread {
2424
fn substart(main: &fn()) -> *raw_thread {
25-
unsafe { rust_raw_thread_start(main) }
25+
unsafe { rust_raw_thread_start(&main) }
2626
}
2727
let raw = substart(main);
2828
Thread {
@@ -39,6 +39,6 @@ impl Drop for Thread {
3939
}
4040

4141
extern {
42-
pub unsafe fn rust_raw_thread_start(f: &fn()) -> *raw_thread;
42+
pub unsafe fn rust_raw_thread_start(f: &(&fn())) -> *raw_thread;
4343
pub unsafe fn rust_raw_thread_join_delete(thread: *raw_thread);
4444
}

src/libcore/unstable.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ mod rustrt {
4747
pub unsafe fn rust_lock_little_lock(lock: rust_little_lock);
4848
pub unsafe fn rust_unlock_little_lock(lock: rust_little_lock);
4949

50-
pub unsafe fn rust_raw_thread_start(f: &fn()) -> *raw_thread;
50+
pub unsafe fn rust_raw_thread_start(f: &(&fn())) -> *raw_thread;
5151
pub unsafe fn rust_raw_thread_join_delete(thread: *raw_thread);
5252
}
5353
}
@@ -72,7 +72,7 @@ pub fn run_in_bare_thread(f: ~fn()) {
7272
let closure: &fn() = || {
7373
f()
7474
};
75-
let thread = rustrt::rust_raw_thread_start(closure);
75+
let thread = rustrt::rust_raw_thread_start(&closure);
7676
rustrt::rust_raw_thread_join_delete(thread);
7777
chan.send(());
7878
}

src/libcore/unstable/intrinsics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ pub extern {
3434

3535
pub fn size_of<T>() -> uint;
3636

37-
pub fn move_val<T>(dst: &mut T, -src: T);
38-
pub fn move_val_init<T>(dst: &mut T, -src: T);
37+
pub fn move_val<T>(dst: &mut T, +src: T);
38+
pub fn move_val_init<T>(dst: &mut T, +src: T);
3939

4040
pub fn min_align_of<T>() -> uint;
4141
pub fn pref_align_of<T>() -> uint;

src/librustc/back/link.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ pub fn build_link_meta(sess: Session, c: &ast::crate, output: &Path,
486486

487487
// This calculates CMH as defined above
488488
fn crate_meta_extras_hash(symbol_hasher: &hash::State,
489-
-cmh_items: ~[@ast::meta_item],
489+
+cmh_items: ~[@ast::meta_item],
490490
dep_hashes: ~[~str]) -> @str {
491491
fn len_and_str(s: &str) -> ~str {
492492
fmt!("%u_%s", s.len(), s)
@@ -535,7 +535,7 @@ pub fn build_link_meta(sess: Session, c: &ast::crate, output: &Path,
535535
name, default));
536536
}
537537

538-
fn crate_meta_name(sess: Session, output: &Path, -opt_name: Option<@str>)
538+
fn crate_meta_name(sess: Session, output: &Path, +opt_name: Option<@str>)
539539
-> @str {
540540
return match opt_name {
541541
Some(v) => v,

src/librustc/driver/driver.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ pub fn pretty_print_input(sess: Session, +cfg: ast::crate_cfg, input: input,
440440
}
441441
}
442442
443-
pub fn get_os(triple: ~str) -> Option<session::os> {
443+
pub fn get_os(triple: &str) -> Option<session::os> {
444444
if str::contains(triple, ~"win32") ||
445445
str::contains(triple, ~"mingw32") {
446446
Some(session::os_win32)
@@ -455,7 +455,7 @@ pub fn get_os(triple: ~str) -> Option<session::os> {
455455
} else { None }
456456
}
457457

458-
pub fn get_arch(triple: ~str) -> Option<session::arch> {
458+
pub fn get_arch(triple: &str) -> Option<session::arch> {
459459
if str::contains(triple, ~"i386") ||
460460
str::contains(triple, ~"i486") ||
461461
str::contains(triple, ~"i586") ||

src/librustc/lib/llvm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,7 @@ pub mod llvm {
14431443
/** Prepares inline assembly. */
14441444
pub unsafe fn LLVMInlineAsm(Ty: TypeRef, AsmString: *c_char,
14451445
Constraints: *c_char, SideEffects: Bool,
1446-
AlignStack: Bool, Dialect: AsmDialect)
1446+
AlignStack: Bool, Dialect: c_uint)
14471447
-> ValueRef;
14481448
}
14491449
}

src/librustc/metadata/creader.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ fn metas_with_ident(ident: @~str, +metas: ~[@ast::meta_item])
222222
metas_with(ident, @~"name", metas)
223223
}
224224

225-
fn existing_match(e: @mut Env, metas: ~[@ast::meta_item], hash: @~str)
225+
fn existing_match(e: @mut Env, metas: &[@ast::meta_item], hash: @~str)
226226
-> Option<int> {
227227
for e.crate_cache.each |c| {
228228
if loader::metadata_matches(*c.metas, metas)

src/librustc/metadata/decoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ pub fn maybe_get_item_ast(intr: @ident_interner, cdata: cmd, tcx: ty::ctxt,
560560
let item_path = item_path(intr, item_doc);
561561
vec::from_slice(item_path.init())
562562
};
563-
match decode_inlined_item(cdata, tcx, path, item_doc) {
563+
match decode_inlined_item(cdata, tcx, copy path, item_doc) {
564564
Some(ref ii) => csearch::found((/*bad*/copy *ii)),
565565
None => {
566566
match item_parent_item(item_doc) {

src/librustc/metadata/loader.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ fn crate_matches(crate_data: @~[u8],
176176
metadata_matches(linkage_metas, metas)
177177
}
178178
179-
pub fn metadata_matches(extern_metas: ~[@ast::meta_item],
179+
pub fn metadata_matches(extern_metas: &[@ast::meta_item],
180180
local_metas: &[@ast::meta_item]) -> bool {
181181
182182
debug!("matching %u metadata requirements against %u items",

src/librustc/metadata/tydecode.rs

-1
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,6 @@ fn parse_mode(st: @mut PState) -> ast::mode {
427427
let m = ast::expl(match next(st) {
428428
'+' => ast::by_copy,
429429
'=' => ast::by_ref,
430-
'#' => ast::by_val,
431430
_ => fail!(~"bad mode")
432431
});
433432
return m;

src/librustc/metadata/tyencode.rs

-1
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,6 @@ pub fn enc_mode(w: io::Writer, cx: @ctxt, m: mode) {
342342
match ty::resolved_mode(cx.tcx, m) {
343343
by_copy => w.write_char('+'),
344344
by_ref => w.write_char('='),
345-
by_val => w.write_char('#')
346345
}
347346
}
348347

src/librustc/middle/astencode.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub fn encode_inlined_item(ecx: @e::EncodeContext,
105105
pub fn decode_inlined_item(cdata: @cstore::crate_metadata,
106106
tcx: ty::ctxt,
107107
maps: Maps,
108-
path: ast_map::path,
108+
+path: ast_map::path,
109109
par_doc: ebml::Doc)
110110
-> Option<ast::inlined_item> {
111111
let dcx = @DecodeContext {

src/librustc/middle/borrowck/gather_loans.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ fn req_loans_in_expr(ex: @ast::expr,
156156
let arg_cmt = self.bccx.cat_expr(*arg);
157157
self.guarantee_valid(arg_cmt, m_imm, scope_r);
158158
}
159-
ast::by_val | ast::by_copy => {}
159+
ast::by_copy => {}
160160
}
161161
}
162162
visit::visit_expr(ex, self, vt);
@@ -172,7 +172,7 @@ fn req_loans_in_expr(ex: @ast::expr,
172172
let arg_cmt = self.bccx.cat_expr(*arg);
173173
self.guarantee_valid(arg_cmt, m_imm, scope_r);
174174
}
175-
ast::by_val | ast::by_copy => {}
175+
ast::by_copy => {}
176176
}
177177
}
178178

src/librustc/middle/lint.rs

+23-1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ pub enum lint {
7878
deprecated_self,
7979
deprecated_mutable_fields,
8080
deprecated_drop,
81+
foreign_mode,
8182

8283
managed_heap_memory,
8384
owned_heap_memory,
@@ -182,6 +183,13 @@ pub fn get_lint_dict() -> LintDict {
182183
default: warn
183184
}),
184185

186+
(@~"foreign_mode",
187+
@LintSpec {
188+
lint: foreign_mode,
189+
desc: "warn about deprecated uses of modes in foreign fns",
190+
default: warn
191+
}),
192+
185193
(@~"deprecated_pattern",
186194
@LintSpec {
187195
lint: deprecated_pattern,
@@ -753,6 +761,20 @@ fn check_item_ctypes(cx: ty::ctxt, it: @ast::item) {
753761

754762
fn check_foreign_fn(cx: ty::ctxt, fn_id: ast::node_id,
755763
decl: &ast::fn_decl) {
764+
// warn about `&&` mode on foreign functions, both because it is
765+
// deprecated and because its semantics have changed recently:
766+
for decl.inputs.eachi |i, arg| {
767+
match ty::resolved_mode(cx, arg.mode) {
768+
ast::by_copy => {}
769+
ast::by_ref => {
770+
cx.sess.span_lint(
771+
foreign_mode, fn_id, fn_id, arg.ty.span,
772+
fmt!("foreign function uses `&&` mode \
773+
on argument %u", i));
774+
}
775+
}
776+
}
777+
756778
let tys = vec::map(decl.inputs, |a| a.ty );
757779
for vec::each(vec::append_one(tys, decl.output)) |ty| {
758780
match ty.node {
@@ -785,7 +807,7 @@ fn check_item_ctypes(cx: ty::ctxt, it: @ast::item) {
785807
if attr::foreign_abi(it.attrs) !=
786808
either::Right(ast::foreign_abi_rust_intrinsic) => {
787809
for nmod.items.each |ni| {
788-
match /*bad*/copy ni.node {
810+
match ni.node {
789811
ast::foreign_item_fn(ref decl, _, _) => {
790812
check_foreign_fn(cx, it.id, decl);
791813
}

src/librustc/middle/liveness.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ pub impl IrMaps {
427427
v.push(id);
428428
}
429429
Arg(_, _, by_ref) |
430-
Arg(_, _, by_val) | ImplicitRet => {
430+
ImplicitRet => {
431431
debug!("--but it is not owned");
432432
}
433433
}
@@ -1006,7 +1006,7 @@ pub impl Liveness {
10061006
// inputs passed by & mode should be considered live on exit:
10071007
for decl.inputs.each |arg| {
10081008
match ty::resolved_mode(self.tcx, arg.mode) {
1009-
by_val | by_ref => {
1009+
by_ref => {
10101010
// By val and by ref do not own, so register a
10111011
// read at the end. This will prevent us from
10121012
// moving out of such variables but also prevent

src/librustc/middle/mem_categorization.rs

-8
Original file line numberDiff line numberDiff line change
@@ -486,14 +486,6 @@ pub impl mem_categorization_ctxt {
486486
let lp = match ty::resolved_mode(self.tcx, mode) {
487487
ast::by_copy => Some(@lp_arg(vid)),
488488
ast::by_ref => None,
489-
ast::by_val => {
490-
// by-value is this hybrid mode where we have a
491-
// pointer but we do not own it. This is not
492-
// considered loanable because, for example, a by-ref
493-
// and and by-val argument might both actually contain
494-
// the same unique ptr.
495-
None
496-
}
497489
};
498490
@cmt_ {
499491
id:id,

src/librustc/middle/moves.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ pub impl VisitContext {
782782
*/
783783

784784
match arg_mode {
785-
by_val | by_ref => self.use_expr(arg_expr, Read, visitor),
785+
by_ref => self.use_expr(arg_expr, Read, visitor),
786786
by_copy => self.consume_expr(arg_expr, visitor)
787787
}
788788
}

src/librustc/middle/resolve.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -2021,7 +2021,7 @@ pub impl Resolver {
20212021
}
20222022
20232023
fn import_path_to_str(@mut self,
2024-
idents: ~[ident],
2024+
idents: &[ident],
20252025
subclass: ImportDirectiveSubclass)
20262026
-> @~str {
20272027
if idents.is_empty() {
@@ -2573,7 +2573,7 @@ pub impl Resolver {
25732573
/// Resolves the given module path from the given root `module_`.
25742574
fn resolve_module_path_from_root(@mut self,
25752575
module_: @mut Module,
2576-
module_path: ~[ident],
2576+
module_path: &[ident],
25772577
index: uint,
25782578
span: span,
25792579
mut name_search_type: NameSearchType)
@@ -2658,7 +2658,7 @@ pub impl Resolver {
26582658
/// rooted at the given module.
26592659
fn resolve_module_path_for_import(@mut self,
26602660
module_: @mut Module,
2661-
module_path: ~[ident],
2661+
module_path: &[ident],
26622662
use_lexical_scope: UseLexicalScopeFlag,
26632663
span: span)
26642664
-> ResolveResult<@mut Module> {
@@ -2944,7 +2944,7 @@ pub impl Resolver {
29442944
*/
29452945
fn resolve_module_prefix(@mut self,
29462946
module_: @mut Module,
2947-
module_path: ~[ident])
2947+
module_path: &[ident])
29482948
-> ResolveResult<ModulePrefixResult> {
29492949
let interner = self.session.parse_sess.interner;
29502950

@@ -3876,7 +3876,7 @@ pub impl Resolver {
38763876
generics: &Generics,
38773877
opt_trait_reference: Option<@trait_ref>,
38783878
self_type: @Ty,
3879-
methods: ~[@method],
3879+
methods: &[@method],
38803880
visitor: ResolveVisitor) {
38813881
// If applicable, create a rib for the type parameters.
38823882
let outer_type_parameter_count = generics.ty_params.len();

src/librustc/middle/trans/_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ pub fn enter_rec_or_struct(bcx: block,
599599
dm: DefMap,
600600
m: &[@Match/&r],
601601
col: uint,
602-
fields: ~[ast::ident],
602+
fields: &[ast::ident],
603603
val: ValueRef)
604604
-> ~[@Match/&r] {
605605
debug!("enter_rec_or_struct(bcx=%s, m=%s, col=%u, val=%?)",

src/librustc/middle/trans/base.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -1682,12 +1682,6 @@ pub fn copy_args_to_allocas(fcx: fn_ctxt,
16821682

16831683
add_clean(bcx, llarg, arg_ty.ty);
16841684
}
1685-
ast::by_val => {
1686-
// always by value, also not owned, so don't add a cleanup:
1687-
let alloc = alloc_ty(bcx, arg_ty.ty);
1688-
Store(bcx, raw_llarg, alloc);
1689-
llarg = alloc;
1690-
}
16911685
}
16921686

16931687
bcx = _match::bind_irrefutable_pat(bcx,
@@ -1812,7 +1806,7 @@ pub fn trans_fn(ccx: @CrateContext,
18121806
debug!("trans_fn(ty_self=%?)", ty_self);
18131807
let _icx = ccx.insn_ctxt("trans_fn");
18141808
ccx.stats.n_fns += 1;
1815-
let the_path_str = path_str(ccx.sess, &path);
1809+
let the_path_str = path_str(ccx.sess, path);
18161810
trans_closure(ccx, path, decl, body, llfndecl, ty_self,
18171811
param_substs, id, impl_id,
18181812
|fcx| {

src/librustc/middle/trans/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ pub fn InlineAsmCall(cx: block, asm: *c_char, cons: *c_char,
885885
886886
let llfty = T_fn(~[], T_void());
887887
let v = llvm::LLVMInlineAsm(llfty, asm, cons, volatile,
888-
alignstack, dia);
888+
alignstack, dia as c_uint);
889889
890890
Call(cx, v, ~[])
891891
}

src/librustc/middle/trans/callee.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -720,14 +720,6 @@ pub fn trans_arg_expr(bcx: block,
720720
val = arg_datum.to_ref_llval(bcx);
721721
}
722722

723-
ast::by_val => {
724-
// NB: avoid running the take glue.
725-
726-
fail_unless!(!bcx.ccx().maps.moves_map.contains_key(
727-
&arg_expr.id));
728-
val = arg_datum.to_value_llval(bcx);
729-
}
730-
731723
ast::by_copy => {
732724
debug!("by copy arg with type %s, storing to scratch",
733725
bcx.ty_to_str(arg_datum.ty));
@@ -757,7 +749,7 @@ pub fn trans_arg_expr(bcx: block,
757749

758750
if formal_ty.ty != arg_datum.ty {
759751
// this could happen due to e.g. subtyping
760-
let llformal_ty = type_of::type_of_explicit_arg(ccx, formal_ty);
752+
let llformal_ty = type_of::type_of_explicit_arg(ccx, &formal_ty);
761753
debug!("casting actual type (%s) to match formal (%s)",
762754
bcx.val_str(val), bcx.llty_str(llformal_ty));
763755
val = PointerCast(bcx, val, llformal_ty);

0 commit comments

Comments
 (0)