Trapping in Dyalog APL v18.0

General APL language issues

Trapping in Dyalog APL v18.0

Postby zaibot.w on Wed Jan 13, 2021 7:30 pm

Hi everyone,

I am migrating an app from Dyalog 17.1 to Dyalog 18.0 and have realized that trapping behavior has changed. I have prepared a code snippet that demonstrates the change. Calling method run results in an infinite loop in Dyalog 18.0, while it works as intended in Dyalog 17.1.

It seems to me, that signalling an error in a Dfns does not terminate the context of the Dfns but rather stops at the current instruction line (as opposed to real functions, where the context of the faulty function is terminated and the instruction pointer is reset to the line in the calling function).

Can someone tell me if this change is intended?

Here is the code:
Code: Select all
:Class Klasse

    ∇ run
      :Access public
      setTrap
      run1
    ∇

    ∇ setTrap;terminate_str;trap_str;method_to_terminate
      :Access private
      #.cnt←0 ⍝ Break an infinite loop, when cnt reached 100 in Dyalog APL 18.0
      method_to_terminate←'run2'
      terminate_str←'⎕←⎕SI ⋄ ⎕TRAP←0⍴⎕TRAP ⋄ →1+↑⎕LC'
      trap_str←'#.cnt+←1 ⋄ ⎕←⎕SI ⋄ ⎕TRAP←,⊂999 ''E'' ((⎕IO+''',method_to_terminate,'''≡↑⎕SI)⊃((⎕IO+2)⊃↑⎕TRAP)''',terminate_str,''') ⋄ ⎕trap←(#.cnt<100)⍴⎕trap ⋄ ⎕SIGNAL 999'
      ⎕TRAP←999 'E'trap_str
    ∇

    ∇ run1
      :Access private
      run2
      ⎕←'Continue here.'
    ∇


    ∇ run2
      :Access private
      run3
      ⎕←'fail'
    ∇

    ∇ run3
      :Access private
      {
          run4
      }0
      ⎕←'fail'
    ∇

    ∇ run4
      :Access private
      run5
      ⎕←'fail'
    ∇

    ∇ run5
      :Access private
      ⍎'⎕SIGNAL 999'
    ∇

:EndClass
zaibot.w
 
Posts: 6
Joined: Mon Jun 29, 2020 4:09 pm

Re: Trapping in Dyalog APL v18.0

Postby AndyS|Dyalog on Thu Jan 14, 2021 1:57 pm

Hi there

I'm talking to my colleagues about this as I am somewhat confused by what is going on. Please can you confirm the full revision numbers of the 17.1 and 18.0 interpreters, as well as the platform(s) your running on.

Can you also confirm that ⎕ml needs to be 3, and that to reproduce the problem we should just call Klasse.run, having declared run to be :Access public shared.
User avatar
AndyS|Dyalog
 
Posts: 257
Joined: Tue May 12, 2009 6:06 pm

Re: Trapping in Dyalog APL v18.0

Postby Phil Last on Thu Jan 14, 2021 4:08 pm

There was a change to the scope of error guards 'though I thought it was after 16 rather than 17.

But so far as I understand it and to the extent that it impacted my work it meant that an error guard in one dfn would control not just other embedded dfns but also any that were called. In other words error guards now have dynamic rather than lexical scope equivalent to :Trap and ⎕TRAP in tradfns.
User avatar
Phil Last
 
Posts: 628
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex

Re: Trapping in Dyalog APL v18.0

Postby Phil Last on Fri Jan 15, 2021 10:38 am

Seems the change to which I was referring was even earlier being introduced in v16.0.

The help "Error Guards" has remained unchanged except for a Note at the end of v16.0 onwards pertaining to tail-calls that, although it's not mentioned, is a side effect of the change.

V16.0 help has another page "Dfns Error Guards" that describes this change but which has been removed from later versions.

But all this is probably a red-herring with regard the original question as that change is apparent between v17.1 and 18.0.

I mention it only because I currently (attempt to) maintain acre in all versions of Dyalog from v14.0 on and occasionally hit mysterious problems that are finally resolved by the realisation that this is the (non-backwards-compatible) cause.
User avatar
Phil Last
 
Posts: 628
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex

Re: Trapping in Dyalog APL v18.0

Postby zaibot.w on Fri Jan 15, 2021 11:52 am

AndyS|Dyalog wrote:Hi there

I'm talking to my colleagues about this as I am somewhat confused by what is going on. Please can you confirm the full revision numbers of the 17.1 and 18.0 interpreters, as well as the platform(s) your running on.

Can you also confirm that ⎕ml needs to be 3, and that to reproduce the problem we should just call Klasse.run, having declared run to be :Access public shared.



Hi,

sorry for the late answer and for the missing information.

So, indeed ⎕io is 0 and ⎕ml is 3, however, I don't know whether this is important for reproducing the error (although the code needs modification if you change these settings, of course).

To reproduce, you should create an instance of Klasse and call run. That's it. Actually, I could've also just used a namespace and regular functions.

Used Dyalog Versions:
Dyalog APL/W Version 17.1.38268 or Dyalog APL/W-64 Version 17.1.38268
vs
Dyalog APL/W Version 18.0.39803 or Dyalog APL/W-64 Version 18.0.39803
zaibot.w
 
Posts: 6
Joined: Mon Jun 29, 2020 4:09 pm

Re: Trapping in Dyalog APL v18.0

Postby AndyS|Dyalog on Mon Jan 18, 2021 7:00 pm

I've investigated further and spoken to my colleagues, and we've come to the conclusion that the 17.1 behaviour is correct. I was getting rather confused as I happened to try a very early 18.0 and then a recent 18.0 and got two different (and in both cases incorrect) results.

FWIW the main problem in 18.0 was due to the new code which supports multi-line input which meant that (effectively) the stack wasn't being cut back correctly when the trap was fired.

This issue requires that you're using ⎕trap 'E', and that the trap statement calls ⎕signal with the same argument as the call to ⎕signal which fired the trap, and that call on ⎕signal was made from a function called from within a dfn.

We have a fix for this which will be in the next DSS update. But zaibot.w, if you can drop support@dyalog.com an email we'll work out the best way to get you the fix too.
User avatar
AndyS|Dyalog
 
Posts: 257
Joined: Tue May 12, 2009 6:06 pm


Return to Language

Who is online

Users browsing this forum: Adam|Dyalog and 1 guest