Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplified invokes: SDK-gen and program-gen implementation for dotnet and nodejs #11418

Merged
merged 1 commit into from Dec 16, 2022

Conversation

Zaid-Ajaj
Copy link
Contributor

Description

This PR implements simplified invoke gen for both SDKs and PCL programs by allowing invokes to:

  • Accepts multi arguments as inputs (instead of a bag of properties)
  • Return a single value as output (instead of a bag of outputs)

Related to #7435

This implementation handles dotnet and nodejs. Python and Go can be implementation on a separate pass. Currently both python and go will fail generation (sdk/program) when encountering simplified invokes

Checklist

  • I have added tests that prove my fix is effective or that my feature works
  • I have run make changelog and committed the changelog/pending/<file> documenting my change
  • Yes, there are changes in this PR that warrants bumping the Pulumi Service API version

@pulumi-bot
Copy link
Contributor

pulumi-bot commented Nov 22, 2022

Changelog

[uncommitted] (2022-12-16)

Features

  • [sdkgen/{dotnet,nodejs}] Initial implementation of simplified invokes for dotnet and nodejs.
    #11418

@Zaid-Ajaj Zaid-Ajaj marked this pull request as ready for review November 23, 2022 21:06
@Zaid-Ajaj Zaid-Ajaj force-pushed the simplified-invoke-gen branch 2 times, most recently from 46f092b to 02d53b5 Compare November 24, 2022 09:55
@Zaid-Ajaj Zaid-Ajaj mentioned this pull request Nov 27, 2022
3 tasks
@Zaid-Ajaj
Copy link
Contributor Author

@iwahbe @Frassle @AaronFriel I've added you for a PR review if you have time 🙏 I also made a quick explanation of what the is and what it does, hope this helps 😄

simplified-invokes-pr.mp4

Copy link
Member

@iwahbe iwahbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left an initial set of feedback. It would be really helpful if you reverted the TS changes so that the only generated code that changes is the code we expect to see changed.

