From d7e1e3b5b24b0f9f0e3dfcc6d1e37d442f1de4e8 Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Sat, 17 Feb 2018 16:32:51 +0100 Subject: Static type check reference parameters --- .../rankingexpression/evaluation/ArrayContext.java | 5 +++-- .../searchlib/rankingexpression/evaluation/Context.java | 3 ++- .../evaluation/DoubleOnlyArrayContext.java | 5 ++++- .../rankingexpression/evaluation/MapContext.java | 7 ++++--- .../rankingexpression/evaluation/MapTypeContext.java | 15 ++++++++------- .../rankingexpression/rule/EvaluationTypeContext.java | 11 ----------- 6 files changed, 21 insertions(+), 25 deletions(-) delete mode 100644 searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/EvaluationTypeContext.java (limited to 'searchlib/src/main') diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/ArrayContext.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/ArrayContext.java index 486affe9371..ee5952d9aea 100644 --- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/ArrayContext.java +++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/ArrayContext.java @@ -2,6 +2,7 @@ package com.yahoo.searchlib.rankingexpression.evaluation; import com.yahoo.searchlib.rankingexpression.RankingExpression; +import com.yahoo.searchlib.rankingexpression.Reference; import com.yahoo.tensor.TensorType; import java.util.Arrays; @@ -82,8 +83,8 @@ public class ArrayContext extends AbstractArrayContext implements Cloneable { } @Override - public TensorType getType(Name name) { - Integer index = nameToIndex().get(name.toString()); + public TensorType getType(Reference reference) { + Integer index = nameToIndex().get(reference.toString()); if (index == null) return null; return values[index].type(); } diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/Context.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/Context.java index 9779e01bf51..4102d4078e6 100644 --- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/Context.java +++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/Context.java @@ -1,6 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.searchlib.rankingexpression.evaluation; +import com.yahoo.searchlib.rankingexpression.Reference; import com.yahoo.searchlib.rankingexpression.rule.Arguments; import com.yahoo.searchlib.rankingexpression.rule.ExpressionNode; import com.yahoo.tensor.Tensor; @@ -14,7 +15,7 @@ import java.util.stream.Collectors; * * @author bratseth */ -public abstract class Context implements EvaluationContext { +public abstract class Context implements EvaluationContext { /** * Returns the value of a simple variable name. diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/DoubleOnlyArrayContext.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/DoubleOnlyArrayContext.java index 01b8bffe995..0004036da4b 100644 --- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/DoubleOnlyArrayContext.java +++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/DoubleOnlyArrayContext.java @@ -2,6 +2,7 @@ package com.yahoo.searchlib.rankingexpression.evaluation; import com.yahoo.searchlib.rankingexpression.RankingExpression; +import com.yahoo.searchlib.rankingexpression.Reference; import com.yahoo.tensor.TensorType; /** @@ -68,7 +69,9 @@ public class DoubleOnlyArrayContext extends AbstractArrayContext { } @Override - public TensorType getType(Name name) { return TensorType.empty; } + public TensorType getType(Reference reference) { + return TensorType.empty; // Double only + } /** Perform a slow lookup by name */ @Override diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/MapContext.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/MapContext.java index c7679ea9e55..4ef24d60bba 100644 --- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/MapContext.java +++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/MapContext.java @@ -1,6 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.searchlib.rankingexpression.evaluation; +import com.yahoo.searchlib.rankingexpression.Reference; import com.yahoo.tensor.TensorType; import java.util.Collections; @@ -15,7 +16,7 @@ import java.util.Set; */ public class MapContext extends Context { - private Map bindings = new HashMap<>(); + private Map bindings = new HashMap<>(); // TODO: Change String to Reference private boolean frozen = false; @@ -42,8 +43,8 @@ public class MapContext extends Context { /** Returns the type of the given value key, or null if it is not bound. */ @Override - public TensorType getType(Name key) { - Value value = bindings.get(key); + public TensorType getType(Reference key) { + Value value = bindings.get(key.toString()); if (value == null) return null; return value.type(); } diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/MapTypeContext.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/MapTypeContext.java index 4ce7dd561e2..985878cfd66 100644 --- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/MapTypeContext.java +++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/MapTypeContext.java @@ -1,6 +1,7 @@ // Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.searchlib.rankingexpression.evaluation;// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +import com.yahoo.searchlib.rankingexpression.Reference; import com.yahoo.tensor.TensorType; import com.yahoo.tensor.evaluation.TypeContext; @@ -13,20 +14,20 @@ import java.util.Map; * * @author bratseth */ -public class MapTypeContext implements TypeContext { +public class MapTypeContext implements TypeContext { - private final Map featureTypes = new HashMap<>(); + private final Map featureTypes = new HashMap<>(); - public void setType(Name name, TensorType type) { - featureTypes.put(name, type); + public void setType(Reference reference, TensorType type) { + featureTypes.put(reference, type); } @Override - public TensorType getType(Name name) { - return featureTypes.get(name); + public TensorType getType(Reference reference) { + return featureTypes.get(reference); } /** Returns an unmodifiable map of the bindings in this */ - public Map bindings() { return Collections.unmodifiableMap(featureTypes); } + public Map bindings() { return Collections.unmodifiableMap(featureTypes); } } diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/EvaluationTypeContext.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/EvaluationTypeContext.java deleted file mode 100644 index 3807fbe2207..00000000000 --- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/EvaluationTypeContext.java +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.searchlib.rankingexpression.rule; - -import com.yahoo.tensor.TensorType; -import com.yahoo.tensor.evaluation.TypeContext; - -public interface EvaluationTypeContext extends TypeContext { - - TensorType getType(String name, Arguments arguments, String output); - -} -- cgit v1.2.3