[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>
3 files changed
tree: 6e763b8e014078cbd4c8205c147ee619e468a307
  1. .dart_tool/
  2. .github/
  3. benchmarks/
  4. build/
  5. docs/
  6. pkg/
  7. runtime/
  8. samples/
  9. sdk/
  10. tests/
  11. third_party/
  12. tools/
  13. utils/
  14. .clang-format
  15. .gitattributes
  16. .gitconfig
  17. .gitignore
  18. .gn
  19. .mailmap
  20. .style.yapf
  21. AUTHORS
  22. BUILD.gn
  23. CHANGELOG.md
  24. codereview.settings
  25. CONTRIBUTING.md
  26. DEPS
  27. LICENSE
  28. OWNERS
  29. PATENT_GRANT
  30. PRESUBMIT.py
  31. README.dart-sdk
  32. README.md
  33. sdk.code-workspace
  34. sdk_args.gni
  35. sdk_packages.yaml
  36. SECURITY.md
  37. WATCHLISTS
README.md

Dart

An approachable, portable, and productive language for high-quality apps on any platform

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 platforms illustration

License & patents

Dart is free and open source.

See LICENSE and PATENT_GRANT.

Using Dart

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).

Building Dart

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.

Contributing to Dart

The easiest way to contribute to Dart is to file issues.

You can also contribute patches, as described in Contributing.

Roadmap

Future plans for Dart are included in the combined Dart and Flutter roadmap on the Flutter wiki.