ceylon / ceylon.ast

Apache License 2.0
18 stars 3 forks source link

Should ceylon.ast comply with the compiler instead of the specification? #123

Closed lucaswerkmeister closed 8 years ago

lucaswerkmeister commented 8 years ago

The ceylon.ast.core module documentation says:

ceylon.ast seeks to comply only with the Ceylon Language Specification, not its implementation in the compiler.

Should we abandon this, and instead seek compliance with the compiler?

If yes: how far do we go? The module documentation cites the example of empty resource lists for try, which are permitted by the grammar so that the compiler can give you a better error message than a syntax error. Should cases like this be allowed as well, or only cases that are actually legal on at least one backend, without any error messages, like #122?

Pros:

Cons:

jvasileff commented 8 years ago

My thoughts:

lucaswerkmeister commented 8 years ago

There don’t seem to be that many deviations

I assume that you don’t want to accept try () and suchlike? Because there’s a lot more cases like that.

jvasileff commented 8 years ago

accept everything that passes through the typechecker without error

To be clear, I mean within reason, and for things that aren't considered bugs-that-will-be-fixed in the typechecker.

jvasileff commented 8 years ago

try ()?

lucaswerkmeister commented 8 years ago

Yes, because that gets you an

error: empty resource list

instead of an

error: incorrect syntax: extraneous token ',' expecting closing parenthesis ')'

which is what the “how far do we go?” question in the issue is about.

jvasileff commented 8 years ago

I see. I'm not currently exposing ceylon.ast to trees that have errors, recognition or otherwise.

Except... I am concerned about what to do about native(other) declarations that have errors like that, since I'm currently ignoring errors that don't apply to Dart. Its unclear to me if the ones I should care about can be distinguished from those that can't. This is a tricky problem:

native("jvm") void foo() {
    try() {}
}

crashes compile-dart, while the same w/o native does not.

Maybe I can pre-process the rhAst to remove stuff I want to completely ignore. But then, what if there's some reason I do need those declarations? Just brainstorming, another option may be to have some filtering mechanism in ceylon.ast.redhat.

jvasileff commented 8 years ago

@lucaswerkmeister I propose we resolve this issue by saying that "within reason" ceylon.ast should accept whatever the typechecker accepts without error, for any backend, after full typechecking.

Hopefully some form of pre-processing or filtering can address issues with allowing errors in native("other") declarations, but that seems like a separate issue.

Tell me if I'm wrong, but it seems that having ceylon.ast vastly reduce its type safety and assertions, to support uses such as being used during typechecking or ceylon/ceylon#1865 before typechecking, would be a much bigger, more complicated, and more fundamental change.

lucaswerkmeister commented 8 years ago

@jvasileff opinions on fe3a0e2?

jvasileff commented 8 years ago

@lucaswerkmeister I think that looks great 👍

lucaswerkmeister commented 8 years ago

Alright, then let’s close this issue :)