| commit | 2cfa1726ad59ed34e2d87b2dafe2f60f775233e3 | [log] [tgz] |
|---|---|---|
| author | Martin Kustermann <kustermann@google.com> | Mon Jul 08 09:52:24 2024 +0000 |
| committer | Commit Queue <dart-scoped@luci-project-accounts.iam.gserviceaccount.com> | Mon Jul 08 09:52:24 2024 +0000 |
| tree | 6e763b8e014078cbd4c8205c147ee619e468a307 | |
| parent | 164c10a1502f9adf21c27ecf4c69c15bcad73968 [diff] |
[dart2wasm] Extend specialized is/as helper functions for non-instantiated types
The specialized is/as checker functions are currently only used
for cases where the type to check against doesn't require checking
argument types.
This CL will extend that for cases where we do have to check
argument types, but we know that there's no need to substitute
type arguments. This saves the RTT system from searching for
the type argument substitution value.
Cases where this applies is for example
```
class Base<T> {}
class Sub<T> extends Base<T> {}
class Sub2<T> extends Base<T> {}
class Sub3<T> extends Base<T> {}
final l = <Base<Object>>[Sub<int>(), Sub2<String>(), Sub3<double>()];
foo<T>() {
final Base<Object> b = l[1];
if (b is Base<T>) { ... }
if (b is Base<String>) { ... }
}
```
Here we know that all classes that directly or indirectly implement
`Base<T>` just pass their type parameter up the hierarchy.
=> There's no need to translate from type parameter array of subclass
to that of the super class.
We'll generate optimized is/as helpers for this case now, e.g.
```
func foo {
...
local.get $var0
global.get $global40
call $<obj> is Base<T0>
...
}
func $<obj> is Base<T0> {
// Check whether obj is in class-id range of Base subtypes
i32.const 0
local.get $var0
struct.get $Base $field0
i32.const 107
i32.sub
i32.const 3
i32.ge_u
br_if $label0
drop
// Call Object._getTypeArguments()
i32.const 0
local.get $var0
local.get $var0
struct.get $Base $field0
i32.const 338
i32.add
call_indirect (param (ref $#Top)) (result (ref $Array<_Type>))
// Check whether first type argument is subtype of T0
i32.const 0
array.get $Array<_Type>
ref.null none
local.get $var1
ref.null none
call $_TypeUniverse.isSubtype
i32.const 1
i32.ne
br_if $label0
drop
i32.const 1
}
```
It has overall negligible code size impact (~ 0.1% increase)
Issue https://github.com/dart-lang/sdk/issues/55516
Change-Id: Ic151269ad1b4a1456782b387beb4d646786ac493
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/374681
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
Dart is:
Approachable: Develop with a strongly typed programming language that is consistent, concise, and offers modern language features like null safety and patterns.
Portable: Compile to ARM, x64, or RISC-V machine code for mobile, desktop, and backend. Compile to JavaScript or WebAssembly for the web.
Productive: Make changes iteratively: use hot reload to see the result instantly in your running app. Diagnose app issues using DevTools.
Dart's flexible compiler technology lets you run Dart code in different ways, depending on your target platform and goals:
Dart Native: For programs targeting devices (mobile, desktop, server, and more), Dart Native includes both a Dart VM with JIT (just-in-time) compilation and an AOT (ahead-of-time) compiler for producing machine code.
Dart Web: For programs targeting the web, Dart Web includes both a development time compiler (dartdevc) and a production time compiler (dart2js).
Dart is free and open source.
See LICENSE and PATENT_GRANT.
Visit dart.dev to learn more about the language, tools, and to find codelabs.
Browse pub.dev for more packages and libraries contributed by the community and the Dart team.
Our API reference documentation is published at api.dart.dev, based on the stable release. (We also publish docs from our beta and dev channels, as well as from the primary development branch).
If you want to build Dart yourself, here is a guide to getting the source, preparing your machine to build the SDK, and building.
There are more documents in our repo at docs.
The easiest way to contribute to Dart is to file issues.
You can also contribute patches, as described in Contributing.
Future plans for Dart are included in the combined Dart and Flutter roadmap on the Flutter wiki.