Code Monkey home page Code Monkey logo

Comments (6)

appleby avatar appleby commented on June 4, 2024

I think maybe the side-effecty stuff at the top of compile-toplevel-define-type-form that appears to be registering the tycon and it's constructors needs to be pushed down into the macro expansion, possibly within an eval-when?

Proof-of-concept PR coming soon (hopefully)...

from deprecated-coalton-prototype.

appleby avatar appleby commented on June 4, 2024

Thinking about this a bit more, perhaps things are not so simple as I had hoped (they never are!).

There seem to be at least three competing concerns here:

  1. Definitions inside a single coalton-toplevel form need to be visible to each other at macro-expansion time.
  2. Definitions should also be visible at :load-toplevel time, so that loading a precompiled FASL does the right thing.
  3. Definitions should be re-definable, ideally without gratuitous warnings in the common case of compiling, then loading a file.

The corollary to (3) is that the definitions should only be registered in the global environment once, probably inside the macro form and possibly wrapped in an (eval-when (:compile-toplevel :load-toplevel :execute) ...). (I suspect the :compile-toplevel is not needed which means the eval-when is not needed, but, as usual, staring at the hyperspec section for Processing Toplevel Forms has left me less than certain...).

But pushing the tycon and ctor registrations down into the macro form means that the macro expander needs some other provision to know about in-process definitions. The current implementation already tracks an extra-tycons parameter for this purpose, and parse-type-expression is smart enough to lookup stuff in extra-tycons before trying the "global environment." Perhaps similar provisions could be made for ctors and the like. So far I have been ignoring other toplevel definition forms like define and declare, which may need similar treatment (haven't looked yet).

Maybe instead of just extra-tycons any of the process-toplevel-* functions (and whatever functions they call) could get passed some kind of environment object that tracks all type/ctor/value definitions, similar to the &environment defmacro parameter.

tl;dr - Not quite as simple as I had hoped. I should probably read and understand the coalton source (and maybe the MACROEXPAND-ALL chapter of this Dick Waters paper) before proceeding further :). I have other stuff I want to work on first, but will circle back to this eventually (famous last words).

from deprecated-coalton-prototype.

stylewarning avatar stylewarning commented on June 4, 2024

This is a good thing to pick up on. I've felt uneasy about the compile-time side effects Coalton does. There needs to be a better way to manage it all.

from deprecated-coalton-prototype.

stylewarning avatar stylewarning commented on June 4, 2024

Probably what needs to happen is side effects need to happen at macroexpansion time, but they also need to be put in the macroexpansion as well so the FASL loader catches them.

It seems to be "working" when I do that, e.g.

diff --git a/src/toplevel-define-type.lisp b/src/toplevel-define-type.lisp
index b016280..9e56c55 100644
--- a/src/toplevel-define-type.lisp
+++ b/src/toplevel-define-type.lisp
@@ -101,6 +101,14 @@ where
     ;; TODO: Structs? Vectors? Classes? This should be thought
     ;; about. Let's start with classes.
     `(progn
+       ;; Make sure database side effects are maintained.
+       (eval-when (:compile-toplevel :load-toplevel :execute)
+         (setf (find-tycon ',tycon-name) ,tycon)
+         ,@(loop :for (_ name ty) :in ctors
+                 :collect `(unless (var-knownp ',name)
+                             (forward-declare-variable ',name))
+                 :collect `(setf (var-declared-type ',name) ,ty)))
+
        ;; Define types. Create the superclass.
        ;;
        ;; TODO: handle special case of 1 ctor.

from deprecated-coalton-prototype.

stylewarning avatar stylewarning commented on June 4, 2024

Note: PR in progress #14

from deprecated-coalton-prototype.

appleby avatar appleby commented on June 4, 2024

The diff in #14 looks similar to what I did in #12. I'm struggling to remember now why I abandoned that PR. Can't remember if I stumbled on a bug or if I was just vaguely unsatisfied with it.

from deprecated-coalton-prototype.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.