diff options
author | Arne H Juul <arnej27959@users.noreply.github.com> | 2021-04-21 16:20:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-21 16:20:59 +0200 |
commit | f1598d54afa672ec895330dba43a9f0fb5687587 (patch) | |
tree | ef7622895ffad73c25d290dd3a6278666525ed5d /config-model/src/main/java/com/yahoo/searchdefinition/MapEvaluationTypeContext.java | |
parent | dc0bca9a4329ac6d4a000cf410e5b784f45bb2e5 (diff) |
Revert "Arnej/evaluate bindings in parent context"
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, 6 insertions, 17 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 fc7362a43e1..bc98f0ab8c5 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/MapEvaluationTypeContext.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/MapEvaluationTypeContext.java @@ -39,8 +39,6 @@ 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<>(); @@ -56,7 +54,6 @@ 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<>(); @@ -66,14 +63,12 @@ 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; @@ -135,16 +130,13 @@ public class MapEvaluationTypeContext extends FunctionReferenceContext implement currentResolutionCallStack.stream().map(Reference::toString).collect(Collectors.joining(" -> ")) + " -> " + reference); - // Bound to a function argument? + // Bound to a function argument, and not to a same-named identifier (which would lead to a loop)? Optional<String> binding = boundIdentifier(reference); - if (binding.isPresent()) { + if (binding.isPresent() && ! binding.get().equals(reference.toString())) { try { // This is not pretty, but changing to bind expressions rather // than their string values requires deeper changes - 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; + return new RankingExpression(binding.get()).type(this); } catch (ParseException e) { throw new IllegalArgumentException(e); } @@ -165,10 +157,7 @@ public class MapEvaluationTypeContext extends FunctionReferenceContext implement // A reference to a function? Optional<ExpressionFunction> function = functionInvocation(reference); if (function.isPresent()) { - var body = function.get().getBody(); - var child = this.withBindings(bind(function.get().arguments(), reference.arguments())); - var type = body.type(child); - return type; + return function.get().getBody().type(this.withBindings(bind(function.get().arguments(), reference.arguments()))); } // A reference to an ONNX model? @@ -308,7 +297,8 @@ 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(); - bindings.put(formalArguments.get(i), identifier); + String identifierBinding = super.getBinding(identifier); + bindings.put(formalArguments.get(i), identifierBinding != null ? identifierBinding : identifier); } return bindings; } @@ -333,7 +323,6 @@ public class MapEvaluationTypeContext extends FunctionReferenceContext implement public MapEvaluationTypeContext withBindings(Map<String, String> bindings) { return new MapEvaluationTypeContext(functions(), bindings, - Optional.of(this), featureTypes, currentResolutionCallStack, queryFeaturesNotDeclared, |