summaryrefslogtreecommitdiff
path: root/src/qmlcompiler/qqmljscompiler.cpp
diff options
context:
space:
mode:
authorAndrei Golubev <andrei.golubev@qt.io>2022-07-01 13:51:12 +0200
committerAndrei Golubev <andrei.golubev@qt.io>2022-07-22 16:38:42 +0200
commit8d0adee3b3317f1fab03742bdf0f7cdbe57df914 (patch)
tree6c51c5ffb0c0542fb4f4db4bd7fcd2eaa59db4c4 /src/qmlcompiler/qqmljscompiler.cpp
parent76d992431e113c3df9b6f879e2889973d5093a44 (diff)
downloadqtdeclarative-8d0adee3b3317f1fab03742bdf0f7cdbe57df914.tar.gz
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) Change-Id: I4070b9d061f03c4c76d03120654ad3f30725493a Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qmlcompiler/qqmljscompiler.cpp')
-rw-r--r--src/qmlcompiler/qqmljscompiler.cpp21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/qmlcompiler/qqmljscompiler.cpp b/src/qmlcompiler/qqmljscompiler.cpp
index bba2aeb310..a3c78f2fbc 100644
--- a/src/qmlcompiler/qqmljscompiler.cpp
+++ b/src/qmlcompiler/qqmljscompiler.cpp
@@ -230,19 +230,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<QmlIR::CompiledFunctionOrExpression> functionsToCompile;
- for (QmlIR::CompiledFunctionOrExpression *foe = object->functionsAndExpressions->first; foe; foe = foe->next)
- functionsToCompile << *foe;
- const QVector<int> 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;
@@ -263,6 +257,12 @@ bool qCompileQmlFile(QmlIR::Document &irDocument, const QString &inputFileName,
std::copy(object->functionsBegin(), object->functionsEnd(),
std::back_inserter(bindingsAndFunctions));
+ QList<QmlIR::CompiledFunctionOrExpression> 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
auto contextMap = v4CodeGen.module()->contextMap;
@@ -345,7 +345,8 @@ bool qCompileQmlFile(QmlIR::Document &irDocument, const QString &inputFileName,
<< diagnosticErrorMessage(inputFileName, *error);
} else if (auto *func = std::get_if<QQmlJSAotFunction>(&result)) {
qCDebug(lcAotCompiler) << "Generated code:" << func->code;
- aotFunctionsByIndex[runtimeFunctionIndices[bindingOrFunction.index()]] = *func;
+ aotFunctionsByIndex[object->runtimeFunctionIndices[bindingOrFunction.index()]] =
+ *func;
}
});
}