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

[program-gen] Emit invoke options and invoke output options in generated programs #1586

Merged
merged 12 commits into from
Jan 14, 2025

Conversation

Zaid-Ajaj
Copy link
Contributor

Built on top of #1585 in order to generate InvokeOptions for invoke calls.

  • Fixes Fix l2-resource-config / plugin download URL code generation #1566
  • Unskips l2-invoke-options
  • Implements optimized import handling when encountering function calls
  • Implements lambda parameter shadowing when generating apply(...)
    • data.applyValue(data -> data.result()) becomes data.applyValue(_data -> _data.result())
  • Fixes apply(...) calls for invokes when used in output variables

This PR prepares program-gen and sdk to handle l2-invoke-options-depends-on which currently generate correct programs but fails the actual conformance test where the invoke has no dependencies cc @julienp

@Zaid-Ajaj Zaid-Ajaj requested a review from a team as a code owner January 10, 2025 20:44
// i.e. (new InvokeOutputOptions.Builder()).dependsOn(resource).build()
functionImports.Add("com.pulumi.deployment.InvokeOutputOptions")
} else if len(call.Args) == 3 {
functionImports.Add("com.pulumi.deployment.InvokeOptions")
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe tweak this to just check the length once?

if len(call.Args) == 3 {
  // Comments as above etc.
  if containsDependsOnInvokeOption(call.Args[2]) {

  } else {

  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done ✅

func inspectFunctionCall(nodes []pcl.Node, inspect func(*model.FunctionCallExpression)) {
for _, node := range nodes {
diags := node.VisitExpressions(model.IdentityVisitor, func(x model.Expression) (model.Expression, hcl.Diagnostics) {
// Ignore the node if it is not a call to invoke.
Copy link
Contributor

Choose a reason for hiding this comment

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

I reckon just add a doc comment to the function explaining what it's doing, then you don't need this line (which I think applies to more than just invokes anyway -- any built-in would also trigger it, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added better docs ✅

// in this case we rename the parameter to _data
// it becomes data.applyValue(_data -> _data.result())
paramName := expr.Signature.Parameters[0].Name
modifiedParamName := "_" + paramName
Copy link
Contributor

Choose a reason for hiding this comment

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

I suspect this isn't safe in general (there might be another variable named _data in scope, for instance) but it's probably a good starting point for now. Probably should add another conformance test around shadowing etc. in future.

@Zaid-Ajaj Zaid-Ajaj merged commit a3a2508 into main Jan 14, 2025
23 checks passed
@Zaid-Ajaj Zaid-Ajaj deleted the zaid/invoke-options-program-gen branch January 14, 2025 15:30
lunaris pushed a commit that referenced this pull request Jan 15, 2025
…esulting output (#1591)

Built on top of #1586

Fixes the SDK in invokes where explicit dependencies of output invokes
should be included in the resulting Output instance

Unskips `l2-invoke-options-depends-on` conformance test that asserts the
behaviour
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.

Fix l2-resource-config / plugin download URL code generation
2 participants