I would like to get the following changes merged into 3.8
r257831
r257838
r257853
r257861
r257869
r257870
These changes are for fixing issues with template type diffing, including a number of asserts from edge cases, at least one mistake in printing, and a lot of general refactoring. There is a large amount of lines changed, but it is confined to one code file and two tests.