eo icon indicating copy to clipboard operation
eo copied to clipboard

Equivalent abstraction syntax yields different XMIR output

Open nikololiahim opened this issue 2 years ago • 5 comments

The following two pieces of code should be syntactically equivalent: singleline.eo

(dir "/tmp").walk
  * ([f] (f.is-dir > @))

multiline.eo

walk.
  dir
    "/tmp"
  *
    [f]
      f.is-dir > @

However, the xmir produced by singleline.eo (this one is wrong, because .walk comes from (dir "string")): singleline.xml

...
<objects>
      <o base="dir" line="1" pos="1">
         <o base="string" data="string" line="1" pos="5">/tmp</o>
      </o>
      <o base=".walk" line="1" method="">
         <o base="array" data="array" line="2" pos="2">
            <o line="2" pos="5">
               <o line="2" pos="5">
                  <o line="2" name="f" pos="6"/>
                  <o base="f" line="2" pos="10"/>
                  <o base=".is-dir" line="2" method="" name="@"/>
               </o>
            </o>
         </o>
      </o>
   </objects>
...

is different from the xmir produced by multiline.eo (this one is correct)

...
<objects>
      <o base=".walk" line="1" pos="0">
         <o base="dir" line="2" pos="2">
            <o base="string" data="string" line="3" pos="4">/tmp</o>
         </o>
         <o base="array" data="array" line="4" pos="2">
            <o line="5" pos="4">
               <o line="5" name="f" pos="5"/>
               <o base="f" line="6" pos="6"/>
               <o base=".is-dir" line="6" method="" name="@"/>
            </o>
         </o>
      </o>
   </objects>
...

nikololiahim avatar Apr 11 '22 11:04 nikololiahim

