Live data from Hacker News

Continued progress porting Emacs to Rust

db48x.net

51–60 of 60 posts

Re: Continued progress porting Emacs to Rust

#51
post #43

Earlier quoted context omitted.

You can't ever usefully dereference a null pointer, so the only thing you can safely do with it is check to see if it is null. I commented on a sibling comment in more detail, but basically in Rust no reference is allowed to be null except temporarily inside an unsafe context.

There isn't anything you can do safely with an actually uninitialized value, though. In the internals of TXR Lisp, I used a null pointer to represent the symbol nil , with all the useful semantics that follows. If an object containing Lisp values is initialized to zero, those values are nil .

Yes, Emacs and Remacs do the same thing. All Lisp values are tagged pointers, and a nil gets encoded as a zero value with a zero tag. It's simple and easy to check for, and you won't have any problems as long as you always remember to do so.

However, this is not a Lisp value; it's a pointer to one. Specifically, it's a pointer to memory set aside to store a specific Lisp variable's value. Leaving it zeroed makes no sense, because eventually someone is going to store a value in there and it'll have to be allocated anyway. Better to do that all in one large block, rather than a thousand tiny ones. Even if we wanted to lazily allocate these, we can't leave a simple Rust reference (or pointer) null past the end of the unsafe block.

Rust does have an Option type, and if you use it on a type that isn't nullable, then the compiler will use the zero value for None variant and all other values for the Some. Since references can never be null, an Option will always take up the same amount of space as a &T; there's no additional overhead. At some point, when enough of the C code is ported to Rust, I'm sure we'll start using this to represent all Lisp values and a Lisp nil will always be a Rust None.

Re: Continued progress porting Emacs to Rust

#52
post #40
post #24

Earlier quoted context omitted.

Although Scheme has a standard, I wouldn’t really call Guile ‘more modern and standardised’: Guile has no standard (it extends the Scheme standard in incompatible ways), and ‘modern’ is hard to define. Emacs Lisp added lexical scope in the past couple of years, probably more recently than Guile added a new language (as opposed to library) feature — is that modern enough? I wouldn’t imagine that the two efforts are co…

it extends the Scheme standard in incompatible ways What does "incompatible" mean here? Incompatible with the Scheme language reports, or incompatible with other Schemes' extensions?

Guile includes a bunch of functions that aren't part of the standard, and have been around before Scheme's standard thought to implement libraries.

Re: Continued progress porting Emacs to Rust

#55
post #51

Earlier quoted context omitted.

There isn't anything you can do safely with an actually uninitialized value, though. In the internals of TXR Lisp, I used a null pointer to represent the symbol nil , with all the useful semantics that follows. If an object containing Lisp values is initialized to zero, those values are nil .

Yes, Emacs and Remacs do the same thing. All Lisp values are tagged pointers, and a nil gets encoded as a zero value with a zero tag. It's simple and easy to check for, and you won't have any problems as long as you always remember to do so. However, this is not a Lisp value; it's a pointer to one. Specifically, it's a pointer to memory set aside to store a specific Lisp variable's value. Leaving it zeroed makes no s…

> Even if we wanted to lazily allocate these, we can't leave a simple Rust reference (or pointer) null past the end of the unsafe block.

So make it an Option, and get rid of the unsafe block altogether.

Re: Continued progress porting Emacs to Rust

#56

The author misunderstands some parts of the C language, in particular related to static variables. "In fact, these aren't just file globals accessible to only one translation unit, these are static variables that are accessible across the whole program." gets the meaning of C's static exactly backwards: C file-scope static variables are only accessible (by name) in their translation unit; all other file-scope variabl…

> gets the meaning of C's static exactly backwards Which one? It has multiple. First, there is storage duration: C99 6.2.4 "There are three storage durations: static, automatic, and allocated." Variables with external linkage defined at file scope are static in the sense that they have static storage duration; it is not incorrect to call them static variables, though a bit unusual. If they have external linkage, it's…

> Which one?

The one that was entirely clear from context: Linkage.

Re: Continued progress porting Emacs to Rust

#58
post #5

And there are related efforts to upgrade the lisp used in emacs to a more modern and standardized version. I think it is GuileEmacs I am remembering. I hope to two efforts are compatible.

It’s a mistake to replace emacs lisp. For a start everyone’s custom code and configurations would have to be modified or scrapped. Package libraries would have to be ported. Much better to just improve it in a backwards compatible way or with libraries. Both of which are happening.

The goal of Guile Emacs is not to replace Elisp; it is to replace the implementation with Guile.

Re: Continued progress porting Emacs to Rust

#59
post #47
post #45

Earlier quoted context omitted.

Anyone who has seriously proposed porting Emacs to any language will have made plans to support running the existing Elisp code without modification. You can easily write an Elisp compiler in Common Lisp. In fact, the original Lisp machine eventually supported Common Lisp as well as the original Lisp Machine Lisp. You could write any individual function in either language, and call from one to the other transparently…

> You can easily write an Elisp compiler in Common Lisp I have no idea how easy it is and I have seen no attempt to do that (running the existing Elisp code without modification on top of a CL runtime). If it would be easy, I'd expect it to be done already. The https://www.cliki.net/CL-Emacs page seems to of no help... Do you know of any attempt demonstrating how easy it actually is? > In fact, the original Lisp mach…

Well, I grant you that it won't be done in a day.

Re: Continued progress porting Emacs to Rust

#60
post #51

Earlier quoted context omitted.

Yes, Emacs and Remacs do the same thing. All Lisp values are tagged pointers, and a nil gets encoded as a zero value with a zero tag. It's simple and easy to check for, and you won't have any problems as long as you always remember to do so. However, this is not a Lisp value; it's a pointer to one. Specifically, it's a pointer to memory set aside to store a specific Lisp variable's value. Leaving it zeroed makes no s…

> Even if we wanted to lazily allocate these, we can't leave a simple Rust reference (or pointer) null past the end of the unsafe block. So make it an Option, and get rid of the unsafe block altogether.

Perhaps one day we will be able to do so.
Post reply on HN