all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Philipp Stephani <p.stephani2@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>, emacs-devel@gnu.org
Subject: Re: Should records be able to mimic primitive types?
Date: Fri, 16 Jun 2017 18:42:08 +0000	[thread overview]
Message-ID: <CAArVCkQxsBu69i+tuNz1JwjTGqUA8AwMJcNDTcPjhUYMJe5+3Q@mail.gmail.com> (raw)
In-Reply-To: <jwvink1xgy3.fsf-monnier+gmane.emacs.devel@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 3372 bytes --]

Stefan Monnier <monnier@iro.umontreal.ca> schrieb am Mo., 12. Juni 2017 um
19:41 Uhr:

> >> It's not trying hard, just a simple check for a known, small, and
> >> rarely-changing list of primitive symbols.
> > To me, that's working very hard:
> > - extra code.
> > - extra maintenance
> > - extra run-time checks.
> > - no benefit since this doesn't catch a common situation.
>
> More concretely: what would be a scenario where such a check would
> be useful?
>
> AFAICT, you need all 3 of:
> 1- First, you'd need someone to be foolish enough to set his record's
>    type to be one of the primitive types.  This is the actual bug that
>    your extra check would aim to catch.
>

Yes, though I wouldn't consider it foolish. make-record can be called
indirectly, maybe even from a function that somehow generates the type
name. People might try to create records named 'integer' and be happy that
that appears to work.


> 2- Then you'd need to pass that object to a chunk of code which uses
>    `type-of` and then checks the result for that primitive type.
>    Otherwise, the type you set would behave just like any other
>    non-primitive type so the "bug" would be harmless anyway.
> 3- Furthermore, you'd need this object to be manipulated exclusively in
>    a way which also works with your record object without signaling an
>    error (e.g. if the primitive type used is `integer`, it means your
>    object should never be passed to the likes of `+` since otherwise the
>    bug would already be discovered by `+` without any need for your extra
>    check).
>
> I haven't seen any evidence that step 1 will ever occur, even by accident.
>

I don't care about how often some bug will occur. Rather the contrary: it's
the rare bugs that are insidious. People learn about the common ones
quickly, but nobody will expect a rare bug, until it arises.


>
> No idea how likely is step 2.  `type-of` is very rarely used (except via
> cl-defmethod) so it's fairly unlikely, but possible.
>
> Step 3 seems again very unlikely in itself, and even more so if step
> 2 occurred: if you checked with type-of that your object is of type
> `integer` there's a very high likelihood that you're going to then use
> operations which only work on integers.
>
> Will all 3 steps ever occur at the same time?
>

I don't think this is an important question. The important point is:
Previously, there were invariants such as (integerp x) == (eq (type-of x)
'integer) or that prin1 would only generate #s(hash-table ...) for actual
hash tables. Now these invariants are broken. But it's critical that
invariants are never broken, no matter how unlikely the breakage is.
Imagine a system where 1 + 1 = 3 in one trillionth of the executions: even
if the bug were rare, that system would be unusable. Even worse, because it
is so rare, it is much more disastrous when it happens, because people
started relying on the invariant that is "almost" guaranteed. But there's a
discontinuity between "invariant is guaranteed" and "invariant is almost
always guaranteed": the latter is identical to "invariant is not guaranteed
at all".


>
> Do we really want to make every call to `make-record` pay the extra test
> in order to hope to catch this hypothetical case?


Yes, absolutely. I don't care whether it's rare or hypothetical, it breaks
an invariant, and invariants must not be broken.

[-- Attachment #2: Type: text/html, Size: 4403 bytes --]

  reply	other threads:[~2017-06-16 18:42 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-04 22:00 Should records be able to mimic primitive types? Paul Eggert
2017-04-05  1:09 ` Stefan Monnier
2017-04-08 15:09   ` Philipp Stephani
2017-04-08 17:57     ` Stefan Monnier
2017-05-01 11:35       ` Philipp Stephani
2017-05-01 12:03         ` Stefan Monnier
2017-06-10 11:39           ` Philipp Stephani
2017-06-10 12:43             ` Eli Zaretskii
2017-06-12 15:07               ` Philipp Stephani
2017-06-12 17:00                 ` Eli Zaretskii
2017-06-12 17:15                   ` Stefan Monnier
2017-06-12 17:22                     ` Eli Zaretskii
2017-06-12 17:47                       ` Stefan Monnier
2017-06-12 17:40       ` Stefan Monnier
2017-06-16 18:42         ` Philipp Stephani [this message]
2017-06-16 19:07           ` Stefan Monnier
2017-09-24 14:47             ` Philipp Stephani
2017-09-24 16:44               ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAArVCkQxsBu69i+tuNz1JwjTGqUA8AwMJcNDTcPjhUYMJe5+3Q@mail.gmail.com \
    --to=p.stephani2@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.