private boolean hasFallthrough(SpecializationGroup group, TypeMirror forType, LocalContext currentValues, boolean fastPath, List<GuardExpression> ignoreGuards) { for (TypeGuard guard : group.getTypeGuards()) { if (currentValues.getValue(guard.getSignatureIndex()) == null) { LocalVariable value = currentValues.getValue(guard.getSignatureIndex()); if (needsCastTo(value.getTypeMirror(), guard.getType())) { return true;
cachedTriples.add(triple); hasImplicitCast = hasImplicitCast || node.getTypeSystem().hasImplicitSourceTypes(guard.getType()); if (!mode.isGuardFallback()) { triple = createTypeCheckOrCast(frameState, group, guard, mode, true, true);
CodeTreeBuilder localsBuilder = CodeTreeBuilder.createBuilder(); for (TypeGuard typeGuard : typeGuards) { int signatureIndex = typeGuard.getSignatureIndex(); LocalVariable value = currentValues.getValue(signatureIndex); TypeMirror targetType = typeGuard.getType(); if (!ElementUtils.needsCastTo(value.getTypeMirror(), targetType)) { continue; LocalVariable castVariable = currentValues.getValue(execution).nextName().newType(typeGuard.getType()).accessWith(null); currentValues.setValue(execution, castVariable); localsBuilder.tree(castVariable.createDeclaration(castBuilder.build()));
CodeTreeBuilder prepareBuilder = CodeTreeBuilder.createBuilder(); CodeTreeBuilder checkBuilder = CodeTreeBuilder.createBuilder(); int signatureIndex = typeGuard.getSignatureIndex(); LocalVariable value = frameState.getValue(signatureIndex); TypeMirror targetType = typeGuard.getType(); LocalVariable currentValue = frameState.getValue(execution); CodeTreeBuilder localsBuilder = CodeTreeBuilder.createBuilder(); LocalVariable castVariable = currentValue.nextName().newType(typeGuard.getType()).accessWith(null); frameState.setValue(execution, castVariable); localsBuilder.tree(castVariable.createDeclaration(castBuilder.build()));
if (boxingEliminationEnabled) { for (TypeGuard checkedGuard : group.getTypeGuards()) { if (!ElementUtils.isPrimitive(checkedGuard.getType())) { } else if (node.getChildExecutions().get(checkedGuard.getSignatureIndex()).getChild().findExecutableType(checkedGuard.getType()) == null) { if (checkedGuard.getSignatureIndex() == execution.getIndex()) { eliminatedGuard = checkedGuard; break; targetType = eliminatedGuard.getType(); } else { targetType = execution.getChild().findAnyGenericExecutableType(context).getReturnType(); List<TypeMirror> sourceTypes = resolveOptimizedImplicitSourceTypes(execution, targetType); if (sourceTypes.size() > 1) { TypeGuard typeGuard = new TypeGuard(targetType, execution.getIndex()); TypeMirror generic = node.getPolymorphicSpecialization().findParameterOrDie(execution).getType(); fallbackVar = originalFrameState.createValue(execution, generic);
boolean canExecuteChild = execution.getIndex() < currentType.getEvaluatedCount(); for (TypeGuard checkedGuard : originalGroup.getTypeGuards()) { if (checkedGuard.getSignatureIndex() == execution.getIndex()) { canExecuteChild = true; break; if (resolveOptimizedImplicitSourceTypes(execution, checkedGuard.getType()).size() > 1) { canExecuteChild = false; break;
List<TypeMirror> originalSourceTypes = typeSystem.lookupSourceTypes(target.getTypeMirror()); List<TypeMirror> sourceTypes = resolveOptimizedImplicitSourceTypes(execution, target.getTypeMirror()); TypeGuard typeGuard = new TypeGuard(target.getTypeMirror(), execution.getIndex()); boolean throwsUnexpected = false; boolean elseIf = false;
List<TypeMirror> sourceTypes = typeSystem.lookupSourceTypes(targetType); if (sourceTypes.size() > 1) { implicitCasts.add(new TypeGuard(targetType, index));
private List<IfTriple> initializeCasts(FrameState frameState, SpecializationGroup group, DSLExpression expression, NodeExecutionMode specializationExecution) { Set<VariableElement> boundElements = expression.findBoundVariableElements(); if (boundElements.isEmpty()) { return Collections.emptyList(); } List<IfTriple> triples = new ArrayList<>(); for (VariableElement variable : boundElements) { Parameter p = group.getSpecialization().findByVariable(variable); if (p != null) { NodeExecutionData execution = p.getSpecification().getExecution(); if (execution != null) { LocalVariable var = frameState.getValue(execution); if (var == null) { throw new AssertionError(); } IfTriple triple = createTypeCheckOrCast(frameState, group, new TypeGuard(p.getType(), execution.getIndex()), specializationExecution, true, false); if (triple != null) { triples.add(triple); } } } } return triples; }
@Override protected int calculateRequiredBits(Object object) { if (object instanceof SpecializationData) { SpecializationData specialization = (SpecializationData) object; if (specialization.isPolymorphic()) { return 0; } else { return 1; } } else if (object instanceof TypeGuard) { TypeGuard guard = (TypeGuard) object; TypeMirror type = guard.getType(); List<TypeMirror> sourceTypes = typeSystem.lookupSourceTypes(type); if (sourceTypes.size() > 1) { return sourceTypes.size(); } throw new AssertionError(); } else if (object instanceof GuardExpression) { return 1; } else { throw new AssertionError(); } }
private boolean isTypeGuardUsedInAnyGuardOrCacheBelow(SpecializationGroup group, LocalContext currentValues, TypeGuard typeGuard, boolean fastPath) { String localName = currentValues.getValue(typeGuard.getSignatureIndex()).getName(); SpecializationData specialization = group.getSpecialization(); for (GuardExpression guard : group.getGuards()) { if (isVariableBoundIn(specialization, guard.getExpression(), localName, currentValues)) { return true; } } if (!fastPath && specialization != null) { for (CacheExpression cache : specialization.getCaches()) { if (isVariableBoundIn(specialization, cache.getExpression(), localName, currentValues)) { return true; } } } for (SpecializationGroup child : group.getChildren()) { if (isTypeGuardUsedInAnyGuardOrCacheBelow(child, currentValues, typeGuard, fastPath)) { return true; } } return false; }
private CodeTree createUpdateImplicitCastState(CodeTreeBuilder parent, FrameState frameState, SpecializationData specialization) { CodeTreeBuilder builder = null; int signatureIndex = 0; for (Parameter p : specialization.getSignatureParameters()) { TypeMirror targetType = p.getType(); TypeMirror polymorphicType = node.getPolymorphicSpecialization().findParameterOrDie(p.getSpecification().getExecution()).getType(); if (typeSystem.hasImplicitSourceTypes(targetType) && needsCastTo(polymorphicType, targetType)) { String implicitFieldName = createImplicitTypeStateLocalName(p); if (builder == null) { builder = parent.create(); } builder.tree(state.createSetInteger(frameState, new TypeGuard(p.getType(), signatureIndex), CodeTreeBuilder.singleString(implicitFieldName))); } signatureIndex++; } return builder == null ? null : builder.build(); }
private SpecializationGroup(SpecializationData data) { this.node = data.getNode(); this.typeGuards = new ArrayList<>(); this.guards = new ArrayList<>(); this.specialization = data; TypeSignature sig = data.getTypeSignature(); for (int i = 1; i < sig.size(); i++) { typeGuards.add(new TypeGuard(sig.get(i), i - 1)); } this.guards.addAll(data.getGuards()); }
protected String toString(Object element) { if (element instanceof SpecializationData) { SpecializationData specialization = (SpecializationData) element; if (specialization.isUninitialized()) { return "uninitialized"; } return ElementUtils.createReferenceName(specialization.getMethod()); } else if (element instanceof TypeGuard) { int index = ((TypeGuard) element).getSignatureIndex(); String simpleName = ElementUtils.getSimpleName(((TypeGuard) element).getType()); return index + ":" + simpleName; } return element.toString(); }
private SpecializationGroup(SpecializationData data) { this.node = data.getNode(); this.typeGuards = new ArrayList<>(); this.guards = new ArrayList<>(); this.specialization = data; TypeSignature sig = data.getTypeSignature(); for (int i = 1; i < sig.size(); i++) { typeGuards.add(new TypeGuard(sig.get(i), i - 1)); } this.guards.addAll(data.getGuards()); }