Skip to content

Commit

Permalink
Remove SignatureBinder.bindVariables
Browse files Browse the repository at this point in the history
  • Loading branch information
dain committed Jul 30, 2020
1 parent 376a6d3 commit 212c36e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,11 @@ public FunctionResolver(Metadata metadata)

FunctionBinding resolveCoercion(Collection<FunctionMetadata> allCandidates, Signature signature)
{
List<TypeSignatureProvider> argumentTypeSignatureProviders = fromTypeSignatures(signature.getArgumentTypes());

List<FunctionMetadata> exactCandidates = allCandidates.stream()
.filter(function -> possibleExactCastMatch(signature, function.getSignature()))
.collect(Collectors.toList());
for (FunctionMetadata candidate : exactCandidates) {
Optional<BoundVariables> boundVariables = new SignatureBinder(metadata, candidate.getSignature(), false)
.bindVariables(argumentTypeSignatureProviders, signature.getReturnType());
if (boundVariables.isPresent()) {
if (canBindSignature(candidate.getSignature(), signature)) {
return toFunctionBinding(candidate, signature);
}
}
Expand All @@ -70,16 +66,20 @@ FunctionBinding resolveCoercion(Collection<FunctionMetadata> allCandidates, Sign
.filter(function -> !function.getSignature().getTypeVariableConstraints().isEmpty())
.collect(Collectors.toList());
for (FunctionMetadata candidate : genericCandidates) {
Optional<BoundVariables> boundVariables = new SignatureBinder(metadata, candidate.getSignature(), false)
.bindVariables(argumentTypeSignatureProviders, signature.getReturnType());
if (boundVariables.isPresent()) {
if (canBindSignature(candidate.getSignature(), signature)) {
return toFunctionBinding(candidate, signature);
}
}

throw new PrestoException(FUNCTION_IMPLEMENTATION_MISSING, format("%s not found", signature));
}

private boolean canBindSignature(Signature declaredSignature, Signature actualSignature)
{
return new SignatureBinder(metadata, declaredSignature, false)
.canBind(fromTypeSignatures(actualSignature.getArgumentTypes()), actualSignature.getReturnType());
}

private FunctionBinding toFunctionBinding(FunctionMetadata functionMetadata, Signature signature)
{
BoundSignature boundSignature = new BoundSignature(
Expand Down Expand Up @@ -344,9 +344,8 @@ private Optional<List<Type>> toTypes(List<TypeSignatureProvider> typeSignaturePr
private boolean isMoreSpecificThan(ApplicableFunction left, ApplicableFunction right)
{
List<TypeSignatureProvider> resolvedTypes = fromTypeSignatures(left.getBoundSignature().getArgumentTypes());
Optional<BoundVariables> boundVariables = new SignatureBinder(metadata, right.getDeclaredSignature(), true)
.bindVariables(resolvedTypes);
return boundVariables.isPresent();
return new SignatureBinder(metadata, right.getDeclaredSignature(), true)
.canBind(resolvedTypes);
}

private static class ApplicableFunction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
package io.prestosql.metadata;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.VerifyException;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
Expand Down Expand Up @@ -116,7 +117,13 @@ public Optional<Signature> bind(List<? extends TypeSignatureProvider> actualArgu
return Optional.of(applyBoundVariables(declaredSignature, boundVariables.get(), actualArgumentTypes.size()));
}

public Optional<BoundVariables> bindVariables(List<? extends TypeSignatureProvider> actualArgumentTypes)
public boolean canBind(List<? extends TypeSignatureProvider> actualArgumentTypes)
{
return bindVariables(actualArgumentTypes).isPresent();
}

@VisibleForTesting
Optional<BoundVariables> bindVariables(List<? extends TypeSignatureProvider> actualArgumentTypes)
{
ImmutableList.Builder<TypeConstraintSolver> constraintSolvers = ImmutableList.builder();
if (!appendConstraintSolversForArguments(constraintSolvers, actualArgumentTypes)) {
Expand All @@ -126,7 +133,13 @@ public Optional<BoundVariables> bindVariables(List<? extends TypeSignatureProvid
return iterativeSolve(constraintSolvers.build());
}

public Optional<BoundVariables> bindVariables(List<? extends TypeSignatureProvider> actualArgumentTypes, TypeSignature actualReturnType)
public boolean canBind(List<? extends TypeSignatureProvider> actualArgumentTypes, TypeSignature actualReturnType)
{
return bindVariables(actualArgumentTypes, actualReturnType).isPresent();
}

@VisibleForTesting
Optional<BoundVariables> bindVariables(List<? extends TypeSignatureProvider> actualArgumentTypes, TypeSignature actualReturnType)
{
ImmutableList.Builder<TypeConstraintSolver> constraintSolvers = ImmutableList.builder();
if (!appendConstraintSolversForReturnValue(constraintSolvers, new TypeSignatureProvider(actualReturnType))) {
Expand Down

0 comments on commit 212c36e

Please sign in to comment.