Vineflower / vineflower

Modern Java decompiler aiming to be as accurate as possible, with an emphasis on output quality. Fork of the Fernflower decompiler.
https://vineflower.org/
Apache License 2.0
1.29k stars 91 forks source link

$QF: Unable to simplify switch on enum #220

Open offbeat-stuff opened 1 year ago

offbeat-stuff commented 1 year ago

// Please report this to the Quiltflower issue tracker, at https://github.com/QuiltMC/quiltflower/issues with a copy of the class file (if you have the rights to distribute it!) [x] I have check the issues tab to see this is not duplicate (probably isnt but I could be wrong)

I dont have the rights to share the class file, its a minecraft class file check net.minecraft.world.level.NaturalSpawner.class under official mappings (1.19.2) method name -> isSpawnPositionOk (type or attributes -> public static boolean)

jaskarth commented 1 year ago

How are you decompiling Minecraft? Through Loom or some other source? I can't replicate on my end

offbeat-stuff commented 1 year ago

just simply through the command line

offbeat-stuff commented 1 year ago

quiltflower version is 1.9.0

offbeat-stuff commented 1 year ago

generated the classes through DecompilerMc

jaskarth commented 1 year ago

Would you be able to provide a link to the tool? I can't find any references to it online. Regardless, this seems like the tool isn't providing classes to Quiltflower properly, as it only happens when related inner classes can't be found.

misode commented 1 year ago

@SuperCoder7979 https://github.com/hube12/DecompilerMC probably, although that doesn't support QF without some modifications

offbeat-stuff commented 1 year ago

It did not use modifications, I just did not decompile with it,

offbeat-stuff commented 1 year ago

I just let it remap the classes, then just used quiltflower to decompile it

offbeat-stuff commented 1 year ago

from the command line using Quiltflower aur package

offbeat-stuff commented 1 year ago

exec java -jar /usr/share/java/quiltflower/quiltflower-1.9.0.jar "$@"

isXander commented 1 year ago

