Skip to content

Commit a45fc14

Browse files
nshahanCommit Queue
authored and
Commit Queue
committed
[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: #49735 Change-Id: Ibe064f4fd3829a858fc9fd920e2e91175d9ae0c9 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/336823 Commit-Queue: Nicholas Shahan <[email protected]> Reviewed-by: Mark Zhou <[email protected]>
1 parent deebb52 commit a45fc14

File tree

3 files changed

+58
-8
lines changed

3 files changed

+58
-8
lines changed

pkg/dev_compiler/lib/src/kernel/compiler.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -1877,8 +1877,8 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
18771877
}
18781878

18791879
js_ast.Expression _emitClassFieldSignature(Field field, Class fromClass) {
1880-
var type = _typeFromClass(field.type, field.enclosingClass!, fromClass);
1881-
var fieldType = field.type;
1880+
var fieldType = _typeFromClass(field.type, field.enclosingClass!, fromClass)
1881+
.extensionTypeErasure;
18821882
var uri = fieldType is InterfaceType
18831883
? _cacheUri(jsLibraryDebuggerName(fieldType.classNode.enclosingLibrary))
18841884
: null;
@@ -1887,9 +1887,9 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
18871887

18881888
return uri == null
18891889
? js('{type: #, isConst: #, isFinal: #}',
1890-
[_emitType(type), isConst, isFinal])
1890+
[_emitType(fieldType), isConst, isFinal])
18911891
: js('{type: #, isConst: #, isFinal: #, libraryUri: #}',
1892-
[_emitType(type), isConst, isFinal, uri]);
1892+
[_emitType(fieldType), isConst, isFinal, uri]);
18931893
}
18941894

