12018-08-22 Myles C. Maxfield <mmaxfield@apple.com>
2
3 [WHLSL] Allow native types to have type arguments (like "vector<float, 4>")
4 https://bugs.webkit.org/show_bug.cgi?id=188773
5
6 Previously, the way to identify a type was strictly by name, which was represented by a string. Therefore, when something like
7 "vector<int, 3>" was parsed, it would produce a TypeRef with the name "vector" and typeArguments [TypeRef, IntLiteral]. Then,
8 there was a pass to convert the TypeRef to have the name "int3" and no typeArguments. After this transformation, each type can
9 be uniquely identified by name.
10
11 This is okay for vectors and matrices, but it is unfortunate for textures (e.g. Texture2D<float4>) because they don't have any
12 natural string-only name. In addition, the canonicalization would have to be made aware of the fact that Texture2D<float4> is
13 the same as Texture2D<vector<float, 4>>. Similarly, an author may wish to typedef float4 to a different name.
14
15 It would be possible to mangle the names of the texture types to something unique, but then we lose information about the inner
16 type. For example, if we did this, Visitor wouldn't recurse into the float4 when encountering Texture2D<float4> because that
17 information would be lost. This could potentially make operations like programWithUnnecessaryThingsRemoved() more difficult to
18 implement in the future.
19
20 So, it would be better to have each type uniquely identified by (name, typeArguments). TypeRef will therefore also have
21 typeArguments which are used to determine which type it is referencing. After this analysis is done to determine what each
22 TypeRef is referencing, subsequent passes shouldn't care about the typeArguments and should only care about the .type field
23 which had been set - this was true even before this patch.
24
25 Reviewed by NOBODY (OOPS!).
26
27 * WebGPUShadingLanguageRI/All.js:
28 * WebGPUShadingLanguageRI/CallExpression.js:
29 (CallExpression.prototype.resolve):
30 * WebGPUShadingLanguageRI/CheckTypesWithArguments.js: Copied from Tools/WebGPUShadingLanguageRI/ResolveTypeDefs.js.
31 (checkTypesWithArguments.TypeWithArgumentsChecker.prototype.visitTypeRef):
32 (checkTypesWithArguments.TypeWithArgumentsChecker):
33 (checkTypesWithArguments):
34 * WebGPUShadingLanguageRI/Checker.js:
35 (Checker.prototype.visitProgram):
36 (Checker.prototype.visitTypeRef):
37 * WebGPUShadingLanguageRI/InferTypesForCall.js:
38 (inferTypesForCall):
39 (inferTypesForTypeArguments):
40 * WebGPUShadingLanguageRI/Intrinsics.js:
41 (Intrinsics.cast):
42 (Intrinsics.bitwiseCast):
43 (Intrinsics.castToHalf):
44 (Intrinsics.):
45 (Intrinsics):
46 * WebGPUShadingLanguageRI/NameContext.js:
47 (NameContext.prototype.add):
48 (NameContext.prototype.get let):
49 (NameContext.underlyingThings.prototype.else):
50 (NameContext.prototype.Symbol.iterator):
51 (NameContext):
52 * WebGPUShadingLanguageRI/NameResolver.js:
53 (NameResolver.prototype.visitTypeRef):
54 (NameResolver.prototype.visitCallExpression):
55 (NameResolver):
56 (NameResolver.prototype.visitVectorType): Deleted.
57 * WebGPUShadingLanguageRI/NativeType.js:
58 (NativeType):
59 (NativeType.prototype.get typeArguments):
60 (NativeType.prototype.toString):
61 (NativeType.create):
62 * WebGPUShadingLanguageRI/Prepare.js:
63 (let.prepare):
64 * WebGPUShadingLanguageRI/Program.js:
65 (Program.prototype.add):
66 (Program.prototype.toString):
67 (Program):
68 * WebGPUShadingLanguageRI/RecursiveTypeChecker.js:
69 (RecursiveTypeChecker.prototype.visitTypeRef):
70 (RecursiveTypeChecker):
71 * WebGPUShadingLanguageRI/RemoveTypeArguments.js: Removed.
72 * WebGPUShadingLanguageRI/ResolveNames.js:
73 (resolveNamesInTypes):
74 * WebGPUShadingLanguageRI/ResolveOverloadImpl.js:
75 * WebGPUShadingLanguageRI/ResolveTypeDefs.js:
76 (resolveTypeDefsInTypes):
77 * WebGPUShadingLanguageRI/Rewriter.js:
78 (Rewriter.prototype.visitTypeRef):
79 (Rewriter.prototype.visitVectorType):
80 (Rewriter):
81 * WebGPUShadingLanguageRI/SPIRV.html:
82 * WebGPUShadingLanguageRI/StandardLibrary.js:
83 (bool.operator):
84 * WebGPUShadingLanguageRI/StatementCloner.js:
85 (StatementCloner.prototype.visitNativeType):
86 * WebGPUShadingLanguageRI/SynthesizeDefaultConstructorOperator.js:
87 (synthesizeDefaultConstructorOperator.FindAllTypes.prototype.visitVectorType):
88 (synthesizeDefaultConstructorOperator.FindAllTypes):
89 (synthesizeDefaultConstructorOperator):
90 * WebGPUShadingLanguageRI/SynthesizeStructAccessors.js:
91 (synthesizeStructAccessors.createTypeRef):
92 * WebGPUShadingLanguageRI/Test.html:
93 * WebGPUShadingLanguageRI/Test.js:
94 * WebGPUShadingLanguageRI/TypeOverloadResolutionFailure.js: Copied from Tools/WebGPUShadingLanguageRI/ResolveTypeDefs.js.
95 (TypeOverloadResolutionFailure):
96 (TypeOverloadResolutionFailure.prototype.get type):
97 (TypeOverloadResolutionFailure.prototype.get reason):
98 (TypeOverloadResolutionFailure.prototype.toString):
99 * WebGPUShadingLanguageRI/TypeRef.js:
100 (TypeRef):
101 (TypeRef.wrap):
102 (TypeRef.prototype.get possibleOverloads):
103 (TypeRef.prototype.set possibleOverloads):
104 (TypeRef.prototype.resolve):
105 (TypeRef.prototype.toString):
106 (TypeRef.instantiate): Deleted.
107 * WebGPUShadingLanguageRI/UnificationContext.js:
108 (UnificationContext.prototype.verify):
109 * WebGPUShadingLanguageRI/VectorType.js:
110 (VectorType):
111 (VectorType.prototype.get elementType):
112 (VectorType.prototype.get numElements):
113 (VectorType.prototype.get numElementsValue):
114 (VectorType.prototype.toString):
115 * WebGPUShadingLanguageRI/Visitor.js:
116 (Visitor.prototype.visitTypeRef):
117 (Visitor.prototype.visitNativeType):
118 (Visitor.prototype.visitVectorType):
119 (Visitor):
120 * WebGPUShadingLanguageRI/index.html:
121