Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/comp/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,25 @@ pure fn struct(cx: ctxt, typ: t) -> sty {
}
}

// Returns struact(cx, typ) but replaces all occurences of platform
// dependent primitive types with their machine type equivalent
pure fn mach_struct(cx: ctxt, cfg: @session::config, typ: t) -> sty {
alt interner::get(*cx.ts, typ).struct {
ty_named(t, _) { mach_struct(cx, cfg, t) }
s { mach_sty(cfg, s) }
}
}

// Converts s to its machine type equivalent
pure fn mach_sty(cfg: @session::config, s: sty) -> sty {
alt s {
ty_int(ast::ty_i.) { ty_int(cfg.int_type) }
ty_uint(ast::ty_u.) { ty_uint(cfg.uint_type) }
ty_float(ast::ty_f.) { ty_float(cfg.float_type) }
s { s }
}
}

pure fn ty_name(cx: ctxt, typ: t) -> option::t<@str> {
alt interner::get(*cx.ts, typ).struct {
ty_named(_, n) { some(n) }
Expand Down Expand Up @@ -1758,7 +1777,9 @@ mod unify {

// Simple structural type comparison.
fn struct_cmp(cx: @ctxt, expected: t, actual: t) -> result {
if struct(cx.tcx, expected) == struct(cx.tcx, actual) {
let tcx = cx.tcx;
let cfg = tcx.sess.get_targ_cfg();
if mach_struct(tcx, cfg, expected) == mach_struct(tcx, cfg, actual) {
ret ures_ok(expected);
}
ret ures_err(terr_mismatch);
Expand Down