pkg/codegen/schema/bind.go Outdated Show resolved Hide resolved
pkg/codegen/schema/schema.go Show resolved Hide resolved
Comment on lines +167 to +174
// SortedFunctionParameters returns a list of properties of the input type from the schema
// for an invoke function call which has multi argument inputs. We assume here
// that the expression is an invoke which has it's args (2nd parameter) annotated
// with the original schema type. The original schema type has properties sorted.
// This is important because model.ObjectType has no guarantee of property order.
func SortedFunctionParameters(expr *model.FunctionCallExpression) []*schema.Property {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This indicates a footgun to me. It looks like this function must be called and then nil checked every time an invoke is generated.

Could we just spread multi-argument invoke parameters into the Signature.Paremeters field? Then retrieving the sorted parameters would be as simple as express.Signature.Parameters[1:].

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the implementation to return an empty array instead of nil because if MultiArgumentInputs then the array of properties is must be non-empty which relies on invoke annotations.

Could we just spread multi-argument invoke parameters into the Signature.Paremeters field? Then retrieving the sorted parameters would be as simple as express.Signature.Parameters[1:].

That would change the shape of the invoke in PCL too and I am more inclined to leave as an object that corresponds with the schema inputs object.

pkg/codegen/nodejs/gen_program_expressions.go Outdated Show resolved Hide resolved
pkg/codegen/dotnet/gen_program_expressions.go Outdated Show resolved Hide resolved
pkg/codegen/schema/schema.go Show resolved Hide resolved
pkg/codegen/testing/test/program_driver.go Outdated Show resolved Hide resolved
pkg/codegen/schema/schema.go Outdated Show resolved Hide resolved
bors bot added a commit that referenced this pull request Dec 5, 2022
11511: [typescript/sdk-gen] Generate JS doc comments for output-versioned invokes r=Zaid-Ajaj a=Zaid-Ajaj

 - Generate JS doc comments for output-versioned invokes
 - Use explicit `any` type within apply lambda

This is part of #11418 but irrelevant to that (big) PR so this will help make the changes smaller and more clear 

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Zaid Ajaj <zaid.naom@gmail.com>
bors bot added a commit that referenced this pull request Dec 7, 2022
11564: [sdk/dotnet/nodejs] Add InvokeSingle variants to dotnet and nodejs SDKs r=Zaid-Ajaj a=Zaid-Ajaj

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

Needed for #11418 where we have invoke calls that return a simple type (such as `number`) but the runtime and engine _require_ the outputs to be a struct (as per the RPC definition) so here we are adding variants of `invoke` that unwraps the returned object and gets the first value from that object.

For example, a provider with a schema `outputs: { type: "number" }` will have an invoke implementation that returns `{ __result: 42.0 }`, in these case (non-object return types) we use `InvokeSingle` instead of `Invoke`

> It doesn't matter what the name of the key is, we always get the first value by first key.

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Zaid Ajaj <zaid.naom@gmail.com>
Copy link
Member

@iwahbe iwahbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good to me.

Can you remove whatever you did that caused whitespace changes to all generated TS functions?

pkg/codegen/testing/test/program_driver.go Show resolved Hide resolved
bors bot added a commit that referenced this pull request Dec 7, 2022
11564: [sdk/dotnet/nodejs] Add InvokeSingle variants to dotnet and nodejs SDKs r=Zaid-Ajaj a=Zaid-Ajaj

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

Needed for #11418 where we have invoke calls that return a simple type (such as `number`) but the runtime and engine _require_ the outputs to be a struct (as per the RPC definition) so here we are adding variants of `invoke` that unwraps the returned object and gets the first value from that object.

For example, a provider with a schema `outputs: { type: "number" }` will have an invoke implementation that returns `{ __result: 42.0 }`, in these case (non-object return types) we use `InvokeSingle` instead of `Invoke`

> It doesn't matter what the name of the key is, we always get the first value by first key.

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


11575: Simplify `findFunctionSchema` r=iwahbe a=iwahbe

Instead of indirecting through .NET function names, just use the schema token to lookup the function.

Co-authored-by: Zaid Ajaj <zaid.naom@gmail.com>
Co-authored-by: Ian Wahbe <ian@wahbe.com>
bors bot added a commit that referenced this pull request Dec 7, 2022
11564: [sdk/dotnet/nodejs] Add InvokeSingle variants to dotnet and nodejs SDKs r=Zaid-Ajaj a=Zaid-Ajaj

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

Needed for #11418 where we have invoke calls that return a simple type (such as `number`) but the runtime and engine _require_ the outputs to be a struct (as per the RPC definition) so here we are adding variants of `invoke` that unwraps the returned object and gets the first value from that object.

For example, a provider with a schema `outputs: { type: "number" }` will have an invoke implementation that returns `{ __result: 42.0 }`, in these case (non-object return types) we use `InvokeSingle` instead of `Invoke`

> It doesn't matter what the name of the key is, we always get the first value by first key.

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Zaid Ajaj <zaid.naom@gmail.com>
bors bot added a commit that referenced this pull request Dec 7, 2022
11564: [sdk/dotnet/nodejs] Add InvokeSingle variants to dotnet and nodejs SDKs r=Zaid-Ajaj a=Zaid-Ajaj

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

Needed for #11418 where we have invoke calls that return a simple type (such as `number`) but the runtime and engine _require_ the outputs to be a struct (as per the RPC definition) so here we are adding variants of `invoke` that unwraps the returned object and gets the first value from that object.

For example, a provider with a schema `outputs: { type: "number" }` will have an invoke implementation that returns `{ __result: 42.0 }`, in these case (non-object return types) we use `InvokeSingle` instead of `Invoke`

> It doesn't matter what the name of the key is, we always get the first value by first key.

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Zaid Ajaj <zaid.naom@gmail.com>
bors bot added a commit that referenced this pull request Dec 7, 2022
11564: [sdk/dotnet/nodejs] Add InvokeSingle variants to dotnet and nodejs SDKs r=Zaid-Ajaj a=Zaid-Ajaj

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

Needed for #11418 where we have invoke calls that return a simple type (such as `number`) but the runtime and engine _require_ the outputs to be a struct (as per the RPC definition) so here we are adding variants of `invoke` that unwraps the returned object and gets the first value from that object.

For example, a provider with a schema `outputs: { type: "number" }` will have an invoke implementation that returns `{ __result: 42.0 }`, in these case (non-object return types) we use `InvokeSingle` instead of `Invoke`

> It doesn't matter what the name of the key is, we always get the first value by first key.

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


11581: Fix PCL binding of options.range = number r=Frassle a=Frassle

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

<!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. -->

Fixes the binding issue with `options { range = number }`.

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [x] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Zaid Ajaj <zaid.naom@gmail.com>
Co-authored-by: Fraser Waters <fraser@pulumi.com>
bors bot added a commit that referenced this pull request Dec 7, 2022
11564: [sdk/dotnet/nodejs] Add InvokeSingle variants to dotnet and nodejs SDKs r=Zaid-Ajaj a=Zaid-Ajaj

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

Needed for #11418 where we have invoke calls that return a simple type (such as `number`) but the runtime and engine _require_ the outputs to be a struct (as per the RPC definition) so here we are adding variants of `invoke` that unwraps the returned object and gets the first value from that object.

For example, a provider with a schema `outputs: { type: "number" }` will have an invoke implementation that returns `{ __result: 42.0 }`, in these case (non-object return types) we use `InvokeSingle` instead of `Invoke`

> It doesn't matter what the name of the key is, we always get the first value by first key.

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Zaid Ajaj <zaid.naom@gmail.com>
bors bot added a commit that referenced this pull request Dec 7, 2022
11564: [sdk/dotnet/nodejs] Add InvokeSingle variants to dotnet and nodejs SDKs r=Zaid-Ajaj a=Zaid-Ajaj

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

Needed for #11418 where we have invoke calls that return a simple type (such as `number`) but the runtime and engine _require_ the outputs to be a struct (as per the RPC definition) so here we are adding variants of `invoke` that unwraps the returned object and gets the first value from that object.

For example, a provider with a schema `outputs: { type: "number" }` will have an invoke implementation that returns `{ __result: 42.0 }`, in these case (non-object return types) we use `InvokeSingle` instead of `Invoke`

> It doesn't matter what the name of the key is, we always get the first value by first key.

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Zaid Ajaj <zaid.naom@gmail.com>
bors bot added a commit that referenced this pull request Dec 7, 2022
11564: [sdk/dotnet/nodejs] Add InvokeSingle variants to dotnet and nodejs SDKs r=Zaid-Ajaj a=Zaid-Ajaj

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

Needed for #11418 where we have invoke calls that return a simple type (such as `number`) but the runtime and engine _require_ the outputs to be a struct (as per the RPC definition) so here we are adding variants of `invoke` that unwraps the returned object and gets the first value from that object.

For example, a provider with a schema `outputs: { type: "number" }` will have an invoke implementation that returns `{ __result: 42.0 }`, in these case (non-object return types) we use `InvokeSingle` instead of `Invoke`

> It doesn't matter what the name of the key is, we always get the first value by first key.

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Zaid Ajaj <zaid.naom@gmail.com>
@Zaid-Ajaj
Copy link
Contributor Author

@iwahbe @Frassle I updated the PR such that it no longer creates diffs in unaffected TS files.

@Zaid-Ajaj Zaid-Ajaj requested a review from iwahbe December 8, 2022 11:09
bors bot added a commit that referenced this pull request Dec 9, 2022
11596: [sdk/gen] Avoid generating Result types for functions with empty outputs r=Zaid-Ajaj a=Zaid-Ajaj

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

<!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. -->

Part of #11418 where we shouldn't generate result types for function invokes that have no properties. 

This is a separate PR to showcase the exact changes required to improve the situation and reduce the diff from #11418

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Zaid Ajaj <zaid.naom@gmail.com>
Copy link
Member

@iwahbe iwahbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a couple of suggestions for code quality. My last area of concern is serialization, but I think that should be relatively quick to fix. I'm hoping there is a way to do it without manual re-implementation.

pkg/codegen/dotnet/gen.go Outdated Show resolved Hide resolved
pkg/codegen/nodejs/gen.go Show resolved Hide resolved
pkg/codegen/nodejs/gen.go Outdated Show resolved Hide resolved
pkg/codegen/nodejs/gen.go Outdated Show resolved Hide resolved
return len(*objectData) == 0, nil
}

