Skip to content

Hide internal implementation details in type objects - #2103

Merged
annagrin merged 14 commits into
dart-lang:masterfrom
annagrin:annagrin/type-objects
May 8, 2023
Merged

annagrin merged 14 commits into
dart-lang:masterfrom
annagrin:annagrin/type-objects

Conversation

@annagrin

@annagrin annagrin commented Apr 29, 2023 •

Copy link
Copy Markdown
Contributor

In this PR:

  • Modify class metadata to determine an object's runtime type kind
  • Modify instance.dart to convert from runtime objects to instances better
    • show types concisely
      • all types are shown as instances of core:Type class
      • print the type name correctly
      • no internal type representation details
      • matches vm display of types
    • show native JavaScript types and errors as objects of their type
  • Move getProperties from debugger to inspector
    • cache runtime kinds of classRefs to support better runtime object type detection
  • Add type inspection tests

Before

image

image

image

image

After

VSCode (consistent with VM)

image

image

image

image

DevTools (consistent with VM)

image

Closes: #2086
Towards: #1949

@annagrin
annagrin requested review from bkonyi, elliette and nshahan May 2, 2023 20:49
Comment thread dwds/lib/src/debugging/metadata/class.dart Outdated
Comment thread dwds/lib/src/debugging/metadata/class.dart
Comment thread dwds/lib/src/debugging/metadata/class.dart Outdated
Comment thread dwds/test/instances/record_type_inspection_test.dart
Comment thread fixtures/_testPackageSound/pubspec.yaml Outdated
Comment thread dwds/lib/src/debugging/metadata/class.dart Outdated
Comment thread dwds/lib/src/debugging/inspector.dart
Comment thread dwds/lib/src/debugging/instance.dart Outdated
Comment thread dwds/lib/src/debugging/instance.dart Outdated
Comment thread dwds/lib/src/debugging/instance.dart Outdated
Comment thread dwds/lib/src/debugging/instance.dart Outdated
Comment thread dwds/lib/src/debugging/instance.dart
Comment thread dwds/lib/src/debugging/metadata/class.dart Outdated
Comment thread dwds/lib/src/debugging/metadata/class.dart Outdated
Comment thread dwds/test/instances/record_type_inspection_test.dart
return InstanceKind.kRecordType;
case RuntimeObjectKind.object:
case RuntimeObjectKind.type:
case RuntimeObjectKind.wrappedType:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does RuntimeObjectKind.wrappedType represent in this context? There might be a different name that causes less confusion.

I really dislike how DDC uses the term "WrappedType" because it always leads to confusion when discussing the types. We have an internal type that is used for all type operations. When we need to return a value from .runtimeType calls we pass our internal type object to a method called wrapType() that returns a Dart Type object that wraps the internal representation. Then in various comments we refer to the wrapping Type object as the "wrapped type". It continually confuses me because I also tend to think of the type inside as the "wrapped type" because it has a wrapper around it. Good news is that all of this is on the list to be deleted when we switch type systems.

@annagrin annagrin May 3, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the dart._Type object we get from DDC on x.runtimeType calls. It has an _type field with the actual DartType. Other runtime kinds (RuntimeObjectKind.type and RuntimeObjectKind.recordType) are for the internal types (RecordType, class types, and primitive types objects). Would ExternalType or TypeWrapper work better than WrappedType?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced by TypeWrapper, to make the 'container' intention clearer.

@annagrin annagrin May 5, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I realized I can optimize the type wrapper case away (by unrolling the recursion in JS code for getting metadata), and minimize the number of wrapType calls. Updated.

Comment thread dwds/lib/src/debugging/metadata/class.dart Outdated
Comment thread dwds/lib/src/debugging/metadata/class.dart Outdated
Comment thread dwds/lib/src/debugging/metadata/class.dart Outdated
Comment thread dwds/lib/src/debugging/inspector.dart Outdated
Comment thread dwds/lib/src/debugging/metadata/class.dart Outdated
@annagrin
annagrin requested review from bkonyi, elliette and nshahan May 4, 2023 22:58

@bkonyi bkonyi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally LGTM, but I'll let a DWDS maintainer give final approval :-)

@nshahan nshahan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with the minor changes from our discussion today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Display of runtime types differs between web and VM apps

4 participants