unison icon indicating copy to clipboard operation
unison copied to clipboard

round trip error with long abilities lists

Open stew opened this issue 1 year ago • 2 comments

the following code fails to round trip. Once it wants to split the abilities list across multiple lines it doesn't indent the abilities enough

ability January where capricorn : {January} ()

ability February where aquarius : {February} ()

ability March where pisces : {March} ()

ability April where aries : {April} ()

ability May where taurus : {May} ()

ability June where gemini : {June} ()

ability July where cancer : {July} ()

ability August where leo : {August} ()

ability September where virgo : {September} ()

ability October where libra : {October} ()

ability November where scorpio : {November} ()

ability December where sagittarius : {December} ()

foo : a ->{January, February, March, April, May, June, July, August, September, October, November, December} a -> ()
foo a b = ()

stew avatar Feb 09 '24 21:02 stew

Has this been fixed? I see this printed as

foo :
  a
  ->{May,
  February,
  October,
  June,
  January,
  November,
  March,
  December,
  April,
  September,
  July,
  August} a
  -> ()
foo a b = ()

which parses fine.

mitchellwrosen avatar Apr 07 '24 16:04 mitchellwrosen

@mitchellwrosen hmm yeah with release 0.5.19 the above example works fine for me. But the cloud client pool.wrap doesn't. If you shrink it to a single line it compiles fine. Interestingly toRemote which has a pretty similar type signature seems to roundtrip fine.

ceedubs avatar Apr 09 '24 14:04 ceedubs

Ok, here's how pool.wrap prints

pool.wrap :
  (a
  ->{Config,
  Exception,
  State,
  Http,
  Services,
  Remote,
  websockets.HttpWebSocket,
  WebSockets,
  Random,
  Log,
  Scratch} b)
  -> a
  ->{Remote} b
pool.wrap f a = await (Remote.fork !pool do randomly do f a)

and here's the (confusing) parse error

  I got confused here:

     12 |   Log,


  I was surprised to find an end of section here.
  I was expecting one of these instead:

  * ,
  * ->

Although it's printed hideously, I don't see why that syntax shouldn't parse. So it's a parse error? Perhaps someone more familiar with the parser could weigh in on whether that should parse or not.

mitchellwrosen avatar May 23 '24 14:05 mitchellwrosen

Oh boy, this makes no sense to me. If you comment out the line it's complaining about...

pool.wrap :
  (a
  ->{Config,
  Exception,
  State,
  Http,
  Services,
  Remote,
  websockets.HttpWebSocket,
  WebSockets,
  Random,
  -- Log,
  Scratch} b)
  -> a
  ->{Remote} b
pool.wrap f a = await (Remote.fork !pool do randomly do f a)

it parses fine... wat

mitchellwrosen avatar May 23 '24 14:05 mitchellwrosen

:-/ hm well see if you can minimize it. what about a different ability besides Log? or deleting the line instead of commenting it? or fewer abilities but with Log?

aryairani avatar May 23 '24 14:05 aryairani

I can't really minimize it in a way that makes it clear what's going on. You can certainly get the error to appear and disappear just by playing around. The Log, Random, and Remote abilities seem to cause the most trouble.

mitchellwrosen avatar May 23 '24 14:05 mitchellwrosen

In this code

pool.wrap :
  (a ->{Config,
  Remote,
  Log,
  Scratch} b)
  -> a
  ->{Remote} b
pool.wrap f a = await (Remote.fork !pool do randomly do f a)

there is a syntax error on Remote,. The lexed tokens of that first ability list are

    Open "{"
      WordyId (NameOnly (Name Relative (Config :| [])))
      Reserved ","
      WordyId (NameOnly (Name Relative (Remote :| [])))
      Semi True
      Reserved ","
      WordyId (NameOnly (Name Relative (Log :| [])))
      Reserved ","
      WordyId (NameOnly (Name Relative (Scratch :| [])))
    Close

That Semi True is what's causing the error - not sure why it's appearing there! Curiously, if we swap the lexeme Remote for Exception, then the Semi True goes away.

    Open "{"
      WordyId (NameOnly (Name Relative (Config :| [])))
      Reserved ","
      WordyId (NameOnly (Name Relative (Exception :| [])))
      Reserved ","
      WordyId (NameOnly (Name Relative (Log :| [])))
      Reserved ","
      WordyId (NameOnly (Name Relative (Scratch :| [])))
    Close

mitchellwrosen avatar May 23 '24 15:05 mitchellwrosen

(a ->{Config,
Random, Scratch} b)

lexes incorrectly (erroneous Semi True) yet both of these lex correctly

Variant 1: space after Random

(a ->{Config,
Random , Scratch} b)

Variant 2: some other string than Random:

(a ->{Config,
Random2, Scratch} b)

mitchellwrosen avatar May 23 '24 15:05 mitchellwrosen

the Semi True is coming from this line

mitchellwrosen avatar May 23 '24 15:05 mitchellwrosen

Just an idea: I see we don't emit virtual semis inside parens. Do we also want to avoid emitting virtual semis inside curly brackets like in this example? @pchiusano maybe you would recall some of the virual semi details.

mitchellwrosen avatar May 23 '24 15:05 mitchellwrosen

@runarorama might also know the answer to the previous question

aryairani avatar May 23 '24 16:05 aryairani

Does it have anything to do with the outdent relative to the {?

aryairani avatar May 23 '24 16:05 aryairani

Yeah @aryairani, it does

mitchellwrosen avatar May 23 '24 17:05 mitchellwrosen

@mitchellwrosen Could you post a concise version of the question to #toolchain-development and if we don't learn anything new in the next couple days then plan to go it alone

aryairani avatar Jun 11 '24 00:06 aryairani