Commit Graph

114 Commits

Author SHA1 Message Date
Ulf Hermann 38fdf2717d QmlCompiler: Handle trivial signal handler constructions
If the signal handler does nothing but return a closure, we have to
compile the closure using the same signature as the outer signal
handler.

In order for this to work, we also have to detect unresolved argument
types for signal handlers. Those are just as bad as unresolved argument
types for other functions.

Fixes: QTBUG-101531
Change-Id: Idb5b3994809d91a4b4ce936282685435eb75e670
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-07-07 19:33:39 +02:00
Ulf Hermann 3f3e961a5a QmlCompiler: Allow wrapping enums into int
This is what we do internally in the QML engine.

Pick-to: 6.4
Fixes: QTBUG-104683
Change-Id: I2f8712cb2cdc56b6c483500627fd8a218edbad81
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-07-07 19:33:27 +02:00
Ulf Hermann 8dc33d3672 QmlCompiler: Don't crash on unknown list value types
Pick-to: 6.4
Fixes: QTBUG-104743
Change-Id: I551b21498bb746acf05be525dbcb72a74f816c04
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-07-06 21:28:05 +02:00
Ulf Hermann 8056df3284 QML: Re-add the Qt namespace enums to the Qt object
They were replaced with an extension to the Qt singleton in Qt6.
However, the singleton is only available when QtQml is imported.
We can easily provide the enums using the metaobject of the Qt
namespace.

Pick-to: 6.4
Change-Id: I5f58d30c749c0cb9e531df180a5cbe75c92e1aa6
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
2022-07-05 23:29:37 +02:00
Ulf Hermann af335a89bd QmlCompiler: Initialize registers with undefined where necessary
If we read the initial state of a register, we need to make sure it
actually exists at that point. Uninitialized variables are implicitly
undefined in JavaScript.

Pick-to: 6.4
Task-number: QTBUG-104687
Change-Id: Ide4fe429b10ec28dcf267e7d34c6316355b16baa
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-07-05 19:50:28 +02:00
Ulf Hermann 7d36ec0bd9 QmlCompiler: Don't push type conversions back into the engine
In many cases we can generate better code for type conversions.
Furthermore, the engine only does QMetaType::convert(). This misses a
lot of conversions we do in other places.

Pick-to: 6.4
Change-Id: I1526ec327d189420885f6a7385f6cc1c2c94b19e
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-07-05 19:50:24 +02:00
Ulf Hermann 4639607036 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 <fabian.kosmale@qt.io>
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
2022-07-05 19:50:19 +02:00
Ulf Hermann 5e4a1738b0 QmlCompiler: Fix register propagation in basic blocks pass
a, We were recording too many jump origins and targets. That messed up
   the basic blocks ordering logic.
b, In the presence of backward jumps, we need to revisit earlier basic
   blocks if additional writes are discovered. Otherwise the type
   adjustment will optimize "dead" type conversions out.

Pick-to: 6.4
Fixes: QTBUG-104665
Change-Id: I7219f85625761817ae4f63582d80d247a85df73b
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-07-05 19:50:15 +02:00
Ulf Hermann 0e3d42c840 QmlCompiler: Don't generate invalid code for storing undefined
We don't actually have to store the retrieved value if it's not
storable.

Pick-to: 6.4
Fixes: QTBUG-104508
Change-Id: Ib091eabf4f4034a577b94e0d5761c5307815599e
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-06-29 13:26:07 +02:00
Ulf Hermann 7230508c3b QmlCompiler: Add missing parentheses to in-place arithmetic operations
Pick-to: 6.4
Fixes: QTBUG-104512
Change-Id: I3d592eeda5cefd9e9805b1811b37bebec5d6fc9c
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-06-28 01:52:43 +02:00
Ulf Hermann a864561468 QmlCompiler: Inline String.arg() into generated code
This way we can compile common translation expressions with .arg(a).

Task-number: QTBUG-101387
Change-Id: I89cdef48b63886684569c5b587ea69c937085b62
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-06-24 22:17:17 +02:00
Ulf Hermann 23fdccf7f3 QmlCompiler: Inline translation methods
We hardcode them into QQmlJSTypePropagator and QQmlJSCodegenerator for
now. This is OK for builtins.

Task-number: QTBUG-101387
Change-Id: Ifab46083b3a782f009859ce969c283d5bb2b4e8b
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-06-24 14:47:58 +02:00
Ulf Hermann 6aad465f08 Introduce a sane resource path to qt_add_qml_module
Since "/qt" is reserved, we can use "/qt/qml" as the default path for
user QML modules.

