Skip to content

Conversation

lsrcz
Copy link
Collaborator

@lsrcz lsrcz commented Sep 13, 2025

This PR introduces ReplaceInvocationsInModule. It operates on TypecheckedModule since type information is required to perform the transformation.

ReplaceInvocationsInModule rewrites all invocations that matches a given callee function and parameter list to different callees and parameter lists. This is particularly useful for tools I am building for transforming a DSLX file into a fully monomorphized form.

The result is a new TypecheckedModule.

@lsrcz lsrcz requested a review from cdleary September 13, 2025 03:44
Copy link
Collaborator

@cdleary cdleary left a comment

Choose a reason for hiding this comment

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

LGTM with comments addressed

return ParseTypecheckResult{.import_data = std::move(import_data), .tm = std::move(tm)};
}

TEST(ReplaceInvocationsTest, NonParametricSimpleReplacement) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would suggest parameterizing these tests to run on both typecheck versions so they don't become tech debt for the deletion of TIv1. The contract for what TI needs to include in TypeInfo is not always clear, so any new use outside of IR converter could encounter subtle differences.

Also as a side note, once we delete TIv1 we can probably expose better data from TIv2 for this use case (e.g. TIv2 keeps parametric envs in ExprOrType format natively).

Copy link
Collaborator

Choose a reason for hiding this comment

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

There are actually a couple of tests in here that fail with TIv2 and so are failing internally at Google:

[ PASSED ] 23 tests.
[ FAILED ] 2 tests, listed below:
[ FAILED ] ReplaceInvocationsTest.ParametricEnumUseImportExplicitReplacement
[ FAILED ] ReplaceInvocationsTest.ParametricToEnvNonEnumTypeAnnotationErrors

Could you either parameterize it or do a quick hack where you change kDefaultTypecheckVersion in parse_and_typecheck.h and run it that way to debug? Let me know if you need help investigating.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I see. Let me have a look when I got some time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants