Skip to content

Commit

Permalink
[NF] Fix function vectorization/cast conflict.
Browse files Browse the repository at this point in the history
- Add the base type of match to vectorized functions, so that it's
  possible to differentiate between vectorized functions with exact or
  type cast arguments and choose the correct one.

Belonging to [master]:
  - OpenModelica/OMCompiler#2635
  - OpenModelica/OpenModelica-testsuite#1025
  • Loading branch information
perost authored and OpenModelica-Hudson committed Sep 6, 2018
1 parent cbc69f9 commit eb0909d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Compiler/NFFrontEnd/NFCall.mo
Expand Up @@ -970,6 +970,10 @@ protected
if listLength(matchedFunctions) > 1 then
exactMatches := MatchedFunction.getExactMatches(matchedFunctions);

if listEmpty(exactMatches) then
exactMatches := MatchedFunction.getExactVectorizedMatches(matchedFunctions);
end if;

if listLength(exactMatches) > 1 then
Error.addSourceMessage(Error.AMBIGUOUS_MATCHING_FUNCTIONS_NFINST,
{typedString(call), Function.candidateFuncListString(list(mfn.func for mfn in matchedFunctions))}, info);
Expand Down
26 changes: 25 additions & 1 deletion Compiler/NFFrontEnd/NFFunction.mo
Expand Up @@ -134,6 +134,7 @@ uniontype FunctionMatchKind
// Instead they are added to each call as is.
// This list represents which args should be vectorized.
list<Boolean> is_vectorized;
FunctionMatchKind baseMatch;
end VECTORIZED;

record NOT_COMPATIBLE end NOT_COMPATIBLE;
Expand Down Expand Up @@ -168,6 +169,16 @@ uniontype FunctionMatchKind
end match;
end isVectorized;

function isExactVectorized
input FunctionMatchKind mk;
output Boolean b;
algorithm
b := match mk
case VECTORIZED(baseMatch = EXACT()) then true;
else false;
end match;
end isExactVectorized;

end FunctionMatchKind;

constant FunctionMatchKind EXACT_MATCH = FunctionMatchKind.EXACT();
Expand All @@ -192,6 +203,12 @@ uniontype MatchedFunction
output list<MatchedFunction> outFuncs = list(mf for mf guard(FunctionMatchKind.isExact(mf.mk)) in matchedFunctions);
end getExactMatches;

function getExactVectorizedMatches
input list<MatchedFunction> matchedFunctions;
output list<MatchedFunction> outFuncs =
list(mf for mf guard(FunctionMatchKind.isExactVectorized(mf.mk)) in matchedFunctions);
end getExactVectorizedMatches;

function isVectorized
input MatchedFunction mf;
output Boolean b = FunctionMatchKind.isVectorized(mf.mk);
Expand Down Expand Up @@ -736,6 +753,7 @@ uniontype Function
list<Dimension> argdims, compdims, vectdims, tmpdims, outvectdims;
Boolean has_cast;
list<Boolean> vectorized;
FunctionMatchKind base_mk = EXACT_MATCH;
algorithm

checked_args := {};
Expand Down Expand Up @@ -806,13 +824,19 @@ uniontype Function
return;
end if;

if TypeCheck.isCastMatch(matchKind) then
base_mk := CAST_MATCH;
elseif TypeCheck.isGenericMatch(matchKind) then
base_mk := GENERIC_MATCH;
end if;

checked_args := (margexp,mty,var) :: checked_args;
idx := idx + 1;
end for;

correct := true;
args := listReverse(checked_args);
funcMatchKind := VECTORIZED(vectdims, listReverse(vectorized));
funcMatchKind := VECTORIZED(vectdims, listReverse(vectorized), base_mk);
end matchArgsVectorize;

function matchArgs
Expand Down

0 comments on commit eb0909d

Please sign in to comment.