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] Fix emitted import statements in generated programs such that imports with the same symbol are fully qualified #1573

Merged
merged 8 commits into from
Jan 7, 2025

Conversation

Zaid-Ajaj
Copy link
Contributor

Description

Fix emitted import statements in generated programs such that imports with the same symbol are fully qualified

if we have two imports such as the following:

  • com.pulumi.my_package.ResourceType
  • com.pulumi.your_package.ResourceType

then we shouldn't generate import statements for them instead, we use the fully qualified name at the usage site.

Unskips l2-failed-create-continue-on-error

Fixes #1558

@Zaid-Ajaj Zaid-Ajaj requested a review from a team as a code owner January 6, 2025 23:44
Comment on lines 762 to 769
for _, importDefA := range importStatements {
for _, importDefB := range importStatements {
if importMember(importDefA) == importMember(importDefB) && importDefA != importDefB {
importsWithDuplicateName.Add(importDefA)
importsWithDuplicateName.Add(importDefB)
}
}
}

Choose a reason for hiding this comment

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

I'm kind of not a fan of this n^2 approach when we can use a set of importMembers.

what if it is a super large program with many files each with tons of imports? It's premature optimization but seems reasonable to turn into a set check

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've optimized the lookup ✅ can you have another look?

}

g.importStatements = importStatements

Choose a reason for hiding this comment

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

this makes me think the name is misleading. They are not import statements they are dependencies because genImport is only called for non conflicting symbols

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed to emittedImportTypeSymbols

Comment on lines 857 to 863
for _, importStatement := range g.importStatements {
// if there is an import statement that ends with the same member name
// return the fully qualified resource name
if strings.HasSuffix(importStatement, "."+member) && pulumiImport(pkg, module, member) != importStatement {
return pulumiImport(pkg, module, member)
}
}

Choose a reason for hiding this comment

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

instead of saving all import statements wouldn't it also be better to just save a set of all types that need to be fully qualified and just check this isn't in that set?

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 ✅

@Zaid-Ajaj Zaid-Ajaj merged commit 784fa7b into main Jan 7, 2025
23 checks passed
@Zaid-Ajaj Zaid-Ajaj deleted the zaid/convert-intrinsic branch January 7, 2025 04:18
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.

[programgen] Duplicate identifiers aren't fully qualified
2 participants