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

Optimize core language by inlining expressions #53

Closed
julianhyde opened this issue Jun 24, 2021 · 1 comment
Closed

Optimize core language by inlining expressions #53

julianhyde opened this issue Jun 24, 2021 · 1 comment

Comments

@julianhyde
Copy link
Collaborator

Optimize core language by inlining expressions.

The paper Secrets of the Glasgow Haskell Compiler inliner (Peyton Jones and Marlow, 1999, revised 2002) describes the approach.

Given the query

let
  val emp = scott.emps
in
  from e in emp
    yield e.deptno
end

we need the compiler (in particular the Calcite compiler) to know that emp is always equivalent to scott.emps and therefore can be translated to a Calcite TableScan. Without inlining, to be safe, we would have to generate a Calcite plan involving a TableFunctionScan (i.e. indirecting at runtime rather than compile time) and that seriously limits query optimization opportunities on the Calcite side.

Inlining also has some other nice effects, such as

  • let val f = fn x => x + 1 in f 3 end3 + 1
  • let val x = 3 in isOdd 3 endisOdd 3
  • (fn x => x + 1) 5let x = 5 in x + 1 end (beta reduction)
  • let x = 1 and y = 2 in y + 3let y = 2 in y + 3 (remove dead declarations)

Inlining is implemented in class Inliner, which is a shuttle that makes multiple passes over the expression tree. It also converts references to built-in functions (say String.length or #length String) into function literals which can be more easily matched by subsequent optimization rules.

The paper has guidelines for when inlining can be done safely (without causing code size or runtime to increase). We implement those guidelines in class Analyzer.

@julianhyde
Copy link
Collaborator Author

Fixed in julianhyde@ab22295.

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

No branches or pull requests

1 participant