[LLVMdev] Closed virtual dispatch (was: Introduce a section to the programmers manual about type hierarchies, polymorphism, and virtual dispatch.)

Philip Reames
Tue, 27 Jan 2015 17:13:00 -0000

On 01/26/2015 09:13 PM, Chandler Carruth wrote:
> If you do need to introduce a type hierarchy, we often prefer to used
> explicitly closed type hierarchies with manual tagged dispatch rather
> than the
> open inheritance model and virtual dispatch that is more common in C++
> code.
> This is because LLVM rarely encourages library consumers to extend its
> core
> types, and leverages the closed and tag-dispatched nature of its
> hierarchies to
> generate significantly more efficient code. We have also found that a
> large
> amount of our usage of type hierarchies fits better with tag-based pattern
> matching rather than dynamic dispatch across a common interface.
Given we have a large number of compiler authors and contributors to the
C++ language spec, it seems really odd to me that we can't solve this
problem in a more elegant way.  The tagged-dispatch as a sealed world
replacement for virtual dispatch is one that comes up on a pretty
regular basis.  Might it be time to figure out how to generalize this
and propose either a clang extension or a language mechanism for some
future version of C++?

Philip