Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide internal implementation details in type objects #2103

Merged
merged 14 commits into from
May 8, 2023

Conversation

annagrin
Copy link
Contributor

@annagrin annagrin commented Apr 29, 2023

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

dwds/lib/src/debugging/metadata/class.dart Outdated Show resolved Hide resolved
dwds/lib/src/debugging/metadata/class.dart Show resolved Hide resolved
dwds/lib/src/debugging/metadata/class.dart Outdated Show resolved Hide resolved
fixtures/_testPackageSound/pubspec.yaml Outdated Show resolved Hide resolved
dwds/lib/src/debugging/metadata/class.dart Outdated Show resolved Hide resolved
dwds/lib/src/debugging/inspector.dart Show resolved Hide resolved
dwds/lib/src/debugging/instance.dart Outdated Show resolved Hide resolved
dwds/lib/src/debugging/instance.dart Outdated Show resolved Hide resolved
dwds/lib/src/debugging/instance.dart Outdated Show resolved Hide resolved
dwds/lib/src/debugging/instance.dart Outdated Show resolved Hide resolved
dwds/lib/src/debugging/metadata/class.dart Outdated Show resolved Hide resolved
return InstanceKind.kRecordType;
case RuntimeObjectKind.object:
case RuntimeObjectKind.type:
case RuntimeObjectKind.wrappedType:
Copy link
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.

Copy link
Contributor Author

@annagrin annagrin May 3, 2023

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

Copy link
Contributor Author

@annagrin annagrin May 5, 2023

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.

dwds/lib/src/debugging/metadata/class.dart Outdated Show resolved Hide resolved
dwds/lib/src/debugging/metadata/class.dart Outdated Show resolved Hide resolved
dwds/lib/src/debugging/metadata/class.dart Outdated Show resolved Hide resolved
Copy link
Collaborator

@bkonyi bkonyi left a comment

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

Copy link
Contributor

@nshahan nshahan left a comment

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.

@annagrin annagrin merged commit fe5b975 into dart-lang:master May 8, 2023
46 checks passed
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