func UnmarshalFunctionSpec(funcSpec *FunctionSpec, data map[string]RawMessage) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to custom unmarshal the entire FunctionSpec? This seems really error prone.

Also, does this need to be public?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I need to control how two fields are unmarshalled: Outputs and ReturnType, the former being derived from the latter. Same goes for marshalling. However, it does not need to be public. I will change that

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be done at the FunctionSpec level. I imagine it would be much easier and less error prone to do at the bind level.

P.S. The current implementation directly calls json.Unmarshal, which won't work for yaml.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be done at the FunctionSpec level. I imagine it would be much easier and less error prone to do at the bind level.

I tried removing the unmarshalling logic and instead only have custom marshalling for ReturnTypeSpec, however that doesn't work with YAML because if I put the attribute yaml:"outputs" on the ReturnTypeSpec, then it fails saying that there are duplicate outputs definitions because the Outputs fields is still there. It can be simplified when we remove Outputs entirely

P.S. The current implementation directly calls json.Unmarshal, which won't work for yaml.

It works because it uses map[string]RawMessage as an intermediate data structure for both JSON and YAML. See unit tests I've added in schema_test.go for marshalling and unmarshalling FunctionSpec

pkg/codegen/schema/schema.go Outdated Show resolved Hide resolved
Copy link
Member

@iwahbe iwahbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm satisfied. LGTM!

@Zaid-Ajaj
Copy link
Contributor Author

bors merge

