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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/js_backend/backend.dart

Issue 654903002: Remove ResolutionEnqueuer.isLive (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add test. Created 6 years, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of js_backend; 5 part of js_backend;
6 6
7 const VERBOSE_OPTIMIZER_HINTS = false; 7 const VERBOSE_OPTIMIZER_HINTS = false;
8 8
9 class JavaScriptItemCompilationContext extends ItemCompilationContext { 9 class JavaScriptItemCompilationContext extends ItemCompilationContext {
10 final Set<HInstruction> boundsChecked = new Set<HInstruction>(); 10 final Set<HInstruction> boundsChecked = new Set<HInstruction>();
(...skipping 1911 matching lines...) Expand 10 before | Expand all | Expand 10 after
1922 // Compute a mapping from class to the closures it contains, so we 1922 // Compute a mapping from class to the closures it contains, so we
1923 // can include the correct ones when including the class. 1923 // can include the correct ones when including the class.
1924 Map<ClassElement, List<LocalFunctionElement>> closureMap = 1924 Map<ClassElement, List<LocalFunctionElement>> closureMap =
1925 new Map<ClassElement, List<LocalFunctionElement>>(); 1925 new Map<ClassElement, List<LocalFunctionElement>>();
1926 for (LocalFunctionElement closure in compiler.resolverWorld.allClosures) { 1926 for (LocalFunctionElement closure in compiler.resolverWorld.allClosures) {
1927 closureMap.putIfAbsent(closure.enclosingClass, () => []).add(closure); 1927 closureMap.putIfAbsent(closure.enclosingClass, () => []).add(closure);
1928 } 1928 }
1929 bool foundClosure = false; 1929 bool foundClosure = false;
1930 Set<Element> reflectableMembers = new Set<Element>(); 1930 Set<Element> reflectableMembers = new Set<Element>();
1931 ResolutionEnqueuer resolution = compiler.enqueuer.resolution; 1931 ResolutionEnqueuer resolution = compiler.enqueuer.resolution;
1932 for (ClassElement cls in resolution.universe.instantiatedClasses) { 1932 for (ClassElement cls in resolution.universe.directlyInstantiatedClasses) {
1933 // Do not process internal classes. 1933 // Do not process internal classes.
1934 if (cls.library.isInternalLibrary || cls.isInjected) continue; 1934 if (cls.library.isInternalLibrary || cls.isInjected) continue;
1935 if (referencedFromMirrorSystem(cls)) { 1935 if (referencedFromMirrorSystem(cls)) {
1936 Set<Name> memberNames = new Set<Name>(); 1936 Set<Name> memberNames = new Set<Name>();
1937 // 1) the class (should be live) 1937 // 1) the class (should be resolved)
1938 assert(invariant(cls, resolution.isLive(cls))); 1938 assert(invariant(cls, cls.isResolved));
1939 reflectableMembers.add(cls); 1939 reflectableMembers.add(cls);
1940 // 2) its constructors (if live) 1940 // 2) its constructors (if resolved)
1941 cls.constructors.forEach((Element constructor) { 1941 cls.constructors.forEach((Element constructor) {
1942 if (resolution.isLive(constructor)) { 1942 if (resolution.hasBeenResolved(constructor)) {
1943 reflectableMembers.add(constructor); 1943 reflectableMembers.add(constructor);
1944 } 1944 }
1945 }); 1945 });
1946 // 3) all members, including fields via getter/setters (if live) 1946 // 3) all members, including fields via getter/setters (if resolved)
1947 cls.forEachClassMember((Member member) { 1947 cls.forEachClassMember((Member member) {
1948 if (resolution.isLive(member.element)) { 1948 if (resolution.hasBeenResolved(member.element)) {
1949 memberNames.add(member.name); 1949 memberNames.add(member.name);
1950 reflectableMembers.add(member.element); 1950 reflectableMembers.add(member.element);
1951 } 1951 }
1952 }); 1952 });
1953 // 4) all overriding members of subclasses/subtypes (should be live) 1953 // 4) all overriding members of subclasses/subtypes (should be resolved)
1954 if (compiler.world.hasAnySubtype(cls)) { 1954 if (compiler.world.hasAnySubtype(cls)) {
1955 for (ClassElement subcls in compiler.world.subtypesOf(cls)) { 1955 for (ClassElement subcls in compiler.world.subtypesOf(cls)) {
1956 subcls.forEachClassMember((Member member) { 1956 subcls.forEachClassMember((Member member) {
1957 if (memberNames.contains(member.name)) { 1957 if (memberNames.contains(member.name)) {
1958 // TODO(20993): find out why this assertion fails. 1958 // TODO(20993): find out why this assertion fails.
1959 // assert(invariant(member.element, 1959 // assert(invariant(member.element,
1960 // resolution.isLive(member.element))); 1960 // resolution.hasBeenResolved(member.element)));
1961 if (resolution.isLive(member.element)) { 1961 if (resolution.hasBeenResolved(member.element)) {
1962 reflectableMembers.add(member.element); 1962 reflectableMembers.add(member.element);
1963 } 1963 }
1964 } 1964 }
1965 }); 1965 });
1966 } 1966 }
1967 } 1967 }
1968 // 5) all its closures 1968 // 5) all its closures
1969 List<LocalFunctionElement> closures = closureMap[cls]; 1969 List<LocalFunctionElement> closures = closureMap[cls];
1970 if (closures != null) { 1970 if (closures != null) {
1971 reflectableMembers.addAll(closures); 1971 reflectableMembers.addAll(closures);
1972 foundClosure = true; 1972 foundClosure = true;
1973 } 1973 }
1974 } else { 1974 } else {
1975 // check members themselves 1975 // check members themselves
1976 cls.constructors.forEach((ConstructorElement element) { 1976 cls.constructors.forEach((ConstructorElement element) {
1977 if (!compiler.enqueuer.resolution.isLive(element)) return; 1977 if (!resolution.hasBeenResolved(element)) return;
1978 if (referencedFromMirrorSystem(element, false)) { 1978 if (referencedFromMirrorSystem(element, false)) {
1979 reflectableMembers.add(element); 1979 reflectableMembers.add(element);
1980 } 1980 }
1981 }); 1981 });
1982 cls.forEachClassMember((Member member) { 1982 cls.forEachClassMember((Member member) {
1983 if (!compiler.enqueuer.resolution.isLive(member.element)) return; 1983 if (!resolution.hasBeenResolved(member.element)) return;
1984 if (referencedFromMirrorSystem(member.element, false)) { 1984 if (referencedFromMirrorSystem(member.element, false)) {
1985 reflectableMembers.add(member.element); 1985 reflectableMembers.add(member.element);
1986 } 1986 }
1987 }); 1987 });
1988 // Also add in closures. Those might be reflectable is their enclosing 1988 // Also add in closures. Those might be reflectable is their enclosing
1989 // member is. 1989 // member is.
1990 List<LocalFunctionElement> closures = closureMap[cls]; 1990 List<LocalFunctionElement> closures = closureMap[cls];
1991 if (closures != null) { 1991 if (closures != null) {
1992 for (LocalFunctionElement closure in closures) { 1992 for (LocalFunctionElement closure in closures) {
1993 if (referencedFromMirrorSystem(closure.memberContext, false)) { 1993 if (referencedFromMirrorSystem(closure.memberContext, false)) {
1994 reflectableMembers.add(closure); 1994 reflectableMembers.add(closure);
1995 foundClosure = true; 1995 foundClosure = true;
1996 } 1996 }
1997 } 1997 }
1998 } 1998 }
1999 } 1999 }
2000 } 2000 }
2001 // We also need top-level non-class elements like static functions and 2001 // We also need top-level non-class elements like static functions and
2002 // global fields. We use the resolution queue to decide which elements are 2002 // global fields. We use the resolution queue to decide which elements are
2003 // part of the live world. 2003 // part of the live world.
2004 for (LibraryElement lib in compiler.libraryLoader.libraries) { 2004 for (LibraryElement lib in compiler.libraryLoader.libraries) {
2005 if (lib.isInternalLibrary) continue; 2005 if (lib.isInternalLibrary) continue;
2006 lib.forEachLocalMember((Element member) { 2006 lib.forEachLocalMember((Element member) {
2007 if (!member.isClass && 2007 if (!member.isClass &&
2008 compiler.enqueuer.resolution.isLive(member) && 2008 resolution.hasBeenResolved(member) &&
2009 referencedFromMirrorSystem(member)) { 2009 referencedFromMirrorSystem(member)) {
2010 reflectableMembers.add(member); 2010 reflectableMembers.add(member);
2011 } 2011 }
2012 }); 2012 });
2013 } 2013 }
2014 // And closures inside top-level elements that do not have a surrounding 2014 // And closures inside top-level elements that do not have a surrounding
2015 // class. These will be in the [:null:] bucket of the [closureMap]. 2015 // class. These will be in the [:null:] bucket of the [closureMap].
2016 if (closureMap.containsKey(null)) { 2016 if (closureMap.containsKey(null)) {
2017 for (Element closure in closureMap[null]) { 2017 for (Element closure in closureMap[null]) {
2018 if (referencedFromMirrorSystem(closure)) { 2018 if (referencedFromMirrorSystem(closure)) {
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
2436 } 2436 }
2437 } 2437 }
2438 2438
2439 /// Records that [constant] is used by the element behind [registry]. 2439 /// Records that [constant] is used by the element behind [registry].
2440 class Dependency { 2440 class Dependency {
2441 final ConstantValue constant; 2441 final ConstantValue constant;
2442 final Element annotatedElement; 2442 final Element annotatedElement;
2443 2443
2444 const Dependency(this.constant, this.annotatedElement); 2444 const Dependency(this.constant, this.annotatedElement);
2445 } 2445 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698