[Mono-bugs] [Bug 53030][Wis] New - bug in tail call handling
bugzilla-daemon@bugzilla.ximian.com
bugzilla-daemon@bugzilla.ximian.com
Sun, 18 Jan 2004 15:16:46 -0500 (EST)
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by malekith@pld-linux.org.
http://bugzilla.ximian.com/show_bug.cgi?id=53030
--- shadow/53030 2004-01-18 15:16:46.000000000 -0500
+++ shadow/53030.tmp.550 2004-01-18 15:16:46.000000000 -0500
@@ -0,0 +1,445 @@
+Bug#: 53030
+Product: Mono/Runtime
+Version: unspecified
+OS:
+OS Details: PLD Linux
+Status: NEW
+Resolution:
+Severity:
+Priority: Wishlist
+Component: misc
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: malekith@pld-linux.org
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: bug in tail call handling
+
+Description of Problem:
+Mono runtime has problem with tail calls (done using tail. prefix to call
+instruction). The problem is it doesn't seem to replace one of arguments.
+
+
+Steps to reproduce the problem:
+1. Compile attached program using ilasm.
+2. Run it.
+3. It should loop.
+4. Comment tail. in line 262 (before FoldLeft call), compile and run. It
+shouldn't loop.
+
+How often does this happen?
+Always.
+
+Additional Information:
+It works fine with .MS and mint.
+
+The actual source of the program was:
+
+#v+
+public variant list ('a)
+{
+ | Cons { hd : 'a; tl : list ('a); }
+ | Nil {}
+}
+
+module M {
+ public 'a, 'b FoldLeft (f : 'b * 'a -> 'b, acc : 'b, l : list ('a)) : 'b {
+ match (l) {
+ | [] => acc
+ | x :: xs => FoldLeft (f, f (acc, x), xs)
+ }
+ }
+ Main () : void {
+ def l = ["foo"];
+ def f (a : string, b : string) { System.Console.WriteLine ("{0} {1}",
+a, b); b };
+ print_endline (FoldLeft (f, "", l))
+ }
+}
+#v-
+
+However it's in nemerle, so here goes the ildasmed assembly:
+
+#v+
+// Input: out.exe
+// Image type: EXE
+// Native code present: No
+// 32-bit only: No
+// Length of IL data: 4608
+
+.assembly extern mscorlib
+{
+ .ver 1:0:3300:0
+ .publickeytoken = (B7 7A 5C 56 19 34 E0 89) // .z\V.4..
+}
+.assembly NemerleGeneratedAssembly
+{
+ .hash algorithm 0x00008004
+ .ver 1:0:0:0
+}
+.mresource public MonoSymbolFile
+{
+}
+.module NemerleGeneratedModule
+// MVID: {A5EEECC5-6FD9-4CEA-A0AA-67A14F377AF8}
+.namespace Nemerle
+{
+.class public auto interface abstract ansi Func1
+{
+ .method public virtual hidebysig abstract instance class
+System.Object apply(class System.Object) cil managed {}
+}
+}
+.namespace Nemerle
+{
+.class public auto interface abstract ansi Func0 implements Nemerle.Func1
+{
+ .method public virtual hidebysig abstract instance class
+System.Object apply() cil managed {}
+}
+}
+.namespace Nemerle
+{
+.class public auto interface abstract ansi Func2 implements Nemerle.Func1
+{
+ .method public virtual hidebysig abstract instance class
+System.Object apply(class System.Object, class System.Object) cil managed {}
+}
+}
+.namespace Nemerle.Core
+{
+.class public auto ansi Null_match extends [mscorlib]System.Exception
+implements [mscorlib]System.Runtime.Serialization.ISerializable
+{
+ .method public hidebysig specialname rtspecialname instance void
+.ctor() cil managed
+ {
+ // Start of method header: 2122
+ .maxstack 8
+ ?L2123:
+ ldarg.0
+ call instance void [mscorlib]System.Exception::.ctor()
+ ret
+ }
+ .method public static hidebysig bool raise_self() cil managed
+ {
+ // Start of method header: 212a
+ .maxstack 8
+ ?L212b:
+ newobj instance void Nemerle.Core.Null_match::.ctor()
+ throw
+ }
+}
+}
+.class public auto ansi list extends [mscorlib]System.Object
+{
+.class nested public auto ansi Cons extends list
+{
+ .field public class System.Object hd
+ .field public class list tl
+ .method public hidebysig specialname rtspecialname instance void
+.ctor(class System.Object, class list) cil managed
+ {
+ // Start of method header: 2139
+ .maxstack 8
+ ?L213a:
+ ldarg.0
+ call instance void list::.ctor()
+ ldarg.0
+ ldarg.2
+ stfld class list list/Cons::tl
+ ldarg.0
+ ldarg.1
+ stfld class System.Object list/Cons::hd
+ ret
+ }
+}
+.class nested public auto ansi Nil extends list
+{
+ .method public hidebysig specialname rtspecialname instance void
+.ctor() cil managed
+ {
+ // Start of method header: 214f
+ .maxstack 8
+ ?L2150:
+ ldarg.0
+ call instance void list::.ctor()
+ ret
+ }
+}
+ .method public hidebysig specialname rtspecialname instance void
+.ctor() cil managed
+ {
+ // Start of method header: 2131
+ .maxstack 8
+ ?L2132:
+ ldarg.0
+ call instance void [mscorlib]System.Object::.ctor()
+ ret
+ }
+}
+.class public auto ansi M extends [mscorlib]System.Object
+{
+.class nested assembly auto ansi _N_lm_f_400 extends
+[mscorlib]System.Object implements Nemerle.Func2, Nemerle.Func1
+{
+ .method famorassem hidebysig specialname rtspecialname instance
+void .ctor() cil managed
+ {
+ // Start of method header: 2452
+ .maxstack 8
+ ?L2453:
+ ldarg.0
+ call instance void [mscorlib]System.Object::.ctor()
+ ret
+ }
+ .method famorassem virtual hidebysig instance class System.Object
+f(class System.Object, class System.Object) cil managed
+ {
+ .override Nemerle.Func2::apply
+ // Start of method header: 245a
+ .maxstack 4
+ .locals init (class System.String,
+ class System.String)
+ ?L2466:
+ ldarg.1
+ castclass class [mscorlib]System.String
+ stloc.0
+ ldarg.2
+ castclass class [mscorlib]System.String
+ stloc.1
+ ldstr "{0} {1}"
+ ldloc.0
+ ldloc.1
+ call void [mscorlib]System.Console::WriteLine(class
+System.String, class System.Object, class System.Object)
+ ldloc.1
+ ret
+ }
+ .method famorassem virtual hidebysig instance class System.Object
+apply(class System.Object) cil managed
+ {
+ .override Nemerle.Func1::apply
+ // Start of method header: 2482
+ .maxstack 8
+ ?L2483:
+ ldarg.0
+ ldarg.1
+ castclass class Nemerle.Tuple2
+ ldfld class System.Object Nemerle.Tuple2::field1
+ ldarg.1
+ castclass class Nemerle.Tuple2
+ ldfld class System.Object Nemerle.Tuple2::field2
+ tail.
+ callvirt instance class System.Object
+Nemerle.Func2::apply(class System.Object, class System.Object)
+ ret
+ }
+}
+ .method public specialname rtspecialname instance void .ctor() cil
+managed
+ {
+ // Start of method header: 2157
+ .maxstack 8
+ ?L2158:
+ ldarg.0
+ call instance void [mscorlib]System.Object::.ctor()
+ ret
+ }
+ .method public static hidebysig class System.Object FoldLeft(class
+Nemerle.Func2, class System.Object, class list) cil managed
+ {
+ // Start of method header: 215f
+ .maxstack 15
+ .locals init (class list,
+ class System.Object,
+ class list)
+ ?L216b:
+ ldarg.2
+ stloc.0
+ ldloc.0
+ dup
+ brtrue.s ?L2177
+ newobj instance void Nemerle.Core.Null_match::.ctor()
+ throw
+ ?L2177:
+ isinst class list/Nil
+ brtrue.s ?L2181
+ ldc.i4.0
+ br.s ?L2182
+ ?L2181:
+ ldc.i4.1
+ ?L2182:
+ brfalse ?L218d
+ ldc.i4.1
+ br ?L218e
+ ?L218d:
+ ldc.i4.0
+ ?L218e:
+ brfalse ?L2199
+ ldc.i4.1
+ br ?L219a
+ ?L2199:
+ ldc.i4.0
+ ?L219a:
+ brfalse ?L21a5
+ ldarg.1
+ br ?L221f
+ ?L21a5:
+ ldloc.0
+ dup
+ brtrue.s ?L21af
+ newobj instance void Nemerle.Core.Null_match::.ctor()
+ throw
+ ?L21af:
+ isinst class list/Cons
+ brtrue.s ?L21b9
+ ldc.i4.0
+ br.s ?L21ba
+ ?L21b9:
+ ldc.i4.1
+ ?L21ba:
+ brfalse ?L21f5
+ ldloc.0
+ castclass class list/Cons
+ ldfld class System.Object list/Cons::hd
+ stloc.1
+ ldc.i4.1
+ brfalse ?L21ef
+ ldloc.0
+ castclass class list/Cons
+ ldfld class list list/Cons::tl
+ stloc.2
+ ldc.i4.1
+ brfalse ?L21e9
+ ldc.i4.1
+ br ?L21ea
+ ?L21e9:
+ ldc.i4.0
+ ?L21ea:
+ br ?L21f0
+ ?L21ef:
+ ldc.i4.0
+ ?L21f0:
+ br ?L21f6
+ ?L21f5:
+ ldc.i4.0
+ ?L21f6:
+ brfalse ?L2201
+ ldc.i4.1
+ br ?L2202
+ ?L2201:
+ ldc.i4.0
+ ?L2202:
+ brfalse ?L2219
+ ldarg.0
+ ldarg.0
+ ldarg.1
+ ldloc.1
+ callvirt instance class System.Object
+Nemerle.Func2::apply(class System.Object, class System.Object)
+ ldloc.2
+ tail.
+ call class System.Object M::FoldLeft(class
+Nemerle.Func2, class System.Object, class list)
+ ret
+ ?L2219:
+ newobj instance void Nemerle.Core.Match_failure::.ctor()
+ throw
+ ?L221f:
+ ret
+ }
+ .method compilercontrolled static hidebysig void Main() cil managed
+ {
+ // Start of method header: 2220
+ .entrypoint
+ .maxstack 4
+ .locals init (class list,
+ class Nemerle.Func2)
+ ?L222c:
+ ldstr "foo"
+ newobj instance void list/Nil::.ctor()
+ newobj instance void list/Cons::.ctor(class
+System.Object, class list)
+ stloc.0
+ newobj instance void M/_N_lm_f_400::.ctor()
+ stloc.1
+ ldloc.1
+ ldstr ""
+ ldloc.0
+ call class System.Object M::FoldLeft(class
+Nemerle.Func2, class System.Object, class list)
+ castclass class [mscorlib]System.String
+ tail.
+ call void [mscorlib]System.Console::WriteLine(class
+System.String)
+ ret
+ }
+}
+.namespace Nemerle.Core
+{
+.class public auto ansi Aliases extends [mscorlib]System.Object
+{
+ .method public specialname rtspecialname instance void .ctor() cil
+managed
+ {
+ // Start of method header: 225b
+ .maxstack 8
+ ?L225c:
+ ldarg.0
+ call instance void [mscorlib]System.Object::.ctor()
+ ret
+ }
+ .method public static hidebysig void ignore(class System.Object)
+cil managed
+ {
+ // Start of method header: 2263
+ .maxstack 8
+ ?L2264:
+ ret
+ }
+}
+}
+.namespace Nemerle
+{
+.class public auto ansi Tuple2 extends [mscorlib]System.Object
+{
+ .field public class System.Object field1
+ .field public class System.Object field2
+ .method public hidebysig specialname rtspecialname instance void
+.ctor(class System.Object, class System.Object) cil managed
+ {
+ // Start of method header: 2265
+ .maxstack 8
+ ?L2266:
+ ldarg.0
+ call instance void [mscorlib]System.Object::.ctor()
+ ldarg.0
+ ldarg.2
+ stfld class System.Object Nemerle.Tuple2::field2
+ ldarg.0
+ ldarg.1
+ stfld class System.Object Nemerle.Tuple2::field1
+ ret
+ }
+}
+}
+.namespace Nemerle.Core
+{
+.class public auto ansi Match_failure extends [mscorlib]System.Exception
+implements [mscorlib]System.Runtime.Serialization.ISerializable
+{
+ .method public hidebysig specialname rtspecialname instance void
+.ctor() cil managed
+ {
+ // Start of method header: 244a
+ .maxstack 8
+ ?L244b:
+ ldarg.0
+ call instance void [mscorlib]System.Exception::.ctor()
+ ret
+ }
+}
+}
+#v-