[ChangeLog][QtQml] The AUTO_RESOURCE_PREFIX option was added to
qt_add_qml_module(). It places your QML modules in the otherwise
reserved resource directory /qt/qml. This directory is also added to the
default QML import path. By using it you don't have to specify custom
import paths anymore. Specifying neither AUTO_RESOURCE_PREFIX nor an
explicit RESOURCE_PREFIX will generate a warning now because such QML
modules are likely invisible in the resource file system.

Fixes: QTBUG-95145
Fixes: QTBUG-103452
Change-Id: Ie27dec5cbf34ea06258d55c659d202cdd61e54b2
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
2022-06-23 09:35:57 +02:00
Ulf Hermann 6a0ab2e8aa QmlCompiler: Fix miscompilation if arguments are overwritten
In that case we need to allocate extra registers. We already did so
before, but we wouldn't use the registers afterwards.

This works nicely in 6.4 because we have a separate type for each store
operation. Therefore, the original function argument (being of a
different "type") won't be found in the list of local registers. Access
to it falls back on the actual arguments array. Only once we've stored
something into the register that mirrors the argument we can retrieve
it.

Pick-to: 6.4
Fixes: QTBUG-104462
Change-Id: Ibb0315cd2f8a8e4106d39fff88a6097b1623eb48
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-06-23 09:35:57 +02:00
Ulf Hermann 87f9847144 QmlCompiler: Properly annotate ThrowException instruction
It doesn't write the accumulator, but it does read it. Generating code
for throwing exceptions reveals that we have to default-construct the
return type rather than converting from undefined/void when throwing an
exception.

Pick-to: 6.2 6.3 6.4
Fixes: QTBUG-104447
Change-Id: I0a725679d8ecb7e87bb20528033097bc0c3c7bb6
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-06-23 09:35:56 +02:00
Ulf Hermann e18919d3f2 QmlCompiler: Check builtin type aliases after list resolution
This way we can determine that QList<qreal> is the same as
QList<double>.

Pick-to: 6.4
Fixes: QTBUG-104129
Change-Id: I96df19da1a613558b950aa6cee46159024c19cc9
Reviewed-by: Evgeniy Dushistov <dushistov@mail.ru>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
2022-06-15 09:43:01 +02:00
Ulf Hermann fb3a81623a QmlCompiler: Reject conversions via QJSValue
Those are generally less efficient than what the interpreter would do,
they can have side effects, and they can throw exceptions. We don't want
to deal with any of that. Most of those implicit conversions have
explicit equivalents. For those that don't we can add them.

Pick-to: 6.2 6.4
Fixes: QTBUG-104010
Change-Id: I62898db92219386c94f2a6c9b56f6fb0b7578832
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
2022-06-15 09:43:01 +02:00
Lucie Gérard 0dc4fd240a Use SPDX license identifiers
Replace the current license disclaimer in files by
a SPDX-License-Identifier.
Files that have to be modified by hand are modified.
License files are organized under LICENSES directory.

Pick-to: 6.4
Task-number: QTBUG-67283
Change-Id: I63563bbeb6f60f89d2c99660400dca7fab78a294
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2022-06-11 08:05:15 +02:00
Ulf Hermann 2a4ec96ae0 QmlCompiler: Don't retrieve metaobjects for value and sequence types
This is not valid QML, and the generated code crashes.

Pick-to: 6.2 6.4
Fixes: QTBUG-104092
Change-Id: If609acc2f2dc84a2e8f7c26d4d1b6c626f337cad
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
2022-06-10 14:41:49 +02:00
Ulf Hermann 8e69558f2f qmltyperegistrar: Parse value type lists
We need to generate isList properties for those, so that qmlcachegen and
qmllint can handle them.

Pick-to: 6.4
Fixes: QTBUG-104129
Change-Id: I7e632279a605694c2fd5f583c8a6dcf9968eb634
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
2022-06-10 14:41:32 +02:00
Ulf Hermann 8ea9646019 QmlCompiler: Don't crash when trying to resolve null list types
If the element type is unknown the list type is also unknown. This will
happen if we cannot resolve the type.

Fixes: QTBUG-103920
Change-Id: If1b05d99a1e64961981b5adb3974a51c11e776d2
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-06-02 10:07:40 +02:00
Ulf Hermann 6ff6c088c2 QmlCompiler: Add support for LoadElement on strings
In JavaScript the [] operator on strings returns a string. QString's
operator[] returns a QChar, but we can easily create a string from that.

Fixes: QTBUG-103371
Change-Id: Id5c960f00ecc7a5dfe30ccbcaac3ffb2a30308b9
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-05-24 15:44:16 +02:00
Ulf Hermann a75ddda71b QmlCompiler: Implement LoadElement for value type lists
Instead of the storedType hack in the type resolver, properly declare
the type LoadElement can return: A merge of undefined and the actual
type. This way we can choose the best concrete type to use for this
independently (and optimize it later).

Task-number: QTBUG-103529
Change-Id: I17b1f835f6a893ec843a90491e92f72ecb2e87fe
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-05-24 15:44:16 +02:00
Ulf Hermann 4d71091a19 qmlcompiler: Evaluate pragma ComponentBehavior
If components are bound we can assume the IDs of outer components are
reachable.

Fixes: QTBUG-102806
Fixes: QTBUG-101012
Change-Id: Ia26d3963d6c2fb9698debb12f9c655c5522f81ea
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-05-24 15:44:16 +02:00
Ulf Hermann 4a10e1d84a QmlCompiler: Detect non-integral values when accessing QQmlListProperty
Pick-to: 6.2 6.3
Fixes: QTBUG-103560
Change-Id: Ifcc73baf7f79e30f6e83ff3e500dd39f95790bfe
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
2022-05-19 22:30:23 +02:00
Ulf Hermann 70da741404 QmlCompiler: Do not coerce value type lists to QQmlListProperty
QQmlListProperty is only for object lists. Object lists are the only
thing we can use in LoadElement for now.

Fixes: QTBUG-103529
Change-Id: Ia120addcfc0afcbf1815d1bd9671f20df8334744
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
2022-05-18 19:40:58 +02:00
Andreas Buhr bdbab58de7 Skip crashing test in tst_qmlcppcodegen on Android
tst_QmlCppCodegen::scopeObjectDestruction() crashes on Android.
Skip this test for now.

Pick-to: 6.2 6.3
Task-number: QTBUG-103044
Task-number: QTBUG-101865
Change-Id: I1d6291decf946b954bffc2378255c209126106fd
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
2022-05-03 15:25:11 +02:00
Sona Kurazyan 2c9c1590e6 Replace uses of deprecated _qs with _s/QStringLiteral
Task-number: QTBUG-101408
Change-Id: Ic925751b73f52d8fa5add5cacc52d6dd6ea2dc27
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-04-29 09:47:43 +02:00
Ulf Hermann c751647430 QmlCompiler: Add test case for descriptive name of invalid type
Task-number: QTBUG-102147
Fixes: QTBUG-102968
Change-Id: Ifa6ab7490ed914f08da19b6928aeb1b105c448e5
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-04-28 22:50:25 +00:00
Ulf Hermann 4ab857c37b QmlCompile: Double-check types before generating lookups
In case of incomplete type information, we can get QJSValue as output
type where we expect QObject*. We cannot generate any sensible code for
that.

Change-Id: If817de7dca3b5b0b58aff92dec2dd12a7c10d250
Pick-to: 6.2 6.3
Fixes: QTBUG-102554
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-04-25 08:44:43 +02:00
Ulf Hermann ec79af7396 DelegateModel: Use actual bindings for required properties
Tracking the change signals is brittle and error prone. We have bindings
for this case. Let's use them. We can construct a synthetic
QV4::Function that contains its own QQmlJSAotFunction. In order to pass
the property index to the function we generalize the "index" property of
QQmlJSAotFunction to contain any extra data the function may want to
use. If there is no compilation unit, we pass that instead.

Fixes: QTBUG-91649
Change-Id: I0758bcc4964a48c6818d18bfb0972e67dbc16a1f
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-04-11 14:12:09 +02:00
Ulf Hermann 8a229c38fb QmlCompiler: Analyze type conversions before reads in basic blocks
The type conversions happen before the value is read. Therefore, we need
to record them in this order. Otherwise, we may lose a type conversion
if the instruction writes the same register as it reads.

Fixes: QTBUG-102281
Change-Id: Id63a69f86af90c8dc987c0301db3958322c006a1
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-04-06 17:12:50 +02:00
Ulf Hermann a55299615f QmlCompiler: Fix string-to-bool conversion via QJSPrimitiveValue
We had a typo in there.

Pick-to: 6.2 6.3
Fixes: QTBUG-102309
Change-Id: I11eb9d35fde3b92d2e48e845740379e10c53774a
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-04-06 17:12:41 +02:00
Ulf Hermann 0b63f3b66d QmlCompiler: Respect qualified property types
Factor out the name construction routine duplicated all over the place
and apply it to all places where it was missing.

Fixes: QTBUG-102147
Change-Id: I7c93b4878cedf3489b978591da8d8dfbb2b98c9b
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-04-06 05:02:34 +02:00
Ulf Hermann d425712e93 QmlCompiler: Allow primitive conversion from any number to bool
Task-number: QTBUG-102281
Change-Id: I0dac4ce9c86c55e52283a6e05b0c3c0cc46551be
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-04-05 14:27:12 +02:00
Andreas Buhr 598bfdb139 Repair tst_qmlcppcodegen on Android
tst_qmlcppcodegen tries to start itself again using QProcess.
This does not work on Android. This patch skips this test.

Task-number: QTBUG-101865
Pick-to: 6.2 6.3
Change-Id: Ib8f9a5e028a938949347bc8e83ea483d0228968e
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2022-04-05 14:12:02 +02:00
Ulf Hermann c12f0f07f5 QmlCompiler: Improve ambiguous type detection
When detecting an ambiguous type, we need to invalidate the entry in the
list of types, rather than delete it. If we delete it and we get yet
another version of the type, we'll add that one just like it was not
ambiguous.

Furthermore, we cannot check the type name when looking for ambiguity.
The QML name can be bent and twisted in various ways, to import
ambiguous-looking types under different names, so that they are actually
not ambiguous.

Pick-to: 6.2 6.3
Fixes: QTBUG-102153
Change-Id: Iee7951229c5f68b168899e55164e8cf91587eec1
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-04-01 20:58:49 +02:00
Ulf Hermann 5901fba811 QmlCompiler: Fix a number of warts regarding type lookup
There was a condition missing in qqml.cpp making most type lookups crash
right away. Furthermore, we need to generate code for type lookups we do
need. Finally, the shadow check should skip instructions we don't need
anymore. Shadowing in optimized-out code is not very interesting.

Pick-to: 6.2 6.3 6.3.0
Change-Id: I34e9de7686528b39a35e59c616e4e28b32a6e031
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-03-23 12:29:26 +01:00
Ulf Hermann 8a9607acfc QmlCompiler: Support type lookups in prefix-imported modules
We just have to return a plain metaType if it's neither an attached type
nor a singleton.

Pick-to: 6.3
Fixes: QTBUG-101811
Change-Id: I6a78ffe4504606d0cb34f1a6ca9d5511a3447d7f
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-03-22 17:47:47 +01:00
Ulf Hermann 922b95ea15 QmlCompiler: Avoid some deprecation warnings
QString::count() is deprecated, and also the "engine" argument to
QQmlListReference. Also, properly convert the results of "length"
retrieval.

Change-Id: Ib7edde1326a0347902174a23147086b9deccfe17
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-03-14 20:53:52 +01:00
Ulf Hermann 6eff3465b5 QmlCompiler: Implement generate_DefineArray
Using the type cloning and adaption mechanism we can now determine what
kind of list we have to create in order to avoid a later conversion. We
can even propagate the type adjustment into the element types we read.

Fixes: QTBUG-100157
Change-Id: Ia2f160ebae56f39ee5946f49d2f8c5b4986a6b77
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-03-14 20:53:52 +01:00
Ulf Hermann 1e722f5e8e QML: Handle dynamic meta objects in AOT lookups
If we are dealing with dynamic metaobjects, the QML engine may not
create property caches. We cannot see this at compile time. Therefore,
we need to establish a fallback infrastructure that does the same
operations on plain QMetaObject.

Pick-to: 6.2 6.3
Fixes: QTBUG-101349
Change-Id: I8c936fc077b0018df71196620b6987825253cb39
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-03-03 18:44:38 +01:00
Andreas Buhr 85b086a97b Fix compilation of tst_qmlcppcodegen on Android
It seems MOC does not like methods named "isnan" on Android.
It generates a call to "__builtin_isnan".
This patch is a workaround. A real fix in MOC would be better.

Pick-to: 6.3
Change-Id: If73a4d7580ac51f6c60f4fb92c9699d077f4452f
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-03-02 14:21:08 +01:00
Ulf Hermann 074b66e007 QmlCompiler: On MoveReg, check if we need to move at all
As we don't store void, null and empty lists, moving those is a noop.
Don't generate invalid code for that.

