diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2022-09-23 16:43:58 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2022-10-14 16:36:36 +0200 |
commit | de2d7cba76bcfbe0a29271df1178c176d00bf9b4 (patch) | |
tree | 5d37fcfad0636975f8ed4292f07140fdecdd19f2 /src/qml/qml/qqmlirloader.cpp | |
parent | d45925b0fdbd8055b60afbf87324325465d89568 (diff) |
Add option to enforce function signatures
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>
Diffstat (limited to 'src/qml/qml/qqmlirloader.cpp')
-rw-r--r-- | src/qml/qml/qqmlirloader.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/qml/qml/qqmlirloader.cpp b/src/qml/qml/qqmlirloader.cpp index 5c322ab021..59853a85e5 100644 --- a/src/qml/qml/qqmlirloader.cpp +++ b/src/qml/qml/qqmlirloader.cpp @@ -43,17 +43,28 @@ void QQmlIRLoader::load() createPragma(type)->componentBehavior = value; }; + const auto createFunctionSignaturePragma = [&]( + Pragma::PragmaType type, + Pragma::FunctionSignatureBehaviorValue value) { + createPragma(type)->functionSignatureBehavior = value; + }; + if (unit->flags & QV4::CompiledData::Unit::IsSingleton) createPragma(Pragma::Singleton); if (unit->flags & QV4::CompiledData::Unit::IsStrict) createPragma(Pragma::Strict); + if (unit->flags & QV4::CompiledData::Unit::ListPropertyAssignReplace) createListPragma(Pragma::ListPropertyAssignBehavior, Pragma::Replace); else if (unit->flags & QV4::CompiledData::Unit::ListPropertyAssignReplaceIfNotDefault) createListPragma(Pragma::ListPropertyAssignBehavior, Pragma::ReplaceIfNotDefault); + if (unit->flags & QV4::CompiledData::Unit::ComponentsBound) createComponentPragma(Pragma::ComponentBehavior, Pragma::Bound); + if (unit->flags & QV4::CompiledData::Unit::FunctionSignaturesEnforced) + createFunctionSignaturePragma(Pragma::FunctionSignatureBehavior, Pragma::Enforced); + for (uint i = 0; i < qmlUnit->nObjects; ++i) { const QV4::CompiledData::Object *serializedObject = qmlUnit->objectAt(i); QmlIR::Object *object = loadObject(serializedObject); |