Change time of instance merging

I've broken this set of related changes into 4 logical parts. Please click on each of the commits and read the commit logs for a more thorough explanation of each component.

Overall, this fixes two interesting issues we encountered:

1. We did "instance merging" right at the end of ShaderGroupEnd, which meant that if you then asked for a serialization of the group, it might (if there was merging) not very closely resemble the input you just gave it. That seems wrong, so we move the merging to right before runtime optimization (with an option to do it immediately, should anybody be in a situation where doing that is critical for memory savings).

2. Better detection and exclusion of code generation for interior nodes that optimization has collapsed down to nothing but did not fully remove. This in turn leads to more robust detection of entire groups that don't do any work. (Such as a displacement shading network that reduces to nothing, signalling the renderer that it doesn't need to displace at all.)