dmholtz/DynamicProgramSlicing

Incorrect slice for implict attribute-uses

dmholtz opened this issue · 2 comments

The slicer produces wrong results, if implicit uses of object attributes occur.

If the slicing criterion is of type object, all of its attributes are implicitly accessed. However, the current implementation does not reflect this implicit behaviour and produces an incorrect slice.

Example: testcases/progress2/e2_in.js (here simplified):

function sliceMe() {
    var a = { course: 'Program Analysis' };
    a.semester = 'Winter';
    return a; // slicing criterion
}
sliceMe();

Expected slice:

function sliceMe() {
    var a = { course: 'Program Analysis' };
    a.semester = 'Winter';
    return a; // slicing criterion
}
sliceMe();

However, the analysis does not include the putField statement of line 3 and computes a wrong slice:

function sliceMe() {
    var a = { course: 'Program Analysis' };
    return a; // slicing criterion
}
sliceMe();

Examples of implicit and explicit attribute uses

Consider the following cases:

  1. Implicit use of all object attributes:
var a = { course: 'Program Analysis' };
a.semester = 'Winter';
return a; // here, both 'course' and 'semester' are implicitly used
  1. Implicit use of all object attributes in composed objects such as lists:
var a = { course: 'Program Analysis' };
a.semester = 'Winter';
var b = { course: 'Analyzing Programs using Deep Learning' };
b. semester = 'Summer';
return [a, b]; // here, all attributes of both objects are implicitly used
  1. Implicit non-use of all object attributes:
var a = { course: 'Program Analysis' };
a.semester = 'Winter';
return a+a; // returns a string, no object attributes are used
  1. Explicit object attribute use:
var a = { course: 'Program Analysis' };
a. semester = 'Winter';
return a.course; // here, the 'semester' attribute of a is not used

Solution Sketch

For a static program analysis, it's hard to detect implicit object attribute correctly and the proposed cases above are hard to distinguish (because semantic rules of JavaScript)

Luckily, for a dynamic program analysis, the type of the object can be utilized to detect implict object attribute uses:

If the slicing criterion is a ReturnStatement and the value of the returned object is a non-primitive (i.e. an object), then all of its attributes are implicitly used. Moreover, this holds recursively: If the object is a composed object (e.g. a list or a nested object), all list values or nested object attributes are implicitly used.

In that cases, the the implicit P-DEF tuples (i.e. property definitions) must be added to the gen(s) set.