Commit Graph

42 Commits

Author SHA1 Message Date
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
Mårten Nordheim af7d0957e4 Fix deprecated uses of QScopedPointer
Which is uses of take() and swap().
And replace it with std::unique_ptr.

Change-Id: I2580383c1d2af0ba6103a66f034235905e0988ac
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2022-03-10 21:02:58 +00:00
Ulf Hermann a2184b9ab7 QQmlPropertyCache: Store checksums in type loader
The type loader is specific to the engine. This way we can
calculate/retrieve the checksum without modifying the property cache,
which makes checksum() threadsafe. The checksums are only needed for
loading and storing compilation units from/to disk. Therefore, there is
no point in keeping them inside the property caches anyway.

Pick-to: 6.3
Task-number: QTBUG-73271
Change-Id: I7bea65e73769f76352bb5947d7229e256e7f2f25
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-03-09 12:40:06 +01:00
Fabian Kosmale 28b32ae449 Avoid spurious dependency on qml_compile_hash_p.h
The compile hash changes on every commit, so including it in a central
header like qv4compileddata_p.h would cause many spurious rebuilds.

As we only needed it there for a static assert, we can simply move that
check into a source file.

Pick-to: 6.2 6.3
Change-Id: I9f24cb3faf5172023b0ece9e6aa07db02638c8be
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-02-13 20:01:39 +01:00
Ulf Hermann 71597472dd Avoid ping-pong between plain pointers and QQmlRefPointer
We want to deal in QQmlRefPointer as much as possible. In particular,
assigning nullptr to a QQmlRefPointer triggers the creation of an empty
QQmlRefPointer and the assignment of that one. Provide a reset() method
to do this in a cleaner way.

In turn, make QQmlGuardedContextData::reset() private. It's really
dangerous and should not be called from outside. setContextData() is
safer but may do additional work. The only place from where reset() was
previously called in its public capacity is probably dead code, though.

Change-Id: Idb72e255dbfad6e5dd963dc76d719bb9edc10471
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-01-25 23:55:27 +01:00
Ulf Hermann ed6b31389a Further tighten checks around QML_COMPILE_HASH
Log the differing hashes in case of a mismatch.

Pick-to: 6.2 6.3
Task-number: QTBUG-99608
Change-Id: Id85306d3cfdb08d235c8717b441105c5d0b68cf3
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-01-20 19:33:01 +01:00
Ulf Hermann 47d6539c24 QQmlEngine: Remove methods that merely forward to QQmlMetaType
There is no reason to drag an engine around for those.

Change-Id: I02100b207f197e75dfd458ff1cce5c4920dd94bd
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-01-18 12:51:38 +01:00
Ulf Hermann a4eae734cd Move composite types into QQmlMetaType
This way we can retrieve them without an engine. Since we construct a
new QMetaTypeInterface for each composite type we load, those
QMetaTypeInterfaces will still be unique even if the same type is used
in different engines. Therefore, we can store them all in the same
container.

This exposes the fact that we don't actually register composite types as
"custom" QMetaTypes in registerInternalCompositeType(), but we expect
them to be registered later on, in particular in
unregisterInternalCompositeType(). Retrieve the IDs once, in order to
have the types registered right away.

Change-Id: Ib8e875a5c950f105996877ea597a6de2b01aa1f5
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-01-15 14:22:42 +01:00
Ulf Hermann 0616a44e8a Fix handling of QML_COMPILE_HASH
We need to check for the contents of the tag file, not its name. We need
to strip the contents before checking. We need to run git in the right
directory. We need to fail if we cannot find any QML_COMPILE_HASH.

Pick-to: 6.3 6.2
Task-number: QTBUG-99608
Change-Id: Ic42a073b196143f8576a84e7a4531b5f2927fb68
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
2022-01-07 01:17:39 +01:00
Ulf Hermann de587f1c55 Do not copy lookups
It leads to data corruption. Also, be more careful about releasing the
property cache. We can only do that if the qobjectlookup member of the
union is active. Unfortunately we have to do a number of checks now, to
make sure it is. In order to still keep the checks inline, we move some
functions around.

