Skip to content

Commit 02a4b5b

Browse files
committed
Merge remote branch 'nmatsakis/issue-4808-representation-of-extern-fn' into incoming
2 parents 9519ee5 + febdb49 commit 02a4b5b

File tree

15 files changed

+311
-128
lines changed

15 files changed

+311
-128
lines changed

src/librustc/middle/astencode.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -451,9 +451,17 @@ impl tr for ast::def {
451451
452452
impl tr for ty::AutoAdjustment {
453453
fn tr(&self, xcx: @ExtendedDecodeContext) -> ty::AutoAdjustment {
454-
ty::AutoAdjustment {
455-
autoderefs: self.autoderefs,
456-
autoref: self.autoref.map(|ar| ar.tr(xcx)),
454+
match self {
455+
&ty::AutoAddEnv(r, s) => {
456+
ty::AutoAddEnv(r.tr(xcx), s)
457+
}
458+
459+
&ty::AutoDerefRef(ref adr) => {
460+
ty::AutoDerefRef(ty::AutoDerefRef {
461+
autoderefs: adr.autoderefs,
462+
autoref: adr.autoref.map(|ar| ar.tr(xcx)),
463+
})
464+
}
457465
}
458466
}
459467
}

src/librustc/middle/borrowck/gather_loans.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -299,17 +299,27 @@ pub impl GatherLoanCtxt {
299299
expr_repr(self.tcx(), expr), adjustment);
300300
let _i = indenter();
301301

302-
match adjustment.autoref {
303-
None => {
302+
match *adjustment {
303+
ty::AutoAddEnv(*) => {
304+
debug!("autoaddenv -- no autoref");
305+
return;
306+
}
307+
308+
ty::AutoDerefRef(
309+
ty::AutoDerefRef {
310+
autoref: None, _ }) => {
304311
debug!("no autoref");
305312
return;
306313
}
307314

308-
Some(ref autoref) => {
315+
ty::AutoDerefRef(
316+
ty::AutoDerefRef {
317+
autoref: Some(ref autoref),
318+
autoderefs: autoderefs}) => {
309319
let mcx = &mem_categorization_ctxt {
310320
tcx: self.tcx(),
311321
method_map: self.bccx.method_map};
312-
let mut cmt = mcx.cat_expr_autoderefd(expr, adjustment);
322+
let mut cmt = mcx.cat_expr_autoderefd(expr, autoderefs);
313323
debug!("after autoderef, cmt=%s", self.bccx.cmt_to_repr(cmt));
314324

315325
match autoref.kind {

src/librustc/middle/borrowck/mod.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -480,9 +480,20 @@ pub impl BorrowckCtxt {
480480
}
481481

482482
fn cat_expr_autoderefd(&self, expr: @ast::expr,
483-
adj: @ty::AutoAdjustment)
484-
-> cmt {
485-
cat_expr_autoderefd(self.tcx, self.method_map, expr, adj)
483+
adj: @ty::AutoAdjustment) -> cmt {
484+
match *adj {
485+
ty::AutoAddEnv(*) => {
486+
// no autoderefs
487+
cat_expr_unadjusted(self.tcx, self.method_map, expr)
488+
}
489+
490+
ty::AutoDerefRef(
491+
ty::AutoDerefRef {
492+
autoderefs: autoderefs, _}) => {
493+
cat_expr_autoderefd(self.tcx, self.method_map, expr,
494+
autoderefs)
495+
}
496+
}
486497
}
487498

488499
fn cat_def(&self,

src/librustc/middle/mem_categorization.rs

+28-18
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,12 @@ pub fn cat_expr_autoderefd(
241241
tcx: ty::ctxt,
242242
method_map: typeck::method_map,
243243
expr: @ast::expr,
244-
adj: @ty::AutoAdjustment) -> cmt {
245-
244+
autoderefs: uint) -> cmt
245+
{
246246
let mcx = &mem_categorization_ctxt {
247247
tcx: tcx, method_map: method_map
248248
};
249-
return mcx.cat_expr_autoderefd(expr, adj);
249+
return mcx.cat_expr_autoderefd(expr, autoderefs);
250250
}
251251

252252
pub fn cat_def(
@@ -361,28 +361,38 @@ pub impl mem_categorization_ctxt {
361361
self.cat_expr_unadjusted(expr)
362362
}
363363

364-
Some(adjustment) => {
365-
match adjustment.autoref {
366-
Some(_) => {
367-
// Equivalent to &*expr or something similar.
368-
// This is an rvalue, effectively.
369-
let expr_ty = ty::expr_ty(self.tcx, expr);
370-
self.cat_rvalue(expr, expr_ty)
371-
}
372-
None => {
373-
// Equivalent to *expr or something similar.
374-
self.cat_expr_autoderefd(expr, adjustment)
375-
}
376-
}
364+
Some(@ty::AutoAddEnv(*)) => {
365+
// Convert a bare fn to a closure by adding NULL env.
366+
// Result is an rvalue.
367+
let expr_ty = ty::expr_ty_adjusted(self.tcx, expr);
368+
self.cat_rvalue(expr, expr_ty)
369+
}
370+
371+
Some(
372+
@ty::AutoDerefRef(
373+
ty::AutoDerefRef {
374+
autoref: Some(_), _})) => {
375+
// Equivalent to &*expr or something similar.
376+
// Result is an rvalue.
377+
let expr_ty = ty::expr_ty_adjusted(self.tcx, expr);
378+
self.cat_rvalue(expr, expr_ty)
379+
}
380+
381+
Some(
382+
@ty::AutoDerefRef(
383+
ty::AutoDerefRef {
384+
autoref: None, autoderefs: autoderefs})) => {
385+
// Equivalent to *expr or something similar.
386+
self.cat_expr_autoderefd(expr, autoderefs)
377387
}
378388
}
379389
}
380390

381391
fn cat_expr_autoderefd(&self,
382392
expr: @ast::expr,
383-
adjustment: &ty::AutoAdjustment) -> cmt {
393+
autoderefs: uint) -> cmt {
384394
let mut cmt = self.cat_expr_unadjusted(expr);
385-
for uint::range(1, adjustment.autoderefs+1) |deref| {
395+
for uint::range(1, autoderefs+1) |deref| {
386396
cmt = self.cat_deref(expr, cmt, deref);
387397
}
388398
return cmt;

src/librustc/middle/moves.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,9 @@ pub impl VisitContext {
410410
// those adjustments is to take a reference, then it's only
411411
// reading the underlying expression, not moving it.
412412
let comp_mode = match self.tcx.adjustments.find(&expr.id) {
413-
Some(adj) if adj.autoref.is_some() => Read,
413+
Some(@ty::AutoDerefRef(
414+
ty::AutoDerefRef {
415+
autoref: Some(_), _})) => Read,
414416
_ => expr_mode.component_mode(expr)
415417
};
416418

src/librustc/middle/trans/callee.rs

+22-6
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,25 @@ pub fn trans(bcx: block, expr: @ast::expr) -> Callee {
9494
}
9595

9696
// any other expressions are closures:
97-
return closure_callee(&expr::trans_to_datum(bcx, expr));
98-
99-
fn closure_callee(db: &DatumBlock) -> Callee {
100-
return Callee {bcx: db.bcx, data: Closure(db.datum)};
97+
return datum_callee(bcx, expr);
98+
99+
fn datum_callee(bcx: block, expr: @ast::expr) -> Callee {
100+
let DatumBlock {bcx, datum} = expr::trans_to_datum(bcx, expr);
101+
match ty::get(datum.ty).sty {
102+
ty::ty_bare_fn(*) => {
103+
let llval = datum.to_appropriate_llval(bcx);
104+
return Callee {bcx: bcx, data: Fn(FnData {llfn: llval})};
105+
}
106+
ty::ty_closure(*) => {
107+
return Callee {bcx: bcx, data: Closure(datum)};
108+
}
109+
_ => {
110+
bcx.tcx().sess.span_bug(
111+
expr.span,
112+
fmt!("Type of callee is neither bare-fn nor closure: %s",
113+
bcx.ty_to_str(datum.ty)));
114+
}
115+
}
101116
}
102117

103118
fn fn_callee(bcx: block, fd: FnData) -> Callee {
@@ -129,7 +144,7 @@ pub fn trans(bcx: block, expr: @ast::expr) -> Callee {
129144
ast::def_binding(*) |
130145
ast::def_upvar(*) |
131146
ast::def_self(*) => {
132-
closure_callee(&expr::trans_to_datum(bcx, ref_expr))
147+
datum_callee(bcx, ref_expr)
133148
}
134149
ast::def_mod(*) | ast::def_foreign_mod(*) |
135150
ast::def_const(*) | ast::def_ty(*) | ast::def_prim_ty(*) |
@@ -392,7 +407,6 @@ pub fn trans_lang_call_with_type_params(bcx: block,
392407
fty);
393408
let mut llfnty = type_of::type_of(callee.bcx.ccx(),
394409
substituted);
395-
llfnty = lib::llvm::struct_tys(llfnty)[0];
396410
new_llval = PointerCast(callee.bcx, fn_data.llfn, llfnty);
397411
}
398412
_ => fail!()
@@ -715,6 +729,8 @@ pub fn trans_arg_expr(bcx: block,
715729
}
716730

717731
ast::by_copy => {
732+
debug!("by copy arg with type %s, storing to scratch",
733+
ty_to_str(ccx.tcx, arg_datum.ty));
718734
let scratch = scratch_datum(bcx, arg_datum.ty, false);
719735

720736
arg_datum.store_to_datum(bcx, arg_expr.id,

src/librustc/middle/trans/common.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1344,6 +1344,12 @@ pub fn expr_ty(bcx: block, ex: @ast::expr) -> ty::t {
13441344
node_id_type(bcx, ex.id)
13451345
}
13461346
1347+
pub fn expr_ty_adjusted(bcx: block, ex: @ast::expr) -> ty::t {
1348+
let tcx = bcx.tcx();
1349+
let t = ty::expr_ty_adjusted(tcx, ex);
1350+
monomorphize_type(bcx, t)
1351+
}
1352+
13471353
pub fn node_id_type_params(bcx: block, id: ast::node_id) -> ~[ty::t] {
13481354
let tcx = bcx.tcx();
13491355
let params = ty::node_id_to_type_params(tcx, id);

0 commit comments

Comments
 (0)