Avoid unnecessarily creating TypeReferences on import #970

Open
mrvoorhe wants to merge 1 commit from Unity-Technologies/avoid-unnecessary-import into master
mrvoorhe commented 2025-05-02 12:35:26 -05:00 (Migrated from github.com)

When importing a TypeSpecification, an element type or generic argument could be a TypeDefinition within the current module. When this happens, a new TypeReference does not need to be created. This can lead to a TypeReference being added to the typeref table for a type that is already in the assembly. This seems to hold together, although I don't think it's ideal. And really my goal is to avoid failing this logic in the ILLink test framework github.com/dotnet/runtime@cec44d6dff/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs (L56)

This fix superceeds https://github.com/jbevain/cecil/pull/138. I've left that fix in since that API is exposed publically and others could be depending on it.

While I was adjusting this logic, I thought I would apply the same logic to a TypeReference where the scope is the current modules assembly. This case is a bit contrived as it shouldn't happen, but if it did, it would result in the same circular reference problem as https://github.com/jbevain/cecil/pull/138

When importing a TypeSpecification, an element type or generic argument could be a TypeDefinition within the current module. When this happens, a new TypeReference does not need to be created. This can lead to a TypeReference being added to the typeref table for a type that is already in the assembly. This seems to hold together, although I don't think it's ideal. And really my goal is to avoid failing this logic in the ILLink test framework https://github.com/dotnet/runtime/blob/cec44d6dff9de95421f199f65bbc80b8296da1c0/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs#L56 This fix superceeds https://github.com/jbevain/cecil/pull/138. I've left that fix in since that API is exposed publically and others could be depending on it. While I was adjusting this logic, I thought I would apply the same logic to a TypeReference where the scope is the current modules assembly. This case is a bit contrived as it shouldn't happen, but if it did, it would result in the same circular reference problem as https://github.com/jbevain/cecil/pull/138
mrvoorhe commented 2025-05-12 09:58:27 -05:00 (Migrated from github.com)

@jbevain I don't think the linux CI failure is related to my changes.

@jbevain I don't think the linux CI failure is related to my changes.
samuraiGH commented 2025-07-20 12:44:14 -05:00 (Migrated from github.com)

@jbevain I don't think the linux CI failure is related to my changes.

This is related to actions/runner-images#11101

I fixed it in #972

> @jbevain I don't think the linux CI failure is related to my changes. This is related to actions/runner-images#11101 I fixed it in #972
samuraiGH commented 2025-09-11 13:02:27 -05:00 (Migrated from github.com)

Now you can just sync your branch

Now you can just sync your branch
mrvoorhe commented 2025-09-12 07:58:22 -05:00 (Migrated from github.com)

@jbevain What do you think about these changes?

@jbevain What do you think about these changes?
This pull request is broken due to missing fork information.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'Unity-Technologies/avoid-unnecessary-import:Unity-Technologies/avoid-unnecessary-import'
git switch 'Unity-Technologies/avoid-unnecessary-import'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'master'
git merge --no-ff 'Unity-Technologies/avoid-unnecessary-import'
git switch 'Unity-Technologies/avoid-unnecessary-import'
git rebase 'master'
git switch 'master'
git merge --ff-only 'Unity-Technologies/avoid-unnecessary-import'
git switch 'Unity-Technologies/avoid-unnecessary-import'
git rebase 'master'
git switch 'master'
git merge --no-ff 'Unity-Technologies/avoid-unnecessary-import'
git switch 'master'
git merge --squash 'Unity-Technologies/avoid-unnecessary-import'
git switch 'master'
git merge --ff-only 'Unity-Technologies/avoid-unnecessary-import'
git switch 'master'
git merge 'Unity-Technologies/avoid-unnecessary-import'
git push origin 'master'
Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-jbevain/cecil!970
No description provided.