This is an archive of the discontinued LLVM Phabricator instance.

Introduce a section to the programmers manual about type hierarchies, polymorphism, and virtual dispatch.
ClosedPublic

Authored by chandlerc on Jan 26 2015, 9:09 PM.

Details

Summary

This is essentially trying to explain the emerging design techniques
being used in LLVM these days somewhere more accessible than the
comments on a particular piece of infrastructure. It covers the
"concepts-based polymorphism" that caused some confusion during initial
reviews of the new pass manager as well as the tagged-dispatch mechanism
used pervasively in LLVM and Clang.

Perhaps most notably, I've tried to provide some criteria to help
developers choose between these options when designing new pieces of
infrastructure.

I'm going to send an email to llvm-dev and cfe-dev with the content of this
change to collect more general feedback as well, but sending this as a diff for
folks to review in Phabricator if that is more convenient.

Diff Detail

Repository
rL LLVM

Event Timeline

chandlerc updated this revision to Diff 18795.Jan 26 2015, 9:09 PM
chandlerc retitled this revision from to Introduce a section to the programmers manual about type hierarchies, polymorphism, and virtual dispatch..
chandlerc updated this object.
chandlerc edited the test plan for this revision. (Show Details)
chandlerc added reviewers: rsmith, dexonsmith.
chandlerc added a subscriber: Unknown Object (MLST).
chandlerc updated this revision to Diff 18799.Jan 26 2015, 11:03 PM

Fix a typo by replacing 'used' with 'use' (and re-flowing the text)...

kristof.beyls added inline comments.
docs/ProgrammersManual.rst
2540 ↗(On Diff #18799)

I'm not a C++ nor object oriented design expert, but could understand the explanation up to this point reasonably well.
I am not sure what is meant with "manual tagged dispatch". A web search gave me some
explanations - but no great ones. I'm wondering if it would be possible to also give a pointer
that explains "tag dispatching" and how it results in closed type hierarchies?
Or maybe one of the videos pointed to above explain it (sorry - haven't watched those yet)?

I think it's a good idea to record and explain best practice used in LLVM object-oriented/type hierarchy design.

mehdi_amini added inline comments.
docs/ProgrammersManual.rst
2506 ↗(On Diff #18799)

" is to that of ", is it correct English? This is not clear to me (I'm not an English-native speaker).

echristo added inline comments.
docs/ProgrammersManual.rst
2506 ↗(On Diff #18799)

Not in this context no. It should probably be "is that of". Though the sentence might read more clearly as: "An alternate, and preferred within LLVM, strategy for the second use case is that of generic programming."

silvas added a subscriber: silvas.Jan 27 2015, 4:11 AM

I really like it. Some minor suggestions.

docs/ProgrammersManual.rst
2505–2506 ↗(On Diff #18799)

Somewhere in this paragraph it might be worth mentioning that the buzz-words "compile-time duck typing" or "static polymorphism" is sometimes used to describe this.

2507–2508 ↗(On Diff #18799)

I would suggest making a connection with "concepts", e.g. ... that conforms to the interface (sometimes called a "concept").

2519–2527 ↗(On Diff #18799)

I think it would be useful to give explicit guidance to the reader as to which of these to look at first. I think it's reasonable to get up to speed on this pattern from these resources from a single ~30min video. It's not clear to the reader from this list whether getting up to speed on this pattern is something that they can click through one of these videos and watch it while eating a sandwich, or whether it is more weekend-scale.

When I encountered this stuff for the first time, IIRC I sort of skipped through the C++Now! 2012 and that really got my interest, then I watched the GoingNative 2013 talk and finally skimmed through some of the resources linked from the github. Based on my anecdotal experience, I would probably favor calling out the GoingNative 2013 talk as "watch this for a quickstart".

2538–2539 ↗(On Diff #18799)

Probably want a link to http://llvm.org/docs/HowToSetUpLLVMStyleRTTI.html . You may want to use the catch-phrase "LLVM-style RTTI" somewhere here as well.

Also feel free to make changes to HowToSetUpLLVMStyleRTTI to better fit into the context of the discussion you're adding here.

Some minor wording suggestions.

docs/ProgrammersManual.rst
2506 ↗(On Diff #18799)

"An alternative strategy (preferred within LLVM) for the second use case is generic programming". Commas can be used for a lot of things in English, and sometimes even native speakers have to backtrack to figure out what kind of use it is (in this case, they are delimiting a parenthetical, so just use parentheses).

2529–2530 ↗(On Diff #18799)

The different "and"'s here are sort of confusing. Maybe "creating a type hierarchy with virtual dispatch" to avoid one of them?

dexonsmith edited edge metadata.Jan 27 2015, 10:30 AM

Chandler: nice writeup.

This revision was automatically updated to reflect the committed changes.
kristof.beyls added inline comments.Jan 27 2015, 11:37 PM
llvm/trunk/docs/ProgrammersManual.rst
2551

Thanks, this makes the "closed type hierarchies" and "manual tagged dispatch" clear to me now.
I don't have any further remarks on the text - looks good to me.