DRMacIver / shrinkray

Shrinkray is a modern multi-format test-case reducer
MIT License
86 stars 2 forks source link

delimiter elimination #4

Closed regehr closed 8 months ago

regehr commented 8 months ago

I just watched shrinkray work on a C++ program and I'd say that its major problem all though was getting rid of parens -- there were extra ones at basically all stages of reduction (including the final output, below). C-Reduce gets a lot of mileage out of a pass that removes matched pairs of delimiters, without disturbing the stuff inside -- if you don't have that pass, then it seems like a good candidate for the short list.

bool
var_27,var_28;
#include<algorithm>
void
n(bool
var_0,char
var_2,char
var_4,char
arr_42[][0][0][0]){
    #pragma clang loop vectorize(enable)
    for(signed
    i_10=0;
    i_10<2;
    i_10+=(var_0)){
        if((((arr_42[0][0][0][i_10]))))var_27=((0));
        var_28=((((arr_42[0][0][0][i_10]))?((std::min((arr_42[0][0][0][i_10]),(std::max((var_2),(var_4)))))):((0))));
    }
}
regehr commented 8 months ago

c-reduce output for reference

bool a, b;
#include <algorithm>
void c(bool d, char e, char f[][0][0][0]) {
  char g = 0;
#pragma clang loop vectorize(enable)
  for (signed h = 0; h < 2; h += d) {
    if (f[0][0][0][h])
      a = 0;
    b = f[0][0][0][h] ? std::min(f[0][0][0][h], std::max(g, e)) : 0;
  }
}
DRMacIver commented 8 months ago

Hmm. Shrink ray does have a pass that does essentially this for braces. I guess maybe I forgot to have it do the same for brackets, which does seem an obvious clear win. It's probably bordering on a one-line change.

DRMacIver commented 8 months ago

Also that Shrink Ray output for your example is clear evidence that I need to do some more work on the formatter, or just call clang-format at the end maybe. Yuck.

regehr commented 8 months ago

yeah, my preference for formatting would be best-effort, based on whatever external tools happen to be in the current PATH. so for example, you might guarantee that if I'm reducing a .c, .cpp, .cxx, or whatever, and clang-format is in the path, then that'll get called at the end.

DRMacIver commented 8 months ago

Yeah that's more or less my current plan. There's #1 which requests setting a custom format tool, which I do plan to implement at some point, but I think probably there's going to end up also being a hard coded list of different formatters and how to invoke them properly.

regehr commented 8 months ago

can confirm that this is fixed for my example

DRMacIver commented 8 months ago

yeah, my preference for formatting would be best-effort, based on whatever external tools happen to be in the current PATH. so for example, you might guarantee that if I'm reducing a .c, .cpp, .cxx, or whatever, and clang-format is in the path, then that'll get called at the end.

This is now implemented!