From aea43bdd4c402e2a0cc320951991485f51117218 Mon Sep 17 00:00:00 2001 From: Andrei Golubev Date: Fri, 1 Jul 2022 13:51:12 +0200 Subject: qqmltypecompiler: align runtime function table order to qmlcachegen When we write runtime functions to compilation unit at run time, the order of the functions in the unit (often) differs from the order of functions in the unit produced ahead of time by qmlcachegen and friends. Additionally, the order also differs from what qmltc expects (and qmlcompiler library in general) Fix the order by simplifying the procedure of JS code generation when we create the compilation unit at run time: new logic just goes over the objects in the document linearly, instead of relying on bindings (which are known to be out of order w.r.t. AST) Fixes: QTBUG-106800 Change-Id: I4070b9d061f03c4c76d03120654ad3f30725493a Reviewed-by: Ulf Hermann (cherry picked from commit 8d0adee3b3317f1fab03742bdf0f7cdbe57df914) Reviewed-by: Qt CI Bot Reviewed-by: Fabian Kosmale --- src/qmlcompiler/qqmljscompiler.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src/qmlcompiler/qqmljscompiler.cpp') diff --git a/src/qmlcompiler/qqmljscompiler.cpp b/src/qmlcompiler/qqmljscompiler.cpp index 36fb42af51..85306c56a8 100644 --- a/src/qmlcompiler/qqmljscompiler.cpp +++ b/src/qmlcompiler/qqmljscompiler.cpp @@ -238,18 +238,13 @@ bool qCompileQmlFile(QmlIR::Document &irDocument, const QString &inputFileName, for (QmlIR::Object *object: qAsConst(irDocument.objects)) { if (object->functionsAndExpressions->count == 0 && object->bindingCount() == 0) continue; - QList functionsToCompile; - for (QmlIR::CompiledFunctionOrExpression *foe = object->functionsAndExpressions->first; foe; foe = foe->next) - functionsToCompile << *foe; - const QVector runtimeFunctionIndices = v4CodeGen.generateJSCodeForFunctionsAndBindings(functionsToCompile); - if (v4CodeGen.hasError()) { + + if (!v4CodeGen.generateRuntimeFunctions(object)) { + Q_ASSERT(v4CodeGen.hasError()); error->appendDiagnostic(inputFileName, v4CodeGen.error()); return false; } - QQmlJS::MemoryPool *pool = irDocument.jsParserEngine.pool(); - object->runtimeFunctionIndices.allocate(pool, runtimeFunctionIndices); - if (!aotCompiler) continue; @@ -270,6 +265,12 @@ bool qCompileQmlFile(QmlIR::Document &irDocument, const QString &inputFileName, std::copy(object->functionsBegin(), object->functionsEnd(), std::back_inserter(bindingsAndFunctions)); + QList functionsToCompile; + for (QmlIR::CompiledFunctionOrExpression *foe = object->functionsAndExpressions->first; + foe; foe = foe->next) { + functionsToCompile << *foe; + } + // AOT-compile bindings and functions in the same order as above so that the runtime // class indices match std::sort(bindingsAndFunctions.begin(), bindingsAndFunctions.end()); @@ -326,7 +327,8 @@ bool qCompileQmlFile(QmlIR::Document &irDocument, const QString &inputFileName, << diagnosticErrorMessage(inputFileName, *error); } else if (auto *func = std::get_if(&result)) { qCInfo(lcAotCompiler) << "Generated code:" << func->code; - aotFunctionsByIndex[runtimeFunctionIndices[bindingOrFunction.index()]] = *func; + aotFunctionsByIndex[object->runtimeFunctionIndices[bindingOrFunction.index()]] = + *func; } }); } -- cgit v1.2.3