From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#69739: 30.0.50; `type-of` is not precise enough Date: Mon, 11 Mar 2024 19:19:40 -0400 Message-ID: Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2211"; mail-complaints-to="usenet@ciao.gmane.io" Cc: monnier@iro.umontreal.ca To: 69739@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Mar 12 00:22:06 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rjoy6-0000M5-0J for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 12 Mar 2024 00:22:06 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rjoxd-00060Z-0k; Mon, 11 Mar 2024 19:21:37 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rjoxa-000609-5e for bug-gnu-emacs@gnu.org; Mon, 11 Mar 2024 19:21:34 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rjoxZ-0000i3-KT for bug-gnu-emacs@gnu.org; Mon, 11 Mar 2024 19:21:33 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rjoy2-00049k-0O; Mon, 11 Mar 2024 19:22:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: monnier@iro.umontreal.ca, bug-gnu-emacs@gnu.org Resent-Date: Mon, 11 Mar 2024 23:22:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 69739 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org X-Debbugs-Original-Xcc: monnier@iro.umontreal.ca Original-Received: via spool by submit@debbugs.gnu.org id=B.171019928115908 (code B ref -1); Mon, 11 Mar 2024 23:22:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 11 Mar 2024 23:21:21 +0000 Original-Received: from localhost ([127.0.0.1]:41468 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rjoxI-00048Q-W1 for submit@debbugs.gnu.org; Mon, 11 Mar 2024 19:21:20 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:57726) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rjoxC-000483-4s for submit@debbugs.gnu.org; Mon, 11 Mar 2024 19:21:14 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rjowW-0005kI-2z for bug-gnu-emacs@gnu.org; Mon, 11 Mar 2024 19:20:28 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rjowJ-0000Yz-Hp for bug-gnu-emacs@gnu.org; Mon, 11 Mar 2024 19:20:24 -0400 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 8D351442C81 for ; Mon, 11 Mar 2024 19:20:07 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1710199201; bh=QRkYvZ+UJHnYRPIGUOwQfw9e1IsIAkf5xRTK/vLYfwY=; h=From:To:Subject:Date:From; b=E3THFMtfxsPnnJtEnf4ghfxHzRAjWsyu+7YZC1i+4TgO+FuXBc7d44/UCCgoRe8VL Teg3MenyrGKRpadCCdxOKZvC8SP+xv3CKAZjjQLHFzEbQDXQ5nXKXwCxqZvsuZp/8J TSdOSf3lYAGB+GmKVZ0Y01XXub3zxZnDYN/wgZ8UBFRtTH2O8VOK4aCXrAcyQTEK8r VEDDCMVtLNoZQL1tUr5czIfFywRSHCz4TVJKtX4Vf5tj1ZaW+mtXxGF9wOarQ+q136 1yNm91Rl4rLFSeohUq0wq/9k7hPnQiROHLSM0e6pLzDI7FZY4UdOLJdVjFydAaYfDp zJmu9V0cpFn5w== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id BD5DC4447A8 for ; Mon, 11 Mar 2024 19:20:01 -0400 (EDT) Original-Received: from pastel (69-165-147-56.dsl.teksavvy.com [69.165.147.56]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 9DECE120403 for ; Mon, 11 Mar 2024 19:20:01 -0400 (EDT) Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:281498 Archived-At: Package: Emacs Version: 30.0.50 `type-of` is supposed to return "the" type of its argument. Given that ELisp has a notion of subtyping, "the" type is expected to mean "the most precise type". This is used in `cl-generic` to decide which method to apply, so it's important that it returns precise information. Currently, there `type-of` fails to return precise enough information in a few cases: - When the argument is nil, it returns `symbol`. The problem here is that `symbol` is not a subtype of `list`, whereas nil is a list. - When the argument is a special form, a C primitive, or a native-compiled function it returns `subr`. Currently our type hierarchy says that `subr` is a subtype of `compiled-function` (and hence of `function`), but a special form is *not* a function (it fails the `functionp` test and can't be `funcall`ed). Currently `cl-generic` works around the first point above by using (if FOO (type-of FOO) 'null) instead of calling `type-of` directly. Suggestion: I suggest we change `type-of` to return `null` for `nil`, `special-form` for subrs that are special forms, `subr-primitive` for C primitives, and `subr-native-elisp` for native-compiled subrs. There are a few other cases where we could improve the precision, tho they are less important because they don't cause problems w.r.t subtyping like the above does. Further improvements could include: - Return `boolean` for `t`. This would be nice otherwise (with the above suggestion) `cl-generic` can dispatch on "nil is a boolean" but not on "t is a boolean". - Return `keyword` for symbols that are keywords. - Return `fixnum` or `bignum` rather than just `integer`. Probably not worth the trouble. - We could go crazy and return `keyword-with-pos` for `symbols-with-pos` that are keywords. Of these further improvements, only the first (return `boolean` for `t`) seems worth the trouble. Still, any change as suggested here would be an incompatible change, so there's risk it'll break some code out there (`type-of` is not used very often, but it *is* used). Another option is to introduce a new function which does the same as `type-of` but with changes like the ones above. (we could even decide to give it a `cl-generic-` prefix to discourage its use elsewhere so we can be more free to change its return value in the future). Stefan