akeep / nanopass-framework-racket

Racket port of the nanopass-framework
MIT License
34 stars 9 forks source link

Internal error from pass.rkt #40

Closed soegaard closed 9 years ago

soegaard commented 9 years ago

This program: https://gist.github.com/soegaard/c921dd922b198b06729e gives the internal error:

../nanopass-framework-racket/private/pass.rkt:302:6: car: contract violation expected: pair? given: #<syntax (((catch-finally (unquote x) ...>

soegaard commented 9 years ago

It has something to do with the catch-finally production.

(CatchFinally (cf) (catch x σ ...) (finally σ ...) (catch-finally x (σ ...) (σ0 ...)))

If it is removed (the corresponding clause in generate-code is also removed) then the internal error disappears.

akeep commented 9 years ago

Wow, that is a really nasty error message.

It is failing because you have a mis-placed close parenthesis on line 1356:

1356 [(catch-finally ,x (,σ ...) (,σ0 ...) (let ([σ (map Statement σ)] 1357 [σ0 (map Statement σ0)]) 1358 (list "catch" (~parens x) (~braces σ) 1359 "finally" (~braces σ0))))])

Your (catch-finally … doesn’t end until the end of the full (let ([σ (map Statement σ)] …) because you are missing the close parenthesis after (,σ0 …)

Once I added a close parenthesis at the end of the (catch-finally …) and removed the corresponding one after the (list “catch” …), it helped quite a bit:

-> (require "urlang.rkt") ; urlang.rkt:1355:69: x: unbound identifier in module ; in: x ; [,bt for context]

The spurious reference to x seems to be in the previous clause:

1354 [(finally ,σ ...) (let ([σ (map Statement σ)]) 1355 (list "finally" (~parens x) (~braces σ)))]

in the (~parens x). When I remove this it seems to be able to load it:

-> (require "urlang.rkt") ->

All of that said, this is pretty egregious for error reporting. It should recognize that it has been handed something of the wrong shape and report it, rather than blowing up with this error message.

(Hopefully this fix will get you rolling though, until I get a chance to look into out why we’re failing this way when we get some syntax we don’t understand.)

-andy:)

On Aug 12, 2015, at 5:15 PM, Jens Axel Søgaard notifications@github.com wrote:

It has something to do with the catch-finally production.

(CatchFinally (cf) (catch x σ ...) (finally σ ...) (catch-finally x (σ ...) (σ0 ...)))

If it is removed (the corresponding clause in generate-code is also removed) then the internal error disappears.

— Reply to this email directly or view it on GitHub https://github.com/akeep/nanopass-framework-racket/issues/40#issuecomment-130451058.

soegaard commented 9 years ago

2015-08-12 23:31 GMT+02:00 Andy Keep notifications@github.com:

Wow, that is a really nasty error message.

Agree.

It is failing because you have a mis-placed close parenthesis on line 1356:

1356 [(catch-finally ,x (,σ ...) (,σ0 ...) (let ([σ (map Statement σ)] 1357 [σ0 (map Statement σ0)]) 1358 (list "catch" (~parens x) (~braces σ) 1359 "finally" (~braces σ0))))])

Your (catch-finally … doesn’t end until the end of the full (let ([σ (map Statement σ)] …) because you are missing the close parenthesis after (,σ0 …)

Nice catch. Due to the error message I didn't even think to look for a misplaced parenthesis.

Once I added a close parenthesis at the end of the (catch-finally …) and removed the corresponding one after the (list “catch” …), it helped quite a bit:

-> (require "urlang.rkt") ; urlang.rkt:1355:69: x: unbound identifier in module ; in: x ; [,bt for context]

The spurious reference to x seems to be in the previous clause:

1354 [(finally ,σ ...) (let ([σ (map Statement σ)]) 1355 (list "finally" (~parens x) (~braces σ)))]

in the (~parens x). When I remove this it seems to be able to load it:

-> (require "urlang.rkt") ->

All of that said, this is pretty egregious for error reporting. It should recognize that it has been handed something of the wrong shape and report it, rather than blowing up with this error message.

(Hopefully this fix will get you rolling though, until I get a chance to look into out why we’re failing this way when we get some syntax we don’t understand.)

It will. Thanks for the tip.

/Jens Axel

akeep commented 9 years ago

Okay, I fixed this up. Turns out it was heading down an error path and in the error was improperly calling car on a syntax object. (Now it is using stx-car.)