Skip to content

Replace cleavir-environment with Trucler#24

Draft
paulapatience wants to merge 3 commits intos-expressionists:mainfrom
paulapatience:introduce-trucler
Draft

Replace cleavir-environment with Trucler#24
paulapatience wants to merge 3 commits intos-expressionists:mainfrom
paulapatience:introduce-trucler

Conversation

@paulapatience
Copy link
Member

@paulapatience paulapatience commented Mar 18, 2023

The first commit (renaming system to client, etc.) should be done. I would like to check through it once more to make sure I didn't miss anything or introduce bugs. I renamed even instances in cleavir-environment to simplify things, i.e., all systems were renamed.

The second commit (replacing environments with clients in cleavir-compilation-policy) should also be done.

The third commit is the crux of the PR. Everything compiles, but running the BIR visualizer results in some issues I still need to fix. Also, there are several FIXME(paul) notes that I have to address.

;; FIXME: We probably want to create and use
;; env:constantp in case the environments don't match
;; up.
;; FIXME(paul) What is env:constantp?
Copy link
Member

Choose a reason for hiding this comment

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

env:constantp would be a cleavir-env function that's like cl:constantp, only a customizable generic. This is out of scope for Trucler since it could be quite sophisticated in general, e.g. detecting that (let () 4) is a constant. But a minimal implementation would do cl:constantp's minimum, i.e. it can detect self-evaluating objects, quoted forms, and constant variables (which would be found via Trucler). Given that you've deleted cleavir-env, this function would be in cst-to-ast instead.


;; FIXME(paul) Does cst-eval here need two environments or only one?
;; In the trucler branch of cleavir, it had one only (but two in the
;; cleavir-environment package).
Copy link
Member

Choose a reason for hiding this comment

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

I believe that eval and cst-eval took one environment as the actual environment argument, and one that was just for specialization. This second predates the use of clients, but now that we are using clients we should do that here too. So, probably cst-eval should take a form, an environment, and a client as arguments (in some order, i guess the convention is client first?)

(type-expand (next env) type-specifier))
;; FIXME(paul) I don't think this expands repeatedly.
;; Then again, what the other one used to do is call TYPE-EXPAND until
;; the environment is NIL.
Copy link
Member

Choose a reason for hiding this comment

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

Having a default method call the generic function again is a bit dangerous if the client forgets to specialize it. It might be better to have an ordinary type-expand function that calls the generic with the trucler:global-environment to avoid this.

;;;
;;; Generic function POLICY.
;;;
;;; FIXME(paul) Add doc?
Copy link
Member

Choose a reason for hiding this comment

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

The documentation should include pretty extensive information here, including probably an example of including policy information in an environment so that it does not have to be repeatedly computed. I suspect that the default recomputation will be pretty bad for performance.

compute policies from optimize declarations, but you should
avoid doing this on every `OPTIMIZE-INFO` call.
<!-- FIXME(paul): Does it really have to respect the protocol?
In what way is it used here? -->
Copy link
Member

Choose a reason for hiding this comment

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

this comment makes less sense in a trucler context, i think. it might be enough to say that we use trucler to get optimize info, so if the client wants policies to make sense, they need to implement trucler properly. describe-optimize no longer has to return policy info (though it probably should to avoid recomputation)

Maybe something like...

Make sure your client respects the OPTIMIZE-DESCRIPTION protocol in Trucler. Cleavir expects additional policy information. By default it will compute a policy anew each time it is needed, but it is recommended that clients cache policy information alongside optimize information to avoid this. CLEAVIR-CST-TO-AST:POLICY should be specialized to retrieve from this cache rather than do computation.

@paulapatience paulapatience force-pushed the introduce-trucler branch 5 times, most recently from 7cfef44 to 2812070 Compare April 9, 2023 13:17
TODO: Review once for possible errors
Removed the dependency on cleavir-environment (in preparation for
migrating to Trucler), which involved replacing uses of environments
with clients, and moving cleavir-environment:optimize-qualities to here.

While here, expanded some tabs to spaces.
Migrating the features of cleavir-environment missing from Trucler to
CST-to-AST.
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.

2 participants