Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(196)

Unified Diff: pkg/analyzer/lib/src/dart/element/element.dart

Issue 1650873002: Fix memory leak in incremental resolver (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer/lib/src/dart/element/element.dart
diff --git a/pkg/analyzer/lib/src/dart/element/element.dart b/pkg/analyzer/lib/src/dart/element/element.dart
index 1ae2e9d9a18c6a469d42a3f0e508a28bb0c55fb0..4139cd188265456c289ba8676c338e6d8d7634f7 100644
--- a/pkg/analyzer/lib/src/dart/element/element.dart
+++ b/pkg/analyzer/lib/src/dart/element/element.dart
@@ -1706,6 +1706,13 @@ abstract class ElementImpl implements Element {
int _docRangeLength;
/**
+ * If true, the element is being used as a map key.
+ * Mutations that change operator== (and hashCode)
+ * will throw an exception.
+ */
+ bool frozen = false;
Brian Wilkerson 2016/02/01 14:58:16 This would be better implemented as a Modifier bec
skybrian 2016/02/02 02:12:19 Hmm. That apparently makes it part of the public A
Brian Wilkerson 2016/02/02 16:32:06 I'm not sure why. The class Modifier isn't part of
+
+ /**
* Initialize a newly created element to have the given [name] at the given
* [_nameOffset].
*/
@@ -1755,6 +1762,7 @@ abstract class ElementImpl implements Element {
* Set the enclosing element of this element to the given [element].
*/
void set enclosingElement(Element element) {
+ _checkNotFrozen();
_enclosingElement = element as ElementImpl;
_cachedLocation = null;
_cachedHashCode = null;
@@ -1836,6 +1844,7 @@ abstract class ElementImpl implements Element {
String get name => _name;
void set name(String name) {
+ _checkNotFrozen();
scheglov 2016/02/01 16:01:25 The location of an Element consists of identifiers
Brian Wilkerson 2016/02/01 16:11:58 Good point! If we went with the method on CachePa
Brian Wilkerson 2016/02/02 16:32:06 It seems to me that the consequences are that we'r
this._name = name;
_cachedLocation = null;
_cachedHashCode = null;
@@ -1852,6 +1861,7 @@ abstract class ElementImpl implements Element {
* declaration of this element.
*/
void set nameOffset(int offset) {
+ _checkNotFrozen();
_nameOffset = offset;
_cachedHashCode = null;
_cachedLocation = null;
@@ -2015,6 +2025,13 @@ abstract class ElementImpl implements Element {
void visitChildren(ElementVisitor visitor) {
// There are no children to visit
}
+
+ void _checkNotFrozen() {
+ if (frozen) {
+ //print("$this at $location is frozen and can't be mutated");
Brian Wilkerson 2016/02/01 14:58:16 Remove debugging code.
skybrian 2016/02/02 01:16:54 I've seen other commented out debugging code check
skybrian 2016/02/02 02:12:19 Done.
Brian Wilkerson 2016/02/02 16:32:06 It's a judgement call. Commented out code tends to
+ throw new StateError("$this at $location is frozen and can't be mutated");
+ }
+ }
}
/**
@@ -4107,8 +4124,8 @@ class ParameterElementImpl extends VariableElementImpl
/**
* Creates a synthetic parameter with [name], [type] and [kind].
*/
- factory ParameterElementImpl.synthetic(String name, DartType type,
- ParameterKind kind) {
+ factory ParameterElementImpl.synthetic(
+ String name, DartType type, ParameterKind kind) {
ParameterElementImpl element = new ParameterElementImpl(name, -1);
element.type = type;
element.synthetic = true;

Powered by Google App Engine
This is Rietveld 408576698