From 46396070368568d44597a36b7c7646f139d92b23 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 27 Jun 2022 16:26:43 +0200 Subject: QmlCompiler: Really fix writing into argument values Arguments are now treated as registers "written" at the beginning of the first basic block. By modeling them this way, we can avoid all the complicated logic on whether to use a local or the arguments array when accessing any particular one of them. Furthermore, we can detect whether they are overwritten or not. If they are not overwritten, we can initialize them as a const reference into the arguments array. This way we save a copy. Treating the arguments as generic registers causes the basic blocks pass to aggressively adjust their types, pushing some conversions back into the QML engine. This is good. Unused arguments become void, for example, and don't have to be passed at all. However, we also need a special case for QJSPrimitiveValue arguments now. Pick-to: 6.4 Fixes: QTBUG-104462 Change-Id: I994bea0929bd508aa41db58dee4a7f12cd20f053 Reviewed-by: Fabian Kosmale Reviewed-by: Sami Shalayel --- .../qml/qmlcppcodegen/data/javaScriptArgument.qml | 82 ++++++++++++++++++++++ 1 file changed, 82 insertions(+) (limited to 'tests/auto/qml/qmlcppcodegen/data/javaScriptArgument.qml') diff --git a/tests/auto/qml/qmlcppcodegen/data/javaScriptArgument.qml b/tests/auto/qml/qmlcppcodegen/data/javaScriptArgument.qml index 870540240e..058a2ad574 100644 --- a/tests/auto/qml/qmlcppcodegen/data/javaScriptArgument.qml +++ b/tests/auto/qml/qmlcppcodegen/data/javaScriptArgument.qml @@ -31,4 +31,86 @@ QtObject { property string c: stringMinusOne(-5) property string d: stringMinusOne(10) + + function printAmount(amount: real) : string { + var sign; + if (amount < 0) { + sign = "-"; + amount = -amount; + } else { + sign = ""; + } + return sign + amount; + } + + property string e: printAmount(10); + property string f: printAmount(-10); + + readonly property string units: " kMGT" + + function roundTo3Digits(number: real) : real { + var factor; + + if (number < 10) + factor = 100; + else if (number < 100) + factor = 10; + else + factor = 1; + + return Math.round(number * factor) / factor; + } + + function prettyPrintScale(amount: real) : string { + var sign; + if (amount < 0) { + sign = "-"; + amount = -amount; + } else { + sign = ""; + } + var unitOffset = 0; + var unitAmount = 1; + for (unitOffset = 0; amount > unitAmount * 1024; ++unitOffset, unitAmount *= 1024) {} + var result = amount / unitAmount; + return sign + roundTo3Digits(result) + units[unitOffset]; + } + + property list scales: [ + prettyPrintScale(0), + + prettyPrintScale(1), + prettyPrintScale(10), + prettyPrintScale(100), + prettyPrintScale(1000), + prettyPrintScale(10000), + prettyPrintScale(100000), + prettyPrintScale(1000000), + prettyPrintScale(10000000), + prettyPrintScale(100000000), + prettyPrintScale(1000000000), + prettyPrintScale(10000000000), + prettyPrintScale(100000000000), + prettyPrintScale(1000000000000), + prettyPrintScale(10000000000000), + + prettyPrintScale(-1), + prettyPrintScale(-10), + prettyPrintScale(-100), + prettyPrintScale(-1000), + prettyPrintScale(-10000), + prettyPrintScale(-100000), + prettyPrintScale(-1000000), + prettyPrintScale(-10000000), + prettyPrintScale(-100000000), + prettyPrintScale(-1000000000), + prettyPrintScale(-10000000000), + prettyPrintScale(-100000000000), + prettyPrintScale(-1000000000000), + prettyPrintScale(-10000000000000), + ] + + function forwardArg(a: real) : string { + return prettyPrintScale(a); + } } -- cgit v1.2.3