Better HN
topnewbestaskshowjobs
Log inSign up

herrington_d

128 karma · joined Sep 6, 2022 (4y ago) · 80 submissions

Submissions

1.

How AST-grep Rewrote Tree-sitter in Rust and Made It 30% Faster(astgrep.com ↗)

93 points · by herrington_d · 4mo ago · 15 comments

comment 8mo ago · link · parent

Isn't the case study.... too contrived and trivial? The largest code change is 800 lines so it can readily fit in a model's context.

However, there is no case for more complicated, multi-file changes or architecture stuff.

comment 9mo ago · link · parent

I also have a tree-sitter Rust rewrite. Though I cannot find it more useful for end users... https://github.com/HerringtonDarkholme/tree-sitter

comment 1y ago · link · parent

it does not always work in my experience due to complex type definitions. Also extra tool calls and time are needed to fix linting.

comment 1y ago · link · parent

There are researches backing some sort of "typed language is better for LLM". Like https://arxiv.org/abs/2504.09246, Type-Constrained Code Generation with Language Models, where LLM's output is constrainted by type checkers.

Also https://arxiv.org/abs/2406.03283, Enhancing Repository-Level Code Generation with Integrated Contextual Information, uses staic analyzers to produce prompts with more context info.

Yet, the argument does directly translate to the conclusion that typed language is rigorously better for LLM without external tools. However, typed language and its static analysis information do seem to help LLM.

comment 1y ago · link · parent

The logic above can support exactly the opposite conclusion: LLM can do dynamic typed language better since it does not need to solve type errors and save several context tokens.

Practically, it was reported that LLM-backed coding agents just worked around type errors by using `any` in a gradually typed language like TypeScript. I also personally observed such usage multiple times.

I also tried using LLM agents with stronger languages like Rust. When complex type errors occured, the agents struggled to fix them and eventually just used `todo!()`

The experience above can be caused by insufficient training data. But it illustrates the importance of eval instead of ideological speculation.

comment 1y ago · link · parent

Hi, ast-grep author here. thanks for sharing the video!

production quality is amazing! I also did some youtube video recently. It is not easy and end product is far from polished.

Really appreciate your help introducing the tool to more people, thanks!

comment 1y ago · link · parent

One thing AE provides but not coroutines is type safety. More concretely AE can specify what a function can do and cannot do lexically in code. A generator/coroutine cannot.

For example, a function annotated with say `query_db(): User can Datebase` means the function can call database and the caller must provide a `Database` handler to call the `query_db`.

The constraint of what can do and not is pretty popular in other programming fields, most notably, NextJS. A server component CANNOT use client feature and a client component CANNOt access server db.

comment 1y ago · link · parent

the blog lacks the review of one critical player effect.ts https://effect.website/docs/error-management/two-error-types...

comment 1y ago · link · parent

Calling other languages like "none of the tooling" in the "why" section sounds like a huge self-roasting since CCL does not have, say, highlighting/LSP/FFI for adoption.

comment 1y ago · link · parent

My point is that type error recovery is the property of the type system. Not the property of structural code editor.

comment 1y ago · link · parent

> Better type information. Because the program is always in a valid state the type checker can always run and give meaningful feedback.

Note that programs can be syntactically well-formed but ill-typed. For example `let x = true + 1` has valid syntax but produces an "undefined" type for the variable `x`, if the type system does not support type error recovery.

A quote from the great paper from POPL 2024, https://hazel.org/papers/marking-popl24.pdf

> If a type error appears _anywhere_, the program is formally meaningless _everywhere_

comment 1y ago · link · parent

This is a pretty fair comment. I wonder how structural editing figures out things like formatting/searching/diffing and copy/paste across different editors.

comment 1y ago · link · parent

Since Skip is maintaining a reactive cache. How is the cached stored? I would speculate it would a distributed in-memory database so the computation service can scale. But I wonder how the system can recover and rebuild the cache if the cache is down.

comment 1y ago · link · parent

The feature dates way back to perhaps 2006, per Jetbrains' PDF archive[1]. Jb also updated their structural search UI/UX in 2018[2]. It is possible that users do not buy in the idea of SSR. Alternatively, it may be caused by the fact that Jb SSR's mixed language support. [3][4][5]

[1] https://www.jetbrains.com/idea/docs/ssr.pdf [2] https://www.youtube.com/watch?v=YeGPO-UHTbs [3] https://www.jetbrains.com/help/idea/structural-search-and-re... [4] https://www.jetbrains.com/help/go/structural-search-and-repl... [5] https://www.jetbrains.com/help/pycharm/structural-search-and...

comment 1y ago · link · parent

Curiously the claim sounds like learning this programming language is equivalent to reading the whole DDIA book. :P

comment 2y ago · link · parent

Cool! is it possible to support structural search like ast-grep[1]? ast-grep has some interactive mode but it is nothing near Scooter.

1: https://ast-grep.github.io/

comment 2y ago · link · parent

Yes, ast-grep already has its own rule syntax [1]. But still parser performance and binary size are critical factors for a general tool.

https://ast-grep.github.io/guide/rule-config.html

comment 2y ago · link · parent

Hi! ast-grep[1] author here. It is a tree-sitter based syntax tool to search tool.

I wonder how you transition from tree-sitter to other builtin parsers? Tree-sitter gave a unified interface to all languages. Using language native parsers will require significant work for various FFI if I am not wrong.

[1]: https://ast-grep.github.io/

comment 2y ago · link · parent

Thank you for sharing this! While AI excels at providing general advice, it often falls short on delivering contextual insights specific to your code. I’m thrilled to see that ast-grep can be effectively used alongside AI to add more value for developers. Great job!

comment 2y ago · link · parent

This can also be achieved via ast-grep by the command `sg -p 'database' -r 'db'`.

https://ast-grep.github.io/guide/rewrite-code.html

comment 2y ago · link · parent

New guide for ast-grep rewriters! A powerful construct to perform complex code transformation!

comment 2y ago · link · parent

A comprehensive guide explains why using code to search code can be more subtle than it looks.
123