Skip to content

Commit

Permalink
Automated rollback of commit cc6bc69.
Browse files Browse the repository at this point in the history
*** Reason for rollback ***

Causing b/264944549

See also #3710

*** Original change description ***

Optimize `VisitorState#getSymbolFromName`

By delegating module lookup to `Symtab#inferModule`.

Fixes #3504

***

PiperOrigin-RevId: 501049979
  • Loading branch information
graememorgan authored and Error Prone Team committed Jan 10, 2023
1 parent 4a71fa8 commit 3a240e3
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions check_api/src/main/java/com/google/errorprone/VisitorState.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@
import com.sun.tools.javac.code.Type.ArrayType;
import com.sun.tools.javac.code.Type.ClassType;
import com.sun.tools.javac.code.Types;
import com.sun.tools.javac.comp.Modules;
import com.sun.tools.javac.model.JavacElements;
import com.sun.tools.javac.parser.Tokens.Token;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
import com.sun.tools.javac.tree.TreeMaker;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.Convert;
import com.sun.tools.javac.util.Name;
import com.sun.tools.javac.util.Names;
import com.sun.tools.javac.util.Options;
Expand Down Expand Up @@ -406,8 +406,20 @@ public Name binaryNameFromClassname(String className) {
*/
@Nullable
public ClassSymbol getSymbolFromName(Name name) {
ModuleSymbol msym = getSymtab().inferModule(Convert.packagePart(name));
return msym != null ? getSymbolFromString(msym, name) : null;
boolean modular = sharedState.modules.getDefaultModule() != getSymtab().noModule;
if (!modular) {
return getSymbolFromString(getSymtab().noModule, name);
}
for (ModuleSymbol msym : sharedState.modules.allModules()) {
ClassSymbol result = getSymbolFromString(msym, name);
if (result != null) {
// TODO(cushon): the path where we iterate over all modules is probably slow.
// Try to learn some lessons from JDK-8189747, and consider disallowing this case and
// requiring users to call the getSymbolFromString(ModuleSymbol, Name) overload instead.
return result;
}
}
return null;
}

@Nullable
Expand Down Expand Up @@ -723,6 +735,7 @@ public static <T> Supplier<T> memoize(Supplier<T> f) {
* {@code SomeClass.instance(context)} has sizable performance improvements in aggregate.
*/
private static final class SharedState {
private final Modules modules;
private final Names names;
private final Symtab symtab;
private final ErrorProneTimings timings;
Expand All @@ -746,6 +759,7 @@ private static final class SharedState {
StatisticsCollector statisticsCollector,
Map<String, SeverityLevel> severityMap,
ErrorProneOptions errorProneOptions) {
this.modules = Modules.instance(context);
this.names = Names.instance(context);
this.symtab = Symtab.instance(context);
this.timings = ErrorProneTimings.instance(context);
Expand Down

0 comments on commit 3a240e3

Please sign in to comment.