Skip to content

Commit d40c8a0

Browse files
jensjohacommit-bot@chromium.org
authored andcommitted
[kernel] Add 'leakingDebugToString' to nodes
This serves two purposes: 1) It can aid in debugging to better know which object you have. 2) It paves the way for a future re-design of toString so toString never leaks. Change-Id: Ice32209b19b961b7e92de829d8bee0ddd8bd6e93 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/122140 Commit-Queue: Jens Johansen <jensj@google.com> Reviewed-by: Johnni Winther <johnniwinther@google.com>
1 parent 8d8faa7 commit d40c8a0

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

pkg/compiler/lib/src/ir/closure.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:kernel/ast.dart' as ir;
6+
import 'package:kernel/text/ast_to_text.dart' as ir show debugNodeToString;
67

78
/// Collection of scope data collected for a single member.
89
class ClosureScopeModel {
@@ -414,4 +415,7 @@ class TypeVariableTypeWithContext implements ir.Node {
414415
String toString() =>
415416
'TypeVariableTypeWithContext(type=$type,context=$context,'
416417
'kind=$kind,typeDeclaration=$typeDeclaration)';
418+
419+
@override
420+
String leakingDebugToString() => ir.debugNodeToString(this);
417421
}

pkg/kernel/lib/ast.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ abstract class Node {
9797
/// (possibly synthesized) name, whereas other AST nodes return the complete
9898
/// textual representation of their subtree.
9999
String toString() => debugNodeToString(this);
100+
101+
/// Returns the textual representation of this node for use in debugging.
102+
///
103+
/// Note that this adds some nodes to a static map to ensure consistent
104+
/// naming, but that it thus also leaks memory.
105+
String leakingDebugToString() => debugNodeToString(this);
100106
}
101107

102108
/// A mutable AST node with a parent pointer.
@@ -5301,6 +5307,12 @@ abstract class Name implements Node {
53015307
visitChildren(Visitor v) {
53025308
// DESIGN TODO: Should we visit the library as a library reference?
53035309
}
5310+
5311+
/// Returns the textual representation of this node for use in debugging.
5312+
///
5313+
/// Note that this adds some nodes to a static map to ensure consistent
5314+
/// naming, but that it thus also leaks memory.
5315+
String leakingDebugToString() => debugNodeToString(this);
53045316
}
53055317

53065318
class _PrivateName extends Name {

0 commit comments

Comments
 (0)