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

Refactor/replace environments by substitution #787

Merged
merged 16 commits into from
Jan 22, 2025

Conversation

b-studios
Copy link
Collaborator

No description provided.

Instead of

        const start_7 = (start_6 - (1));
        const acc_10 = new Cons_0(tmp_32, acc_9);
        start_6 = start_7;
        acc_9 = acc_10;
        continue toList_worker_3;

we now genereate

        const tmp_start_0 = start_0;
        const tmp_acc_0 = acc_0;
        start_0 = (tmp_start_0 - (1));
        acc_0 = new Cons_0(tmp_2, tmp_acc_0);
        continue toList_worker_0;

when translating tail calls.

case cps.Stmt.Resume(r, b, ks2, k2) =>
pure(js.Return(js.Call(RESUME, nameRef(r), toJS(b)(using nonrecursive(b)), toJS(ks2), toJS(k2))))
pure(js.Return(js.Call(RESUME, nameRef(r), toJS(b)(using nonrecursive(b)), toJS(ks2), requiringThunk { toJS(k2) })))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This might slow down some benchmarks, but is necessary in the general case to avoid SOs

val a = Id("a")
val ks = Id("ks")
cps.Cont.ContLam(a, ks, cps.Hole())
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This needs to be replaced by a specialized error continuation

@@ -21,6 +21,8 @@ object Optimizer extends Phase[CoreTransformed, CoreTransformed] {

def optimize(source: Source, mainSymbol: symbols.Symbol, core: ModuleDecl)(using Context): ModuleDecl =

val isLLVM = Context.config.backend().name == "llvm"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is REALLY hacky. Another solution would be to first optimize and then do polymorphism boxing. However, this alternative currently (I didn't try to find out why) fails a lot of test.

@b-studios b-studios marked this pull request as ready for review January 22, 2025 15:30
patternMatches = 0,
branches = 5,
pushedFrames = 531467,
poppedFrames = 531467,
allocations = 0,
closures = 265750,
closures = 26,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This change is particularly significant...

case (tpe1, TTop) => true
case (TBottom, tpe1) => true
case _ => false // conservative :)
// sys error s"Cannot compare ${tpe1} ${tpe2} in ${covariant}" // conservative :)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If you ever want to fix more bugs, comment this in again.

@b-studios b-studios merged commit 63435f9 into master Jan 22, 2025
2 checks passed
@b-studios b-studios deleted the refactor/replace-environments-by-substitution branch January 22, 2025 16:14
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.

1 participant