Skip to content

Commit

Permalink
Fix casting between interface types
Browse files Browse the repository at this point in the history
A search of the instance's class info is required for all casts
to interface types. It should be possible to eliminate it in some
cases by being clever. For example, group the methods in an
interface vtable by the super-interfaces and let the resulting
vtable point to the middle of the sub-interface vtable.
  • Loading branch information
greedy committed Jul 25, 2011
1 parent 3f096d2 commit 8cfa901
Showing 1 changed file with 0 additions and 19 deletions.
19 changes: 0 additions & 19 deletions src/compiler/scala/tools/nsc/backend/llvm/GenLLVM.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1122,32 +1122,13 @@ abstract class GenLLVM extends SubComponent {
recordType(typeKindType(targettk))
val obj = getrefptr(src)(_insns)
if (targettk.isInterfaceType) {
srctk.toType.typeSymbol.info.baseClasses.filter(_.isTrait).indexOf(targettk.toType.typeSymbol) match {
case -1 => {
val iface0 = nextvar(rtReference)
val vtbl = nextvar(rtVtable)
val iface1 = nextvar(rtReference)
_insns.append(new insertvalue(iface0, new CUndef(rtReference), obj, Seq[LMConstant[LMInt]](0)))
_insns.append(new call(vtbl, rtIfaceCast, Seq(obj, externClassP(targettk.toType.typeSymbol))))
_insns.append(new insertvalue(iface1, iface0, vtbl, Seq[LMConstant[LMInt]](1)))
iface1
}
case tgtidx => {
val vtbl = nextvar(rtVtable)
val vtblptr = nextvar(rtVtable.pointer)
val clsptrptr = nextvar(rtClass.pointer.pointer)
val clsptr = nextvar(rtClass.pointer)
val iref0 = nextvar(rtReference)
val iref1 = nextvar(rtReference)
_insns.append(new getelementptr(clsptrptr, obj, Seq[LMConstant[LMInt]](0, 0)))
_insns.append(new load(clsptr, clsptrptr))
_insns.append(new getelementptr(vtblptr, clsptr, Seq[LMConstant[LMInt]](0, 7, tgtidx, 1)))
_insns.append(new load(vtbl, vtblptr))
_insns.append(new insertvalue(iref0, new CUndef(rtReference), obj, Seq[LMConstant[LMInt]](0)))
_insns.append(new insertvalue(iref1, iref0, vtbl, Seq[LMConstant[LMInt]](1)))
iref1
}
}
} else if (!targettk.isInterfaceType && !srctk.isInterfaceType) {
src
} else {
Expand Down

0 comments on commit 8cfa901

Please sign in to comment.