From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: akater Newsgroups: gmane.emacs.bugs Subject: bug#49291: [akater] Re: [akater] [PATCH] lisp/emacs-lisp/eieio.el (initialize-instance): Fix initform Date: Wed, 30 Jun 2021 16:49:15 +0000 Message-ID: <871r8juwl0.fsf@gmail.com> References: <875yxvuwtf.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="35430"; mail-complaints-to="usenet@ciao.gmane.io" To: 49291@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jun 30 19:01:21 2021 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 1lydaT-0008wB-BK for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 30 Jun 2021 19:01:21 +0200 Original-Received: from localhost ([::1]:32866 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lydaS-0002jM-Az for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 30 Jun 2021 13:01:20 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:56958) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lydaA-0002j9-Ah for bug-gnu-emacs@gnu.org; Wed, 30 Jun 2021 13:01:05 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:47100) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lydaA-0001TY-2S for bug-gnu-emacs@gnu.org; Wed, 30 Jun 2021 13:01:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lydaA-0007qc-01 for bug-gnu-emacs@gnu.org; Wed, 30 Jun 2021 13:01:02 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: Resent-From: akater Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 30 Jun 2021 17:01:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 49291 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 49291-submit@debbugs.gnu.org id=B49291.162507243330124 (code B ref 49291); Wed, 30 Jun 2021 17:01:01 +0000 Original-Received: (at 49291) by debbugs.gnu.org; 30 Jun 2021 17:00:33 +0000 Original-Received: from localhost ([127.0.0.1]:58646 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lydZg-0007po-Gt for submit@debbugs.gnu.org; Wed, 30 Jun 2021 13:00:32 -0400 Original-Received: from mail-ed1-f42.google.com ([209.85.208.42]:42854) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lydZe-0007pc-Qw for 49291@debbugs.gnu.org; Wed, 30 Jun 2021 13:00:32 -0400 Original-Received: by mail-ed1-f42.google.com with SMTP id n25so4227762edw.9 for <49291@debbugs.gnu.org>; Wed, 30 Jun 2021 10:00:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:references:date:message-id:mime-version; bh=h9v5ODuIKF6Zx79ZYQkp4TiKXalh2XVXR8+UV2SOsVQ=; b=Gt0MhCnvxEY2fIQnNm1E7/1vb31Z5gvU8JQ7Pd+2LNTJSuSDq/6LZL7svVrousvEhO N/npwpKpd8t+lGULL7AK6g9TYtaaxortGBkuOOwRNPhDXHLugY54gUVvSm1yncPg7Ucf 1SekDT8/kymqEXNczqCQfhSXW9Z7DczGmMQCJqjnolToFRAOJAc2xYFZcqaGhApMPHEI IbGSOEgvg7R6mE9TIASXVGpf8SMMHUCr14te6HnWjGDqxzo5iX8rH7GSwQB9zcuxEifr pXMPlb9RbxSNk2qjVqmRK+jO3phbtMcCuEn1VqqQD/akWroVob5z1+Z/hky9iJmM9VXs u6HA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:references:date:message-id :mime-version; bh=h9v5ODuIKF6Zx79ZYQkp4TiKXalh2XVXR8+UV2SOsVQ=; b=lIguNv0QZ70I+Di232umtL8DryahfKXjlJycH9TvsE2l/6T6pPZNkkcBmAusSbkKyO fmRqybakk3AVby1ayv2qXE14Apts34QblCYQyeYieHx+v1vJnmbYs8tfsNUGSWW/ZVl6 RxWHDMr3W2FwxvrwovDTiAy06PUVy9AD503c6Uww848z6uu5Z6pLvqqx8EiQxz5Z9tG7 jbsctqG3vpMlkq4d9ODjyXXK7hYDW8MO79auknt+i7JvHhUdFQ/hIp2Z6Uc4TFpEi2AE cT82DlIABT0jzCzhyAFhJ7ZUtK5D70spMpVFYYefbTRc7b4er4CaAiJHeGwztZQU048y 6Tfg== X-Gm-Message-State: AOAM531g2gfFQIXoSkl+P2YTn8MOS0uqSe1KaE3nCSQxKbSwpmnBkTTk r6kJPjYLF69v+IUlWNejFwNa9MZ0PwXxeg== X-Google-Smtp-Source: ABdhPJyLejRXT66qXkdTYTd9lvVd5d/D4098ewfMA/PaukGJqNInxznlE0CXfs+v740AY80C/t67iA== X-Received: by 2002:a05:6402:14d8:: with SMTP id f24mr1589687edx.195.1625072424908; Wed, 30 Jun 2021 10:00:24 -0700 (PDT) Original-Received: from localhost ([185.220.101.194]) by smtp.googlemail.com with ESMTPSA id y27sm9292906ejk.89.2021.06.30.10.00.23 for <49291@debbugs.gnu.org> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Jun 2021 10:00:24 -0700 (PDT) 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" Xref: news.gmane.io gmane.emacs.bugs:209224 Archived-At: --=-=-= Content-Type: text/plain -------------------- Start of forwarded message -------------------- From: akater To: Stefan Monnier , 49291@gnu.org Subject: Re: [akater] [PATCH] lisp/emacs-lisp/eieio.el (initialize-instance): Fix initform Date: Wed, 30 Jun 2021 16:44:12 +0000 --=-=-= Content-Type: multipart/mixed; boundary="==-=-=" --==-=-= Content-Type: multipart/signed; boundary="===-=-=" --===-=-= Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable There are iusses, some stylistic, some related to comments in the code. - There is a comment here: > First, see if any of our defaults are `lambda', and > re-evaluate them and apply the value to our slots.=20=20=20=20=20=20=20= =20=20=20=20=20=20 I don't observe anything like this happening. Looks like it refers to eieio-default-eval-maybe (likely referring to any compound form with fbound car as to `lambda') which used to be in eieio-core in 27 but now is gone. Maybe we should drop this comment? - There is a comment: > For each slot, see if we need to evaluate it Slots are self-evaluating objects; I think it was meant to be =E2=80=9Cto evaluate its initform=E2=80=9D. - There is FIXME > FIXME: We should be able to just do (aset this (+ i ) dflt)!=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20 Local variable dflt had been removed after Emacs 27 release. The comment should likely have been gone too, or at least updated. It suggests to assign the value of initform with a low-level `aset' applied to eieio--class struct but (1) I don't understand the + i shift (2) eieio--class is not declared to be of :type vector, neither does it inherit from a struct declared to be of :type vector. I suggest to replace the comment with =E2=80=9CTODO: maybe specify eieio--class as vector and use aset here=E2=80= =9D - I employ when-let which requires subr-x at compile time. I can't check the build cleanly right now, only with some dirty reverts related to libseccomp issues but aside from that, this subr-x dependency doesn't break byte-compilation of eieio.el. I hope it's fine? --===-=-= Content-Type: application/pgp-signature; name=signature.asc Content-Transfer-Encoding: base64 LS0tLS1CRUdJTiBQR1AgU0lHTkFUVVJFLS0tLS0KCmlRSkxCQUVCQ2dBMUZpRUVndTVTSlJkblFP RjM0ZGpOc3I2eFliSHNmMFFGQW1EY24yUVhIRzUxWTJ4bFlYSnoKY0dGalpVQm5iV0ZwYkM1amIy MEFDZ2tRc3I2eFliSHNmMFNGbmhBQW9WeEJqUk5KR1ljZUlIWkZFSEZPQmZ1VQpvcVZHQ0laK3lC dHBGWkpGTTRzK05CWG0zTTd5S1R5MjR6MkxDUVVrby9SOENzSjI4aktQSWpwV3JwUG5DNmlvClNW Y0RhWEpPdDkyQndGRmRza1lpWTBSb2c1RkEvYnFYVSt1ZTBveTlXUE9jL1lndlVEY1V6NGtwOTVa WEUycS8KWWlXUXVPZU5OWThwUTdjWENYWi9UMkh1ZlIvRjRtNGt5aVFFNEVjSjk0UGdGOXlpOUVU c3pCN21LdUhHM3R1ZQo0aEFORW54N1ZoMnF5U0hsNmo0bmN6L0tvc0Z5c2N1SXJuZFFPaTUrb21H TUdBOTRpRjd4RFZqRFdNS05SVCs5Ci8vK210dmQ5UnpRbVNkTDVhWmtNMlIrNXgzZzl4cjlaQnRX V0NhZDhkWmlWWGhna0pFOUFhR3k5UHVzM2x5UGYKZm9XS09FVDljT3hBcjdpVDY3VjgrOE9FcDlV R2ZGSUlPVkZReWg4dlB6UkNJVVhvbndNMW9saFZHbms5MElaagp6Qy9nMW9OWDR1UjVBdngvN1BK MlM2N3U5ZWVURzBmekhSWW9nYVBVenkzZWVlV1VEUEZWM3JpNGZQVk1BVXlxClpYcEVJZWlZRnB0 MkpFMFZIcllmK1R0VDh6RWdEL29qRmlxK0xyNVRHRjViaFNVUDZ6dXcwSEZHVDY1Z2hPUWsKSmk2 eXdPdlpMTDdtejZHTUM2d3p4TTl4dnB0eU96SFFtR2g5a2ZaVUluMVVTVWlxR0FRTDNERVBlRWE5 Wk9UWQo1d0UxckdOY1pRUm0rSmhZZlVmWFc5NnZGTWE2WVdmR1AyamZCQW5aNXZJUXlKM2dIQ3Uy anUrKy9ONWYvck1MCnpYMnJGQS9zN3JpamZlSDZoakU9Cj1hTnNXCi0tLS0tRU5EIFBHUCBTSUdO QVRVUkUtLS0tLQ== --===-=-=-- --==-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-lisp-emacs-lisp-eieio.el-initialize-instance-Fix-eva.patch Content-Description: Fix eval initform >From 588e7ff1b34ccfbc9e3cb97d06ae3315487d42c9 Mon Sep 17 00:00:00 2001 From: akater Date: Wed, 30 Jun 2021 11:43:23 +0000 Subject: [PATCH] lisp/emacs-lisp/eieio.el (initialize-instance): Fix eval initform: Do not evaluate initform of a slot when initarg for the slot is provided. According to the following secitons of CLHS: - Object Creation and Initialization - Initialization Arguments - Defaulting of Initialization Arguments - Rules for Initialization Arguments --- lisp/emacs-lisp/eieio.el | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/lisp/emacs-lisp/eieio.el b/lisp/emacs-lisp/eieio.el index 1c8c372aae..ec05a07307 100644 --- a/lisp/emacs-lisp/eieio.el +++ b/lisp/emacs-lisp/eieio.el @@ -53,6 +53,7 @@ defun eieio-version () (message eieio-version)) (require 'eieio-core) +(eval-when-compile (require 'subr-x)) ;;; Defining a new class @@ -740,7 +741,7 @@ defclass eieio-default-superclass nil "Construct the new object THIS based on SLOTS.") (cl-defmethod initialize-instance ((this eieio-default-superclass) - &optional slots) + &optional slots) "Construct the new object THIS based on SLOTS. SLOTS is a tagged list where odd numbered elements are tags, and even numbered elements are the values to store in the tagged slot. @@ -749,20 +750,25 @@ defclass eieio-default-superclass nil to have this constructor called automatically. If these steps are not taken, then new objects of your class will not have their values dynamically set from SLOTS." - ;; First, see if any of our defaults are `lambda', and - ;; re-evaluate them and apply the value to our slots. (let* ((this-class (eieio--object-class this)) + (initargs slots) (slots (eieio--class-slots this-class))) (dotimes (i (length slots)) - ;; For each slot, see if we need to evaluate it. + ;; For each slot, see if we need to evaluate its initform. (let* ((slot (aref slots i)) + (slot-name (eieio-slot-descriptor-name slot)) (initform (cl--slot-descriptor-initform slot))) - ;; Those slots whose initform is constant already have the right - ;; value set in the default-object. - (unless (macroexp-const-p initform) - ;; FIXME: We should be able to just do (aset this (+ i ) dflt)! - (eieio-oset this (cl--slot-descriptor-name slot) - (eval initform t)))))) + (unless (or (eq eieio--unbound initform) + (when-let ((initarg + (car (rassq slot-name + (eieio--class-initarg-tuples + this-class))))) + (plist-get initargs initarg)) + ;; Those slots whose initform is constant already have + ;; the right value set in the default-object. + (macroexp-const-p initform)) + ;; TODO: Maybe specify eieio--class as vector explicitly and use aset + (eieio-oset this slot-name (eval initform t)))))) ;; Shared initialize will parse our slots for us. (shared-initialize this slots)) -- 2.31.1 --==-=-=-- --=-=-= Content-Type: text/plain -------------------- End of forwarded message -------------------- --=-=-= Content-Type: multipart/signed; boundary="====-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" --====-=-= Content-Type: text/plain --====-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQJLBAEBCgA1FiEEgu5SJRdnQOF34djNsr6xYbHsf0QFAmDcoIsXHG51Y2xlYXJz cGFjZUBnbWFpbC5jb20ACgkQsr6xYbHsf0TW0A//bxR0gdtdkzOzglIvl4Xcaevs YLyPPs/eNMzEl6+UmIHQrOgP0TM4NOHF2ij07+Yl7Aa+hr5uEsjTokHldJ+/nZBN 10f2X01V/81ZSw7WvoSlQNzPBpm6MDTssxH0uw9zHam6+8Kz3Migjju6a7g5Yw5M U9ryw/86t74Fxb/aS5vaDqFQtPhZUcroSVU+RFalQRYcsSCBGH3cAnBgS8LSUQHj mQVIi2XrgRyVHVSgTa0ChS6aAgwQQixe7YuyBxsLU7bqhmX1DjGFnpK5DACGmMn1 qr407RkjIM6jdCvOFHpkgdS7NGucRxIctLMhQca5KhGDdo0zw4EQJ4Bo+/Dmkk6x Q0JqiuI/TnF31/YmK8PdSrTgpplbVbAtOBRHPJiRmdzSpt9OGnvoJ8bpSCyAG6A/ A+8rHITVibScfxRFTGKyKzAxfcxnuABeZL9ApF67MUZ5GjtY4xUBTmRNch599WOj WFNgC/4JQThnqi3ALKfdWDwj8nfTlRKCVOeuVYQ0Gyxis6vJQzbpn32gZzuKBjKe /FjZ08xwxNSqloJ2cKmsMGezAYm8SEb871AFmkF/isWuvg9djA2DQjPV3H6uASrh Al1yBdDyscRCo5/ANxpJsJu3Ag5dcwTAreCl7k64nGZK6nSAUcraxdFGyBjaixek mVOqC0FRb06Ck4chaMQ= =ndrl -----END PGP SIGNATURE----- --====-=-=-- --=-=-=--