Skip to content

Commit 3be597d

Browse files
Merge branch 'master' into develop
2 parents 22604e9 + 026763a commit 3be597d

20 files changed

+384
-807
lines changed

README.md

+2-20
Original file line numberDiff line numberDiff line change
@@ -190,26 +190,8 @@ Settings are an object used to create an instance of `GPU`. Example: `new GPU(s
190190
* 'webgl2': Use the `WebGL2Kernel` for transpiling a kernel
191191
* 'headlessgl' **New in V2!**: Use the `HeadlessGLKernel` for transpiling a kernel
192192
* 'cpu': Use the `CPUKernel` for transpiling a kernel
193-
* `onIstanbulCoverageVariable`: For testing. Used for when coverage is inject into function values, and is desired to be preserved (`cpu` mode ONLY).
194-
Use like this:
195-
```js
196-
const { getFileCoverageDataByName } = require('istanbul-spy');
197-
const gpu = new GPU({
198-
mode: 'cpu',
199-
onIstanbulCoverageVariable: (name, kernel) => {
200-
const data = getFileCoverageDataByName(name);
201-
if (!data) {
202-
throw new Error(`Could not find istanbul identifier ${name}`);
203-
}
204-
const { path } = getFileCoverageDataByName(name);
205-
const variable = `const ${name} = __coverage__['${path}'];\n`;
206-
if (!kernel.hasPrependString(variable)) {
207-
kernel.prependString(variable);
208-
}
209-
}
210-
});
211-
```
212-
* `removeIstanbulCoverage`: Boolean. For testing and code coverage. Removes istanbul artifacts that were injected at testing runtime.
193+
* `onIstanbulCoverageVariable`: Removed in v2.11.0, use v8 coverage
194+
* `removeIstanbulCoverage`: Removed in v2.11.0, use v8 coverage
213195

214196
## `gpu.createKernel` Settings
215197
Settings are an object used to create a `kernel` or `kernelMap`. Example: `gpu.createKernel(settings)`

dist/gpu-browser-core.js

+22-89
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
*
55
* GPU Accelerated JavaScript
66
*
7-
* @version 2.10.0
8-
* @date Tue Aug 25 2020 14:05:30 GMT-0400 (Eastern Daylight Time)
7+
* @version 2.11.0
8+
* @date Tue Jan 05 2021 15:55:59 GMT-0500 (Eastern Standard Time)
99
*
1010
* @license MIT
1111
* The MIT License
1212
*
13-
* Copyright (c) 2020 gpu.js Team
13+
* Copyright (c) 2021 gpu.js Team
1414
*/(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){
1515

1616
},{}],2:[function(require,module,exports){
@@ -1020,18 +1020,6 @@ class CPUFunctionNode extends FunctionNode {
10201020
return retArr;
10211021
}
10221022
break;
1023-
case 'value.value[]':
1024-
if (this.removeIstanbulCoverage) {
1025-
return retArr;
1026-
}
1027-
retArr.push(`${mNode.object.object.name}.${mNode.object.property.name}[${mNode.property.value}]`);
1028-
return retArr;
1029-
case 'value.value[][]':
1030-
if (this.removeIstanbulCoverage) {
1031-
return retArr;
1032-
}
1033-
retArr.push(`${mNode.object.object.object.name}.${mNode.object.object.property.name}[${mNode.object.property.value}][${mNode.property.value}]`);
1034-
return retArr;
10351023
case 'this.constants.value':
10361024
case 'this.constants.value[]':
10371025
case 'this.constants.value[][]':
@@ -2039,8 +2027,6 @@ class FunctionBuilder {
20392027
followingReturnStatement,
20402028
dynamicArguments,
20412029
dynamicOutput,
2042-
onIstanbulCoverageVariable,
2043-
removeIstanbulCoverage,
20442030
} = kernel;
20452031

20462032
const argumentTypes = new Array(kernelArguments.length);
@@ -2091,12 +2077,12 @@ class FunctionBuilder {
20912077
functionBuilder.trackFunctionCall(functionName, calleeFunctionName, args);
20922078
};
20932079

2094-
const onNestedFunction = (ast, returnType) => {
2080+
const onNestedFunction = (ast, source) => {
20952081
const argumentNames = [];
20962082
for (let i = 0; i < ast.params.length; i++) {
20972083
argumentNames.push(ast.params[i].name);
20982084
}
2099-
const nestedFunction = new FunctionNode(null, Object.assign({}, nodeOptions, {
2085+
const nestedFunction = new FunctionNode(source, Object.assign({}, nodeOptions, {
21002086
returnType: null,
21012087
ast,
21022088
name: ast.id.name,
@@ -2127,8 +2113,6 @@ class FunctionBuilder {
21272113
triggerImplyArgumentType,
21282114
triggerImplyArgumentBitRatio,
21292115
onFunctionCall,
2130-
onIstanbulCoverageVariable: onIstanbulCoverageVariable ? (name) => onIstanbulCoverageVariable(name, kernel) : null,
2131-
removeIstanbulCoverage,
21322116
optimizeFloatMemory,
21332117
precision,
21342118
constants,
@@ -2181,8 +2165,6 @@ class FunctionBuilder {
21812165
triggerImplyArgumentBitRatio,
21822166
onFunctionCall,
21832167
onNestedFunction,
2184-
onIstanbulCoverageVariable: onIstanbulCoverageVariable ? (name) => onIstanbulCoverageVariable(name, kernel) : null,
2185-
removeIstanbulCoverage,
21862168
}));
21872169
}
21882170

@@ -2259,8 +2241,12 @@ class FunctionBuilder {
22592241
retList = retList || [];
22602242

22612243
if (this.nativeFunctionNames.indexOf(functionName) > -1) {
2262-
if (retList.indexOf(functionName) === -1) {
2244+
const nativeFunctionIndex = retList.indexOf(functionName);
2245+
if (nativeFunctionIndex === -1) {
22632246
retList.push(functionName);
2247+
} else {
2248+
const dependantNativeFunctionName = retList.splice(nativeFunctionIndex, 1)[0];
2249+
retList.push(dependantNativeFunctionName);
22642250
}
22652251
return retList;
22662252
}
@@ -2604,8 +2590,6 @@ class FunctionNode {
26042590
this.dynamicArguments = null;
26052591
this.strictTypingChecking = false;
26062592
this.fixIntegerDivisionAccuracy = null;
2607-
this.onIstanbulCoverageVariable = null;
2608-
this.removeIstanbulCoverage = false;
26092593

26102594
if (settings) {
26112595
for (const p in settings) {
@@ -2681,7 +2665,7 @@ class FunctionNode {
26812665

26822666
if (ast.type === 'MemberExpression') {
26832667
if (ast.object && ast.property) {
2684-
if (ast.object.hasOwnProperty('name') && ast.object.name[0] === '_') {
2668+
if (ast.object.hasOwnProperty('name') && ast.object.name !== 'Math') {
26852669
return this.astMemberExpressionUnroll(ast.property);
26862670
}
26872671

@@ -2772,7 +2756,7 @@ class FunctionNode {
27722756
}
27732757

27742758
for (let i = 0; i < functions.length; i++) {
2775-
this.onNestedFunction(functions[i]);
2759+
this.onNestedFunction(functions[i], this.source);
27762760
}
27772761
}
27782762

@@ -2901,6 +2885,11 @@ class FunctionNode {
29012885
if (this.getVariableSignature(ast.callee, true) === 'this.color') {
29022886
return null;
29032887
}
2888+
if (ast.callee.type === 'MemberExpression' && ast.callee.object && ast.callee.property && ast.callee.property.name && ast.arguments) {
2889+
const functionName = ast.callee.property.name;
2890+
this.inferArgumentTypesIfNeeded(functionName, ast.arguments);
2891+
return this.lookupReturnType(functionName, ast, this);
2892+
}
29042893
throw this.astErrorOutput('Unknown call expression', ast);
29052894
}
29062895
if (ast.callee && ast.callee.name) {
@@ -3341,8 +3330,6 @@ class FunctionNode {
33413330
'value[][][]',
33423331
'value[][][][]',
33433332
'value.value',
3344-
'value.value[]',
3345-
'value.value[][]',
33463333
'value.thread.value',
33473334
'this.thread.value',
33483335
'this.output.value',
@@ -3556,20 +3543,11 @@ class FunctionNode {
35563543
astThisExpression(ast, retArr) {
35573544
return retArr;
35583545
}
3559-
isIstanbulAST(ast) {
3560-
const variableSignature = this.getVariableSignature(ast);
3561-
return variableSignature === 'value.value[]' || variableSignature === 'value.value[][]';
3562-
}
35633546
astSequenceExpression(sNode, retArr) {
35643547
const { expressions } = sNode;
35653548
const sequenceResult = [];
35663549
for (let i = 0; i < expressions.length; i++) {
35673550
const expression = expressions[i];
3568-
if (this.removeIstanbulCoverage) {
3569-
if (expression.type === 'UpdateExpression' && this.isIstanbulAST(expression.argument)) {
3570-
continue;
3571-
}
3572-
}
35733551
const expressionResult = [];
35743552
this.astGeneric(expression, expressionResult);
35753553
sequenceResult.push(expressionResult.join(''));
@@ -3601,12 +3579,6 @@ class FunctionNode {
36013579
checkAndUpconvertBitwiseUnary(uNode, retArr) {}
36023580

36033581
astUpdateExpression(uNode, retArr) {
3604-
if (this.removeIstanbulCoverage) {
3605-
const signature = this.getVariableSignature(uNode.argument);
3606-
if (this.isIstanbulAST(uNode.argument)) {
3607-
return retArr;
3608-
}
3609-
}
36103582
if (uNode.prefix) {
36113583
retArr.push(uNode.operator);
36123584
this.astGeneric(uNode.argument, retArr);
@@ -3810,28 +3782,8 @@ class FunctionNode {
38103782
signature: variableSignature,
38113783
property: ast.property,
38123784
};
3813-
case 'value.value[]':
3814-
if (this.removeIstanbulCoverage) {
3815-
return { signature: variableSignature };
3816-
}
3817-
if (this.onIstanbulCoverageVariable) {
3818-
this.onIstanbulCoverageVariable(ast.object.object.name);
3819-
return {
3820-
signature: variableSignature
3821-
};
3822-
}
3823-
case 'value.value[][]':
3824-
if (this.removeIstanbulCoverage) {
3825-
return { signature: variableSignature };
3826-
}
3827-
if (this.onIstanbulCoverageVariable) {
3828-
this.onIstanbulCoverageVariable(ast.object.object.object.name);
3829-
return {
3830-
signature: variableSignature
3831-
};
3832-
}
3833-
default:
3834-
throw this.astErrorOutput('Unexpected expression', ast);
3785+
default:
3786+
throw this.astErrorOutput('Unexpected expression', ast);
38353787
}
38363788
}
38373789

@@ -6307,8 +6259,6 @@ class Kernel {
63076259
this.optimizeFloatMemory = null;
63086260
this.strictIntegers = false;
63096261
this.fixIntegerDivisionAccuracy = null;
6310-
this.onIstanbulCoverageVariable = null;
6311-
this.removeIstanbulCoverage = false;
63126262
this.built = false;
63136263
this.signature = null;
63146264
}
@@ -6335,11 +6285,6 @@ class Kernel {
63356285
}
63366286
this[p] = settings[p];
63376287
continue;
6338-
case 'removeIstanbulCoverage':
6339-
if (settings[p] !== null) {
6340-
this[p] = settings[p];
6341-
}
6342-
continue;
63436288
case 'nativeFunctions':
63446289
if (!settings.nativeFunctions) continue;
63456290
this.nativeFunctions = [];
@@ -8334,13 +8279,8 @@ class WebGLFunctionNode extends FunctionNode {
83348279
retArr.push(this.memberExpressionPropertyMarkup(property));
83358280
retArr.push(']');
83368281
return retArr;
8337-
case 'value.value[]':
8338-
case 'value.value[][]':
8339-
if (this.removeIstanbulCoverage) {
8340-
return retArr;
8341-
}
8342-
default:
8343-
throw this.astErrorOutput('Unexpected expression', mNode);
8282+
default:
8283+
throw this.astErrorOutput('Unexpected expression', mNode);
83448284
}
83458285

83468286
if (mNode.computed === false) {
@@ -10179,7 +10119,6 @@ class WebGLKernel extends GLKernel {
1017910119

1018010120
this.maxTexSize = null;
1018110121
this.onRequestSwitchKernel = null;
10182-
this.removeIstanbulCoverage = true;
1018310122

1018410123
this.texture = null;
1018510124
this.mappedTextures = null;
@@ -10376,7 +10315,7 @@ class WebGLKernel extends GLKernel {
1037610315
return this.createTexture();
1037710316
};
1037810317
const onRequestIndex = () => {
10379-
return textureIndexes++;
10318+
return this.constantTextureCount + textureIndexes++;
1038010319
};
1038110320
const onUpdateValueMismatch = (constructor) => {
1038210321
this.switchKernels({
@@ -13534,8 +13473,6 @@ class GPU {
1353413473
this.functions = [];
1353513474
this.nativeFunctions = [];
1353613475
this.injectedNative = null;
13537-
this.onIstanbulCoverageVariable = settings.onIstanbulCoverageVariable || null;
13538-
this.removeIstanbulCoverage = settings.hasOwnProperty('removeIstanbulCoverage') ? settings.removeIstanbulCoverage : null;
1353913476
if (this.mode === 'dev') return;
1354013477
this.chooseKernel();
1354113478
if (settings.functions) {
@@ -13711,8 +13648,6 @@ class GPU {
1371113648
gpu: _kernel.gpu,
1371213649
validate,
1371313650
returnType: _kernel.returnType,
13714-
onIstanbulCoverageVariable: _kernel.onIstanbulCoverageVariable,
13715-
removeIstanbulCoverage: _kernel.removeIstanbulCoverage,
1371613651
tactic: _kernel.tactic,
1371713652
onRequestFallback,
1371813653
onRequestSwitchKernel,
@@ -13731,8 +13666,6 @@ class GPU {
1373113666
functions: this.functions,
1373213667
nativeFunctions: this.nativeFunctions,
1373313668
injectedNative: this.injectedNative,
13734-
onIstanbulCoverageVariable: this.onIstanbulCoverageVariable,
13735-
removeIstanbulCoverage: this.removeIstanbulCoverage,
1373613669
gpu: this,
1373713670
validate,
1373813671
onRequestFallback,

dist/gpu-browser-core.min.js

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)