Found this error in a mixin export. Bytecode for method:

  // access flags 0x1
  // signature (Lnet/minecraft/client/gui/navigation/ScreenDirection;Ljava/util/function/Predicate<TE;>;TE;)TE;
  // declaration: E nextEntry(net.minecraft.client.gui.navigation.ScreenDirection, java.util.function.Predicate<E>, E)
  public nextEntry(Lnet/minecraft/client/gui/navigation/ScreenDirection;Ljava/util/function/Predicate;Lnet/minecraft/client/gui/components/AbstractSelectionList$Entry;)Lnet/minecraft/client/gui/components/AbstractSelectionList$Entry;
    // parameter  direction
    // parameter  predicate
    // parameter  currentEntry
  @Lorg/jetbrains/annotations/Nullable;()
    // annotable parameter count: 3 (visible)
    @Lorg/jetbrains/annotations/Nullable;() // parameter 2
   L0
    LINENUMBER 414 L0
    GETSTATIC net/minecraft/client/gui/components/AbstractSelectionList$1.$SwitchMap$net$minecraft$client$gui$navigation$ScreenDirection : [I
    ALOAD 1
    INVOKEVIRTUAL net/minecraft/client/gui/navigation/ScreenDirection.ordinal ()I
    IALOAD
    TABLESWITCH
      1: L1
      2: L1
      3: L2
      4: L3
      default: L4
   L4
   FRAME SAME
    NEW java/lang/IncompatibleClassChangeError
    DUP
    INVOKESPECIAL java/lang/IncompatibleClassChangeError.<init> ()V
    ATHROW
   L1
    LINENUMBER 415 L1
   FRAME SAME
    ICONST_0
    GOTO L5
   L2
    LINENUMBER 416 L2
   FRAME SAME
    ICONST_M1
    GOTO L5
   L3
    LINENUMBER 417 L3
   FRAME SAME
    ICONST_1
   L5
   FRAME SAME1 I
    ISTORE 4
   L6
    LINENUMBER 419 L6
    ALOAD 0
    INVOKEVIRTUAL net/minecraft/client/gui/components/AbstractSelectionList.children ()Ljava/util/List;
    INVOKEINTERFACE java/util/List.isEmpty ()Z (itf)
    IFNE L7
    ILOAD 4
    IFEQ L7
   L8
    LINENUMBER 421 L8
    ALOAD 3
    IFNONNULL L9
   L10
    LINENUMBER 422 L10
    ILOAD 4
    IFLE L11
    ICONST_0
    GOTO L12
   L11
   FRAME APPEND [I]
    ALOAD 0
    INVOKEVIRTUAL net/minecraft/client/gui/components/AbstractSelectionList.children ()Ljava/util/List;
    INVOKEINTERFACE java/util/List.size ()I (itf)
    ICONST_1
    ISUB
   L12
   FRAME SAME1 I
    ISTORE 5
   L13
    GOTO L14
   L9
    LINENUMBER 424 L9
   FRAME SAME
    ALOAD 0
    INVOKEVIRTUAL net/minecraft/client/gui/components/AbstractSelectionList.children ()Ljava/util/List;
    ALOAD 3
    INVOKEINTERFACE java/util/List.indexOf (Ljava/lang/Object;)I (itf)
    ILOAD 4
    IADD
    ISTORE 5
   L14
    LINENUMBER 427 L14
   FRAME APPEND [I]
    ILOAD 5
    ISTORE 6
   L15
   FRAME APPEND [I]
    ILOAD 6
    IFLT L7
    ILOAD 6
    ALOAD 0
    ALOAD 0
    SWAP
    INVOKESPECIAL net/minecraft/client/gui/components/AbstractSelectionList.redirect$zzb000$modifyChildrenCall (Lnet/minecraft/client/gui/components/AbstractSelectionList;)Ljava/util/List;
    INVOKEINTERFACE java/util/List.size ()I (itf)
    IF_ICMPGE L7
   L16
    LINENUMBER 428 L16
    ALOAD 0
    INVOKEVIRTUAL net/minecraft/client/gui/components/AbstractSelectionList.children ()Ljava/util/List;
    ILOAD 6
    INVOKEINTERFACE java/util/List.get (I)Ljava/lang/Object; (itf)
    CHECKCAST net/minecraft/client/gui/components/AbstractSelectionList$Entry
    ASTORE 7
   L17
    LINENUMBER 429 L17
    ALOAD 2
    ALOAD 7
    INVOKEINTERFACE java/util/function/Predicate.test (Ljava/lang/Object;)Z (itf)
    IFEQ L18
   L19
    LINENUMBER 430 L19
    ALOAD 7
    ARETURN
   L18
    LINENUMBER 427 L18
   FRAME APPEND [net/minecraft/client/gui/components/AbstractSelectionList$Entry]
    ILOAD 6
    ILOAD 4
    IADD
    ISTORE 6
    GOTO L15
   L7
    LINENUMBER 434 L7
   FRAME CHOP 3
    ACONST_NULL
    ARETURN
   L20
    LOCALVARIABLE this Lnet/minecraft/client/gui/components/AbstractSelectionList; L0 L20 0
    // signature Lnet/minecraft/client/gui/components/AbstractSelectionList<TE;>;
    // declaration: this extends net.minecraft.client.gui.components.AbstractSelectionList<E>
    LOCALVARIABLE direction Lnet/minecraft/client/gui/navigation/ScreenDirection; L0 L20 1
    LOCALVARIABLE predicate Ljava/util/function/Predicate; L0 L20 2
    // signature Ljava/util/function/Predicate<TE;>;
    // declaration: predicate extends java.util.function.Predicate<E>
    LOCALVARIABLE currentEntry Lnet/minecraft/client/gui/components/AbstractSelectionList$Entry; L0 L20 3
    // signature TE;
    // declaration: currentEntry extends E
    LOCALVARIABLE i I L6 L20 4
    LOCALVARIABLE j I L13 L9 5
    LOCALVARIABLE j I L14 L7 5
    LOCALVARIABLE k I L15 L7 6
    LOCALVARIABLE entry Lnet/minecraft/client/gui/components/AbstractSelectionList$Entry; L17 L18 7
    // signature TE;
    // declaration: entry extends E
    MAXSTACK = 3
    MAXLOCALS = 8

Resulting in

        int i = switch(1.$SwitchMap$net$minecraft$client$gui$navigation$ScreenDirection[direction.ordinal()]) {
            case 1, 2 -> 0;
            case 3 -> -1;
            case 4 -> 1;
            default -> throw new IncompatibleClassChangeError();
        };
Gaming32 commented 9 months ago

I just got this warning/error, but it simplified it perfectly. (VineFlower 1.9.3)

// $VF: Unable to simplify switch on enum
// Please report this to the Vineflower issue tracker, at https://github.com/Vineflower/vineflower/issues with a copy of the class file (if you have the rights to distribute it!)
public static File getAppDir(String var0) {
    String s = System.getProperty("user.home", ".");
    File file1;
    switch(getOs()) {
        case linux:
        case solaris:
            file1 = new File(s, '.' + var0 + '/');
            break;
        case windows:
            String s1 = System.getenv("APPDATA");
            if (s1 != null) {
                file1 = new File(s1, "." + var0 + '/');
            } else {
                file1 = new File(s, '.' + var0 + '/');
            }
            break;
        case macos:
            file1 = new File(s, "Library/Application Support/" + var0);
            break;
        default:
            file1 = new File(s, var0 + '/');
    }
tildejustin commented 9 months ago

also got one that has no visible errors but still says it didn't simplify, 1.10.0-SNAPSHOT build 86

   // $VF: Unable to simplify switch on enum
    // Please report this to the Vineflower issue tracker, at https://github.com/Vineflower/vineflower/issues with a copy of the class file (if you have the rights to distribute it!)
    public int method_2565(double d) {
        double var3 = d - ((double)MathHelper.floor(d) + 0.5);
        switch (this) {
            case SIZE_1:
                return (var3 < 0.0 ? !(var3 < -0.3125) : !(var3 < 0.3125)) ? MathHelper.floor(d * 32.0) : MathHelper.ceil(d * 32.0);
            case SIZE_2:
                if (var3 < 0.0 ? !(var3 < -0.3125) : !(var3 < 0.3125)) {
                    return MathHelper.ceil(d * 32.0);
                }

                return MathHelper.floor(d * 32.0);
            case SIZE_3:
                if (var3 > 0.0) {
                    return MathHelper.floor(d * 32.0);
                }

                return MathHelper.ceil(d * 32.0);
            case SIZE_4:
                if (var3 < 0.0 ? !(var3 < -0.1875) : !(var3 < 0.1875)) {
                    return MathHelper.floor(d * 32.0);
                }

                return MathHelper.ceil(d * 32.0);
            case SIZE_5:
                if (var3 < 0.0 ? !(var3 < -0.1875) : !(var3 < 0.1875)) {
                    return MathHelper.ceil(d * 32.0);
                }

                return MathHelper.floor(d * 32.0);
            case SIZE_6:
            default:
                return var3 > 0.0 ? MathHelper.ceil(d * 32.0) : MathHelper.floor(d * 32.0);
        }
    }