Commit Graph

17 Commits

Author SHA1 Message Date
Fraser Waters 571fadae3f Use slice.Prealloc instead of make([]T, 0, ...)
Fixes https://github.com/pulumi/pulumi/issues/12738

https://github.com/pulumi/pulumi/pull/11834 turned on the prealloc
linter and changed a load of slice uses from just `var x T[]` to `x :=
make([]T, 0, preallocSize)`. This was good for performance but it turns
out there are a number of places in the codebase that treat a `nil`
slice as semnatically different to an empty slice.

Trying to test that, or even reason that through for every callsite is
untractable, so this PR replaces all expressions of the form `make([]T,
0, size)` with a call to `slice.Prealloc[T](size)`. When size is 0 that
returns a nil array, rather than an empty array.
2023-06-29 11:27:50 +01:00
Fraser Waters 645cf425f9 Make SortedKeys type safe with generics 2023-02-13 20:59:13 +00:00
Ian Wahbe 65b6b01abd Don't use *schema.Package in python codegen 2022-12-07 17:54:38 +01:00
Ian Wahbe 7d5a38c9b1 Standardize the FS abstraction for codegen 2022-11-09 13:12:51 -08:00
Anton Tayanovskyy 7d31e772ae Repro tf-bridge 611 2022-10-05 15:34:14 -04:00
Eng Zer Jun 57b25b45d1
refactor: use `os.ReadDir` for lightweight directory reading
`os.ReadDir` was added in Go 1.16 as part of the deprecation of `ioutil`
package. It is a more efficient implementation than `ioutil.ReadDir`.

Reference: https://pkg.go.dev/io/ioutil#ReadDir
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-09-24 15:20:43 +08:00
Ian Wahbe 90913de3fb
[codegen/dotnet] Allow generated SDKs to have a global namespace other then `Pulumi` ()
* Allow .NET packages alternate owners

Specifically, this allows a generated package with a enclosing namespace
different then "Pulumi."

* New test case files

* Remove unused import

* Update CHANGELOG_PENDING.md

* Update codegen from master merge

* Use rootNamespace instead of namespace

* publisher overrides Author and "Company" in .NET

* Add publisher propagation to CHANGELOG_PENDING.md

* Fix nits

* Use fmt.Sprintf over +

* Restore sdk_driver.go (mostly)

* Add docs to allLanguages add documentation.

* Update tests from master

* Add rootNamespace to docs
2022-01-21 12:58:11 -08:00
Pat Gavlin 0a45f8d3ab
[codegen/go] Rewrite cyclic types. ()
When computing the type name for a field of an object type, we must
ensure that we do not generate invalid recursive struct types. A struct
type T contains invalid recursion if the closure of its fields and its
struct-typed fields' fields includes a field of type T. A few examples:

Directly invalid:

    type T struct { Invalid T }

Indirectly invalid:

    type T struct { Invalid S }

    type S struct { Invalid T }

In order to avoid generating invalid struct types, we replace all
references to types involved in a cyclical definition with *T. The
examples above therefore become:

(1) type T struct { Valid *T }

(2) type T struct { Valid *S }

    type S struct { Valid *T }

We do this using a rewriter that turns all fields involved in reference
cycles into optional fields.

These changes also include an enhancement to the SDK codegen test
driver in the interest of making iterating and debugging more convenient:  if the -sdk.no-checks flag is passed, the driver will not run post-generation checks.
2021-09-28 07:33:14 -07:00
Mikhail Shilkov af0054093a Add helper methods to StringSet 2021-06-09 12:02:32 +02:00
pulumi-bot 73a66f48ea [breaking] Changing the version of go.mod in sdk / pkg to be v3 2021-04-14 19:32:18 +01:00
Justin Van Patten e86a69bedd
[codegen/nodejs] Emit externally referenced resources/types () 2021-01-29 16:52:00 -08:00
Komal 8fb8ea80c0
[codegen/*] - Extract common enum name replacer ()
* Extract common enum char replacer

* PR feedback
2020-11-11 10:42:08 -08:00
Komal 1a10e06588
Add a helper function to clean the codegen dir () 2020-07-15 16:11:37 -07:00
Pat Gavlin 1d6cce98fe
[codegen/python] Fix nested quotes. ()
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
CyrusNajmabadi 66bd3f4aa8
Breaking changes due to Feature 2.0 work
* Make `async:true` the default for `invoke` calls ()

* Switch away from native grpc impl. ()

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

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

* Handle all errors for now. ()


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

* Upgrade all paths for sdk and pkg to v2

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

Adjust C# generation

* Replace IDeployment with a sealed class ()

Replace IDeployment with a sealed class

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

* 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 ()
2020-04-14 09:30:25 +01:00
Pat Gavlin 1860b4f656 Appease the linter 2020-04-02 21:43:03 -07:00
Pat Gavlin aa655c6076 Add a package for binding HCL2 as Pulumi config.
These changes add preliminary (read: incomplete) support for
representing Pulumi programs using HCL2. Language-specific code
generators can use this representation as a basis for understanding the
semantics of a Pulumi program.
2020-04-02 21:25:30 -07:00