Skip to content

Mixin method remap: fix desc being dropped & support wildcards#164

Open
Moulberry wants to merge 8 commits intoFabricMC:masterfrom
Moulberry:mixin_method_remap_fixes
Open

Mixin method remap: fix desc being dropped & support wildcards#164
Moulberry wants to merge 8 commits intoFabricMC:masterfrom
Moulberry:mixin_method_remap_fixes

Conversation

@Moulberry
Copy link
Copy Markdown

@Moulberry Moulberry commented Apr 26, 2026

Fixed descriptor being dropped when input had descriptor

Descriptor should be used in output if and only if either:

  1. Descriptor was present in input
  2. Descriptor is necessary to disambiguate

Added support for resolving multiple targets when using wildcard

See remapSeparateRemappedName test for example

After the rewrite commit, this addresses a lot of additional problems and edge cases brought up by LlamaLad7 on discord

byte[] data;
private ClassInstance mrjOrigin;
private final Map<String, MemberInstance> members = new HashMap<>(); // methods and fields are distinct due to their different desc separators
private final Map<String, MemberInstance> members = new LinkedHashMap<>(); // methods and fields are distinct due to their different desc separators
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Should I sort based on TrMethod#getIndex or is making this a LinkedHashMap sufficient?

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.

This is probably fine

Comment on lines +255 to +259
String quantifier = info.getQuantifier();
if (quantifier.equals("*") || quantifier.startsWith("{0,")) {
quantifier = "";
}
list.add(new MemberInfo(mappedOwner, mappedName, quantifier, mappedDesc));
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.

Can you elaborate on the goal behind these lines

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.

Regarding quantifiers in this case, if the quantifier has a minimum of 1 or more, we cannot replicate this behaviour when emitting multiple name + desc pairs, so we should probably error

In all other cases we should just be able to keep the original quantifier

Copy link
Copy Markdown
Author

@Moulberry Moulberry Apr 26, 2026

Choose a reason for hiding this comment

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

The quantifier is stripped to match the behaviour from this PR before the rewrite (2e1a11b)

so if we know it's going to be * that we're inserting, we may as well just not

If we're passing a desc I probably wouldn't use a quantifier

I don't even really know what the point of the minimum is inside mixins itself, so I don't even know what behaviour we would need to be replicating here

Okay yeah all it does is throw an error: https://github.com/FabricMC/Mixin/blob/main/src/main/java/org/spongepowered/asm/mixin/injection/selectors/TargetSelectors.java#L248

If there's a quantifier of 1 or more I'm not sure if it's better to show a warning, remove the quantifier and continue or error and not remap at all. I'd lean towards the first option

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.

I could take or leave the quantifier stripping given we're now handling all kinds of quantifier, but if we're going to keep it presumably we want to handle startsWith("{,") too

Copy link
Copy Markdown
Author

@Moulberry Moulberry Apr 26, 2026

Choose a reason for hiding this comment

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

True yes startsWith("{,") should also be included, technically { followed by any whitespace followed by , also works

Copy link
Copy Markdown
Author

@Moulberry Moulberry Apr 26, 2026

Choose a reason for hiding this comment

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

Actually I just realized that, because of how the code works, using a max specifier like method{0,4} will always just try to replace it with the first 4 methods w/ descriptors. canInject() needs to be made smarter so it knows it can ignore methods if their match index is >4

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