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

Add copy-tree #25

Merged
merged 3 commits into from
May 22, 2023
Merged

Add copy-tree #25

merged 3 commits into from
May 22, 2023

Conversation

josephmturner
Copy link
Contributor

Resolves #24.

I copied the tests from /test/lisp/subr-tests.el. Would it be appropriate to indicate that the tests were copied from Emacs? Perhaps you'd prefer shorter tests?

@minad
Copy link
Member

minad commented May 21, 2023 via email

compat-30.el Outdated Show resolved Hide resolved
compat-tests.el Outdated Show resolved Hide resolved
@josephmturner
Copy link
Contributor Author

Yes, a short comment is appropriate.

Done.

However many tests are copied from Emacs. At some point we should think about possibly synchronizing the test suites.

This sounds like a good idea! Although in this case, it wouldn't work...

@josephmturner
Copy link
Contributor Author

I see now that I forgot to change the final literal. Fixed in the latest force-push.

But... IIUC the printed representation of structs are different pre- and post-26, so I'm not sure how to do this without a conditional.

I think we have to use make-record here instead, such that the reader of Emacs < 26.1 accepts the syntax. Then conditionally enable the record tests only on Emacs >= 26.1.

If the latest force-push doesn't work, could we keep the existing test which uses cl-defstruct to appease the pre-26 reader, and then wrap everything after the first let-block with (when (version<= "26.1" emacs-version) ...)?

According to Stefan , "[copy-tree] used to [work with structs]
back when cl-defstruct used vectors", so for pre-26 users, compat--copy-tree isn't necessary for dealing with structs anyway.

@minad
Copy link
Member

minad commented May 22, 2023

But... IIUC the printed representation of structs are different pre- and post-26, so I'm not sure how to do this without a conditional.

Yes, using the printed representation for the test is not ideal. You could still use a condition (if (< emacs-major-version 26) str1 str2), where str1 is the old string representation.

According to Stefan , "[copy-tree] used to [work with structs]
back when cl-defstruct used vectors", so for pre-26 users, compat--copy-tree isn't necessary for dealing with structs anyway.

That's right. But our test suite should cover all the supported Emacs versions in any case.

compat-tests.el Outdated Show resolved Hide resolved
@josephmturner
Copy link
Contributor Author

Yes, using the printed representation for the test is not ideal. You could still use a condition (if (< emacs-major-version 26) str1 str2), where str1 is the old string representation.

Okay! What would the string representation be for pre 26 versions?

@minad
Copy link
Member

minad commented May 22, 2023

Okay! What would the string representation be for pre 26 versions?

Run Emacs 25 :)

@minad
Copy link
Member

minad commented May 22, 2023

You could just guess the representation by looking at the old cl-defstruct definition. I suspect it was just the vector representation, e.g., [foo ...] for a foo struct, but I haven't checked.

@josephmturner
Copy link
Contributor Author

You could just guess the representation by looking at the old cl-defstruct definition. I suspect it was just the vector representation, e.g., [foo ...] for a foo struct, but I haven't checked.

Thanks, I'll do that. I was not looking forward to building Emacs 25.

@phikal
Copy link
Member

phikal commented May 22, 2023 via email

@josephmturner
Copy link
Contributor Author

josephmturner commented May 22, 2023

https://git.sr.ht/~pkal/guix-emacs-historical

Thank you!! This looks like a useful resource.

The pre-26 representation is [cl-struct-foo value] (I downloaded the 25 source, then renamed and evaled the old cl-defstruct definition)

@minad
Copy link
Member

minad commented May 22, 2023

@phikal Could you make these portable tarballs available somewhere, ideally signed?

@phikal
Copy link
Member

phikal commented May 22, 2023 via email

@josephmturner
Copy link
Contributor Author

josephmturner commented May 22, 2023

It looks like the problem now is that the pre-26 versions are failing due to (void-function recordp):

https://github.com/emacs-compat/compat/actions/runs/5043804459/jobs/9046066759?pr=25#step:6:66

Since recordp is defined in the C code, should we just mark compat--copy-tree as only available for 26 and later?

@phikal
Copy link
Member

phikal commented May 22, 2023

Since recordp is defined in the C code, should we just mark compat--copy-tree as only available for 26 and later?

No, I would oppose that.

We can either define a compatibility predicate recordp that would always return nil (since records were added in 26, though I don't think this would work), or we can check if recordp is fboundp before invoking it.

@josephmturner
Copy link
Contributor Author

We can either define a compatibility predicate recordp that would always return nil (since records were added in 26, though I don't think this would work), or we can check if recordp is fboundp before invoking it.

Okay, will do.

@minad
Copy link
Member

minad commented May 22, 2023

I agree with Philip.

Also we should not add recordp support to Compat, since we cannot reliably port back the record functionality. Please just check (fboundp 'recordp).

@phikal
Copy link
Member

phikal commented May 22, 2023

Yes, a short comment is appropriate. However many tests are copied from Emacs. At some point we should think about possibly synchronizing the test suites.

A number of our tests are more extensive than what Emacs has, which is the reason why the core has expressed interest in copying our code. So there is certainly potential for collaboration here.

@josephmturner
Copy link
Contributor Author

I have wrapped the body of compat--copy-tree with

  (let ((compat--recordp (if (fboundp #'recordp)
                             #'recordp
                           #'always))
    ...)

and replaced (recordp ...) with (funcall compat--recordp ...).

The backtrace now shows an error at (length (setq tree (copy-sequence tree))).

@minad
Copy link
Member

minad commented May 22, 2023

@josephmturner Thanks. I am trying to investigate the problem now.

@phikal
Copy link
Member

phikal commented May 22, 2023 via email

It seems we should avoid using the printed representation for the tests.
@minad minad merged commit c2c5e39 into emacs-compat:emacs-30 May 22, 2023
@minad
Copy link
Member

minad commented May 22, 2023

I merged this for now, with some more basic tests added, avoiding the printed representation. Regarding the fboundp check I would like to avoid this in the first place, but this requires some modification of compat-defun

minad added a commit that referenced this pull request May 22, 2023
@josephmturner
Copy link
Contributor Author

Also, remember not to sharp-quote a function symbol you are checking with `fboundp', because the point is that it might very well not be bound.

Good catch. Thank you!

@josephmturner
Copy link
Contributor Author

I merged this for now, with some more basic tests added, avoiding the printed representation. Regarding the fboundp check I would like to avoid this in the first place, but this requires some modification of compat-defun

Thank you!! I learned a lot working with you two today :)

@minad
Copy link
Member

minad commented May 22, 2023

Joseph, thank you, for the addition to both Emacs proper and Compat!

@josephmturner josephmturner deleted the emacs-30 branch May 22, 2023 09:45
minad added a commit that referenced this pull request May 24, 2023
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.

3 participants