Pick-to: 6.2 6.3
Fixes: QTBUG-99211
Change-Id: If6dd879e67b172e1a9035e83fbfacbe73c6c7476
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-12-16 20:03:31 +00:00
Fabian Kosmale 5bb746520d Use QHash instead of QMap for resolved types
This vastly speeds up resolved type reference lookups in
QQmlObjectCreator::createInstance, which translates to significant
improvements in qmlbench:
perf record -b ./src/qmlbench --shell frame-count delegates_qobject.qml
went from roughly 730 frames to > 800 locally.

To have a stable order in the hash, we simply sort a tempory vector of
keys. As this happens only once, the overhead is negligible and
partially offset by the better memory locality of the QHash anyway.

Task-number: QTBUG-88672
Change-Id: Ib547a87fd0d2d81f366ea927ade232f33b3d3788
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-05-20 13:19:25 +02:00
Alex Shaw 3464655f5e Add QJSEngine::registerModule
Some applications that use JavaScript as a scripting language may want
to extend JS through C++ code. The current way to do that is with
global objects.
ES6 provides a better way of encapsulating code: modules.
registerModule() allows an application to provide a QJSValue as a named module.
Developers familiar with Node.js will find this very easy to use.

Example:
```c++
QJSValue num(666);
myEngine.registerModule("themarkofthebeast", num);
```
```js
import badnews from "themarkofthebeast";
```

[ChangeLog][QtQml][QJSEngine] Adds the ability to register QJSValues in
C++ as modules for importing in MJS files.

Change-Id: I0c98dcb746aa2aa15aa2ab3082129d106413a23b
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-05-01 17:26:00 -04:00
Ulf Hermann 2b49615db4 Redesign the AOT lookups
Each kind of lookup should come with a function that tries to execute
the lookup, taking a minimal number of parameters, and another one that
initializes the lookup, taking whatever is needed for that. No
initialization should be done in the execution step and vice versa.
Rather, the execution step should be repeated if an initialization had
to be done first.

This way, the happy path can be very fast if the lookups have been
initialized before.

Change-Id: Ic435b3dd4906d00144138cb05161a99a0a9c64ed
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-04-30 17:54:10 +02:00
Ulf Hermann 221b2789db Streamline retrieval of context property names and IDs
Most of this can be inline, and we never need to copy the actual
identifier hash.

Change-Id: I6468b6b1a571e4854c00c865a2aa57c3b2f0ca8c
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-04-15 11:14:19 +02:00
Ulf Hermann 7660c30e08 Cache static compilation units
If we load the same file multiple times, we can re-use the old mapping.
In fact we may leak memory if we don't. The fact that we have to use a
mutex here is somewhat regrettable, but I haven't found a better way
of serializing access.

Task-number: QTBUG-89659
Pick-to: 5.15
Change-Id: Iaa44ac80faa5e95f30c05e950ab35083a8b0416b
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-01-12 11:18:51 +01:00
Lars Knoll 7cf80e6de0 Remove the property cache from QQmlValueTypeWrapper
Instead operate directly on the meta object.

We could maybe have an optimization, where we have a global map
from id to QQmlPropertyData for each value type.

Task-number: QTBUG-88765
Change-Id: I259a06ba116a536b56380c2636737c6c016665d9
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2020-12-02 12:54:53 +01:00
Ulf Hermann f3ff873f67 Respect QV4_FORCE_INTERPRETER when AOT compiled functions are available
Those should not be executed then.

Change-Id: I80bc4b2da0bc0e5813ba4eef4b756065d48ac586
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-11-26 15:00:04 +01:00
Ulf Hermann f263e6ac93 Fix logic to select AOT compiled function
We only want the function if it's not a nullptr and if it matches the
required index.

Change-Id: I5695bfb950f66e5a7589b042c3313297c51533d2
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
2020-10-23 13:31:03 +02:00
Lars Knoll 229987d915 Do proper memory management on the metatype interfaces we create
Those interfaces are always registered in pairs. Add an external
refcount to CompositeMetaTypeIds, and do registration and
de-registration through this class.

Change-Id: I4f3a53ad935a43a734d6506ffc768f507b48ee1f
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-08-28 13:49:14 +02:00
Lars Knoll 8248b5a485 Always group the metaType and listType together
They are always created and destroyed together, so grouping
them makes the required memory management of them easier.

Change-Id: Ia1980f31f9bdff6a1accd229bc8380ae153edf67
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-08-28 13:49:08 +02:00
Karsten Heimrich 1b10ce6a08 Port QtDeclarative from QStringRef to QStringView
Task-number: QTBUG-84319
Change-Id: I2dcfb8a2db98282c7a1acdad1e6f4f949f26df15
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
2020-06-16 22:46:16 +02:00
Simon Hausmann ca1098ec1e Add support for binding ahead-of-time compiled bindings to QProperties
When the ahead-of-time built binding returns the same type as the
QProperty, then we can connect them directly with a small shim and pass
through the context and scope objects.

Change-Id: I9cb49d1fa35490a4ccb06965397674d5534c067d
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2020-04-22 09:54:02 +02:00
Simon Hausmann 505863e700 Add a hook that allows for ahead-of-time compiled functions
Use the unused field in the CachedUnit structure provided by qmlcachegen
to allow for providing function pointers for functions and bindings that
are compiled ahead of time.

Provided is the pointer into an array that is terminated with a {index:
0, functionPtr: nullptr} entry. The array index field in each array
entry allows for gaps.

Change-Id: I7457f5eea5f14e5f94431b9cc6da042cb03517a0
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-04-22 06:35:26 +02:00
Ulf Hermann f1fd2b982a V4: Move constant evaluation of doubles and strings into base CU
We don't need to execute anything for that. The translation evaluation
is kept in the executable CU because we might not have a
QCoreApplication.

Change-Id: I2ee39b220305e74b8c8f5540b8e59a91e2ed2b4c
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2020-04-03 09:12:10 +02:00
Ulf Hermann 3f0c9122c5 Encapsulate QV4::ResolvedTypeReference
It's used all over the place. We need a proper interface.

Change-Id: Iebe254ef3bf35503bf3fdd3639979a5db2b3449e
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-03-25 10:51:47 +01:00
Ulf Hermann 581250ff9e Fix typo: inlineComponendId -> inlineComponentId
Change-Id: Ic0c768fc2402d8674e06e84dfe4dc90d05407167
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-03-24 19:05:05 +01:00
Ulf Hermann 789929f939 Use QTypeRevision for all versions and revisions
In many places we carry major and minor versions or revisions that are
loosely coupled to minor versions. As the Qt minor version resets now,
we need to handle these things more systematically. In particular, we
need to add a "major" part to revisions.

QTypeRevision can express the current major/minor pairs more efficiently
and can also be used to add a major version to revisions. This change
does not change the semantics, yet, but only replaces the types.

Change-Id: Ie58ba8114d7e4c6427f0f28716deee71995c0d24
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-02-03 15:22:12 +01:00
Fabian Kosmale 684f9df784 Long live QML inline components
[ChangeLog][QtQml] It is now possible to declare new QML components in
a QML file via the component keyword. They can be used just as if they
were declared in another file, with the only difference that the type
name needs to be prefixed with the name of the containing type outside
of the file were the inline component has been declared.

Notably, inline components are not closures: In the following
example, the output would be 42

// MyItem.qml
Item {
    property int i: 33
    component IC: Item {
        Component.onCompleted: console.log(i)
    }
}
// user.qml
Item {
    property int i: 42
    MyItem.IC {}
}

Fixes: QTBUG-79382
Change-Id: I6a5ffc43f093a76323f435cfee9bab217781b8f5
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2020-01-23 15:58:10 +01:00
Alexandru Croitor 5fb8f1a328 Fix Qt6 build in preparation of qt5 submodule update
Fixes the QTextStream usages.

Change-Id: I0c009a82fb644a9f3c3d42ec410d18b680977f23
(cherry picked from commit 1c5c5f7aad)
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2019-12-19 07:37:51 +00:00
Ulf Hermann f807de3be0 Allow custom disk cache paths
Fixes: QTBUG-58858
Change-Id: I973a4b9f3ca618bda1943ff3fd0f8c9343b8f57d
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2019-12-10 13:07:52 +01:00
Simon Hausmann 16cbcc606d Add support for primitive self-references in composite types
This has been long missing and will also help with the implementation of
inline components and the referenced bugs.

Done-with: Fabian Kosmale <fabian.kosmale@qt.io>
Task-number: QTBUG-41087
Task-number: QTBUG-35910
Change-Id: Ia42a8f9808ece543f8ce2314b3352507fab22c62
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2019-10-21 12:47:54 +02:00
Ulf Hermann fcae2d13e4 Fix property cache leaks
Leaks happened when using unqualified context property lookups and when
looking up properties of singletons. We need to release the caches when
unlinking.

Fixes: QTBUG-78859
Change-Id: I8b86bcf72f71a463fb259eb6ae6c46be62729d72
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2019-09-30 17:19:09 +02:00
Yulong Bai d1b72c98b4 Fix unused captured 'this' warning
Change-Id: I90ddcfe42cae7364d321bd1c3a05eaba416081d4
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-08-07 18:13:12 +02:00
Ulf Hermann be600348ef Split qqmltypeloader{_p.h|.cpp} into a several files
No one can read this mess.

Change-Id: Icec4f2afc466435c1ae5e4e80fa2c1b5baf7d087
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-07-11 09:42:52 +02:00
Alexey Edelev 2d83adbec9 Switch to FloatingPointShortest precision when convert from numeric type to string
This change keeps double precision for value in case if number
of significant digits exceed six

Fixes: QTBUG-76303
Change-Id: Ifc97e845094d06d2f2e2445298305513cb7b56e2
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2019-07-10 13:06:55 +02:00
Ulf Hermann dbb38f35da Remove some unneeded includes
Change-Id: Id05059dfc9910dad206e511b08f18487e241e508
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-07-08 13:55:22 +02:00
Ulf Hermann 4d9ffeff74 Inline CompiledData::unlink() into the only caller
The compiler never links anything and therefore it doesn't need to
unlink, either.

Change-Id: I9ccdc012f9333abc5f4b60174b794e490772e1fd
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2019-06-24 11:13:08 +02:00
Ulf Hermann e9de399dda Move unit checksum generation into qv4compiler
Only the compiler ever has to do this, and we want the structure
definition for the compiled data as a common header.

Change-Id: Ie5c6d6c9dcd180dea79f54d0f7d10f3fc50fa20e
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-06-24 11:13:08 +02:00
Ulf Hermann e72637deed Move saveToDisk into SaveableUnitPointer
This way we can keep the flag mutilation closely local to the place
where we write the data. Also, SaveableUnitPointer doesn't need a full
CompilationUnit this way.

Change-Id: I01872e4c406cb2ccbaa1fa35325cc063b1e8a7df
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-06-24 11:13:05 +02:00
Ulf Hermann 84f8ceef3f Move the header checking into ExecutableCompilationUnit
We don't need to verify the header unless we want to execute the code.

Change-Id: Ieac51c47faafcd7047228b4264aa7750ba3d8889
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-06-14 19:08:51 +02:00
Mikhail Svetkin 2dae14637f qtlite: Fix build with -no-feature-translation
Change-Id: I9d6adc8d0a74c457bdff68a1c712995ffaee7a6a
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2019-06-11 15:55:20 +02:00
Ulf Hermann 6c76ee30ce Eliminate qmldevtools_build
Move the relevant files into more fitting locations and build the
devtools from only parser, compiler and qmldirparser.

Change-Id: Ibf37a1187f36d02983f9f43c6622acb243785b7b
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-05-31 15:18:55 +02:00