Pick-to: 6.2 6.3
Change-Id: Ica6714acd0ce8a5ddca44d9a397e776eb3df4247
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-03-01 08:51:52 +01:00
Ulf Hermann 23ab2e0f55 QmlCompiler: Correctly label arguments and return types of JS functions
Returning void from any JS function doesn't quite cut it.

Pick-to: 6.3
Fixes: QTBUG-101285
Change-Id: I199813627614061ec25139277e8ea23cb844aac5
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
2022-02-25 14:08:22 +01:00
Ulf Hermann c8e756e560 QML: Take care of QVariant when converting function arguments
We cannot convert to QVariant using QMetaType::convert(). But we can
just construct a QVariant with the desired type and data. This will
become an issue once we automatically convert argument types to match
the desired type inside the function.

As a side effect, also allow declaring "var" arguments to functions.

Change-Id: Idc14021d8d85d3d09ee7b7f286de91b56ea02bfd
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-02-23 12:09:42 +01:00
Ulf Hermann 88147eb3f6 QmlCompiler: Avoid infinite loop in dead store elimination
We have to mark the required variables also in block 0. And we shouldn't
generate empty blocks.

Pick-to: 6.3
Fixes: QTBUG-101011
Change-Id: I0dd19f69f45f507cb83e2ddfba3060de48a940b4
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-02-18 16:48:50 +01:00
Ulf Hermann d0f4e0c037 QmlCompiler: Perform QVariant conversion in JavaScript semantics
In JavaScript we have a number of extra conversions not covered by
qvariant_cast. Therefore, add a method to perform a QVariant conversion
in JavaScript semantics to QJSEngine, and use that in the compiler.

Pick-to: 6.3
Fixes: QTBUG-100883
Change-Id: I8b0bfa0974bc6b339d2601fb373859bc710788c8
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Jarkko Koivikko <jarkko.koivikko@code-q.fi>
2022-02-18 12:13:47 +01:00
Ulf Hermann 69fefd94e8 QmlCompiler: Do not crash on attempts to lookup a function in the scope
Rather, reject the code and let the engine handle it.

Pick-to: 6.2 6.3
Fixes: QTBUG-100980
Change-Id: Ibcd1249ba3550b40121622752b4ca22d1df3ed2a
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Jarkko Koivikko <jarkko.koivikko@code-q.fi>
2022-02-18 12:13:47 +01:00
Ulf Hermann 795d7dafe5 QmlCompiler: Do not generate block comments into C++ code
The code we're commenting could again contain block comments. You cannot
nest them.

Pick-to: 6.2 6.3
Fixes: QTBUG-100978
Change-Id: I78685bf29dd30f05e5a3b17abc43ba0b4cb6849e
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
2022-02-18 12:13:47 +01:00
Ulf Hermann 4c716dd19c QmlCompiler: Correctly encode inf/nan/-0 into C++
Pick-to: 6.2 6.3
Fixes: QTBUG-100947
Change-Id: If0b05adac91f687daf697f3510e4cf48e7de4537
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-02-18 12:13:47 +01:00
Ulf Hermann db6459665c QmlCompiler: Place code for CmpNeInt in parentheses
Otherwise it will apply the '!' to the first argument.

Fixes: QTBUG-100480
Pick-to: 6.2 6.3
Change-Id: Iaefa25d062ad8bbd9d4278ffeaa52fc53ed417e2
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-02-04 15:55:00 +01:00
Ulf Hermann 3747c02fe6 QmlCompiler: Handle ID lookups of incomplete types correctly
Incomplete types are generally stored in some wrapper type. We cannot
just assign to the accumulator. Also, we already know whether we have an
ID lookup there. No need to determine it again.

Pick-to: 6.2 6.3
Change-Id: I1f9fd9f147c44975df33fe862523987d8e711905
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-01-22 09:59:09 +01:00
Ulf Hermann e19d48d073 QmlCompiler: Respect revisions
The only place where revisions matter is at the boundary between
composite and non-composite types. The revision of the first composite
type inherited from determines which members of all composite ancestors
are available. Therefore, store the revision together with the base type
and pass it through the imports to have it available. Then use it to
check availability of methods and properties.

The test exposes two further problems, which are fixed, too:

1. If no method is found to call, we need to generate an error in the
   type propagator. We don't know what the call will result in, after
   all, and the code generator should reject it.
2. We need to check the right scopes for hasOwnMethod(). Otherwise we
   might not find methods that are available.

