Skip to content

Prepare for variable names changes due to patterns support in DDC #2042

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions dwds/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 18.0.2-dev

- Support new DDC temp names for patterns. - [#2042](https://github.com/dart-lang/webdev/pull/2042)

## 18.0.1

- Fix failure to map JS exceptions to dart. - [#2004](https://github.com/dart-lang/webdev/pull/2004)
Expand Down
20 changes: 16 additions & 4 deletions dwds/lib/src/debugging/dart_scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,19 @@ import 'package:dwds/src/debugging/debugger.dart';
import 'package:dwds/src/utilities/objects.dart';
import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';

// TODO(sdk/issues/44262) - use an alternative way to identify synthetic
// variables.
final ddcTemporaryVariableRegExp = RegExp(r'^(t[0-9]+\$?[0-9]*|__t[\$\w*]+)$');
/// The regular expressions used to filter out temp variables.
/// Needs to be kept in sync with SDK repo.
///
/// TODO(annagrin) - use an alternative way to identify
/// synthetic variables.
/// Issue: https://github.com/dart-lang/sdk/issues/44262
final ddcTemporaryVariableRegExp = RegExp(r'^t(\$[0-9]*)+\w*$');
final ddcTemporaryTypeVariableRegExp = RegExp(r'^__t[\$\w*]+$');

/// Temporary variable regex before SDK changes for patterns.
/// TODO(annagrin): remove after dart 3.0 is stable.
final previousDdcTemporaryVariableRegExp =
RegExp(r'^(t[0-9]+\$?[0-9]*|__t[\$\w*]+)$');

/// Find the visible Dart properties from a JS Scope Chain, coming from the
/// scopeChain attribute of a Chrome CallFrame corresponding to [frame].
Expand Down Expand Up @@ -65,7 +75,9 @@ Future<List<Property>> visibleProperties({
// Dart generic function, where the type arguments get passed in as
// parameters. Hide those.
return (type == 'function' && description.startsWith('class ')) ||
(ddcTemporaryVariableRegExp.hasMatch(name)) ||
previousDdcTemporaryVariableRegExp.hasMatch(name) ||
ddcTemporaryVariableRegExp.hasMatch(name) ||
ddcTemporaryTypeVariableRegExp.hasMatch(name) ||
(type == 'object' && description == 'dart.LegacyType.new');
});

Expand Down
132 changes: 56 additions & 76 deletions dwds/lib/src/injected/client.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions dwds/lib/src/services/expression_evaluator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ class ExpressionEvaluator {

// Compile expression using an expression compiler, such as
// frontend server or expression compiler worker.
//
// TODO(annagrin): map JS locals to dart locals in the expression
// and JS scope before passing them to the dart expression compiler.
// Issue: https://github.com/dart-lang/sdk/issues/40273
final compilationResult = await _compiler.compileExpressionToJs(
isolateId,
libraryUri.toString(),
Expand Down
2 changes: 1 addition & 1 deletion dwds/lib/src/version.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dwds/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: dwds
# Every time this changes you need to run `dart run build_runner build`.
version: 18.0.1
version: 18.0.2-dev
description: >-
A service that proxies between the Chrome debug protocol and the Dart VM
service protocol.
Expand Down
28 changes: 28 additions & 0 deletions dwds/test/evaluate_common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,27 @@ void testAll({
await context.service.resume(isolateId);
});

test('extension method scope variables can be evaluated', () async {
await onBreakPoint(isolateId, mainScript, 'extension', () async {
final event = await stream
.firstWhere((event) => event.kind == EventKind.kPauseBreakpoint);

final stack = await context.service.getStack(isolateId);
final scope = _getFrameVariables(stack.frames!.first);
for (var p in scope.entries) {
final name = p.key;
final value = p.value as InstanceRef;
final result = await context.service
.evaluateInFrame(isolateId, event.topFrame!.index!, name!);

expect(
result,
isA<InstanceRef>().having((instance) => instance.valueAsString,
'valueAsString', value.valueAsString));
}
});
}, skip: 'https://github.com/dart-lang/webdev/issues/1371');

test('uses correct null safety mode', () async {
await onBreakPoint(isolateId, mainScript, 'printLocal', () async {
final event = await stream
Expand Down Expand Up @@ -695,3 +716,10 @@ void testAll({
});
});
}

Map<String?, InstanceRef?> _getFrameVariables(Frame frame) {
return <String?, InstanceRef?>{
for (var variable in frame.vars!)
variable.name: variable.value as InstanceRef?,
};
}
62 changes: 48 additions & 14 deletions dwds/test/variable_scope_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,75 @@
import 'package:dwds/src/debugging/dart_scope.dart';
import 'package:dwds/src/services/chrome_proxy_service.dart';
import 'package:test/test.dart';
import 'package:test_common/logging.dart';
import 'package:test_common/test_sdk_configuration.dart';
import 'package:vm_service/vm_service.dart';

import 'fixtures/context.dart';
import 'fixtures/project.dart';

void main() {
final provider = TestSdkConfigurationProvider();
// set to true for debug logging.
final debug = false;

final provider = TestSdkConfigurationProvider(verbose: debug);
tearDownAll(provider.dispose);

final context =
TestContext(TestProject.testScopesWithSoundNullSafety, provider);

setUpAll(() async {
await context.setUp();
setCurrentLogWriter(debug: debug);
await context.setUp(verboseCompiler: debug);
});

tearDownAll(() async {
await context.tearDown();
});

group('ddcTemporaryVariableRegExp', () {
test('matches correctly', () {
expect(ddcTemporaryVariableRegExp.hasMatch(r't4$'), isTrue);
expect(ddcTemporaryVariableRegExp.hasMatch(r't4$0'), isTrue);
expect(ddcTemporaryVariableRegExp.hasMatch(r't4$10'), isTrue);
expect(ddcTemporaryVariableRegExp.hasMatch(r't4$0'), isTrue);
expect(ddcTemporaryVariableRegExp.hasMatch(r't1'), isTrue);
expect(ddcTemporaryVariableRegExp.hasMatch(r't10'), isTrue);
expect(ddcTemporaryVariableRegExp.hasMatch(r'__t$TL'), isTrue);
expect(ddcTemporaryVariableRegExp.hasMatch(r'__t$StringN'), isTrue);
expect(ddcTemporaryVariableRegExp.hasMatch(r'__t$IdentityMapOfString$T'),
group('temporary variable regular expression', () {
setUpAll(() => setCurrentLogWriter(debug: debug));
test('matches correctly for pre-patterns temporary variables', () {
expect(previousDdcTemporaryVariableRegExp.hasMatch(r't4$'), isTrue);
expect(previousDdcTemporaryVariableRegExp.hasMatch(r't4$0'), isTrue);
expect(previousDdcTemporaryVariableRegExp.hasMatch(r't4$10'), isTrue);
expect(previousDdcTemporaryVariableRegExp.hasMatch(r't4$0'), isTrue);
expect(previousDdcTemporaryVariableRegExp.hasMatch(r't1'), isTrue);
expect(previousDdcTemporaryVariableRegExp.hasMatch(r't10'), isTrue);
expect(previousDdcTemporaryVariableRegExp.hasMatch(r'__t$TL'), isTrue);
expect(
previousDdcTemporaryVariableRegExp.hasMatch(r'__t$StringN'), isTrue);
expect(
previousDdcTemporaryVariableRegExp
.hasMatch(r'__t$IdentityMapOfString$T'),
isTrue);

expect(previousDdcTemporaryVariableRegExp.hasMatch(r't'), isFalse);
expect(previousDdcTemporaryVariableRegExp.hasMatch(r't10foo'), isFalse);
expect(previousDdcTemporaryVariableRegExp.hasMatch(r't$10foo'), isFalse);
});

test('matches correctly for post-patterns temporary variables', () {
expect(ddcTemporaryVariableRegExp.hasMatch(r't$364$'), isTrue);
expect(ddcTemporaryVariableRegExp.hasMatch(r't$364$0'), isTrue);
expect(ddcTemporaryVariableRegExp.hasMatch(r't$364$10'), isTrue);
expect(ddcTemporaryVariableRegExp.hasMatch(r't$364$0'), isTrue);
expect(ddcTemporaryVariableRegExp.hasMatch(r't$361'), isTrue);
expect(ddcTemporaryVariableRegExp.hasMatch(r't$36$350$350'), isTrue);
expect(
ddcTemporaryVariableRegExp.hasMatch(r't$36$350$354$35isSet'), isTrue);
expect(ddcTemporaryTypeVariableRegExp.hasMatch(r'__t$TL'), isTrue);
expect(ddcTemporaryTypeVariableRegExp.hasMatch(r'__t$StringN'), isTrue);
expect(
ddcTemporaryTypeVariableRegExp.hasMatch(r'__t$IdentityMapOfString$T'),
isTrue);

expect(ddcTemporaryVariableRegExp.hasMatch(r't'), isFalse);
expect(ddcTemporaryVariableRegExp.hasMatch(r'this'), isFalse);
expect(ddcTemporaryVariableRegExp.hasMatch(r'\$this'), isFalse);
expect(ddcTemporaryVariableRegExp.hasMatch(r't10'), isFalse);
expect(ddcTemporaryVariableRegExp.hasMatch(r't10foo'), isFalse);
expect(ddcTemporaryVariableRegExp.hasMatch(r't$10foo'), isFalse);
expect(ddcTemporaryVariableRegExp.hasMatch(r'ten'), isFalse);
});
});

Expand Down Expand Up @@ -109,6 +141,8 @@ void main() {
};
}

setUpAll(() => setCurrentLogWriter(debug: debug));

setUp(() async {
service = context.service;
vm = await service.getVM();
Expand Down
6 changes: 2 additions & 4 deletions test_common/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ environment:
sdk: ">=3.0.0-134.0.dev <4.0.0"

dependencies:
dwds: 18.0.1
dwds:
path: ../dwds
file: ^6.1.3
logging: ^1.0.1
path: ^1.8.1
Expand All @@ -15,6 +16,3 @@ dependencies:
dev_dependencies:
lints: ^2.0.0

# dependency_overrides:
# dwds:
# path: ../dwds
2 changes: 2 additions & 0 deletions webdev/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## 3.0.3-dev

## 3.0.2

- Update `build_daemon` constraint to `^4.0.0`.
Expand Down
2 changes: 1 addition & 1 deletion webdev/lib/src/version.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions webdev/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: webdev
# Every time this changes you need to run `dart run build_runner build`.
version: 3.0.2
version: 3.0.3-dev
# We should not depend on a dev SDK before publishing.
# publish_to: none
description: >-
Expand Down Expand Up @@ -52,9 +52,9 @@ dev_dependencies:
webdriver: ^3.0.0

# Comment out before releasing webdev.
# dependency_overrides:
# dwds:
# path: ../dwds
dependency_overrides:
dwds:
path: ../dwds

executables:
webdev: