Created
July 5, 2020 22:13
-
-
Save jackfirth/7f29e2e79d37a37e9a3c7059da5da594 to your computer and use it in GitHub Desktop.
Hypothetical sketch of a system for adding rewrite rules to APIs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; This is a hypothetical syntax for defining rewrite rules that can be used to create custom optimizations and | |
| ;; refactoring suggestions. This example assumes there's some sort of geometry library that accepts angles in terms of | |
| ;; either degrees or radians using wrapper structs like `(struct degrees (value))` and `(struct radians (value))`. If | |
| ;; the wrapping is done right where the function is called, it allocates garbage that specialized degree-specific and | |
| ;; radian-specific functions wouldn't allocate. But we don't want to double the API surface, so we instead create inlining | |
| ;; rules that fire when the wrapping is done at the call site. | |
| (define-rewrite-rule rotate-degrees-specialization | |
| @explanation{Using the @racket[rotate-degrees] function avoids allocating the intermediate @racket[degrees] value.} | |
| #:surface-as hidden-optimization | |
| #:from (rotate (degrees 270)) | |
| #:to (rotate-degrees 270)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment