Question about array out-of-bound checking
lgxbslgx opened this issue · comments
Hi all,
I added the + 1
to the function Array::iter
to trigger the out-of-bound error. But all the tests passed locally (x86 & Linux). Whether the compiler do such check? Or is it a bug?
/// @intrinsic %array.iter
pub fn iter[T](self : Array[T], f : (T) -> Unit) -> Unit {
- for i = 0; i < self.length(); i = i + 1 {
+ for i = 0; i < self.length() + 1; i = i + 1 {
f(self[i])
}
}
Best Regards,
-- Guoxiong
It seems that the compiler uses builtin intrinsic by default. Actually this code won't be executed even if you write:
pub fn iter[T](self : Array[T], f : (T) -> Unit) -> Unit {}
all tests can also be completed.
It seems that the compiler uses builtin intrinsic by default. Actually this code won't be executed even if you write:
pub fn iter[T](self : Array[T], f : (T) -> Unit) -> Unit {}
all tests can also be completed.
It seems you are right. I added debug("test")
to the begining of the function Array::iter
, but the message can't be printed.
The body of function which marked@intrinsic
said it's default implementation. Compiler may not use default implementation if it found builtin platform specific implementation.
You can remove the @intrinsic
mark to disable this behavior.
we will disable @intrinsic in debug mode
Thanks for your answers.