[WHLSL] Remove unnecessary ASSERT()s and clean up visitor lambdas
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 14 Jun 2019 05:45:43 +0000 (05:45 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 14 Jun 2019 05:45:43 +0000 (05:45 +0000)
https://bugs.webkit.org/show_bug.cgi?id=198706

Reviewed by Dean Jackson, Saam Barati, and Robin Morisset.

Some minor refactoring.

If the code is going to unconditionally downcast<Foo>(bar), there's no need
to guard that with an ASSERT(is<Foo>(bar)) because the downcast() call will
do that automatically.

No new tests because there is no behavior change.

* Modules/webgpu/WHLSL/AST/WHLSLConstantExpression.h:
(WebCore::WHLSL::AST::ConstantExpression::visit):
(WebCore::WHLSL::AST::ConstantExpression::visit const):
* Modules/webgpu/WHLSL/Metal/WHLSLEntryPointScaffolding.cpp:
(WebCore::WHLSL::Metal::EntryPointScaffolding::resourceHelperTypes):
(WebCore::WHLSL::Metal::EntryPointScaffolding::mangledOutputPath):
(WebCore::WHLSL::Metal::EntryPointScaffolding::unpackResourcesAndNamedBuiltIns):
* Modules/webgpu/WHLSL/Metal/WHLSLFunctionWriter.cpp:
(WebCore::WHLSL::Metal::FunctionDefinitionWriter::visit):
(WebCore::WHLSL::Metal::FunctionDefinitionWriter::constantExpressionString):
* Modules/webgpu/WHLSL/Metal/WHLSLNativeFunctionWriter.cpp:
(WebCore::WHLSL::Metal::writeNativeFunction):
* Modules/webgpu/WHLSL/Metal/WHLSLNativeTypeWriter.cpp:
(WebCore::WHLSL::Metal::writeNativeType):
* Modules/webgpu/WHLSL/Metal/WHLSLTypeNamer.cpp:
(WebCore::WHLSL::Metal::find):
(WebCore::WHLSL::Metal::TypeNamer::createNameNode):
(WebCore::WHLSL::Metal::TypeNamer::insert):
(WebCore::WHLSL::Metal::TypeNamer::emitUnnamedTypeDefinition):
(WebCore::WHLSL::Metal::TypeNamer::emitNamedTypeDefinition):
* Modules/webgpu/WHLSL/WHLSLChecker.cpp:
(WebCore::WHLSL::Checker::visit):
(WebCore::WHLSL::argumentTypeForAndOverload):
* Modules/webgpu/WHLSL/WHLSLInferTypes.cpp:
(WebCore::WHLSL::inferTypesForTypeArguments):
* Modules/webgpu/WHLSL/WHLSLIntrinsics.cpp:
(WebCore::WHLSL::Intrinsics::addFullTexture):
(WebCore::WHLSL::Intrinsics::addDepthTexture):
* Modules/webgpu/WHLSL/WHLSLPropertyResolver.cpp:
(WebCore::WHLSL::modify):
(WebCore::WHLSL::PropertyResolver::visit):
* Modules/webgpu/WHLSL/WHLSLVisitor.cpp:
(WebCore::WHLSL::Visitor::visit):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@246428 268f45cc-cd09-0410-ab3c-d52691b4dbfc

13 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLConstantExpression.h
Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLEntryPointScaffolding.cpp
Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLFunctionWriter.cpp
Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLNativeFunctionWriter.cpp
Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLNativeTypeWriter.cpp
Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLTypeNamer.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLChecker.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLInferTypes.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLIntrinsics.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLIntrinsics.h
Source/WebCore/Modules/webgpu/WHLSL/WHLSLPropertyResolver.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLVisitor.cpp

index 3b687cf..db06abb 100644 (file)
@@ -1,3 +1,52 @@
+2019-06-13  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        [WHLSL] Remove unnecessary ASSERT()s and clean up visitor lambdas
+        https://bugs.webkit.org/show_bug.cgi?id=198706
+
+        Reviewed by Dean Jackson, Saam Barati, and Robin Morisset.
+
+        Some minor refactoring.
+
+        If the code is going to unconditionally downcast<Foo>(bar), there's no need
+        to guard that with an ASSERT(is<Foo>(bar)) because the downcast() call will
+        do that automatically.
+
+        No new tests because there is no behavior change.
+
+        * Modules/webgpu/WHLSL/AST/WHLSLConstantExpression.h:
+        (WebCore::WHLSL::AST::ConstantExpression::visit):
+        (WebCore::WHLSL::AST::ConstantExpression::visit const):
+        * Modules/webgpu/WHLSL/Metal/WHLSLEntryPointScaffolding.cpp:
+        (WebCore::WHLSL::Metal::EntryPointScaffolding::resourceHelperTypes):
+        (WebCore::WHLSL::Metal::EntryPointScaffolding::mangledOutputPath):
+        (WebCore::WHLSL::Metal::EntryPointScaffolding::unpackResourcesAndNamedBuiltIns):
+        * Modules/webgpu/WHLSL/Metal/WHLSLFunctionWriter.cpp:
+        (WebCore::WHLSL::Metal::FunctionDefinitionWriter::visit):
+        (WebCore::WHLSL::Metal::FunctionDefinitionWriter::constantExpressionString):
+        * Modules/webgpu/WHLSL/Metal/WHLSLNativeFunctionWriter.cpp:
+        (WebCore::WHLSL::Metal::writeNativeFunction):
+        * Modules/webgpu/WHLSL/Metal/WHLSLNativeTypeWriter.cpp:
+        (WebCore::WHLSL::Metal::writeNativeType):
+        * Modules/webgpu/WHLSL/Metal/WHLSLTypeNamer.cpp:
+        (WebCore::WHLSL::Metal::find):
+        (WebCore::WHLSL::Metal::TypeNamer::createNameNode):
+        (WebCore::WHLSL::Metal::TypeNamer::insert):
+        (WebCore::WHLSL::Metal::TypeNamer::emitUnnamedTypeDefinition):
+        (WebCore::WHLSL::Metal::TypeNamer::emitNamedTypeDefinition):
+        * Modules/webgpu/WHLSL/WHLSLChecker.cpp:
+        (WebCore::WHLSL::Checker::visit):
+        (WebCore::WHLSL::argumentTypeForAndOverload):
+        * Modules/webgpu/WHLSL/WHLSLInferTypes.cpp:
+        (WebCore::WHLSL::inferTypesForTypeArguments):
+        * Modules/webgpu/WHLSL/WHLSLIntrinsics.cpp:
+        (WebCore::WHLSL::Intrinsics::addFullTexture):
+        (WebCore::WHLSL::Intrinsics::addDepthTexture):
+        * Modules/webgpu/WHLSL/WHLSLPropertyResolver.cpp:
+        (WebCore::WHLSL::modify):
+        (WebCore::WHLSL::PropertyResolver::visit):
+        * Modules/webgpu/WHLSL/WHLSLVisitor.cpp:
+        (WebCore::WHLSL::Visitor::visit):
+
 2019-06-12  Myles C. Maxfield  <mmaxfield@apple.com>
 
         [WHLSL] Hook up compute
index 8eeceb0..7656f62 100644 (file)
@@ -88,14 +88,14 @@ public:
         return WTF::get<IntegerLiteral>(m_variant);
     }
 