18951895
DartType _memberRuntimeType(Member member, Class fromClass) {

pkg/dev_compiler/test/expression_compiler/runtime_debugger_api_test.dart

+40
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ void main(List<String> args) async {
2222
legacyCode: false,
2323
moduleFormat: ModuleFormat.amd,
2424
args: args,
25+
enableExperiments: ['inline-class'],
2526
);
2627
runSharedTests(setup, driver);
2728
});
@@ -34,6 +35,7 @@ void main(List<String> args) async {
3435
legacyCode: false,
3536
moduleFormat: ModuleFormat.amd,
3637
args: args,
38+
enableExperiments: ['inline-class'],
3739
);
3840
runSharedTests(setup, driver);
3941
});
@@ -63,6 +65,16 @@ class BaseClass {
6365
BaseClass? nullableField;
6466
AnotherClass nonNullableField = AnotherClass();
6567
68+
Ext get extensionTypeGetter => Ext(AnotherClass());
69+
Ext get _privateExtensionTypeGetter => Ext(AnotherClass());
70+
ExtString extensionTypeField = ExtString('hello');
71+
ExtString _privateExtensionTypeField = ExtString('hello');
72+
static const ExtDuration staticConstExtensionTypeField =
73+
const ExtDuration(Duration.zero);
74+
static ExtDuration staticExtensionTypeField = ExtDuration(Duration.zero);
75+
static final ExtDuration staticFinalExtensionTypeField =
76+
ExtDuration(Duration.zero);
77+
6678
BaseClass(this.field, this._field) {
6779
int y = 1;
6880
lateFinalField = 35;
@@ -96,6 +108,12 @@ class AnotherClass {
96108
int a = 0;
97109
}
98110
111+
extension type Ext(AnotherClass _) {}
112+
113+
extension type ExtString(String _) {}
114+
115+
extension type const ExtDuration(Duration _) {}
116+
99117
main() {
100118
int x = 15;
101119
var derived = DerivedClass();
@@ -195,6 +213,20 @@ void runSharedTests(
195213
'staticField': {'isStatic': true},
196214
'_staticField': {'isStatic': true},
197215
'_unusedStaticField': {'isStatic': true},
216+
// NOTE: Fields typed as an extension type appear as their static
217+
// erased type for now. This isn't necessarily the runtime type
218+
// of the value either.
219+
'extensionTypeField': {
220+
'className': 'String',
221+
'classLibraryId': 'dart:core',
222+
},
223+
'_privateExtensionTypeField': {
224+
'className': 'String',
225+
'classLibraryId': 'dart:core',
226+
},
227+
'staticConstExtensionTypeField': {'isStatic': true},
228+
'staticExtensionTypeField': {'isStatic': true},
229+
'staticFinalExtensionTypeField': {'isStatic': true},
198230
},
199231
'methods': {
200232
'method': {},
@@ -204,6 +236,8 @@ void runSharedTests(
204236
'_privateGetter': {'isGetter': true},
205237
'factory': {'isStatic': true},
206238
'staticMethod': {'isStatic': true},
239+
'extensionTypeGetter': {'isGetter': true},
240+
'_privateExtensionTypeGetter': {'isGetter': true},
207241
},
208242
});
209243
});
@@ -237,6 +271,8 @@ void runSharedTests(
237271
'_privateGetter': {'isGetter': true},
238272
'factory': {'isStatic': true},
239273
'staticMethod': {'isStatic': true},
274+
'extensionTypeGetter': {'isGetter': true},
275+
'_privateExtensionTypeGetter': {'isGetter': true},
240276
},
241277
});
242278
});
@@ -529,7 +565,9 @@ void runSharedTests(
529565
expectedResult: [
530566
'_field',
531567
'_newPrivateField',
568+
'_privateExtensionTypeField',
532569
'_unusedField',
570+
'extensionTypeField',
533571
'field',
534572
'functionField',
535573
'lateFinalField',
@@ -545,7 +583,9 @@ void runSharedTests(
545583
expression: 'dart.getObjectFieldNames(base)',
546584
expectedResult: [
547585
'_field',
586+
'_privateExtensionTypeField',
548587
'_unusedField',
588+
'extensionTypeField',
549589
'field',
550590
'functionField',
551591
'lateFinalField',

pkg/dev_compiler/test/shared_test_options.dart

+14-4
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ class SetupCompilerOptions {
6161
final bool enableAsserts;
6262

6363
static fe.CompilerOptions _getOptions(
64-
{required bool enableAsserts, required bool soundNullSafety}) {
64+
{required bool enableAsserts,
65+
required bool soundNullSafety,
66+
required List<String> enableExperiments}) {
6567
var options = fe.CompilerOptions()
6668
..verbose = false // set to true for debugging
6769
..sdkRoot = sdkRoot
@@ -72,7 +74,10 @@ class SetupCompilerOptions {
7274
soundNullSafety ? _sdkSoundSummaryPath : _sdkUnsoundSummaryPath
7375
..environmentDefines =
7476
addGeneratedVariables({}, enableAsserts: enableAsserts)
75-
..nnbdMode = soundNullSafety ? fe.NnbdMode.Strong : fe.NnbdMode.Weak;
77+
..nnbdMode = soundNullSafety ? fe.NnbdMode.Strong : fe.NnbdMode.Weak
78+
..explicitExperimentalFlags = fe.parseExperimentalFlags(
79+
fe.parseExperimentalArguments(enableExperiments),
80+
onError: (e) => throw e);
7681
return options;
7782
}
7883

@@ -82,8 +87,11 @@ class SetupCompilerOptions {
8287
this.legacyCode = false,
8388
this.moduleFormat = ModuleFormat.amd,
8489
this.canaryFeatures = false,
90+
List<String> enableExperiments = const [],
8591
}) : options = _getOptions(
86-
soundNullSafety: soundNullSafety, enableAsserts: enableAsserts) {
92+
soundNullSafety: soundNullSafety,
93+
enableAsserts: enableAsserts,
94+
enableExperiments: enableExperiments) {
8795
options.onDiagnostic = (fe.DiagnosticMessage m) {
8896
diagnosticMessages.addAll(m.plainTextFormatted);
8997
if (m.severity == fe.Severity.error ||
@@ -111,7 +119,8 @@ class SetupCompilerOptions {
111119
bool soundNullSafety = true,
112120
bool legacyCode = false,
113121
ModuleFormat moduleFormat = ModuleFormat.amd,
114-
List<String> args = const <String>[],
122+
List<String> enableExperiments = const [],
123+
List<String> args = const [],
115124
}) {
116125
// Find if the test is run with arguments overriding the configuration
117126
late bool enableAsserts;
@@ -135,6 +144,7 @@ class SetupCompilerOptions {
135144
legacyCode: legacyCode,
136145
moduleFormat: moduleFormat,
137146
canaryFeatures: canaryFeatures,
147+
enableExperiments: enableExperiments,
138148
);
139149
}
140150

0 commit comments

Comments
 (0)