Changeset 247499 in webkit


Ignore:
Timestamp:
Jul 16, 2019 4:10:17 PM (5 years ago)
Author:
commit-queue@webkit.org
Message:

Unreviewed, rolling out r247493.
https://bugs.webkit.org/show_bug.cgi?id=199841

"The new whlsl-for-loop.html test is failing on the bots"
(Requested by rmorisset on #webkit).

Reverted changeset:

"[WHLSL] Desugar for loops and while loops"
https://bugs.webkit.org/show_bug.cgi?id=199726
https://trac.webkit.org/changeset/247493

Location:
trunk
Files:
2 deleted
18 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r247493 r247499  
     12019-07-16  Commit Queue  <commit-queue@webkit.org>
     2
     3        Unreviewed, rolling out r247493.
     4        https://bugs.webkit.org/show_bug.cgi?id=199841
     5
     6        "The new whlsl-for-loop.html test is failing on the bots"
     7        (Requested by rmorisset on #webkit).
     8
     9        Reverted changeset:
     10
     11        "[WHLSL] Desugar for loops and while loops"
     12        https://bugs.webkit.org/show_bug.cgi?id=199726
     13        https://trac.webkit.org/changeset/247493
     14
    1152019-07-16  Robin Morisset  <rmorisset@apple.com>
    216
  • trunk/LayoutTests/webgpu/whlsl-return-spec-tests.html

    r247493 r247499  
    112112            }
    113113        `);
    114     await checkFail(
    115         `
    116             int foo(int x)
    117             {
    118                 int y = 6;
    119                 if (x == 7)
    120                     int y = 8;
    121                 return y;
    122             }
    123         `);
     114
     115    program = `
     116        int foo(int x)
     117        {
     118            int y = 6;
     119            if (x == 7)
     120                int y = 8;
     121            return y;
     122        }
     123    `;
     124    assert_equals(await callIntFunction(program, "foo", [makeInt(7)]), 6);
    124125};
    125126
  • trunk/Source/WebCore/ChangeLog

    r247498 r247499  
     12019-07-16  Commit Queue  <commit-queue@webkit.org>
     2
     3        Unreviewed, rolling out r247493.
     4        https://bugs.webkit.org/show_bug.cgi?id=199841
     5
     6        "The new whlsl-for-loop.html test is failing on the bots"
     7        (Requested by rmorisset on #webkit).
     8
     9        Reverted changeset:
     10
     11        "[WHLSL] Desugar for loops and while loops"
     12        https://bugs.webkit.org/show_bug.cgi?id=199726
     13        https://trac.webkit.org/changeset/247493
     14
    1152019-07-16  Per Arne Vollan  <pvollan@apple.com>
    216
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLAST.h

    r247493 r247499  
    102102#include "WHLSLVariableDeclarationsStatement.h"
    103103#include "WHLSLVariableReference.h"
     104#include "WHLSLWhileLoop.h"
    104105
    105106#endif
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLForLoop.h

    r247493 r247499  
    4545class ForLoop : public Statement {
    4646public:
    47     ForLoop(CodeLocation location, UniqueRef<Expression>&& condition, UniqueRef<Expression>&& increment, UniqueRef<Statement>&& body)
     47    ForLoop(CodeLocation location, Variant<UniqueRef<Statement>, UniqueRef<Expression>>&& initialization, std::unique_ptr<Expression>&& condition, std::unique_ptr<Expression>&& increment, UniqueRef<Statement>&& body)
    4848        : Statement(location)
     49        , m_initialization(WTFMove(initialization))
    4950        , m_condition(WTFMove(condition))
    5051        , m_increment(WTFMove(increment))
     
    5354    }
    5455
    55     virtual ~ForLoop() = default;
     56    virtual ~ForLoop()
     57    {
     58    }
    5659
    5760    ForLoop(const ForLoop&) = delete;
     
    6063    bool isForLoop() const override { return true; }
    6164
    62     Expression& condition() { return m_condition; }
    63     Expression& increment() { return m_increment; }
     65    Variant<UniqueRef<Statement>, UniqueRef<Expression>>& initialization() { return m_initialization; }
     66    Expression* condition() { return m_condition.get(); }
     67    Expression* increment() { return m_increment.get(); }
    6468    Statement& body() { return m_body; }
    6569
    6670private:
    67     UniqueRef<Expression> m_condition;
    68     UniqueRef<Expression> m_increment;
     71    Variant<UniqueRef<Statement>, UniqueRef<Expression>> m_initialization;
     72    std::unique_ptr<Expression> m_condition;
     73    std::unique_ptr<Expression> m_increment;
    6974    UniqueRef<Statement> m_body;
    7075};
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLStatement.h

    r247493 r247499  
    6363    virtual bool isTrap() const { return false; }
    6464    virtual bool isVariableDeclarationsStatement() const { return false; }
     65    virtual bool isWhileLoop() const { return false; }
    6566
    6667    CodeLocation codeLocation() const { return m_codeLocation; }
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLWhileLoop.h

    r247498 r247499  
    3131#include "WHLSLLexer.h"
    3232#include "WHLSLStatement.h"
    33 #include "WHLSLVariableDeclarationsStatement.h"
    34 #include <memory>
    3533#include <wtf/UniqueRef.h>
    36 #include <wtf/Variant.h>
    37 #include <wtf/Vector.h>
    3834
    3935namespace WebCore {
     
    4339namespace AST {
    4440
    45 class ForLoop : public Statement {
     41class WhileLoop : public Statement {
    4642public:
    47     ForLoop(CodeLocation location, UniqueRef<Expression>&& condition, UniqueRef<Expression>&& increment, UniqueRef<Statement>&& body)
     43    WhileLoop(CodeLocation location, UniqueRef<Expression>&& conditional, UniqueRef<Statement>&& body)
    4844        : Statement(location)
    49         , m_condition(WTFMove(condition))
    50         , m_increment(WTFMove(increment))
     45        , m_conditional(WTFMove(conditional))
    5146        , m_body(WTFMove(body))
    5247    {
    5348    }
    5449
    55     virtual ~ForLoop() = default;
     50    virtual ~WhileLoop() = default;
    5651
    57     ForLoop(const ForLoop&) = delete;
    58     ForLoop(ForLoop&&) = default;
     52    WhileLoop(const WhileLoop&) = delete;
     53    WhileLoop(WhileLoop&&) = default;
    5954
    60     bool isForLoop() const override { return true; }
     55    bool isWhileLoop() const override { return true; }
    6156
    62     Expression& condition() { return m_condition; }
    63     Expression& increment() { return m_increment; }
     57    Expression& conditional() { return m_conditional; }
    6458    Statement& body() { return m_body; }
    6559
    6660private:
    67     UniqueRef<Expression> m_condition;
    68     UniqueRef<Expression> m_increment;
     61    UniqueRef<Expression> m_conditional;
    6962    UniqueRef<Statement> m_body;
    7063};
     
    7669}
    7770
    78 SPECIALIZE_TYPE_TRAITS_WHLSL_STATEMENT(ForLoop, isForLoop())
     71SPECIALIZE_TYPE_TRAITS_WHLSL_STATEMENT(WhileLoop, isWhileLoop())
    7972
    8073#endif
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLFunctionWriter.cpp

    r247493 r247499  
    129129    void visit(AST::Trap&) override;
    130130    void visit(AST::VariableDeclarationsStatement&) override;
     131    void visit(AST::WhileLoop&) override;
    131132    void visit(AST::IntegerLiteral&) override;
    132133    void visit(AST::UnsignedIntegerLiteral&) override;
     
    350351}
    351352
     353void FunctionDefinitionWriter::visit(AST::WhileLoop& whileLoop)
     354{
     355    emitLoop(LoopConditionLocation::BeforeBody, &whileLoop.conditional(), nullptr, whileLoop.body());
     356}
     357
    352358void FunctionDefinitionWriter::visit(AST::ForLoop& forLoop)
    353359{
    354     emitLoop(LoopConditionLocation::BeforeBody, &forLoop.condition(), &forLoop.increment(), forLoop.body());
     360    m_stringBuilder.append("{\n");
     361
     362    WTF::visit(WTF::makeVisitor([&](AST::Statement& statement) {
     363        checkErrorAndVisit(statement);
     364    }, [&](UniqueRef<AST::Expression>& expression) {
     365        checkErrorAndVisit(expression);
     366        takeLastValue(); // We don't need to do anything with the result.
     367    }), forLoop.initialization());
     368
     369    emitLoop(LoopConditionLocation::BeforeBody, forLoop.condition(), forLoop.increment(), forLoop.body());
     370    m_stringBuilder.append("}\n");
    355371}
    356372
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLASTDumper.cpp

    r247493 r247499  
    394394}
    395395
     396void ASTDumper::visit(AST::WhileLoop& whileLoop)
     397{
     398    m_out.print("while (");
     399    visit(whileLoop.conditional());
     400    m_out.print(")");
     401    visit(whileLoop.body());
     402}
     403
    396404void ASTDumper::visit(AST::DoWhileLoop& doWhileLoop)
    397405{
     
    405413void ASTDumper::visit(AST::ForLoop& forLoop)
    406414{
    407     m_out.print("for (; ");
    408     visit(forLoop.condition());
     415    m_out.print("for (");
     416    WTF::visit(WTF::makeVisitor([&](UniqueRef<AST::Statement>& statement) {
     417        visit(statement);
     418    }, [&](UniqueRef<AST::Expression>& expression) {
     419        visit(expression);
     420    }), forLoop.initialization());
    409421    m_out.print("; ");
    410     visit(forLoop.increment());
     422    if (forLoop.condition())
     423        visit(*forLoop.condition());
     424    m_out.print("; ");
     425    if (forLoop.increment())
     426        visit(*forLoop.increment());
    411427    m_out.print(") ");
    412428    visit(forLoop.body());
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLASTDumper.h

    r247493 r247499  
    101101    void visit(AST::Trap&) override;
    102102    void visit(AST::VariableDeclarationsStatement&) override;
     103    void visit(AST::WhileLoop&) override;
    103104    void visit(AST::VariableDeclaration&) override;
    104105    void visit(AST::AssignmentExpression&) override;
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLChecker.cpp

    r247493 r247499  
    5858#include "WHLSLTernaryExpression.h"
    5959#include "WHLSLVisitor.h"
     60#include "WHLSLWhileLoop.h"
    6061#include <wtf/HashMap.h>
    6162#include <wtf/HashSet.h>
     
    501502    void visit(AST::LogicalExpression&) override;
    502503    void visit(AST::IfStatement&) override;
     504    void visit(AST::WhileLoop&) override;
    503505    void visit(AST::DoWhileLoop&) override;
    504506    void visit(AST::ForLoop&) override;
     
    12461248}
    12471249
     1250void Checker::visit(AST::WhileLoop& whileLoop)
     1251{
     1252    if (!recurseAndRequireBoolType(whileLoop.conditional()))
     1253        return;
     1254    checkErrorAndVisit(whileLoop.body());
     1255}
     1256
    12481257void Checker::visit(AST::DoWhileLoop& doWhileLoop)
    12491258{
     
    12541263void Checker::visit(AST::ForLoop& forLoop)
    12551264{
    1256     if (!recurseAndRequireBoolType(forLoop.condition()))
    1257         return;
    1258     checkErrorAndVisit(forLoop.increment());
     1265    WTF::visit(WTF::makeVisitor([&](UniqueRef<AST::Statement>& statement) {
     1266        checkErrorAndVisit(statement);
     1267    }, [&](UniqueRef<AST::Expression>& expression) {
     1268        checkErrorAndVisit(expression);
     1269    }), forLoop.initialization());
     1270    if (error())
     1271        return;
     1272    if (forLoop.condition()) {
     1273        if (!recurseAndRequireBoolType(*forLoop.condition()))
     1274            return;
     1275    }
     1276    if (forLoop.increment())
     1277        checkErrorAndVisit(*forLoop.increment());
    12591278    checkErrorAndVisit(forLoop.body());
    12601279}
     
    14161435void Checker::visit(AST::CommaExpression& commaExpression)
    14171436{
    1418     ASSERT(!commaExpression.list().isEmpty());
     1437    ASSERT(commaExpression.list().size() > 0);
    14191438    Visitor::visit(commaExpression);
    14201439    if (error())
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.cpp

    r247493 r247499  
    4444#include "WHLSLVariableDeclaration.h"
    4545#include "WHLSLVariableReference.h"
     46#include "WHLSLWhileLoop.h"
    4647
    4748namespace WebCore {
     
    120121        return;
    121122
    122     checkErrorAndVisit(ifStatement.body());
    123     if (error())
    124         return;
    125 
    126     if (ifStatement.elseBody())
    127         checkErrorAndVisit(*ifStatement.elseBody());
     123    {
     124        NameContext nameContext(&m_nameContext);
     125        NameResolver newNameResolver(*this, nameContext);
     126        newNameResolver.checkErrorAndVisit(ifStatement.body());
     127    }
     128    if (error())
     129        return;
     130
     131    if (ifStatement.elseBody()) {
     132        NameContext nameContext(&m_nameContext);
     133        NameResolver newNameResolver(*this, nameContext);
     134        newNameResolver.checkErrorAndVisit(*ifStatement.elseBody());
     135    }
     136}
     137
     138void NameResolver::visit(AST::WhileLoop& whileLoop)
     139{
     140    checkErrorAndVisit(whileLoop.conditional());
     141    if (error())
     142        return;
     143
     144    NameContext nameContext(&m_nameContext);
     145    NameResolver newNameResolver(*this, nameContext);
     146    newNameResolver.checkErrorAndVisit(whileLoop.body());
    128147}
    129148
    130149void NameResolver::visit(AST::DoWhileLoop& whileLoop)
    131150{
    132     checkErrorAndVisit(whileLoop.body());
    133     if (error())
    134         return;
     151    {
     152        NameContext nameContext(&m_nameContext);
     153        NameResolver newNameResolver(*this, nameContext);
     154        newNameResolver.checkErrorAndVisit(whileLoop.body());
     155    }
    135156
    136157    checkErrorAndVisit(whileLoop.conditional());
     
    139160void NameResolver::visit(AST::ForLoop& forLoop)
    140161{
    141     checkErrorAndVisit(forLoop.condition());
    142     if (error())
    143         return;
    144     checkErrorAndVisit(forLoop.increment());
    145     if (error())
    146         return;
    147 
    148     checkErrorAndVisit(forLoop.body());
     162    NameContext nameContext(&m_nameContext);
     163    NameResolver newNameResolver(*this, nameContext);
     164    newNameResolver.Visitor::visit(forLoop);
    149165}
    150166
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.h

    r247493 r247499  
    5151    void visit(AST::Block&) override;
    5252    void visit(AST::IfStatement&) override;
     53    void visit(AST::WhileLoop&) override;
    5354    void visit(AST::DoWhileLoop&) override;
    5455    void visit(AST::ForLoop&) override;
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLParser.cpp

    r247493 r247499  
    10641064    AST::Statements statements;
    10651065    while (!peekTypes<Token::Type::RightCurlyBracket, Token::Type::Case, Token::Type::Default>()) {
    1066         bool allowVariableDeclarations = true;
    1067         PARSE(statement, Statement, allowVariableDeclarations);
     1066        PARSE(statement, Statement);
    10681067        statements.append(WTFMove(*statement));
    10691068    }
     
    11441143}
    11451144
    1146 auto Parser::parseForLoop() -> Expected<AST::Block, Error>
     1145auto Parser::parseForLoop() -> Expected<AST::ForLoop, Error>
    11471146{
    11481147    CONSUME_TYPE(origin, For);
    11491148    CONSUME_TYPE(leftParenthesis, LeftParenthesis);
    11501149
     1150    auto parseRemainder = [&](Variant<UniqueRef<AST::Statement>, UniqueRef<AST::Expression>>&& initialization) -> Expected<AST::ForLoop, Error> {
     1151        CONSUME_TYPE(semicolon, Semicolon);
     1152
     1153        std::unique_ptr<AST::Expression> condition(nullptr);
     1154        if (!tryType(Token::Type::Semicolon)) {
     1155            if (auto expression = parseExpression())
     1156                condition = (*expression).moveToUniquePtr();
     1157            else
     1158                return Unexpected<Error>(expression.error());
     1159            CONSUME_TYPE(secondSemicolon, Semicolon);
     1160        }
     1161
     1162        std::unique_ptr<AST::Expression> increment(nullptr);
     1163        if (!tryType(Token::Type::RightParenthesis)) {
     1164            if (auto expression = parseExpression())
     1165                increment = (*expression).moveToUniquePtr();
     1166            else
     1167                return Unexpected<Error>(expression.error());
     1168            CONSUME_TYPE(rightParenthesis, RightParenthesis);
     1169        }
     1170
     1171        PARSE(body, Statement);
     1172        AST::CodeLocation location(origin->codeLocation,  (*body)->codeLocation());
     1173        return AST::ForLoop(location, WTFMove(initialization), WTFMove(condition), WTFMove(increment), WTFMove(*body));
     1174    };
    11511175
    11521176    auto variableDeclarations = backtrackingScope<Expected<AST::VariableDeclarationsStatement, Error>>([&]() {
    11531177        return parseVariableDeclarations();
    11541178    });
    1155     Optional<UniqueRef<AST::Statement>> initialization;
    1156     if (variableDeclarations)
    1157         initialization = static_cast<UniqueRef<AST::Statement>>(makeUniqueRef<AST::VariableDeclarationsStatement>(WTFMove(*variableDeclarations)));
    1158     else {
    1159         PARSE(effectfulExpression, EffectfulExpression);
    1160         initialization = WTFMove(*effectfulExpression);
    1161     }
    1162 
    1163     CONSUME_TYPE(semicolon, Semicolon);
    1164 
    1165     Optional<UniqueRef<AST::Expression>> condition;
    1166     auto secondSemicolon = tryType(Token::Type::Semicolon);
    1167     if (!secondSemicolon) {
    1168         PARSE(expression, Expression);
    1169         condition = WTFMove(*expression);
    1170         CONSUME_TYPE(secondSemicolon, Semicolon);
    1171     } else
    1172         condition = static_cast<UniqueRef<AST::Expression>>(makeUniqueRef<AST::BooleanLiteral>(*secondSemicolon, true));
    1173 
    1174     Optional<UniqueRef<AST::Expression>> increment;
    1175     auto rightParenthesis = tryType(Token::Type::RightParenthesis);
    1176     if (!rightParenthesis) {
    1177         PARSE(expression, Expression);
    1178         increment = WTFMove(*expression);
    1179         CONSUME_TYPE(rightParenthesis, RightParenthesis);
    1180     } else
    1181         increment = static_cast<UniqueRef<AST::Expression>>(makeUniqueRef<AST::BooleanLiteral>(*origin, true)); // FIXME: NullLiteral would make more sense, but is buggy right now. Anything side-effect free is fine.
    1182 
    1183     PARSE(body, Statement);
    1184     AST::CodeLocation location(origin->codeLocation,  (*body)->codeLocation());
    1185 
    1186     auto forLoop = makeUniqueRef<AST::ForLoop>(location, WTFMove(*condition), WTFMove(*increment), WTFMove(*body));
    1187     AST::Statements statements = Vector<UniqueRef<AST::Statement>>::from(WTFMove(*initialization), WTFMove(forLoop));
    1188     return AST::Block(location, WTFMove(statements));
    1189 }
    1190 
    1191 auto Parser::parseWhileLoop() -> Expected<AST::ForLoop, Error>
     1179    if (variableDeclarations) {
     1180        UniqueRef<AST::Statement> declarationStatement = makeUniqueRef<AST::VariableDeclarationsStatement>(WTFMove(*variableDeclarations));
     1181        return parseRemainder(WTFMove(declarationStatement));
     1182    }
     1183
     1184    PARSE(effectfulExpression, EffectfulExpression);
     1185
     1186    return parseRemainder(WTFMove(*effectfulExpression));
     1187}
     1188
     1189auto Parser::parseWhileLoop() -> Expected<AST::WhileLoop, Error>
    11921190{
    11931191    CONSUME_TYPE(origin, While);
     
    11981196
    11991197    AST::CodeLocation location(origin->codeLocation,  (*body)->codeLocation());
    1200     auto increment = makeUniqueRef<AST::BooleanLiteral>(*origin, true); // FIXME: NullLiteral would make more sense, but is buggy right now. Anything side-effect free is fine.
    1201     return AST::ForLoop(location, WTFMove(*conditional), WTFMove(increment), WTFMove(*body));
     1198    return AST::WhileLoop(location, WTFMove(*conditional), WTFMove(*body));
    12021199}
    12031200
     
    12581255}
    12591256
    1260 auto Parser::parseStatement(bool allowVariableDeclarations) -> Expected<UniqueRef<AST::Statement>, Error>
     1257auto Parser::parseStatement() -> Expected<UniqueRef<AST::Statement>, Error>
    12611258{
    12621259    PEEK(token);
     
    12761273    case Token::Type::For: {
    12771274        PARSE(forLoop, ForLoop);
    1278         return { makeUniqueRef<AST::Block>(WTFMove(*forLoop)) };
     1275        return { makeUniqueRef<AST::ForLoop>(WTFMove(*forLoop)) };
    12791276    }
    12801277    case Token::Type::While: {
    12811278        PARSE(whileLoop, WhileLoop);
    1282         return { makeUniqueRef<AST::ForLoop>(WTFMove(*whileLoop)) };
     1279        return { makeUniqueRef<AST::WhileLoop>(WTFMove(*whileLoop)) };
    12831280    }
    12841281    case Token::Type::Do: {
     
    13501347
    13511348    {
    1352         auto effectfulExpressionStatement = backtrackingScope<Expected<UniqueRef<AST::Statement>, Error>>([&]() -> Expected<UniqueRef<AST::Statement>, Error> {
     1349        auto effectfulExpression = backtrackingScope<Expected<UniqueRef<AST::Expression>, Error>>([&]() -> Expected<UniqueRef<AST::Expression>, Error> {
    13531350            PARSE(result, EffectfulExpression);
    13541351            CONSUME_TYPE(semicolon, Semicolon);
    13551352            return result;
    13561353        });
    1357         if (effectfulExpressionStatement)
    1358             return effectfulExpressionStatement;
    1359     }
    1360 
    1361     if (allowVariableDeclarations) {
    1362         PARSE(variableDeclarations, VariableDeclarations);
    1363         CONSUME_TYPE(semicolon, Semicolon);
    1364         return { makeUniqueRef<AST::VariableDeclarationsStatement>(WTFMove(*variableDeclarations)) };
    1365     }
    1366 
    1367     return Unexpected<Error>("A variable declaration is only valid inside a block");
    1368 }
    1369 
    1370 auto Parser::parseEffectfulExpression() -> Expected<UniqueRef<AST::Statement>, Error>
     1354        if (effectfulExpression)
     1355            return { makeUniqueRef<AST::EffectfulExpressionStatement>(WTFMove(*effectfulExpression)) };
     1356    }
     1357
     1358    PARSE(variableDeclarations, VariableDeclarations);
     1359    CONSUME_TYPE(semicolon, Semicolon);
     1360    return { makeUniqueRef<AST::VariableDeclarationsStatement>(WTFMove(*variableDeclarations)) };
     1361}
     1362
     1363auto Parser::parseEffectfulExpression() -> Expected<UniqueRef<AST::Expression>, Error>
    13711364{
    13721365    PEEK(origin);
    1373     if (origin->type == Token::Type::Semicolon) {
    1374         AST::Statements statements;
    1375         return { makeUniqueRef<AST::Block>(*origin, WTFMove(statements)) };
    1376     }
    1377 
    13781366    Vector<UniqueRef<AST::Expression>> expressions;
     1367    if (origin->type == Token::Type::Semicolon)
     1368        return { makeUniqueRef<AST::CommaExpression>(*origin, WTFMove(expressions)) };
     1369
    13791370    PARSE(effectfulExpression, EffectfulAssignment);
    13801371    expressions.append(WTFMove(*effectfulExpression));
     
    13861377
    13871378    if (expressions.size() == 1)
    1388         return { makeUniqueRef<AST::EffectfulExpressionStatement>(WTFMove(expressions[0])) };
     1379        return WTFMove(expressions[0]);
    13891380    unsigned endOffset = m_lexer.peek().startOffset();
    13901381    AST::CodeLocation location(origin->startOffset(), endOffset);
    1391     auto expression = makeUniqueRef<AST::CommaExpression>(location, WTFMove(expressions));
    1392     return { makeUniqueRef<AST::EffectfulExpressionStatement>(WTFMove(expression)) };
     1382    return { makeUniqueRef<AST::CommaExpression>(location, WTFMove(expressions)) };
    13931383}
    13941384
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLParser.h

    r247493 r247499  
    9292#include "WHLSLVariableDeclarationsStatement.h"
    9393#include "WHLSLVariableReference.h"
     94#include "WHLSLWhileLoop.h"
    9495#include <wtf/Expected.h>
    9596#include <wtf/Optional.h>
     
    203204    Expected<AST::SwitchStatement, Error> parseSwitchStatement();
    204205    Expected<AST::SwitchCase, Error> parseSwitchCase();
    205     Expected<AST::Block, Error> parseForLoop();
    206     Expected<AST::ForLoop, Error> parseWhileLoop();
     206    Expected<AST::ForLoop, Error> parseForLoop();
     207    Expected<AST::WhileLoop, Error> parseWhileLoop();
    207208    Expected<AST::DoWhileLoop, Error> parseDoWhileLoop();
    208209    Expected<AST::VariableDeclaration, Error> parseVariableDeclaration(UniqueRef<AST::UnnamedType>&&);
    209210    Expected<AST::VariableDeclarationsStatement, Error> parseVariableDeclarations();
    210     Expected<UniqueRef<AST::Statement>, Error> parseStatement(bool allowVariableDeclaration = false);
    211 
    212     Expected<UniqueRef<AST::Statement>, Error> parseEffectfulExpression();
     211    Expected<UniqueRef<AST::Statement>, Error> parseStatement();
     212
     213    Expected<UniqueRef<AST::Expression>, Error> parseEffectfulExpression();
    213214    Expected<UniqueRef<AST::Expression>, Error> parseEffectfulAssignment();
    214215    struct SuffixExpression {
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLStatementBehaviorChecker.cpp

    r247493 r247499  
    4545#include "WHLSLVariableDeclarationsStatement.h"
    4646#include "WHLSLVisitor.h"
     47#include "WHLSLWhileLoop.h"
    4748#include <cstdint>
    4849#include <wtf/OptionSet.h>
     
    109110    void visit(AST::ForLoop& forLoop) override
    110111    {
     112        // The initialization always has a behavior of Nothing, which we already add unconditionally below,
     113        // so we can just ignore the initialization.
     114
    111115        checkErrorAndVisit(forLoop.body());
     116        if (error())
     117            return;
     118        auto b = m_stack.takeLast();
     119        b.remove(Behavior::Break);
     120        b.remove(Behavior::Continue);
     121        b.add(Behavior::Nothing);
     122        m_stack.append(b);
     123    }
     124
     125    void visit(AST::WhileLoop& whileLoop) override
     126    {
     127        checkErrorAndVisit(whileLoop.body());
    112128        if (error())
    113129            return;
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLVisitor.cpp

    r247493 r247499  
    332332    else if (is<AST::Trap>(statement))
    333333        checkErrorAndVisit(downcast<AST::Trap>(statement));
    334     else {
    335         ASSERT(is<AST::VariableDeclarationsStatement>(statement));
     334    else if (is<AST::VariableDeclarationsStatement>(statement))
    336335        checkErrorAndVisit(downcast<AST::VariableDeclarationsStatement>(statement));
    337     }
     336    else
     337        checkErrorAndVisit(downcast<AST::WhileLoop>(statement));
    338338}
    339339
     
    428428void Visitor::visit(AST::ForLoop& forLoop)
    429429{
    430     checkErrorAndVisit(forLoop.condition());
    431     checkErrorAndVisit(forLoop.increment());
     430    WTF::visit(WTF::makeVisitor([&](UniqueRef<AST::Statement>& statement) {
     431        checkErrorAndVisit(statement);
     432    }, [&](UniqueRef<AST::Expression>& expression) {
     433        checkErrorAndVisit(expression);
     434    }), forLoop.initialization());
     435    if (forLoop.condition())
     436        checkErrorAndVisit(*forLoop.condition());
     437    if (forLoop.increment())
     438        checkErrorAndVisit(*forLoop.increment());
    432439    checkErrorAndVisit(forLoop.body());
    433440}
     
    469476    for (auto& variableDeclaration : variableDeclarationsStatement.variableDeclarations())
    470477        checkErrorAndVisit(variableDeclaration.get());
     478}
     479
     480void Visitor::visit(AST::WhileLoop& whileLoop)
     481{
     482    checkErrorAndVisit(whileLoop.conditional());
     483    checkErrorAndVisit(whileLoop.body());
    471484}
    472485
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLVisitor.h

    r247493 r247499  
    8686class Trap;
    8787class VariableDeclarationsStatement;
     88class WhileLoop;
    8889class VariableDeclaration;
    8990class AssignmentExpression;
     
    166167    virtual void visit(AST::Trap&);
    167168    virtual void visit(AST::VariableDeclarationsStatement&);
     169    virtual void visit(AST::WhileLoop&);
    168170    virtual void visit(AST::VariableDeclaration&);
    169171    virtual void visit(AST::AssignmentExpression&);
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r247493 r247499  
    1325713257                C21BF70221CD89C400227979 /* WHLSLEnumerationMemberLiteral.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLEnumerationMemberLiteral.h; sourceTree = "<group>"; };
    1325813258                C21BF70321CD89C500227979 /* WHLSLReturn.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLReturn.h; sourceTree = "<group>"; };
     13259                C21BF70421CD89C600227979 /* WHLSLWhileLoop.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLWhileLoop.h; sourceTree = "<group>"; };
    1325913260                C21BF70521CD89C700227979 /* WHLSLFunctionAttribute.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLFunctionAttribute.h; sourceTree = "<group>"; };
    1326013261                C21BF70621CD89C700227979 /* WHLSLCommaExpression.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLCommaExpression.h; sourceTree = "<group>"; };
     
    1713217133                                C21BF71421CD89D300227979 /* WHLSLVariableDeclarationsStatement.h */,
    1713317134                                C21BF71321CD89D200227979 /* WHLSLVariableReference.h */,
     17135                                C21BF70421CD89C600227979 /* WHLSLWhileLoop.h */,
    1713417136                        );
    1713517137                        path = AST;
Note: See TracChangeset for help on using the changeset viewer.