unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Emacs 26.0.50 (Git@head) Nested defsubst fails
@ 2017-02-24  1:32 raman
  2017-02-24  4:12 ` Stefan Monnier
  0 siblings, 1 reply; 5+ messages in thread
From: raman @ 2017-02-24  1:32 UTC (permalink / raw)
  To: emacs-devel

I tracked down the breakage to the following use case:

If you have two functions defined via defsubst -- calling the  first
function from within the second causes a byte compile error. Appears to
be independent of lexical scoping. If interested I can email out a file
showing the breakage. 


Also, looking at define-inline and the comments in that file, I see that
we dont appear to have a prefered/recommended solution to  writing
functions that should be in-lined -- might be worth getting that fixed.

According to that file, defsubst and cl-defsubst appear to have
different issues with each --- though defsubst at least fo rmy use-case
has worked well for 20+ years.

emacspeak has a lot of defsubst forms that go back a long time, and I
tried a patch where I changed all defsubst forms to defun --- that
inexplicably led to build failures  that I could not explain ---
essentially the build system started loading all of emacspeak to build
each individual file.
-- 



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Emacs 26.0.50 (Git@head) Nested defsubst fails
  2017-02-24  1:32 Emacs 26.0.50 (Git@head) Nested defsubst fails raman
@ 2017-02-24  4:12 ` Stefan Monnier
  2017-02-24 16:20   ` raman
  0 siblings, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2017-02-24  4:12 UTC (permalink / raw)
  To: emacs-devel

> According to that file, defsubst and cl-defsubst appear to have
> different issues with each --- though defsubst at least fo rmy use-case
> has worked well for 20+ years.

`defsubst` is supposed to work reliably (with the caveat that it
doesn't support recursion, which would result in infinite-inlining) and
be very easy to use.

`cl-defsubst` can result in slightly more efficient code, but has
various quirks.

`define-inline` is designed to be reliable and give good performance: it
should result in code that's at least as efficient as that of
`cl-defubst`.  But it requires more effort on the part of the programmer
(it asks the programmer to write a kind of restricted macro).

I think `cl-defsubst` should be deprecated: if performance really
matters, `define-inline` is a better choice anyway and it's not that
hard to use.

Maybe the same could be said of `defsubst` but I haven't thought enough
about it to be sure.


        Stefan




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Emacs 26.0.50 (Git@head) Nested defsubst fails
  2017-02-24  4:12 ` Stefan Monnier
@ 2017-02-24 16:20   ` raman
  2017-02-24 17:36     ` T.V Raman
  0 siblings, 1 reply; 5+ messages in thread
From: raman @ 2017-02-24 16:20 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

When I said nested use fails,  it wasn't a recursive call to a defsubst
function -- here is what I meant:

(defsubst inner (x) 
...)


(defsubst outer (y)
..
(inner)
..)

Used to work, byte-compile now errors out.

I've also seen instances where even if compile succeeds, the result of
compilation is wrong, throws errors in unpredictable ways.
(>> According to that file, defsubst and cl-defsubst appear to have
>> different issues with each --- though defsubst at least fo rmy use-case
>> has worked well for 20+ years.
>
> `defsubst` is supposed to work reliably (with the caveat that it
> doesn't support recursion, which would result in infinite-inlining) and
> be very easy to use.
>
> `cl-defsubst` can result in slightly more efficient code, but has
> various quirks.
>
> `define-inline` is designed to be reliable and give good performance: it
> should result in code that's at least as efficient as that of
> `cl-defubst`.  But it requires more effort on the part of the programmer
> (it asks the programmer to write a kind of restricted macro).
>
> I think `cl-defsubst` should be deprecated: if performance really
> matters, `define-inline` is a better choice anyway and it's not that
> hard to use.
>
> Maybe the same could be said of `defsubst` but I haven't thought enough
> about it to be sure.
>
>
>         Stefan
>
>

-- 



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Emacs 26.0.50 (Git@head) Nested defsubst fails
  2017-02-24 16:20   ` raman
@ 2017-02-24 17:36     ` T.V Raman
  2017-02-24 18:24       ` Stefan Monnier
  0 siblings, 1 reply; 5+ messages in thread
From: T.V Raman @ 2017-02-24 17:36 UTC (permalink / raw)
  To: raman; +Cc: monnier, emacs-devel

Here's a sample file demonstrating the problem.
;;; byte compiling this with emacs 26 fails.
;;; Changing outer defsubst to defun succeeds


(defvar test-bc-null-char (format "%c" 0)
  "Null char.")

(defsubst inner (mode)
  "Remove null-char C-@."
  (declare (special test-bc-null-char))
  (goto-char (point-min))
  (cond
   ((eq mode 'all)
    (while (search-forward  test-bc-null-char nil t) (replace-match " control at ")))
   (t (while (search-forward  test-bc-null-char nil t) (replace-match "")))))

(defsubst  outer(mode)
  "Clean-up text before sending it out."
  (let ((inhibit-read-only t))
    (test-bc-fix-null-char mode)))

-- 

-- 



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Emacs 26.0.50 (Git@head) Nested defsubst fails
  2017-02-24 17:36     ` T.V Raman
@ 2017-02-24 18:24       ` Stefan Monnier
  0 siblings, 0 replies; 5+ messages in thread
From: Stefan Monnier @ 2017-02-24 18:24 UTC (permalink / raw)
  To: T.V Raman; +Cc: emacs-devel

> Here's a sample file demonstrating the problem.
> ;;; byte compiling this with emacs 26 fails.
> ;;; Changing outer defsubst to defun succeeds

Byte compilation of this file worked fine for me.  Then again, I suspect
this is not the example you wanted to show, since the `inner` function
is simply not used at all.


        Stefan



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-02-24 18:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-24  1:32 Emacs 26.0.50 (Git@head) Nested defsubst fails raman
2017-02-24  4:12 ` Stefan Monnier
2017-02-24 16:20   ` raman
2017-02-24 17:36     ` T.V Raman
2017-02-24 18:24       ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).