Skip to content

Commit

Permalink
Re-bind HCL program before passing it to each language rendering (#3135)
Browse files Browse the repository at this point in the history
### 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
mikhailshilkov committed Mar 11, 2024
1 parent a39bed4 commit 1e0e6a4
Show file tree
Hide file tree
Showing 2 changed files with 1,080 additions and 1,062 deletions.
2,082 changes: 1,041 additions & 1,041 deletions provider/cmd/pulumi-resource-azure-native/schema.json
60 changes: 39 additions & 21 deletions provider/pkg/gen/examples.go

0 comments on commit 1e0e6a4

Please sign in to comment.