@Graur please, verify this report (it's pretty old) and fix if the bug is still here

yegor256 avatar Aug 23 '22 19:08 yegor256

@l3r8yJ Please, take care of this

Graur avatar Sep 21 '22 15:09 Graur

@Graur sure!

l3r8yJ avatar Sep 21 '22 15:09 l3r8yJ

@Graur did I understand correctly that this class does not work correctly? If so, maybe we should transfer issue here?

l3r8yJ avatar Sep 22 '22 00:09 l3r8yJ

@l3r8yJ For this ticket we don't care about any particular class. We need just to compare two xmir files produced from singleline EO representation and multiline

Graur avatar Sep 22 '22 08:09 Graur

@Graur did i understand correctly that I need to reproduce the code in singleline and multiline, then compare xmir and say whether the bug report is relevant or not?

l3r8yJ avatar Oct 21 '22 13:10 l3r8yJ

@l3r8yJ Absolutely right. But if they are different we need to fix it

Graur avatar Oct 21 '22 13:10 Graur

@Graur got it!

l3r8yJ avatar Oct 21 '22 13:10 l3r8yJ

@Graur have a look, please

Here is singleline:

<objects>
      <o abstract="" line="3" name="app" pos="0">
         <o line="3" name="args" pos="1" vararg=""/>
         <o alias="1" base="dir" line="4" pos="3">
            <o base="string" data="string" line="4" pos="7">/tmp</o>
         </o>
         <o base=".walk" line="4" method="" pos="14">
            <o base="array" data="array" line="5" pos="4">
               <o alias="2" line="5" pos="7">
                  <o abstract="" line="5" pos="7">
                     <o line="5" name="f" pos="8"/>
                     <o alias="3" base="f" line="5" pos="12"/>
                     <o base=".is-dir" line="5" method="" name="@" pos="13"/>
                  </o>
               </o>
            </o>
         </o>
      </o>
</objects>

Here is multiline:

<objects>
      <o abstract="" line="3" name="app" pos="0">
         <o line="3" name="args" pos="1" vararg=""/>
         <o base=".walk" line="4" pos="2">
            <o base="dir" line="5" pos="4">
               <o base="string" data="string" line="6" pos="6">/tmp</o>
            </o>
            <o base="array" data="array" line="7" pos="4">
               <o abstract="" line="8" pos="6">
                  <o line="8" name="f" pos="7"/>
                  <o base="f" line="9" pos="8"/>
                  <o base=".is-dir" line="9" method="" name="@" pos="9"/>
               </o>
            </o>
         </o>
      </o>
</objects>

in multiline we're good, but in singleline we get an error: The object has attribute without a name, line=5, pos=7 (noname-attributes:22)

btw, code example was taken from a pdf about eo: image

l3r8yJ avatar Oct 21 '22 15:10 l3r8yJ

@Graur have a look, please Looks like

(dir "/tmp").walk
  [f] f.is-dir > @

works fine, we don't need the * symbol before [f].

also xmir is the same as multiline:

<objects>
      <o abstract="" line="3" name="app" pos="0">
         <o line="3" name="args" pos="1" vararg=""/>
         <o alias="1" base="dir" line="4" pos="3">
            <o base="string" data="string" line="4" pos="7">/tmp</o>
         </o>
         <o base=".walk" line="4" method="" pos="14">
            <o abstract="" line="5" pos="4">
               <o line="5" name="f" pos="5"/>
               <o base="f" line="5" pos="8"/>
               <o base=".is-dir" line="5" method="" name="@" pos="9"/>
            </o>
         </o>
      </o>
</objects>

Where do I need to create an eo pdf fixing issue?

l3r8yJ avatar Oct 24 '22 09:10 l3r8yJ

@l3r8yJ You can find it here: https://github.com/objectionary/eo/blob/master/paper/sections/syntax.tex#L480-L506. And commit your changes just like you do it with code

Graur avatar Oct 24 '22 09:10 Graur

@nikololiahim @yegor256 have a look, please

I compared

walk.
  dir
    "/tmp"
  [f]
    f.is-dir > @  

and

(dir "/tmp").walk
  [f] > (f.is-dir > @)

here is a comparison between the correct variants multiline:

   <objects>
      <o abstract="" line="3" name="app" pos="0">
         <o line="3" name="args" pos="1" vararg=""/>
         <o base=".walk" line="4" pos="2">
            <o base="dir" line="5" pos="4">
               <o base="string" data="string" line="6" pos="6">/tmp</o>
            </o>
            <o abstract="" line="7" pos="4">
               <o line="7" name="f" pos="5"/>
               <o base="f" line="8" pos="6"/>
               <o base=".is-dir" line="8" method="" name="@" pos="7"/>
            </o>
         </o>
      </o>
   </objects>

singleline:

   <objects>
      <o abstract="" line="3" name="app" pos="0">
         <o line="3" name="args" pos="1" vararg=""/>
         <o alias="1" base="dir" line="4" pos="3">
            <o base="string" data="string" line="4" pos="7">/tmp</o>
         </o>
         <o base=".walk" line="4" method="" pos="14">
            <o abstract="" line="5" pos="4">
               <o line="5" name="f" pos="5"/>
               <o alias="2" base="f" line="5" pos="9"/>
               <o base=".is-dir" line="5" method="" name="@" pos="10"/>
            </o>
         </o>
      </o>
   </objects>

In comparsion, are we looking to base tag? If so, it looks like the same xmirs now, doesn't it?

l3r8yJ avatar Oct 24 '22 11:10 l3r8yJ

@yegor256 please take a look, it looks like the author of the issue is not active, what should we do?

l3r8yJ avatar Nov 13 '22 12:11 l3r8yJ

@mximp please, help us here

yegor256 avatar Nov 13 '22 12:11 yegor256

@l3r8yJ I still see some issues. Have you tried to run the single-line code:

(dir "/tmp").walk
  [f] > (f.is-dir > @)

I suppose it will fail as according to XMIR it tries to call .walk on the abstract object [f] > (f.is-dir > @) whereas it is expected to be called on (dir "/tmp")

mximp avatar Nov 16 '22 09:11 mximp

@mximp where we are with this problem?

yegor256 avatar Mar 05 '23 05:03 yegor256

@mximp I went back to this issue and will solve it

l3r8yJ avatar Aug 03 '23 21:08 l3r8yJ

@l3r8yJ where are you with this problem? If you don't mind I can take it

maxonfjvipon avatar Sep 08 '23 07:09 maxonfjvipon

@maxonfjvipon sure, I don't have time to fit it into my schedule ; (

l3r8yJ avatar Sep 08 '23 07:09 l3r8yJ

@yegor256 @Graur I don't see any problem here. I simplified the example:

if. > first
  TRUE
  1
  2
TRUE.if > second
  1
  2

This is xmir after PARSING step and yes, these objects look differently:

<o base=".if" line="2" name="first" pos="2">
<o base="bool" data="bytes" line="3" pos="4">01</o>
    <o base="int" data="bytes" line="4" pos="4">00 00 00 00 00 00 00 01</o>
    <o base="int" data="bytes" line="5" pos="4">00 00 00 00 00 00 00 02</o>
</o>
<o base="bool" data="bytes" line="6" pos="2">01</o>
<o base=".if" line="6" method="" name="second" pos="6">
    <o base="int" data="bytes" line="7" pos="4">00 00 00 00 00 00 00 01</o>
    <o base="int" data="bytes" line="8" pos="4">00 00 00 00 00 00 00 02</o>
</o>

But they become the same after OPTIMIZATION step:

<o base=".if" line="2" loc="Φ.main.first" name="first" pos="2">
    <o base="org.eolang.bool"
       data="bytes"
       line="3"
       loc="Φ.main.first.ρ"
       pos="4">01</o>
    <o base="org.eolang.int"
       data="bytes"
       line="4"
       loc="Φ.main.first.α0"
       pos="4">00 00 00 00 00 00 00 01</o>
    <o base="org.eolang.int"
       data="bytes"
       line="5"
       loc="Φ.main.first.α1"
       pos="4">00 00 00 00 00 00 00 02</o>
</o>
<o base=".if" line="6" loc="Φ.main.second" name="second" pos="6">
    <o base="org.eolang.bool"
       data="bytes"
       line="6"
       loc="Φ.main.second.ρ"
       pos="2">01</o>
    <o base="org.eolang.int"
       data="bytes"
       line="7"
       loc="Φ.main.second.α0"
       pos="4">00 00 00 00 00 00 00 01</o>
    <o base="org.eolang.int"
       data="bytes"
       line="8"
       loc="Φ.main.second.α1"
       pos="4">00 00 00 00 00 00 00 02</o>
</o>

I believe there's no dogma that the same objects written in different notations should look the same after parsing step. That's why I think we can just close the ticket

maxonfjvipon avatar Sep 08 '23 07:09 maxonfjvipon

@Graur I agree

yegor256 avatar Sep 08 '23 08:09 yegor256