diff options
author | Arne Juul <arnej@verizonmedia.com> | 2021-04-22 06:24:30 +0000 |
---|---|---|
committer | Arne Juul <arnej@verizonmedia.com> | 2021-04-22 06:24:30 +0000 |
commit | 7179bd7dae6aca37ae1aa061161da3d998c2644e (patch) | |
tree | 923d31bb3a4fe4550c5f04897493bcdb0ea91a01 /config-model/src/main/java/com/yahoo/searchdefinition/MapEvaluationTypeContext.java | |
parent | 4c46d92474745467a53eb53336fd4c5c162b2375 (diff) |
Reapply "Arnej/evaluate bindings in parent context"
This reverts commit f1598d54afa672ec895330dba43a9f0fb5687587.
Diffstat (limited to 'config-model/src/main/java/com/yahoo/searchdefinition/MapEvaluationTypeContext.java')
-rw-r--r-- | config-model/src/main/java/com/yahoo/searchdefinition/MapEvaluationTypeContext.java | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/MapEvaluationTypeContext.java b/config-model/src/main/java/com/yahoo/searchdefinition/MapEvaluationTypeContext.java index bc98f0ab8c5..fc7362a43e1 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/MapEvaluationTypeContext.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/MapEvaluationTypeContext.java @@ -39,6 +39,8 @@ import java.util.stream.Collectors; */ public class MapEvaluationTypeContext extends FunctionReferenceContext implements TypeContext<Reference> { + private final Optional<MapEvaluationTypeContext> parent; + private final Map<Reference, TensorType> featureTypes = new HashMap<>(); private final Map<Reference, TensorType> resolvedTypes = new HashMap<>(); @@ -54,6 +56,7 @@ public class MapEvaluationTypeContext extends FunctionReferenceContext implement MapEvaluationTypeContext(Collection<ExpressionFunction> functions, Map<Reference, TensorType> featureTypes) { super(functions); + this.parent = Optional.empty(); this.featureTypes.putAll(featureTypes); this.currentResolutionCallStack = new ArrayDeque<>(); this.queryFeaturesNotDeclared = new TreeSet<>(); @@ -63,12 +66,14 @@ public class MapEvaluationTypeContext extends FunctionReferenceContext implement private MapEvaluationTypeContext(Map<String, ExpressionFunction> functions, Map<String, String> bindings, + Optional<MapEvaluationTypeContext> parent, Map<Reference, TensorType> featureTypes, Deque<Reference> currentResolutionCallStack, SortedSet<Reference> queryFeaturesNotDeclared, boolean tensorsAreUsed, Map<Reference, TensorType> globallyResolvedTypes) { super(functions, bindings); + this.parent = parent; this.featureTypes.putAll(featureTypes); this.currentResolutionCallStack = currentResolutionCallStack; this.queryFeaturesNotDeclared = queryFeaturesNotDeclared; @@ -130,13 +135,16 @@ public class MapEvaluationTypeContext extends FunctionReferenceContext implement currentResolutionCallStack.stream().map(Reference::toString).collect(Collectors.joining(" -> ")) + " -> " + reference); - // Bound to a function argument, and not to a same-named identifier (which would lead to a loop)? + // Bound to a function argument? Optional<String> binding = boundIdentifier(reference); - if (binding.isPresent() && ! binding.get().equals(reference.toString())) { + if (binding.isPresent()) { try { // This is not pretty, but changing to bind expressions rather // than their string values requires deeper changes - return new RankingExpression(binding.get()).type(this); + var expr = new RankingExpression(binding.get()); + var type = expr.type(parent.orElseThrow( + () -> new IllegalArgumentException("when a binding is present we must have a parent context"))); + return type; } catch (ParseException e) { throw new IllegalArgumentException(e); } @@ -157,7 +165,10 @@ public class MapEvaluationTypeContext extends FunctionReferenceContext implement // A reference to a function? Optional<ExpressionFunction> function = functionInvocation(reference); if (function.isPresent()) { - return function.get().getBody().type(this.withBindings(bind(function.get().arguments(), reference.arguments()))); + var body = function.get().getBody(); + var child = this.withBindings(bind(function.get().arguments(), reference.arguments())); + var type = body.type(child); + return type; } // A reference to an ONNX model? @@ -297,8 +308,7 @@ public class MapEvaluationTypeContext extends FunctionReferenceContext implement Map<String, String> bindings = new HashMap<>(formalArguments.size()); for (int i = 0; i < formalArguments.size(); i++) { String identifier = invocationArguments.expressions().get(i).toString(); - String identifierBinding = super.getBinding(identifier); - bindings.put(formalArguments.get(i), identifierBinding != null ? identifierBinding : identifier); + bindings.put(formalArguments.get(i), identifier); } return bindings; } @@ -323,6 +333,7 @@ public class MapEvaluationTypeContext extends FunctionReferenceContext implement public MapEvaluationTypeContext withBindings(Map<String, String> bindings) { return new MapEvaluationTypeContext(functions(), bindings, + Optional.of(this), featureTypes, currentResolutionCallStack, queryFeaturesNotDeclared, |