-    template<typename T> void visit(T&& t)
+    template <typename Visitor> auto visit(const Visitor& visitor) -> decltype(WTF::visit(visitor, std::declval<Variant<IntegerLiteral, UnsignedIntegerLiteral, FloatLiteral, NullLiteral, BooleanLiteral, EnumerationMemberLiteral>&>()))
     {
-        WTF::visit(WTFMove(t), m_variant);
+        return WTF::visit(visitor, m_variant);
     }
 
-    template<typename T> void visit(T&& t) const
+    template <typename Visitor> auto visit(const Visitor& visitor) const -> decltype(WTF::visit(visitor, std::declval<Variant<IntegerLiteral, UnsignedIntegerLiteral, FloatLiteral, NullLiteral, BooleanLiteral, EnumerationMemberLiteral>&>()))
     {
-        WTF::visit(WTFMove(t), m_variant);
+        return WTF::visit(visitor, m_variant);
     }
 
     ConstantExpression clone() const
index 3baa37f..01fb71e 100644 (file)
@@ -148,7 +148,6 @@ String EntryPointScaffolding::resourceHelperTypes()
             if (iterator == m_resourceMap.end())
                 continue;
             auto& unnamedType = *m_entryPointItems.inputs[iterator->value].unnamedType;
-            ASSERT(is<AST::ReferenceType>(unnamedType));
             auto& referenceType = downcast<AST::ReferenceType>(unnamedType);
             auto mangledTypeName = m_typeNamer.mangledNameForType(referenceType.elementType());
             auto addressSpace = toString(referenceType.addressSpace());
@@ -277,10 +276,7 @@ String EntryPointScaffolding::mangledOutputPath(Vector<String>& path)
 
     AST::StructureDefinition* structureDefinition = nullptr;
     auto& unifyNode = m_functionDefinition.type().unifyNode();
