Skip to content

Commit

Permalink
Fix partial check in record constructors (#7576)
Browse files Browse the repository at this point in the history
  • Loading branch information
perost committed Jun 18, 2021
1 parent 7a4ad0e commit 89b043c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
10 changes: 9 additions & 1 deletion OMCompiler/Compiler/NFFrontEnd/NFCall.mo
Expand Up @@ -257,10 +257,18 @@ public
local
list<Function> fnl;
Boolean is_external;
InstContext.Type fn_context;

case UNTYPED_CALL()
algorithm
fnl := Function.typeRefCache(call.ref);
// Strip any contexts that don't apply inside the function itself.
if InstContext.inRelaxed(context) then
fn_context := InstContext.set(NFInstContext.FUNCTION, NFInstContext.RELAXED);
else
fn_context := NFInstContext.FUNCTION;
end if;

fnl := Function.typeRefCache(call.ref, fn_context);
then
typeArgs(call, context, info);

Expand Down
27 changes: 16 additions & 11 deletions OMCompiler/Compiler/NFFrontEnd/NFFunction.mo
Expand Up @@ -1325,10 +1325,11 @@ uniontype Function
"Returns the function(s) referenced by the given cref, and types them if
they are not already typed."
input ComponentRef functionRef;
input InstContext.Type context = NFInstContext.FUNCTION;
output list<Function> functions;
algorithm
functions := match functionRef
case ComponentRef.CREF() then typeNodeCache(functionRef.node);
case ComponentRef.CREF() then typeNodeCache(functionRef.node, context);
else
algorithm
Error.assertion(false, getInstanceName() + " got invalid function call reference", sourceInfo());
Expand All @@ -1341,6 +1342,7 @@ uniontype Function
"Returns the function(s) in the cache of the given node, and types them if
they are not already typed."
input InstNode functionNode;
input InstContext.Type context = NFInstContext.FUNCTION;
output list<Function> functions;
protected
InstNode fn_node;
Expand All @@ -1352,9 +1354,9 @@ uniontype Function

// Type the function(s) if not already done.
if not typed then
functions := list(typeFunctionSignature(f) for f in functions);
functions := list(typeFunctionSignature(f, context) for f in functions);
InstNode.setFuncCache(fn_node, CachedData.FUNCTION(functions, true, special));
functions := list(typeFunctionBody(f) for f in functions);
functions := list(typeFunctionBody(f, context) for f in functions);
InstNode.setFuncCache(fn_node, CachedData.FUNCTION(functions, true, special));
end if;
end typeNodeCache;
Expand All @@ -1371,22 +1373,24 @@ uniontype Function

function typeFunction
input output Function fn;
input InstContext.Type context = NFInstContext.FUNCTION;
algorithm
fn := typeFunctionSignature(fn);
fn := typeFunctionBody(fn);
fn := typeFunctionSignature(fn, context);
fn := typeFunctionBody(fn, context);
end typeFunction;

function typeFunctionSignature
"Types a function's parameters and local components."
input output Function fn;
input InstContext.Type context;
protected
DAE.FunctionAttributes attr;
InstNode node = fn.node;
algorithm
if not isTyped(fn) then
// Type all the components in the function.
Typing.typeClassType(node, NFBinding.EMPTY_BINDING, NFInstContext.FUNCTION, node);
Typing.typeComponents(node, NFInstContext.FUNCTION);
Typing.typeClassType(node, NFBinding.EMPTY_BINDING, context, node);
Typing.typeComponents(node, context);

if InstNode.isPartial(node) then
ClassTree.applyComponents(Class.classTree(InstNode.getClass(node)), boxFunctionParameter);
Expand All @@ -1402,25 +1406,26 @@ uniontype Function
function typeFunctionBody
"Types the body of a function, along with any component bindings."
input output Function fn;
input InstContext.Type context;
protected
Boolean pure;
DAE.FunctionAttributes attr;
algorithm
// Type the bindings of components in the function.
for c in fn.inputs loop
Typing.typeComponentBinding(c, NFInstContext.FUNCTION);
Typing.typeComponentBinding(c, context);
end for;

for c in fn.outputs loop
Typing.typeComponentBinding(c, NFInstContext.FUNCTION);
Typing.typeComponentBinding(c, context);
end for;

for c in fn.locals loop
Typing.typeComponentBinding(c, NFInstContext.FUNCTION);
Typing.typeComponentBinding(c, context);
end for;

// Type the algorithm section of the function, if it has one.
Typing.typeFunctionSections(fn.node, NFInstContext.FUNCTION);
Typing.typeFunctionSections(fn.node, context);

// Type any derivatives of the function.
for fn_der in fn.derivatives loop
Expand Down
4 changes: 3 additions & 1 deletion OMCompiler/Compiler/NFFrontEnd/NFTyping.mo
Expand Up @@ -193,13 +193,15 @@ function typeStructor
protected
CachedData cache;
list<Function> fnl;
InstContext.Type context;
algorithm
cache := InstNode.getFuncCache(node);

() := match cache
case CachedData.FUNCTION(funcs = fnl, typed = false)
algorithm
fnl := list(Function.typeFunction(fn) for fn in fnl);
context := InstContext.set(NFInstContext.FUNCTION, NFInstContext.RELAXED);
fnl := list(Function.typeFunction(fn, context) for fn in fnl);
fnl := list(OperatorOverloading.patchOperatorRecordConstructorBinding(fn) for fn in fnl);
InstNode.setFuncCache(node, CachedData.FUNCTION(fnl, true, cache.specialBuiltin));
then
Expand Down

0 comments on commit 89b043c

Please sign in to comment.