Enabling cross-library optimization and compile-time error checking - - PowerPoint PPT Presentation

enabling cross library optimization and compile time
SMART_READER_LITE
LIVE PREVIEW

Enabling cross-library optimization and compile-time error checking - - PowerPoint PPT Presentation

Enabling cross-library optimization and compile-time error checking in the presence of procedural macros Andrew W. Keep R. Kent Dybvig 1 1 Library Groups Andrew W. Keep R. Kent Dybvig 2 2 Goals Cross-library


slide-1
SLIDE 1

Enabling cross-library optimization and compile-time error checking in the presence of procedural macros

Andrew W. Keep R. Kent Dybvig

1

1

slide-2
SLIDE 2

Library Groups

Andrew W. Keep R. Kent Dybvig

2

2

slide-3
SLIDE 3

Goals

  • Cross-library optimizations
  • Type checking across library boundaries
  • Single binary for multiple libraries
  • Unchanged development process

3

3

slide-4
SLIDE 4

Library Groups

  • Explicitly combine libraries
  • Optionally add a top-level program
  • A new form: library-group

4

4

slide-5
SLIDE 5

Example

(library (tree) (export make-tree ---) (import (rnrs)) (define make-tree ---)

  • --)

5

5

slide-6
SLIDE 6

(library (tree constants) (export quote-tree t0 ---) (import (rnrs) (tree)) (define-syntax quote-tree

  • -- (make-tree ---) ---)

(define t0 (quote-tree))

  • --)

Example

6

6

slide-7
SLIDE 7

(import (rnrs) (tree) (tree constants)) (define tree->list ---) (tree->list t0) (tree-value (tree-children t2)) (tree->list (quote-tree 5 (7 9)))

Example

7

7

slide-8
SLIDE 8

(library-group (library (tree) (export make-tree ---) (import (rnrs)) (define make-tree ---)

  • --)

(library (tree constants) (export quote-tree t0 ---) (import (rnrs) (tree)) (define-syntax quote-tree

  • -- (make-tree ---) ---)

(define t0 (quote-tree))

  • --)

(import (rnrs) (tree) (tree constants)) (define tree->list ---) (tree->list t0) (tree-value (tree-children t2)) (tree->list (quote-tree 5 (7 9))))

Example

8

8

slide-9
SLIDE 9

Example

(library-group (include “tree.sls”) (include “tree/constants.sls”) (include “app.sps”))

9

9

slide-10
SLIDE 10

Library Group Syntax

library-group -> (library-group (library-group (library-group lglib* lgprog) | (library-group (library-group (library-group lglib*) lglib

  • > library | (include filename)

lgprog

  • > program | (include filename)

10

10

slide-11
SLIDE 11

Challenges

  • Achieving proper phasing
  • Handling cyclic dependencies
  • Enabling cross-library optimization/checking

11

11

slide-12
SLIDE 12

Implementation: Libraries

  • Visit code, invoke code, metadata
  • Import dependencies form a DAG
  • Invoke code body uses letrec* semantics

12

12

slide-13
SLIDE 13

(letrec* ([make-tree ---]

  • --)

(set-top-level! $make-tree make-tree)

  • --)

Example

13

13

slide-14
SLIDE 14

(letrec* ([t0 tree-constant]

  • --)

(set-top-level! $t0 t0)

  • --)

Example

14

14

slide-15
SLIDE 15

(letrec* ([tree->list ---]) (tree->list $t0) ($tree-value ($tree-children $t2)) (tree->list tree-constant))

Example

15

15

slide-16
SLIDE 16

Implementation: Library Groups

  • Combine letrec* expressions
  • Preserve existing library exports
  • Invoke libraries needed during expansion

16

16

slide-17
SLIDE 17

Library Group 1

(lambda (uid) (case uid [(tree) (letrec* ([make-tree ―]

  • --)
  • --)]

[(constants) (letrec* ([t0 ---] ---)

  • --)]

[else (letrec* ([tree->list ---]) (tree->list $t0) ($tree-value (car ($tree-children $t2))) (tree->list ---))]))

17

17

slide-18
SLIDE 18

Library Group 1

  • Advantages:
  • Single output binary
  • Matches existing library semantics
  • Disadvantages:
  • Hinders cross-library optimizations

18

18

slide-19
SLIDE 19

Library Group 2

(letrec* ([make-tree ---] ---) (set-top-level! $make-tree make-tree)

  • (letrec* ([t0 tree-constant] ---)

(set-top-level! $t0 t0)

  • (letrec* ([tree->list ---])

(tree->list $t0) ($tree-value (car ($tree-children $t2)))) (tree->list tree-constant)))

19

19

slide-20
SLIDE 20

Library Group 2

  • Advantages:
  • Creates a single invoke code
  • Allows optimizations and checking
  • Disadvantage:
  • Causes dependency problems

20

20

slide-21
SLIDE 21

Dependency Problems

(A) (B) (C)

21

21

slide-22
SLIDE 22

Dependency Problems

(A) (B) (C)

21

21

slide-23
SLIDE 23

Dependency Problems

(A) (B) (C)

21

21

slide-24
SLIDE 24

(lambda (uid) (letrec* ([make-tree ---] ---)

  • (mark-invoked! ‘tree)

(let ([nested-lib (lambda (uid) (letrec* ([t0 ---] ---)

  • (mark-invoked! ‘constants)

(let ([nested-lib program code]) (if (eq? uid ‘constants) nested-lib (nested-lib uid)))))]) (if (eq? uid ‘tree) nested-lib (nested-lib uid)))))

Library Group 3

22

22

slide-25
SLIDE 25

Library Group 3

  • Advantages:
  • Avoids synthetic cycles
  • Allows optimization and checking
  • Single output binary

23

23

slide-26
SLIDE 26

Caveat: Dynamic Dependencies

  • Arises from use of eval in init expressions
  • Library groups allow explicit ordering
  • Work arounds
  • Transform into import dependency
  • Move into initialization function

24

24

slide-27
SLIDE 27

Fixing Dynamic Dependencies

  • Start with case-based library-group
  • Lift “simple” letrec* bindings
  • Requires letrec* style optimization

25

25

slide-28
SLIDE 28

Library Phasing

  • Retain phasing between libraries in group
  • Cannot simply recompile from source
  • Relatively straightforward solution

26

26

slide-29
SLIDE 29

Summary

  • Library groups meet our goals:
  • Cross-library optimization
  • Type checking across library boundaries
  • Single output binary
  • Maintains proper phasing order
  • Avoids synthetic import dependency cycles

27

27

slide-30
SLIDE 30

Thanks

Questions?

28

28