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

Make the compiler use a Packed AST (PAST) internally #1

Open
Araq opened this issue Apr 30, 2020 · 4 comments
Open

Make the compiler use a Packed AST (PAST) internally #1

Araq opened this issue Apr 30, 2020 · 4 comments

Comments

@Araq
Copy link
Member

Araq commented Apr 30, 2020

See the code in compiler/past.nim and compiler/bitabs.nim for a rather precise outline of the structure. The plan is to use NimTree throughout the compiler which is a linearized representation of the AST that only supports in-place mutation in strategic places. In order to support Nim's VM / macro system there will be two operations:

proc fromTree(t: NimTree): PNode
proc toTree(n: PNode): NimTree

Instead of mutating an AST, you create a fresh one. The number of allocations is very low because a full tree is essentially stored as a single string/blob in memory.

@disruptek
Copy link

Are these files in a branch somewhere?

@disruptek
Copy link

Oh, I'm an idiot. 😆

@timotheecour
Copy link
Member

I like #6 a lot because it goes in the right direction, has clear benefits and the complexity is worth the cost; but I don't think that's the case here.

IMO this is a case of premature optimization that not only will add a lot of complexity + bugs (eg code that needs mutation) but, in the end, may end up being slower (when you're forced to copy a subtree instead of mutating an inner node). Analogy with packedjson falls short (lots of mutations/transformations happen during compilation) and I can think of other ways to optimize performance that are less disruptive.

In any case, it'd need some POC with profiling.

@Araq
Copy link
Member Author

Araq commented May 11, 2020

I can think of other ways to optimize performance that are less disruptive.
In any case, it'd need some POC with profiling.

Maybe, but the idea is also to have a cleaner API so that we can change the representation easily. Then the representation can be picked that gives us the most performance. The Packed AST design enforces an API that supports packed ASTs, usually abstract APIs not written with this structure in mind don't support it at all.

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

No branches or pull requests

3 participants