Skip to content

Commit

Permalink
Disable signature merging unless decompiler is active, closes SpongeP…
Browse files Browse the repository at this point in the history
  • Loading branch information
Mumfrey committed Jul 3, 2018
1 parent 09b2a04 commit 2c72246
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,15 @@ public static enum Option {
*/
DEBUG_EXPORT_DECOMPILE_THREADED(Option.DEBUG_EXPORT_DECOMPILE, Inherit.ALLOW_OVERRIDE, "async"),

/**
* By default, if the runtime export decompiler is active, mixin generic
* signatures are merged into target classes. However this can cause
* problems with some runtime subsystems which attempt to reify generics
* using the signature data. Set this option to <tt>false</tt> to
* disable generic signature merging.
*/
DEBUG_EXPORT_DECOMPILE_MERGESIGNATURES(Option.DEBUG_EXPORT_DECOMPILE, Inherit.ALLOW_OVERRIDE, "mergeGenericSignatures"),

/**
* Run the CheckClassAdapter on all classes after mixins are applied,
* also enables stricter checks on mixins for use at dev-time, promotes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.transformer.ClassInfo.Field;
import org.spongepowered.asm.mixin.transformer.ext.extensions.ExtensionClassExporter;
import org.spongepowered.asm.mixin.transformer.meta.MixinMerged;
import org.spongepowered.asm.mixin.transformer.meta.MixinRenamed;
import org.spongepowered.asm.mixin.transformer.throwables.InvalidMixinException;
Expand Down Expand Up @@ -237,10 +238,22 @@ public String toString() {
*/
protected final Profiler profiler = MixinEnvironment.getProfiler();

/**
* Flag to track whether signatures from applied mixins should be merged
* into target classes. This is only true when the runtime decompiler is
* active. If this is disabled, signatures on merged mixin methods are
* stripped instead of remapped.
*/
protected final boolean mergeSignatures;

MixinApplicatorStandard(TargetClassContext context) {
this.context = context;
this.targetName = context.getClassName();
this.targetClass = context.getClassNode();

ExtensionClassExporter exporter = context.getExtensions().<ExtensionClassExporter>getExtension(ExtensionClassExporter.class);
this.mergeSignatures = exporter.isDecompilerActive()
&& MixinEnvironment.getCurrentEnvironment().getOption(Option.DEBUG_EXPORT_DECOMPILE_MERGESIGNATURES);
}

/**
Expand Down Expand Up @@ -316,7 +329,9 @@ protected final void applyMixin(MixinTargetContext mixin, ApplicatorPass pass) {
}

protected void applySignature(MixinTargetContext mixin) {
this.context.mergeSignature(mixin.getSignature());
if (this.mergeSignatures) {
this.context.mergeSignature(mixin.getSignature());
}
}

/**
Expand Down Expand Up @@ -389,6 +404,16 @@ protected void mergeNewFields(MixinTargetContext mixin) {
if (target == null) {
// This is just a local field, so add it
this.targetClass.fields.add(field);

if (field.signature != null) {
if (this.mergeSignatures) {
SignatureVisitor sv = mixin.getSignature().getRemapper();
new SignatureReader(field.signature).accept(sv);
field.signature = sv.toString();
} else {
field.signature = null;
}
}
}
}
}
Expand Down Expand Up @@ -468,9 +493,13 @@ protected void mergeMethod(MixinTargetContext mixin, MethodNode method) {
mixin.methodMerged(method);

if (method.signature != null) {
SignatureVisitor sv = mixin.getSignature().getRemapper();
new SignatureReader(method.signature).accept(sv);
method.signature = sv.toString();
if (this.mergeSignatures) {
SignatureVisitor sv = mixin.getSignature().getRemapper();
new SignatureReader(method.signature).accept(sv);
method.signature = sv.toString();
} else {
method.signature = null;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ public ExtensionClassExporter(MixinEnvironment env) {
}
}

public boolean isDecompilerActive() {
return this.decompiler != null;
}

private IDecompiler initDecompiler(MixinEnvironment env, File outputPath) {
if (!env.getOption(Option.DEBUG_EXPORT_DECOMPILE)) {
return null;
Expand Down

0 comments on commit 2c72246

Please sign in to comment.