diff options
| author | Ulf Hermann <ulf.hermann@qt.io> | 2023-02-22 11:06:54 +0100 |
|---|---|---|
| committer | Ulf Hermann <ulf.hermann@qt.io> | 2023-02-23 12:25:48 +0100 |
| commit | ab9f4d2e2614d693c254a027a28824e83c7760f0 (patch) | |
| tree | ddc6e1b239d9341ef79aa996b661ccf70b843a61 /src | |
| parent | 7bf2bddd1f848237dc48dc2240c47f356596ca18 (diff) | |
QmlCompiler: Drop broken line comments in generated C++
They didn't work because the ordering of instructions is not the same as
the ordering of lines. They also weren't very helpful because a single
line may result in multiple instructions and vice versa. On top of
everything, they also introduced UB via the std::upper_bound call.
Rather, just print the name of the function and the place in the file at
the beginning of each C++ function. That is much more helpful since we
can then just correlate it to the original QML code. For
instruction-by-instruction mapping we have to consult the byte code
trace anyway.
Pick-to: 6.5 6.4 6.2
Fixes: QTBUG-111340
Change-Id: I599ce384cfaf88a7347583a55976a3b98080435d
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src')
| -rw-r--r-- | src/qmlcompiler/qqmljscodegenerator.cpp | 32 | ||||
| -rw-r--r-- | src/qmlcompiler/qqmljscodegenerator_p.h | 7 | ||||
| -rw-r--r-- | src/qmlcompiler/qqmljscompiler.cpp | 4 | ||||
| -rw-r--r-- | src/qmlcompiler/qqmljscompiler_p.h | 1 | ||||
| -rw-r--r-- | src/qmlcompiler/qqmljslintercodegen.cpp | 1 |
5 files changed, 6 insertions, 39 deletions
diff --git a/src/qmlcompiler/qqmljscodegenerator.cpp b/src/qmlcompiler/qqmljscodegenerator.cpp index 9370e002b5..c5985946f2 100644 --- a/src/qmlcompiler/qqmljscodegenerator.cpp +++ b/src/qmlcompiler/qqmljscodegenerator.cpp @@ -56,9 +56,8 @@ QString QQmlJSCodeGenerator::castTargetName(const QQmlJSScope::ConstPtr &type) c QQmlJSCodeGenerator::QQmlJSCodeGenerator(const QV4::Compiler::Context *compilerContext, const QV4::Compiler::JSUnitGenerator *unitGenerator, const QQmlJSTypeResolver *typeResolver, - QQmlJSLogger *logger, const QStringList &sourceCodeLines) + QQmlJSLogger *logger) : QQmlJSCompilePass(unitGenerator, typeResolver, logger) - , m_sourceCodeLines(sourceCodeLines) , m_context(compilerContext) {} @@ -141,6 +140,9 @@ QT_WARNING_POP QQmlJSAotFunction result; result.includes.swap(m_includes); + result.code += u"// %1 at line %2, column %3\n"_s + .arg(m_context->name).arg(m_context->line).arg(m_context->column); + QDuplicateTracker<QString> generatedVariables; for (auto registerIt = m_registerVariables.cbegin(), registerEnd = m_registerVariables.cend(); registerIt != registerEnd; ++registerIt) { @@ -2585,17 +2587,6 @@ QV4::Moth::ByteCodeHandler::Verdict QQmlJSCodeGenerator::startInstruction( || !m_state.accumulatorVariableOut.isEmpty() || !isTypeStorable(m_typeResolver, m_state.changedRegister().storedType())); - const int currentLine = currentSourceLocation().startLine; - if (currentLine != m_lastLineNumberUsed) { - const int nextLine = nextJSLine(currentLine); - for (auto line = currentLine - 1; line < nextLine - 1; ++line) { - m_body += u"// "_s; - m_body += m_sourceCodeLines.value(line).trimmed(); - m_body += u'\n'; - } - m_lastLineNumberUsed = currentLine; - } - // If the instruction has no side effects and doesn't write any register, it's dead. // We might still need the label, though, and the source code comment. if (!m_state.hasSideEffects() && changedRegisterVariable().isEmpty()) @@ -3193,21 +3184,6 @@ QString QQmlJSCodeGenerator::conversion(const QQmlJSScope::ConstPtr &from, return QString(); } -int QQmlJSCodeGenerator::nextJSLine(uint line) const -{ - auto findLine = [](int line, const QV4::CompiledData::CodeOffsetToLineAndStatement &entry) { - return entry.line > line; - }; - const auto codeToLine - = std::upper_bound(m_context->lineAndStatementNumberMapping.constBegin(), - m_context->lineAndStatementNumberMapping.constEnd(), - line, - findLine); - bool bNoNextLine = m_context->lineAndStatementNumberMapping.constEnd() == codeToLine; - - return static_cast<int>(bNoNextLine ? -1 : codeToLine->line); -} - void QQmlJSCodeGenerator::reject(const QString &thing) { setError(u"Cannot generate efficient code for %1"_s.arg(thing)); diff --git a/src/qmlcompiler/qqmljscodegenerator_p.h b/src/qmlcompiler/qqmljscodegenerator_p.h index 4719764294..4a7e1dc1dc 100644 --- a/src/qmlcompiler/qqmljscodegenerator_p.h +++ b/src/qmlcompiler/qqmljscodegenerator_p.h @@ -33,7 +33,7 @@ public: QQmlJSCodeGenerator(const QV4::Compiler::Context *compilerContext, const QV4::Compiler::JSUnitGenerator *unitGenerator, const QQmlJSTypeResolver *typeResolver, - QQmlJSLogger *logger, const QStringList &sourceCodeLines); + QQmlJSLogger *logger); ~QQmlJSCodeGenerator() = default; QQmlJSAotFunction run(const Function *function, const InstructionAnnotations *annotations, @@ -288,17 +288,12 @@ private: return m_typeResolver->jsGlobalObject()->property(u"console"_s).type(); } - int nextJSLine(uint line) const; - - QStringList m_sourceCodeLines; - // map from instruction offset to sequential label number QHash<int, QString> m_labels; const QV4::Compiler::Context *m_context = nullptr; const InstructionAnnotations *m_annotations = nullptr; - int m_lastLineNumberUsed = -1; bool m_skipUntilNextLabel = false; QStringList m_includes; diff --git a/src/qmlcompiler/qqmljscompiler.cpp b/src/qmlcompiler/qqmljscompiler.cpp index 964c01c1a2..700bdb0d50 100644 --- a/src/qmlcompiler/qqmljscompiler.cpp +++ b/src/qmlcompiler/qqmljscompiler.cpp @@ -650,7 +650,6 @@ void QQmlJSAotCompiler::setDocument( m_logger->setFileName(resourcePathInfo.fileName()); m_logger->setCode(irDocument->code); m_unitGenerator = &irDocument->jsGenerator; - m_entireSourceCodeLines = irDocument->code.split(u'\n'); QQmlJSScope::Ptr target = QQmlJSScope::create(); QQmlJSImportVisitor visitor(target, m_importer, m_logger, resourcePathInfo.canonicalPath() + u'/', @@ -796,8 +795,7 @@ QQmlJSAotFunction QQmlJSAotCompiler::doCompile( return compileError(); QQmlJSCodeGenerator codegen( - context, m_unitGenerator, &m_typeResolver, m_logger, - m_entireSourceCodeLines); + context, m_unitGenerator, &m_typeResolver, m_logger); QQmlJSAotFunction result = codegen.run(function, &typePropagationResult, error); return error->isValid() ? compileError() : result; } diff --git a/src/qmlcompiler/qqmljscompiler_p.h b/src/qmlcompiler/qqmljscompiler_p.h index 3483226a09..9f6afe0fc5 100644 --- a/src/qmlcompiler/qqmljscompiler_p.h +++ b/src/qmlcompiler/qqmljscompiler_p.h @@ -76,7 +76,6 @@ protected: const QString &message, QtMsgType type, const QQmlJS::SourceLocation &location) const; QQmlJSTypeResolver m_typeResolver; - QStringList m_entireSourceCodeLines; const QString m_resourcePath; const QStringList m_qmldirFiles; diff --git a/src/qmlcompiler/qqmljslintercodegen.cpp b/src/qmlcompiler/qqmljslintercodegen.cpp index f22059fc39..2b79e34efa 100644 --- a/src/qmlcompiler/qqmljslintercodegen.cpp +++ b/src/qmlcompiler/qqmljslintercodegen.cpp @@ -27,7 +27,6 @@ void QQmlJSLinterCodegen::setDocument(const QmlIR::JSCodeGen *codegen, Q_UNUSED(codegen); m_document = document; m_unitGenerator = &document->jsGenerator; - m_entireSourceCodeLines = document->code.split(u'\n'); } std::variant<QQmlJSAotFunction, QQmlJS::DiagnosticMessage> |
