typegpu 0.12.8 → 0.12.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/common/attachAutoResizer.d.ts +33 -0
- package/common/attachAutoResizer.js +83 -0
- package/common/index.d.ts +1 -0
- package/common/index.js +1 -0
- package/common/writeSoA.js +4 -3
- package/core/commandEncoder/commandEncoder.d.ts +1 -1
- package/core/declare/tgpuDeclare.d.ts +10 -7
- package/core/declare/tgpuDeclare.js +25 -10
- package/core/function/comptime.d.ts +2 -0
- package/core/function/comptime.js +29 -24
- package/core/function/createCallableSchema.js +32 -37
- package/core/function/dualImpl.js +45 -44
- package/core/function/tgpuComputeFn.d.ts +0 -3
- package/core/function/tgpuFn.d.ts +1 -0
- package/core/function/tgpuFn.js +14 -4
- package/core/function/tgpuFragmentFn.d.ts +1 -1
- package/core/function/tgpuVertexFn.d.ts +1 -1
- package/core/pipeline/computePipeline.js +5 -2
- package/core/pipeline/drawState.js +1 -1
- package/core/pipeline/renderPipeline.js +5 -2
- package/core/pipeline/webgpuLimitations.js +11 -3
- package/core/resolve/externals.js +4 -0
- package/core/resolve/namespace.d.ts +4 -0
- package/core/resolve/namespace.js +1 -2
- package/core/resolve/stitch.js +13 -8
- package/core/root/init.d.ts +3 -3
- package/core/root/init.js +12 -13
- package/core/root/rootTypes.d.ts +44 -37
- package/core/slot/accessor.js +4 -4
- package/core/texture/texture.d.ts +3 -3
- package/core/texture/texture.js +60 -44
- package/core/texture/textureFormats.d.ts +4 -3
- package/core/texture/textureFormats.js +17 -6
- package/core/texture/textureWrite.d.ts +9 -0
- package/core/texture/textureWrite.js +21 -0
- package/core/unroll/tgpuUnroll.js +2 -4
- package/core/vertexLayout/vertexAttribute.d.ts +1 -4
- package/core/vertexLayout/vertexLayout.js +11 -30
- package/data/alignmentOf.d.ts +1 -1
- package/data/alignmentOf.js +5 -12
- package/data/array.js +34 -2
- package/data/attributes.d.ts +16 -3
- package/data/attributes.js +11 -2
- package/data/compiledIO.js +3 -3
- package/data/dataIO.js +77 -111
- package/data/dataTypes.d.ts +0 -2
- package/data/dataTypes.js +3 -3
- package/data/disarray.js +2 -0
- package/data/index.d.ts +4 -3
- package/data/index.js +3 -2
- package/data/offsetUtils.js +23 -13
- package/data/offsets.js +1 -2
- package/data/partialIO.js +2 -3
- package/data/ref.js +35 -37
- package/data/schemaCallWrapper.js +2 -2
- package/data/schemaMemoryLayout.d.ts +6 -1
- package/data/schemaMemoryLayout.js +23 -14
- package/data/schemasEqual.d.ts +37 -0
- package/data/schemasEqual.js +122 -0
- package/data/sizeOf.d.ts +1 -1
- package/data/sizeOf.js +2 -3
- package/data/snippet.d.ts +1 -1
- package/data/struct.js +27 -1
- package/data/unstruct.js +2 -0
- package/data/vectorImpl.js +45 -21
- package/data/vertexFormatData.js +7 -9
- package/data/wgslTypes.d.ts +28 -13
- package/data/wgslTypes.js +33 -39
- package/extension.d.ts +0 -4
- package/package.json +2 -2
- package/resolutionCtx.d.ts +1 -1
- package/resolutionCtx.js +26 -7
- package/serial/restore.d.ts +4 -3
- package/serial/restore.js +2 -1
- package/shared/meta.js +1 -1
- package/shared/symbols.d.ts +5 -0
- package/shared/symbols.js +6 -1
- package/shared/utilityTypes.d.ts +0 -6
- package/std/bitcast.d.ts +1 -1
- package/std/comptime.d.ts +67 -0
- package/std/comptime.js +88 -0
- package/std/environment.js +2 -4
- package/std/index.d.ts +2 -0
- package/std/index.js +2 -0
- package/std/matrix.js +5 -5
- package/std/numeric.d.ts +2 -1
- package/std/numeric.js +47 -10
- package/std/typeOf.d.ts +31 -0
- package/std/typeOf.js +54 -0
- package/tgpu.d.ts +1 -1
- package/tgpu.js +1 -1
- package/tgpuBindGroupLayout.d.ts +6 -3
- package/tgpuBindGroupLayout.js +15 -2
- package/tgpuLogger.d.ts +3 -0
- package/tgpuLogger.js +3 -0
- package/tgpuUnstableNamespace.d.ts +1 -0
- package/tgpuUnstableNamespace.js +5 -0
- package/tgsl/accessIndex.js +10 -7
- package/tgsl/accessProp.js +5 -57
- package/tgsl/consoleLog/serializers.d.ts +1 -8
- package/tgsl/consoleLog/serializers.js +53 -37
- package/tgsl/consoleLog/types.d.ts +1 -1
- package/tgsl/conversion.js +21 -0
- package/tgsl/forOfUtils.js +1 -1
- package/tgsl/generationHelpers.d.ts +0 -1
- package/tgsl/generationHelpers.js +1 -4
- package/tgsl/shaderGenerator.d.ts +5 -0
- package/tgsl/shellless.js +3 -20
- package/tgsl/swizzle.d.ts +24 -0
- package/tgsl/swizzle.js +112 -0
- package/tgsl/wgslGenerator.d.ts +13 -3
- package/tgsl/wgslGenerator.js +150 -152
- package/types.d.ts +10 -10
- package/types.js +1 -1
- package/unwrapper.d.ts +2 -2
- package/data/deepEqual.d.ts +0 -21
- package/data/deepEqual.js +0 -93
- package/taskQueue.d.ts +0 -6
- package/taskQueue.js +0 -30
package/tgsl/wgslGenerator.js
CHANGED
|
@@ -8,14 +8,15 @@ import { fallthroughCopyOrigin, isMutableOrigin, isStoredInMemory, snip, } from
|
|
|
8
8
|
import * as wgsl from "../data/wgslTypes.js";
|
|
9
9
|
import { invariant, ResolutionError, WgslForbiddenStatementError, WgslTypeError, } from "../errors.js";
|
|
10
10
|
import { getName } from "../shared/meta.js";
|
|
11
|
-
import { $gpuCallable, $internal, $providing, isMarkedInternal } from "../shared/symbols.js";
|
|
11
|
+
import { $gpuCallable, $gpuCallableStrictSignature, $internal, $providing, isMarkedInternal, } from "../shared/symbols.js";
|
|
12
12
|
import { safeStringify } from "../shared/stringify.js";
|
|
13
|
-
import {
|
|
13
|
+
import { powOperator } from "../std/numeric.js";
|
|
14
14
|
import { add, div, mul, neg, sub } from "../std/operators.js";
|
|
15
15
|
import { eq, ne, lt, le, gt, ge, not } from "../std/boolean.js";
|
|
16
16
|
import { asComptime, isConstant, isGPUCallable, } from "../types.js";
|
|
17
17
|
import { convertStructValues, convertToCommonType, tryConvertSnippet } from "./conversion.js";
|
|
18
18
|
import { ArrayExpression, coerceToSnippet, concretize, numericLiteralToSnippet, } from "./generationHelpers.js";
|
|
19
|
+
import { Swizzle } from "./swizzle.js";
|
|
19
20
|
import { accessIndex } from "./accessIndex.js";
|
|
20
21
|
import { accessProp } from "./accessProp.js";
|
|
21
22
|
import { resolveData } from "../core/resolve/resolveData.js";
|
|
@@ -29,7 +30,7 @@ import { mathToStd, supportedLogOps } from "./jsPolyfills.js";
|
|
|
29
30
|
import * as forOfUtils from "./forOfUtils.js";
|
|
30
31
|
import { isTgpuRange } from "../std/range.js";
|
|
31
32
|
import { stringifyNode, stringifyObjectProperty } from "../shared/tseynit.js";
|
|
32
|
-
import { setSourceNode, stringifySnippet } from "./stringifySnippet.js";
|
|
33
|
+
import { getSourceNode, setSourceNode, stringifySnippet } from "./stringifySnippet.js";
|
|
33
34
|
import { getAttributesString } from "../data/attributes.js";
|
|
34
35
|
import { validSelectBranchTypes } from "../std/boolean.js";
|
|
35
36
|
import { isInfixDispatch } from "./infixDispatch.js";
|
|
@@ -122,7 +123,7 @@ function operatorToType(lhs, op, rhs) {
|
|
|
122
123
|
return lhs;
|
|
123
124
|
}
|
|
124
125
|
const unaryOpCodeToCodegen = {
|
|
125
|
-
'-': neg[$gpuCallable].
|
|
126
|
+
'-': neg[$gpuCallable].bind(neg),
|
|
126
127
|
void: () => snip(undefined, wgsl.Void, 'constant', false),
|
|
127
128
|
'!': (ctx, [argExpr]) => {
|
|
128
129
|
if (argExpr === undefined) {
|
|
@@ -142,11 +143,11 @@ const unaryOpCodeToCodegen = {
|
|
|
142
143
|
},
|
|
143
144
|
};
|
|
144
145
|
const binaryOpCodeToCodegen = {
|
|
145
|
-
'+': add[$gpuCallable].
|
|
146
|
-
'-': sub[$gpuCallable].
|
|
147
|
-
'*': mul[$gpuCallable].
|
|
148
|
-
'/': div[$gpuCallable].
|
|
149
|
-
'**':
|
|
146
|
+
'+': add[$gpuCallable].bind(add),
|
|
147
|
+
'-': sub[$gpuCallable].bind(sub),
|
|
148
|
+
'*': mul[$gpuCallable].bind(mul),
|
|
149
|
+
'/': div[$gpuCallable].bind(div),
|
|
150
|
+
'**': powOperator[$gpuCallable].bind(powOperator),
|
|
150
151
|
};
|
|
151
152
|
const usageToVarTemplateMap = {
|
|
152
153
|
private: 'private',
|
|
@@ -339,26 +340,102 @@ export class WgslGenerator {
|
|
|
339
340
|
return shelllessCall;
|
|
340
341
|
}
|
|
341
342
|
/**
|
|
342
|
-
* A wrapper for `
|
|
343
|
-
*
|
|
343
|
+
* A wrapper for `_expression` that updates `ctx.expectedType` while generating.
|
|
344
|
+
* The result is NOT converted to the expected type.
|
|
344
345
|
*/
|
|
345
|
-
|
|
346
|
+
_expressionWithTypeSuggestion(expression, expectedType) {
|
|
346
347
|
const prevExpectedType = this.ctx.expectedType;
|
|
347
348
|
this.ctx.expectedType = expectedType;
|
|
348
349
|
try {
|
|
349
|
-
|
|
350
|
-
if (expectedType instanceof AutoStruct) {
|
|
351
|
-
// We provide a certain AutoStruct object to later
|
|
352
|
-
// investigate what props were accessed. No need to
|
|
353
|
-
// convert the result.
|
|
354
|
-
return result;
|
|
355
|
-
}
|
|
356
|
-
return setSourceNode(tryConvertSnippet(this.ctx, result, expectedType), expression);
|
|
350
|
+
return this._expression(expression);
|
|
357
351
|
}
|
|
358
352
|
finally {
|
|
359
353
|
this.ctx.expectedType = prevExpectedType;
|
|
360
354
|
}
|
|
361
355
|
}
|
|
356
|
+
/**
|
|
357
|
+
* Like `_expressionWithTypeSuggestion`, but also tries to convert the result
|
|
358
|
+
* when it does not match the expected type.
|
|
359
|
+
*/
|
|
360
|
+
_expressionWithTypeConversion(expression, expectedType) {
|
|
361
|
+
const result = this._expressionWithTypeSuggestion(expression, expectedType);
|
|
362
|
+
if (expectedType instanceof AutoStruct) {
|
|
363
|
+
// We provide a certain AutoStruct object to later
|
|
364
|
+
// investigate what props were accessed. No need to
|
|
365
|
+
// convert the result.
|
|
366
|
+
return result;
|
|
367
|
+
}
|
|
368
|
+
return setSourceNode(tryConvertSnippet(this.ctx, result, expectedType), expression);
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* @param calleeSnippet The snippet the callee was produced from, used for more descriptive errors.
|
|
372
|
+
*/
|
|
373
|
+
call(_callee, args, calleeSnippet) {
|
|
374
|
+
const callee = mathToStd.get(_callee) ?? _callee;
|
|
375
|
+
if (supportedLogOps().includes(callee)) {
|
|
376
|
+
return this.ctx.generateLog(callee, args);
|
|
377
|
+
}
|
|
378
|
+
if (callee === constant) {
|
|
379
|
+
throw new Error('Constants cannot be defined within TypeGPU function scope. To address this, move the constant definition outside the function scope.');
|
|
380
|
+
}
|
|
381
|
+
if (isInfixDispatch(callee)) {
|
|
382
|
+
if (!args[0]) {
|
|
383
|
+
throw new WgslTypeError(`An infix operator '${getName(callee.operator)}' was called without any arguments`);
|
|
384
|
+
}
|
|
385
|
+
const lhs = coerceToSnippet(callee.lhs);
|
|
386
|
+
const rhs = args[0];
|
|
387
|
+
return callee.operator[$gpuCallable](this.ctx, [lhs, rhs]);
|
|
388
|
+
}
|
|
389
|
+
if (isGPUCallable(callee)) {
|
|
390
|
+
const strictSignature = callee[$gpuCallableStrictSignature];
|
|
391
|
+
let convertedArguments;
|
|
392
|
+
if (strictSignature) {
|
|
393
|
+
// The function's signature does not depend on the context, so it can be used to
|
|
394
|
+
// give a hint to the argument expressions that a specific type is expected.
|
|
395
|
+
convertedArguments = args.map((arg, i) => {
|
|
396
|
+
const argType = strictSignature.argTypes[i];
|
|
397
|
+
if (!argType) {
|
|
398
|
+
return arg;
|
|
399
|
+
}
|
|
400
|
+
const converted = tryConvertSnippet(this.ctx, arg, argType);
|
|
401
|
+
const sourceNode = getSourceNode(arg);
|
|
402
|
+
return sourceNode !== undefined ? setSourceNode(converted, sourceNode) : converted;
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
else {
|
|
406
|
+
convertedArguments = args;
|
|
407
|
+
}
|
|
408
|
+
try {
|
|
409
|
+
return callee[$gpuCallable](this.ctx, convertedArguments);
|
|
410
|
+
}
|
|
411
|
+
catch (err) {
|
|
412
|
+
if (err instanceof ResolutionError) {
|
|
413
|
+
throw err;
|
|
414
|
+
}
|
|
415
|
+
throw new ResolutionError(err, [
|
|
416
|
+
{
|
|
417
|
+
toString: () => `fn:${getName(callee)}`,
|
|
418
|
+
},
|
|
419
|
+
]);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
if (!isMarkedInternal(callee) || isGenericFn(callee)) {
|
|
423
|
+
const result = this._callShellless(callee, args);
|
|
424
|
+
if (result) {
|
|
425
|
+
return result;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
// try to throw a descriptive error
|
|
429
|
+
const maybeMathMethod = Object.getOwnPropertyNames(Math).find((prop) => Math[prop] === callee);
|
|
430
|
+
if (maybeMathMethod) {
|
|
431
|
+
throw new Error(`Unsupported Math functionality 'Math.${maybeMathMethod}()'. Use an std alternative, or implement the function manually.`);
|
|
432
|
+
}
|
|
433
|
+
const maybeConsoleMethod = Object.getOwnPropertyNames(console).find((prop) => console[prop] === callee);
|
|
434
|
+
if (maybeConsoleMethod) {
|
|
435
|
+
throw new Error(`Unsupported console functionality 'console.${maybeConsoleMethod}()'.`);
|
|
436
|
+
}
|
|
437
|
+
throw new Error(`Function '${getName(callee) ?? (calleeSnippet ? stringifySnippet(calleeSnippet) : String(callee))}' is not marked with the 'use gpu' directive and cannot be used in a shader`);
|
|
438
|
+
}
|
|
362
439
|
_expression(expression) {
|
|
363
440
|
// Remembering which JS expression produced the snippet, for more descriptive errors
|
|
364
441
|
return setSourceNode(this._expressionImpl(expression), expression);
|
|
@@ -499,7 +576,7 @@ export class WgslGenerator {
|
|
|
499
576
|
}
|
|
500
577
|
const type = operatorToType(convLhs.dataType, op, convRhs.dataType);
|
|
501
578
|
if (exprType === NODE.assignmentExpr) {
|
|
502
|
-
validateSnippetMutation(convLhs, expression);
|
|
579
|
+
this.validateSnippetMutation(convLhs, expression);
|
|
503
580
|
this.tryMarkModified(lhs);
|
|
504
581
|
// Compound assignment operators are okay, e.g. +=, -=, *=, /=, ...
|
|
505
582
|
if (op === '=' &&
|
|
@@ -570,125 +647,36 @@ export class WgslGenerator {
|
|
|
570
647
|
const type = typeof expression[1] === 'string'
|
|
571
648
|
? numericLiteralToSnippet(parseNumericString(expression[1]))
|
|
572
649
|
: numericLiteralToSnippet(expression[1]);
|
|
573
|
-
invariant(type, `Expected ${stringifyNode(expression)} to be valid numeric literal`);
|
|
650
|
+
invariant(type, () => `Expected ${stringifyNode(expression)} to be valid numeric literal`);
|
|
574
651
|
return type;
|
|
575
652
|
}
|
|
576
653
|
if (expression[0] === NODE.call) {
|
|
577
654
|
// Function Call
|
|
578
655
|
const [_, calleeNode, argNodes] = expression;
|
|
579
656
|
const _callee = this._expression(calleeNode);
|
|
580
|
-
const callee = mathToStd.
|
|
581
|
-
|
|
582
|
-
: _callee;
|
|
583
|
-
if (supportedLogOps().includes(callee.value)) {
|
|
584
|
-
return this.ctx.generateLog(callee.value, argNodes.map((arg) => this._expression(arg)));
|
|
585
|
-
}
|
|
586
|
-
if (wgsl.isWgslStruct(callee.value)) {
|
|
587
|
-
// Struct schema call.
|
|
588
|
-
if (argNodes.length > 1) {
|
|
589
|
-
throw new WgslTypeError('Struct schemas should always be called with at most 1 argument');
|
|
590
|
-
}
|
|
591
|
-
// No arguments `Struct()`, resolve struct name and return.
|
|
592
|
-
if (!argNodes[0]) {
|
|
593
|
-
// The schema becomes the data type.
|
|
594
|
-
return snip(`${this.ctx.resolve(callee.value).value}()`, callee.value,
|
|
595
|
-
// A new struct, so not a reference.
|
|
596
|
-
/* origin */ 'runtime', false);
|
|
597
|
-
}
|
|
598
|
-
const arg = this._typedExpression(argNodes[0], callee.value);
|
|
599
|
-
// Either `Struct({ x: 1, y: 2 })`, or `Struct(otherStruct)`.
|
|
600
|
-
// In both cases, we just let the argument resolve everything.
|
|
601
|
-
return snip(this.ctx.resolveSnippet(arg).value, callee.value,
|
|
602
|
-
// A new struct, so not a reference.
|
|
603
|
-
/* origin */ 'runtime', arg.possibleSideEffects);
|
|
604
|
-
}
|
|
605
|
-
if (wgsl.isWgslArray(callee.value)) {
|
|
606
|
-
// Array schema call.
|
|
607
|
-
if (argNodes.length > 1) {
|
|
608
|
-
throw new WgslTypeError('Array schemas should always be called with at most 1 argument');
|
|
609
|
-
}
|
|
610
|
-
// No arguments `array<...>()`, resolve array type and return.
|
|
611
|
-
if (!argNodes[0]) {
|
|
612
|
-
// The schema becomes the data type.
|
|
613
|
-
return this.typeInstantiation(callee.value, []);
|
|
614
|
-
}
|
|
615
|
-
const arg = this._typedExpression(argNodes[0], callee.value);
|
|
616
|
-
// `d.arrayOf(...)([...])`.
|
|
617
|
-
// We don't resolve the ArrayExpression object itself to
|
|
618
|
-
// avoid reference checks (we're copying so it's fine)
|
|
619
|
-
if (arg.value instanceof ArrayExpression) {
|
|
620
|
-
return this.typeInstantiation(callee.value, arg.value.elements);
|
|
621
|
-
}
|
|
622
|
-
// `d.arrayOf(...)(otherArr)`.
|
|
623
|
-
// We just let the argument resolve everything.
|
|
624
|
-
return snip(this.ctx.resolveSnippet(arg).value, callee.value,
|
|
625
|
-
// A new array, so not a reference.
|
|
626
|
-
/* origin */ fallthroughCopyOrigin(arg.origin), arg.possibleSideEffects);
|
|
627
|
-
}
|
|
628
|
-
if (callee.value === constant) {
|
|
629
|
-
throw new Error('Constants cannot be defined within TypeGPU function scope. To address this, move the constant definition outside the function scope.');
|
|
630
|
-
}
|
|
631
|
-
if (isInfixDispatch(callee.value)) {
|
|
632
|
-
if (!argNodes[0]) {
|
|
633
|
-
throw new WgslTypeError(`An infix operator '${getName(callee.value.operator)}' was called without any arguments`);
|
|
634
|
-
}
|
|
635
|
-
const lhs = coerceToSnippet(callee.value.lhs);
|
|
636
|
-
const rhs = this._expression(argNodes[0]);
|
|
637
|
-
const callable = callee.value.operator[$gpuCallable];
|
|
638
|
-
return callable.call(this.ctx, [lhs, rhs]);
|
|
639
|
-
}
|
|
640
|
-
if ((callee.value === _ref || callee.value === unroll) && argNodes[0]) {
|
|
657
|
+
const callee = mathToStd.get(_callee.value) ?? _callee.value;
|
|
658
|
+
if ((callee === _ref || callee === unroll) && argNodes[0]) {
|
|
641
659
|
this.tryMarkModified(argNodes[0]);
|
|
642
660
|
}
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
const strictSignature =
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
const
|
|
652
|
-
|
|
653
|
-
throw new WgslTypeError(`Call '${stringifyNode(expression)}' is invalid since the function expected fewer arguments`);
|
|
654
|
-
}
|
|
655
|
-
return this._typedExpression(arg, argType);
|
|
656
|
-
});
|
|
657
|
-
}
|
|
658
|
-
else {
|
|
659
|
-
convertedArguments = argNodes.map((arg) => this._expression(arg));
|
|
660
|
-
}
|
|
661
|
-
try {
|
|
662
|
-
return callable.call(this.ctx, convertedArguments);
|
|
663
|
-
}
|
|
664
|
-
catch (err) {
|
|
665
|
-
if (err instanceof ResolutionError) {
|
|
666
|
-
throw err;
|
|
661
|
+
let args;
|
|
662
|
+
if (isGPUCallable(callee) && callee[$gpuCallableStrictSignature]) {
|
|
663
|
+
const strictSignature = callee[$gpuCallableStrictSignature];
|
|
664
|
+
// The function's signature does not depend on the context, so it can be used to
|
|
665
|
+
// give a hint to the argument expressions that a specific type is expected.
|
|
666
|
+
args = argNodes.map((arg, i) => {
|
|
667
|
+
const argType = strictSignature.argTypes[i];
|
|
668
|
+
if (!argType) {
|
|
669
|
+
const length = strictSignature.argTypes.length;
|
|
670
|
+
throw new WgslTypeError(`Call '${stringifyNode(expression)}' is invalid, the function expected at most ${length} argument${length === 1 ? '' : 's'}`);
|
|
667
671
|
}
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
},
|
|
672
|
-
]);
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
if (!isMarkedInternal(callee.value) || isGenericFn(callee.value)) {
|
|
676
|
-
const args = argNodes.map((arg) => this._expression(arg));
|
|
677
|
-
const result = this._callShellless(callee.value, args);
|
|
678
|
-
if (result) {
|
|
679
|
-
return result;
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
// try to throw a descriptive error
|
|
683
|
-
const maybeMathMethod = Object.getOwnPropertyNames(Math).find((prop) => Math[prop] === callee.value);
|
|
684
|
-
if (maybeMathMethod) {
|
|
685
|
-
throw new Error(`Unsupported Math functionality 'Math.${maybeMathMethod}()'. Use an std alternative, or implement the function manually.`);
|
|
672
|
+
// It's only a suggestion, the conversion happens later on
|
|
673
|
+
return this._expressionWithTypeSuggestion(arg, argType);
|
|
674
|
+
});
|
|
686
675
|
}
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
throw new Error(`Unsupported console functionality 'console.${maybeConsoleMethod}()'.`);
|
|
676
|
+
else {
|
|
677
|
+
args = argNodes.map((arg) => this._expression(arg));
|
|
690
678
|
}
|
|
691
|
-
|
|
679
|
+
return this.call(callee, args, _callee);
|
|
692
680
|
}
|
|
693
681
|
if (expression[0] === NODE.objectExpr) {
|
|
694
682
|
// Normalize to `objectProperty[]`
|
|
@@ -714,7 +702,7 @@ export class WgslGenerator {
|
|
|
714
702
|
let expr;
|
|
715
703
|
if (accessed) {
|
|
716
704
|
// Generating the expression expecting a specific type
|
|
717
|
-
expr = this.
|
|
705
|
+
expr = this._expressionWithTypeConversion(value, accessed.type);
|
|
718
706
|
}
|
|
719
707
|
else {
|
|
720
708
|
// Generating the expression and inferring the type instead
|
|
@@ -750,7 +738,7 @@ The generated shader will omit it, so its runtime side effects will not occur.`)
|
|
|
750
738
|
}
|
|
751
739
|
continue;
|
|
752
740
|
}
|
|
753
|
-
const expr = this.
|
|
741
|
+
const expr = this._expressionWithTypeConversion(value, propType);
|
|
754
742
|
entries[key] = expr;
|
|
755
743
|
if (expr.possibleSideEffects) {
|
|
756
744
|
keysWithSideEffectsInSourceOrder.push(key);
|
|
@@ -787,7 +775,7 @@ The generated shader will evaluate them in declaration order.`);
|
|
|
787
775
|
if (wgsl.isWgslArray(arrType)) {
|
|
788
776
|
elemType = arrType.elementType;
|
|
789
777
|
// The array is typed, so its elements should be as well.
|
|
790
|
-
values = valueNodes.map((value) => this.
|
|
778
|
+
values = valueNodes.map((value) => this._expressionWithTypeConversion(value, elemType));
|
|
791
779
|
// Since it's an expected type, we enforce the length
|
|
792
780
|
if (values.length !== arrType.elementCount) {
|
|
793
781
|
throw new WgslTypeError(`Cannot create value of type '${arrType}' from an array of length: ${values.length}`);
|
|
@@ -880,13 +868,12 @@ The generated shader will evaluate them in declaration order.`);
|
|
|
880
868
|
let body = this._block(options.body, /* allowInlining */ false);
|
|
881
869
|
const scope = this.ctx.topFunctionScope;
|
|
882
870
|
invariant(scope, 'Expected function scope to be present');
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
body.code = body.code.replace(regex, (match) => replacements[match] ?? '#ERR');
|
|
871
|
+
if (scope.placeholderForVariable.size > 0) {
|
|
872
|
+
const keywordForPlaceholder = new Map();
|
|
873
|
+
for (const [variable, placeholder] of scope.placeholderForVariable) {
|
|
874
|
+
keywordForPlaceholder.set(placeholder, scope.modifiedVariables.has(variable) ? 'var' : 'let');
|
|
875
|
+
}
|
|
876
|
+
body.code = body.code.replace(/#VAR_\d+#/g, (match) => keywordForPlaceholder.get(match) ?? '#ERR');
|
|
890
877
|
}
|
|
891
878
|
// Only after generating the body can we determine the return type
|
|
892
879
|
const returnType = options.determineReturnType();
|
|
@@ -978,7 +965,7 @@ The generated shader will evaluate them in declaration order.`);
|
|
|
978
965
|
if (returnNode !== undefined) {
|
|
979
966
|
const expectedReturnType = this.ctx.topFunctionReturnType;
|
|
980
967
|
let returnSnippet = expectedReturnType
|
|
981
|
-
? this.
|
|
968
|
+
? this._expressionWithTypeConversion(returnNode, expectedReturnType)
|
|
982
969
|
: this._expression(returnNode);
|
|
983
970
|
if (returnSnippet.value === undefined && wgsl.isVoid(returnSnippet.dataType)) {
|
|
984
971
|
this.ctx.reportReturnType(wgsl.Void);
|
|
@@ -1213,10 +1200,11 @@ Try 'return ${typeStr}(${str});' instead.
|
|
|
1213
1200
|
}
|
|
1214
1201
|
if (statement[0] === NODE.if) {
|
|
1215
1202
|
const [_, condNode, consNode, altNode] = statement;
|
|
1216
|
-
const condition = this.
|
|
1217
|
-
|
|
1203
|
+
const condition = this._expressionWithTypeConversion(condNode, bool);
|
|
1204
|
+
const comptimeCondition = asComptime(condition);
|
|
1205
|
+
if (typeof comptimeCondition?.value === 'boolean') {
|
|
1218
1206
|
// the condition is known at comptime
|
|
1219
|
-
let node =
|
|
1207
|
+
let node = comptimeCondition.value ? consNode : altNode;
|
|
1220
1208
|
if (node === undefined) {
|
|
1221
1209
|
return { code: '', definesInNearestScope: false };
|
|
1222
1210
|
}
|
|
@@ -1268,7 +1256,7 @@ ${this.ctx.pre}else ${alternate}`,
|
|
|
1268
1256
|
this.ctx.pushBlockScope();
|
|
1269
1257
|
const [initStatement, conditionExpr, updateStatement] = this.ctx.withResetIndentLevel(() => [
|
|
1270
1258
|
init ? this._statement(init).code : undefined,
|
|
1271
|
-
condition ? this.
|
|
1259
|
+
condition ? this._expressionWithTypeConversion(condition, bool) : undefined,
|
|
1272
1260
|
update ? this._statement(update).code : undefined,
|
|
1273
1261
|
]);
|
|
1274
1262
|
const initStr = initStatement ? initStatement.slice(0, -1) : '';
|
|
@@ -1289,7 +1277,7 @@ ${this.ctx.pre}else ${alternate}`,
|
|
|
1289
1277
|
this.#unrollingChain = [];
|
|
1290
1278
|
try {
|
|
1291
1279
|
const [_, condition, body] = statement;
|
|
1292
|
-
const condSnippet = this.
|
|
1280
|
+
const condSnippet = this._expressionWithTypeConversion(condition, bool);
|
|
1293
1281
|
const conditionStr = this.ctx.resolveSnippet(condSnippet).value;
|
|
1294
1282
|
const bodyStr = this._block(blockifySingleStatement(body), /* allowInlining */ false).code;
|
|
1295
1283
|
return {
|
|
@@ -1327,7 +1315,7 @@ ${this.ctx.pre}else ${alternate}`,
|
|
|
1327
1315
|
? value.map((i) => coerceToSnippet(i))
|
|
1328
1316
|
: value instanceof ArrayExpression
|
|
1329
1317
|
? value.elements
|
|
1330
|
-
: Array.from({ length: knownEnd.value }, (_, i) => forOfUtils.getElementSnippet(iterableSnippet, snip(i, u32, 'constant')));
|
|
1318
|
+
: Array.from({ length: knownEnd.value }, (_, i) => forOfUtils.getElementSnippet(iterableSnippet, snip(i, u32, 'constant', false)));
|
|
1331
1319
|
if (elements.length === 0) {
|
|
1332
1320
|
return { code: '', definesInNearestScope: false };
|
|
1333
1321
|
}
|
|
@@ -1504,7 +1492,7 @@ ${stringifyNode(statement)}`);
|
|
|
1504
1492
|
const [_, op, arg] = statement;
|
|
1505
1493
|
const argExpr = this._expression(arg);
|
|
1506
1494
|
const argStr = this.ctx.resolveSnippet(argExpr).value;
|
|
1507
|
-
validateSnippetMutation(argExpr, statement);
|
|
1495
|
+
this.validateSnippetMutation(argExpr, statement);
|
|
1508
1496
|
this.tryMarkModified(arg);
|
|
1509
1497
|
return { code: `${this.ctx.pre}${argStr}${op};`, definesInNearestScope: false };
|
|
1510
1498
|
}
|
|
@@ -1585,6 +1573,17 @@ ${stringifyNode(statement)}`);
|
|
|
1585
1573
|
}
|
|
1586
1574
|
}
|
|
1587
1575
|
}
|
|
1576
|
+
validateSnippetMutation(mutated, expr) {
|
|
1577
|
+
if (mutated.value instanceof Swizzle) {
|
|
1578
|
+
if (mutated.value.base.value instanceof Swizzle) {
|
|
1579
|
+
throw new Error(`'${stringifyNode(expr)}' is invalid. Nested swizzle mutation is disallowed for JS consistency.`);
|
|
1580
|
+
}
|
|
1581
|
+
throwIfImmutable(mutated.value.base.origin, expr, asComptime(mutated.value.base) !== undefined);
|
|
1582
|
+
}
|
|
1583
|
+
else {
|
|
1584
|
+
throwIfImmutable(mutated.origin, expr, asComptime(mutated) !== undefined);
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1588
1587
|
}
|
|
1589
1588
|
const immutabilityReasons = {
|
|
1590
1589
|
constant: 'the left side is a constant',
|
|
@@ -1596,14 +1595,13 @@ const immutabilityReasons = {
|
|
|
1596
1595
|
argument: 'non-pointer arguments cannot be mutated',
|
|
1597
1596
|
handle: 'textures and samplers cannot be mutated',
|
|
1598
1597
|
};
|
|
1599
|
-
function
|
|
1600
|
-
if (isMutableOrigin(
|
|
1598
|
+
function throwIfImmutable(origin, expr, knownAtComptime) {
|
|
1599
|
+
if (isMutableOrigin(origin)) {
|
|
1601
1600
|
return;
|
|
1602
1601
|
}
|
|
1603
|
-
const reason =
|
|
1602
|
+
const reason = knownAtComptime
|
|
1604
1603
|
? 'the left side is immutable during shader execution. Try using tgpu.privateVar or buffers'
|
|
1605
|
-
: (immutabilityReasons[
|
|
1606
|
-
'the left side is not a reference to an existing value');
|
|
1604
|
+
: (immutabilityReasons[origin] ?? 'the left side is not a reference to an existing value');
|
|
1607
1605
|
throw new WgslTypeError(`'${stringifyNode(expr)}' is invalid, because ${reason}.`);
|
|
1608
1606
|
}
|
|
1609
1607
|
function assertExhaustive(value) {
|
package/types.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ import type { TgpuVar } from './core/variable/tgpuVariable.ts';
|
|
|
18
18
|
import { type AnyData, UnknownData } from './data/dataTypes.ts';
|
|
19
19
|
import type { MapValueToSnippet, ResolvedSnippet, Snippet } from './data/snippet.ts';
|
|
20
20
|
import { type AnyMatInstance, type AnyVecInstance, type BaseData } from './data/wgslTypes.ts';
|
|
21
|
-
import { $cast, $comptimeValueOf, $gpuCallable, $gpuValueOf, $internal, $ownSnippet, $resolve } from './shared/symbols.ts';
|
|
21
|
+
import { $cast, $comptimeValueOf, $gpuCallable, $gpuCallableStrictSignature, $gpuValueOf, $internal, $ownSnippet, $resolve } from './shared/symbols.ts';
|
|
22
22
|
import type { TgpuBindGroupLayout, TgpuLayoutEntry } from './tgpuBindGroupLayout.ts';
|
|
23
23
|
import type { WgslEnableExtension } from './wgslExtensions.ts';
|
|
24
24
|
import type { Infer } from './shared/repr.ts';
|
|
@@ -65,6 +65,8 @@ export type FunctionScopeLayer = {
|
|
|
65
65
|
functionType: 'normal' | 'compute' | 'vertex' | 'fragment';
|
|
66
66
|
argAccess: Record<string, FunctionArgumentAccess>;
|
|
67
67
|
externalMap: Record<string, unknown>;
|
|
68
|
+
/** Snippets of externals already looked up in this function, so each is only coerced once */
|
|
69
|
+
externalSnippets: Map<string, Snippet>;
|
|
68
70
|
/**
|
|
69
71
|
* The return type of the function. If undefined, the type should be inferred
|
|
70
72
|
* from the implementation (relevant for shellless functions).
|
|
@@ -312,7 +314,7 @@ export interface ResolutionCtx {
|
|
|
312
314
|
getDedented(code: string): string;
|
|
313
315
|
pushBlockScope(): void;
|
|
314
316
|
popBlockScope(): void;
|
|
315
|
-
generateLog(op: SupportedLogOp, args: Snippet[]): Snippet;
|
|
317
|
+
generateLog(op: SupportedLogOp, args: readonly Snippet[]): Snippet;
|
|
316
318
|
getById(id: string): Snippet | null;
|
|
317
319
|
defineVariable(id: string, snippet: Snippet): void;
|
|
318
320
|
setBlockExternals(externals: Record<string, Snippet>): void;
|
|
@@ -359,14 +361,13 @@ export interface WithComptimeValue {
|
|
|
359
361
|
* A `[$comptimeValueOf]` implementation for resources that are only known at runtime
|
|
360
362
|
*/
|
|
361
363
|
export declare function runtimeOnly(): ComptimeValue;
|
|
364
|
+
export type GPUCallableStrictSignature = {
|
|
365
|
+
argTypes: (BaseData | BaseData[])[];
|
|
366
|
+
returnType: BaseData;
|
|
367
|
+
};
|
|
362
368
|
export interface GPUCallable<TArgs extends unknown[] = unknown[]> {
|
|
363
|
-
[$gpuCallable]:
|
|
364
|
-
|
|
365
|
-
argTypes: (BaseData | BaseData[])[];
|
|
366
|
-
returnType: BaseData;
|
|
367
|
-
} | undefined;
|
|
368
|
-
call(ctx: ResolutionCtx, args: MapValueToSnippet<TArgs>): Snippet;
|
|
369
|
-
};
|
|
369
|
+
[$gpuCallable](ctx: ResolutionCtx, args: MapValueToSnippet<TArgs>): Snippet;
|
|
370
|
+
[$gpuCallableStrictSignature]?: GPUCallableStrictSignature | undefined;
|
|
370
371
|
}
|
|
371
372
|
export declare function isGPUCallable(value: unknown): value is GPUCallable;
|
|
372
373
|
export type WithCast<T = BaseData> = GPUCallable<[v?: Infer<T>]> & {
|
|
@@ -383,7 +384,6 @@ export declare function asComptime(snippet: Snippet): Snippet | undefined;
|
|
|
383
384
|
export declare function isConstant(snippet: Snippet): boolean;
|
|
384
385
|
export declare function isWgsl(value: unknown): value is Wgsl;
|
|
385
386
|
export type BindableBufferUsage = 'uniform' | 'readonly' | 'mutable';
|
|
386
|
-
export type BufferUsage = 'uniform' | 'readonly' | 'mutable' | 'vertex';
|
|
387
387
|
export declare function isGPUBuffer(value: unknown): value is GPUBuffer;
|
|
388
388
|
export declare function isBuffer(value: unknown): value is TgpuBuffer<BaseData>;
|
|
389
389
|
export declare function isUsableAsVertex<T extends TgpuBuffer<BaseData>>(buffer: T): buffer is T & VertexFlag;
|
package/types.js
CHANGED
|
@@ -2,7 +2,7 @@ import { isLazy, isProviding, isSlot, } from "./core/slot/slotTypes.js";
|
|
|
2
2
|
import { UnknownData } from "./data/dataTypes.js";
|
|
3
3
|
import { withValue } from "./data/snippet.js";
|
|
4
4
|
import { isWgslData, } from "./data/wgslTypes.js";
|
|
5
|
-
import { $cast, $comptimeValueOf, $gpuCallable, $gpuValueOf, $internal, $ownSnippet, $resolve, } from "./shared/symbols.js";
|
|
5
|
+
import { $cast, $comptimeValueOf, $gpuCallable, $gpuCallableStrictSignature, $gpuValueOf, $internal, $ownSnippet, $resolve, } from "./shared/symbols.js";
|
|
6
6
|
export class NormalState {
|
|
7
7
|
type = 'normal';
|
|
8
8
|
}
|
package/unwrapper.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { TgpuRenderBundleEncoder, TgpuRenderPass } from './core/commandEnco
|
|
|
6
6
|
import type { TgpuComputePipeline } from './core/pipeline/computePipeline.ts';
|
|
7
7
|
import type { TgpuRenderPipeline } from './core/pipeline/renderPipeline.ts';
|
|
8
8
|
import type { TgpuComparisonSampler, TgpuSampler } from './core/sampler/sampler.ts';
|
|
9
|
-
import type { TgpuTexture, TgpuTextureView } from './core/texture/texture.ts';
|
|
9
|
+
import type { TgpuTexture, TgpuTextureRenderView, TgpuTextureView } from './core/texture/texture.ts';
|
|
10
10
|
import type { TgpuVertexLayout } from './core/vertexLayout/vertexLayout.ts';
|
|
11
11
|
import type { TgpuBindGroup, TgpuBindGroupLayout } from './tgpuBindGroupLayout.ts';
|
|
12
12
|
import type { BaseData } from './data/wgslTypes.ts';
|
|
@@ -23,7 +23,7 @@ export interface Unwrapper {
|
|
|
23
23
|
unwrap(resource: TgpuBindGroup): GPUBindGroup;
|
|
24
24
|
unwrap(resource: TgpuBuffer<BaseData>): GPUBuffer;
|
|
25
25
|
unwrap(resource: TgpuBufferBinding<BaseData>): GPUBuffer;
|
|
26
|
-
unwrap(resource: TgpuTextureView): GPUTextureView;
|
|
26
|
+
unwrap(resource: TgpuTextureView | TgpuTextureRenderView): GPUTextureView;
|
|
27
27
|
unwrap(resource: TgpuVertexLayout): GPUVertexBufferLayout;
|
|
28
28
|
unwrap(resource: TgpuSampler): GPUSampler;
|
|
29
29
|
unwrap(resource: TgpuComparisonSampler): GPUSampler;
|
package/data/deepEqual.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { AnyData } from './dataTypes.ts';
|
|
2
|
-
/**
|
|
3
|
-
* Performs a deep comparison of two TypeGPU data schemas.
|
|
4
|
-
*
|
|
5
|
-
* @param a The first data schema to compare.
|
|
6
|
-
* @param b The second data schema to compare.
|
|
7
|
-
* @returns `true` if the schemas are deeply equal, `false` otherwise.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```ts
|
|
11
|
-
* import { vec3f, struct, deepEqual } from 'typegpu/data';
|
|
12
|
-
*
|
|
13
|
-
* const schema1 = struct({ a: vec3f });
|
|
14
|
-
* const schema2 = struct({ a: vec3f });
|
|
15
|
-
* const schema3 = struct({ b: vec3f });
|
|
16
|
-
*
|
|
17
|
-
* console.log(deepEqual(schema1, schema2)); // true
|
|
18
|
-
* console.log(deepEqual(schema1, schema3)); // false
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
export declare function deepEqual(a: AnyData, b: AnyData): boolean;
|
package/data/deepEqual.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { isDisarray, isLooseDecorated, isUnstruct } from "./dataTypes.js";
|
|
2
|
-
import { isWgslStorageTexture, isWgslTexture } from "./texture.js";
|
|
3
|
-
import { isAtomic, isDecorated, isPtr, isWgslArray, isWgslStruct } from "./wgslTypes.js";
|
|
4
|
-
/**
|
|
5
|
-
* Performs a deep comparison of two TypeGPU data schemas.
|
|
6
|
-
*
|
|
7
|
-
* @param a The first data schema to compare.
|
|
8
|
-
* @param b The second data schema to compare.
|
|
9
|
-
* @returns `true` if the schemas are deeply equal, `false` otherwise.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```ts
|
|
13
|
-
* import { vec3f, struct, deepEqual } from 'typegpu/data';
|
|
14
|
-
*
|
|
15
|
-
* const schema1 = struct({ a: vec3f });
|
|
16
|
-
* const schema2 = struct({ a: vec3f });
|
|
17
|
-
* const schema3 = struct({ b: vec3f });
|
|
18
|
-
*
|
|
19
|
-
* console.log(deepEqual(schema1, schema2)); // true
|
|
20
|
-
* console.log(deepEqual(schema1, schema3)); // false
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
export function deepEqual(a, b) {
|
|
24
|
-
if (a === b) {
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
if (a.type !== b.type) {
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
if ((isWgslStruct(a) && isWgslStruct(b)) || (isUnstruct(a) && isUnstruct(b))) {
|
|
31
|
-
const aProps = a.propTypes;
|
|
32
|
-
const bProps = b.propTypes;
|
|
33
|
-
const aKeys = Object.keys(aProps);
|
|
34
|
-
const bKeys = Object.keys(bProps);
|
|
35
|
-
if (aKeys.length !== bKeys.length) {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
for (let i = 0; i < aKeys.length; i++) {
|
|
39
|
-
const keyA = aKeys[i];
|
|
40
|
-
const keyB = bKeys[i];
|
|
41
|
-
if (keyA !== keyB ||
|
|
42
|
-
!keyA ||
|
|
43
|
-
!keyB ||
|
|
44
|
-
!deepEqual(aProps[keyA], bProps[keyB])) {
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return true;
|
|
49
|
-
}
|
|
50
|
-
if ((isWgslArray(a) && isWgslArray(b)) || (isDisarray(a) && isDisarray(b))) {
|
|
51
|
-
return (a.elementCount === b.elementCount &&
|
|
52
|
-
deepEqual(a.elementType, b.elementType));
|
|
53
|
-
}
|
|
54
|
-
if (isPtr(a) && isPtr(b)) {
|
|
55
|
-
return (a.addressSpace === b.addressSpace &&
|
|
56
|
-
a.access === b.access &&
|
|
57
|
-
a.implicit === b.implicit &&
|
|
58
|
-
deepEqual(a.inner, b.inner));
|
|
59
|
-
}
|
|
60
|
-
if (isAtomic(a) && isAtomic(b)) {
|
|
61
|
-
return deepEqual(a.inner, b.inner);
|
|
62
|
-
}
|
|
63
|
-
if (isWgslTexture(a) && isWgslTexture(b)) {
|
|
64
|
-
// Dimension and multisampling are already encoded in the type
|
|
65
|
-
return deepEqual(a.sampleType, b.sampleType);
|
|
66
|
-
}
|
|
67
|
-
if (isWgslStorageTexture(a) && isWgslStorageTexture(b)) {
|
|
68
|
-
// Dimension is already encoded in the type
|
|
69
|
-
return a.format === b.format && a.access === b.access;
|
|
70
|
-
}
|
|
71
|
-
if ((isDecorated(a) && isDecorated(b)) || (isLooseDecorated(a) && isLooseDecorated(b))) {
|
|
72
|
-
if (!deepEqual(a.inner, b.inner)) {
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
if (a.attribs.length !== b.attribs.length) {
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
for (let i = 0; i < a.attribs.length; i++) {
|
|
79
|
-
const attrA = a.attribs[i];
|
|
80
|
-
const attrB = b.attribs[i];
|
|
81
|
-
const paramsA = attrA.params ?? [];
|
|
82
|
-
const paramsB = attrB.params ?? [];
|
|
83
|
-
if (attrA.type !== attrB.type ||
|
|
84
|
-
paramsA.length !== paramsB.length ||
|
|
85
|
-
paramsA.some((param, idx) => param !== paramsB[idx])) {
|
|
86
|
-
return false;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return true;
|
|
90
|
-
}
|
|
91
|
-
// All other types have been checked for equality at the start
|
|
92
|
-
return true;
|
|
93
|
-
}
|