From 9ceec72fb27b592f0adfbcbc1544ebec20798072 Mon Sep 17 00:00:00 2001 From: Nicholas Shahan Date: Wed, 5 Jun 2024 10:07:43 -0700 Subject: [PATCH 1/2] Hide more temporary variables when debugging Some variables created by DDC that are not present in the original source code were being shown by the debugger in the local scope. Update the regular expression used to detect temporary variable names. It has been simplified to: if the variable starts with 't$' or contains '$35' then it should be hidden. DDC names it's temporary variables to start with the characters `t$`. Hiding all of these does hide some valid variable names that could appear in the original source, but that is the status quo and not being changed here. In addition some names that are created by the CFE and added to the program contain an illegal character '#' which DDC replaces as '$35'. Variables with this sequence in the name can't appear in the original source so we hide them as well. This should hide variables synthetically added to support late local variables. --- dwds/lib/src/debugging/dart_scope.dart | 10 +++++++++- dwds/test/variable_scope_test.dart | 9 +++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/dwds/lib/src/debugging/dart_scope.dart b/dwds/lib/src/debugging/dart_scope.dart index 2b64b0ac3..5e340a65a 100644 --- a/dwds/lib/src/debugging/dart_scope.dart +++ b/dwds/lib/src/debugging/dart_scope.dart @@ -12,7 +12,15 @@ import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; /// 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 ddcTemporaryVariableRegExp = RegExp( + // Starts with t$ + r'^t\$' + // followed by anything + r'.*' + // or, + r'|' + // anything that contains the sequence '$35'. + r'.*\$35.*'); final ddcTemporaryTypeVariableRegExp = RegExp(r'^__t[\$\w*]+$'); /// Temporary variable regex before SDK changes for patterns. diff --git a/dwds/test/variable_scope_test.dart b/dwds/test/variable_scope_test.dart index 4d080f4f8..b879317b2 100644 --- a/dwds/test/variable_scope_test.dart +++ b/dwds/test/variable_scope_test.dart @@ -71,6 +71,14 @@ void main() { ddcTemporaryVariableRegExp.hasMatch(r't$36$350$354$35isSet'), isTrue, ); + expect( + ddcTemporaryVariableRegExp.hasMatch(r't$36$35variable$35isSet'), + isTrue, + ); + expect( + ddcTemporaryVariableRegExp.hasMatch(r'synthetic$35variable'), + isTrue, + ); expect(ddcTemporaryTypeVariableRegExp.hasMatch(r'__t$TL'), isTrue); expect(ddcTemporaryTypeVariableRegExp.hasMatch(r'__t$StringN'), isTrue); expect( @@ -84,6 +92,7 @@ void main() { expect(ddcTemporaryVariableRegExp.hasMatch(r't10'), isFalse); expect(ddcTemporaryVariableRegExp.hasMatch(r't10foo'), isFalse); expect(ddcTemporaryVariableRegExp.hasMatch(r'ten'), isFalse); + expect(ddcTemporaryVariableRegExp.hasMatch(r'my$3635variable'), isFalse); }); }); From 6ae731f61beebdce0bd6cc56eb85bbc74d38d83d Mon Sep 17 00:00:00 2001 From: Nicholas Shahan Date: Wed, 5 Jun 2024 10:30:37 -0700 Subject: [PATCH 2/2] Update CHANGELOG --- dwds/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dwds/CHANGELOG.md b/dwds/CHANGELOG.md index 9f835dfac..e6a48cfa2 100644 --- a/dwds/CHANGELOG.md +++ b/dwds/CHANGELOG.md @@ -4,6 +4,8 @@ - Respect the value of `pause_isolates_on_start` during page-refreshes. - [#2431](https://github.com/dart-lang/webdev/pull/2431) - Fix issue where DAP clients wouldn't resume after a restart. - [#2441](https://github.com/dart-lang/webdev/pull/2441) - Add implementation for the VM Service's `getFlagList` API. - [#2438](https://github.com/dart-lang/webdev/pull/2438) +- Hide more variables from the local scope when debugging. These variables were synthetically added by the compiler to + support late local variables and don't appear in the original source code. - [#2445](https://github.com/dart-lang/webdev/pull/2445) ## 24.0.0