[ddc] Update debugger field signatures

Erases extension types to their representation type for field
signatures. This is the best representation we have at runtime for
the field. Note this isn't necessarily the runtime type of the
field value.

Issue: https://github.com/dart-lang/sdk/issues/49735
Change-Id: Ibe064f4fd3829a858fc9fd920e2e91175d9ae0c9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/336823
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Mark Zhou <markzipan@google.com>
This commit is contained in:
Nicholas Shahan
2023-11-21 01:55:46 +00:00
committed by Commit Queue
parent deebb52c2b
commit a45fc14739
3 changed files with 58 additions and 8 deletions
@@ -1877,8 +1877,8 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
}
js_ast.Expression _emitClassFieldSignature(Field field, Class fromClass) {
var type = _typeFromClass(field.type, field.enclosingClass!, fromClass);
var fieldType = field.type;
var fieldType = _typeFromClass(field.type, field.enclosingClass!, fromClass)
.extensionTypeErasure;
var uri = fieldType is InterfaceType
? _cacheUri(jsLibraryDebuggerName(fieldType.classNode.enclosingLibrary))
: null;
@@ -1887,9 +1887,9 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
return uri == null
? js('{type: #, isConst: #, isFinal: #}',
[_emitType(type), isConst, isFinal])
[_emitType(fieldType), isConst, isFinal])
: js('{type: #, isConst: #, isFinal: #, libraryUri: #}',
[_emitType(type), isConst, isFinal, uri]);
[_emitType(fieldType), isConst, isFinal, uri]);
}
DartType _memberRuntimeType(Member member, Class fromClass) {
@@ -22,6 +22,7 @@ void main(List<String> args) async {
legacyCode: false,
moduleFormat: ModuleFormat.amd,
args: args,
enableExperiments: ['inline-class'],
);
runSharedTests(setup, driver);
});
@@ -34,6 +35,7 @@ void main(List<String> args) async {
legacyCode: false,
moduleFormat: ModuleFormat.amd,
args: args,
enableExperiments: ['inline-class'],
);
runSharedTests(setup, driver);
});
@@ -63,6 +65,16 @@ class BaseClass {
BaseClass? nullableField;
AnotherClass nonNullableField = AnotherClass();
Ext get extensionTypeGetter => Ext(AnotherClass());
Ext get _privateExtensionTypeGetter => Ext(AnotherClass());
ExtString extensionTypeField = ExtString('hello');
ExtString _privateExtensionTypeField = ExtString('hello');
static const ExtDuration staticConstExtensionTypeField =
const ExtDuration(Duration.zero);
static ExtDuration staticExtensionTypeField = ExtDuration(Duration.zero);
static final ExtDuration staticFinalExtensionTypeField =
ExtDuration(Duration.zero);
BaseClass(this.field, this._field) {
int y = 1;
lateFinalField = 35;
@@ -96,6 +108,12 @@ class AnotherClass {
int a = 0;
}
extension type Ext(AnotherClass _) {}
extension type ExtString(String _) {}
extension type const ExtDuration(Duration _) {}
main() {
int x = 15;
var derived = DerivedClass();
@@ -195,6 +213,20 @@ void runSharedTests(
'staticField': {'isStatic': true},
'_staticField': {'isStatic': true},
'_unusedStaticField': {'isStatic': true},
// NOTE: Fields typed as an extension type appear as their static
// erased type for now. This isn't necessarily the runtime type
// of the value either.
'extensionTypeField': {
'className': 'String',
'classLibraryId': 'dart:core',
},
'_privateExtensionTypeField': {
'className': 'String',
'classLibraryId': 'dart:core',
},
'staticConstExtensionTypeField': {'isStatic': true},
'staticExtensionTypeField': {'isStatic': true},
'staticFinalExtensionTypeField': {'isStatic': true},
},
'methods': {
'method': {},
@@ -204,6 +236,8 @@ void runSharedTests(
'_privateGetter': {'isGetter': true},
'factory': {'isStatic': true},
'staticMethod': {'isStatic': true},
'extensionTypeGetter': {'isGetter': true},
'_privateExtensionTypeGetter': {'isGetter': true},
},
});
});
@@ -237,6 +271,8 @@ void runSharedTests(
'_privateGetter': {'isGetter': true},
'factory': {'isStatic': true},
'staticMethod': {'isStatic': true},
'extensionTypeGetter': {'isGetter': true},
'_privateExtensionTypeGetter': {'isGetter': true},
},
});
});
@@ -529,7 +565,9 @@ void runSharedTests(
expectedResult: [
'_field',
'_newPrivateField',
'_privateExtensionTypeField',
'_unusedField',
'extensionTypeField',
'field',
'functionField',
'lateFinalField',
@@ -545,7 +583,9 @@ void runSharedTests(
expression: 'dart.getObjectFieldNames(base)',
expectedResult: [
'_field',
'_privateExtensionTypeField',
'_unusedField',
'extensionTypeField',
'field',
'functionField',
'lateFinalField',
+14 -4
View File
@@ -61,7 +61,9 @@ class SetupCompilerOptions {
final bool enableAsserts;
static fe.CompilerOptions _getOptions(
{required bool enableAsserts, required bool soundNullSafety}) {
{required bool enableAsserts,
required bool soundNullSafety,
required List<String> enableExperiments}) {
var options = fe.CompilerOptions()
..verbose = false // set to true for debugging
..sdkRoot = sdkRoot
@@ -72,7 +74,10 @@ class SetupCompilerOptions {
soundNullSafety ? _sdkSoundSummaryPath : _sdkUnsoundSummaryPath
..environmentDefines =
addGeneratedVariables({}, enableAsserts: enableAsserts)
..nnbdMode = soundNullSafety ? fe.NnbdMode.Strong : fe.NnbdMode.Weak;
..nnbdMode = soundNullSafety ? fe.NnbdMode.Strong : fe.NnbdMode.Weak
..explicitExperimentalFlags = fe.parseExperimentalFlags(
fe.parseExperimentalArguments(enableExperiments),
onError: (e) => throw e);
return options;
}
@@ -82,8 +87,11 @@ class SetupCompilerOptions {
this.legacyCode = false,
this.moduleFormat = ModuleFormat.amd,
this.canaryFeatures = false,
List<String> enableExperiments = const [],
}) : options = _getOptions(
soundNullSafety: soundNullSafety, enableAsserts: enableAsserts) {
soundNullSafety: soundNullSafety,
enableAsserts: enableAsserts,
enableExperiments: enableExperiments) {
options.onDiagnostic = (fe.DiagnosticMessage m) {
diagnosticMessages.addAll(m.plainTextFormatted);
if (m.severity == fe.Severity.error ||
@@ -111,7 +119,8 @@ class SetupCompilerOptions {
bool soundNullSafety = true,
bool legacyCode = false,
ModuleFormat moduleFormat = ModuleFormat.amd,
List<String> args = const <String>[],
List<String> enableExperiments = const [],
List<String> args = const [],
}) {
// Find if the test is run with arguments overriding the configuration
late bool enableAsserts;
@@ -135,6 +144,7 @@ class SetupCompilerOptions {
legacyCode: legacyCode,
moduleFormat: moduleFormat,
canaryFeatures: canaryFeatures,
enableExperiments: enableExperiments,
);
}