Puzzling infinite loop in template code

29 views
Skip to first unread message

Andrew Knapp

unread,
Apr 2, 2018, 8:18:54 AM4/2/18
to ats-lang-users
I can't figure out why this code loops forever. Is it a bug in the compiler?

#include "share/atspre_staload.hats"
#include "share/atspre_define.hats"

staload UN
= "prelude/SATS/unsafe.sats"

abst0ype foo
(a:t0ype) = lint
abst0ype twice
(a:t0ype) = int

extern fun{a:t@ype} myprint (x: string): void

implement
(a) myprint<twice(a)>(x) =
  let
    val f
= myprint<a>
 
in
    f
(x);
    f
(x);
 
end

implement
(a) myprint<foo(a)>(x) =
 
begin
   
print("foo(");
    myprint
<a>(x);
   
print(")");
 
end

implement myprint
<int>(x) = print(x)

implement main0
() =
  let
    val x
= "LOOP"
 
in
    myprint
<twice(foo(int))>(x)
 
end



Hongwei Xi

unread,
Apr 2, 2018, 8:35:11 AM4/2/18
to ats-lan...@googlegroups.com
This is caused by a known tail-call optimization bug.
You can circumvent the bug by adding some do-nothing code:

implement(a) myprint<twice(a)>(x) =
  let
    val f
= myprint<a>
 
in
    f
(x);
    f
(x);
    () where { val () = () } // do nothing
  end


--
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+unsubscribe@googlegroups.com.
To post to this group, send email to ats-lang-users@googlegroups.com.
Visit this group at https://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/bf714b63-50da-41c2-9ebc-0f74194572a4%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages