Skip to content

Rework resolver #489

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

Merged
merged 27 commits into from
Feb 20, 2019
Merged

Rework resolver #489

merged 27 commits into from
Feb 20, 2019

Conversation

dcodeIO
Copy link
Member

@dcodeIO dcodeIO commented Feb 15, 2019

See: #473

The previously weird resolver logic has been replaced with less weird tree-based lookups, the internal IR changed accordingly and the AST updated to include nested type names that the resolver can now deal with.

Other notes:

  • Also adds support for export *, fixes Support export * #249
  • The --noTreeShaking compiler flag has been removed and replaced with an explicit lazy compilation mechanism. Reason is that top-level control flow requires that namespace and static class members are compiled directly if these access mutable top-level variables. Otherwise, their values are wrong when compiled after top-level control flow has concluded.
    var a = 1;
    class A {
      static readonly b = a; // should be 1, but is 2 when compiled lazily
    }
    a = 2;
    There are ways to detect this condition, of course, but the standard library especially requires an explicit mechanism so we can keep user binaries as bloat-free as possible anyway, so @lazy was born. Downside is that compilation of a user program is now more like JS, upside is that compilation is now more like JS. Means: functions are compiled when used only, but globals are compiled sequentially with other top-level logic unless @lazy.
  • Instead of automagically picking up an exported main function by name, and make it call start to execute top-level logic when it's first called, this mechanism has been replaced with a @start decorator. Any function can become the function that kicks off the module now and a user who uses @export function main for other reasons won't be surprised anymore. fixes [bug] Split doesn't work with main function #476
  • The AST has been slimmed down by removing reverse-linking between individual nodes entirely, which is now exclusively represented by IR. Might make it a little harder to work with, but makes sense for a compiler in order to reduce overall memory footprint significantly respectively to make the AST easily serializable at some point.

@dcodeIO
Copy link
Member Author

dcodeIO commented Feb 17, 2019

Most of the bare features that were necessary are in now. However, this obviously escalated to a point where half the compiler has been rewritten and shit will definitely hit the fan when merged. Going to take some additional time to go through the code step by step next, before regenerating tests and double checking them.

@dcodeIO
Copy link
Member Author

dcodeIO commented Feb 19, 2019

Alright, this passes the test suite now. That is, locally and node stable, but not LTS on Travis and only in the push build apparently, which totally makes sense (again). Also, the test suite is terrible. It covers quite some stuff and that's good, better than nothing, but it's unstructured and as such hard to work with and extend. Should either be fewer files with each covering one aspect (it's currently rather randomly distributed) or more folders for specific things, like syntax-level, feature-level, std-level etc.

@dcodeIO
Copy link
Member Author

dcodeIO commented Feb 19, 2019

Ok, next up: Nested types for #423

@dcodeIO dcodeIO changed the title [WIP] Rework resolver Rework resolver Feb 19, 2019
Turns out that we can completely eliminate linking between AST nodes now, leading the path to making it easily serializable at some point and less memory consuming in general
this PR is breaking in many different ways, so it's a sensible thing to up the version
@torch2424
Copy link
Contributor

WOAH! Export * is now supported!!! 🎉 🎉 🎉 😄 😄 😄

Made my day, thank you @dcodeIO 👍

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.

[bug] Split doesn't work with main function
2 participants