Re: Segmentation fault in Braun Tree example (modified)

2020-08-20 Thread Timmy Jose
Okay, that was embarrassing! I should probably have rested a bit before 
having another look at it before posting it. Thank you for the fix. :-)

> When I encounter a segfault, it is usually caused by recursion depth 
being over some kind of limit.

Thank you! This is a useful tip to keep in mind.

Cheers,

Timmy

On Thursday, August 20, 2020 at 9:39:22 PM UTC+5:30 gmhwxi wrote:

> When I encounter a segfault, it is usually caused by recursion depth being 
> over some kind of limit.
>
> In your code, the 'aux' function is defined but never called. Here is a 
> fixed version:
>
> fun
> {a: t@ype}
> brauntest1 (t0: tree a): bool = 
>   let exception Negative of ()
>   fun aux (t0: tree a): bool = 
> case+ t0 of
>   | tree_nil () => true
>   | tree_cons (tl, _, tr) => 
>   let val szl = size (tl)
>   val szr = size (tr)
>   in
> if abs (szl - szr) > 1 then $raise Negative ()
>   else aux(tl) andalso aux(tr)
>   end
>   in
> try aux(t0) with ~Negative () => false
>   end
>
> On Thu, Aug 20, 2020 at 6:46 AM Timmy Jose  wrote:
>
>>
>>
>> Hi,
>>
>> I have a variation of the Braun Tree test (where the size of the left and 
>> right subtrees differ by at most 1 at every level) from the tutorials, and 
>> this one, for some reason gives a segmentation fault.
>>
>> Here is the snippet:
>>
>> fun
>> {a: t@ype}
>> brauntest1 (t0: tree a): bool = 
>>   let exception Negative of ()
>>   fun aux (t0: tree a): bool = 
>> case+ t0 of
>>   | tree_nil () => true
>>   | tree_cons (tl, _, tr) => 
>>   let val szl = size (tl)
>>   val szr = size (tr)
>>   in
>> if abs (szl - szr) > 1 then $raise Negative ()
>>   else brauntest1 (tl) andalso brauntest1 (tr)
>>   end
>>   in
>> try brauntest1 (t0) with ~Negative () => false
>>   end
>>
>> And here is the output from `lldb` (gdb has some code-signing issues on 
>> macOS). 
>>
>> $ lldb braun
>> (lldb) target create "braun"
>> Current executable set to 'braun' (x86_64).
>> (lldb) r
>> Process 28137 launched: '/braun' (x86_64)
>> Process 28137 stopped
>> * thread #1, queue = 'com.apple.main-thread', stop reason = 
>> EXC_BAD_ACCESS (code=2, address=0x7ffeef3fff68)
>> frame #0: 0x00011577 braun`brauntest1_3__3__1 + 39
>> braun`brauntest1_3__3__1:
>> ->  0x11577 <+39>: callq  0x11c3a   ; symbol stub 
>> for: setjmp
>> 0x1157c <+44>: testl  %eax, %eax
>> 0x1157e <+46>: je 0x115de   ; <+142>
>> 0x11580 <+48>: movq   0xb31(%rip), %rcx ; 
>> my_atsexnframe_getref.my_atsexnframe
>> Target 0: (braun) stopped.
>> (lldb)
>>
>> Anybody seen this before, or have an idea what might be going wrong?
>>
>> Thanks!
>>
>> Timmy
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "ats-lang-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to ats-lang-user...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ats-lang-users/ad557181-8986-4784-a724-2f2bba9cd5d9n%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"ats-lang-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ats-lang-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/afa8ffd4-f3d5-4a27-93d0-07c9bceb6a00n%40googlegroups.com.


Re: Segmentation fault in Braun Tree example (modified)

2020-08-20 Thread Hongwei Xi
When I encounter a segfault, it is usually caused by recursion depth being
over some kind of limit.

In your code, the 'aux' function is defined but never called. Here is a
fixed version:

fun
{a: t@ype}
brauntest1 (t0: tree a): bool =
  let exception Negative of ()
  fun aux (t0: tree a): bool =
case+ t0 of
  | tree_nil () => true
  | tree_cons (tl, _, tr) =>
  let val szl = size (tl)
  val szr = size (tr)
  in
if abs (szl - szr) > 1 then $raise Negative ()
  else aux(tl) andalso aux(tr)
  end
  in
try aux(t0) with ~Negative () => false
  end

On Thu, Aug 20, 2020 at 6:46 AM Timmy Jose  wrote:

>
>
> Hi,
>
> I have a variation of the Braun Tree test (where the size of the left and
> right subtrees differ by at most 1 at every level) from the tutorials, and
> this one, for some reason gives a segmentation fault.
>
> Here is the snippet:
>
> fun
> {a: t@ype}
> brauntest1 (t0: tree a): bool =
>   let exception Negative of ()
>   fun aux (t0: tree a): bool =
> case+ t0 of
>   | tree_nil () => true
>   | tree_cons (tl, _, tr) =>
>   let val szl = size (tl)
>   val szr = size (tr)
>   in
> if abs (szl - szr) > 1 then $raise Negative ()
>   else brauntest1 (tl) andalso brauntest1 (tr)
>   end
>   in
> try brauntest1 (t0) with ~Negative () => false
>   end
>
> And here is the output from `lldb` (gdb has some code-signing issues on
> macOS).
>
> $ lldb braun
> (lldb) target create "braun"
> Current executable set to 'braun' (x86_64).
> (lldb) r
> Process 28137 launched: '/braun' (x86_64)
> Process 28137 stopped
> * thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS
> (code=2, address=0x7ffeef3fff68)
> frame #0: 0x00011577 braun`brauntest1_3__3__1 + 39
> braun`brauntest1_3__3__1:
> ->  0x11577 <+39>: callq  0x11c3a   ; symbol stub for:
> setjmp
> 0x1157c <+44>: testl  %eax, %eax
> 0x1157e <+46>: je 0x115de   ; <+142>
> 0x11580 <+48>: movq   0xb31(%rip), %rcx ;
> my_atsexnframe_getref.my_atsexnframe
> Target 0: (braun) stopped.
> (lldb)
>
> Anybody seen this before, or have an idea what might be going wrong?
>
> Thanks!
>
> Timmy
>
> --
> You received this message because you are subscribed to the Google Groups
> "ats-lang-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ats-lang-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/ad557181-8986-4784-a724-2f2bba9cd5d9n%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"ats-lang-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ats-lang-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLqhKexD7BhuSSGF9EUZ9cqz%2BZJ-nWg-2s1Tz7JeZWFwMA%40mail.gmail.com.


Segmentation fault in Braun Tree example (modified)

2020-08-20 Thread Timmy Jose


Hi,

I have a variation of the Braun Tree test (where the size of the left and 
right subtrees differ by at most 1 at every level) from the tutorials, and 
this one, for some reason gives a segmentation fault.

Here is the snippet:

fun
{a: t@ype}
brauntest1 (t0: tree a): bool = 
  let exception Negative of ()
  fun aux (t0: tree a): bool = 
case+ t0 of
  | tree_nil () => true
  | tree_cons (tl, _, tr) => 
  let val szl = size (tl)
  val szr = size (tr)
  in
if abs (szl - szr) > 1 then $raise Negative ()
  else brauntest1 (tl) andalso brauntest1 (tr)
  end
  in
try brauntest1 (t0) with ~Negative () => false
  end

And here is the output from `lldb` (gdb has some code-signing issues on 
macOS). 

$ lldb braun
(lldb) target create "braun"
Current executable set to 'braun' (x86_64).
(lldb) r
Process 28137 launched: '/braun' (x86_64)
Process 28137 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS 
(code=2, address=0x7ffeef3fff68)
frame #0: 0x00011577 braun`brauntest1_3__3__1 + 39
braun`brauntest1_3__3__1:
->  0x11577 <+39>: callq  0x11c3a   ; symbol stub for: 
setjmp
0x1157c <+44>: testl  %eax, %eax
0x1157e <+46>: je 0x115de   ; <+142>
0x11580 <+48>: movq   0xb31(%rip), %rcx ; 
my_atsexnframe_getref.my_atsexnframe
Target 0: (braun) stopped.
(lldb)

Anybody seen this before, or have an idea what might be going wrong?

Thanks!

Timmy

-- 
You received this message because you are subscribed to the Google Groups 
"ats-lang-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ats-lang-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/ad557181-8986-4784-a724-2f2bba9cd5d9n%40googlegroups.com.