scijs / cwise-parser

Parser for cwise
MIT License
8 stars 6 forks source link

Coverify incompatibility ("cwise-parser: Computed this is not allowed") #3

Open rreusser opened 9 years ago

rreusser commented 9 years ago

@jaspervdg, @mikolalysenko: here's a minimal test case that fails with a coverify transform:

// coverify-test.js:
var cwise = require('cwise');

var dot = cwise({
  args:['array', 'array'],
  pre: function() {
    this.sum = 0;
  },  
  body: function(a,b) {
    this.sum += a * b;
  },  
  post: function() {
    return this.sum;
  }
});

With browserify@10.1.3 and coverify@1.3.2, Run:

$ browserify -t coverify coverify-test.js | node

The transform succeeds, but executing the resulting code fails:

$ browserify -t coverify coverify-test.js |node
COVERAGE "/Users/rreusser/projects/scijs/rreusser/ndarray-ldl-factorization/coverify-test.js" [[12,28],[12,28],[0,29],[56,74],[100,104],[100,112],[100,113],[83,117],[147,151],[147,164],[147,165],[127,169],[203,207],[203,211],[196,212],[179,216],[47,218],[41,219],[41,219],[31,220]]
COVERED "/Users/rreusser/projects/scijs/rreusser/ndarray-ldl-factorization/coverify-test.js" 2
COVERED "/Users/rreusser/projects/scijs/rreusser/ndarray-ldl-factorization/coverify-test.js" 1
COVERED "/Users/rreusser/projects/scijs/rreusser/ndarray-ldl-factorization/coverify-test.js" 0
COVERED "/Users/rreusser/projects/scijs/rreusser/ndarray-ldl-factorization/coverify-test.js" 19
COVERED "/Users/rreusser/projects/scijs/rreusser/ndarray-ldl-factorization/coverify-test.js" 18
COVERED "/Users/rreusser/projects/scijs/rreusser/ndarray-ldl-factorization/coverify-test.js" 17
COVERED "/Users/rreusser/projects/scijs/rreusser/ndarray-ldl-factorization/coverify-test.js" 16
COVERED "/Users/rreusser/projects/scijs/rreusser/ndarray-ldl-factorization/coverify-test.js" 3
COVERED "/Users/rreusser/projects/scijs/rreusser/ndarray-ldl-factorization/coverify-test.js" 7
COVERED "/Users/rreusser/projects/scijs/rreusser/ndarray-ldl-factorization/coverify-test.js" 11
COVERED "/Users/rreusser/projects/scijs/rreusser/ndarray-ldl-factorization/coverify-test.js" 15

[stdin]:773
      throw new Error("cwise-parser: Computed this is not allowed")
            ^
Error: cwise-parser: Computed this is not allowed
    at visit ([stdin]:773:13)
    at visit ([stdin]:812:17)
    at visit ([stdin]:770:9)
    at visit ([stdin]:816:13)
    at visit ([stdin]:812:17)
    at visit ([stdin]:816:13)
    at visit ([stdin]:812:17)
    at visit ([stdin]:812:17)
    at preprocess ([stdin]:821:5)
    at createCWise ([stdin]:27:17)
jaspervdg commented 9 years ago

Basically the problem is that coverify sprinkles coverageWrap all over the pre, body, and post functions (even if you avoid the quoted error you just get another one). Still, there are two parts to this problem: one is that coverify turns this.sum into f(this).sum, which is not allowed (and it is probably not a good idea to relax this requirement here), the second part is that coverageWrap gets renamed by cwise (essentially "external" calls are not allowed). The latter could perhaps be solved, but I would not be surprised if we then still run into scoping issues. In other words: assuming you do want coverage information of the pre/body/post functions, I'm not quite sure how to go about realizing that (except for using an ad-hoc procedure that basically ensures the functions are not touched by coverify, and then adding it back in manually by passing in a function as scalar). So what kind of solution are you looking for?

rreusser commented 9 years ago

Thanks for the response and sorry to have let the discussion drop. I've been negligent enough to take the inner workings of cwise for granted, but I'm finally sitting down and working through what's going on here, so I'll see if I can figure out what a solution would even mean.