Skip to content

Commit

Permalink
feat: Removal of istanbul handling
Browse files Browse the repository at this point in the history
  • Loading branch information
robertleeplummerjr authored and ammyk9 committed Aug 6, 2024
1 parent 2d51ed6 commit 42393ee
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 443 deletions.
22 changes: 2 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,26 +190,8 @@ Settings are an object used to create an instance of `GPU`. Example: `new GPU(s
* 'webgl2': Use the `WebGL2Kernel` for transpiling a kernel
* 'headlessgl' **New in V2!**: Use the `HeadlessGLKernel` for transpiling a kernel
* 'cpu': Use the `CPUKernel` for transpiling a kernel
* `onIstanbulCoverageVariable`: For testing. Used for when coverage is inject into function values, and is desired to be preserved (`cpu` mode ONLY).
Use like this:
```js
const { getFileCoverageDataByName } = require('istanbul-spy');
const gpu = new GPU({
mode: 'cpu',
onIstanbulCoverageVariable: (name, kernel) => {
const data = getFileCoverageDataByName(name);
if (!data) {
throw new Error(`Could not find istanbul identifier ${name}`);
}
const { path } = getFileCoverageDataByName(name);
const variable = `const ${name} = __coverage__['${path}'];\n`;
if (!kernel.hasPrependString(variable)) {
kernel.prependString(variable);
}
}
});
```
* `removeIstanbulCoverage`: Boolean. For testing and code coverage. Removes istanbul artifacts that were injected at testing runtime.
* `onIstanbulCoverageVariable`: Removed in v2.11.0, use v8 coverage
* `removeIstanbulCoverage`: Removed in v2.11.0, use v8 coverage

## `gpu.createKernel` Settings
Settings are an object used to create a `kernel` or `kernelMap`. Example: `gpu.createKernel(settings)`
Expand Down
97 changes: 13 additions & 84 deletions dist/gpu-browser-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
*
* GPU Accelerated JavaScript
*
* @version 2.10.6
* @date Wed Dec 02 2020 15:14:25 GMT-0500 (Eastern Standard Time)
* @version 2.11.0
* @date Tue Jan 05 2021 15:55:59 GMT-0500 (Eastern Standard Time)
*
* @license MIT
* The MIT License
*
* Copyright (c) 2020 gpu.js Team
* Copyright (c) 2021 gpu.js Team
*/(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.GPU = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){

},{}],2:[function(require,module,exports){
Expand Down Expand Up @@ -1020,18 +1020,6 @@ class CPUFunctionNode extends FunctionNode {
return retArr;
}
break;
case 'value.value[]':
if (this.removeIstanbulCoverage) {
return retArr;
}
retArr.push(`${mNode.object.object.name}.${mNode.object.property.name}[${mNode.property.value}]`);
return retArr;
case 'value.value[][]':
if (this.removeIstanbulCoverage) {
return retArr;
}
retArr.push(`${mNode.object.object.object.name}.${mNode.object.object.property.name}[${mNode.object.property.value}][${mNode.property.value}]`);
return retArr;
case 'this.constants.value':
case 'this.constants.value[]':
case 'this.constants.value[][]':
Expand Down Expand Up @@ -2039,8 +2027,6 @@ class FunctionBuilder {
followingReturnStatement,
dynamicArguments,
dynamicOutput,
onIstanbulCoverageVariable,
removeIstanbulCoverage,
} = kernel;

const argumentTypes = new Array(kernelArguments.length);
Expand Down Expand Up @@ -2127,8 +2113,6 @@ class FunctionBuilder {
triggerImplyArgumentType,
triggerImplyArgumentBitRatio,
onFunctionCall,
onIstanbulCoverageVariable: onIstanbulCoverageVariable ? (name) => onIstanbulCoverageVariable(name, kernel) : null,
removeIstanbulCoverage,
optimizeFloatMemory,
precision,
constants,
Expand Down Expand Up @@ -2181,8 +2165,6 @@ class FunctionBuilder {
triggerImplyArgumentBitRatio,
onFunctionCall,
onNestedFunction,
onIstanbulCoverageVariable: onIstanbulCoverageVariable ? (name) => onIstanbulCoverageVariable(name, kernel) : null,
removeIstanbulCoverage,
}));
}

Expand Down Expand Up @@ -2608,8 +2590,6 @@ class FunctionNode {
this.dynamicArguments = null;
this.strictTypingChecking = false;
this.fixIntegerDivisionAccuracy = null;
this.onIstanbulCoverageVariable = null;
this.removeIstanbulCoverage = false;

if (settings) {
for (const p in settings) {
Expand Down Expand Up @@ -2685,7 +2665,7 @@ class FunctionNode {

if (ast.type === 'MemberExpression') {
if (ast.object && ast.property) {
if (ast.object.hasOwnProperty('name') && ast.object.name[0] === '_') {
if (ast.object.hasOwnProperty('name') && ast.object.name !== 'Math') {
return this.astMemberExpressionUnroll(ast.property);
}

Expand Down Expand Up @@ -2905,6 +2885,11 @@ class FunctionNode {
if (this.getVariableSignature(ast.callee, true) === 'this.color') {
return null;
}
if (ast.callee.type === 'MemberExpression' && ast.callee.object && ast.callee.property && ast.callee.property.name && ast.arguments) {
const functionName = ast.callee.property.name;
this.inferArgumentTypesIfNeeded(functionName, ast.arguments);
return this.lookupReturnType(functionName, ast, this);
}
throw this.astErrorOutput('Unknown call expression', ast);
}
if (ast.callee && ast.callee.name) {
Expand Down Expand Up @@ -3345,8 +3330,6 @@ class FunctionNode {
'value[][][]',
'value[][][][]',
'value.value',
'value.value[]',
'value.value[][]',
'value.thread.value',
'this.thread.value',
'this.output.value',
Expand Down Expand Up @@ -3560,20 +3543,11 @@ class FunctionNode {
astThisExpression(ast, retArr) {
return retArr;
}
isIstanbulAST(ast) {
const variableSignature = this.getVariableSignature(ast);
return variableSignature === 'value.value[]' || variableSignature === 'value.value[][]';
}
astSequenceExpression(sNode, retArr) {
const { expressions } = sNode;
const sequenceResult = [];
for (let i = 0; i < expressions.length; i++) {
const expression = expressions[i];
if (this.removeIstanbulCoverage) {
if (expression.type === 'UpdateExpression' && this.isIstanbulAST(expression.argument)) {
continue;
}
}
const expressionResult = [];
this.astGeneric(expression, expressionResult);
sequenceResult.push(expressionResult.join(''));
Expand Down Expand Up @@ -3605,12 +3579,6 @@ class FunctionNode {
checkAndUpconvertBitwiseUnary(uNode, retArr) {}

astUpdateExpression(uNode, retArr) {
if (this.removeIstanbulCoverage) {
const signature = this.getVariableSignature(uNode.argument);
if (this.isIstanbulAST(uNode.argument)) {
return retArr;
}
}
if (uNode.prefix) {
retArr.push(uNode.operator);
this.astGeneric(uNode.argument, retArr);
Expand Down Expand Up @@ -3814,28 +3782,8 @@ class FunctionNode {
signature: variableSignature,
property: ast.property,
};
case 'value.value[]':
if (this.removeIstanbulCoverage) {
return { signature: variableSignature };
}
if (this.onIstanbulCoverageVariable) {
this.onIstanbulCoverageVariable(ast.object.object.name);
return {
signature: variableSignature
};
}
case 'value.value[][]':
if (this.removeIstanbulCoverage) {
return { signature: variableSignature };
}
if (this.onIstanbulCoverageVariable) {
this.onIstanbulCoverageVariable(ast.object.object.object.name);
return {
signature: variableSignature
};
}
default:
throw this.astErrorOutput('Unexpected expression', ast);
default:
throw this.astErrorOutput('Unexpected expression', ast);
}
}

Expand Down Expand Up @@ -6311,8 +6259,6 @@ class Kernel {
this.optimizeFloatMemory = null;
this.strictIntegers = false;
this.fixIntegerDivisionAccuracy = null;
this.onIstanbulCoverageVariable = null;
this.removeIstanbulCoverage = false;
this.built = false;
this.signature = null;
}
Expand All @@ -6339,11 +6285,6 @@ class Kernel {
}
this[p] = settings[p];
continue;
case 'removeIstanbulCoverage':
if (settings[p] !== null) {
this[p] = settings[p];
}
continue;
case 'nativeFunctions':
if (!settings.nativeFunctions) continue;
this.nativeFunctions = [];
Expand Down Expand Up @@ -8338,13 +8279,8 @@ class WebGLFunctionNode extends FunctionNode {
retArr.push(this.memberExpressionPropertyMarkup(property));
retArr.push(']');
return retArr;
case 'value.value[]':
case 'value.value[][]':
if (this.removeIstanbulCoverage) {
return retArr;
}
default:
throw this.astErrorOutput('Unexpected expression', mNode);
default:
throw this.astErrorOutput('Unexpected expression', mNode);
}

if (mNode.computed === false) {
Expand Down Expand Up @@ -10183,7 +10119,6 @@ class WebGLKernel extends GLKernel {

this.maxTexSize = null;
this.onRequestSwitchKernel = null;
this.removeIstanbulCoverage = true;

this.texture = null;
this.mappedTextures = null;
Expand Down Expand Up @@ -13538,8 +13473,6 @@ class GPU {
this.functions = [];
this.nativeFunctions = [];
this.injectedNative = null;
this.onIstanbulCoverageVariable = settings.onIstanbulCoverageVariable || null;
this.removeIstanbulCoverage = settings.hasOwnProperty('removeIstanbulCoverage') ? settings.removeIstanbulCoverage : null;
if (this.mode === 'dev') return;
this.chooseKernel();
if (settings.functions) {
Expand Down Expand Up @@ -13715,8 +13648,6 @@ class GPU {
gpu: _kernel.gpu,
validate,
returnType: _kernel.returnType,
onIstanbulCoverageVariable: _kernel.onIstanbulCoverageVariable,
removeIstanbulCoverage: _kernel.removeIstanbulCoverage,
tactic: _kernel.tactic,
onRequestFallback,
onRequestSwitchKernel,
Expand All @@ -13735,8 +13666,6 @@ class GPU {
functions: this.functions,
nativeFunctions: this.nativeFunctions,
injectedNative: this.injectedNative,
onIstanbulCoverageVariable: this.onIstanbulCoverageVariable,
removeIstanbulCoverage: this.removeIstanbulCoverage,
gpu: this,
validate,
onRequestFallback,
Expand Down
8 changes: 4 additions & 4 deletions dist/gpu-browser-core.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 42393ee

Please sign in to comment.