bors bot added a commit that referenced this pull request Dec 16, 2022
11418: Simplified invokes: SDK-gen and program-gen implementation for dotnet and nodejs r=Zaid-Ajaj a=Zaid-Ajaj

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

This PR implements simplified invoke gen for both SDKs and PCL programs by allowing invokes to:
 - Accepts multi arguments as inputs (instead of a bag of properties)
 - Return a single value as output (instead of a bag of outputs)

Related to #7435 

This implementation handles dotnet and nodejs. Python and Go can be implementation on a separate pass. Currently both python and go will fail generation (sdk/program) when encountering simplified invokes

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [x] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Zaid Ajaj <zaid.naom@gmail.com>
@bors
Copy link
Contributor

bors bot commented Dec 16, 2022

Timed out.

@Zaid-Ajaj
Copy link
Contributor Author

bors retry

@bors
Copy link
Contributor

bors bot commented Dec 16, 2022

Build succeeded:

@bors bors bot merged commit 68bf791 into master Dec 16, 2022
@bors bors bot deleted the simplified-invoke-gen branch December 16, 2022 16:04
bors bot added a commit that referenced this pull request Dec 21, 2022
11701: Revert "Simplified invokes: SDK-gen and program-gen implementation for dotnet and nodejs" r=iwahbe a=AaronFriel

Reverts #11418.

Fixes #11699. The addition of the `ReturnType` field on `schema.FunctionSpec` broke the API contract between Pulumi's codegen package and tfbridge and other tools.

From my comment on #11699.

> I was able to bisect pu/pu to a commit that had the issue, but couldn't reproduce the behavior with a synthetic schema. PR #11418 should be reverted because it introduces the breaking change, and before that PR is reintroduced, the breaking change to the schema should be addressed.
> 
> Notes on root causing:
> 
> Adding an unserialized `ReturnType` field on the `schema.FunctionSpec` type was a breaking change in the API contract with the tfgen bridge and any other tools that generate a PackageSpec directly (without marshaling/unmarshaling) before binding it and calling `GeneratePackage`.
> 
> In [cd6f658](cd6f658) we can see that a regression test fails to catch this case, the generated code is correct and matches the "before" case! That's because the regression tests in Pulumi load schemas from JSON, so the `ReturnType` field is populated. That occurs in the implementation of `unmarshalFunctionSpec` at line 1656:
> 
> https://github.com/pulumi/pulumi/blob/78c9bf4ee4def5130bfd5b29346ece7c61cec08a/pkg/codegen/schema/schema.go#L1649-L1658
> 
> This function in the bridge is unaware of the new field, and so it only populates `Outputs`.
> 
> https://github.com/pulumi/pulumi-terraform-bridge/blob/36b10921bfd25a5cabf0a342d0e449278a256a8b/pkg/tfgen/generate_schema.go#L607-L638




Co-authored-by: Aaron Friel <mayreply@aaronfriel.com>
bors bot added a commit that referenced this pull request Dec 21, 2022
11701: Revert "Simplified invokes: SDK-gen and program-gen implementation for dotnet and nodejs" r=iwahbe a=AaronFriel

Reverts #11418.

Fixes #11699. The addition of the `ReturnType` field on `schema.FunctionSpec` broke the API contract between Pulumi's codegen package and tfbridge and other tools.

From my comment on #11699.

> I was able to bisect pu/pu to a commit that had the issue, but couldn't reproduce the behavior with a synthetic schema. PR #11418 should be reverted because it introduces the breaking change, and before that PR is reintroduced, the breaking change to the schema should be addressed.
> 
> Notes on root causing:
> 
> Adding an unserialized `ReturnType` field on the `schema.FunctionSpec` type was a breaking change in the API contract with the tfgen bridge and any other tools that generate a PackageSpec directly (without marshaling/unmarshaling) before binding it and calling `GeneratePackage`.
> 
> In [cd6f658](cd6f658) we can see that a regression test fails to catch this case, the generated code is correct and matches the "before" case! That's because the regression tests in Pulumi load schemas from JSON, so the `ReturnType` field is populated. That occurs in the implementation of `unmarshalFunctionSpec` at line 1656:
> 
> https://github.com/pulumi/pulumi/blob/78c9bf4ee4def5130bfd5b29346ece7c61cec08a/pkg/codegen/schema/schema.go#L1649-L1658
> 
> This function in the bridge is unaware of the new field, and so it only populates `Outputs`.
> 
> https://github.com/pulumi/pulumi-terraform-bridge/blob/36b10921bfd25a5cabf0a342d0e449278a256a8b/pkg/tfgen/generate_schema.go#L607-L638




Co-authored-by: Aaron Friel <mayreply@aaronfriel.com>
@iwahbe iwahbe restored the simplified-invoke-gen branch December 21, 2022 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants