[WHLSL] Implement property resolver
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 23 May 2019 09:29:27 +0000 (09:29 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 23 May 2019 09:29:27 +0000 (09:29 +0000)
commit1e9830a861b3cc61f25a19838a29e48b44637983
tree7bb24821225ffcabef15e8b939fbec8edf4a7a7a
parentd9c6ea886d9f61b2c2f661b20999ebe066586dd5
[WHLSL] Implement property resolver
https://bugs.webkit.org/show_bug.cgi?id=195925
<rdar://problem/48219643>

Reviewed by Saam Barati and Robin Morisset.

Source/WebCore:

The property resolver is the thing that replaces dot expressions, index expressions, and
read-modify-write expressions with calls to getters, setters, and anders. This patch doesn't
fully implement the property resolver, but implements enough for simple dot expressions to
work. This is enough for us to be able to test most of the rest of the compiler. Index
expressions and read-modify-write expressions are not fully included in this patch, and will
be finished in a follow-up patch.

The property resolver may introduce anonymous variables in various places. In order to do
this, after the property resolver runs, it will insert all these anonymous variables in the
beginning of the function. However, this means that entries in the VariableDeclarations
vector will all shift, which means VariableDeclarations have to be allocated on the heap so
backreferences to them stay valid. This patch moves the storage associated with these values
to living directly in the vector's storage to living in heap storage (via filling the vector
with UniqueRefs).

This patch also adds the third concept of value-ness. We now have right values, left values,
and abstract left values (for things which have setters but have no address). This addition
is required for the analysis the property resolver performs. This concept is also present in
the spec.

Test: webgpu/whlsl-dot-expressions.html

* Modules/webgpu/WHLSL/AST/WHLSLAddressSpace.h:
(WebCore::WHLSL::AST::TypeAnnotation::TypeAnnotation):
(WebCore::WHLSL::AST::TypeAnnotation::leftAddressSpace const):
(WebCore::WHLSL::AST::TypeAnnotation::isRightValue const):
(WebCore::WHLSL::AST::TypeAnnotation::visit):
* Modules/webgpu/WHLSL/AST/WHLSLAssignmentExpression.h:
(WebCore::WHLSL::AST::AssignmentExpression::takeRight):
* Modules/webgpu/WHLSL/AST/WHLSLConstantExpression.h:
* Modules/webgpu/WHLSL/AST/WHLSLDotExpression.h:
* Modules/webgpu/WHLSL/AST/WHLSLEntryPointType.h:
* Modules/webgpu/WHLSL/AST/WHLSLExpression.h:
(WebCore::WHLSL::AST::Expression::maybeResolvedType):
(WebCore::WHLSL::AST::Expression::resolvedType):
(WebCore::WHLSL::AST::Expression::maybeTypeAnnotation const):
(WebCore::WHLSL::AST::Expression::typeAnnotation const):
(WebCore::WHLSL::AST::Expression::setTypeAnnotation):
(WebCore::WHLSL::AST::Expression::addressSpace const): Deleted.
(WebCore::WHLSL::AST::Expression::setAddressSpace): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLFloatLiteral.h:
(WebCore::WHLSL::AST::FloatLiteral::clone const):
* Modules/webgpu/WHLSL/AST/WHLSLIndexExpression.h:
* Modules/webgpu/WHLSL/AST/WHLSLIntegerLiteral.cpp:
(WebCore::WHLSL::AST::IntegerLiteral::valueForSelectedType const):
* Modules/webgpu/WHLSL/AST/WHLSLIntegerLiteral.h:
(WebCore::WHLSL::AST::IntegerLiteral::clone const):
* Modules/webgpu/WHLSL/AST/WHLSLMakeArrayReferenceExpression.h:
(WebCore::WHLSL::AST::MakeArrayReferenceExpression::MakeArrayReferenceExpression):
(WebCore::WHLSL::AST::MakeArrayReferenceExpression::leftValue):
(WebCore::WHLSL::AST::MakeArrayReferenceExpression::lValue): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLMakePointerExpression.h:
(WebCore::WHLSL::AST::MakePointerExpression::MakePointerExpression):
(WebCore::WHLSL::AST::MakePointerExpression::leftValue):
(WebCore::WHLSL::AST::MakePointerExpression::lValue): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLNullLiteral.h:
(WebCore::WHLSL::AST::NullLiteral::clone const):
* Modules/webgpu/WHLSL/AST/WHLSLPropertyAccessExpression.h:
(WebCore::WHLSL::AST::PropertyAccessExpression::possibleGetterOverloads):
(WebCore::WHLSL::AST::PropertyAccessExpression::possibleSetterOverloads):
(WebCore::WHLSL::AST::PropertyAccessExpression::possibleAnderOverloads):
(WebCore::WHLSL::AST::PropertyAccessExpression::getterFunction):
(WebCore::WHLSL::AST::PropertyAccessExpression::anderFunction):
(WebCore::WHLSL::AST::PropertyAccessExpression::threadAnderFunction):
(WebCore::WHLSL::AST::PropertyAccessExpression::setterFunction):
(WebCore::WHLSL::AST::PropertyAccessExpression::setPossibleGetterOverloads):
(WebCore::WHLSL::AST::PropertyAccessExpression::setPossibleAnderOverloads):
(WebCore::WHLSL::AST::PropertyAccessExpression::setPossibleSetterOverloads):
(WebCore::WHLSL::AST::PropertyAccessExpression::setGetterFunction):
(WebCore::WHLSL::AST::PropertyAccessExpression::setAnderFunction):
(WebCore::WHLSL::AST::PropertyAccessExpression::setThreadAnderFunction):
(WebCore::WHLSL::AST::PropertyAccessExpression::setSetterFunction):
(WebCore::WHLSL::AST::PropertyAccessExpression::takeBase):
(WebCore::WHLSL::AST::PropertyAccessExpression::possibleGetOverloads): Deleted.
(WebCore::WHLSL::AST::PropertyAccessExpression::possibleSetOverloads): Deleted.
(WebCore::WHLSL::AST::PropertyAccessExpression::possibleAndOverloads): Deleted.
(WebCore::WHLSL::AST::PropertyAccessExpression::setPossibleGetOverloads): Deleted.
(WebCore::WHLSL::AST::PropertyAccessExpression::setPossibleSetOverloads): Deleted.
(WebCore::WHLSL::AST::PropertyAccessExpression::setPossibleAndOverloads): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLReadModifyWriteExpression.h:
(WebCore::WHLSL::AST::ReadModifyWriteExpression::oldVariableReference):
(WebCore::WHLSL::AST::ReadModifyWriteExpression::newVariableReference):
(WebCore::WHLSL::AST::ReadModifyWriteExpression::leftValue):
(WebCore::WHLSL::AST::ReadModifyWriteExpression::takeLeftValue):
(WebCore::WHLSL::AST::ReadModifyWriteExpression::takeOldValue):
(WebCore::WHLSL::AST::ReadModifyWriteExpression::takeNewValue):
(WebCore::WHLSL::AST::ReadModifyWriteExpression::takeNewValueExpression):
(WebCore::WHLSL::AST::ReadModifyWriteExpression::takeResultExpression):
(WebCore::WHLSL::AST::ReadModifyWriteExpression::ReadModifyWriteExpression):
(WebCore::WHLSL::AST::ReadModifyWriteExpression::lValue): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLResolvableType.h:
(WebCore::WHLSL::AST::ResolvableType::maybeResolvedType const):
(WebCore::WHLSL::AST::ResolvableType::resolvedType const):
(WebCore::WHLSL::AST::ResolvableType::maybeResolvedType):
(WebCore::WHLSL::AST::ResolvableType::resolvedType):
* Modules/webgpu/WHLSL/AST/WHLSLResourceSemantic.cpp:
(WebCore::WHLSL::AST::ResourceSemantic::isAcceptableType const):
* Modules/webgpu/WHLSL/AST/WHLSLSpecializationConstantSemantic.cpp:
(WebCore::WHLSL::AST::SpecializationConstantSemantic::isAcceptableType const):
* Modules/webgpu/WHLSL/AST/WHLSLStageInOutSemantic.cpp:
(WebCore::WHLSL::AST::StageInOutSemantic::isAcceptableType const):
* Modules/webgpu/WHLSL/AST/WHLSLStructureDefinition.h:
(WebCore::WHLSL::AST::StructureDefinition::find):
* Modules/webgpu/WHLSL/AST/WHLSLTypeReference.h:
(WebCore::WHLSL::AST::TypeReference::maybeResolvedType const):
(WebCore::WHLSL::AST::TypeReference::resolvedType const):
* Modules/webgpu/WHLSL/AST/WHLSLUnsignedIntegerLiteral.cpp:
(WebCore::WHLSL::AST::UnsignedIntegerLiteral::valueForSelectedType const):
* Modules/webgpu/WHLSL/AST/WHLSLUnsignedIntegerLiteral.h:
(WebCore::WHLSL::AST::UnsignedIntegerLiteral::clone const):
* Modules/webgpu/WHLSL/AST/WHLSLVariableDeclaration.h:
* Modules/webgpu/WHLSL/AST/WHLSLVariableDeclarationsStatement.h:
(WebCore::WHLSL::AST::VariableDeclarationsStatement::VariableDeclarationsStatement):
(WebCore::WHLSL::AST::VariableDeclarationsStatement::variableDeclarations):
* Modules/webgpu/WHLSL/Metal/WHLSLEntryPointScaffolding.cpp:
(WebCore::WHLSL::Metal::attributeForSemantic):
(WebCore::WHLSL::Metal::EntryPointScaffolding::mangledInputPath):
(WebCore::WHLSL::Metal::EntryPointScaffolding::unpackResourcesAndNamedBuiltIns):
(WebCore::WHLSL::Metal::FragmentEntryPointScaffolding::helperTypes):
(WebCore::WHLSL::Metal::FragmentEntryPointScaffolding::unpack):
* Modules/webgpu/WHLSL/Metal/WHLSLFunctionWriter.cpp:
(WebCore::WHLSL::Metal::FunctionDeclarationWriter::visit):
(WebCore::WHLSL::Metal::FunctionDefinitionWriter::visit):
* 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::findInVector):
(WebCore::WHLSL::Metal::TypeNamer::visit):
(WebCore::WHLSL::Metal::TypeNamer::createNameNode):
* Modules/webgpu/WHLSL/WHLSLASTDumper.cpp:
(WebCore::WHLSL::ASTDumper::visit):
* Modules/webgpu/WHLSL/WHLSLCheckDuplicateFunctions.cpp:
(WebCore::WHLSL::checkDuplicateFunctions):
* Modules/webgpu/WHLSL/WHLSLChecker.cpp:
(WebCore::WHLSL::resolveWithOperatorAnderIndexer):
(WebCore::WHLSL::resolveWithOperatorLength):
(WebCore::WHLSL::resolveWithReferenceComparator):
(WebCore::WHLSL::resolveByInstantiation):
(WebCore::WHLSL::checkOperatorOverload):
(WebCore::WHLSL::Checker::assignTypes):
(WebCore::WHLSL::commit):
(WebCore::WHLSL::Checker::visit):
(WebCore::WHLSL::Checker::recurseAndGetInfo):
(WebCore::WHLSL::Checker::getInfo):
(WebCore::WHLSL::Checker::assignType):
(WebCore::WHLSL::Checker::forwardType):
(WebCore::WHLSL::getUnnamedType):
(WebCore::WHLSL::Checker::finishVisitingPropertyAccess): Deleted.
(WebCore::WHLSL::Checker::recurseAndWrapBaseType): Deleted.
* Modules/webgpu/WHLSL/WHLSLGatherEntryPointItems.cpp:
(WebCore::WHLSL::Gatherer::takeEntryPointItems):
(WebCore::WHLSL::Gatherer::visit):
* Modules/webgpu/WHLSL/WHLSLInferTypes.cpp:
(WebCore::WHLSL::matchAndCommit):
(WebCore::WHLSL::commit):
(WebCore::WHLSL::inferTypesForCall):
* Modules/webgpu/WHLSL/WHLSLLiteralTypeChecker.cpp:
(WebCore::WHLSL::getNativeTypeDeclaration):
* Modules/webgpu/WHLSL/WHLSLNameResolver.cpp:
(WebCore::WHLSL::NameResolver::visit):
* Modules/webgpu/WHLSL/WHLSLParser.cpp:
(WebCore::WHLSL::Parser::parseParameters):
(WebCore::WHLSL::Parser::parseVariableDeclarations):
* Modules/webgpu/WHLSL/WHLSLPipelineDescriptor.h:
* Modules/webgpu/WHLSL/WHLSLPrepare.cpp:
(WebCore::WHLSL::prepareShared):
* Modules/webgpu/WHLSL/WHLSLPrepare.h:
* Modules/webgpu/WHLSL/WHLSLPropertyResolver.cpp: Added.
(WebCore::WHLSL::PropertyResolver::visit):
(WebCore::WHLSL::setterCall):
(WebCore::WHLSL::getterCall):
(WebCore::WHLSL::modify):
(WebCore::WHLSL::PropertyResolver::simplifyRightValue):
(WebCore::WHLSL::LeftValueSimplifier::visit):
(WebCore::WHLSL::PropertyResolver::simplifyLeftValue):
(WebCore::WHLSL::resolveProperties):
* Modules/webgpu/WHLSL/WHLSLPropertyResolver.h: Copied from Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLEntryPointType.h.
* Modules/webgpu/WHLSL/WHLSLRecursiveTypeChecker.cpp:
(WebCore::WHLSL::RecursiveTypeChecker::visit):
* Modules/webgpu/WHLSL/WHLSLResolveOverloadImpl.cpp:
(WebCore::WHLSL::conversionCost):
* Modules/webgpu/WHLSL/WHLSLResolvingType.h:
(WebCore::WHLSL::ResolvingType::getUnnamedType):
* Modules/webgpu/WHLSL/WHLSLStandardLibrary.txt:
* Modules/webgpu/WHLSL/WHLSLSynthesizeArrayOperatorLength.cpp:
(WebCore::WHLSL::FindArrayTypes::takeArrayTypes):
(WebCore::WHLSL::synthesizeArrayOperatorLength):
* Modules/webgpu/WHLSL/WHLSLSynthesizeConstructors.cpp:
(WebCore::WHLSL::FindAllTypes::takeUnnamedTypes):
(WebCore::WHLSL::FindAllTypes::takeNamedTypes):
(WebCore::WHLSL::synthesizeConstructors):
* Modules/webgpu/WHLSL/WHLSLSynthesizeEnumerationFunctions.cpp:
(WebCore::WHLSL::synthesizeEnumerationFunctions):
* Modules/webgpu/WHLSL/WHLSLSynthesizeStructureAccessors.cpp:
(WebCore::WHLSL::synthesizeStructureAccessors):
* Modules/webgpu/WHLSL/WHLSLVisitor.cpp:
(WebCore::WHLSL::Visitor::visit):
* Modules/webgpu/WHLSL/WHLSLVisitor.h:
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm:
(WebCore::trySetWHLSLFunctionsForPipelineDescriptor):

