Skip to content

Commit

Permalink
Fix random mixin members not getting remapped due to concurrency issu…
Browse files Browse the repository at this point in the history
…es (#115)

* Fix random mixin members not getting remapped due to concurrency issues

* spotlessApply
  • Loading branch information
Yeregorix authored Nov 3, 2023
1 parent 36ef1ec commit b0b1aa1
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2016, 2018, Player, asie
* Copyright (c) 2021, FabricMC
* Copyright (c) 2021, 2023, FabricMC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
Expand All @@ -18,12 +18,12 @@

package net.fabricmc.tinyremapper.extension.mixin;

import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.function.Consumer;

import org.objectweb.asm.ClassVisitor;
Expand All @@ -43,7 +43,7 @@
*/
public class MixinExtension implements TinyRemapper.Extension {
private final Logger logger;
private final Map<Integer, List<Consumer<CommonData>>> tasks;
private final Map<Integer, Collection<Consumer<CommonData>>> tasks;
private final Set<AnnotationTarget> targets;

public enum AnnotationTarget {
Expand Down Expand Up @@ -76,7 +76,7 @@ public MixinExtension(Set<AnnotationTarget> targets) {

public MixinExtension(Set<AnnotationTarget> targets, Logger.Level logLevel) {
this.logger = new Logger(logLevel);
this.tasks = new HashMap<>();
this.tasks = new ConcurrentHashMap<>();
this.targets = targets;
}

Expand All @@ -95,8 +95,7 @@ public void attach(Builder builder) {
* Hard-target: Shadow, Overwrite, Accessor, Invoker, Implements.
*/
private ClassVisitor analyzeVisitor(int mrjVersion, String className, ClassVisitor next) {
tasks.putIfAbsent(mrjVersion, new ArrayList<>());
return new HardTargetMixinClassVisitor(tasks.get(mrjVersion), next);
return new HardTargetMixinClassVisitor(tasks.computeIfAbsent(mrjVersion, k -> new ConcurrentLinkedQueue<>()), next);
}

private void stateProcessor(TrEnvironment environment) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2016, 2018, Player, asie
* Copyright (c) 2021, FabricMC
* Copyright (c) 2021, 2023, FabricMC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
Expand All @@ -19,6 +19,7 @@
package net.fabricmc.tinyremapper.extension.mixin.hard;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
Expand All @@ -41,7 +42,7 @@
import net.fabricmc.tinyremapper.extension.mixin.hard.data.SoftInterface;

public class HardTargetMixinClassVisitor extends ClassVisitor {
private final List<Consumer<CommonData>> tasks;
private final Collection<Consumer<CommonData>> tasks;
private MxClass _class;

// @Mixin
Expand All @@ -51,7 +52,7 @@ public class HardTargetMixinClassVisitor extends ClassVisitor {
// @Implements
private final List<SoftInterface> interfaces = new ArrayList<>();

public HardTargetMixinClassVisitor(List<Consumer<CommonData>> tasks, ClassVisitor delegate) {
public HardTargetMixinClassVisitor(Collection<Consumer<CommonData>> tasks, ClassVisitor delegate) {
super(Constant.ASM_VERSION, delegate);
this.tasks = Objects.requireNonNull(tasks);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2016, 2018, Player, asie
* Copyright (c) 2021, FabricMC
* Copyright (c) 2021, 2023, FabricMC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
Expand All @@ -18,6 +18,7 @@

package net.fabricmc.tinyremapper.extension.mixin.hard;

import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;
Expand All @@ -32,13 +33,13 @@
import net.fabricmc.tinyremapper.extension.mixin.hard.annotation.ShadowAnnotationVisitor;

class HardTargetMixinFieldVisitor extends FieldVisitor {
private final List<Consumer<CommonData>> tasks;
private final Collection<Consumer<CommonData>> tasks;
private final MxMember field;

private final boolean remap;
private final List<String> targets;

HardTargetMixinFieldVisitor(List<Consumer<CommonData>> tasks, FieldVisitor delegate, MxMember field,
HardTargetMixinFieldVisitor(Collection<Consumer<CommonData>> tasks, FieldVisitor delegate, MxMember field,
boolean remap, List<String> targets) {
super(Constant.ASM_VERSION, delegate);
this.tasks = Objects.requireNonNull(tasks);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2016, 2018, Player, asie
* Copyright (c) 2021, FabricMC
* Copyright (c) 2021, 2023, FabricMC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
Expand All @@ -18,6 +18,7 @@

package net.fabricmc.tinyremapper.extension.mixin.hard;

import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;
Expand All @@ -35,13 +36,13 @@
import net.fabricmc.tinyremapper.extension.mixin.hard.annotation.ShadowAnnotationVisitor;

class HardTargetMixinMethodVisitor extends MethodVisitor {
private final List<Consumer<CommonData>> data;
private final Collection<Consumer<CommonData>> data;
private final MxMember method;

private final boolean remap;
private final List<String> targets;

HardTargetMixinMethodVisitor(List<Consumer<CommonData>> data, MethodVisitor delegate, MxMember method, boolean remap, List<String> targets) {
HardTargetMixinMethodVisitor(Collection<Consumer<CommonData>> data, MethodVisitor delegate, MxMember method, boolean remap, List<String> targets) {
super(Constant.ASM_VERSION, delegate);
this.data = Objects.requireNonNull(data);
this.method = Objects.requireNonNull(method);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2016, 2018, Player, asie
* Copyright (c) 2021, FabricMC
* Copyright (c) 2021, 2023, FabricMC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
Expand Down Expand Up @@ -42,14 +42,14 @@
* do not lower the first character of the remaining part.
*/
public class AccessorAnnotationVisitor extends AnnotationVisitor {
private final List<Consumer<CommonData>> tasks;
private final Collection<Consumer<CommonData>> tasks;
private final MxMember method;
private final List<String> targets;

private boolean remap;
private boolean isSoftTarget;

public AccessorAnnotationVisitor(List<Consumer<CommonData>> tasks, AnnotationVisitor delegate, MxMember method, boolean remap, List<String> targets) {
public AccessorAnnotationVisitor(Collection<Consumer<CommonData>> tasks, AnnotationVisitor delegate, MxMember method, boolean remap, List<String> targets) {
super(Constant.ASM_VERSION, delegate);

this.tasks = Objects.requireNonNull(tasks);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2016, 2018, Player, asie
* Copyright (c) 2021, FabricMC
* Copyright (c) 2021, 2023, FabricMC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
Expand Down Expand Up @@ -81,7 +81,7 @@ public AnnotationVisitor visitAnnotation(String name, String descriptor) {
}
}

public static void visitMethod(List<Consumer<CommonData>> tasks, MxMember method, List<SoftInterface> interfaces) {
public static void visitMethod(Collection<Consumer<CommonData>> tasks, MxMember method, List<SoftInterface> interfaces) {
tasks.add(data -> new SoftImplementsMappable(data, method, interfaces).result());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2016, 2018, Player, asie
* Copyright (c) 2021, FabricMC
* Copyright (c) 2021, 2023, FabricMC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
Expand Down Expand Up @@ -40,14 +40,14 @@
* do not lower the first character of the remaining part.
*/
public class InvokerAnnotationVisitor extends AnnotationVisitor {
private final List<Consumer<CommonData>> tasks;
private final Collection<Consumer<CommonData>> tasks;
private final MxMember method;
private final List<String> targets;

private boolean remap;
private boolean isSoftTarget;

public InvokerAnnotationVisitor(List<Consumer<CommonData>> tasks, AnnotationVisitor delegate, MxMember method, boolean remap, List<String> targets) {
public InvokerAnnotationVisitor(Collection<Consumer<CommonData>> tasks, AnnotationVisitor delegate, MxMember method, boolean remap, List<String> targets) {
super(Constant.ASM_VERSION, delegate);

this.tasks = Objects.requireNonNull(tasks);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2016, 2018, Player, asie
* Copyright (c) 2021, FabricMC
* Copyright (c) 2021, 2023, FabricMC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
Expand Down Expand Up @@ -38,13 +38,13 @@
* an error message will show up and the behaviour is undefined.
*/
public class OverwriteAnnotationVisitor extends AnnotationVisitor {
private final List<Consumer<CommonData>> tasks;
private final Collection<Consumer<CommonData>> tasks;
private final MxMember method;
private final List<String> targets;

private boolean remap;

public OverwriteAnnotationVisitor(List<Consumer<CommonData>> tasks, AnnotationVisitor delegate, MxMember method, boolean remap, List<String> targets) {
public OverwriteAnnotationVisitor(Collection<Consumer<CommonData>> tasks, AnnotationVisitor delegate, MxMember method, boolean remap, List<String> targets) {
super(Constant.ASM_VERSION, delegate);

this.tasks = Objects.requireNonNull(tasks);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2016, 2018, Player, asie
* Copyright (c) 2021, FabricMC
* Copyright (c) 2021, 2023, FabricMC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
Expand Down Expand Up @@ -40,14 +40,14 @@
* If a prefix is detected, will only attempt to match the prefix-stripped name.
*/
public class ShadowAnnotationVisitor extends AnnotationVisitor {
private final List<Consumer<CommonData>> tasks;
private final Collection<Consumer<CommonData>> tasks;
private final MxMember member;
private final List<String> targets;

private boolean remap;
private String prefix;

public ShadowAnnotationVisitor(List<Consumer<CommonData>> tasks, AnnotationVisitor delegate, MxMember member, boolean remap, List<String> targets) {
public ShadowAnnotationVisitor(Collection<Consumer<CommonData>> tasks, AnnotationVisitor delegate, MxMember member, boolean remap, List<String> targets) {
super(Constant.ASM_VERSION, delegate);
this.tasks = Objects.requireNonNull(tasks);
this.member = Objects.requireNonNull(member);
Expand Down

0 comments on commit b0b1aa1

Please sign in to comment.