Skip to content

Commit

Permalink
Merge remote-tracking branch 'fabric/main' into lunar
Browse files Browse the repository at this point in the history
  • Loading branch information
phase committed May 20, 2024
2 parents ff71c64 + 2f35deb commit d51f57a
Show file tree
Hide file tree
Showing 26 changed files with 439 additions and 94 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ jobs:
env:
MAVEN_URL: ${{ secrets.MAVEN_URL }}
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
MAVEN_CENTRAL_URL: ${{ secrets.MAVEN_CENTRAL_URL }}
MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
MAVEN_CENTRAL_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
SIGNING_SERVER: ${{ secrets.SIGNING_SERVER }}
SIGNING_PGP_KEY: ${{ secrets.SIGNING_PGP_KEY }}
12 changes: 8 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ sourceSets {
ext.languageVersion = langVer
ext.modularityExcluded = true // don't add ourselves
}
modularityDummy {}
}

// Because Mixin aims to support a variety of environments, we have to be able to run with older versions of GSON and Guava that lack official module
Expand All @@ -160,6 +161,9 @@ dependencies {
def log4j2 = 'org.apache.logging.log4j:log4j-core:2.11.2'
def gson = 'com.google.code.gson:gson:2.2.4'

// stagingJar guava
// stagingJar gson

implementation guava
implementation log4j2
implementation gson
Expand Down Expand Up @@ -348,7 +352,7 @@ if (JavaVersion.current().isJava8Compatible()) {
}

task stagingJar(type: ShadowJar) {
sourceSets.findAll { !(it.name =~ /example|test/) }.each {
sourceSets.findAll { !(it.name =~ /example|test|modularityDummy/) }.each {
from it.output
}
configurations = [project.configurations.stagingJar]
Expand All @@ -370,7 +374,7 @@ task stagingJar(type: ShadowJar) {
if (project.doSignJar) {
archiveClassifier.set('unsigned')
}

mergeServiceFiles()
}

Expand All @@ -385,7 +389,7 @@ shadowJar {
build.dependsOn(shadowJar)

if (project.doSignJar) {
// Define signjar task
// Define signjar task
task signJar() {
inputs.files(stagingJar.outputs)
outputs.files stagingJar.outputs.files.collect {
Expand Down Expand Up @@ -434,7 +438,7 @@ task javadocJar(type: Jar, dependsOn: javadoc) {
artifacts {
if (project.doSignJar) {
archives signJar.outputs.files[0]
} else {
} else {
archives stagingJar
}
archives sourceJar
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ packaging=jar
description=Mixin
url=https://www.spongepowered.org
organization=SpongePowered
buildVersion=0.8.5+lunar.3
buildVersion=0.8.5+lunar.4
buildType=RELEASE
asmVersion=9.6
legacyForgeAsmVersion=5.0.3
Expand Down
10 changes: 10 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
pluginManagement {
repositories {
gradlePluginPortal()
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
}
}

rootProject.name = name
59 changes: 58 additions & 1 deletion src/main/java/org/spongepowered/asm/mixin/MixinEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,64 @@ boolean isSupported() {
return JavaVersion.current() >= JavaVersion.JAVA_18 && ASM.isAtLeastVersion(9, 2);
}

};
},

/**
* Java 19 or above is required
*/
JAVA_19(19, Opcodes.V19, LanguageFeatures.METHODS_IN_INTERFACES | LanguageFeatures.PRIVATE_SYNTHETIC_METHODS_IN_INTERFACES
| LanguageFeatures.PRIVATE_METHODS_IN_INTERFACES | LanguageFeatures.NESTING | LanguageFeatures.DYNAMIC_CONSTANTS
| LanguageFeatures.RECORDS | LanguageFeatures.SEALED_CLASSES) {

@Override
boolean isSupported() {
return JavaVersion.current() >= JavaVersion.JAVA_19 && ASM.isAtLeastVersion(9, 3);
}

},

/**
* Java 20 or above is required
*/
JAVA_20(20, Opcodes.V20, LanguageFeatures.METHODS_IN_INTERFACES | LanguageFeatures.PRIVATE_SYNTHETIC_METHODS_IN_INTERFACES
| LanguageFeatures.PRIVATE_METHODS_IN_INTERFACES | LanguageFeatures.NESTING | LanguageFeatures.DYNAMIC_CONSTANTS
| LanguageFeatures.RECORDS | LanguageFeatures.SEALED_CLASSES) {

@Override
boolean isSupported() {
return JavaVersion.current() >= JavaVersion.JAVA_20 && ASM.isAtLeastVersion(9, 4);
}

},

/**
* Java 21 or above is required
*/
JAVA_21(21, Opcodes.V21, LanguageFeatures.METHODS_IN_INTERFACES | LanguageFeatures.PRIVATE_SYNTHETIC_METHODS_IN_INTERFACES
| LanguageFeatures.PRIVATE_METHODS_IN_INTERFACES | LanguageFeatures.NESTING | LanguageFeatures.DYNAMIC_CONSTANTS
| LanguageFeatures.RECORDS | LanguageFeatures.SEALED_CLASSES) {

@Override
boolean isSupported() {
return JavaVersion.current() >= JavaVersion.JAVA_21 && ASM.isAtLeastVersion(9, 5);
}

},

/**
* Java 22 or above is required
*/
JAVA_22(22, Opcodes.V22, LanguageFeatures.METHODS_IN_INTERFACES | LanguageFeatures.PRIVATE_SYNTHETIC_METHODS_IN_INTERFACES
| LanguageFeatures.PRIVATE_METHODS_IN_INTERFACES | LanguageFeatures.NESTING | LanguageFeatures.DYNAMIC_CONSTANTS
| LanguageFeatures.RECORDS | LanguageFeatures.SEALED_CLASSES) {

@Override
boolean isSupported() {
return JavaVersion.current() >= JavaVersion.JAVA_22 && ASM.isAtLeastVersion(9, 6);
}

},
;

/**
* Default compatibility level to use if not specified by the service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,19 @@ public abstract class InjectionPoint {
}

/**
* Selector type for slice delmiters, ignored for normal injection points.
* <tt>Selectors</tt> can be supplied in {@link At} annotations by including
* a colon (<tt>:</tt>) character followed by the selector type
* (case-sensitive), eg:
* Additional specifier for injection points. <tt>Specifiers</tt> can be
* supplied in {@link At} annotations by including a colon (<tt>:</tt>)
* character followed by the specifier type (case-sensitive), eg:
*
* <blockquote><pre>&#064;At(value = "INVOKE:LAST", ... )</pre></blockquote>
*/
public enum Selector {

public enum Specifier {

/**
* Use all instructions from the query result.
*/
ALL,

/**
* Use the <em>first</em> instruction from the query result.
*/
Expand All @@ -186,13 +190,13 @@ public enum Selector {
* more than one instruction this should be considered a fail-fast error
* state and a runtime exception will be thrown.
*/
ONE;
ONE,

/**
* Default selector type used if no selector is explicitly specified.
* <em>For internal use only. Currently {@link #FIRST}</em>
* Use the default setting as defined by the consumer. For slices this
* is {@link #FIRST}, for all other consumers this is {@link #ALL}
*/
public static final Selector DEFAULT = Selector.FIRST;
DEFAULT;

}

Expand Down Expand Up @@ -276,26 +280,26 @@ enum ShiftByViolationBehaviour {
}

private final String slice;
private final Selector selector;
private final Specifier specifier;
private final String id;
private final IMessageSink messageSink;


protected InjectionPoint() {
this("", Selector.DEFAULT, null);
this("", Specifier.DEFAULT, null);
}

protected InjectionPoint(InjectionPointData data) {
this(data.getSlice(), data.getSelector(), data.getId(), data.getMessageSink());
this(data.getSlice(), data.getSpecifier(), data.getId(), data.getMessageSink());
}

public InjectionPoint(String slice, Selector selector, String id) {
this(slice, selector, id, null);
public InjectionPoint(String slice, Specifier specifier, String id) {
this(slice, specifier, id, null);
}

public InjectionPoint(String slice, Selector selector, String id, IMessageSink messageSink) {
public InjectionPoint(String slice, Specifier specifier, String id, IMessageSink messageSink) {
this.slice = slice;
this.selector = selector;
this.specifier = specifier;
this.id = id;
this.messageSink = messageSink;
}
Expand All @@ -304,8 +308,8 @@ public String getSlice() {
return this.slice;
}

public Selector getSelector() {
return this.selector;
public Specifier getSpecifier(Specifier defaultSpecifier) {
return this.specifier == Specifier.DEFAULT ? defaultSpecifier : this.specifier;
}

public String getId() {
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/org/spongepowered/asm/mixin/injection/Slice.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.spongepowered.asm.mixin.injection.InjectionPoint.Selector;
import org.spongepowered.asm.mixin.injection.InjectionPoint.Specifier;

/**
* A <tt>Slice</tt> identifies a section of a method to search for injection
Expand Down Expand Up @@ -162,10 +162,10 @@

/**
* Injection point which specifies the <em>start</em> of the slice region.
* {@link At}s supplied here should generally specify a {@link Selector}
* {@link At}s supplied here should generally use a {@link Specifier}
* in order to identify which instruction should be used for queries which
* return multiple results. The selector is specified by appending the
* selector type to the injection point type as follows:
* return multiple results. The specifier is supplied by appending the
* specifier type to the injection point type as follows:
*
* <blockquote><pre>&#064;At(value = "INVOKE:LAST", ... )</pre></blockquote>
*
Expand All @@ -182,9 +182,9 @@
/**
* Injection point which specifies the <em>end</em> of the slice region.
* Like {@link #from}, {@link At}s supplied here should generally specify a
* {@link Selector} in order to identify which instruction should be used
* for queries which return multiple results. The selector is specified by
* appending the selector type to the injection point type as follows:
* {@link Specifier} in order to identify which instruction should be used
* for queries which return multiple results. The specifier is supplied by
* appending the specifier type to the injection point type as follows:
*
* <blockquote><pre>&#064;At(value = "INVOKE:LAST", ... )</pre></blockquote>
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,7 @@ private class Callback extends InsnList {
this.invoke = target.extendStack();
this.ctor = target.extendStack();

this.invoke.add(target.arguments.length);
if (this.canCaptureLocals) {
this.invoke.add(this.localTypes.length - this.frameSize);
}
this.invoke.add().add(handlerArgs);

//If the handler doesn't captureArgs, the CallbackInfo(Returnable) will be the first LVT slot, otherwise it will be at the target's frameSize
int callbackInfoSlot = handlerArgs.length == 1 ? Bytecode.isStatic(handler) ? 0 : 1 : frameSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.spongepowered.asm.mixin.injection.Coerce;
import org.spongepowered.asm.mixin.injection.InjectionPoint;
import org.spongepowered.asm.mixin.injection.InjectionPoint.RestrictTargetLevel;
import org.spongepowered.asm.mixin.injection.InjectionPoint.Specifier;
import org.spongepowered.asm.mixin.injection.invoke.RedirectInjector;
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
import org.spongepowered.asm.mixin.injection.struct.InjectionNodes.InjectionNode;
Expand Down Expand Up @@ -294,7 +295,7 @@ private Collection<TargetNode> findTargetNodes(InjectorTarget injectorTarget, Li
IMixinContext mixin = this.info.getMixin();
MethodNode method = injectorTarget.getMethod();
Map<Integer, TargetNode> targetNodes = new TreeMap<Integer, TargetNode>();
Collection<AbstractInsnNode> nodes = new ArrayList<AbstractInsnNode>(32);
List<AbstractInsnNode> nodes = new ArrayList<AbstractInsnNode>(32);

for (InjectionPoint injectionPoint : injectionPoints) {
nodes.clear();
Expand All @@ -307,22 +308,37 @@ private Collection<TargetNode> findTargetNodes(InjectorTarget injectorTarget, Li
injectorTarget, injectorTarget.getMergedBy(), injectorTarget.getMergedPriority()));
}

if (this.findTargetNodes(method, injectionPoint, injectorTarget, nodes)) {
if (!this.findTargetNodes(method, injectionPoint, injectorTarget, nodes)) {
continue;
}

Specifier specifier = injectionPoint.getSpecifier(Specifier.ALL);
if (specifier == Specifier.ONE && nodes.size() != 1) {
throw new InvalidInjectionException(this.info, String.format("%s on %s has specifier :ONE but matched %d instructions",
injectionPoint, this, nodes.size()));
} else if (specifier != Specifier.ALL && nodes.size() > 1) {
AbstractInsnNode specified = nodes.get(specifier == Specifier.FIRST ? 0 : nodes.size() - 1);
this.addTargetNode(method, targetNodes, injectionPoint, specified);
} else {
for (AbstractInsnNode insn : nodes) {
Integer key = method.instructions.indexOf(insn);
TargetNode targetNode = targetNodes.get(key);
if (targetNode == null) {
targetNode = new TargetNode(insn);
targetNodes.put(key, targetNode);
}
targetNode.nominators.add(injectionPoint);
this.addTargetNode(method, targetNodes, injectionPoint, insn);
}
}
}

return targetNodes.values();
}

protected void addTargetNode(MethodNode method, Map<Integer, TargetNode> targetNodes, InjectionPoint injectionPoint, AbstractInsnNode insn) {
Integer key = method.instructions.indexOf(insn);
TargetNode targetNode = targetNodes.get(key);
if (targetNode == null) {
targetNode = new TargetNode(insn);
targetNodes.put(key, targetNode);
}
targetNode.nominators.add(injectionPoint);
}

protected boolean findTargetNodes(MethodNode into, InjectionPoint injectionPoint, InjectorTarget injectorTarget,
Collection<AbstractInsnNode> nodes) {
return injectionPoint.find(into.desc, injectorTarget.getSlice(injectionPoint), nodes);
Expand Down
Loading

0 comments on commit d51f57a

Please sign in to comment.