Skip to content

Commit db1f552

Browse files
author
Anna Gringauze
authored
Use DDC runtime debugger API (#2159)
* Use DDC debugger API * Fix analyzer warnings * Cleanup * Run instance tests with frontend server and build daemon * Add canary option to webdev and expression compiler worker * Update for latest sdk changes * cleanup and add tests * Updated issue reference * Remove unused API * Try making it work with current sdk changes * Cleanup * Cleanup * Cleanup * Cleanup * Update SDK min consrraint to require new debugger runtime API * Cleanup * Temporarily only test on main * More running on main * More running on main * More running on main * Fix failing webdev test * Remove unnecessary asyncs * Run type system verification tests for non-canary mode as well * Now run CI on dev
1 parent 87bd77f commit db1f552

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+856
-876
lines changed

.github/workflows/dart.yml

Lines changed: 100 additions & 100 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dwds/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- Require clients to specify the `basePath` on `AssetReader`. - [#2160](https://github.com/dart-lang/webdev/pull/2160)
44
- Update SDK constraint to `>=3.1.0-254.0.dev <4.0.0`. - [#2169](https://github.com/dart-lang/webdev/pull/2169)
55
- Require min `build_web_compilers` version `4.0.4` - [#2171](https://github.com/dart-lang/webdev/pull/2171)
6+
- Switch to using new debugging API from DDC to support new type system. - [#2159](https://github.com/dart-lang/webdev/pull/2159)
67

78
## 19.0.2
89

dwds/debug_extension/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ description: >-
66
A chrome extension for Dart debugging.
77
88
environment:
9-
sdk: ">=3.1.0-254.0.dev <4.0.0"
9+
sdk: ">=3.1.0-340.0.dev <4.0.0"
1010

1111
dependencies:
1212
async: ^2.3.0

dwds/debug_extension_mv3/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ description: >-
66
A Chrome extension for Dart debugging.
77
88
environment:
9-
sdk: ">=3.1.0-254.0.dev <4.0.0"
9+
sdk: ">=3.1.0-340.0.dev <4.0.0"
1010

1111
dependencies:
1212
built_value: ^8.3.0

dwds/lib/src/debugging/classes.dart

Lines changed: 24 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -77,88 +77,12 @@ class ClassHelper extends Domain {
7777

7878
if (libraryUri == null || classId == null || className == null) return null;
7979

80-
final rawName = className.split('<').first;
8180
final expression = '''
82-
(function() {
83-
${globalLoadStrategy.loadLibrarySnippet(libraryUri)}
84-
var result = {};
85-
var clazz = library["$rawName"];
86-
var descriptor = {
87-
'name': clazz.name,
88-
'dartName': sdkUtils.typeName(clazz)
89-
};
90-
91-
// TODO(grouma) - we display all inherited methods since we don't provide
92-
// the superClass information. This is technically not correct.
93-
var proto = clazz.prototype;
94-
var methodNames = [];
95-
for (; proto != null; proto = Object.getPrototypeOf(proto)) {
96-
var methods = Object.getOwnPropertyNames(proto);
97-
for (var i = 0; i < methods.length; i++) {
98-
if (methodNames.indexOf(methods[i]) == -1
99-
&& methods[i] != 'constructor') {
100-
methodNames.push(methods[i]);
101-
}
102-
}
103-
if (proto.constructor.name == 'Object') break;
104-
}
105-
106-
descriptor['methods'] = {};
107-
for (var name of methodNames) {
108-
descriptor['methods'][name] = {
109-
// TODO(jakemac): how can we get actual const info?
110-
"isConst": false,
111-
"isStatic": false,
112-
}
113-
}
114-
115-
var fields = sdkUtils.getFields(clazz);
116-
var fieldNames = fields ? Object.keys(fields) : [];
117-
descriptor['fields'] = {};
118-
for (var name of fieldNames) {
119-
var field = fields[name];
120-
var libraryUri = Object.getOwnPropertySymbols(fields[name]["type"])
121-
.find(x => x.description == "libraryUri");
122-
descriptor['fields'][name] = {
123-
// TODO(jakemac): how can we get actual const info?
124-
"isConst": false,
125-
"isFinal": field.isFinal,
126-
"isStatic": false,
127-
"classRefName": fields[name]["type"]["name"],
128-
"classRefDartName": sdkUtils.typeName(fields[name]["type"]),
129-
"classRefLibraryId" : field["type"][libraryUri],
130-
}
131-
}
132-
133-
// TODO(elliette): The following static member information is minimal and
134-
// should be replaced once DDC provides full symbol information (see
135-
// https://github.com/dart-lang/sdk/issues/40273):
136-
137-
descriptor['staticFields'] = {};
138-
var staticFieldNames = sdkUtils.getStaticFields(clazz) ?? [];
139-
for (const name of staticFieldNames) {
140-
descriptor['staticFields'][name] = {
141-
"isStatic": true,
142-
// DDC only provides names of static members, we set isConst/isFinal
143-
// to false even though they could be true.
144-
"isConst": false,
145-
"isFinal": false,
146-
}
147-
}
148-
149-
descriptor['staticMethods'] = {};
150-
var staticMethodNames = sdkUtils.getStaticMethods(clazz) ?? [];
151-
for (var name of staticMethodNames) {
152-
descriptor['methods'][name] = {
153-
// DDC only provides names of static members, we set isConst
154-
// to false even though it could be true.
155-
"isConst": false,
156-
"isStatic": true,
157-
}
158-
}
159-
160-
return descriptor;
161-
})()
81+
(function() {
82+
const sdk = ${globalLoadStrategy.loadModuleSnippet}('dart_sdk');
83+
const dart = sdk.dart;
84+
return dart.getClassMetadata('$libraryUri', '$className');
85+
})()
16286
''';
16387

16488
RemoteObject result;
@@ -176,35 +100,34 @@ class ClassHelper extends Domain {
176100
final methodRefs = <FuncRef>[];
177101
final methodDescriptors =
178102
classDescriptor['methods'] as Map<String, dynamic>;
179-
final staticMethodDescriptors =
180-
classDescriptor['staticMethods'] as Map<String, dynamic>;
181-
methodDescriptors.addAll(staticMethodDescriptors);
182103
methodDescriptors.forEach((name, descriptor) {
183104
final methodId = 'methods|$classId|$name';
184105
methodRefs.add(
185106
FuncRef(
186107
id: methodId,
187108
name: name,
188109
owner: classRef,
189-
isConst: descriptor['isConst'] as bool,
190-
isStatic: descriptor['isStatic'] as bool,
191-
// TODO(annagrin): get information about getters and setters from symbols.
192-
// https://github.com/dart-lang/sdk/issues/46723
193-
implicit: false,
110+
isConst: descriptor['isConst'] as bool? ?? false,
111+
isStatic: descriptor['isStatic'] as bool? ?? false,
112+
implicit: descriptor['isImplicit'] as bool? ?? false,
113+
isAbstract: descriptor['isAbstract'] as bool? ?? false,
114+
isGetter: descriptor['isGetter'] as bool? ?? false,
115+
isSetter: descriptor['isSetter'] as bool? ?? false,
194116
),
195117
);
196118
});
197119
final fieldRefs = <FieldRef>[];
120+
198121
final fieldDescriptors = classDescriptor['fields'] as Map<String, dynamic>;
199122
fieldDescriptors.forEach((name, descriptor) {
200123
final classMetaData = ClassMetaData(
201-
jsName: descriptor['classRefName'],
202124
runtimeKind: RuntimeObjectKind.type,
203125
classRef: classRefFor(
204-
descriptor['classRefLibraryId'],
205-
descriptor['classRefDartName'],
126+
descriptor['classLibraryId'],
127+
descriptor['className'],
206128
),
207129
);
130+
208131
fieldRefs.add(
209132
FieldRef(
210133
name: name,
@@ -215,34 +138,19 @@ class ClassHelper extends Domain {
215138
kind: classMetaData.kind,
216139
classRef: classMetaData.classRef,
217140
),
218-
isConst: descriptor['isConst'] as bool,
219-
isFinal: descriptor['isFinal'] as bool,
220-
isStatic: descriptor['isStatic'] as bool,
141+
isConst: descriptor['isConst'] as bool? ?? false,
142+
isFinal: descriptor['isFinal'] as bool? ?? false,
143+
isStatic: descriptor['isStatic'] as bool? ?? false,
221144
id: createId(),
222145
),
223146
);
224147
});
225148

226-
final staticFieldDescriptors =
227-
classDescriptor['staticFields'] as Map<String, dynamic>;
228-
staticFieldDescriptors.forEach((name, descriptor) {
229-
fieldRefs.add(
230-
FieldRef(
231-
name: name,
232-
owner: classRef,
233-
declaredType: InstanceRef(
234-
identityHashCode: createId().hashCode,
235-
id: createId(),
236-
kind: InstanceKind.kType,
237-
classRef: classRef,
238-
),
239-
isConst: descriptor['isConst'] as bool,
240-
isFinal: descriptor['isFinal'] as bool,
241-
isStatic: descriptor['isStatic'] as bool,
242-
id: createId(),
243-
),
244-
);
245-
});
149+
final superClassLibraryId = classDescriptor['superClassLibraryId'];
150+
final superClassName = classDescriptor['superClassName'];
151+
final superClassRef = superClassName == null
152+
? null
153+
: classRefFor(superClassLibraryId, superClassName);
246154

247155
// TODO: Implement the rest of these
248156
// https://github.com/dart-lang/webdev/issues/176.
@@ -257,6 +165,7 @@ class ClassHelper extends Domain {
257165
subclasses: [],
258166
id: classId,
259167
traceAllocations: false,
168+
superClass: superClassRef,
260169
);
261170
}
262171
}

dwds/lib/src/debugging/inspector.dart

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -349,11 +349,14 @@ class AppInspector implements AppInspectorInterface {
349349
throwInvalidParam('invoke', 'library uri is null');
350350
}
351351
final findLibrary = '''
352-
(function() {
353-
${globalLoadStrategy.loadLibrarySnippet(libraryUri)};
354-
return library;
355-
})();
356-
''';
352+
(function() {
353+
const sdk = ${globalLoadStrategy.loadModuleSnippet}('dart_sdk');
354+
const dart = sdk.dart;
355+
const library = dart.getLibrary('$libraryUri');
356+
if (!library) throw 'cannot find library for $libraryUri';
357+
return library;
358+
})();
359+
''';
357360
final remoteLibrary = await jsEvaluate(findLibrary);
358361
return jsCallFunctionOn(remoteLibrary, jsFunction, arguments);
359362
}
@@ -601,15 +604,6 @@ class AppInspector implements AppInspectorInterface {
601604
.toList();
602605
}
603606

604-
/// Compute the last possible element index in the range of [offset]..end
605-
/// that includes [count] elements, if available.
606-
static int? _calculateRangeEnd({
607-
int? count,
608-
required int offset,
609-
required int length,
610-
}) =>
611-
count == null ? null : math.min(offset + count, length);
612-
613607
/// Calculate the number of available elements in the range.
614608
static int _calculateRangeCount({
615609
int? count,
@@ -634,30 +628,21 @@ class AppInspector implements AppInspectorInterface {
634628
// TODO(#809): Sometimes we already know the type of the object, and
635629
// we could take advantage of that to short-circuit.
636630
final receiver = remoteObjectFor(id);
637-
final end =
638-
_calculateRangeEnd(count: count, offset: offset, length: length);
639631
final rangeCount =
640632
_calculateRangeCount(count: count, offset: offset, length: length);
641633
final args =
642-
[offset, rangeCount, end].map(dartIdFor).map(remoteObjectFor).toList();
634+
[offset, rangeCount].map(dartIdFor).map(remoteObjectFor).toList();
643635
// If this is a List, just call sublist. If it's a Map, get the entries, but
644636
// avoid doing a toList on a large map using skip/take to get the section we
645637
// want. To make those alternatives easier in JS, pass both count and end.
646638
final expression = '''
647-
function (offset, count, end) {
648-
const sdk = ${globalLoadStrategy.loadModuleSnippet}("dart_sdk");
649-
if (sdk.core.Map.is(this)) {
650-
const entries = sdk.dart.dload(this, "entries");
651-
const skipped = sdk.dart.dsend(entries, "skip", [offset])
652-
const taken = sdk.dart.dsend(skipped, "take", [count]);
653-
return sdk.dart.dsend(taken, "toList", []);
654-
} else if (sdk.core.List.is(this)) {
655-
return sdk.dart.dsendRepl(this, "sublist", [offset, end]);
656-
} else {
657-
return this;
658-
}
659-
}
660-
''';
639+
function (offset, count) {
640+
const sdk = ${globalLoadStrategy.loadModuleSnippet}("dart_sdk");
641+
const dart = sdk.dart;
642+
return dart.getSubRange(this, offset, count);
643+
}
644+
''';
645+
661646
return await jsCallFunctionOn(receiver, expression, args);
662647
}
663648

0 commit comments

Comments
 (0)