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

Use DeBruijn levels in SExpr0. #11987

Merged
merged 1 commit into from
Dec 9, 2021
Merged

Conversation

nickchapman-da
Copy link
Contributor

@nickchapman-da nickchapman-da commented Dec 6, 2021

Move to using DB-levels (not DB-indexes) in SExpr0.

  • ClosureConversion code to compute freeVars is much simpler.
  • adapt Compiler.scala

(During the dev for this change, I ran with both index and level numbers, and ensure behaviour is unchanged.)

This PR is waiting for the fix in: #12047

This PR is part of work to cleanup the speedy compiler: #11669

@nickchapman-da nickchapman-da added the component/daml-engine DAML-LF Engine & Interpreter label Dec 6, 2021
@nickchapman-da nickchapman-da force-pushed the nick-db-levels-for-sexpr0 branch from 76a7b7f to 46c5063 Compare December 6, 2021 14:49
@nickchapman-da nickchapman-da changed the title Use DB-levels in SExpr0. Use DeBruijn levels in SExpr0. Dec 8, 2021
@nickchapman-da nickchapman-da marked this pull request as ready for review December 8, 2021 11:35
Copy link
Collaborator

@remyhaemmerle-da remyhaemmerle-da left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@cocreature cocreature left a comment

Choose a reason for hiding this comment

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

Thanks!

…des both index and level, and performs a runtime check.

changelog_begin
changelog_end

add runtime check in freeVars: determination that a variable is-free using levels instead of indexes

remove DB-indexes and runtime check; simplify freeVars computation in closure-conversion
@nickchapman-da nickchapman-da force-pushed the nick-db-levels-for-sexpr0 branch from d051ead to 1783596 Compare December 9, 2021 11:43
Copy link
Collaborator

@remyhaemmerle-da remyhaemmerle-da left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks.

Comment on lines 97 to +107
def decrement1(x: SExpr): SExpr = SEApp(SEBuiltin(SBSubInt64), List(x, SEValue(SInt64(1))))
val decrement = SEAbs(1, decrement1(SEVar(1)))
val decrement = SEAbs(1, decrement1(mkVar(0)))

def subtract2(x: SExpr, y: SExpr): SExpr = SEApp(SEBuiltin(SBSubInt64), List(x, y))
val subtract = SEAbs(2, subtract2(SEVar(2), SEVar(1)))
val subtract = SEAbs(2, subtract2(mkVar(0), mkVar(1)))

def twice2(f: SExpr, x: SExpr): SExpr = SEApp(f, List(SEApp(f, List(x))))
val twice = SEAbs(2, twice2(SEVar(2), SEVar(1)))
val twice = SEAbs(2, twice2(mkVar(3), mkVar(4)))

def thrice2(f: SExpr, x: SExpr): SExpr = SEApp(f, List(SEApp(f, List(SEApp(f, List(x))))))
val thrice = SEAbs(2, thrice2(SEVar(2), SEVar(1)))
val thrice = SEAbs(2, thrice2(mkVar(0), mkVar(1)))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not very important, but I do not really like the use of global index in this class.
How are they calculated ? ...
I assume the level is somehow global, and those expression should be use in a very specific place.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree.
Actually, I think there is very little value in this class. I should delete it.
It's left over form my very first explorations into speedy.

Comment on lines +28 to +30
mapping.get(v) match {
case Some(loc) => loc
case None =>
throw sys.error(s"lookup($abs),in:$mapping")
case None => sys.error(s"lookup($v),in:$mapping")
Copy link
Collaborator

Choose a reason for hiding this comment

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

why not using getOrElse ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤷‍♂️

@nickchapman-da nickchapman-da merged commit fdf7431 into main Dec 9, 2021
@nickchapman-da nickchapman-da deleted the nick-db-levels-for-sexpr0 branch December 9, 2021 14:17
realvictorprm pushed a commit that referenced this pull request Dec 10, 2021
…des both index and level, and performs a runtime check. (#11987)

changelog_begin
changelog_end

add runtime check in freeVars: determination that a variable is-free using levels instead of indexes

remove DB-indexes and runtime check; simplify freeVars computation in closure-conversion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/daml-engine DAML-LF Engine & Interpreter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants