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

Use c3 linearization in the MOP #1033

Merged
merged 14 commits into from
Jan 30, 2024
Merged

Use c3 linearization in the MOP #1033

merged 14 commits into from
Jan 30, 2024

Conversation

fare
Copy link
Collaborator

@fare fare commented Oct 31, 2023

Runtime improvements

MOP:

  • Use c3 linearization for class precedence list.
  • Implement and use the C3 linearization algorithm for multiple inheritance.
  • Unify struct fields and class slots, using struct inheritance then class precedence list for slot order. This improves on previous semantics, but introduces a slight incompatibility and will require updating the optimizer.
  • Accordingly update various modules in std.

Also:

  • Define defmutable in prelude.
  • Add a (dump-backtrace?) parameter to control backtrace printing.
  • Support build-manifest in the runtime.
  • Move DBG macro in the runtime for past and future debugging.

Regenerate bootstrap.

@netlify
Copy link

netlify bot commented Oct 31, 2023

Deploy Preview for elastic-ritchie-8f47f9 ready!

Name Link
🔨 Latest commit 43f6781
🔍 Latest deploy log https://app.netlify.com/sites/elastic-ritchie-8f47f9/deploys/65b878d710dc500008b5a344
😎 Deploy Preview https://deploy-preview-1033--elastic-ritchie-8f47f9.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@fare
Copy link
Collaborator Author

fare commented Oct 31, 2023

Builds upon the cli branch of #1027.

@vyzo vyzo changed the base branch from master to cli October 31, 2023 14:24
@fare fare force-pushed the gxpkg-c3 branch 4 times, most recently from dc2d52e to b81f43a Compare October 31, 2023 23:51
@fare fare changed the title [WIP] Use c3 in defclass, gxpkg [WIP] Better graph traversal in defclass, gxpkg Nov 1, 2023
@fare fare force-pushed the gxpkg-c3 branch 2 times, most recently from 54b9b04 to 08e591d Compare November 1, 2023 21:25
@fare fare changed the title [WIP] Better graph traversal in defclass, gxpkg Use c3 linearization in defclass, and more Nov 1, 2023
@fare fare changed the base branch from cli to bad-syntax November 3, 2023 22:27
@fare fare changed the base branch from bad-syntax to master November 3, 2023 22:45
@fare fare changed the base branch from master to string November 4, 2023 06:37
Base automatically changed from string to master November 4, 2023 07:06
Copy link
Collaborator

@vyzo vyzo left a comment

Choose a reason for hiding this comment

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

Generally looks good, but can you please avoid the internal splicing defs as it makes the code slower?

Also, can you optimize a tad the intermediate garbage lists?
I suspect the code is about twice as slow as it could be.

I will add the slicing let form for v0.19 so that we don't have this problem in the future.

doc/reference/std/misc/rtd.md Outdated Show resolved Hide resolved
src/gerbil/prelude/core.ss Outdated Show resolved Hide resolved
src/gerbil/runtime/c3.ss Outdated Show resolved Hide resolved
src/gerbil/runtime/c3.ss Outdated Show resolved Hide resolved
src/gerbil/runtime/c3.ss Outdated Show resolved Hide resolved
src/gerbil/runtime/error.ss Show resolved Hide resolved
src/gerbil/runtime/mop.ss Outdated Show resolved Hide resolved
src/gerbil/runtime/mop.ss Outdated Show resolved Hide resolved
src/gerbil/runtime/system.ss Outdated Show resolved Hide resolved
src/gerbil/runtime/system.ss Outdated Show resolved Hide resolved
@fare fare enabled auto-merge (squash) November 4, 2023 11:01
@fare
Copy link
Collaborator Author

fare commented Nov 4, 2023

PTAL

Copy link
Collaborator

@vyzo vyzo left a comment

Choose a reason for hiding this comment

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

looks mostly good, some cosmetic comments.

src/gerbil/runtime/c3.ss Outdated Show resolved Hide resolved
src/gerbil/runtime/c3.ss Outdated Show resolved Hide resolved
src/gerbil/runtime/c3.ss Outdated Show resolved Hide resolved
src/gerbil/runtime/error.ss Show resolved Hide resolved
src/gerbil/runtime/mop.ss Outdated Show resolved Hide resolved
src/gerbil/runtime/mop.ss Show resolved Hide resolved
src/gerbil/runtime/mop.ss Outdated Show resolved Hide resolved
@fare fare force-pushed the gxpkg-c3 branch 2 times, most recently from 96cde9f to 65e6169 Compare November 8, 2023 00:38
@fare
Copy link
Collaborator Author

fare commented Nov 8, 2023

PTAL

src/gerbil/runtime/c3.ss Outdated Show resolved Hide resolved
src/gerbil/runtime/mop.ss Outdated Show resolved Hide resolved
src/gerbil/runtime/mop.ss Outdated Show resolved Hide resolved
@fare
Copy link
Collaborator Author

fare commented Jan 7, 2024

PTAL

doc/reference/gerbil/runtime/MOP.md Outdated Show resolved Hide resolved
doc/reference/std/errors.md Outdated Show resolved Hide resolved
Copy link
Collaborator

@vyzo vyzo left a comment

Choose a reason for hiding this comment

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

Some more comments for using the low level fx ops, we know they are fixnum and we don't need the type checks there.

