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

Drop intrinsic lists in core #194

Merged
merged 19 commits into from
Nov 24, 2022
Merged

Drop intrinsic lists in core #194

merged 19 commits into from
Nov 24, 2022

Conversation

b-studios
Copy link
Collaborator

@b-studios b-studios commented Nov 22, 2022

Please do not merge.

Using the intrinsic list encoding on core is really annoying on the module level, since a special return value usally unit has to be made up to terminate the list. This is a technical debt that we carry around for quite some time now,

As a step forward, here we

  • introduce core.Definition
  • introduce core.Scope to locally use core.Definition
  • reenable simple optimizations on Core
  • add additional optimizations to simplify Scope(Scope...))
  • introduce core.Defintion.Mutual to separate out mutually recursive block definitions
  • refactor the toplevel module declarate to use List[Definition] instead of Stmt
  • Also refactor lifted.

Completely unrelated to this PR, 7ff2ce2 also desugars while into a recursive function to further simplify core and lifted.

def addToScope(definition: Definition, body: Stmt): Stmt = body match {
case Scope(definitions, body) => Scope(definition :: definitions, body)
case other => Scope(List(definition), other)
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We use this helper function (for now) to not introduce too many Scopes in the translation.


case Definition.Let(id, tpe, binding) =>
js.Const(nameDef(id), toJS(binding))
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The refactoring bares first fruit.

Def(id, tpe, transform(block)(using env, Context), rest)
case (core.Definition.Let(id, tpe, binding), rest) =>
Let(id, tpe, transform(binding)(using env, Context), rest)
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Here we go back to the horrible intrinsic lists, to refactor one bit at a time. :)

@b-studios
Copy link
Collaborator Author

@phischu @marzipankaiser there is probably a better way to implement the translation to Machine. For now all LLVM tests go through. Maybe you could revise it? I propose the following:

  1. we merge this PR if it looks at all ok to you
  2. we implement Mutual blocks in core and lifted (like sketched in core)
  3. we revisit the computation of free variables, both in lifted and in Machine

WDYT?

@b-studios b-studios marked this pull request as ready for review November 23, 2022 21:04
@phischu phischu merged commit 9afdfa2 into master Nov 24, 2022
@b-studios b-studios deleted the refactor/non-intrinsic-core branch November 24, 2022 17:37
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.

None yet

2 participants