Search in sources :

Example 11 with IntSet

use of it.unimi.dsi.fastutil.ints.IntSet in project gradle by gradle.

the class ClassSetAnalysisData method reduceToTypesAffecting.

/**
 * Returns a shrunk down version of this class set, which only contains information about types that could affect the other set.
 * This is useful for reducing the size of classpath snapshots, since a classpath usually contains a lot more types than the client
 * actually uses.
 *
 * Apart from the obvious classes that are directly used by the other set, we also need to keep any classes that might affect any number
 * of classes, like package-info, module-info and inlineable constants.
 */
public ClassSetAnalysisData reduceToTypesAffecting(ClassSetAnalysisData other, CompilerApiData compilerApiData) {
    if (fullRebuildCause != null) {
        return this;
    }
    Set<String> usedClasses = new HashSet<>(classHashes.size());
    for (Map.Entry<String, DependentsSet> entry : dependents.entrySet()) {
        if (entry.getValue().isDependencyToAll()) {
            usedClasses.add(entry.getKey());
        }
    }
    for (String cls : classHashes.keySet()) {
        if (cls.endsWith(PACKAGE_INFO)) {
            usedClasses.add(cls);
        }
    }
    usedClasses.addAll(other.dependents.keySet());
    Multimap<String, String> dependencies = getForwardDependencyView();
    Set<String> visited = new HashSet<>(usedClasses.size());
    Deque<String> pending = new ArrayDeque<>(usedClasses);
    while (!pending.isEmpty()) {
        String cls = pending.poll();
        if (visited.add(cls)) {
            usedClasses.add(cls);
            pending.addAll(dependencies.get(cls));
        }
    }
    Set<String> usedConstantSources = compilerApiData.isSupportsConstantsMapping() ? compilerApiData.getConstantToClassMapping().getConstantDependents().keySet() : classesToConstants.keySet();
    usedClasses.addAll(usedConstantSources);
    Map<String, HashCode> classHashes = new HashMap<>(usedClasses.size());
    Map<String, DependentsSet> dependents = new HashMap<>(usedClasses.size());
    Map<String, IntSet> classesToConstants = new HashMap<>(usedClasses.size());
    for (String usedClass : usedClasses) {
        HashCode hash = this.classHashes.get(usedClass);
        if (hash != null) {
            classHashes.put(usedClass, hash);
            DependentsSet dependentsSet = this.dependents.get(usedClass);
            if (dependentsSet != null) {
                if (dependentsSet.isDependencyToAll()) {
                    dependents.put(usedClass, dependentsSet);
                } else {
                    Set<String> usedAccessibleClasses = new HashSet<>(dependentsSet.getAccessibleDependentClasses());
                    usedAccessibleClasses.retainAll(usedClasses);
                    if (!usedAccessibleClasses.isEmpty()) {
                        dependents.put(usedClass, DependentsSet.dependentClasses(Collections.emptySet(), usedAccessibleClasses));
                    }
                }
            }
            IntSet constants = this.classesToConstants.get(usedClass);
            if (constants != null && usedConstantSources.contains(usedClass)) {
                classesToConstants.put(usedClass, constants);
            }
        }
    }
    return new ClassSetAnalysisData(classHashes, dependents, classesToConstants, null);
}
Also used : DependentsSet(org.gradle.api.internal.tasks.compile.incremental.compilerapi.deps.DependentsSet) HashMap(java.util.HashMap) IntSet(it.unimi.dsi.fastutil.ints.IntSet) ArrayDeque(java.util.ArrayDeque) HashCode(org.gradle.internal.hash.HashCode) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashSet(java.util.HashSet)

Example 12 with IntSet

use of it.unimi.dsi.fastutil.ints.IntSet in project gradle by gradle.

the class ClassAnalysisSerializer method read.

@Override
public ClassAnalysis read(Decoder decoder) throws Exception {
    String className = decoder.readString();
    boolean relatedToAll = decoder.readBoolean();
    Set<String> classes = STRING_SET_SERIALIZER.read(decoder);
    IntSet constants = IntSetSerializer.INSTANCE.read(decoder);
    Set<String> superTypes = STRING_SET_SERIALIZER.read(decoder);
    return new ClassAnalysis(className, classes, relatedToAll, constants, superTypes);
}
Also used : IntSet(it.unimi.dsi.fastutil.ints.IntSet) ClassAnalysis(org.gradle.api.internal.tasks.compile.incremental.deps.ClassAnalysis)

Example 13 with IntSet

use of it.unimi.dsi.fastutil.ints.IntSet in project gradle by gradle.

the class ClassDependenciesVisitor method analyze.

public static ClassAnalysis analyze(String className, ClassReader reader) {
    IntSet constants = new IntOpenHashSet(2);
    Set<String> classDependencies = Sets.newHashSet();
    ClassDependenciesVisitor visitor = new ClassDependenciesVisitor(constants, classDependencies, new ClassRelevancyFilter(className), reader);
    reader.accept(visitor, ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
    return new ClassAnalysis(className, classDependencies, visitor.isDependencyToAll(), constants, visitor.getSuperTypes());
}
Also used : IntOpenHashSet(it.unimi.dsi.fastutil.ints.IntOpenHashSet) IntSet(it.unimi.dsi.fastutil.ints.IntSet) ClassAnalysis(org.gradle.api.internal.tasks.compile.incremental.deps.ClassAnalysis)

Example 14 with IntSet

use of it.unimi.dsi.fastutil.ints.IntSet in project gradle by gradle.

the class JarSnapshot method getRelevantConstants.

public IntSet getRelevantConstants(JarSnapshot other, Set<String> affectedClasses) {
    IntSet result = new IntOpenHashSet();
    for (String affectedClass : affectedClasses) {
        IntSet difference = new IntOpenHashSet(other.getData().data.getConstants(affectedClass));
        difference.removeAll(data.data.getConstants(affectedClass));
        result.addAll(difference);
    }
    return result;
}
Also used : IntOpenHashSet(it.unimi.dsi.fastutil.ints.IntOpenHashSet) IntSet(it.unimi.dsi.fastutil.ints.IntSet)

Example 15 with IntSet

use of it.unimi.dsi.fastutil.ints.IntSet in project gradle by gradle.

the class PreviousCompilation method getDependents.

public DependentsSet getDependents(String className, IntSet newConstants) {
    IntSet constants = new IntOpenHashSet(analysis.getData().getConstants(className));
    constants.removeAll(newConstants);
    return analysis.getRelevantDependents(className, constants);
}
Also used : IntOpenHashSet(it.unimi.dsi.fastutil.ints.IntOpenHashSet) IntSet(it.unimi.dsi.fastutil.ints.IntSet)

Aggregations

IntSet (it.unimi.dsi.fastutil.ints.IntSet)20 IntOpenHashSet (it.unimi.dsi.fastutil.ints.IntOpenHashSet)12 HashMap (java.util.HashMap)3 DependentsSet (org.gradle.api.internal.tasks.compile.incremental.compilerapi.deps.DependentsSet)3 ArrayDeque (java.util.ArrayDeque)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 ClassAnalysis (org.gradle.api.internal.tasks.compile.incremental.deps.ClassAnalysis)2 Page (com.facebook.presto.common.Page)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 LeafEntry (de.lmu.ifi.dbs.elki.index.tree.LeafEntry)1 SpatialEntry (de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialEntry)1 DeLiCluDirectoryEntry (de.lmu.ifi.dbs.elki.index.tree.spatial.rstarvariants.deliclu.DeLiCluDirectoryEntry)1 DeLiCluEntry (de.lmu.ifi.dbs.elki.index.tree.spatial.rstarvariants.deliclu.DeLiCluEntry)1 DeLiCluNode (de.lmu.ifi.dbs.elki.index.tree.spatial.rstarvariants.deliclu.DeLiCluNode)1 IntArraySet (it.unimi.dsi.fastutil.ints.IntArraySet)1 IntIterator (it.unimi.dsi.fastutil.ints.IntIterator)1 IOException (java.io.IOException)1 ConciseBitmapFactory (org.apache.druid.collections.bitmap.ConciseBitmapFactory)1 MutableBitmap (org.apache.druid.collections.bitmap.MutableBitmap)1