Closed paciorek closed 10 months ago
This duplicates (accidentally) #1295 but has more detail so I've closed 1295.
Relatedly, missing variables are handled differently outside of optim
. In the following, compilation of both causes an error from the C++ compiler, but in the former case, there is a warning about b
being missing.
test <- nimbleFunction(
run = function() {
a <- 7
c <- a+b # warning about 'b' not yet created, then C++ compilation fails
return(c)
returnType(double(0))
})
test2 <- nimbleFunction(
run = function() {
a <- 7
return(a+b) # no warning, C++ compilation fails
returnType(double(0))
})
My thinking at the moment is there are two issues here.
b
above) is missing in return()
as we do with assign
.
b
rather than just warning, but I suspect Perry thought this through and decided on warning for good reason.nimOptim
(and nimIntegrate
) we should handle function args differently such that we look to see if they exist rather than standard processing of them as names. I think we may be able to modify sizeOptim
to deal with this.Branch fix_1356
has changes to address both issues. For the first issue I set .AllowUnknowns
to FALSE
in sizeReturn
. For the second, I flag the function argument of nimOptim
as something not to warn about when not finding in the symbol table.
I am not seeing the full context here in terms of the size processing so my suggested fixes will need a review from @perrydv .
I will file a separate issue about the question of warning vs. error in the case above of b
not being found.
When using
nimOptim
or the (being drafted)nimIntegrate
, we get the warningvariable '<some_nimbleFunction>' has not been created yet
when the output ofoptim
is assigned to a variable. When instead the output is directly returned, the warning is not given. It looks like this relates to howtypeEnv$.AllowUnknowns
is set insizeAssign
vs.sizeReturn
. InsizeAssign
we set it to FALSE before callingasserts <- recurseSetSizes(code, symTab, typeEnv, useArgs = c(FALSE, TRUE))
, but we don't do that before callingrecurseSetSizes
insizeReturn
.@perrydv do you have any idea why we handle
.AllowUnknowns
differently in these two situations?Here's an example.