diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2022-02-21 17:35:44 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2022-03-03 18:44:21 +0100 |
commit | 4679710f4d9d44605fa55022d8d6d2fd19d7176a (patch) | |
tree | a305eacf6eaa34488af181b89f364eaf1027cc22 | |
parent | 8dd7201994c41a5adb8f26a43509fd0dab031bf7 (diff) |
QmlCompiler: Store arguments as QQmlJSRegisterContent
This way we can uniquely track the stored types throughout the
compilation.
Change-Id: Ibf3814a37f105c2eede2a08f547ab5fbfa1c16e2
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r-- | src/qmlcompiler/qqmljscodegenerator.cpp | 16 | ||||
-rw-r--r-- | src/qmlcompiler/qqmljscompilepass_p.h | 7 | ||||
-rw-r--r-- | src/qmlcompiler/qqmljsfunctioninitializer.cpp | 12 | ||||
-rw-r--r-- | src/qmlcompiler/qqmljsshadowcheck.cpp | 2 | ||||
-rw-r--r-- | src/qmlcompiler/qqmljsstoragegeneralizer.cpp | 17 | ||||
-rw-r--r-- | src/qmlcompiler/qqmljstypepropagator.cpp | 2 |
6 files changed, 25 insertions, 31 deletions
diff --git a/src/qmlcompiler/qqmljscodegenerator.cpp b/src/qmlcompiler/qqmljscodegenerator.cpp index 1eacfdc25a..874f0918bd 100644 --- a/src/qmlcompiler/qqmljscodegenerator.cpp +++ b/src/qmlcompiler/qqmljscodegenerator.cpp @@ -146,7 +146,7 @@ QT_WARNING_POP for (const auto loopLabel : m_context->labelInfo) m_labels.insert(loopLabel, u"label_%1"_qs.arg(m_labels.count())); - m_state.State::operator=(initialState(function, m_typeResolver)); + m_state.State::operator=(initialState(function)); const QByteArray byteCode = function->code; decode(byteCode.constData(), static_cast<uint>(byteCode.length())); eliminateDeadStores(); @@ -179,9 +179,9 @@ QT_WARNING_POP for (const Section §ion : m_sections) result.code += section.code(); - for (const QQmlJSScope::ConstPtr &argType : qAsConst(function->argumentTypes)) { - if (argType) { - result.argumentTypes.append(argType->augmentedInternalName()); + for (const QQmlJSRegisterContent &argType : qAsConst(function->argumentTypes)) { + if (argType.isValid()) { + result.argumentTypes.append(argType.storedType()->augmentedInternalName()); } else { result.argumentTypes.append(u"void"_qs); } @@ -2578,7 +2578,7 @@ QString QQmlJSCodeGenerator::registerVariable(int index) const if (index >= QV4::CallData::OffsetCount && index < firstRegisterIndex()) { const int argumentIndex = index - QV4::CallData::OffsetCount; return u"*static_cast<"_qs - + castTargetName(m_function->argumentTypes[argumentIndex]) + + castTargetName(m_function->argumentTypes[argumentIndex].storedType()) + u"*>(argumentsPtr["_qs + QString::number(argumentIndex) + u"])"_qs; } return m_registerVariables.value(index).value(registerType(index).storedType()); @@ -2592,10 +2592,8 @@ QString QQmlJSCodeGenerator::changedRegisterVariable() const QQmlJSRegisterContent QQmlJSCodeGenerator::registerType(int index) const { - if (index >= QV4::CallData::OffsetCount && index < firstRegisterIndex()) { - return m_typeResolver->globalType( - m_function->argumentTypes[index - QV4::CallData::OffsetCount]); - } + if (index >= QV4::CallData::OffsetCount && index < firstRegisterIndex()) + return m_function->argumentTypes[index - QV4::CallData::OffsetCount]; return m_state.registers[index]; } diff --git a/src/qmlcompiler/qqmljscompilepass_p.h b/src/qmlcompiler/qqmljscompilepass_p.h index 97ec018ae6..af5c9204e6 100644 --- a/src/qmlcompiler/qqmljscompilepass_p.h +++ b/src/qmlcompiler/qqmljscompilepass_p.h @@ -84,7 +84,7 @@ public: struct Function { QQmlJSScopesById addressableScopes; - QList<QQmlJSScope::ConstPtr> argumentTypes; + QList<QQmlJSRegisterContent> argumentTypes; QQmlJSScope::ConstPtr returnType; QQmlJSScope::ConstPtr qmlScope; QByteArray code; @@ -187,12 +187,11 @@ protected: const Function *m_function = nullptr; QQmlJS::DiagnosticMessage *m_error = nullptr; - State initialState(const Function *function, const QQmlJSTypeResolver *resolver) + State initialState(const Function *function) { State state; for (int i = 0; i < function->argumentTypes.count(); ++i) { - state.registers[FirstArgument + i] - = resolver->globalType(function->argumentTypes.at(i)); + state.registers[FirstArgument + i] = function->argumentTypes.at(i); Q_ASSERT(state.registers[FirstArgument + i].isValid()); } return state; diff --git a/src/qmlcompiler/qqmljsfunctioninitializer.cpp b/src/qmlcompiler/qqmljsfunctioninitializer.cpp index 77f2894b91..c993197399 100644 --- a/src/qmlcompiler/qqmljsfunctioninitializer.cpp +++ b/src/qmlcompiler/qqmljsfunctioninitializer.cpp @@ -92,16 +92,20 @@ void QQmlJSFunctionInitializer::populateSignature( for (const QQmlJS::AST::BoundName &argument : qAsConst(arguments)) { if (argument.typeAnnotation) { if (const auto type = m_typeResolver->typeFromAST(argument.typeAnnotation->type)) { - function->argumentTypes.append(m_typeResolver->trackedType(type)); + function->argumentTypes.append( + m_typeResolver->tracked( + m_typeResolver->globalType(type))); } else { function->argumentTypes.append( - m_typeResolver->trackedType(m_typeResolver->varType())); + m_typeResolver->tracked( + m_typeResolver->globalType(m_typeResolver->varType()))); signatureError(u"Cannot resolve the argument type %1."_qs .arg(argument.typeAnnotation->type->toString())); } } else { - function->argumentTypes.append(m_typeResolver->trackedType( - m_typeResolver->varType())); + function->argumentTypes.append( + m_typeResolver->tracked( + m_typeResolver->globalType(m_typeResolver->varType()))); signatureError(u"Functions without type annotations won't be compiled"_qs); } } diff --git a/src/qmlcompiler/qqmljsshadowcheck.cpp b/src/qmlcompiler/qqmljsshadowcheck.cpp index bdcad2a21e..79f197750c 100644 --- a/src/qmlcompiler/qqmljsshadowcheck.cpp +++ b/src/qmlcompiler/qqmljsshadowcheck.cpp @@ -58,7 +58,7 @@ void QQmlJSShadowCheck::run( m_annotations = annotations; m_function = function; m_error = error; - m_state = initialState(function, m_typeResolver); + m_state = initialState(function); decode(m_function->code.constData(), static_cast<uint>(m_function->code.length())); } diff --git a/src/qmlcompiler/qqmljsstoragegeneralizer.cpp b/src/qmlcompiler/qqmljsstoragegeneralizer.cpp index 9af98eed85..889150f2dd 100644 --- a/src/qmlcompiler/qqmljsstoragegeneralizer.cpp +++ b/src/qmlcompiler/qqmljsstoragegeneralizer.cpp @@ -61,18 +61,6 @@ QQmlJSCompilePass::InstructionAnnotations QQmlJSStorageGeneralizer::run( } } - for (QQmlJSScope::ConstPtr &argument : function->argumentTypes) { - Q_ASSERT(argument); - if (QQmlJSScope::ConstPtr stored = m_typeResolver->genericType( - argument, QQmlJSTypeResolver::ComponentIsGeneric::Yes)) { - argument = std::move(stored); - } else { - setError(QStringLiteral("Cannot store the argument type %1.") - .arg(argument->internalName(), 0)); - return InstructionAnnotations(); - } - } - const auto transformRegister = [&](QQmlJSRegisterContent &content, int offset) { if (QQmlJSScope::ConstPtr specific = content.storedType()) { if (QQmlJSScope::ConstPtr generic = m_typeResolver->genericType(specific)) { @@ -95,6 +83,11 @@ QQmlJSCompilePass::InstructionAnnotations QQmlJSStorageGeneralizer::run( return true; }; + for (QQmlJSRegisterContent &argument : function->argumentTypes) { + Q_ASSERT(argument.isValid()); + transformRegister(argument, 0); + } + for (auto i = annotations.begin(), iEnd = annotations.end(); i != iEnd; ++i) { if (!transformRegister(i->second.changedRegister, i.key())) return InstructionAnnotations(); diff --git a/src/qmlcompiler/qqmljstypepropagator.cpp b/src/qmlcompiler/qqmljstypepropagator.cpp index fb7c40cf7a..2760f3401b 100644 --- a/src/qmlcompiler/qqmljstypepropagator.cpp +++ b/src/qmlcompiler/qqmljstypepropagator.cpp @@ -66,7 +66,7 @@ QQmlJSCompilePass::InstructionAnnotations QQmlJSTypePropagator::run( m_prevStateAnnotations = m_state.annotations; m_state = PassState(); - m_state.State::operator=(initialState(m_function, m_typeResolver)); + m_state.State::operator=(initialState(m_function)); reset(); decode(m_function->code.constData(), static_cast<uint>(m_function->code.length())); |