uw-pluverse / perses

language-agnostic program reducer.
GNU General Public License v3.0
168 stars 24 forks source link

Error Occurred While Parsing Shift Operators in Java #27

Closed Qeryu closed 9 months ago

Qeryu commented 10 months ago

When I performed a reduction on the following Java code, I encountered some issues.

#!/bin/bash

set -o pipefail
set -o nounset

rm T.class
javac T.java \
&& timeout -s 9 5 java T | grep -q '4'
public class T {

    private static int counter() {
        return 100;
    }

    public static void main(String[] args) {
        for (int i = 0; i < counter(); ++i) {
            System.out.println(1<<2);
        }
    }

}

During the reduction, Perses generated the following error message.

$ java -jar perses_deploy.jar --test-script r.sh --input-file T.java 
[10:13:12] [INFO   ] Tree Building: Start building spar-tree from input file SourceFile{file=/home/qeryu/others/perses_java_issue/T.java, lang=org.perses.grammar.java.LanguageJava@5e3a8624} 
[10:13:12] [INFO   ] Tree Building: Step 1: Antlr parsing. 
[10:13:12] [INFO   ] Tree Building: Step 2: Converting parse tree to spar-tree 
[10:13:12] [INFO   ] Tree Building: Step 3: Simplifying spar-tree 
[10:13:12] [INFO   ] Tree Building: Finished in TimeSpan{startMillis=1705457592389, endMillis=1705457592904, formatted=0 seconds} 
[10:13:12] [INFO   ] The reduction process started at 10:13:12 2024/01/17 
[10:13:12] [INFO   ] Cache setting: query-caching=enabled, edit-caching=enabled 
[10:13:12] [INFO   ] Reduction algorithm is org.perses.reduction.reducer.PersesNodePrioritizedDfsReducer 
[10:13:13] [SEVERE ] ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** 
[10:13:13] [SEVERE ] * 
[10:13:13] [SEVERE ] * The initial sanity check failed. 
[10:13:13] [SEVERE ] * The files have been saved, and you can check them at: 
[10:13:13] [SEVERE ] *     /tmp/1705457593470-0 
[10:13:13] [SEVERE ] * 
[10:13:13] [SEVERE ] ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** 
Exception in thread "main" java.lang.IllegalStateException
        at org.perses.reduction.ReductionDriver.sanityCheck(ReductionDriver.kt:343)
        at org.perses.reduction.ReductionDriver.reduce(ReductionDriver.kt:114)
        at org.perses.Main.run(Main.java:92)
        at org.perses.Main.main(Main.java:47)

Upon checking /tmp/1705457593470-0, I found that the Java code was parsed as follows:

...

{
System
.
out
.
println
(
1
<
<
2
)
;
}

...

In lines 11-12, the left shift operator was parsed as two less than signs, which I believe is an incorrect parse. When reducing C language code that uses shift operators, it can be parsed correctly.

Could this parsing error be due to an issue with how I'm using Perses?

chengniansun commented 10 months ago

Thank you for your bug report. I will release a fix soon.

Meanwhile, can you try the flag --code-format with the value COMPACT_ORIG_FORMAT.

https://github.com/uw-pluverse/perses/blob/cbc9a99bb61381881e2afddf293db3dcbac51424/test/org/perses/golden_perses_cmd_usage.txt#L34

Qeryu commented 10 months ago

Thanks, it works

chengniansun commented 10 months ago

Tracked with the internal issue 486

chengniansun commented 9 months ago

This is fixed in the internal repo, and will cut a release soon.