Merge pull request #3945 from 9rnsr/refactor_template

[Refactoring] template.c
Add TemplateInstance::tnext to construct instantiation dependency graph

To detect speculative instantiations in codegen phase, `tnext` is neccesary for the `test6()` case `runnable/link13350.d`. That's a big difference from the PR #2550.