Pick-to: 6.2 6.3
Fixes: QTBUG-99128
Change-Id: I4c320b8dfb490b140d7b8c16e6b638b32f156faa
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-01-21 01:23:58 +01:00
Ulf Hermann 6a54c6013d QmlCompiler: Handle context push/pop in dead code
Otherwise we end up with unmatched curly braces in the generated code.

Pick-to: 6.2 6.3
Change-Id: I4c24d4062a8ed54cd6a9ecb43dfd2b5d0a26c9e1
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
2022-01-18 12:51:38 +01:00
Ulf Hermann bd0f4459ce Re-allow retrieval of list properties in QQmlJSCodeGenerator
It's not particularly slow. It probably was when we were using
QQmlListReference or JavaScript arrays.

Pick-to: 6.3
Change-Id: I1a4575a5b84cdfb732a6c3615d00bbe2abaffc94
Reviewed-by: Fawzi Mohamed <fawzi.mohamed@qt.io>
2022-01-15 14:22:42 +01:00
Ulf Hermann 0ea14fa126 QmlCompiler: Don't try to get attached objects for non-QObject*
We might end up in this situation if we don't know enough about the
base of the attached lookup. This would generate invalid C++ code.

Pick-to: 6.2 6.3
Change-Id: I210077388d0d1d0d4e9454bd3ba3792af9b42049
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-12-17 12:43:14 +01:00
Ulf Hermann dd0b82abdc QQmlJSImportsVisitor: Break inheritance cycles
If we keep them around, later passes on the same data may run into
infinite loops. We cannot fully prevent any further processing of the
data because the import can happen from deep within a hierarchy of
components and modules.

Also, separate the deprecation check from the inheritance check.

Pick-to: 6.2
Change-Id: I62ce7cd15be83f60cd72b63ab858632fbc7dea66
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-12-12 12:05:28 +01:00
Ulf Hermann 2aa118c118 QQmlJSAotContext: flushPendingBinding() before capturing a property
This avoids duplicate evaluation and binding loops.

Pick-to: 6.2
Change-Id: I5eba42d9dca0782dd964bd64c088c2e158faa9b3
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-12-10 10:06:28 +01:00
Ulf Hermann af356e3bc8 qmlcachegen: Don't generate bad code if we cannot resolve a return type
If we cannot resolve a return type, we need to refrain from calling the
method.

Pick-to: 6.2
Task-number: QTBUG-99042
Change-Id: Ie5ba0367c83c178f7e5c112072ca97d3c1c1fb1f
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-12-10 02:42:47 +01:00
Ulf Hermann 25333a6af2 QmlCompiler: Split type name by last "::" rather than first
The outer type name can include namespaces, the inner one cannot.

Task-number: QTBUG-99042
Change-Id: Idaa3abbfa7b4ff0c908edd7fdee5c4e2ba0337dc
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-12-10 02:42:47 +01:00
Ulf Hermann 1003626e6a QmlCompiler: Fix return type calculation
We can return void from a function, explicitly or implicitly, and we
need to be able to wrap that into a QVariant. In order to explicitly
return void, we need the void type to be exposed and understood.

Pick-to: 6.2
Change-Id: I513cabb25469b89a85b5d212a6825a037400729d
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-12-06 19:35:50 +01:00
Ulf Hermann b7b5127747 Test that we can retrieve attached types from "recursive" names
This is what the various SelectionRectangle.qml types in qqc2 do. Amends
commit e6c44662cdc8acfbdbf1c7ed071e1253ff0c1321.

Change-Id: Icb98f262d669ed165a3b3ab1be79b150b6cedc44
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-12-04 17:11:27 +01:00
Ulf Hermann 58ff7aa4fe Compile QML files ahead of time with qmlcachegen
qmlcachegen compiles bindings and functions to C++ as far as
QQmlJSAotCompiler can. It does respect "pragma Strict" and rejects the
file if it's violated. Furthermore, it sets up the logger to follow the
qt.qml.compiler.aot logging category. By default it's completely silent.

Compiling the examples with qmlcachegen exposes a bug in the type
resolver where it returns an invalid generic type. It should never do
that. Fix it by returning JSValue.

[ChangeLog][QtQml][Important Behavior Changes] QML bindings and
functions are now compiled to C++ by qmlcachegen, if possible. Use the
qt.qml.compiler.aot logging category to receive diagnostics about the
compilation.

Task-number: QTBUG-98305
Change-Id: I6953812c3fd20b68339617a5714fcbe16a384360
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-12-03 12:09:26 +01:00