Rosetta: Replacing Representers and Analyzers with a central system

Introduction

Hi maintainers (and interested watchers),

For the last few weeks I’ve been experimenting with the idea of having a centralised system for generating representations, analysing code, and creating snippets, rather than having individual tools. I’ve now got to the stage where I’m certain this is the route forward we’ll take.

It is not yet ready for review, but as there’s been lots of talk about adding/improving analyzers/representers, and Bethany’s work in updating the Python track to the latest version involves involves regenerating millions of representations, I wanted to flag it now so people don’t invest tons of work into systems we will replace, but can also get excited about this world becoming much easier to get into.

Rosetta

My motivations for doing this are three-fold:

  1. Making it more accessible to contributors, so we can improve the breadth of tracks that have analyzers and representers.
  2. Making this whole system much faster so we can do more with it.
  3. Making the whole system lots cheaper, so we can regenerate things as and when we need to.

I’ve now got to the point where I’ve got a single repository that does everything all the existing tooling does, using tree-sitter grammars. It effectively turns every language into the same system that we can work with consistently. The project is called Rosetta.

Rosetta is about 3000x faster than any of the existing tools as it doesn’t need to compile code using real compilers. It can generate a representation, analyze the solution, and create a snippet sequentially in about 2ms, whereas this currently takes about 4-8s for existing tracks. (To put that into a wider perspective, that means generating the millions of Python representations will take half an hour, rather than 23 days).

I’ve created a DSL that makes it very easy to add things and is very readable. I’ve also left the ability to write manual code in case you want to go beyond the DSL too, but my aims is that 99% of the time, we can use the DSL to achieve what we want.

I’ve ported all the representer normalisations and all¹ the analyzer rules across all languages that have them.

Some comparisons using Elixir, as it’s one of the best and most complete tracks for all tools:

This same DSL will work across all languages.

There’s a dedicated transition folder that goes into detail on any changes in languages (for languages with existing tooling, there’s quite a few bugfixes, and for those without it explains the decisions made by the new representers). I’m still manually working through these to check any regressions etc.

Plan for launching it

Again, this is not yet ready for review. I’m still working through everything, improving and expanding. the DSL, etc.

My aim is to launch this some time in the next 6 weeks. To start with, I intend to just sub out the existing systems for this, then regenerate representations for all solutions.

But then there’s so much more we can do. We can generate analysis and representations effectively instantly - whenever students run tests or quickly before they submit, which gives us tons of new potential opportunities.

And it’s really easy to add analysis now. If you want to say “Make sure the student doesn’t use this library”, you can do in one line. If you want to look for different patterns that’s students use, and block on bad ones, you can write some more complex rules (e.g. Ruby TwoFer). LLMs understand this very easily. You can give an LLM a solution to an exercise and say “If the student does XYZ, leave this comment” and it will write those rules very easily. And we have tons of golden tests in the repository which give me a lot of confidence about how it works.

Reflections

In line with the letter I sent to maintainers this week, this is a good example of something that has been very humbling. I spent a lot of time exploring tree-sitter when we were originally considering analyzers/representers years ago, and there have been several well-funded, failed, projects to unify ASTs into one system. It all seemed pretty impossible. And now Claude has created dozens of tree-sitter grammars and a whole system to use them in a couple of days².

I will be sad to see the existing code retired, as I and many of you put a huge amount of effort into that, but all of that product-thinking and the ideas and rules we created are still in Rosetta. Over the last year, there’s only been a handful of meaningful improvements to the analyzers/representers so I see those projects as having stalled, largely due to the complexity of them and the lack of time of our their original creators. I hope now there’s a central system we can get a lot more momentum in adding more rules across tracks, from a more time-rich group in the community.

The one thing I’ve not decided on yet is linting. Some tracks have analyzers that are either partially or entirely linters. I don’t think moving those bits into Rosetta will work, so I need to decide whether to keep those in the current state or do something else with them. I think linting is different to educational feedback anyway, so I think having the more formal split is good, and we should treat linting output differently in the product journey.

I will let you know when things are ready to dig into (although feel free to explore if you’re curious!), and I’m happy to answer any questions you have! :slight_smile:


¹ all but one or two that I’m not sure we care about. We can bring them over - it’s just a lot of code for little gain.
² This has also been a good example of Claude being able to do stuff, but it being quite horrible code, and lots of stupid ideas. I’ve had to take it through a lot of iterations to get to a point where I’m comfortable enough to believe in this, and there are more to come pre-launch.

4 Likes

This sounds very exciting. I’ll readily admit, writing the C# analyzer and representer was a lot of fun. But, it also is quite time-consuming, which is why only a handful of exercises on the C# track have specific analyzer rules. If the barrier to add new analyzer rules becomes drastically lower, then I can imagine a lot of concept exercises getting analyzer rules defined for them, which is great.

2 Likes

This one is a bummer for me. One of the behaviors of the Elixir analyzer that I really liked was getting compiler warnings, and that’s now gone :disappointed: . They’re a big part of “linting” your Elixir code when you work locally.

2 Likes

Compiler warnings won’t go! We can get them from the test-runner itself by extending the spec there which means we can show them in the editor on every test run if we want, rather than something that you only see after you submit your code. So I think this will better.

From Elixir’s transition file.

  • elixir.solution.compiler_warnings passed on the compiler’s warnings. Rosetta doesn’t run the Elixir compiler. For example, a lasagna alarm that sets x = 1 and never reads it used to get this comment, and now gets none. We’ll take these from the test-runner instead.

(Sidenote: as I mentioned, this isn’t really ready for review yet. My aim is to remove all regressions unless they really add very little value before we get this live, and open discussions/issues on any changes we need to main to keep things in other places!)

1 Like

You should just zero out the Python transition stuff. The Two-Fer stuff was done as a POC, and the vast majority of the rest was me setting up PyLint but failing to produce new rules that were exercise focused. I think half of the Two-Fer stuff doesn’t even trigger.

There is a linting discussion to have later – but the real reason I used PyLint was for the infrastructure it set up for custom ast-based rules that could be more reliable than hand-rolling analysis via text (wow do those Two-Fer rules make me crazy).

But I will refrain from too much critique. :wink: I will want some of PyLints rules back … but that can be later as things solidify.

Fascinated to see how the whole tree-sitter grammars and other stuff interacts.

1 Like

I’m curious to see how this unified grammar monster behaves when languages evolve…looking forward to seeing how we (or mentors) are expected to add analyser feedback (the workflow integration with tracks or the website).

1 Like