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 /tests/auto/qml/qqmllanguage/data | |
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 'tests/auto/qml/qqmllanguage/data')
-rw-r--r-- | tests/auto/qml/qqmllanguage/data/signatureEnforced.qml | 35 | ||||
-rw-r--r-- | tests/auto/qml/qqmllanguage/data/signatureIgnored.qml | 25 |
2 files changed, 60 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmllanguage/data/signatureEnforced.qml b/tests/auto/qml/qqmllanguage/data/signatureEnforced.qml new file mode 100644 index 0000000000..e2ddd75b55 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/signatureEnforced.qml @@ -0,0 +1,35 @@ +pragma FunctionSignatureBehavior: Enforced + +import StaticTest +import QtQml + +QtObject { + property rect rect: ({ x: 12, y: 13 }) + property withLength withLength: 5 + + function a(r: rect) { + r.x = 77 // does not write back + } + + function b(s: string) : int { + return s.length // this is a string + } + + function c(w: withLength) : int { + return w.length || 67; + } + + function d(r) { + r.y = 77 // does write back + } + + property int l: b(withLength) + property int m: rect.x + property int n: c(99) // creates a withLength + property int o: rect.y + + Component.onCompleted: { + a(rect) + d(rect) + } +} diff --git a/tests/auto/qml/qqmllanguage/data/signatureIgnored.qml b/tests/auto/qml/qqmllanguage/data/signatureIgnored.qml new file mode 100644 index 0000000000..0e9d0f42dc --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/signatureIgnored.qml @@ -0,0 +1,25 @@ +import StaticTest +import QtQml + +QtObject { + property rect rect: ({ x: 12, y: 13 }) + property withLength withLength: 5 + + function a(r: rect) { + r.x = 77 // writes back + } + + function b(s: string) : int { + return s.length // this is not in fact a string + } + + function c(w: withLength) : int { + return w.length || 67 + } + + property int l: b(withLength) + property int m: rect.x + property int n: c(99) // passes a number + + Component.onCompleted: a(rect) +} |