uw-pluverse / perses

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

A question about reducing JavaScript code #26

Closed ayuan0828 closed 8 months ago

ayuan0828 commented 8 months ago

I tried using Perses to reduce the javascript code, but no matter how many lines of code there are in the javascript file, the final result of the reduction is empty. I don't know which step is wrong, can you help me?

Executed command:

java -jar perses_deploy.jar -t test.sh -i test.js

test.sh:

#!/bin/bash
/home/quickjs/quickjs-2021-03-27/qjs test.js

test.js:

print("a");

the result:

[19:10:14] [INFO   ] The command-line options are: "--alg": "perses_node_priority_with_dfs_delta", "--append-to-progress-dump-file": "false", "--call-creduce": "false", "--call-formatter": "false", "--creduce-cmd": "creduce", "--default-delta-debugger-for-kleene": "DFS", "--designated-parser-facade-class-name": "", "--edit-caching": "true", "--enable-lightweight-refreshing": "false", "--enable-line-slicer": "false", "--enable-token-slicer": "false", "--enable-tree-slicer": "false", "--enable-vulcan": "false", "--fixpoint": "true", "--format-cmd": "", "--help, -h": "false", "--input-file, --input, -i": "test.js", "--language-ext-jars": "[]", "--list-algs": "false", "--list-langs": "false", "--list-parser-facades": "false", "--list-verbosity-levels": "false", "--max-bfs-depth-for-regular-rule-node": "5", "--max-edit-count-for-regular-rule-node": "100", "--non-deletion-iteration-limit": "10", "--pass-level-caching": "false", "--profile": "false", "--query-cache-refresh-threshold": "0", "--query-cache-type": "COMPACT_QUERY_CACHE", "--query-caching": "AUTO", "--reparse-each-iteration": "true", "--script-execution-keep-waiting-after-timeout": "true", "--script-execution-timeout-in-seconds": "600", "--stop-at-first-compatible-child-for-regular-rule-node": "false", "--test-script, --test, -t": "test.sh", "--threads": "auto", "--verbosity": "INFO", "--version": "false", "--vulcan-fixpoint": "false", "--window-size": "4" 
[19:10:14] [INFO   ] Tree Building: Start building spar-tree from input file SourceFile{file=FileWithContent{file=/home/reduce/test.js}, lang=LanguageJavaScript{name=javascript, extensions=[javascript, js], defaultCodeFormatControl=COMPACT_ORIG_FORMAT}} 
[19:10:14] [INFO   ] Tree Building: Step 1: Antlr parsing. 
[19:10:15] [INFO   ] Tree Building: Step 2: Converting parse tree to spar-tree 
[19:10:15] [INFO   ] Tree Building: Step 3: Simplifying spar-tree 
[19:10:15] [INFO   ] Tree Building: Finished in TimeSpan{startMillis=1704712214979, endMillis=1704712215071, formatted=0 seconds} 
[19:10:15] [INFO   ] The reduction process started at 19:10:15 2024/01/08 
[19:10:15] [INFO   ] Cache setting: query-caching=disabled, edit-caching=enabled, query-cache=compact_query_cache 
[19:10:15] [INFO   ] Reduction algorithm is perses_node_priority_with_dfs_delta 
[19:10:15] [INFO   ] The number of lexemes in the token factory is is 5 
[19:10:15] [INFO   ] Reduction Started at 19:10:15 2024/01/08 
[19:10:15] [INFO   ] perses_node_priority_with_dfs_delta started at 19:10:15 2024/01/08. #tokens=4 
[19:10:15] [INFO   ] Fixpoint[1]:Reducer[perses_node_priority_with_dfs_delta]: New fixpoint iteration started. #Tokens=4 
[19:10:15] [INFO   ] Fixpoint[1]:Reducer[perses_node_priority_with_dfs_delta]: Reduce node (#leaves=4) 
[19:10:15] [INFO   ] perses_node_priority_with_dfs_delta ended at 19:10:15 2024/01/08. #old=4, #new=0 
[19:10:15] [INFO   ] Fixpoint[1]:Reducer[perses_node_priority_with_dfs_delta]: New minimal, delete 4 tokens, ratio=0/4=0.00% 
[19:10:15] [INFO   ] Fixpoint[1]:Reducer[perses_node_priority_with_dfs_delta]: Reduce node (#leaves=0): queue=0, delete 4 tokens, ratio=0/4=0.00% 
[19:10:15] [INFO   ] Fixpoint[1]:Reducer[perses_node_priority_with_dfs_delta]: Fixpoint iteration finished, delete 4 tokens, ratio=0/4=0.00% 
[19:10:15] [INFO   ] Rebuilding spar-tree. 
[19:10:15] [INFO   ] perses_node_priority_with_dfs_delta started at 19:10:15 2024/01/08. #tokens=0 
[19:10:15] [INFO   ] Fixpoint[2]:Reducer[perses_node_priority_with_dfs_delta]: New fixpoint iteration started. #Tokens=0 
[19:10:15] [INFO   ] perses_node_priority_with_dfs_delta ended at 19:10:15 2024/01/08. #old=0, #new=0 
[19:10:15] [INFO   ] Fixpoint[2]:Reducer[perses_node_priority_with_dfs_delta]: Fixpoint iteration finished, delete 0 tokens, ratio=0/4=0.00% 
[19:10:15] [INFO   ] Reduction ended at 19:10:15 2024/01/08 
[19:10:15] [INFO   ] Elapsed time is 0 seconds 
[19:10:15] [INFO   ] Removed 4 token(s). Reduction ratio is 0/4=0.00% 
[19:10:15] [INFO   ] Test script execution count: 2 
chengniansun commented 8 months ago

The reduction script specifies that the reduced program should exit with 0. If an empty program exits 0, then perses will produce an empty file.

There are more examples of the reduction scripts in the folder //test/org/perses/toy_benchmarks.

ayuan0828 commented 8 months ago

I understand the reason now, thank you very much.