LayoutTests:

* webgpu/whlsl-dot-expressions-expected.html: Added.
* webgpu/whlsl-dot-expressions.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245680 268f45cc-cd09-0410-ab3c-d52691b4dbfc
60 files changed:
LayoutTests/ChangeLog
LayoutTests/webgpu/whlsl-dot-expressions-expected.html [new file with mode: 0644]
LayoutTests/webgpu/whlsl-dot-expressions.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLAddressSpace.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLAssignmentExpression.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLConstantExpression.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLDotExpression.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLEntryPointType.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLExpression.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLFloatLiteral.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLIndexExpression.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLIntegerLiteral.cpp
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLIntegerLiteral.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLMakeArrayReferenceExpression.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLMakePointerExpression.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLNullLiteral.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLPropertyAccessExpression.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLReadModifyWriteExpression.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLResolvableType.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLResourceSemantic.cpp
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLSpecializationConstantSemantic.cpp
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLStageInOutSemantic.cpp
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLStructureDefinition.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLTypeReference.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLUnsignedIntegerLiteral.cpp
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLUnsignedIntegerLiteral.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLVariableDeclaration.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLVariableDeclarationsStatement.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/WHLSLASTDumper.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLCheckDuplicateFunctions.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLChecker.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLGatherEntryPointItems.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLInferTypes.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLLiteralTypeChecker.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLParser.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLPipelineDescriptor.h
Source/WebCore/Modules/webgpu/WHLSL/WHLSLPrepare.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLPrepare.h
Source/WebCore/Modules/webgpu/WHLSL/WHLSLPropertyResolver.cpp [new file with mode: 0644]
Source/WebCore/Modules/webgpu/WHLSL/WHLSLPropertyResolver.h [new file with mode: 0644]
Source/WebCore/Modules/webgpu/WHLSL/WHLSLRecursiveTypeChecker.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLResolveOverloadImpl.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLResolvingType.h
Source/WebCore/Modules/webgpu/WHLSL/WHLSLStandardLibrary.txt
Source/WebCore/Modules/webgpu/WHLSL/WHLSLSynthesizeArrayOperatorLength.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLSynthesizeConstructors.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLSynthesizeEnumerationFunctions.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLSynthesizeStructureAccessors.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLVisitor.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLVisitor.h
Source/WebCore/Sources.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm