Unnamed: 0
int64
0
305k
body
stringlengths
7
52.9k
name
stringlengths
1
185
33,900
String () { return super.toString() + " MAYBE_YIELD"; }
toString
33,901
boolean () { return myNegated; }
isNegated
33,902
String () { @NonNls StringBuilder builder = new StringBuilder(); builder.append("Condition ").append(getElement()); if (myNegated) builder.append(", negated"); if (myDependent.size() > 1) { builder.append(", dependent: "); builder.append(StringUtil.join(ContainerUtil.filter(myDependent, d -> d != this), i -> String.valueOf(i.num()), ", ")); } return builder.toString(); }
getElementPresentation
33,903
Set<ConditionInstruction> () { return myDependent; }
getDependentConditions
33,904
String () { return super.toString() + " MAYBE_RETURN"; }
toString
33,905
boolean () { GrExpression expression = (GrExpression) getElement(); assert expression != null; final PsiType type = expression.getType(); return !PsiTypes.voidType().equals(type) && !PsiUtil.isVoidMethodCall(expression); }
mayReturnValue
33,906
GrControlFlowPolicy () { return INSTANCE; }
getInstance
33,907
boolean (@NotNull GrReferenceExpression ref) { return !ref.isQualified() || isThisRef(ref.getQualifierExpression()); }
isReferenceAccepted
33,908
boolean (@NotNull GrVariable variable) { return true; }
isVariableInitialized
33,909
String () { @NonNls final StringBuilder builder = new StringBuilder(); builder.append(num()); builder.append("("); for (Instruction successor : allSuccessors()) { builder.append(successor.num()); builder.append(','); } if (allPredecessors().iterator().hasNext()) builder.delete(builder.length() - 1, builder.length()); builder.append(") ").append("THROW. ").append(getElementPresentation()); return builder.toString(); }
toString
33,910
boolean (@NotNull GrReferenceExpression ref) { return !ref.isQualified() || isThisRef(ref.getQualifierExpression()); }
isReferenceAccepted
33,911
boolean (@NotNull GrVariable variable) { return variable.getInitializerGroovy() != null || hasTupleInitializer(variable) || variable instanceof GrParameter; }
isVariableInitialized
33,912
boolean (@NotNull GrVariable variable) { final PsiElement parent = variable.getParent(); return parent instanceof GrVariableDeclaration && ((GrVariableDeclaration)parent).getTupleInitializer() != null; }
hasTupleInitializer
33,913
GrResolverPolicy () { return INSTANCE; }
getInstance
33,914
Deque<CallInstruction> (@NotNull Instruction instruction) { return myEnv.get(instruction.num()); }
callStack
33,915
void (@NotNull Deque<CallInstruction> callStack, @NotNull Instruction instruction) { myEnv.set(instruction.num(), callStack); }
update
33,916
List<Optional<E>> (int n) { //noinspection unchecked Optional<E>[] optionals = new Optional[n]; Arrays.fill(optionals, Optional.empty()); return Arrays.asList(optionals); }
getEmptyInfo
33,917
List<E> (@NotNull Instruction instruction, @NotNull List<Optional<E>> info, @NotNull CallEnvironment env) { List<E> prevInfos = new SmartList<>(); for (Instruction i : getPrevious(instruction, env)) { Optional<E> prevInfo = info.get(i.num()); prevInfo.ifPresent(e -> prevInfos.add(e)); } return prevInfos; }
getPrevInfos
33,918
Iterable<Instruction> (@NotNull Instruction instruction, @NotNull CallEnvironment env) { return myDfa.isForward() ? instruction.predecessors(env) : instruction.successors(env); }
getPrevious
33,919
Iterable<Instruction> (@NotNull Instruction instruction, @NotNull CallEnvironment env) { return myDfa.isForward() ? instruction.successors(env) : instruction.predecessors(env); }
getNext
33,920
boolean () { if (myCounter == null) { myCounter = new WorkCounter(); return false; } return myCounter.isTimeOver(); }
checkCounter
33,921
long () { return ourThreadMXBean != null ? ourThreadMXBean.getCurrentThreadUserTime() : System.nanoTime(); }
getCurrentTime
33,922
boolean () { return getCurrentTime() - myStart > myTimeLimit; }
isTimeOver
33,923
DFAType (@Nullable PsiType mixin, @Nullable ConditionInstruction instruction) { if (mixin == null) { return this; } Mixin newMixin = new Mixin(mixin, instruction, instruction != null && instruction.isNegated()); if (mixins.contains(newMixin)) { return this; } DFAType newDfaType = new DFAType(this.primary); newDfaType.mixins.addAll(this.mixins); newDfaType.mixins.add(newMixin); return newDfaType; }
withNewMixin
33,924
DFAType (@NotNull NegatingGotoInstruction negation) { if (mixins.isEmpty()) { return this; } final Set<ConditionInstruction> conditionsToNegate = negation.getCondition().getDependentConditions(); if (ContainerUtil.and(mixins, mixin -> !conditionsToNegate.contains(mixin.myCondition))) { return this; } DFAType result = copy(); for (ListIterator<Mixin> iterator = result.mixins.listIterator(); iterator.hasNext(); ) { Mixin mixin = iterator.next(); if (conditionsToNegate.contains(mixin.myCondition)) { iterator.set(mixin.negate()); } } return result; }
withNegated
33,925
DFAType (DFAType t1, DFAType t2, PsiManager manager) { if (t1.equals(t2)) return t1; if (dominates(t1, t2)) { return t1; } if (dominates(t2, t1)) { return t2; } final PsiType primary = TypesUtil.getLeastUpperBoundNullable(t1.primary, t2.primary, manager); final PsiType type1 = reduce(t1.mixins); final PsiType type2 = reduce(t2.mixins); if (type1 != null && type2 != null) { return create(primary).withNewMixin(GenericsUtil.getLeastUpperBound(type1, type2, manager), null); } return create(primary); }
merge
33,926
boolean (Object obj) { if (obj == this) return true; if (!(obj instanceof DFAType other)) return false; if (!eq(primary, other.primary)) return false; if (mixins.size() != other.mixins.size()) return false; for (Mixin mixin1 : mixins) { boolean contains = false; for (Mixin mixin2 : other.mixins) { if (mixin1.equals(mixin2)) { contains = mixin1.myNegated == mixin2.myNegated; break; } } if (!contains) return false; } return true; }
equals
33,927
PsiType () { if (mixins.isEmpty()) return primary; List<PsiType> types = new ArrayList<>(); if (primary != null) { types.add(primary); } for (Mixin mixin : mixins) { if (mixin.myNegated) { continue; } if (mixin.myType.equals(PsiTypes.nullType())) { continue; } types.add(mixin.myType); } if (types.isEmpty()) return null; return PsiIntersectionType.createIntersection(types.toArray(PsiType.createArray(types.size()))); }
getResultType
33,928
DFAType (@Nullable PsiType type) { return type == null ? NULL_DFA_TYPE : new DFAType(type); }
create
33,929
boolean (PsiType t1, PsiType t2) { return t1 == t2 || Comparing.equal(TypeConversionUtil.erasure(t1), TypeConversionUtil.erasure(t2)); }
eq
33,930
boolean (DFAType dominating, DFAType dominated) { boolean primaryDominating = dominated.primary == null || dominated.primary == PsiTypes.nullType() || dominated.primary == dominating.primary; if (!primaryDominating) return false; return dominating.mixins.isEmpty() || dominated.mixins == dominating.mixins; }
dominates
33,931
PsiType (List<Mixin> mixins) { List<PsiType> types = mixins.stream() .filter(it -> !it.myNegated) .map(it -> it.myType) .collect(toList()); return types.isEmpty() ? null : PsiIntersectionType.createIntersection(types); }
reduce
33,932
DFAType () { final DFAType type = new DFAType(primary); type.mixins.addAll(mixins); return type; }
copy
33,933
String () { return "{" + primary + " : " + mixins + "}"; }
toString
33,934
Mixin () { return new Mixin(myType, myCondition, !myNegated); }
negate
33,935
String () { return (myNegated ? "!" : "") + myType; }
toString
33,936
boolean (Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Mixin mixin = (Mixin)o; if (!myType.equals(mixin.myType)) return false; if (!Objects.equals(myCondition, mixin.myCondition)) return false; return true; }
equals
33,937
int () { int result = myType.hashCode(); result = 31 * result + (myCondition != null ? myCondition.hashCode() : 0); return result; }
hashCode
33,938
TypeDfaState (@NotNull List<? extends TypeDfaState> ins) { if (ins.size() == 0) { return TypeDfaState.EMPTY_STATE; } if (ins.size() == 1) { return ins.get(0); } TypeDfaState result = ins.get(0); for (int i = 1; i < ins.size(); i++) { if (ins.get(i) != TypeDfaState.EMPTY_STATE) { result = TypeDfaState.merge(result, ins.get(i), myManager); } else { return TypeDfaState.EMPTY_STATE; } } return result; }
join
33,939
boolean (@NotNull TypeDfaState e1, @NotNull TypeDfaState e2) { return e1 == e2 || e1.contentsEqual(e2); }
eq
33,940
Int2ObjectMap<DFAType> (@NotNull Int2ObjectMap<DFAType> cached, @Nullable TypeDfaState candidate) { if (candidate == null || candidate.getRawVarTypes().isEmpty()) { return cached; } List<Int2ObjectMap.Entry<DFAType>> newTypes = new SmartList<>(); for (Int2ObjectMap.Entry<DFAType> candidateEntry : candidate.getRawVarTypes().int2ObjectEntrySet()) { int index = candidateEntry.getIntKey(); if (candidate.isProhibited(index) || (cached.containsKey(index) && checkDfaStatesConsistency(cached, candidateEntry))) { continue; } newTypes.add(candidateEntry); } if (newTypes.isEmpty()) { return cached; } Int2ObjectMap<DFAType> newState = new Int2ObjectOpenHashMap<>(cached.size() + newTypes.size()); newState.putAll(cached); for (var entry : newTypes) { newState.put(entry.getIntKey(), entry.getValue()); } return newState; }
mergeForCaching
33,941
boolean (@NotNull Int2ObjectMap<DFAType> cached, @NotNull Int2ObjectMap.Entry<DFAType> incoming) { if (!ApplicationManager.getApplication().isUnitTestMode() || ApplicationManagerEx.isInStressTest() || DfaCacheConsistencyKt.mustSkipConsistencyCheck()) { return true; } DFAType cachedType = cached.get(incoming.getIntKey()); if (cachedType != null && !Objects.equals(cachedType, incoming.getValue())) { throw new IllegalStateException("Attempt to cache different types: for descriptor " + incoming.getIntKey() + ", existing was " + cachedType + " and incoming is " + incoming.getValue()); } return true; }
checkDfaStatesConsistency
33,942
TypeDfaState (@NotNull TypeDfaState left, @NotNull TypeDfaState right, PsiManager manager) { if (left == right) { return left; } Int2ObjectMap<DFAType> dominantMap = guessDominantMap(left.myVarTypes, right.myVarTypes); if (dominates(left, right, dominantMap)) { return left; } if (dominates(right, left, dominantMap)) { return right; } BitSet resultSet = mergeProhibitedVariables(left.myProhibitedCachingVars, right.myProhibitedCachingVars); Int2ObjectMap<DFAType> resultMap = dominantMap != null ? dominantMap : mergeTypeMaps(left.myVarTypes, right.myVarTypes, manager, resultSet); return new TypeDfaState(resultMap, resultSet); }
merge
33,943
TypeDfaState (int variableIndex, @NotNull DFAType type) { BitSet newSet; if (variableIndex == 0 || !myProhibitedCachingVars.get(variableIndex)) { newSet = myProhibitedCachingVars; } else { newSet = (BitSet)myProhibitedCachingVars.clone(); newSet.set(variableIndex, false); } Int2ObjectMap<DFAType> newTypes; if (myVarTypes.get(variableIndex) == type) { newTypes = myVarTypes; } else { newTypes = new Int2ObjectOpenHashMap<>(myVarTypes); newTypes.put(variableIndex, type); } if (newSet == myProhibitedCachingVars && newTypes == myVarTypes) { return this; } else { return new TypeDfaState(newTypes, newSet); } }
withNewType
33,944
TypeDfaState (int variableIndex) { if (variableIndex == 0 || myProhibitedCachingVars.get(variableIndex)) { return this; } BitSet newProhibitedVars = (BitSet)myProhibitedCachingVars.clone(); newProhibitedVars.set(variableIndex, true); return new TypeDfaState(myVarTypes, newProhibitedVars); }
withRemovedBinding
33,945
String () { String evicted = myProhibitedCachingVars.isEmpty() ? "" : ", (caching prohibited: " + myProhibitedCachingVars + ")"; return myVarTypes.toString() + evicted; }
toString
33,946
BitSet (BitSet leftSet, BitSet rightSet) { if (leftSet.equals(rightSet)) { return leftSet; } BitSet prohibited = ((BitSet)leftSet.clone()); prohibited.or(rightSet); return prohibited; }
mergeProhibitedVariables
33,947
Int2ObjectMap<DFAType> (Int2ObjectMap<DFAType> leftMap, Int2ObjectMap<DFAType> rightMap, PsiManager manager, BitSet prohibited) { Int2ObjectMap<DFAType> newFMap = new Int2ObjectOpenHashMap<>(); Stream.concat(rightMap.int2ObjectEntrySet().stream(), leftMap.int2ObjectEntrySet().stream()).forEach(entry -> { int descriptorId = entry.getIntKey(); if (descriptorId == 0 || prohibited.get(descriptorId) || !leftMap.containsKey(descriptorId) || !rightMap.containsKey(descriptorId)) { return; } DFAType candidate = entry.getValue(); DFAType existing = newFMap.get(descriptorId); if (existing == null) { newFMap.put(descriptorId, candidate); } else if (candidate != existing) { newFMap.put(descriptorId, DFAType.merge(candidate, existing, manager)); } }); return newFMap; }
mergeTypeMaps
33,948
boolean (Int2ObjectMap<DFAType> dominator, Int2ObjectMap<DFAType> dominated) { for (Int2ObjectMap.Entry<DFAType> dominatedEntry : dominated.int2ObjectEntrySet()) { DFAType dominatingType = dominator.get(dominatedEntry.getIntKey()); if (dominatingType == null || !DFAType.dominates(dominatingType, dominatedEntry.getValue())) { return false; } } return true; }
dominatesAll
33,949
boolean (TypeDfaState dominator, TypeDfaState dominated, Int2ObjectMap<DFAType> dominantMap) { boolean dominateByTypes = dominated.myVarTypes.isEmpty() || dominantMap == dominator.myVarTypes; if (!dominateByTypes) return false; return dominator.myProhibitedCachingVars.equals(dominated.myProhibitedCachingVars); }
dominates
33,950
InferenceContext () { InferenceContext context = ourInferenceContext.get(); return context != null ? context : getTopContext(); }
getCurrentContext
33,951
InferenceContext () { return InferenceContext.TOP_CONTEXT; }
getTopContext
33,952
PsiType (@NotNull final GrReferenceExpression refExpr) { final GrControlFlowOwner scope = isFlatDFAAllowed() ? ControlFlowUtils.getTopmostOwner(refExpr) : ControlFlowUtils.findControlFlowOwner(refExpr); if (scope == null) return null; final GroovyReference rValueReference = refExpr.getRValueReference(); PsiElement resolve = rValueReference == null ? null : rValueReference.resolve(); boolean mixinOnly = resolve instanceof GrField && isCompileStatic(refExpr); final VariableDescriptor descriptor = createDescriptor(refExpr); if (descriptor == null) return null; final ReadWriteVariableInstruction rwInstruction = ControlFlowUtils.findRWInstruction(refExpr, getFlatControlFlow(scope).getFlow()); if (rwInstruction == null) return null; final InferenceCache cache = getInferenceCache(scope); int descriptorIndex = cache.getGroovyFlow().getIndex(descriptor); if (descriptorIndex == 0) return null; return cache.getInferredType(descriptorIndex, rwInstruction, mixinOnly); }
getInferredType
33,953
PsiType (int descriptor, Instruction instruction, GrControlFlowOwner scope) { InferenceCache cache = getInferenceCache(scope); return cache.getInferredType(descriptor, instruction, false); }
getInferredType
33,954
PsiType (@Nullable PsiElement context, @NotNull GrVariable variable) { if (context == null) return variable.getType(); final GrControlFlowOwner scope = isFlatDFAAllowed() ? ControlFlowUtils.getTopmostOwner(ControlFlowUtils.findControlFlowOwner(context)) : ControlFlowUtils.findControlFlowOwner(context); if (scope == null) return null; final Instruction nearest = ControlFlowUtils.findNearestInstruction(context, scope.getControlFlow()); if (nearest == null) return null; boolean mixinOnly = variable instanceof GrField && isCompileStatic(scope); final InferenceCache cache = getInferenceCache(scope); final VariableDescriptor descriptor = createDescriptor(variable); int descriptorIndex = cache.getGroovyFlow().getIndex(descriptor); if (descriptorIndex == 0) { if (variable instanceof GrField) { // variable is not used anywhere in the scope, therefore it is enough to return its declared type return variable.getDeclaredType(); } else { return null; } } final PsiType inferredType = cache.getInferredType(descriptorIndex, nearest, mixinOnly); return inferredType != null ? inferredType : variable.getType(); }
getVariableTypeInContext
33,955
boolean (@NotNull GrControlFlowOwner scope) { return getInferenceCache(scope).isTooComplexToAnalyze(); }
isTooComplexTooAnalyze
33,956
InferenceCache (@NotNull final GrControlFlowOwner scope) { if (isFlatDFAAllowed() && ControlFlowUtils.getTopmostOwner(scope) != scope) { LOG.error("Flat DFA inconsistency: scope is " + scope + ", but topmost owner is " + ControlFlowUtils.getTopmostOwner(scope)); } return CachedValuesManager.getCachedValue(scope, () -> Result.create(new InferenceCache(scope), MODIFICATION_COUNT)); }
getInferenceCache
33,957
GroovyControlFlow (@NotNull final GrControlFlowOwner scope) { if (isFlatDFAAllowed()) { return CachedValuesManager.getCachedValue(scope, () -> Result.create(ControlFlowBuilder.buildFlatControlFlow(scope), MODIFICATION_COUNT)); } else { return ControlFlowUtils.getGroovyControlFlow(scope); } }
getFlatControlFlow
33,958
List<DefinitionMap> (@NotNull GroovyControlFlow flow) { final ReachingDefinitionsDfaInstance dfaInstance = new TypesReachingDefinitionsInstance(); final ReachingDefinitionsSemilattice lattice = new ReachingDefinitionsSemilattice(); final DFAEngine<DefinitionMap> engine = new DFAEngine<>(flow.getFlow(), dfaInstance, lattice); List<@Nullable DefinitionMap> maps = engine.performDFAWithTimeout(); if (maps == null) { return null; } return ContainerUtil.map(maps, it -> it == null ? DefinitionMap.NEUTRAL : it); }
getDefUseMaps
33,959
PsiType (final PsiElement element) { if (element instanceof GrReferenceExpression && ((GrReferenceExpression)element).getQualifierExpression() == null) { return getInitializerTypeFor(element); } if (element instanceof GrVariable) { return ((GrVariable)element).getTypeGroovy(); } return null; }
getInitializerType
33,960
PsiType (PsiElement element) { final PsiElement parent = skipParentheses(element.getParent(), true); if (parent instanceof GrAssignmentExpression) { if (element instanceof GrIndexProperty) { final GrExpression rvalue = ((GrAssignmentExpression)parent).getRValue(); return rvalue != null ? rvalue.getType() : null; //don't try to infer assignment type in case of index property because of infinite recursion (example: a[2]+=4) } return ((GrAssignmentExpression)parent).getType(); } if (parent instanceof GrTuple list) { GrTupleAssignmentExpression assignment = list.getParent(); if (assignment != null) { final GrExpression rValue = assignment.getRValue(); if (rValue != null) { int idx = list.indexOf(element); if (idx >= 0) { return getMultiAssignmentType(rValue, idx); } } } } if (parent instanceof GrUnaryExpression unary) { if (TokenSets.POSTFIX_UNARY_OP_SET.contains(unary.getOperationTokenType())) { return unary.getOperationType(); } } return null; }
getInitializerTypeFor
33,961
GrExpression (GrExpression lValue) { final PsiElement parent = lValue.getParent(); if (parent instanceof GrAssignmentExpression) return ((GrAssignmentExpression)parent).getRValue(); if (parent instanceof GrTuple) { final int i = ((GrTuple)parent).indexOf(lValue); final GrTupleAssignmentExpression grandParent = ((GrTuple)parent).getParent(); LOG.assertTrue(grandParent != null); final GrExpression rValue = grandParent.getRValue(); if (rValue instanceof GrListOrMap && !((GrListOrMap)rValue).isMap()) { final GrExpression[] initializers = ((GrListOrMap)rValue).getInitializers(); if (i < initializers.length) return initializers[i]; } } return null; }
getInitializerFor
33,962
boolean (Instruction @NotNull [] flow) { // in large flows there are a lot of variables, so minor inability to infer type for a parameter should not be noticeable. // on the other side, people may omit types of parameters in short methods, so augmenting may be useful there return flow.length < 20; }
isSimpleEnoughForAugmenting
33,963
DFAFlowInfo (@NotNull List<DefinitionMap> definitionMaps, @NotNull Instruction instruction, int descriptorId, @NotNull Predicate<? super Instruction> predicate) { Map<Pair<Instruction, Integer>, Collection<Pair<Instruction, Integer>>> interesting = new LinkedHashMap<>(); LinkedList<Pair<Instruction, Integer>> queue = new LinkedList<>(); queue.add(Pair.create(instruction, descriptorId)); Map<PsiElement, Collection<ReadWriteVariableInstruction>> scopeCache = new HashMap<>(); while (!queue.isEmpty()) { Pair<Instruction, Integer> pair = queue.removeFirst(); if (!interesting.containsKey(pair)) { Set<Pair<Instruction, Integer>> dependencies = findDependencies(definitionMaps, pair.first, pair.second, scopeCache); interesting.put(pair, dependencies); dependencies.forEach(queue::addLast); } } Set<Instruction> interestingInstructions = interesting.keySet().stream() .map(it -> it.getFirst()) .filter(predicate).collect(Collectors.toSet()); Set<Instruction> acyclicInstructions = findNodesOutsideCycles(mapGraph(interesting)).stream() .map(it -> it.getFirst()) .filter(predicate) .collect(Collectors.toSet()); Set<Integer> interestingDescriptors = interesting.keySet().stream() .map(it -> it.getSecond()) .collect(Collectors.toSet()); return new DFAFlowInfo(interestingInstructions, acyclicInstructions, interestingDescriptors); }
collectFlowInfo
33,964
void (@NotNull List<@Nullable TypeDfaState> dfaResult, Set<Instruction> storingInstructions) { for (var instruction : storingInstructions) { int index = instruction.num(); myVarTypes[index].getAndUpdate(oldState -> TypesSemilattice.mergeForCaching(oldState, dfaResult.get(index))); } }
cacheDfaResult
33,965
DefinitionMap (int instructionNum) { return myDefinitionMaps.getValue().get(instructionNum); }
getDefinitionMaps
33,966
TypeDfaState (@NotNull final TypeDfaState state, @NotNull final Instruction instruction) { TypeDfaState newState; if (instruction.num() == 0) { newState = handleStartInstruction(); } else if (instruction instanceof ReadWriteVariableInstruction) { newState = handleReadWriteVariable(state, (ReadWriteVariableInstruction)instruction); } else if (instruction instanceof MixinTypeInstruction) { newState = handleMixin(state, (MixinTypeInstruction)instruction); } else if (instruction instanceof ArgumentsInstruction) { newState = handleArguments(state, (ArgumentsInstruction)instruction); } else if (instruction instanceof NegatingGotoInstruction) { newState = handleNegation(state, (NegatingGotoInstruction)instruction); } else { newState = state; } myCache.publishDescriptor(newState, instruction); return newState; }
fun
33,967
TypeDfaState () { TypeDfaState state = TypeDfaState.EMPTY_STATE; for (int descriptor : myFlowInfo.getInterestingDescriptors()) { PsiType initialType = myInitialTypeProvider.initialType(descriptor); if (initialType != null) { state = state.withNewType(descriptor, DFAType.create(initialType)); } } return state; }
handleStartInstruction
33,968
boolean (@NotNull TypeDfaState baseDfaState, @NotNull Int2ObjectMap<DFAType> newDfaTypes) { var oldMap = baseDfaState.getRawVarTypes(); for (var entry : newDfaTypes.int2ObjectEntrySet()) { if (!oldMap.containsKey(entry.getIntKey()) || !oldMap.get(entry.getIntKey()).equals(entry.getValue())) { return false; } } return true; }
hasNoChanges
33,969
TypeDfaState (@NotNull final TypeDfaState state, @NotNull final MixinTypeInstruction instruction) { final int descriptor = instruction.getVariableDescriptor(); if (descriptor == 0) return state; return updateVariableType(state, instruction, descriptor, () -> { ReadWriteVariableInstruction originalInstr = instruction.getInstructionToMixin(myFlow.getFlow()); if (originalInstr != null) { assert !originalInstr.isWrite(); } return state.getNotNullDFAType(descriptor).withNewMixin(instruction.inferMixinType(), instruction.getConditionInstruction()); }); }
handleMixin
33,970
TypeDfaState (@NotNull TypeDfaState state, @NotNull ReadWriteVariableInstruction instruction) { final PsiElement element = instruction.getElement(); if (element == null) return state; int descriptor = instruction.getDescriptor(); if (instruction.isWrite()) { return updateVariableType( state, instruction, descriptor, () -> { PsiType initializerType = TypeInferenceHelper.getInitializerType(element); VariableDescriptor actualDescriptor = myFlow.getVarIndices()[descriptor]; if (initializerType == null && actualDescriptor instanceof ResolvedVariableDescriptor && TypeInferenceHelper.isSimpleEnoughForAugmenting(myFlow.getFlow())) { GrVariable variable = ((ResolvedVariableDescriptor)actualDescriptor).getVariable(); PsiType augmentedType = TypeAugmenter.Companion.inferAugmentedType(variable); return DFAType.create(augmentedType); } else { return DFAType.create(initializerType); } } ); } else { return state; } }
handleReadWriteVariable
33,971
TypeDfaState (TypeDfaState state, ArgumentsInstruction instruction) { TypeDfaState newState = state; for (Map.Entry<Integer, Collection<Argument>> entry : instruction.getArguments().entrySet()) { final int descriptor = entry.getKey(); final Collection<Argument> arguments = entry.getValue(); newState = handleArgument(newState, instruction, descriptor, arguments); } return newState; }
handleArguments
33,972
TypeDfaState (TypeDfaState state, ArgumentsInstruction instruction, int descriptorId, Collection<Argument> arguments) { return updateVariableType(state, instruction, descriptorId, () -> { DFAType result = state.getNotNullDFAType(descriptorId); final GroovyResolveResult[] results = instruction.getElement().multiResolve(false); for (GroovyResolveResult variant : results) { if (!(variant instanceof GroovyMethodResult)) continue; GroovyMethodCandidate candidate = ((GroovyMethodResult)variant).getCandidate(); if (candidate == null) continue; ArgumentMapping<PsiCallParameter> mapping = candidate.getArgumentMapping(); if (mapping == null) continue; for (Argument argument : arguments) { PsiType parameterType = mapping.expectedType(argument); if (parameterType == null) continue; PsiType typeToMixin = variant.getSubstitutor().substitute(parameterType); result = result.withNewMixin(typeToMixin, null); } } return result; }); }
handleArgument
33,973
TypeDfaState (@NotNull TypeDfaState state, @NotNull Instruction instruction, int descriptorId, @NotNull Supplier<DFAType> computation) { if (descriptorId == 0) { return state; } if (!myFlowInfo.getInterestingInstructions().contains(instruction)) { return state.withRemovedBinding(descriptorId); } DFAType type = myCache.getCachedInferredType(descriptorId, instruction); if (type == null) { if (myFlowInfo.getAcyclicInstructions().contains(instruction)) { type = computation.get(); } else { type = runWithoutCaching(state, computation); } } return state.withNewType(descriptorId, type); }
updateVariableType
33,974
TypeDfaState (@NotNull TypeDfaState state, @NotNull NegatingGotoInstruction negation) { TypeDfaState newState = state; for (Int2ObjectMap.Entry<DFAType> entry : state.getRawVarTypes().int2ObjectEntrySet()) { DFAType before = entry.getValue(); DFAType after = before.withNegated(negation); if (before != after) { newState = newState.withNewType(entry.getIntKey(), after); } } return newState; }
handleNegation
33,975
DefinitionMap (@NotNull List<? extends DefinitionMap> ins) { if (ins.size() == 0) { return NEUTRAL; } DefinitionMap result = ins.get(0); for (int i = 1; i < ins.size(); i++) { result = result.withMerged(ins.get(i)); } return result; }
join
33,976
FragmentVariableInfos (@NotNull final GrStatement first, @NotNull final GrStatement last, @NotNull final GrControlFlowOwner flowOwner, @NotNull GroovyControlFlow flow) { final Int2ObjectMap<int[]> dfaResult = inferDfaResult(flow.getFlow()); final LinkedHashSet<Integer> fragmentInstructions = getFragmentInstructions(first, last, flow.getFlow()); final int[] postorder = reversedPostOrder(flow.getFlow()); LinkedHashSet<Integer> reachableFromFragmentReads = getReachable(fragmentInstructions, flow.getFlow(), dfaResult, postorder); LinkedHashSet<Integer> fragmentReads = filterReads(fragmentInstructions, flow.getFlow()); final Map<String, VariableInfo> imap = new LinkedHashMap<>(); final Map<String, VariableInfo> omap = new LinkedHashMap<>(); final PsiManager manager = first.getManager(); for (final Integer ref : fragmentReads) { ReadWriteVariableInstruction rwInstruction = (ReadWriteVariableInstruction)flow.getFlow()[ref]; final int[] defs = dfaResult.get((int)ref); assert defs != null; int descriptorId = rwInstruction.getDescriptor(); VariableDescriptor descriptor = flow.getVarIndices()[descriptorId]; if (!allDefsInFragment(defs, fragmentInstructions) || isLocallyDeclaredOutOf(rwInstruction.getElement(), descriptor, flowOwner)) { addVariable(descriptor.getName(), imap, manager, getType(rwInstruction.getElement())); } } Set<Integer> outerBound = getFragmentOuterBound(fragmentInstructions, flow.getFlow()); for (final Integer ref : reachableFromFragmentReads) { ReadWriteVariableInstruction rwInstruction = (ReadWriteVariableInstruction)flow.getFlow()[ref]; int descriptorId = rwInstruction.getDescriptor(); VariableDescriptor descriptor = flow.getVarIndices()[descriptorId]; final int[] defs = dfaResult.get((int)ref); assert defs != null; if (anyDefInFragment(defs, fragmentInstructions)) { for (int insnNum : outerBound) { addVariable(descriptor.getName(), omap, manager, getVariableTypeAt(flowOwner, flow.getFlow()[insnNum], descriptorId, descriptor)); } if (!allProperDefsInFragment(defs, ref, fragmentInstructions, postorder)) { PsiType inputType = getType(rwInstruction.getElement()); addVariable(descriptor.getName(), imap, manager, inputType); } } } addClosureUsages(imap, omap, first, last, flowOwner); return new FragmentVariableInfos() { @Override public VariableInfo[] getInputVariableNames() { return imap.values().toArray(VariableInfo.EMPTY_ARRAY); } @Override public VariableInfo[] getOutputVariableNames() { return omap.values().toArray(VariableInfo.EMPTY_ARRAY); } }; }
obtainVariableFlowInformation
33,977
VariableInfo[] () { return imap.values().toArray(VariableInfo.EMPTY_ARRAY); }
getInputVariableNames
33,978
VariableInfo[] () { return omap.values().toArray(VariableInfo.EMPTY_ARRAY); }
getOutputVariableNames
33,979
PsiType (GrControlFlowOwner flowOwner, Instruction instruction, int descriptorId, VariableDescriptor descriptor) { PsiElement context = instruction.getElement(); PsiType outputType = TypeInferenceHelper.getInferredType(descriptorId, instruction, flowOwner); if (outputType == null) { GrVariable variable = resolveToLocalVariable(context, descriptor.getName()); if (variable != null) { outputType = variable.getDeclaredType(); } } return outputType; }
getVariableTypeAt
33,980
GrVariable (@Nullable PsiElement element, @NotNull String name) { if (element == null) return null; ElementResolveResult<GrVariable> result = GrReferenceResolveRunnerKt.resolveToLocalVariable(element, name); return result != null ? result.getElement() : null; }
resolveToLocalVariable
33,981
boolean (@Nullable PsiElement element, @NotNull VariableDescriptor descriptor, @NotNull GrControlFlowOwner flowOwner) { GrVariable variable = resolveToLocalVariable(element, descriptor.getName()); if (variable == null) return false; return !PsiImplUtilKt.isDeclaredIn(variable, flowOwner); }
isLocallyDeclaredOutOf
33,982
Int2ObjectMap<int[]> (Instruction @NotNull [] flow) { final ReachingDefinitionsDfaInstance dfaInstance = new ReachingDefinitionsDfaInstance(); final ReachingDefinitionsSemilattice lattice = new ReachingDefinitionsSemilattice(); final DFAEngine<DefinitionMap> engine = new DFAEngine<>(flow, dfaInstance, lattice); return postprocess(engine.performForceDFA(), flow); }
inferDfaResult
33,983
void (final Map<String, VariableInfo> imap, final Map<String, VariableInfo> omap, final GrStatement first, final GrStatement last, GrControlFlowOwner flowOwner) { flowOwner.accept(new GroovyRecursiveElementVisitor() { @Override public void visitClosure(@NotNull GrClosableBlock closure) { addUsagesInClosure(imap, omap, closure, first, last); super.visitClosure(closure); } private static void addUsagesInClosure(final Map<String, VariableInfo> imap, final Map<String, VariableInfo> omap, final GrClosableBlock closure, final GrStatement first, final GrStatement last) { closure.accept(new GroovyRecursiveElementVisitor() { @Override public void visitReferenceExpression(@NotNull GrReferenceExpression refExpr) { if (refExpr.isQualified()) { return; } String name = refExpr.getReferenceName(); if (name == null) return; GrVariable variable = resolveToLocalVariable(refExpr, name); if (variable == null) return; if (PsiImplUtilKt.isDeclaredIn(variable, closure)) return; if (!(variable instanceof GrField)) { if (!isInFragment(first, last, variable)) { if (isInFragment(first, last, closure)) { addVariable(name, imap, variable.getManager(), variable.getType()); } } else { if (!isInFragment(first, last, closure)) { addVariable(name, omap, variable.getManager(), variable.getType()); } } } } }); } }); }
addClosureUsages
33,984
void (@NotNull GrClosableBlock closure) { addUsagesInClosure(imap, omap, closure, first, last); super.visitClosure(closure); }
visitClosure
33,985
void (final Map<String, VariableInfo> imap, final Map<String, VariableInfo> omap, final GrClosableBlock closure, final GrStatement first, final GrStatement last) { closure.accept(new GroovyRecursiveElementVisitor() { @Override public void visitReferenceExpression(@NotNull GrReferenceExpression refExpr) { if (refExpr.isQualified()) { return; } String name = refExpr.getReferenceName(); if (name == null) return; GrVariable variable = resolveToLocalVariable(refExpr, name); if (variable == null) return; if (PsiImplUtilKt.isDeclaredIn(variable, closure)) return; if (!(variable instanceof GrField)) { if (!isInFragment(first, last, variable)) { if (isInFragment(first, last, closure)) { addVariable(name, imap, variable.getManager(), variable.getType()); } } else { if (!isInFragment(first, last, closure)) { addVariable(name, omap, variable.getManager(), variable.getType()); } } } } }); }
addUsagesInClosure
33,986
void (@NotNull GrReferenceExpression refExpr) { if (refExpr.isQualified()) { return; } String name = refExpr.getReferenceName(); if (name == null) return; GrVariable variable = resolveToLocalVariable(refExpr, name); if (variable == null) return; if (PsiImplUtilKt.isDeclaredIn(variable, closure)) return; if (!(variable instanceof GrField)) { if (!isInFragment(first, last, variable)) { if (isInFragment(first, last, closure)) { addVariable(name, imap, variable.getManager(), variable.getType()); } } else { if (!isInFragment(first, last, closure)) { addVariable(name, omap, variable.getManager(), variable.getType()); } } } }
visitReferenceExpression
33,987
void (String name, Map<String, VariableInfo> map, PsiManager manager, PsiType type) { VariableInfoImpl info = (VariableInfoImpl)map.get(name); if (info == null) { info = new VariableInfoImpl(name, manager); map.put(name, info); } info.addSubtype(type); }
addVariable
33,988
LinkedHashSet<Integer> (final LinkedHashSet<Integer> instructions, final Instruction[] flow) { final LinkedHashSet<Integer> result = new LinkedHashSet<>(); for (final Integer i : instructions) { final Instruction instruction = flow[i]; if (isReadInsn(instruction)) { result.add(i); } } return result; }
filterReads
33,989
boolean (int[] defs, LinkedHashSet<Integer> fragmentInstructions) { for (int def : defs) { if (!fragmentInstructions.contains(def)) return false; } return true; }
allDefsInFragment
33,990
boolean (int[] defs, int ref, LinkedHashSet<Integer> fragmentInstructions, int[] postorder) { for (int def : defs) { if (!fragmentInstructions.contains(def) && postorder[def] < postorder[ref]) return false; } return true; }
allProperDefsInFragment
33,991
boolean (int[] defs, LinkedHashSet<Integer> fragmentInstructions) { for (int def : defs) { if (fragmentInstructions.contains(def)) return true; } return false; }
anyDefInFragment
33,992
PsiType (PsiElement element) { if (element instanceof GrVariable) { return ((GrVariable)element).getTypeGroovy(); } else if (element instanceof GrReferenceExpression) return ((GrReferenceExpression)element).getType(); return null; }
getType
33,993
LinkedHashSet<Integer> (GrStatement first, GrStatement last, Instruction[] flow) { LinkedHashSet<Integer> result = new LinkedHashSet<>(); for (Instruction instruction : flow) { if (isInFragment(instruction, first, last)) { result.add(instruction.num()); } } return result; }
getFragmentInstructions
33,994
boolean (Instruction instruction, GrStatement first, GrStatement last) { final PsiElement element = instruction.getElement(); if (element == null) return false; return isInFragment(first, last, element); }
isInFragment
33,995
boolean (GrStatement first, GrStatement last, PsiElement element) { final PsiElement parent = first.getParent(); if (!PsiTreeUtil.isAncestor(parent, element, true)) return false; PsiElement run = element; while (run.getParent() != parent) run = run.getParent(); return isBetween(first, last, run); }
isInFragment
33,996
boolean (PsiElement first, PsiElement last, PsiElement run) { while (first != null && first != run) first = first.getNextSibling(); if (first == null) return false; while (last != null && last != run) last = last.getPrevSibling(); if (last == null) return false; return true; }
isBetween
33,997
LinkedHashSet<Integer> (final LinkedHashSet<Integer> fragmentInsns, final Instruction[] flow, final @NotNull Int2ObjectMap<int[]> dfaResult, final int[] postorder) { final LinkedHashSet<Integer> result = new LinkedHashSet<>(); for (final Instruction insn : flow) { if (isReadInsn(insn)) { final int ref = insn.num(); int[] definitions = dfaResult.get(ref); if (definitions != null) { for (final int def : definitions) { if (fragmentInsns.contains(def) && (!fragmentInsns.contains(ref) || postorder[ref] < postorder[def] && checkPathIsOutsideOfFragment(def, ref, flow, fragmentInsns))) { result.add(ref); break; } } } } } return result; }
getReachable
33,998
Set<Integer> (@NotNull LinkedHashSet<Integer> fragmentInstructions, Instruction @NotNull [] flow) { final Set<Integer> result = new HashSet<>(); for (Integer num : fragmentInstructions) { for (Instruction successor : flow[num].allSuccessors()) { if (!fragmentInstructions.contains(successor.num())) { result.add(num); } } } return result; }
getFragmentOuterBound
33,999
boolean (int def, int ref, Instruction[] flow, LinkedHashSet<Integer> fragmentInsns) { Boolean path = findPath(flow[def], ref, fragmentInsns, false, new HashMap<>()); assert path != null : "def=" + def + ", ref=" + ref; return path.booleanValue(); }
checkPathIsOutsideOfFragment