- Add a 'context' string to N_prf F_guard nodes to allow for more descriptive error messages by keeping track of the primitive function, or type pattern function, that is being guarded.
- Add argument types to guard so that we can avoid guards from being optimised away based on dim or shape information, in cases where only the dim or shape of a returned value is needed. (In these cases, hideAkv would not be sufficient)
x1', .., xn' = _guard_ (x1, .., xn, type1, .., typen, pred1, .., predm);
Guards expects n values with corresponding types, and m boolean predicates. If all predicates are true then guard behaves as the identify function on arguments xi, otherwise an error will be raised. These guards serve as a barrier for optimisation and code rewrites around conformity checks and type pattern checks.
In order to be able to catch as many error messages as possible before aborting, a new primitive function _guard_error_
is added.
It behaves similarly to _type_error_
, however it prints a warning to the console and returns false, instead of aborting.
This allows us to print multiple errors, after which the _guard_
function will catch this false value, and aborts the program.
In the future this will allow us to also print a stack-trace at this point.
With this, we get multiple type pattern errors at once:
*** SAC runtime warning
*** In ./tests/type-patterns/test-type-pattern-multiple-errors.sac, line 11, column 1
*** Type pattern error in application of foo: feature `m:shp' in b does not match feature `shp' in a
*** SAC runtime warning
*** In ./tests/type-patterns/test-type-pattern-multiple-errors.sac, line 11, column 1
*** Type pattern error in application of foo: feature `o:shp' in c does not match feature `shp' in a
*** SAC runtime error
*** In ./tests/type-patterns/test-type-pattern-multiple-errors.sac, line 11, column 1
*** Type pattern pre-condition of foo failed
Closes #2362 (closed)