-    ASSERT(is<AST::NamedType>(unifyNode));
-    auto& namedType = downcast<AST::NamedType>(unifyNode);
-    ASSERT(is<AST::StructureDefinition>(namedType));
-    structureDefinition = &downcast<AST::StructureDefinition>(namedType);
+    structureDefinition = &downcast<AST::StructureDefinition>(downcast<AST::NamedType>(unifyNode));
     for (auto& component : path) {
         ASSERT(structureDefinition);
         auto* next = structureDefinition->find(component);
@@ -317,9 +313,7 @@ String EntryPointScaffolding::unpackResourcesAndNamedBuiltIns()
                 auto lengthTemporaryName = m_namedBindGroups[i].namedBindings[j].lengthInformation->temporaryName;
 
                 auto& unnamedType = *m_entryPointItems.inputs[iterator->value].unnamedType;
-                ASSERT(is<AST::ReferenceType>(unnamedType));
-                auto& referenceType = downcast<AST::ReferenceType>(unnamedType);
-                auto mangledTypeName = m_typeNamer.mangledNameForType(referenceType.elementType());
+                auto mangledTypeName = m_typeNamer.mangledNameForType(downcast<AST::ReferenceType>(unnamedType).elementType());
 
                 stringBuilder.append(makeString("size_t ", lengthTemporaryName, " = ", variableName, '.', lengthElementName, ".x;\n"));
                 stringBuilder.append(makeString(lengthTemporaryName, " = ", lengthTemporaryName, " << 32;\n"));
index c02cbc5..009d431 100644 (file)
@@ -397,7 +397,6 @@ void FunctionDefinitionWriter::visit(AST::FloatLiteral& floatLiteral)
 void FunctionDefinitionWriter::visit(AST::NullLiteral& nullLiteral)
 {
     auto& unifyNode = nullLiteral.resolvedType().unifyNode();
-    ASSERT(is<AST::UnnamedType>(unifyNode));
     auto& unnamedType = downcast<AST::UnnamedType>(unifyNode);
     bool isArrayReferenceType = is<AST::ArrayReferenceType>(unnamedType);
 
@@ -620,23 +619,21 @@ void FunctionDefinitionWriter::visit(AST::VariableReference& variableReference)
 
 String FunctionDefinitionWriter::constantExpressionString(AST::ConstantExpression& constantExpression)
 {
-    String result;
-    constantExpression.visit(WTF::makeVisitor([&](AST::IntegerLiteral& integerLiteral) {
-        result = makeString("", integerLiteral.value());
-    }, [&](AST::UnsignedIntegerLiteral& unsignedIntegerLiteral) {
-        result = makeString("", unsignedIntegerLiteral.value());
-    }, [&](AST::FloatLiteral& floatLiteral) {
-        result = makeString("", floatLiteral.value());
-    }, [&](AST::NullLiteral&) {
-        result = "nullptr"_str;
-    }, [&](AST::BooleanLiteral& booleanLiteral) {
-        result = booleanLiteral.value() ? "true"_str : "false"_str;
-    }, [&](AST::EnumerationMemberLiteral& enumerationMemberLiteral) {
+    return constantExpression.visit(WTF::makeVisitor([&](AST::IntegerLiteral& integerLiteral) -> String {
+        return makeString("", integerLiteral.value());
+    }, [&](AST::UnsignedIntegerLiteral& unsignedIntegerLiteral) -> String {
+        return makeString("", unsignedIntegerLiteral.value());
+    }, [&](AST::FloatLiteral& floatLiteral) -> String {
+        return makeString("", floatLiteral.value());
+    }, [&](AST::NullLiteral&) -> String {
+        return "nullptr"_str;
+    }, [&](AST::BooleanLiteral& booleanLiteral) -> String {
+        return booleanLiteral.value() ? "true"_str : "false"_str;
+    }, [&](AST::EnumerationMemberLiteral& enumerationMemberLiteral) -> String {
         ASSERT(enumerationMemberLiteral.enumerationDefinition());
         ASSERT(enumerationMemberLiteral.enumerationDefinition());
-        result = makeString(m_typeNamer.mangledNameForType(*enumerationMemberLiteral.enumerationDefinition()), '.', m_typeNamer.mangledNameForEnumerationMember(*enumerationMemberLiteral.enumerationMember()));
+        return makeString(m_typeNamer.mangledNameForType(*enumerationMemberLiteral.enumerationDefinition()), '.', m_typeNamer.mangledNameForEnumerationMember(*enumerationMemberLiteral.enumerationMember()));
     }));
-    return result;
 }
 
 class RenderFunctionDefinitionWriter : public FunctionDefinitionWriter {
index 3afb180..db3947b 100644 (file)
@@ -134,7 +134,6 @@ String writeNativeFunction(AST::NativeFunctionDeclaration& nativeFunctionDeclara
         ASSERT(nativeFunctionDeclaration.parameters().size() == 1);
         auto metalParameterName = typeNamer.mangledNameForType(*nativeFunctionDeclaration.parameters()[0]->type());
         auto& parameterType = nativeFunctionDeclaration.parameters()[0]->type()->unifyNode();
-        ASSERT(is<AST::UnnamedType>(parameterType));
         auto& unnamedParameterType = downcast<AST::UnnamedType>(parameterType);
         if (is<AST::ArrayType>(unnamedParameterType)) {
             auto& arrayParameterType = downcast<AST::ArrayType>(unnamedParameterType);
@@ -351,13 +350,11 @@ String writeNativeFunction(AST::NativeFunctionDeclaration& nativeFunctionDeclara
     if (nativeFunctionDeclaration.name().startsWith("Interlocked"_str)) {
         if (nativeFunctionDeclaration.name() == "InterlockedCompareExchange") {
             ASSERT(nativeFunctionDeclaration.parameters().size() == 4);
-            ASSERT(is<AST::PointerType>(*nativeFunctionDeclaration.parameters()[0]->type()));
             auto& firstArgumentPointer = downcast<AST::PointerType>(*nativeFunctionDeclaration.parameters()[0]->type());
             auto firstArgumentAddressSpace = firstArgumentPointer.addressSpace();
             auto firstArgumentPointee = typeNamer.mangledNameForType(firstArgumentPointer.elementType());
             auto secondArgument = typeNamer.mangledNameForType(*nativeFunctionDeclaration.parameters()[1]->type());
             auto thirdArgument = typeNamer.mangledNameForType(*nativeFunctionDeclaration.parameters()[2]->type());
-            ASSERT(is<AST::PointerType>(*nativeFunctionDeclaration.parameters()[3]->type()));
             auto& fourthArgumentPointer = downcast<AST::PointerType>(*nativeFunctionDeclaration.parameters()[3]->type());
             auto fourthArgumentAddressSpace = fourthArgumentPointer.addressSpace();
             auto fourthArgumentPointee = typeNamer.mangledNameForType(fourthArgumentPointer.elementType());
@@ -369,12 +366,10 @@ String writeNativeFunction(AST::NativeFunctionDeclaration& nativeFunctionDeclara
         }
 
         ASSERT(nativeFunctionDeclaration.parameters().size() == 3);
-        ASSERT(is<AST::PointerType>(*nativeFunctionDeclaration.parameters()[0]->type()));
         auto& firstArgumentPointer = downcast<AST::PointerType>(*nativeFunctionDeclaration.parameters()[0]->type());
         auto firstArgumentAddressSpace = firstArgumentPointer.addressSpace();
         auto firstArgumentPointee = typeNamer.mangledNameForType(firstArgumentPointer.elementType());
         auto secondArgument = typeNamer.mangledNameForType(*nativeFunctionDeclaration.parameters()[1]->type());
-        ASSERT(is<AST::PointerType>(*nativeFunctionDeclaration.parameters()[2]->type()));
         auto& thirdArgumentPointer = downcast<AST::PointerType>(*nativeFunctionDeclaration.parameters()[2]->type());
         auto thirdArgumentAddressSpace = thirdArgumentPointer.addressSpace();
         auto thirdArgumentPointee = typeNamer.mangledNameForType(thirdArgumentPointer.elementType());
index 4948d9d..f57d5c0 100644 (file)
@@ -71,9 +71,7 @@ String writeNativeType(AST::NativeTypeDeclaration& nativeTypeDeclaration)
         ASSERT(WTF::holds_alternative<UniqueRef<AST::TypeReference>>(nativeTypeDeclaration.typeArguments()[0]));
         auto& typeReference = WTF::get<UniqueRef<AST::TypeReference>>(nativeTypeDeclaration.typeArguments()[0]);
         auto& unifyNode = typeReference->unifyNode();
-        ASSERT(is<AST::NamedType>(unifyNode));
         auto& namedType = downcast<AST::NamedType>(unifyNode);
-        ASSERT(is<AST::NativeTypeDeclaration>(namedType));
         auto& parameterType = downcast<AST::NativeTypeDeclaration>(namedType);
         auto prefix = ([&]() -> String {
             if (parameterType.name() == "bool")
@@ -116,9 +114,7 @@ String writeNativeType(AST::NativeTypeDeclaration& nativeTypeDeclaration)
         ASSERT(WTF::holds_alternative<UniqueRef<AST::TypeReference>>(nativeTypeDeclaration.typeArguments()[0]));
         auto& typeReference = WTF::get<UniqueRef<AST::TypeReference>>(nativeTypeDeclaration.typeArguments()[0]);
         auto& unifyNode = typeReference->unifyNode();
-        ASSERT(is<AST::NamedType>(unifyNode));
         auto& namedType = downcast<AST::NamedType>(unifyNode);
-        ASSERT(is<AST::NativeTypeDeclaration>(namedType));
         auto& parameterType = downcast<AST::NativeTypeDeclaration>(namedType);
         auto prefix = ([&]() -> String {
             if (parameterType.name() == "half")
index 41138dd..c3d8272 100644 (file)
@@ -201,7 +201,6 @@ static BaseTypeNameNode& find(AST::UnnamedType& unnamedType, Vector<UniqueRef<Ba
             return find(downcast<AST::PointerType>(unnamedType).elementType(), types).children();
         if (is<AST::ArrayReferenceType>(unnamedType))
             return find(downcast<AST::ArrayReferenceType>(unnamedType).elementType(), types).children();
-        ASSERT(is<AST::ArrayType>(unnamedType));
         return find(downcast<AST::ArrayType>(unnamedType).type(), types).children();
     })();
     auto iterator = findInVector(unnamedType, vectorToSearch);
@@ -306,7 +305,6 @@ UniqueRef<BaseTypeNameNode> TypeNamer::createNameNode(AST::UnnamedType& unnamedT
         auto& arrayReferenceType = downcast<AST::ArrayReferenceType>(unnamedType);
         return makeUniqueRef<ArrayReferenceTypeNameNode>(parent, generateNextTypeName(), arrayReferenceType.addressSpace());
     }
-    ASSERT(is<AST::ArrayType>(unnamedType));
     auto& arrayType = downcast<AST::ArrayType>(unnamedType);
     return makeUniqueRef<ArrayTypeNameNode>(parent, generateNextTypeName(), arrayType.numElements());
 }
@@ -327,7 +325,6 @@ size_t TypeNamer::insert(AST::UnnamedType& unnamedType, Vector<UniqueRef<BaseTyp
         vectorToInsertInto = &item->children();
         parent = &item;
     } else {
-        ASSERT(is<AST::ArrayType>(unnamedType));
         auto& item = types[insert(downcast<AST::ArrayType>(unnamedType).type(), types)];
         vectorToInsertInto = &item->children();
         parent = &item;
@@ -399,7 +396,6 @@ void TypeNamer::emitUnnamedTypeDefinition(BaseTypeNameNode& baseTypeNameNode, Ha
         stringBuilder.append("    uint length;\n");
         stringBuilder.append("};\n");
     } else {
-        ASSERT(is<ArrayTypeNameNode>(baseTypeNameNode));
         auto& arrayType = downcast<ArrayTypeNameNode>(baseTypeNameNode);
         ASSERT(baseTypeNameNode.parent());
         stringBuilder.append(makeString("typedef Array<", arrayType.parent()->mangledName(), ", ", arrayType.numElements(), "> ", arrayType.mangledName(), ";\n"));
@@ -418,7 +414,6 @@ void TypeNamer::emitNamedTypeDefinition(AST::NamedType& namedType, HashSet<AST::
     if (is<AST::EnumerationDefinition>(namedType)) {
         auto& enumerationDefinition = downcast<AST::EnumerationDefinition>(namedType);
         auto& baseType = enumerationDefinition.type().unifyNode();
-        ASSERT(is<AST::NamedType>(baseType));
         stringBuilder.append(makeString("enum class ", mangledNameForType(enumerationDefinition), " : ", mangledNameForType(downcast<AST::NamedType>(baseType)), " {\n"));
         for (auto& enumerationMember : enumerationDefinition.enumerationMembers())
             stringBuilder.append(makeString("    ", mangledNameForEnumerationMember(enumerationMember), ",\n"));
@@ -432,7 +427,6 @@ void TypeNamer::emitNamedTypeDefinition(AST::NamedType& namedType, HashSet<AST::
             stringBuilder.append(makeString("    ", mangledNameForType(structureElement.type()), ' ', mangledNameForStructureElement(structureElement), ";\n"));
         stringBuilder.append("};\n");
     } else {
-        ASSERT(is<AST::TypeDefinition>(namedType));
         auto& typeDefinition = downcast<AST::TypeDefinition>(namedType);
         stringBuilder.append(makeString("typedef ", mangledNameForType(typeDefinition.type()), ' ', mangledNameForType(typeDefinition), ";\n"));
     }
index 1561a4f..35c70c9 100644 (file)
@@ -656,14 +656,12 @@ void Checker::visit(AST::EnumerationDefinition& enumerationDefinition)
     auto enumerationMembers = enumerationDefinition.enumerationMembers();
 
     auto matchAndCommitMember = [&](AST::EnumerationMember& member) -> bool {
-        bool success = false;
-        member.value()->visit(WTF::makeVisitor([&](AST::Expression& value) {
+        return member.value()->visit(WTF::makeVisitor([&](AST::Expression& value) -> bool {
             auto valueInfo = recurseAndGetInfo(value);
             if (!valueInfo)
-                return;
-            success = static_cast<bool>(matchAndCommit(valueInfo->resolvingType, *baseType));
+                return false;
+            return static_cast<bool>(matchAndCommit(valueInfo->resolvingType, *baseType));
         }));
-        return success;
     };
 
     for (auto& member : enumerationMembers) {
@@ -679,13 +677,13 @@ void Checker::visit(AST::EnumerationDefinition& enumerationDefinition)
     int64_t nextValue = 0;
     for (auto& member : enumerationMembers) {
         if (member.get().value()) {
-            int64_t value;
-            member.get().value()->visit(WTF::makeVisitor([&](AST::IntegerLiteral& integerLiteral) {
-                value = integerLiteral.valueForSelectedType();
-            }, [&](AST::UnsignedIntegerLiteral& unsignedIntegerLiteral) {
-                value = unsignedIntegerLiteral.valueForSelectedType();
-            }, [&](auto&) {
+            auto value = member.get().value()->visit(WTF::makeVisitor([&](AST::IntegerLiteral& integerLiteral) -> int64_t {
+                return integerLiteral.valueForSelectedType();
+            }, [&](AST::UnsignedIntegerLiteral& unsignedIntegerLiteral) -> int64_t {
+                return unsignedIntegerLiteral.valueForSelectedType();
+            }, [&](auto&) -> int64_t {
                 ASSERT_NOT_REACHED();
+                return 0;
             }));
             nextValue = baseType->successor()(value);
         } else {
@@ -706,14 +704,14 @@ void Checker::visit(AST::EnumerationDefinition& enumerationDefinition)
     }
 
     auto getValue = [&](AST::EnumerationMember& member) -> int64_t {
-        int64_t value;
         ASSERT(member.value());
-        member.value()->visit(WTF::makeVisitor([&](AST::IntegerLiteral& integerLiteral) {
-            value = integerLiteral.value();
-        }, [&](AST::UnsignedIntegerLiteral& unsignedIntegerLiteral) {
-            value = unsignedIntegerLiteral.value();
-        }, [&](auto&) {
+        auto value = member.value()->visit(WTF::makeVisitor([&](AST::IntegerLiteral& integerLiteral) -> int64_t {
+            return integerLiteral.value();
+        }, [&](AST::UnsignedIntegerLiteral& unsignedIntegerLiteral) -> int64_t {
+            return unsignedIntegerLiteral.value();
+        }, [&](auto&) -> int64_t {
             ASSERT_NOT_REACHED();
+            return 0;
         }));
         return value;
     };
@@ -977,7 +975,6 @@ static Optional<UniqueRef<AST::UnnamedType>> argumentTypeForAndOverload(AST::Unn
         return { makeUniqueRef<AST::PointerType>(Lexer::Token(namedType.origin()), addressSpace, AST::TypeReference::wrap(Lexer::Token(namedType.origin()), namedType)) };
     }
 
-    ASSERT(is<AST::UnnamedType>(unifyNode));
     auto& unnamedType = downcast<AST::UnnamedType>(unifyNode);
 
     if (is<AST::ArrayReferenceType>(unnamedType))
@@ -1305,20 +1302,19 @@ void Checker::visit(AST::SwitchStatement& switchStatement)
             hasDefault = true;
             continue;
         }
-        bool success;
-        switchCase.value()->visit(WTF::makeVisitor([&](AST::IntegerLiteral& integerLiteral) {
-            success = static_cast<bool>(matchAndCommit(*valueType, integerLiteral.type()));
-        }, [&](AST::UnsignedIntegerLiteral& unsignedIntegerLiteral) {
-            success = static_cast<bool>(matchAndCommit(*valueType, unsignedIntegerLiteral.type()));
-        }, [&](AST::FloatLiteral& floatLiteral) {
-            success = static_cast<bool>(matchAndCommit(*valueType, floatLiteral.type()));
-        }, [&](AST::NullLiteral& nullLiteral) {
-            success = static_cast<bool>(matchAndCommit(*valueType, nullLiteral.type()));
-        }, [&](AST::BooleanLiteral&) {
-            success = matches(*valueType, m_intrinsics.boolType());
-        }, [&](AST::EnumerationMemberLiteral& enumerationMemberLiteral) {
+        auto success = switchCase.value()->visit(WTF::makeVisitor([&](AST::IntegerLiteral& integerLiteral) -> bool {
+            return static_cast<bool>(matchAndCommit(*valueType, integerLiteral.type()));
+        }, [&](AST::UnsignedIntegerLiteral& unsignedIntegerLiteral) -> bool {
+            return static_cast<bool>(matchAndCommit(*valueType, unsignedIntegerLiteral.type()));
+        }, [&](AST::FloatLiteral& floatLiteral) -> bool {
+            return static_cast<bool>(matchAndCommit(*valueType, floatLiteral.type()));
+        }, [&](AST::NullLiteral& nullLiteral) -> bool {
+            return static_cast<bool>(matchAndCommit(*valueType, nullLiteral.type()));
+        }, [&](AST::BooleanLiteral&) -> bool {
+            return matches(*valueType, m_intrinsics.boolType());
+        }, [&](AST::EnumerationMemberLiteral& enumerationMemberLiteral) -> bool {
             ASSERT(enumerationMemberLiteral.enumerationDefinition());
-            success = matches(*valueType, *enumerationMemberLiteral.enumerationDefinition());
+            return matches(*valueType, *enumerationMemberLiteral.enumerationDefinition());
         }));
         if (!success) {
             setError();
@@ -1339,31 +1335,37 @@ void Checker::visit(AST::SwitchStatement& switchStatement)
                 return;
             }
 
-            bool success = true;
-            firstCase.value()->visit(WTF::makeVisitor([&](AST::IntegerLiteral& firstIntegerLiteral) {
-                secondCase.value()->visit(WTF::makeVisitor([&](AST::IntegerLiteral& secondIntegerLiteral) {
-                    success = firstIntegerLiteral.value() != secondIntegerLiteral.value();
-                }, [&](AST::UnsignedIntegerLiteral& secondUnsignedIntegerLiteral) {
-                    success = static_cast<int64_t>(firstIntegerLiteral.value()) != static_cast<int64_t>(secondUnsignedIntegerLiteral.value());
-                }, [](auto&) {
+            auto success = firstCase.value()->visit(WTF::makeVisitor([&](AST::IntegerLiteral& firstIntegerLiteral) -> bool {
+                return secondCase.value()->visit(WTF::makeVisitor([&](AST::IntegerLiteral& secondIntegerLiteral) -> bool {
+                    return firstIntegerLiteral.value() != secondIntegerLiteral.value();
+                }, [&](AST::UnsignedIntegerLiteral& secondUnsignedIntegerLiteral) -> bool {
+                    return static_cast<int64_t>(firstIntegerLiteral.value()) != static_cast<int64_t>(secondUnsignedIntegerLiteral.value());
+                }, [](auto&) -> bool {
+                    return true;
                 }));
-            }, [&](AST::UnsignedIntegerLiteral& firstUnsignedIntegerLiteral) {
-                secondCase.value()->visit(WTF::makeVisitor([&](AST::IntegerLiteral& secondIntegerLiteral) {
-                    success = static_cast<int64_t>(firstUnsignedIntegerLiteral.value()) != static_cast<int64_t>(secondIntegerLiteral.value());
-                }, [&](AST::UnsignedIntegerLiteral& secondUnsignedIntegerLiteral) {
-                    success = firstUnsignedIntegerLiteral.value() != secondUnsignedIntegerLiteral.value();
-                }, [](auto&) {
+            }, [&](AST::UnsignedIntegerLiteral& firstUnsignedIntegerLiteral) -> bool {
+                return secondCase.value()->visit(WTF::makeVisitor([&](AST::IntegerLiteral& secondIntegerLiteral) -> bool {
+                    return static_cast<int64_t>(firstUnsignedIntegerLiteral.value()) != static_cast<int64_t>(secondIntegerLiteral.value());
+                }, [&](AST::UnsignedIntegerLiteral& secondUnsignedIntegerLiteral) -> bool {
+                    return firstUnsignedIntegerLiteral.value() != secondUnsignedIntegerLiteral.value();
+                }, [](auto&) -> bool {
+                    return true;
                 }));
-            }, [&](AST::EnumerationMemberLiteral& firstEnumerationMemberLiteral) {
-                secondCase.value()->visit(WTF::makeVisitor([&](AST::IntegerLiteral&) {
-                }, [&](AST::EnumerationMemberLiteral& secondEnumerationMemberLiteral) {
+            }, [&](AST::EnumerationMemberLiteral& firstEnumerationMemberLiteral) -> bool {
+                return secondCase.value()->visit(WTF::makeVisitor([&](AST::EnumerationMemberLiteral& secondEnumerationMemberLiteral) -> bool {
                     ASSERT(firstEnumerationMemberLiteral.enumerationMember());
                     ASSERT(secondEnumerationMemberLiteral.enumerationMember());
-                    success = firstEnumerationMemberLiteral.enumerationMember() != secondEnumerationMemberLiteral.enumerationMember();
-                }, [](auto&) {
+                    return firstEnumerationMemberLiteral.enumerationMember() != secondEnumerationMemberLiteral.enumerationMember();
+                }, [](auto&) -> bool {
+                    return true;
                 }));
-            }, [](auto&) {
+            }, [](auto&) -> bool {
+                return true;
             }));
+            if (!success) {
+                setError();
+                return;
+            }
         }
     }
 
@@ -1372,13 +1374,13 @@ void Checker::visit(AST::SwitchStatement& switchStatement)
             HashSet<int64_t> values;
             bool zeroValueExists;
             for (auto& switchCase : switchStatement.switchCases()) {
-                int64_t value;
-                switchCase.value()->visit(WTF::makeVisitor([&](AST::IntegerLiteral& integerLiteral) {
-                    value = integerLiteral.valueForSelectedType();
-                }, [&](AST::UnsignedIntegerLiteral& unsignedIntegerLiteral) {
-                    value = unsignedIntegerLiteral.valueForSelectedType();
-                }, [](auto&) {
+                auto value = switchCase.value()->visit(WTF::makeVisitor([&](AST::IntegerLiteral& integerLiteral) -> int64_t {
+                    return integerLiteral.valueForSelectedType();
+                }, [&](AST::UnsignedIntegerLiteral& unsignedIntegerLiteral) -> int64_t {
+                    return unsignedIntegerLiteral.valueForSelectedType();
+                }, [](auto&) -> int64_t {
                     ASSERT_NOT_REACHED();
+                    return 0;
                 }));
                 if (!value)
                     zeroValueExists = true;
@@ -1405,7 +1407,6 @@ void Checker::visit(AST::SwitchStatement& switchStatement)
                 return;
             }
         } else {
-            ASSERT(is<AST::EnumerationDefinition>(*valueType));
             HashSet<AST::EnumerationMember*> values;
             for (auto& switchCase : switchStatement.switchCases()) {
                 switchCase.value()->visit(WTF::makeVisitor([&](AST::EnumerationMemberLiteral& enumerationMemberLiteral) {
index f565cfd..9b31d92 100644 (file)
@@ -188,7 +188,6 @@ bool inferTypesForTypeArguments(AST::NamedType& possibleType, AST::TypeArguments
         return typeArguments.isEmpty();
     }
 
-    ASSERT(is<AST::NativeTypeDeclaration>(possibleType));
     auto& nativeTypeDeclaration = downcast<AST::NativeTypeDeclaration>(possibleType);
     if (nativeTypeDeclaration.typeArguments().size() != typeArguments.size())
         return false;
index cb9d8d1..c8bffb8 100644 (file)
@@ -347,11 +347,7 @@ bool Intrinsics::addMatrix(AST::NativeTypeDeclaration& nativeTypeDeclaration)
 
 bool Intrinsics::addFullTexture(AST::NativeTypeDeclaration& nativeTypeDeclaration, AST::TypeReference& innerType)
 {
-    unsigned textureTypeIndex = WTF_ARRAY_LENGTH(m_textureTypeNames);
-    for (unsigned i = 0; i < WTF_ARRAY_LENGTH(m_textureTypeNames); ++i) {
-        if (nativeTypeDeclaration.name() == m_textureTypeNames[i])
-            textureTypeIndex = i;
-    }
+    auto textureTypeIndex = std::find(m_textureTypeNames, m_textureTypeNames + WTF_ARRAY_LENGTH(m_textureTypeNames), nativeTypeDeclaration.name()) - m_textureTypeNames;
     if (textureTypeIndex == WTF_ARRAY_LENGTH(m_textureTypeNames))
         return false;
 
@@ -377,9 +373,9 @@ bool Intrinsics::addFullTexture(AST::NativeTypeDeclaration& nativeTypeDeclaratio
     return true;
 }
 
-bool Intrinsics::addDepthTexture(AST::NativeTypeDeclaration& nativeTypeDeclaration, AST::TypeReference& innerType)
+void Intrinsics::addDepthTexture(AST::NativeTypeDeclaration& nativeTypeDeclaration, AST::TypeReference& innerType)
 {
-    AST::NativeTypeDeclaration** texture;
+    AST::NativeTypeDeclaration** texture = nullptr;
     if (nativeTypeDeclaration.name() == "TextureDepth2D")
         texture = m_textureDepth2D;
     else if (nativeTypeDeclaration.name() == "RWTextureDepth2D")
@@ -388,19 +384,14 @@ bool Intrinsics::addDepthTexture(AST::NativeTypeDeclaration& nativeTypeDeclarati
         texture = m_textureDepth2DArray;
     else if (nativeTypeDeclaration.name() == "RWTextureDepth2DArray")
         texture = m_rwTextureDepth2DArray;
-    else if (nativeTypeDeclaration.name() == "TextureDepthCube")
+    else {
+        ASSERT(nativeTypeDeclaration.name() == "TextureDepthCube");
         texture = m_textureDepthCube;
-    else
-        ASSERT_NOT_REACHED();
-    unsigned innerTypeIndex = WTF_ARRAY_LENGTH(m_depthTextureInnerTypes);
-    for (unsigned i = 0; i < WTF_ARRAY_LENGTH(m_depthTextureInnerTypes); ++i) {
-        if (innerType.name() == m_depthTextureInnerTypes[i])
-            innerTypeIndex = i;
     }
+    auto innerTypeIndex = std::find(m_depthTextureInnerTypes, m_depthTextureInnerTypes + WTF_ARRAY_LENGTH(m_depthTextureInnerTypes), innerType.name()) - m_depthTextureInnerTypes;
     ASSERT(innerTypeIndex != WTF_ARRAY_LENGTH(m_depthTextureInnerTypes));
     nativeTypeDeclaration.setIsTexture();
     texture[innerTypeIndex] = &nativeTypeDeclaration;
-    return true;
 }
 
 void Intrinsics::addTexture(AST::NativeTypeDeclaration& nativeTypeDeclaration)
@@ -413,8 +404,8 @@ void Intrinsics::addTexture(AST::NativeTypeDeclaration& nativeTypeDeclaration)
         m_textureSet.add(&nativeTypeDeclaration);
         return;
     }
-    if (addDepthTexture(nativeTypeDeclaration, innerType))
-        m_textureSet.add(&nativeTypeDeclaration);
+    addDepthTexture(nativeTypeDeclaration, innerType);
+    m_textureSet.add(&nativeTypeDeclaration);
 }
 
 void Intrinsics::add(AST::NativeTypeDeclaration& nativeTypeDeclaration)
index d23bf97..ad857c5 100644 (file)
@@ -231,7 +231,7 @@ private:
     bool addVector(AST::NativeTypeDeclaration&);
     bool addMatrix(AST::NativeTypeDeclaration&);
     bool addFullTexture(AST::NativeTypeDeclaration&, AST::TypeReference&);
-    bool addDepthTexture(AST::NativeTypeDeclaration&, AST::TypeReference&);
+    void addDepthTexture(AST::NativeTypeDeclaration&, AST::TypeReference&);
     void addTexture(AST::NativeTypeDeclaration&);
 
     HashSet<const AST::NativeTypeDeclaration*> m_textureSet;
index f80da99..75b4ae3 100644 (file)
@@ -306,7 +306,6 @@ static Optional<ModifyResult> modify(AST::PropertyAccessExpression& propertyAcce
         if (iterator->base().typeAnnotation().leftAddressSpace())
             break;
         ASSERT(!iterator->base().typeAnnotation().isRightValue());
-        ASSERT(is<AST::PropertyAccessExpression>(iterator->base()));
         iterator = &downcast<AST::PropertyAccessExpression>(iterator->base());
     }
     auto leftExpression = iterator->takeBase();
@@ -519,7 +518,6 @@ void PropertyResolver::visit(AST::AssignmentExpression& assignmentExpression)
         return;
     }
     ASSERT(!assignmentExpression.left().typeAnnotation().isRightValue());
-    ASSERT(is<AST::PropertyAccessExpression>(assignmentExpression.left()));
 
     auto type = assignmentExpression.right().resolvedType().clone();
 
index 2063d2a..3443d53 100644 (file)
@@ -59,10 +59,8 @@ void Visitor::visit(AST::UnnamedType& unnamedType)
         checkErrorAndVisit(downcast<AST::PointerType>(unnamedType));
     else if (is<AST::ArrayReferenceType>(unnamedType))
         checkErrorAndVisit(downcast<AST::ArrayReferenceType>(unnamedType));
-    else {
-        ASSERT(is<AST::ArrayType>(unnamedType));
+    else
         checkErrorAndVisit(downcast<AST::ArrayType>(unnamedType));
-    }
 }
 
 void Visitor::visit(AST::NamedType& namedType)
@@ -73,10 +71,8 @@ void Visitor::visit(AST::NamedType& namedType)
         checkErrorAndVisit(downcast<AST::StructureDefinition>(namedType));
     else if (is<AST::EnumerationDefinition>(namedType))
         checkErrorAndVisit(downcast<AST::EnumerationDefinition>(namedType));
-    else {
-        ASSERT(is<AST::NativeTypeDeclaration>(namedType));
+    else
         checkErrorAndVisit(downcast<AST::NativeTypeDeclaration>(namedType));
-    }
 }
 
 void Visitor::visit(AST::TypeDefinition& typeDefinition)
@@ -336,10 +332,8 @@ void Visitor::visit(AST::Statement& statement)
         checkErrorAndVisit(downcast<AST::Trap>(statement));
     else if (is<AST::VariableDeclarationsStatement>(statement))
         checkErrorAndVisit(downcast<AST::VariableDeclarationsStatement>(statement));
-    else {
-        ASSERT(is<AST::WhileLoop>(statement));
+    else
         checkErrorAndVisit(downcast<AST::WhileLoop>(statement));
-    }
 }
 
 void Visitor::visit(AST::Break&)
@@ -396,10 +390,8 @@ void Visitor::visit(AST::Expression& expression)
         checkErrorAndVisit(downcast<AST::UnsignedIntegerLiteral>(expression));
     else if (is<AST::EnumerationMemberLiteral>(expression))
         checkErrorAndVisit(downcast<AST::EnumerationMemberLiteral>(expression));
-    else {
-        ASSERT(is<AST::VariableReference>(expression));
+    else
         checkErrorAndVisit(downcast<AST::VariableReference>(expression));
-    }
 }
 
 void Visitor::visit(AST::DotExpression& dotExpression)