Commit graph

61 commits

Author SHA1 Message Date
Pat Gavlin 00fbbb6544
[codegen/hcl2] Fix nested apply rewrites (#5013)
Rewrites that should produce nested applies due to functions that return
eventual types were instead producing a single top-level apply. These
changes fix that by considering a function that produces an eventual
value as inspecting eventual values.
2020-07-16 10:26:10 -07:00
Pat Gavlin 4961567ecf
[codegen/hcl2] Add a template trivia constructor (#5009)
Just what it says on the tin. Currently it's not possible to create a
valid value of this type because the `bytes` field is unexported. This
constructor fixes that.
2020-07-14 12:07:44 -07:00
Pat Gavlin 86599a06a6
[codegen/hcl2] Fix applies on relative traversals. (#5008)
The apply rewrite for relative traversals did not consider whether or
not the receiver was eventually-typed, and did not properly check
whether or not the relative traversal itself was eventually-typed. These
changes correct those mistakes.
2020-07-14 12:07:35 -07:00
Komal 0ede17ced2
Remove duplicated methods (#4985) 2020-07-08 16:50:46 -07:00
Pat Gavlin d07c3698e5
[codegen/{hcl2,schema}] Abstract package loading. (#4975)
Instead of requiring a plugin host for package loading in the HCL2
binder, define a much narrower interface that exposes the ability to
fetch the schema for a package at a specific version. This interface is
defined in the schema package, which also exposes a caching loader that
is backed by provider plugins.

These changes also add some convenience methods to `*schema.Package` for
fast access to particular resources and functions.

Related to #1635.
2020-07-07 14:45:18 -07:00
Pat Gavlin 2d530e8038
[hcl2] Fix tokenless body item printing. (#4974)
In general, each item in an HCL2 body must be followed by a trailing
newline. The printer did not properly insert these newlines for body
items without any associated tokens/trivia, or with trivia that did not
include a trailing new line.

Related to #1635.
2020-07-07 13:46:26 -07:00
Pat Gavlin a8a20ecb4b
[codegen/*] Add support for explicit secrets. (#4927)
- Add a new builtin function, secret, that marks its input value as
  secret
- Add support for this function to the various code generators

Fixes #4924.
2020-06-30 11:35:24 -07:00
Pat Gavlin 69ba47cff2
[codegen/*] Add support for resource options. (#4925)
The PCL binder has supported resource options for some time, but these
options haven't been used or processed by the various code generators.
These options--particularly the parent and provider options0--are
critical for import codegen. These changes implement the basic set of
options, and add a note about fleshing out the rest as necessary.

One component of these changes is a new rewriter that rewrites property
references into property paths that are understood by the Pulumi engine.
This rewriter is used to preprocess the contents of the `ignoreChanges`
resource option.

These changes also hack around a weakness in the HCL2 type system:
In Go, references to resources should be typed as `hcl2.ResourceType`.
Unfortunately, this breaks the existing collection semantics associated
with resources. Because of this, the Go code generator does not have
enough information to know that it should generate a `[]pulumi.Resource`
for lists of resources. These changes hack around that limitation using
a Go-specific opaque type and some hardcoded comparisons in
`argumentTypeName`.

Fixes #4923.
2020-06-29 16:33:52 -07:00
Evan Boyle 94cd67b564
[Go Program Gen] Improved type handling and invokes (#4749) 2020-06-05 18:52:00 -07:00
Pat Gavlin d77cda98fc
[codegen/hcl2] Fixes for RewriteConversions. (#4743)
- Typecheck in all cases where a type may have changed
- Do not perform literal conversions if the type is already correct
- Perform literal conversions before checking to see if a call to
  `__convert` is required. This catches cases such as string literals
  passed where ints are required. Without this change, that form in
  particular generates a bare number literal rather than a number
  literal wrapped in a `__convert`.
2020-06-02 12:00:35 -07:00
Mikhail Shilkov cf8b6c1237
Convert primitive types in C# program gen (#4686) 2020-05-29 12:38:53 +02:00
Pat Gavlin e973ec0491
[codegen/hcl2] Fix assignability from dynamic. (#4704)
Types like output(T), promise(T), and union(T_0, ..., T_N) should be
assignable from dynamic if they contain an element type that is
assignable from dynamic.

This allows consumers to use the following code to check if some type
behaves like the dynamic type w.r.t. conversions:

```
if t.AssignableFrom(model.DynamicType) {
}
```

Fixes #4703.
2020-05-26 09:05:42 -07:00
Pat Gavlin cb8066d74a
[codegen/hcl2] Fix ForExpression.Evaluate. (#4701)
This expression was not evaluated correctly when producing a dictionary.
2020-05-26 09:05:35 -07:00
Pat Gavlin 05032d6850 [codegen/hcl2] Fix assignability from dynamic.
Types like output(T), promise(T), and union(T_0, ..., T_N) should be
assignable from dynamic if they contain an element type that is
assignable from dynamic.

This allows consumers to use the following code to check if some type
behaves like the dynamic type w.r.t. conversions:

```
if t.AssignableFrom(model.DynamicType) {
}
```

Fixes #4703.
2020-05-26 08:21:09 -07:00
Pat Gavlin 5330c97684
[codegen/hcl2/model] Remove type caches. (#4683) 2020-05-22 10:47:34 +01:00
Evan Boyle 8dd329f57f
Go basic program gen (#4667) 2020-05-21 10:23:33 -07:00
Mikhail Shilkov adfa8116fb
Introduce k8s compatibility mode to C# codegen (#4544)
Introduce k8s compatibility mode to C# codegen
2020-05-19 11:41:06 +02:00
Pat Gavlin 088751a4a8
[codegen/hcl2] Refactor package schema loading. (#4661)
- Move the implementation of loadPackageSchema into a method on
  PackageCache
- Protect the cache with synchronization primitives to enable
  concurrency in downstream consumers
- Use jsoniter to deserialize schemas
2020-05-18 17:35:11 -07:00
Mikhail Shilkov 5b410ec440
Resolve referenced packages for every TF program (#4636) 2020-05-15 19:18:07 +02:00
Pat Gavlin 647b6627a2
[codegen/hcl2] Fix descent in RewriteConversions. (#4614)
Descend into anonymous function expressions, the operands to conditional
expressions, and the value in for expressions.
2020-05-13 08:25:26 -07:00
Pat Gavlin 33258326e0
[codegen/hcl2] Add a conversion insertion pass. (#4594)
Add a rewriter that reifies implicit conversions into a call to the
`__convert` intrinsic. Code generators can recognize this intrinsic and
use it to generate appropriate conversion code.

Part of this work involves redesigning the type annotations system.
Annotations are now only applicable to opaque and object types. Instead
of inspecting annotations directly, code generators should use
`hcl2.GetSchemaForType` to extract the `schema.Type` for a `model.Type`.
2020-05-11 11:17:36 -07:00
Pat Gavlin 255620ea1e
[codegen/nodejs] Await invokes in async contexts. (#4598)
If we are generating code into an async context (e.g. an async main),
await calls to invoke rather than leaving them as promises. This results
in more idiomatic code withing such contexts.
2020-05-11 10:21:56 -07:00
Pat Gavlin fc00c16e31
[codegen/hcl2] Fix iterator apply rewrites. (#4589)
There are two expressions in HCL2 that are used to iterate over
collections:

- Splat expressions, e.g. `foo.*.bar`, and
- For expressions, e.g. `[for v in foo: v.bar]`

In both of these cases, the parts of the expression that are not the
collection being iterated behave like callbacks, and must be treated as
such by the apply rewriter.
2020-05-07 12:15:40 -07:00
Pat Gavlin 8fded5f29f
[codegen/hcl2] Fix template control tokens. (#4584)
Token detection was broken for conditional and for expressions that
represent template control sequences. The code originally attempted to
determine whether or not a conditional or for expression was a control
sequence by inspecting the expression's parent. Unfortunately, that
approach is unable to distinguish between expressions that are control
sequences and those that are merely template parts. These changes
instead inspect the first token of the expression for a template control
token (i.e. `%{`): if such a token is found, the expression is detected
as a template control sequence.
2020-05-07 09:12:00 -07:00
Pat Gavlin 96300f12d9
[codegen/*] Improve range type binding + codegen. (#4552)
- Determine variable types for ranged resources by typechecking an
  equivalent expression
- Detect top-level await in NodeJS and generate an async main
- Fix `pulumi.all` generation for NodeJS
- Fix a bug in the lowering of relative traversals in Python
2020-05-04 15:04:35 -07:00
Pat Gavlin 8c4c46052d Fix the entries() signature 2020-05-01 13:10:56 -07:00
Pat Gavlin 50b1049337 Fix a misspelling 2020-05-01 11:04:44 -07:00
Pat Gavlin 21634768aa [hcl2] Fix package loading and trivia detection
- Load packages referenced by all node types, not just resource nodes
- Fix trivia detection
2020-05-01 11:00:58 -07:00
Pat Gavlin ca5cb05482 [hcl2/model] String literal + traversal fixes.
- Properly escape string literals inside template expressions and
  heredocs
- Fix trailing trivia detection for scope and relative traversals
2020-04-30 16:38:36 -07:00
Pat Gavlin 1d6cce98fe
[codegen/python] Fix nested quotes. (#4539)
Unlike most languages with interpolated strings, Python's formatted
string literals do not allow the nesting of quotes. For example,
this expression is not legal Python:

    f"Foo {"bar"} baz"

If an interpolation requires quotes, those quotes nust differ from the
quotes used by the enclosing literal. We can fix the previous example
by rewriting it with single quotes:

    f"Foo {'bar'} baz"

However, this presents a problem if there are more than two levels of
nesting, as Python only has two kinds of quotes (four if the outermost
string uses """ or '''): in this case, the expression becomes
unspellable, and must be assigned to a local that is then used in place
of the original expression. So this:

    f"Foo {bar[f'index {baz["qux"]}']} zed"

becomes this:

    index = "qux"
    f"Foo {bar[f'index {baz[index]}']}"

To put it bluntly, Python code generation reqiures register allocation,
but for quotes. These changes implement exactly that.

These changes also include a fix for traversals that access values that
are dictionaries rather than objects, and must use indexers rather than
attributes.
2020-04-30 16:34:25 -07:00
Pat Gavlin 1eff2b9acf
[hcl2/model] Propagate annotations in InputType. (#4535)
When creating the inputty version of an `ObjectType`, ensure that the
result carries any annotations present on the original type.
2020-04-30 14:16:43 -07:00
Pat Gavlin 6bd81de8aa
[hcl2] Fix tokens and printing for TraverseIndex. (#4536)
The tokens that make up the "key" portion of an index traversal
(e.g. `"foo"` in `a["foo"]`) are structured like those that make up a
block label: an open quote token, a string literal token, and a close
quote token. The token mapper did not account for that fact, and instead
recorded the key token as the open quote. These changes correct that
error, and adjust the code in `literalText` to allow for
properly-escaped and quoted strings where necessary.
2020-04-30 13:44:32 -07:00
Pat Gavlin 6ae15f6a44
[codegen/hcl] Fix binop printing. (#4537)
The code that handles automatic parenthesis insertion was broken for
operators with the same precedence.
2020-04-30 13:44:05 -07:00
Pat Gavlin b4daf94c2f
[codegen] Add support for caching package schemas. (#4534)
If a single process is going to bind and generate multiple programs, it
is useful to be able to cache package schemas in order to avoid the
(large) overhead of deserializing schemas multiple times.
2020-04-30 13:22:24 -07:00
Pat Gavlin 2e9499a000
[codegen/hcl2] Fix the apply rewriter. (#4486)
Some of the apply rewriter's assumptions were broken by the richer
expressions available in HCL2. These changes fix those broken
assumptions, in particular the assumption that only scope traversal
expressions are sources of eventual values.
2020-04-24 22:04:24 -07:00
Pat Gavlin dc2d91e294
[codegen/hcl2] Separate binding and typechecking. (#4483)
This allows consumers to change the inputs to an expression and re-run
typechecking to compute the expression's new type.
2020-04-24 08:52:52 -07:00
Pat Gavlin 18ecd1c8a9 Apply rewriter: separate global and expr data
This will make some incoming fixes that address nested applies easier to
write and understand.
2020-04-22 15:48:56 -07:00
Pat Gavlin 9204d70c54 Fix Python input property names.
- Fix input property names and forms for invokes. Previously we
  generated a dict; now we generate properly-named args.
- Fix nested property names for resources.
2020-04-21 13:55:33 -07:00
Pat Gavlin 1d672563da Fix output property names in Python codegen.
Some property names are mapped from their `camelCase` Pulumi name to a
`snake_case` Python name. This mapping is irregular, and only occurs for
resources properties and function calls.

Note that there's still more work to do here: this only fixes names on
the output side; the input side is still broken for nested resource
proprerties and function calls.

The underlying design--annotated types in `hcl2/model`--may need some
additional work in the future, but I _believe_ it's good enough for now.
2020-04-21 10:25:27 -07:00
Pat Gavlin 807cf44cd7
Codegen: collect imports from function calls. (#4445)
Codegen: collect imports from function calls; fix Python resource names.

Just what it says on the tin.
2020-04-21 10:24:42 -07:00
Pat Gavlin 1f19cbbe08
Clean up the language-specific schema APIs. (#4454)
Rather than forcing consumers to deal with language-specific data
ad-hoc, add an API that allows all language-specific data to be decoded
up-front.
2020-04-20 16:36:05 -07:00
Pat Gavlin f081d98a39
HCL2: support for tolerating missing variables. (#4430)
When this tolerance is enabled, diagnostics will not be emitted for
missing variables.
2020-04-17 08:24:44 -07:00
Pat Gavlin 398878de31
Various codegen updates. (#4424)
- Define `null` in Pulumi HCL2
- Bind Pulumi HCL2 in topological order s.t. variable types can be
  properly computed
- Fix resources that range over bools and numbers
- Add element, length, lookup, readFile, and split functions
- Do not rewrite function signatures with input types during binding
- Fix splat expression binding for non-lists
- Add support for evaluating expressions
- Add support for operator precedence to code generators
- Add support for constants to the HCL2 IR
- Add support for generating ranged resources in Python
- Add support for generating conditional resource in Node and Python
- Fix various naming issues in Python
2020-04-16 16:44:34 -07:00
CyrusNajmabadi 66bd3f4aa8
Breaking changes due to Feature 2.0 work
* Make `async:true` the default for `invoke` calls (#3750)

* Switch away from native grpc impl. (#3728)

* Remove usage of the 'deasync' library from @pulumi/pulumi. (#3752)

* Only retry as long as we get unavailable back.  Anything else continues. (#3769)

* Handle all errors for now. (#3781)


* Do not assume --yes was present when using pulumi in non-interactive mode (#3793)

* Upgrade all paths for sdk and pkg to v2

* Backport C# invoke classes and other recent gen changes (#4288)

Adjust C# generation

* Replace IDeployment with a sealed class (#4318)

Replace IDeployment with a sealed class

* .NET: default to args subtype rather than Args.Empty (#4320)

* Adding system namespace for Dotnet code gen

This is required for using Obsolute attributes for deprecations

```
Iam/InstanceProfile.cs(142,10): error CS0246: The type or namespace name 'ObsoleteAttribute' could not be found (are you missing a using directive or an assembly reference?) [/Users/stack72/code/go/src/github.com/pulumi/pulumi-aws/sdk/dotnet/Pulumi.Aws.csproj]
Iam/InstanceProfile.cs(142,10): error CS0246: The type or namespace name 'Obsolete' could not be found (are you missing a using directive or an assembly reference?) [/Users/stack72/code/go/src/github.com/pulumi/pulumi-aws/sdk/dotnet/Pulumi.Aws.csproj]
```

* Fix the nullability of config type properties in C# codegen (#4379)
2020-04-14 09:30:25 +01:00
Pat Gavlin 51588ede49
Fix various printing issues. (#4378)
- Parentheses were not handled properly
- Literals inside of template control sequences were not handled
  properly

These changes also improve test coverage for the printers.
2020-04-13 19:11:56 -07:00
Pat Gavlin 71aa0f020f
Fix treatment of trivia in template expressions. (#4352)
And improve test coverage for the same.
2020-04-09 16:37:52 -07:00
Pat Gavlin 2f22c1c59c
HCL2 updates (#4309)
Pulumi HCL2 IR:
- Add support for invokes
- Add support for resource options, incl. ranged resources
- Allow the apply rewriter to ignore promise-typed values
- Add tests for the binder
- Add support functions for TF: entries and range

NodeJS codegen:
- Simplify for expression codegen
- Add support for invoke codegen
- Add support for entries and range functions
- Add tests

Python codegen:
- Implement codegen for most expression types
- Add support for invoke codegen
- Add tests
2020-04-06 19:43:16 -07:00
Pat Gavlin 742c047211 Remove an unused import 2020-04-02 22:09:50 -07:00
Pat Gavlin 1860b4f656 Appease the linter 2020-04-02 21:43:03 -07:00
Pat Gavlin e831ecbc0e Update package references 2020-04-02 21:25:30 -07:00