Skip to content

Unified Workspaces#117

Open
iwillspeak wants to merge 6 commits into
mainfrom
feature/workspaces
Open

Unified Workspaces#117
iwillspeak wants to merge 6 commits into
mainfrom
feature/workspaces

Conversation

@iwillspeak

Copy link
Copy Markdown
Owner

A unifying solution to #101 and #111.

The rough sketch / plan here is to switch to a more incremental appraoch to compilation. A workspace
module will be introduced which manages source code in both the raw and parsed state. On top of this a compilation layer manages binding and symbols.

In addition we need to intorduce a true first class Symbol type. A Symbol will represent an item which
can be bound or defined. We can then use these to refer to definitions and references to differen item
types (variables, macros, libraries, etc.). Symbols proivde the layer of abstraction to allow the bound tree
to build up semantic inforamation about a given item before we pin down its location (e.g. local, global. etc).

We can build on them later with attributes to facilitate things like "suggested names" for potential "phi" symbols
such as those referring to a lambda definition, or type information from inference.

WE only lower symbols to actual local / environment / argument slots or indicies in the later Lower pass
once semantic analysis has been completed.

This should then open us up to some more adanced refactorings such as inlining, escape analysis, and closure
lifting.

@iwillspeak iwillspeak self-assigned this Apr 22, 2026
@iwillspeak iwillspeak added feature New feature or request Roadmap Larger scale planned feature or tracking issue labels Apr 22, 2026
Initial design work for unifying a solution to #101 and #111.
Firethorn 1.0 changes TextLength from int to uint32. Centralise the
int/uint32 boundary in Text.fs by adding TextDocument.advance, which
converts an int character count to Firethorn.TextLength.

Remove all #if USE_NEW_FIRETHORN conditional code paths now that the
upgrade is complete.

Benchmark results on the Scheme parser hot path (chibi-r7rs-tests.scm,
BenchmarkDotNet v0.15.8, Linux, Intel i7-10750H, .NET 10.0.7):

  Firethorn 0.4.1: 16.08 ms, 15.9 MB allocated
  Firethorn 1.0.0: 13.33 ms, 14.14 MB allocated
  Ratio: 0.89x time, 0.89x memory (~11% less memory, ~17% faster)
Not all CST nodes _are_ for a specific document. Fabricated syntax may
not have a document at all. Documents will be fused to the CST in the
Stx pass. The parser should return a root with the document and CST.
A CST Item's TextDocument is now held in the SyntaxRoot that the parser
returns. This can either be discarded or retained by the caller.

Later phases like the binder expect a SyntaxRoot<Program> or similar
rather than just a Program so the document must be preserved.

This brings all the tests back to passing.

Still TODO:

 * Stop resolving the source locations when the Stx tree is created.
Replace the 96 bytes (+ padding) of TextLocation with a single compact
16 byte struct. This should reduce memory use on syntax trees and avoids
us having to do the range -> location resolution in the Stx.ofExpr call.
saving us a reasonably expensive search on each node we project.
@iwillspeak iwillspeak force-pushed the feature/workspaces branch from c97446e to f458ed2 Compare May 1, 2026 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request Roadmap Larger scale planned feature or tracking issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant