[M3devel] narrow still failing..

Rodney M. Bates rodney_bates at lcwb.coop
Mon Jan 20 18:02:40 CET 2014


Lots more experiments, still no reproduction of the problem on AMD64_LINUX.
The 5 cases in the program below all work.  But earlier versions of this
test program, with bugs, (failure to repeat x:=y before every Z* call)
suggested a hypothesis.

For x := BDD.Format(x)

Perhaps the compiler does something to the LHS x (zeros it out?) before
narrowing and passing the x that is an actual parameter to Format.

If so, it is an implementation bug, as the language says (2.3.1):

   (for v := e)

   "The order of evaluation of v and e is undefined, but e will be evaluated
    before v is updated."

_____________________________________________________________________________________

MODULE Main;

TYPE T = OBJECT l : T; END;

TYPE Root = T OBJECT id : CARDINAL; END;

PROCEDURE Format(x : T) : TEXT =
   BEGIN
     RETURN "Format"
   END Format;

PROCEDURE P() : REFANY =
   BEGIN
     VAR x, y : REFANY;
     BEGIN
       y := NEW ( Root );
       x := y;
       Z1(x);
       x := y;
       Z2(x);
       x := y;
       Z3(x);
       x := y;
       Z4(x);
       x := y;
       Z5(x);
       RETURN x
     END
   END P;

PROCEDURE Z1(VAR x : REFANY) =
   BEGIN
     TYPECASE x OF
       T (b) => x := Format(b)
     END;
   END Z1;

PROCEDURE Z2(VAR x : REFANY) =
   VAR b : T;
   BEGIN
     b := x;
     x := Format(b)
   END Z2;

PROCEDURE Z3(VAR x : REFANY) =
   BEGIN
     x := Format(x)
   END Z3;

PROCEDURE Z4(VAR x : REFANY) =
   BEGIN
     TYPECASE x OF
       T => x := Format (x)
     END;
   END Z4;

PROCEDURE Z5(VAR x : REFANY) =
   BEGIN
     IF ISTYPE (x, T) THEN
       x := Format (x)
     END;
   END Z5;

BEGIN
   EVAL P()
END Main.

______________________________________________________________________________________

On 01/19/2014 04:01 PM, mika at async.caltech.edu wrote:
> As in the ISTYPE/TYPECASE example, the following works:
>
>
> PROCEDURE Z(VAR x : REFANY) =
>    BEGIN
>      TYPECASE x OF
>        BDD.T(b) => x := BDD.Format(b)
>      END;
>    END Z;
>
> (244)rover:~/refany/src>../FreeBSD4/refany
> a
>
>
> This does NOT work:
>
> PROCEDURE Z(VAR x : REFANY) =
>    BEGIN
>      TYPECASE x OF
>        BDD.T(b) => x := BDD.Format(x)
>      END;
>    END Z;
>
>
> (242)rover:~/refany/src>../FreeBSD4/refany
>
>
> ***
> *** runtime error:
> ***    NARROW failed
> ***    file "/big/home/mika/refany/src/Main.m3", line 22
> ***
>
>    use option @M3stackdump to get a stack trace
> Abort
>
>
> Same result PM3 / CM3.
>
>       Mika
>




More information about the M3devel mailing list