Other than that, I think we should rename the plist/alist thing to properties.

But let's move this forward, the rename can happen in the next step to alleviate some pain.

src/gerbil/runtime/c3.ss Outdated Show resolved Hide resolved
src/gerbil/runtime/mop.ss Outdated Show resolved Hide resolved
src/gerbil/runtime/mop.ss Show resolved Hide resolved
src/gerbil/runtime/mop.ss Outdated Show resolved Hide resolved
src/gerbil/runtime/mop.ss Outdated Show resolved Hide resolved
src/gerbil/runtime/mop.ss Outdated Show resolved Hide resolved
src/gerbil/runtime/mop.ss Outdated Show resolved Hide resolved
@fare
Copy link
Collaborator Author

fare commented Jan 8, 2024

PTAL

Copy link
Collaborator

@vyzo vyzo left a comment

Choose a reason for hiding this comment

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

there are a few unrelated things, maybe we should pick them up for separate prs.

doc/reference/std/errors.md Outdated Show resolved Hide resolved
doc/reference/std/misc/rtd.md Outdated Show resolved Hide resolved
src/gerbil/runtime/c3.ss Outdated Show resolved Hide resolved
src/gerbil/runtime/mop.ss Show resolved Hide resolved
src/std/debug/DBG.ss Outdated Show resolved Hide resolved
Copy link
Collaborator

@vyzo vyzo left a comment

Choose a reason for hiding this comment

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

can we resolve the open threads?

doc/reference/std/errors.md Outdated Show resolved Hide resolved
Use c3 linearization for the class precedence list.
Use the class precedence list for the slot index allocation.
Test and document it all.

Define defmutable in prelude.

Add a (dump-backtrace?) parameter to control backtrace printing.

Support build-manifest in the runtime.

Distinguish cases of "Bad syntax".

Regenerate the runtime bootstrap.

std/misc/rtd: add type=?

Integrate feedback from review.

Fix c3-test for destructive operations

More review feedback

Checkpointing progress with MOP refactoring
Copy link
Collaborator

@vyzo vyzo left a comment

Choose a reason for hiding this comment

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

Well ok, let's merge it and follow up.

I left a big pile of comments for the follow up(s).

- The solution is to create a *new* API with *new* names that
must absolutely not clash with the old names.
Add a suffix or prefix such as `*`, `/2` or `%`, or take the opportunity
to give functions better, longer and/or more systematic names.
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's drop the "longer" :)


This parameter is notably used by the `display-exception` method for
the `Error` type in the runtime, and by `with-exception-stack-trace`
(see above) that is also used in the default exceptio handler installed
Copy link
Collaborator

Choose a reason for hiding this comment

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

exceptio*n

@@ -27,6 +27,7 @@
"gerbil/runtime/system"
"gerbil/runtime/loader"
"gerbil/runtime/control"
"gerbil/runtime/c3"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should collect those in a separate text file for inclusion, I hate myself for having 3 different versions of this list; can happen in a subsequent pr.

Comment on lines 162 to 163
;; c3 linearization
c3-linearize not-null? remove-nulls append-reverse
Copy link
Collaborator

Choose a reason for hiding this comment

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

we'll need to groups those better, c3-linearize goes with the mp, the other two are general utilities.

(def (class-opt? key)
(memq (stx-e key) '(slots: id: name: plist: constructor: unchecked:)))
(def (class-opt? key)
(memq (stx-e key) '(slots: id: name: alist: constructor: unchecked:)))
Copy link
Collaborator

Choose a reason for hiding this comment

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

these should become properties:, but we can do in follow up.

Comment on lines 810 to 811
;; In exchange for which 3. it's somewhat simpler and slightly faster in
;; the usual case that doesn't involve a call to next-method.
Copy link
Collaborator

Choose a reason for hiding this comment

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

probably quite a bit more than slightly :)

Comment on lines 813 to 817
;; Changing the protocol to access an explicit super argument would be
;; semantically nicer and would enable linear complexity for next-method
;; (in the number of classes, or even just in the number of applicable method,
;; if resolved only once), but would be notably more complex and somewhat
;; incompatible (or involve much cleverness for backward compatibility).
Copy link
Collaborator

Choose a reason for hiding this comment

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

this comment is quite misleading i think, do we need it?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Basically there is a tradeoff: either you have faster and simpler/leaner code for 99% of the cases, and let 1% have a quadratic which is usually small, or make verything slower/more bloated for that 1%....

f*ck the 1%! occupy LiSP! :)

(defrules defmutable ()
((_ var value) (begin (def var value) (set! var var) (void))))

(def gerbil-system-manifest
Copy link
Collaborator

Choose a reason for hiding this comment

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

this ends up being completely unrelated and maybe we should pull it to a separate pr... oh well, probably too much work and pain.

src/gerbil/runtime/util.ss Outdated Show resolved Hide resolved
src/gerbil/runtime/util.ss Outdated Show resolved Hide resolved
@vyzo vyzo changed the title Use c3 linearization in defclass, and more Use c3 linearization in the MOP Jan 29, 2024
@fare fare enabled auto-merge (squash) January 30, 2024 04:23
@fare fare merged commit c47bc90 into master Jan 30, 2024
12 checks passed
@fare fare deleted the gxpkg-c3 branch January 30, 2024 04:56
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.

None yet

2 participants