Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Type[length] #52

Closed
lucaswerkmeister opened this issue Aug 3, 2014 · 14 comments
Closed

Support for Type[length] #52

lucaswerkmeister opened this issue Aug 3, 2014 · 14 comments
Assignees
Labels
Milestone

Comments

@lucaswerkmeister
Copy link
Member

We need to support ceylon/ceylon-spec#1041.

I’ll probably wait until it’s properly specified though.

@lucaswerkmeister lucaswerkmeister added this to the Initial release milestone Aug 3, 2014
@lucaswerkmeister lucaswerkmeister self-assigned this Aug 3, 2014
@lucaswerkmeister
Copy link
Member Author

This has now been declared “an unofficial hidden feature of 1.1”, so ceylon.ast support may slip to 1.2.

@lucaswerkmeister
Copy link
Member Author

Moving to 1.2; if I added it now, I would just have to update it later for consistency with the spec anyways.

@lucaswerkmeister
Copy link
Member Author

Alright, these have been added to the spec as

TupleType: "[" TypeList "]" | PrimaryType "[" DecimalLiteral "]"

How do we model them?

My best idea currently would be to turn TupleType into an abstract class with the two subclasses ListTupleType and LengthTupleType, but I don’t really like the sound of that too much.

@jvasileff
Copy link
Member

A three class solution sounds right to me.

lucaswerkmeister added a commit that referenced this issue Nov 4, 2015
in preparation for #52. Mostly done with the following two commands:

    find source -name TupleType.ceylon \
      -execdir git mv {} ListTupleType.ceylon \;
   find source -name '*.ceylon' \
     -exec grep -q TupleType {} \; \
     -exec sed -i 's/TupleType/ListTupleType/g' {} \; \
     -exec git add {} +

then manual fixup.
lucaswerkmeister added a commit that referenced this issue Nov 4, 2015
@lucaswerkmeister
Copy link
Member Author

I implemented exactly what I proposed in the above comment, since I haven’t been able to think of anything better (neither layout nor name) in the meantime. Done.

@lucaswerkmeister
Copy link
Member Author

Fuck me, I already did this half a year ago in c4329c1 without mentioning this issue. So now I have two implementations of this and need to decide which to keep.

@lucaswerkmeister
Copy link
Member Author

So we currently have two implementations of this:

  1. SequentialType has an optional length child of type IntegerLiteral
  2. TupleType is an abstract supertype of ListTupleType (previously TupleType) and LengthTupleType (PrimaryType plus IntegerLiteral).

Which one should we keep? 1 is closer to the RedHat AST, while 2 is slightly closer to the spec.

I think I lean slightly towards 2. Any other opinions?

@lucaswerkmeister
Copy link
Member Author

What’s really mysterious, by the way, is this: both implementations have tests, and all tests currently pass. I don’t understand how this is possible, since both versions should erase to the same RedHat AST – and consequently, it shouldn’t be possible to distinguish between them, and both versions should be converted back to the same version (I would expect 2 due to this). I’ll definitely have to look into this too.

@jvasileff
Copy link
Member

I'd lean towards 2, I think, since it is indeed a ceylon.language::Tuple. But of course, that's not absolute. Sequence, Sequential, and Tuple are often used interchangeably. Notably, in ceylon.ast, ceylon.language::Empty is represented by a TupleType, even though it is not a ceylon.language::Tuple.

Oh, wait, no. I change my vote. It seems SequentialType is of the form Type[whatever] and TupleType is of the form [whatever]. So String[2] would be of the SequentialType form.

@lucaswerkmeister
Copy link
Member Author

I guess that from the viewpoint that ceylon.ast is about syntax, not semantics, 1 makes more sense…

@lucaswerkmeister
Copy link
Member Author

Found out why the tests work: primaryType and type test objects are completely missing. No one is testing typeToCeylon. Probably related to #100. screams in horror

I’ll add those, check that the tests fail as they should, then remove solution 2.

lucaswerkmeister added a commit that referenced this issue Nov 5, 2015
The parse and compile functions for SimpleType, PrimaryType, MainType,
and UnionableType were missing, as well as tests for all of them plus
Type. Most likely a relic from the time before all of this
infrastructure was being auto-generated by source-gen.

Noticed in #52 and #100; fixes #100.

Note that tests currently don’t pass; this is expected since we have two
implementations of #52 right now, so the backwards conversion for one of
them must fail. This will be resolved in a separate commit which will
remove one of the implementations.
lucaswerkmeister added a commit that referenced this issue Nov 5, 2015
This reverts commit eb65713, reversing
changes made to 65b5410.

See #52; that problem had actually already been fixed in c4329c1, so
3ee7245 and 8b6c3fd added an unnecessary *second* solution to the
problem, which this commit removes again.
@lucaswerkmeister
Copy link
Member Author

Done again. Once I fixed the tests (9487f13), they indeed failed as expected, so now I know they work :) and once I removed 2 in ae4c94d, they worked again.

@lucaswerkmeister
Copy link
Member Author

Reopening again because there’s one last open question. Per spec, only decimal integer literals are allowed, not binary or hex ones:

TupleType: "[" TypeList "]" | PrimaryType "[" DecimalLiteral "]"

I enforced this in implementation 2 (here), but not in implementation 1. Should I add it to implementation 1? It depends on whether this is considered a syntax error or a different error. It looks like a syntax error in the spec, but the compiler grammar accepts any integer literal, and instead of a syntax error you get an “error: must be a positive decimal integer”, probably from LiteralVisitor.

I could live with both; probably leaning slightly towards not adding the check (but documenting that).

@lucaswerkmeister
Copy link
Member Author

Not checking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants