diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2021-11-16 15:45:14 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2021-11-26 11:57:52 +0100 |
commit | cb3ec010fff39a9b5b35b1afb3af478cf118c3ca (patch) | |
tree | 4934ef3eb31bcc8f5806e7b1be06e7508b7948e3 /src/qmllint | |
parent | ab4a4be2ed10fbb04015da01811d9be6b003ec17 (diff) |
QmlCompiler: Move type generalization into separate compile pass
We want to be able to skip it.
Task-number: QTBUG-98305
Change-Id: Ibb0293d348f2828a28be4c458cf955b4cc706caa
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qmllint')
-rw-r--r-- | src/qmllint/codegen.cpp | 30 | ||||
-rw-r--r-- | src/qmllint/qqmllinter.cpp | 3 |
2 files changed, 13 insertions, 20 deletions
diff --git a/src/qmllint/codegen.cpp b/src/qmllint/codegen.cpp index a4908ba1b9..dc961f85e0 100644 --- a/src/qmllint/codegen.cpp +++ b/src/qmllint/codegen.cpp @@ -30,6 +30,7 @@ #include <QtQmlCompiler/private/qqmljsimportvisitor_p.h> #include <QtQmlCompiler/private/qqmljsshadowcheck_p.h> +#include <QtQmlCompiler/private/qqmljsstoragegeneralizer_p.h> #include <QtQmlCompiler/private/qqmljstypepropagator_p.h> #include <QFileInfo> @@ -263,24 +264,18 @@ bool Codegen::generateFunction(QV4::Compiler::ContextType contextType, if (function->argumentTypes.isEmpty()) { for (const QQmlJS::AST::BoundName &argument : qAsConst(arguments)) { if (argument.typeAnnotation) { - const auto rawType = m_typeResolver->typeFromAST(argument.typeAnnotation->type); - if (m_typeResolver->storedType(rawType, - QQmlJSTypeResolver::ComponentIsGeneric::Yes)) { - function->argumentTypes.append(rawType); - continue; + if (const auto type = m_typeResolver->typeFromAST(argument.typeAnnotation->type)) { + function->argumentTypes.append(type); } else { - return fail(QStringLiteral("Cannot store the argument type %1.") - .arg(rawType ? rawType->internalName() : u"<unknown>"_qs)); + return fail(QStringLiteral("Cannot resolve argument type %1") + .arg(argument.typeAnnotation->type->toString())); } } else { return fail(QStringLiteral("Functions without type annotations won't be compiled")); - return false; } } } - QQmlJSTypePropagator propagator(m_unitGenerator, m_typeResolver.get(), m_logger, m_typeInfo); - if (!function->returnType) { if (ast->typeAnnotation) { function->returnType = m_typeResolver->typeFromAST(ast->typeAnnotation->type); @@ -289,25 +284,24 @@ bool Codegen::generateFunction(QV4::Compiler::ContextType contextType, } } - if (function->returnType) { - if (!m_typeResolver->storedType(function->returnType, - QQmlJSTypeResolver::ComponentIsGeneric::Yes)) { - return fail(QStringLiteral("Cannot store the return type %1.") - .arg(function->returnType->internalName())); - } - } - function->isSignalHandler = !function->returnType && contextType == QV4::Compiler::ContextType::Binding; function->addressableScopes = m_typeResolver->objectsById(); function->code = context->code; function->sourceLocations = context->sourceLocationTable.get(); + QQmlJSTypePropagator propagator(m_unitGenerator, m_typeResolver.get(), m_logger, m_typeInfo); QQmlJSCompilePass::InstructionAnnotations annotations = propagator.run(function, error); if (!error->isValid()) { QQmlJSShadowCheck shadowCheck(m_unitGenerator, m_typeResolver.get(), m_logger); shadowCheck.run(&annotations, function, error); } + + if (!error->isValid()) { + QQmlJSStorageGeneralizer generalizer(m_unitGenerator, m_typeResolver.get(), m_logger); + generalizer.run(annotations, function, error); + } + if (error->isValid()) { error->type = context->returnsClosure ? QtDebugMsg : QtWarningMsg; return false; diff --git a/src/qmllint/qqmllinter.cpp b/src/qmllint/qqmllinter.cpp index a6fa6b8101..c8b5d09735 100644 --- a/src/qmllint/qqmllinter.cpp +++ b/src/qmllint/qqmllinter.cpp @@ -185,8 +185,7 @@ bool QQmlLinter::lintFile(const QString &filename, const QString *fileContents, } std::unique_ptr<QQmlJSTypeResolver> typeResolver - = std::make_unique<QQmlJSTypeResolver>( - &m_importer, QQmlJSTypeResolver::TypeStorage::Indirect, m_logger.get()); + = std::make_unique<QQmlJSTypeResolver>(&m_importer, m_logger.get()); // Type resolving is using document parent mode here so that it produces fewer false positives // on the "parent" property of QQuickItem. It does produce a few false negatives this way |