Skip to content

Commit facb02e

Browse files
committed
---
yaml --- r: 128629 b: refs/heads/try c: 1fcc4f9 h: refs/heads/master i: 128627: d8f82e8 v: v3
1 parent 5fc0c10 commit facb02e

File tree

18 files changed

+65
-305
lines changed

18 files changed

+65
-305
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 07d86b46a949a94223da714e35b343243e4ecce4
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: a86d9ad15e339ab343a12513f9c90556f677b9ca
5-
refs/heads/try: 50834e7de42b3e153a2203467d9589ae063fb63f
5+
refs/heads/try: 1fcc4f9c5fcebc932d9ee11766ed7fac8a9517f4
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/doc/tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ OS X, the install page provides links to native installers.
7676
> the precise details of which are not discussed here.
7777
7878
For Linux and OS X, the install page provides links to binary tarballs.
79-
To install the Rust compiler from a binary tarball, download
79+
To install the Rust compiler from the from a binary tarball, download
8080
the binary package, extract it, and execute the `install.sh` script in
8181
the root directory of the package.
8282

branches/try/src/librustc/metadata/encoder.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,8 +1755,7 @@ fn encode_reachable_extern_fns(ecx: &EncodeContext, rbml_w: &mut Encoder) {
17551755
match ecx.tcx.map.find(*id) {
17561756
Some(ast_map::NodeItem(i)) => {
17571757
match i.node {
1758-
ast::ItemFn(_, _, abi, ref generics, _)
1759-
if abi != abi::Rust && !generics.is_type_parameterized() => {
1758+
ast::ItemFn(_, _, abi, _, _) if abi != abi::Rust => {
17601759
rbml_w.wr_tagged_u32(tag_reachable_extern_fn_id, *id);
17611760
}
17621761
_ => {}

branches/try/src/librustc/middle/trans/base.rs

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl<'a> Drop for StatRecorder<'a> {
171171
}
172172

173173
// only use this for foreign function ABIs and glue, use `decl_rust_fn` for Rust functions
174-
pub fn decl_fn(ccx: &CrateContext, name: &str, cc: llvm::CallConv,
174+
fn decl_fn(ccx: &CrateContext, name: &str, cc: llvm::CallConv,
175175
ty: Type, output: ty::t) -> ValueRef {
176176

177177
let llfn: ValueRef = name.with_c_str(|buf| {
@@ -1922,27 +1922,20 @@ pub fn trans_item(ccx: &CrateContext, item: &ast::Item) {
19221922
let _icx = push_ctxt("trans_item");
19231923
match item.node {
19241924
ast::ItemFn(ref decl, _fn_style, abi, ref generics, ref body) => {
1925-
if !generics.is_type_parameterized() {
1925+
if abi != Rust {
1926+
let llfndecl = get_item_val(ccx, item.id);
1927+
foreign::trans_rust_fn_with_foreign_abi(
1928+
ccx, &**decl, &**body, item.attrs.as_slice(), llfndecl, item.id);
1929+
} else if !generics.is_type_parameterized() {
19261930
let llfn = get_item_val(ccx, item.id);
1927-
if abi != Rust {
1928-
foreign::trans_rust_fn_with_foreign_abi(ccx,
1929-
&**decl,
1930-
&**body,
1931-
item.attrs.as_slice(),
1932-
llfn,
1933-
&param_substs::empty(),
1934-
item.id,
1935-
None);
1936-
} else {
1937-
trans_fn(ccx,
1938-
&**decl,
1939-
&**body,
1940-
llfn,
1941-
&param_substs::empty(),
1942-
item.id,
1943-
item.attrs.as_slice(),
1944-
TranslateItems);
1945-
}
1931+
trans_fn(ccx,
1932+
&**decl,
1933+
&**body,
1934+
llfn,
1935+
&param_substs::empty(),
1936+
item.id,
1937+
item.attrs.as_slice(),
1938+
TranslateItems);
19461939
} else {
19471940
// Be sure to travel more than just one layer deep to catch nested
19481941
// items in blocks and such.

branches/try/src/librustc/middle/trans/foreign.rs

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -24,7 +24,6 @@ use middle::trans::type_of::*;
2424
use middle::trans::type_of;
2525
use middle::ty::FnSig;
2626
use middle::ty;
27-
use middle::subst::Subst;
2827
use std::cmp;
2928
use libc::c_uint;
3029
use syntax::abi::{Cdecl, Aapcs, C, Win64, Abi};
@@ -526,26 +525,6 @@ pub fn trans_foreign_mod(ccx: &CrateContext, foreign_mod: &ast::ForeignMod) {
526525
// inline the one into the other. Of course we could just generate the
527526
// correct code in the first place, but this is much simpler.
528527

529-
pub fn decl_rust_fn_with_foreign_abi(ccx: &CrateContext,
530-
t: ty::t,
531-
name: &str)
532-
-> ValueRef {
533-
let tys = foreign_types_for_fn_ty(ccx, t);
534-
let llfn_ty = lltype_for_fn_from_foreign_types(ccx, &tys);
535-
let cconv = match ty::get(t).sty {
536-
ty::ty_bare_fn(ref fn_ty) => {
537-
let c = llvm_calling_convention(ccx, fn_ty.abi);
538-
c.unwrap_or(llvm::CCallConv)
539-
}
540-
_ => fail!("expected bare fn in decl_rust_fn_with_foreign_abi")
541-
};
542-
let llfn = base::decl_fn(ccx, name, cconv, llfn_ty, ty::mk_nil());
543-
add_argument_attributes(&tys, llfn);
544-
debug!("decl_rust_fn_with_foreign_abi(llfn_ty={}, llfn={})",
545-
ccx.tn.type_to_string(llfn_ty), ccx.tn.val_to_string(llfn));
546-
llfn
547-
}
548-
549528
pub fn register_rust_fn_with_foreign_abi(ccx: &CrateContext,
550529
sp: Span,
551530
sym: String,
@@ -575,39 +554,31 @@ pub fn trans_rust_fn_with_foreign_abi(ccx: &CrateContext,
575554
body: &ast::Block,
576555
attrs: &[ast::Attribute],
577556
llwrapfn: ValueRef,
578-
param_substs: &param_substs,
579-
id: ast::NodeId,
580-
hash: Option<&str>) {
557+
id: ast::NodeId) {
581558
let _icx = push_ctxt("foreign::build_foreign_fn");
582-
583-
let fnty = ty::node_id_to_type(ccx.tcx(), id);
584-
let mty = fnty.subst(ccx.tcx(), &param_substs.substs);
585-
let tys = foreign_types_for_fn_ty(ccx, mty);
559+
let tys = foreign_types_for_id(ccx, id);
586560

587561
unsafe { // unsafe because we call LLVM operations
588562
// Build up the Rust function (`foo0` above).
589-
let llrustfn = build_rust_fn(ccx, decl, body, param_substs, attrs, id, hash);
563+
let llrustfn = build_rust_fn(ccx, decl, body, attrs, id);
590564

591565
// Build up the foreign wrapper (`foo` above).
592-
return build_wrap_fn(ccx, llrustfn, llwrapfn, &tys, mty);
566+
return build_wrap_fn(ccx, llrustfn, llwrapfn, &tys, id);
593567
}
594568

595569
fn build_rust_fn(ccx: &CrateContext,
596570
decl: &ast::FnDecl,
597571
body: &ast::Block,
598-
param_substs: &param_substs,
599572
attrs: &[ast::Attribute],
600-
id: ast::NodeId,
601-
hash: Option<&str>)
573+
id: ast::NodeId)
602574
-> ValueRef {
603575
let _icx = push_ctxt("foreign::foreign::build_rust_fn");
604576
let tcx = ccx.tcx();
605-
let t = ty::node_id_to_type(tcx, id).subst(
606-
ccx.tcx(), &param_substs.substs);
577+
let t = ty::node_id_to_type(tcx, id);
607578

608579
let ps = ccx.tcx.map.with_path(id, |path| {
609580
let abi = Some(ast_map::PathName(special_idents::clownshoe_abi.name));
610-
link::mangle(path.chain(abi.move_iter()), hash)
581+
link::mangle(path.chain(abi.move_iter()), None)
611582
});
612583

613584
// Compute the type that the function would have if it were just a
@@ -630,19 +601,22 @@ pub fn trans_rust_fn_with_foreign_abi(ccx: &CrateContext,
630601

631602
let llfn = base::decl_internal_rust_fn(ccx, t, ps.as_slice());
632603
base::set_llvm_fn_attrs(attrs, llfn);
633-
base::trans_fn(ccx, decl, body, llfn, param_substs, id, [], TranslateItems);
604+
base::trans_fn(ccx, decl, body, llfn, &param_substs::empty(), id, [],
605+
TranslateItems);
634606
llfn
635607
}
636608

637609
unsafe fn build_wrap_fn(ccx: &CrateContext,
638610
llrustfn: ValueRef,
639611
llwrapfn: ValueRef,
640612
tys: &ForeignTypes,
641-
t: ty::t) {
613+
id: ast::NodeId) {
642614
let _icx = push_ctxt(
643615
"foreign::trans_rust_fn_with_foreign_abi::build_wrap_fn");
644616
let tcx = ccx.tcx();
645617

618+
let t = ty::node_id_to_type(tcx, id);
619+
646620
debug!("build_wrap_fn(llrustfn={}, llwrapfn={}, t={})",
647621
ccx.tn.val_to_string(llrustfn),
648622
ccx.tn.val_to_string(llwrapfn),

branches/try/src/librustc/middle/trans/monomorphize.rs

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -18,7 +18,6 @@ use middle::trans::base::{trans_enum_variant, push_ctxt, get_item_val};
1818
use middle::trans::base::{trans_fn, decl_internal_rust_fn};
1919
use middle::trans::base;
2020
use middle::trans::common::*;
21-
use middle::trans::foreign;
2221
use middle::ty;
2322
use middle::typeck;
2423
use util::ppaux::Repr;
@@ -124,29 +123,19 @@ pub fn monomorphic_fn(ccx: &CrateContext,
124123
monomorphizing.insert(fn_id, depth + 1);
125124
}
126125

127-
let hash;
128-
let s = {
126+
let s = ccx.tcx.map.with_path(fn_id.node, |path| {
129127
let mut state = sip::SipState::new();
130128
hash_id.hash(&mut state);
131129
mono_ty.hash(&mut state);
132130

133-
hash = format!("h{}", state.result());
134-
ccx.tcx.map.with_path(fn_id.node, |path| {
135-
exported_name(path, hash.as_slice())
136-
})
137-
};
138-
131+
exported_name(path, format!("h{}", state.result()).as_slice())
132+
});
139133
debug!("monomorphize_fn mangled to {}", s);
140134

141135
// This shouldn't need to option dance.
142136
let mut hash_id = Some(hash_id);
143-
let mk_lldecl = |abi: abi::Abi| {
144-
let lldecl = if abi != abi::Rust {
145-
foreign::decl_rust_fn_with_foreign_abi(ccx, mono_ty, s.as_slice())
146-
} else {
147-
decl_internal_rust_fn(ccx, mono_ty, s.as_slice())
148-
};
149-
137+
let mk_lldecl = || {
138+
let lldecl = decl_internal_rust_fn(ccx, mono_ty, s.as_slice());
150139
ccx.monomorphized.borrow_mut().insert(hash_id.take_unwrap(), lldecl);
151140
lldecl
152141
};
@@ -155,21 +144,13 @@ pub fn monomorphic_fn(ccx: &CrateContext,
155144
ast_map::NodeItem(i) => {
156145
match *i {
157146
ast::Item {
158-
node: ast::ItemFn(ref decl, _, abi, _, ref body),
147+
node: ast::ItemFn(ref decl, _, _, _, ref body),
159148
..
160149
} => {
161-
let d = mk_lldecl(abi);
150+
let d = mk_lldecl();
162151
set_llvm_fn_attrs(i.attrs.as_slice(), d);
163-
164-
if abi != abi::Rust {
165-
foreign::trans_rust_fn_with_foreign_abi(
166-
ccx, &**decl, &**body, [], d, &psubsts, fn_id.node,
167-
Some(hash.as_slice()));
168-
} else {
169-
trans_fn(ccx, &**decl, &**body, d, &psubsts, fn_id.node, [],
170-
IgnoreItems);
171-
}
172-
152+
trans_fn(ccx, &**decl, &**body, d, &psubsts, fn_id.node, [],
153+
IgnoreItems);
173154
d
174155
}
175156
_ => {
@@ -181,7 +162,7 @@ pub fn monomorphic_fn(ccx: &CrateContext,
181162
let parent = ccx.tcx.map.get_parent(fn_id.node);
182163
let tvs = ty::enum_variants(ccx.tcx(), local_def(parent));
183164
let this_tv = tvs.iter().find(|tv| { tv.id.node == fn_id.node}).unwrap();
184-
let d = mk_lldecl(abi::Rust);
165+
let d = mk_lldecl();
185166
set_inline_hint(d);
186167
match v.node.kind {
187168
ast::TupleVariantKind(ref args) => {
@@ -199,7 +180,7 @@ pub fn monomorphic_fn(ccx: &CrateContext,
199180
d
200181
}
201182
ast_map::NodeMethod(mth) => {
202-
let d = mk_lldecl(abi::Rust);
183+
let d = mk_lldecl();
203184
set_llvm_fn_attrs(mth.attrs.as_slice(), d);
204185
trans_fn(ccx, &*mth.pe_fn_decl(), &*mth.pe_body(), d, &psubsts, mth.id, [],
205186
IgnoreItems);
@@ -208,7 +189,7 @@ pub fn monomorphic_fn(ccx: &CrateContext,
208189
ast_map::NodeTraitMethod(method) => {
209190
match *method {
210191
ast::Provided(mth) => {
211-
let d = mk_lldecl(abi::Rust);
192+
let d = mk_lldecl();
212193
set_llvm_fn_attrs(mth.attrs.as_slice(), d);
213194
trans_fn(ccx, &*mth.pe_fn_decl(), &*mth.pe_body(), d,
214195
&psubsts, mth.id, [], IgnoreItems);
@@ -221,7 +202,7 @@ pub fn monomorphic_fn(ccx: &CrateContext,
221202
}
222203
}
223204
ast_map::NodeStructCtor(struct_def) => {
224-
let d = mk_lldecl(abi::Rust);
205+
let d = mk_lldecl();
225206
set_inline_hint(d);
226207
base::trans_tuple_struct(ccx,
227208
struct_def.fields.as_slice(),
@@ -249,7 +230,7 @@ pub fn monomorphic_fn(ccx: &CrateContext,
249230
ccx.monomorphizing.borrow_mut().insert(fn_id, depth);
250231

251232
debug!("leaving monomorphic fn {}", ty::item_path_str(ccx.tcx(), fn_id));
252-
(lldecl, true)
233+
(lldecl, false)
253234
}
254235

255236
// Used to identify cached monomorphized functions and vtables

branches/try/src/librustc/middle/typeck/collect.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,17 @@ pub fn ensure_no_ty_param_bounds(ccx: &CrateCtxt,
444444
}
445445
}
446446

447+
fn ensure_generics_abi(ccx: &CrateCtxt,
448+
span: Span,
449+
abi: abi::Abi,
450+
generics: &ast::Generics) {
451+
if generics.ty_params.len() > 0 &&
452+
!(abi == abi::Rust || abi == abi::RustIntrinsic) {
453+
span_err!(ccx.tcx.sess, span, E0123,
454+
"foreign functions may not use type parameters");
455+
}
456+
}
457+
447458
pub fn convert(ccx: &CrateCtxt, it: &ast::Item) {
448459
let tcx = ccx.tcx;
449460
debug!("convert: item {} with id {}", token::get_ident(it.ident), it.id);
@@ -561,8 +572,13 @@ pub fn convert(ccx: &CrateCtxt, it: &ast::Item) {
561572
},
562573
ast::ItemTy(_, ref generics) => {
563574
ensure_no_ty_param_bounds(ccx, it.span, generics, "type");
564-
let tpt = ty_of_item(ccx, it);
565-
write_ty_to_tcx(tcx, it.id, tpt.ty);
575+
let pty = ty_of_item(ccx, it);
576+
write_ty_to_tcx(tcx, it.id, pty.ty);
577+
},
578+
ast::ItemFn(_, _, abi, ref generics, _) => {
579+
ensure_generics_abi(ccx, it.span, abi, generics);
580+
let pty = ty_of_item(ccx, it);
581+
write_ty_to_tcx(tcx, it.id, pty.ty);
566582
},
567583
_ => {
568584
// This call populates the type cache with the converted type

branches/try/src/test/compile-fail/generic-extern.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
extern {
12-
fn foo<T>(); //~ ERROR foreign items may not have type parameters
13-
}
11+
extern "C" fn foo<T>() {} //~ERROR foreign functions may not use type parameters
1412

1513
fn main() {
16-
foo::<i32>();
14+
let _ = foo::<int>;
1715
}

branches/try/src/test/compile-fail/generic-no-mangle.rs

Lines changed: 0 additions & 18 deletions
This file was deleted.

branches/try/src/test/run-make/extern-fn-generic/Makefile

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)