Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-bind HCL program before passing it to each language rendering (#3135)
### Problem Program generation (`x.GenerateProgram` functions for each language) have side effects since they change the `program` object passed to them in-place. Currently, we pass the same `program` object through the entire pipleline of example generation for all languages. This means, that all languages except nodejs (which is the first in the list) is affected by previous languages in subtle ways. Mostly, this seems to break schema type information in hard-to-understand ways. See the list of issues and a diff link below for examples. ### Change This PR moves the invocation of `hcl2.BindProgram` inside the language loop, which prevents us from sharing the `program`. This should eliminate the cross-language effects. Entirely unexpectedly to me, this leads to a substantial performance _gain_ not penalty: the schema generation time reduced from 110s to 13s on my laptop! The second code change you see here is extending the ability to write examples to disk from HCL-only to any language. (see below) ### Validation I logged all examples in all languages before and after the change, and pushed them to [this PR](#3134). This way it's easier to validate the results. 700+ python, 200+ go, and a number of csharp examples are pure improvements with better type instantiations. The only seeming regression are C# changes from `new[] {}` to `new() {}` where the old option looks correct. I guess that's something that worked by luck then? ### Issues Fixed Fix #2608 Fix #2575 Fix #2084 Fix #2083 Fix #2275 Fix #2047 Fix #1479 Fix #2827 (the example it shows is fixed)
- Loading branch information