They are equal to QList<QString> and QList<QVariant>, respectively. We
cannot express this fact in qmltypes, but since those are builtin, we
can just hardcode it.
Task-number: QTBUG-112227
Change-Id: Iebeb5f6a5350d1c7184b1d9e6a38647e048c3806
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
In the happy case this just retrieves the internal QList from the list
property. In the sad case it produces a deep copy. That's not worse than
what the interpreter does, though.
Fixes: QTBUG-112227
Change-Id: I8b2b0ac74c90b6dcee876e83a64502756733c1c5
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
It can actually be null rather than undefined. We need to generate a
separate check for that and output the correct error messages.
Amends commit 05f56d7c78
Change-Id: Ia795e31805181640cd5be19359af51067d3fc8d6
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
A pointer type can hold bool as either nullptr or some value. We don't
need to produce a QVariant for that.
Change-Id: I368c3fa703d08ff396a5b4702ba7d1f2614b1467
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This adds support for 8- and 16-bit signed and unsigned integer types.
The test exposes that the engine fails to correctly convert out of range
values when assigning to a 32-bit int property. Fix that as drive-by.
Fixes: QTBUG-101634
Change-Id: I0a4177f49ffc062a1f444e30424e94c1f293e70c
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
JavaScript can coerce anything to bool, so should we.
Change-Id: Id560e4c1dc10b5432c0cedf3110ad3377bbc5f59
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This allows us to do the relevant conversions in a more civilized way,
dropping the outputVariantConversion() method. The latter is brittle
because you have to manually add it to each instruction, and it uses
QMetaType::convert() which is actually not guaranteed to give the same
results as a QML type coercion.
Task-number: QTBUG-94807
Change-Id: I4d6d05a60beb3b4dfc3da6f0142de25667510904
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
If the "Addressable" option to ValueTypeBehavior is set, you can use the
"as" operator to cast a previously unknown type into either undefined
or the given type. We can use this in qmlcachegen to generate efficient
code for further operations on the same type.
In the generated C++ it in fact only works for GetLookup because:
a, We generally don't do SetLookup on value types, yet.
b, We generally don't call methods on value types, yet.
c, We cannot store a union of undefined and a sequence type, yet.
However, getting properties of value types is the most important
application of the new casts so this is well worth it.
As a side effect we can also look up things in potentially undefined
results of other operations now. For example list lookups.
Task-number: QTBUG-94807
Change-Id: Ifdf34f1f3f67b7a0a8953b9ed0e947b74638a28c
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
If we have an exact match we should definitely use that.
Change-Id: I2846ecf6f9963a978b84b70fbe18acdfe6eb45e6
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
The interpreter does this and so should the enum lookup adapter for
generated C++ code.
Pick-to: 6.5 6.4 6.2
Fixes: QTBUG-109816
Change-Id: I576480c3ca808743ddc0ceaf2f0bd8a1de776a41
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This patch extends the logic for the 2-argument Math.min() and
Math.max() functions by reutilizing the same logic to compare two
elements and evaluate all arguments with the current max or min.
Fixes: QTBUG-108741
Change-Id: I993a26a1d44d66226c751272dfc2dc63330d115d
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This patch adds support for get lookups of QVariantMap properties.
Setting or modifying is not supported and will reject.
Also, QQmlJSRegisterContent::JavaScriptObjectProperty was
renamed to QQmlJSRegisterContent::GenericObjectProperty
Tests were added to TestQmllint::cleanQmlCode() and
tst_QmlCppCodegen::variantMapLookup().
Pick-to: 6.5
Fixes: QTBUG-105545
Change-Id: I653ee4e7de1fb1514e1e563a92cfc28633268a7e
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
It should result in NaN, not in 0. The typedArray() test exposes that
ExecutionEngine::toVariant() also gets this wrong. Fix that, too.
[ChangeLog][QtQml][Important Behavior Changes] Converting a JavaScript
value to a double or float, for example by inserting it into a typed
array, now assumes JavaScript type coercion semantics. In particular,
converting a value that is not actually a number now results in NaN
where it previously sometimes resulted in 0.
Pick-to: 6.5 6.4 6.2
Fixes: QTBUG-111179
Change-Id: If24444ae9014c8972761c565a6920f06699e485c
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Since we're already using 3 of the 4 enums in PlatformDialogHelper, we
can just as well declare PlatformDialogHelper as extended namespace and
avoid all the fiddling with Q_ENUMS and QFLAGS.
As an additional upside, we get code using those enums to compile to
C++ this way.
Pick-to: 6.5
Fixes: QTBUG-110933
Change-Id: I60bfc15c94133be368fa98ee1b3a0ab7a2bc53ef
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
We should generate type checking code for only strict comparison
of var against null/undefined types or vice versa cases. The non-
strict comparison should be handled elsewhere. Removed pragma Strict to
allow to add warning emitting tests of non-strict comparison.
This amends 6a816a9e0d
Pick-to: 6.5
Fixes: QTBUG-110769
Change-Id: I7f9a457e71a621a005f377216e841bec01667454
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
The code generated for QObject comparisons holds for both weak and
strong comparisons. Improve tst_qmlcppcodegen by adding missing weak
comparison tests.
Amends afc7928d1a.
Pick-to: 6.5
Change-Id: Ib6176a39b329e792b81b3d8e8a288dcea074320b
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
There are many ways to "hide" the qmldir from the engine at run time,
which turns singletons into regular types. While all of this is invalid,
we should not assert on it, but rather produce a legible warning.
Furthermore, sharpen the importing of extra modules from qrc as implicit
imports. We should really only import modules the file in question can
ever be part of. Otherwise we needlessly produce the above situation and
hide legitimate warning messages.
Amends commit 7517c1b3ae.
Now we need to teach our tools about the default import paths in the
resorurce file system. They cannot guess any type they may find in any
resource file anymore.
Pick-to: 6.5
Task-number: QTBUG-106929
Change-Id: Ic8c02396d10830a7f461e8a81649bb8c9a1add1f
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
You should be able to assign any list of QObjects to any other list of
QObjects.
Pick-to: 6.5
Fixes: QTBUG-108155
Change-Id: I6ddf0b49f7248ad56cc9560d217f3ea316c648a8
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
We can use QSequentialIterable for this.
Pick-to: 6.5
Fixes: QTBUG-110438
Change-Id: I7e82d0f089c9bb9eab46be46dedc2db3726e64b0
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
We do this for function return types, property types, and function
argument types already. Formally, we would have to store some
"isPointer" somewhere, but considering that we never read it anyway,
let's not go there.
This allows the compilers to recognize lists of QObject-derived types as
proper lists. This way we can generate better code for moving them
around or getting their length.
Pick-to: 6.5
Task-number: QTBUG-110438
Change-Id: I35e0fc21d574afc18799e9c3cef402f05b60a3ed
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
qmlimportscanner is rather limited in how it works,
and does not pick up the Qt.labs.folderlistmodel
dependency for Dialogs.
Pick-to: 6.5
Fixes: QTBUG-103044
Change-Id: I778f5c8981f1a2603bc3a5d2fd249a83de6c9bd8
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Otherwise we later try to perform value type lookups on them. That won't
work.
Pick-to: 6.5
Task-number: QTBUG-110438
Change-Id: I1690a3375841ba5a1ff1a471a7f88bd2023ab4c4
Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Unfortunately value types behave differently when compiled to C++.
Document the difference and introduce a pragma to make them behave one
way or the other.
Pick-to: 6.5
Fixes: QTBUG-109221
Change-Id: Ib2685153c0b4ae209bafbea7a01229377fdb47dd
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
We can coerce QDateTime, QDate and QTime into each other because they
would all be represented by a Date object in JavaScript. Furthermore we
can coerce them all to QString. Technically, we could also coerce
strings to all of them, but we don't want to because that is terrible.
Fixes: QTBUG-109380
Change-Id: I176bfb5b715a6a6750cb5918c44261fa23fb8832
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Since we can produce QJSPrimitiveValue in metaTypeFromJS, we should also
handle the other direction.
Fixes: QTBUG-109867
Pick-to: 6.5
Change-Id: I2c7598d19eba3e78d071ca3eceb32deda4d0ead8
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
We should be able to compare QObject * with QObject * or a
nullptr.
Pick-to: 6.5
Fixes: QTBUG-109377
Change-Id: I0e9d6fdc89cbb471774d6382316dfb4813310e1d
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
The code generator currently rejects any comparisons other than
primitive types. Add comparison capability for var types against
null or undefined types and vice versa. To achieve this, we generate
code that fetches the contained object within the variant and
comparison is done depending on the stored type.
Ideally, we also need to add comparison capability for QObject *, that will be handled with QTBUG-109377.
Pick-to: 6.5
Fixes: QTBUG-108632
Change-Id: Ib15450d7922f6025c78def5cc548c74827ad740f
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Previously all list types used as arguments or return types for methods
had to be looked up via the imports. However, builtin types are not part
of the imports at run time. Therefore, recognize list types already
early on, when generating the IR. This is the same way we do it for
property types and it allows us to easily identify lists of builtins.
Pick-to: 6.5
Fixes: QTBUG-109147
Change-Id: I91fa9c8fc99c1e0155cc5db5faddd928ca7fabbc
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
We need to explicitly cast to double if we are wrapping a number type
that's not natively accepted by the ctors.
As a side effect, correctly run conversions from generic QVariant to
QJSPrimitiveValue through the engine now. For that we need another
clause in metaTypeFromJS().
Since we are calling methods that return list types in the test, we need
to add another clause that converts JS arrays to list types. Otherwise
we cannot run that test in interpreted mode.
Pick-to: 6.5 6.2 6.4 6.4.2
Task-number: QTBUG-109111
Change-Id: I87f7aafd24371d2c1ffe85569e1f2cd3a1979742
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
A StoreElement on a JS value can do pretty much anything you can
imagine, after all.
Pick-to: 6.5 6.4 6.4.2
Fixes: QTBUG-109196
Change-Id: Ic638d94b55e6340eb9fe56abc663a6f0f2277f5e
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
If we try to lookup the length of a generic QVariant, we fail, and so
far crashed. We should ideally detect that we are dealing with an array
(and thus length is a known, available property), but for now simply
reject compilation to C++.
Pick-to: 6.4
Fixes: QTBUG-109164
Change-Id: I9d4149ac09a351754d012dbc829774413d6b32eb
Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
We want to always import dependencies, always import qualified scripts,
and always try to load C++-based types from the binary. Furthermore,
directory imports should be imported with their qmldir URI where
possible, so that we can find them when loading local C++-based types.
Fixes: QTBUG-109109
Change-Id: I58f08f479623a886c802035b41f5f604338468b5
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
We obviously want to see the defaulted parameters when generating the
handlers.
Fixes: QTBUG-108762
Change-Id: I33a52bac305238467d45650bf8a2ad59d40e366f
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
We currently force the lookup metatype to be exactly the same data type
with the caller's. As a result, the conversion from enum to integral
data type is not recognized. Relax this comparison by using
isTypeCompatible helper.
Pick-to: 6.4
Fixes: QTBUG-109007
Change-Id: I188dc3e6c1fd7100e9ed5c4ba5d0c90d85d79be4
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* If we got an object type exposed as namespace, we still need to add
the "*" to get its augmentedInternalName(). Otherwise we cannot get
its metaobject, needed to look up enums.
* Enums cannot be shadowed. The shadow check will produce garbage if we
try to check because an enum lookup also does not use the accumulator,
which then contains some artifact from a previous operation.
* If we find a property lookup on a plain QMetaObject* we have to
immediately return in order to not confuse it with attached
properties.
Pick-to: 6.4 6.2
Fixes: QTBUG-109048
Change-Id: If9e3b4806e4d773de9cf48f1b3750b684a8c8f69
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
If the local type is a namespace, the resulting type can only be a
namespace, too, no matter what kind of tag the foreign one has.
Furthermore, we can re-use types with other QML_* tags this way.
Task-number: QTBUG-108883
Change-Id: Ib2ae08d5b081b8faa35124314f97d406d7b4f76f
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
The same type can be exported multiple times with different attributes,
even in the same module.
This requires us to fix directory imports as qmllint otherwise complains
about SegFault.bad.qml and SegFault.qml being the same type (which they
obviously aren't).
Task-number: QTCREATORBUG-27590
Change-Id: I295d927b9a07acbb715055a6883ac44b50129c2d
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
We provide semi-private functions in the AOT context for this. Since we
cannot know the complete run time type of the potential logging category
at compile time, we have to check any first argument that might be one
separately.
Fixes: QTBUG-107175
Change-Id: I46a8922b1c5c16d2b450b8728d650d31dfd867e3
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Those are not stored. If we compare null to null or undefined to
undefined, we do not have to generate a comparison at all. the result is
statically known.
Pick-to: 6.4
Fixes: QTBUG-108634
Change-Id: I6a5323c2e0c023838609aec90d7ecc15b885dc08
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
When preparing for such a call, the byte code loads an "empty" constant.
This has to be represented in the type system so that we don't hit the
assert at the end of the instruction.
Pick-to: 6.4 6.2
Task-number: QTBUG-108441
Change-Id: I66220bfae3d3a4b8e9600d84d4cfc43ac858b77e
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
There are multiple types of signal indexes, one of them
belongs to QMetaMethod::signalIndex and another one to
QObjectPrivate::signalIndex.
Stop mixing them up in aot-compiled code when capturing
properties as this leads to weird and hard to debug bugs.
Add a smaller version of the drag and drop example as test
to make sure that the bug does not appear again, without any
visual elements.
Fixes: QTBUG-104047
Fixes: QTBUG-104716
Pick-to: 6.4 6.2
Change-Id: I4f64ba237e824ff0ba1624c29ddcf5371d03d69e
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
We don't discern between empty and undefined values in the compiler.
Fixes: QTBUG-104192
Change-Id: Ida06386433ef9e8f9a7cba4bec99ba8e77edc324
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Since lists are allowed as property types, you should be able to pass
them as arguments to methods, too. For now we only handle QML-defined
methods, implemented by adding JavaScript functions to your QML
elements. The usual type coercion rules apply if you pass JavaScript
arrays to such methods. That is, it usually works.
We now resolve properties with the "list" flag to their actual types
(QQmlListProperty or QList) already when populating the QQmlJSScope, and
store the list types as members of QQmlJSScope rather than as a special
map in QQmlJSTypeResolver. This allows us to do the same to lists passed
as arguments and simplifies some of the type analysis.
Fixes: QTBUG-107171
Change-Id: Idf71ccdc1d59f472c17084a36b5d7879c4d959c0
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This is a semantic patch using ClangTidyTransformator to convert
sequences of Q_UNREACHABLE() + return into Q_UNREACHABLE_RETURN(),
newly added to qtbase.
const std::string unr = "unr", val = "val", ret = "ret";
auto makeUnreachableReturn = cat("Q_UNREACHABLE_RETURN(",
ifBound(val, cat(node(val)), cat("")),
")");
auto ignoringSwitchCases = [](auto stmt) {
return anyOf(stmt, switchCase(subStmt(stmt)));
};
makeRule(stmt(ignoringSwitchCases(stmt(isExpandedFromMacro("Q_UNREACHABLE")).bind(unr)),
nextStmt(returnStmt(optionally(hasReturnValue(expr().bind(val)))).bind(ret))),
{changeTo(node(unr), cat(makeUnreachableReturn,
";")), // TODO: why is the ; lost w/o this?
changeTo(node(ret), cat(""))},
cat("use ", makeUnreachableReturn));
a.k.a qt-use-unreachable-return.
subStmt() and nextStmt() are non-standard matchers.
There was one false positive, suppressed it with NOLINTNEXTLINE.
It's not really a false positiive, it's just that Clang sees the world
in one way and if conditonal compilation (#if) differs for other
compilers, Clang doesn't know better. This is an artifact of matching
two consecutive statements.
Change-Id: I3855b2dc8523db1ea860f72ad9818738162495c6
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
By default, the QML engine does not enforce signatures given as type
annotations to functions. By passing different types than the function
declares, you can get different behavior between the interpreter/JIT and
the AOT-compiled code. In addition, in interpreted or JIT'ed mode, we
pass all non-primitive value types as references. This means, if you
modify them within the called function, the modifications are propagated
back to the place where the value was loaded from.
Enforcing the signature prevents all of this, at a run time cost. Since
we have to coerce all arguments to the desired types, the function call
overhead grows. This change introduces a pragma
"FunctionSignatureBehavior" which you can set to "Ignored" or "Enforced"
to choose one way or the other as universal way of handling type
annotations.
Fixes: QTBUG-106819
Change-Id: I50e9b2bd6702907da44974cd9e05b48a96bb609e
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This is a semantic patch using ClangTidyTransformator as in
qtbase/df9d882d41b741fef7c5beeddb0abe9d904443d8, but extended to
handle typedefs and accesses through pointers, too:
const std::string o = "object";
auto hasTypeIgnoringPointer = [](auto type) { return anyOf(hasType(type), hasType(pointsTo(type))); };
auto derivedFromAnyOfClasses = [&](ArrayRef<StringRef> classes) {
auto exprOfDeclaredType = [&](auto decl) {
return expr(hasTypeIgnoringPointer(hasUnqualifiedDesugaredType(recordType(hasDeclaration(decl))))).bind(o);
};
return exprOfDeclaredType(cxxRecordDecl(isSameOrDerivedFrom(hasAnyName(classes))));
};
auto renameMethod = [&] (ArrayRef<StringRef> classes,
StringRef from, StringRef to) {
return makeRule(cxxMemberCallExpr(on(derivedFromAnyOfClasses(classes)),
callee(cxxMethodDecl(hasName(from), parameterCountIs(0)))),
changeTo(cat(access(o, cat(to)), "()")),
cat("use '", to, "' instead of '", from, "'"));
};
renameMethod(<classes>, "count", "size");
renameMethod(<classes>, "length", "size");
except that on() was replaced with a matcher that doesn't ignoreParens().
a.k.a qt-port-to-std-compatible-api V5 with config Scope: 'Container'.
Change-Id: I58e1b41b91c34d2e860dbb5847b3752edbfc6fc9
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
In case of an enum the actual contained type is the one the enum
dictates. This brings registerContains() in line with containedType()
and makes it possible to match previously discovered types on subsequent
passes of the type propagator. Therefore, it avoids infinite loops where
the same types would be tracked over and over.
Pick-to: 6.4
Fixes: QTBUG-107176
Fixes: QTBUG-107542
Change-Id: I4b8d66b157d0ec0ece4ca345cb99a630b8898a1b
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This is a semantic patch using ClangTidyTransformator as in
qtbase/df9d882d41b741fef7c5beeddb0abe9d904443d8:
auto QtContainerClass = anyOf(
expr(hasType(cxxRecordDecl(isSameOrDerivedFrom(hasAnyName(classes))))).bind(o),
expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o));
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container',
with the extended set of container classes recognized.
Change-Id: Idb1f75dfe2323bd1d9e8b4d58d54f1b4b80c7ed7
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
If we cannot access a property due to a version mismatch, that's not an
unqualified access.
Pick-to: 6.4
Fixes: QTBUG-107080
Change-Id: I1780b171928df437a2121601f1aac829dbe1e994
Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
We want to use the aotFunction member also for typed JavaScript
functions.
Change-Id: Iad6d12ebed3ad3069832484137ed8e4d9e7a7cf4
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
We now actually need a valid metatype.
Task-number: QTBUG-106194
Change-Id: Idfc41cae4216e30058f797b08863c350f473ba55
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Some of the math operators were still missing. Add them and test them
all.
Since the "runInterpreted()" test function takes too long now, split the
qmlcppcodegen test in two: One that runs in compiled mode and one that
runs in interpreted mode.
Fixes: QTBUG-105188
Change-Id: I4b641d5e51b5a7e2a9254be40f257d7b249deb13
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Just create a dummy type that has the actual name. To make that
possible, export the property cache creator's class counter to the
autotests – otherwise, we cannot know the name of the actual type, as it
would depend on the order in which the tests run.
Change-Id: I36b24183fbd041179f2ffffd17026b224c9737fa
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
All of those are legal in ECMAScript, and so we need to support them in
script bindings. As we have stricter rules for literal bindings, add an
extra method there to check for what QQmlPropertyValidator does.
Pick-to: 6.4
Fixes: QTBUG-105252
Task-number: QTBUG-105188
Change-Id: I0621b2c3aa196414f669873e93670557284a8bca
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
So far we have only accepted QQmlListReference. However, we can also
pass a QQmlListProperty around as value.
Pick-to: 6.2 6.3 6.4
Fixes: QTBUG-105137
Change-Id: I7d4cd3048b62594298f91013c4cda5ec864a28df
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
We should not convert from undefined on storeNameSloppy. The reset is
intentional.
Task-number: QTBUG-104508
Change-Id: Iede88fe6331dd173c9e8ea0ec4200df2b8bd30eb
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>