-
Notifications
You must be signed in to change notification settings - Fork 28
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
Garbage collector #20
Comments
Hello, I haven't followed everything closely in the project, but I thought that at some point you used to use manishearth garbage collector crate. Why did you migrate? Did you make a post or a big commit explaining the reasons for migrations and what your current design is? I'm also wondering an extra thing: how are you able to trace elements across closure calls? In my lispy rust project, I had to go to great lengths to be able to trace values that are used in a closure, I wonder how you plan to go past the difficulty. At least for me and a few other people, the fact that Rust doesn't track the captured values used in a rust Happy to see you sticking with it though (I also hope to have a R7RS fully compliant interpreter/compiler by the next decade) Also, thank you for that hosted-langs link, I started to feel alone when searching frantically around internet for my issues when implementing it. Looks like I will have to write my own allocator after all. |
I never actually implemented anything with rust-gc, but I did look into every rust implementation I could find. I wrote a post about my final design. The reasons I did not go with rust-gc is firstly that it Using
can you share some example code illustrating the problem? I am not sure I follow. |
Let's say you want to host this piece of code: ;; Lexical binding by default.
(setq captured '(atom1 atom2))
(defun scm-closure (foo)
"Return non-nil if FOO is a nice value."
(memq foo captured)) As long as
Therefore, if |
Normally that code would not be a closure, because closures capture their lexical environment, and (let ((captured '(atom1 atom2)))
(defun scm-closure (foo)
"Return non-nil if FOO is a nice value."
(memq foo captured))) In that case I capture the whole lexical environment and store it as a list in the function object Lines 190 to 196 in a1e5983
Using cons cells is important here, because it means that multiple closures will share their closed-over lexical variables. When the GC traces the function object, it will trace the lexical environment as well. My lisp closures don't map to Rust closures, so they are two different issues. As far as Rust goes, my roots are created with the root! macro, which pins a value on the stack. It does not expose an "owned" value, so you can't move a root into closures. You can move a reference, but not the actual root. This means that Rust closures are not a problem for me. |
The plan for the garbage collector is to be generational, copying collector. The old generation will use Immix style mark region collector, which Jon Harrop calls a breakthrough in gc design. I don't fully understand yet why it is so great, but the rust interpreter folks used immix for their project as well. Our current implementation already allows for copying object pointers via indirection, so we have the ability to implement this.
When to promote objects to the Major heap?
A typical generational GC will promote objects after the survive N minor heap collections, where N is usually 1. However we can take advantage of the execution patterns of Emacs. Commands in Emacs are usually run in short bursts with lots of waiting. Everytime you type a character or run a command, emacs will evaluate some code. The best time to run GC is after the command completes and the display has been updated. This is also the best time to promote objects, because anything that is still live will typically live for a long time. If the current command generates so much garbage that it fills the minor (nursery) heap, then we could use Chenny's Semi-space copying approach to remove dead objects, without promotion.
The text was updated successfully, but these errors were encountered: