Minor: Replaced all template funs with vals and moved type definitions from templates to root packages.
Incremental build fixes and improvements.

- It now works again on a per-file basis.
- Added support for custom classes (structs and capabilities).
- Capabilities are now properly invalidated by template changes.
- Templates can now be defined in arbitrary files and there can be multiple templates in the same file, incremental build will work as expected.