Skip to content

SSA lowering and interpreter#167

Open
tothambrus11 wants to merge 2 commits into
enlightware:mainfrom
kyouko-taiga:ssa-emitter
Open

SSA lowering and interpreter#167
tothambrus11 wants to merge 2 commits into
enlightware:mainfrom
kyouko-taiga:ssa-emitter

Conversation

@tothambrus11

@tothambrus11 tothambrus11 commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

This PR adds a single static assignment IR to the Ferlium compiler, along with an interpreter built on top of the HIR interpreter's evaluation context for easy standard library interoperability.

All existing language test suites pass with both interpreters.

Current known limitations:

  • The max call stack depth and fuel protections are not implemented yet.
  • Some aspects of the language still assume some sort of dynamic tracking, e.g. to conditionally execute drops (all ferlium values should be lowered as optionals)

@stephanemagnenat

Copy link
Copy Markdown
Member

Does it supersedes #125?

@stephanemagnenat

Copy link
Copy Markdown
Member

@tothambrus11 do you plan to clean the history?

@stephanemagnenat

Copy link
Copy Markdown
Member

@tothambrus11 tell me when you wish me to review.

One question is that in main, there is Callable in HIR, but I am not sure it should live there, as it is very much related to the HIR tree walker interpreter. What do you think?

@stephanemagnenat

Copy link
Copy Markdown
Member

Another question I have is whether we really need SSA-specific value (especially for things like boxed integer) or we can just use a normal Ferlium value. This feels like a duplication smell to me, but maybe there is a good reason.

@tothambrus11 tothambrus11 mentioned this pull request Jun 30, 2026
Comment thread CONVENTIONS.md Outdated

## Documentation

Documentation enables local reasoning - it's a shortcut for understanding so readers can avoid looking up implementation

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be removed...
It's adapted from the Hylo style guide.

@stephanemagnenat stephanemagnenat Jun 30, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, let's discuss this convention file when the PR is ready to be merged!

@stephanemagnenat

Copy link
Copy Markdown
Member

@tothambrus11 fyi I am still working on proper first-class subscripts and using subscripts for field projections and allowing custom field projections for user-defined newtypes/typedefs.

That will add a few new first-class-subscript-related HIR node types, very similar to their function equivalent.

I hope this work to be done by latest tomorrow. Is that ok I ping you here when it is done?

@tothambrus11

Copy link
Copy Markdown
Contributor Author

Yeah sure! I run out of official hours, but I'm happy to contribute to the project in my own OSS time.

@stephanemagnenat

stephanemagnenat commented Jul 3, 2026

Copy link
Copy Markdown
Member

@tothambrus11 I pushed the subscript-based projection work to origin/main. The only missing part so far is similar support of type inference for subscripts as for normal functions. That should only affect type inference and not HIR representation, so unexpected design-issues aside, that next step should not affect the SSA work.

@tothambrus11

Copy link
Copy Markdown
Contributor Author

Thanks, I'll try rebasing.

@stephanemagnenat

Copy link
Copy Markdown
Member

The type inference work for subscripts is in main, it indeed did not affect HIR shape.

@stephanemagnenat

stephanemagnenat commented Jul 4, 2026

Copy link
Copy Markdown
Member

@tothambrus11 fyi in 1216d8f I renamed the HIR node Apply to FunctionApply for the sake of clarity of symmetry with SubscriptApply. StaticApply keeps having a generic name because it can statically apply any callable once the details are known.

Also, now subscript bundled functions have proper names for debugging purposes.

@tothambrus11 tothambrus11 marked this pull request as ready for review July 7, 2026 23:19
@tothambrus11

Copy link
Copy Markdown
Contributor Author

@stephanemagnenat The PR should be ready, it's already migrated to the new subscript representation.

@stephanemagnenat

stephanemagnenat commented Jul 10, 2026

Copy link
Copy Markdown
Member

@tothambrus11 very good, thank you very much.

I reviewed it. Overall looks great!

Some questions/comments:

  1. There are many commits containing the long history of this PR, I would consider squashing them into one (retaining the authors), would that be ok for you?
  2. File .vscode/launch.json has a single, SSA-specific job. Is it in this PR on purpose? I am not against it, just it feels very SSA orientated, so maybe we should rename it if we want to keep it.
  3. The SSA-defined Value in src/ssa/value.rs still has things like manually-defined Float. While discussing with @kyouko-taiga it seems that this was an initial import. It is my understanding that most branches are not used. Is that correct? I could also do the clean-up on my side as long as I have a clear understanding of the design goal regarding that one (Generalize SSA constants and literal materialization #172).
  4. The change to the String for SSA surfaced an underlying design issue that we could get away with it. I have been thinking of a clean solution and wrote an issue about that (Make HIR immediates trivially copyable and materialize owned literals explicitly #174).

This review highlighted some design issues in Ferlium HIR and I laid out a series of changes to fix them: #173 -> #174 -> #172

@stephanemagnenat

Copy link
Copy Markdown
Member

@tothambrus11 fyi your latest push failed due to a lint error.

@stephanemagnenat

Copy link
Copy Markdown
Member

I am now working on the merging.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants