Skip to content

More precise use-defs in rename code#1113

Open
sungshik wants to merge 4 commits into
mainfrom
more-precise-usedefs-in-rename
Open

More precise use-defs in rename code#1113
sungshik wants to merge 4 commits into
mainfrom
more-precise-usedefs-in-rename

Conversation

@sungshik

Copy link
Copy Markdown
Contributor

This PR updates the rename code to make it compatible with companion PR usethesource/rascal#2801, which updates the computation of use-def relations.

@sungshik sungshik changed the title More precise usedefs in rename More precise use-defs in rename code Jun 10, 2026

@toinehartman toinehartman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good stuff! I cannot completely understand how these changes will influence uses of the use-def relation that are not used to index tm.definitions.

I would expect the main benefit of this TModel extension to be that we can override (one of) the following functions from the rename framework. As you mentioned off-line, this is something we can address in the future.

I think with the addition of tm.define2id, we should be able to implement the following without any tree visits.

https://github.com/usethesource/typepal/blob/bde05af0748c6200f72403ad4f6ec420ccb051f8/src/analysis/typepal/refactor/Rename.rsc#L430-L437

Or even the (only) function that calls the above:

https://github.com/usethesource/typepal/blob/bde05af0748c6200f72403ad4f6ec420ccb051f8/src/analysis/typepal/refactor/Rename.rsc#L348-L372

visit (tr) {
case (Expression) `<Expression e>(<{Expression ","}* _> <KeywordArguments[Expression] kwArgs>)`: {
funcKwDefs = keywordFormalDefs[tm.useDef[e.src]];
funcKwDefs = keywordFormalDefs[getUseDef(tm)[e.src]];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It seems expensive to do this inside the visit, but since we're modifying the use-defs inside this visit as well, it might be necessary to do it here...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point! The use-defs are modified during the visit, but as far as I understand the code: (a) entries are only created, not deleted, not updated; (b) none of the created entries have e.src as use. So, I think it is safe to call getUseDef only once, before the visit, because the subset of it that is read during the visit doesn't change.

I made the change, ran the tests, and everything seems fine. What do you think?

@sonarqubecloud

Copy link
Copy Markdown

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.

2 participants