Skip to content

Commit 70452e5

Browse files
committed
Consider nullability for equivalence of monomorphized fns.
1 parent 7f45ae5 commit 70452e5

File tree

3 files changed

+40
-12
lines changed

3 files changed

+40
-12
lines changed

src/librustc/middle/trans/base.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2007,6 +2007,11 @@ pub fn trans_enum_variant(ccx: @CrateContext,
20072007
// XXX is there a better way to reconstruct the ty::t?
20082008
let repr = adt::represent_type(ccx, enum_ty);
20092009

2010+
debug!("trans_enum_variant: name=%s tps=%s repr=%? enum_ty=%s",
2011+
unsafe { str::raw::from_c_str(llvm::LLVMGetValueName(llfndecl)) },
2012+
~"[" + str::connect(ty_param_substs.map(|&t| ty_to_str(ccx.tcx, t)), ", ") + ~"]",
2013+
repr, ty_to_str(ccx.tcx, enum_ty));
2014+
20102015
adt::trans_start_init(bcx, repr, fcx.llretptr.get(), disr);
20112016
for vec::eachi(args) |i, va| {
20122017
let lldestptr = adt::trans_field_ptr(bcx,

src/librustc/middle/trans/common.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1311,10 +1311,35 @@ pub enum mono_param_id {
13111311
mono_any,
13121312
mono_repr(uint /* size */,
13131313
uint /* align */,
1314-
bool /* is_float */,
1314+
MonoDataClass,
13151315
datum::DatumMode),
13161316
}
13171317
1318+
#[deriving(Eq)]
1319+
pub enum MonoDataClass {
1320+
MonoBits, // Anything not treated differently from arbitrary integer data
1321+
MonoNonNull, // Non-null pointers (used for optional-pointer optimization)
1322+
// FIXME(#3547)---scalars and floats are
1323+
// treated differently in most ABIs. But we
1324+
// should be doing something more detailed
1325+
// here.
1326+
MonoFloat
1327+
}
1328+
1329+
pub fn mono_data_classify(t: ty::t) -> MonoDataClass {
1330+
match ty::get(t).sty {
1331+
ty::ty_float(_) => MonoFloat,
1332+
ty::ty_rptr(*) | ty::ty_uniq(*) |
1333+
ty::ty_box(*) | ty::ty_opaque_box(*) |
1334+
ty::ty_estr(ty::vstore_uniq) | ty::ty_evec(_, ty::vstore_uniq) |
1335+
ty::ty_estr(ty::vstore_box) | ty::ty_evec(_, ty::vstore_box) |
1336+
ty::ty_bare_fn(*) => MonoNonNull,
1337+
// Is that everything? Would closures or slices qualify?
1338+
_ => MonoBits
1339+
}
1340+
}
1341+
1342+
13181343
#[deriving(Eq)]
13191344
pub struct mono_id_ {
13201345
def: ast::def_id,
@@ -1338,6 +1363,12 @@ impl to_bytes::IterBytes for mono_param_id {
13381363
}
13391364
}
13401365
1366+
impl to_bytes::IterBytes for MonoDataClass {
1367+
fn iter_bytes(&self, lsb0: bool, f:to_bytes::Cb) {
1368+
(*self as u8).iter_bytes(lsb0, f)
1369+
}
1370+
}
1371+
13411372
impl to_bytes::IterBytes for mono_id_ {
13421373
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
13431374
to_bytes::iter_bytes_2(&self.def, &self.params, lsb0, f);

src/librustc/middle/trans/monomorphize.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -395,22 +395,14 @@ pub fn make_mono_id(ccx: @CrateContext,
395395
let size = machine::llbitsize_of_real(ccx, llty);
396396
let align = machine::llalign_of_pref(ccx, llty);
397397
let mode = datum::appropriate_mode(subst);
398-
399-
// FIXME(#3547)---scalars and floats are
400-
// treated differently in most ABIs. But we
401-
// should be doing something more detailed
402-
// here.
403-
let is_float = match ty::get(subst).sty {
404-
ty::ty_float(_) => true,
405-
_ => false
406-
};
398+
let data_class = mono_data_classify(subst);
407399

408400
// Special value for nil to prevent problems
409401
// with undef return pointers.
410402
if size <= 8u && ty::type_is_nil(subst) {
411-
mono_repr(0u, 0u, is_float, mode)
403+
mono_repr(0u, 0u, data_class, mode)
412404
} else {
413-
mono_repr(size, align, is_float, mode)
405+
mono_repr(size, align, data_class, mode)
414406
}
415407
} else {
416408
mono_precise(subst, None)

0 commit comments

Comments
 (0)