From unknown Fri Jun 13 10:01:27 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#42345 <42345@debbugs.gnu.org> To: bug#42345 <42345@debbugs.gnu.org> Subject: Status: 3.0.4 says "wrong num' of arg's to 1" vs 2.2.4: "wrong num' of arg's to baz" Reply-To: bug#42345 <42345@debbugs.gnu.org> Date: Fri, 13 Jun 2025 17:01:27 +0000 retitle 42345 3.0.4 says "wrong num' of arg's to 1" vs 2.2.4: "wrong num' o= f arg's to baz" reassign 42345 guile submitter 42345 Matt Wette severity 42345 normal thanks From debbugs-submit-bounces@debbugs.gnu.org Mon Jul 13 12:41:14 2020 Received: (at submit) by debbugs.gnu.org; 13 Jul 2020 16:41:14 +0000 Received: from localhost ([127.0.0.1]:49083 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jv1Vy-00066K-1j for submit@debbugs.gnu.org; Mon, 13 Jul 2020 12:41:14 -0400 Received: from lists.gnu.org ([209.51.188.17]:44528) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jv1Vv-00066C-Ts for submit@debbugs.gnu.org; Mon, 13 Jul 2020 12:41:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34862) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jv1Vv-00049u-M8 for bug-guile@gnu.org; Mon, 13 Jul 2020 12:41:11 -0400 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]:54780) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jv1Vu-0005VV-8L for bug-guile@gnu.org; Mon, 13 Jul 2020 12:41:11 -0400 Received: by mail-pj1-x1035.google.com with SMTP id mn17so109950pjb.4 for ; Mon, 13 Jul 2020 09:41:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:references:to:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=1lqLzouoDW46mRHxid/eYcJ5j6cEEIeK6IHjSqLQXps=; b=exyqdezhp7d6YH0kOJBFNKevPof7pnKNKR1lwFgnXslC8B065pCtoqtBf1cfRVspDu eWzBLaehKMTaBEZyB3SG/KKRRGCZ/P6eAvreRHs/3+ZR9RLIjjAjeaDBKsl+v2pOdEuT 2qSmbsYtgaI8vFBXMcjxfw1DSLymXUoUlvJya6r/RUP84g3rGok2wXxOkhWFWQSerQ9+ aqeRsMSZR9agtaXUVM3q5ogA2/Y5YSD6gXZlAVx29rc+uEKCWEoIjZUVBrGXp+l3EvWR YKLPi+G5i/gYgzPh7u2FrDJ3T0zibjphHzLbIN45m2NTukG7oVU/tJeMVIBdJGLyHhj/ 1xnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:references:to:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=1lqLzouoDW46mRHxid/eYcJ5j6cEEIeK6IHjSqLQXps=; b=s8DY5KYdpOTWXPpFEfAnLWCoJGFxMANGv0rdbcY8bnuwRB/Q62QWXrcUn+QRZm+DvQ Em0DYlGkKF+BtLB0CU2VecxzmzznXAHiJ39R0D+Qycg1Oap4Be9t8/uixRk5+qMb92Q/ fuDRgwgw+VdkNX9M52VG8jRk+6BMZ9ri4vi7rSORq1w/Bul9CDSkc0qW8iwWbihxeHyT 3wpdGv+csil2tpdnU3GlhZlgvOl0VNGrBc7WvFx41fHP/QiXfFIHzQIiT6o1PepXIEQi MKrZ0opp8GRcHsJggLbMDsnLtj9rHRMrZf062K2ML9op46O36wX9Ga7cefpdFi7p8GhT lGcg== X-Gm-Message-State: AOAM530H/Dz7H+oju9IzZJ44iaBYSX2p79HRYWftcNcYuBVhjIgtdplF F6N9yXcqlztt08nVkF4BQKvt5WBZJ3E= X-Google-Smtp-Source: ABdhPJzLLxpoIaEUGheDU1mAONSKXrpB6vdBpNXp1pE22NbguNPQnb7DW2aYs/DJBsXzm1NlkZ5bFQ== X-Received: by 2002:a17:90a:3624:: with SMTP id s33mr248029pjb.148.1594658468852; Mon, 13 Jul 2020 09:41:08 -0700 (PDT) Received: from [192.168.2.183] (64-52-176-132.championbroadband.com. [64.52.176.132]) by smtp.gmail.com with ESMTPSA id j10sm13074651pgh.28.2020.07.13.09.41.07 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 13 Jul 2020 09:41:08 -0700 (PDT) Subject: 3.0.4 says "wrong num' of arg's to 1" vs 2.2.4: "wrong num' of arg's to baz" References: To: bug-guile@gnu.org From: Matt Wette X-Forwarded-Message-Id: Message-ID: <104d8455-0da3-8dcf-13da-1a4ecec442a2@gmail.com> Date: Mon, 13 Jul 2020 09:41:06 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Received-SPF: pass client-ip=2607:f8b0:4864:20::1035; envelope-from=matt.wette@gmail.com; helo=mail-pj1-x1035.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) In Guile 3.0.4, the program below results in the error: /home/mwette/zz.scm:5:2: In procedure bar: Wrong number of arguments to 1 In Guile 2.2.4, the same program results in the error: ;;; /home/mwette/zz.scm:11:14: warning: wrong number of arguments to `bar' ;;; compiled /home/mwette/.cache/guile/ccache/2.2-LE-8-3.A/home/mwette/zz.scm.go However, once compiled, Guile 3.0.4, will repeat the same error message, while Guile 2.2.4, will not report any error. I consider reporting "1" as the name of a procedure a bug. Here is the program: (define (foo)   (define (bar a b)     (+ a b))   (define (baz)     (let* ((a 1)        (b 2)        (r (bar a b a)))       r))   (baz)) (foo) From debbugs-submit-bounces@debbugs.gnu.org Sun May 23 15:59:00 2021 Received: (at control) by debbugs.gnu.org; 23 May 2021 19:59:00 +0000 Received: from localhost ([127.0.0.1]:41793 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lkuFX-0003py-Ri for submit@debbugs.gnu.org; Sun, 23 May 2021 15:58:59 -0400 Received: from mail-ej1-f48.google.com ([209.85.218.48]:43894) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lkuFV-0003pk-Dc for control@debbugs.gnu.org; Sun, 23 May 2021 15:58:57 -0400 Received: by mail-ej1-f48.google.com with SMTP id f18so8249378ejq.10 for ; Sun, 23 May 2021 12:58:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=L2BS4WS7mXHm2DyQZmmPavjTTJ1G4DRXEbiW8iuvzAw=; b=XKAbjjaHDuvQ5Xq08uKLnfEZA1+FiJZ1uckxs0avIXRSuRvlya6qLdQKxxe352gB7H N30M2jriXwunXbAzRc5mo5OjnmthEWJQpOz1le538FZL7rpVZ4KYDP3VKnI6qFGoncJV D5ZcuA8l6eUs5DKko+zd1XkxeraWkycYP7yRy4G2ZgJUgQ4XBPNfTXAIznn+uJM028XM CJnKTqjILjrLCDUZyLoSUw4a3zhzGz6BWU6rHzGxiWl+8IYb+KvgRQV+mozJrqRnZwdk mlXFNeFkpOTITDM+iP+Qns1C2za2XZ5JjOshoNAFglkQqJmjLiN7MSSHlZsQzrygRqbA IQlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=L2BS4WS7mXHm2DyQZmmPavjTTJ1G4DRXEbiW8iuvzAw=; b=r48V7zyMNvWJIhj39A7f/03+zgsHa4vkPU0DGfvti3kwjsL6bdfsHVbZoHubfLuyWB Djdvk+Ow6hr4cGszvVEavEtwHqwh3mlW4hnY2xhEMvhh0B1akqHiBo1egX77N4sPHNYE yA/I14BiPgAk2q9tWfF+sUpGbfW/QtEJ7NR6xKXfwM8Wo8I04+YaWbnbrXovT8qyAhc1 F5TIPx/tP6sVamfZBz7JvQUaPFrspo+zuGvA4mggttz/rp9kE0xB9Q/vrBHlkkhwjlbY OXuOYaAOgh69EvWNJywym0FaZk1BoBbMBgL18R+vX8ADz5xPvSPbowJnr1GM022ghTBL WINQ== X-Gm-Message-State: AOAM531Y1F5eC2LBPEIfRTi8OpflcDKqNCxPR7EQJenIGHAh9fPhew/h lDCy7XKchk76EaBIfxLXYOozLEuEa3WDQQ== X-Google-Smtp-Source: ABdhPJyLbMXFLnMPivBiGF7haw3nUMFcg1WG3IKtCucx0SJZhbEMTut+DsvrQ962JFgTSiuRDkFmiA== X-Received: by 2002:a17:906:e210:: with SMTP id gf16mr20101631ejb.472.1621799931462; Sun, 23 May 2021 12:58:51 -0700 (PDT) Received: from [192.168.178.20] (b2b-109-90-125-150.unitymedia.biz. [109.90.125.150]) by smtp.gmail.com with ESMTPSA id h21sm5869648ejc.2.2021.05.23.12.58.50 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 23 May 2021 12:58:51 -0700 (PDT) To: control@debbugs.gnu.org From: Taylan Kammer Subject: merge 42345 42757 Message-ID: Date: Sun, 23 May 2021 21:58:49 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.2 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) merge 42345 42757 From debbugs-submit-bounces@debbugs.gnu.org Sun May 23 18:11:22 2021 Received: (at 42345) by debbugs.gnu.org; 23 May 2021 22:11:22 +0000 Received: from localhost ([127.0.0.1]:41909 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lkwJe-0000oV-3P for submit@debbugs.gnu.org; Sun, 23 May 2021 18:11:22 -0400 Received: from mail-ed1-f45.google.com ([209.85.208.45]:37395) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lkwJZ-0000oF-Gr for 42345@debbugs.gnu.org; Sun, 23 May 2021 18:11:21 -0400 Received: by mail-ed1-f45.google.com with SMTP id g7so17508297edm.4 for <42345@debbugs.gnu.org>; Sun, 23 May 2021 15:11:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:cc:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=FiTRIocwpJ73ibk59sKr2UrFE3xjBt5UzH7jxqpDenk=; b=fThJ66uNhQknxRnTEkVBilHl2jE4dchG97faJeBrJGSdrwWpB9h5K6HDm4ktkix5aZ nsPdTJ1nfrhcY7TZhfNNlvetqJHPJZ0gwkspxDq633UBJCkmBWg3ELwtWA/zRkVSwRTf s/czO32CMJPjOm82aMH1v+9kXiLVOyWLTFD+eFn+IVMMwgRVEZsK3ohKD4Ft5qWOa9Wa QDyljjszLt3WwlukHMhz9RXvXbRLcHOwK02xDdrdV8hlWHDy+eS7Y3dgjCnI863h3Udv 7tgwQP1Xnlk6ABzcg2SmqrUJDgyVeUPRVPHB7Sr/78M46tVAvLYu8vilyjoBjMQBNB9C e7Pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:cc:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=FiTRIocwpJ73ibk59sKr2UrFE3xjBt5UzH7jxqpDenk=; b=aJ2GwTa641Gs/PWJlyZx3wsU18TPfx9IgfMBo59v8w/dfUq9p/R+DqrQLuL8ahN35v Bwo4WfEOgIZJp90ZoFPs5Y+OfjJKY8SmqUMKP1XoYZVj2B2lMIMO+6ijDPN9OMElbf2L lG4R/bJt6pzM/c9gwg+JCDWh1WDlCtUc7gc4dSWWkBHBA1gV6FN5GXsBwvkBw+fOW8Mv rK/PGDxYuckwrjwMCY/cp52+LPtJiUulqoIKuIjISIBqJr4sGdad81bnw0eVrfJxPLPI WD1aRZ2OyMSIDz14XOnzJxMsGz6yH4fyvJX7hh9h/jJL8YP3wV3LB1u60Mmb7KN9TB6Q dfOw== X-Gm-Message-State: AOAM532rpXu3HhwMeavfxHJg5r973yOizqNixeJk4wphA8XSQGAY2jqO M9WyBeyhxNRdbR7CWRPJ/Zc= X-Google-Smtp-Source: ABdhPJy7uoOwspBjbeFzLWlsT2wV4BtGAJ2elQWkD0a5JzyCWqM/dj17gJbAMm+U3z6J36ttdbF9uA== X-Received: by 2002:a05:6402:17d9:: with SMTP id s25mr22206852edy.337.1621807871779; Sun, 23 May 2021 15:11:11 -0700 (PDT) Received: from [192.168.178.20] (b2b-109-90-125-150.unitymedia.biz. [109.90.125.150]) by smtp.gmail.com with ESMTPSA id jt11sm7090728ejb.83.2021.05.23.15.11.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 23 May 2021 15:11:11 -0700 (PDT) To: 42345@debbugs.gnu.org From: Taylan Kammer Subject: "Wrong number of arguments to 1" Message-ID: <62c508e7-74b1-adc2-affb-7f3f82ebcbf9@gmail.com> Date: Mon, 24 May 2021 00:11:10 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.2 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 42345 Cc: Andy Wingo , Christopher Lam , Matt Wette X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Note: merged with https://bugs.gnu.org/42757 as it's the same bug. Andy is in CC since we almost certainly need his input. :-) I've been working on this since a few days (had to learn much about the VM) and here's an explanation of what's going on. Firstly here's a minimal procedure that exhibits the bug: (define (test x) (define (inner-proc a) #f) (inner-proc 0 x)) Calling this procedure will always result in the error message: Wrong number of arguments to 0 Because the first argument to inner-proc is 0. Were the first argument x, then the argument we pass to 'test' would appear in the error message. That's our bug at a high level: the first argument to inner-proc being reported as the procedure that raised the error. The disassembly is quite slim: Disassembly of # at #x559c98764348: 0 (instrument-entry 82) 2 (assert-nargs-ee/locals 2 0) ;; 2 slots (1 arg) 3 (make-immediate 1 2) ;; 0 4 (handle-interrupts) 5 (tail-call-label 2) ;; inner-proc at #x559c98764364 ---------------------------------------- Disassembly of inner-proc at #x559c98764364: 0 (instrument-entry 81) 2 (assert-nargs-ee/locals 1 0) ;; 1 slot (0 args) 3 (make-immediate 0 4) ;; #f 4 (handle-interrupts) 5 (return-values) Here's some explanations for those who aren't savvy with the VM, starting from the top. (The instructions, like assert-nargs-ee/locals, are defined in libguile/vm-engine.c.) Ignore the instrument-entry and handle-interrupts instructions. - (assert-nargs-ee/locals 2 0) checks the number of arguments, ensuring that there's a total of 2 slots on the stack. [1] - (make-immediate 1 2) puts the Scheme number 0 in slot 0. [2] - (tail-call-label 2) jumps to the beginning of inner-proc. [3] - (assert-nargs-ee/locals 1 0) checks the number of arguments, ensuring that there's a total of 1 slot on the stack. [4] That's where the error is raised, by calling error_wrong_num_args from libguile/intrinsics.c, because there's 2 slots on the stack, not 1. Error_wrong_num_args tries to get the currently executed procedure from slot 0, and finds the number 0 there, wrongly using that instead. [1] Slot 0 is usually filled with the procedure being executed itself, before it's called, so the number of slots is usually the number of arguments plus one. [2] Slot references in the VM are referenced backwards from N-1 to 0, where N is the number of slots. In our case, as we have 2 slots, the number 1 refers to slot 0. The reason has to do with the Guile stack growing downwards. The constant 0 is represented by 2 because of its type tag as an "immediate" int, see scm.h for details. [3] The 2 represents the relative position of the first instruction of inner-proc, in 4-byte units. It's pretty close, as it's compiled right aside our top-level procedure 'test'. Since we're currently on instruction 5 of 'test', and instructions are 4 bytes long, and 'test' begins at 0x559c98764348, this means we're jumping to: 0x559c98764348 + 5*4 + 2*4 = 0x559c98764364 Which happens to be the address of inner-proc, see? :-) [4] I don't know why only one slot even though it has one argument; it should be two slots. Maybe an optimization, as the compiler decides that the procedure doesn't ever need a reference to itself? To summarize: for some reason the compiler decides to *not* use an extra slot for the currently-executed procedure when calling inner-proc, which leads to the first argument to inner-proc (in this case 0) being used as the "procedure being executed" during error reporting. Perhaps that optimization (assuming it is one and not simply a bug in the compiler) should be disabled, or maybe the code shouldn't even compile since it can be statically proven that a procedure is being called with the wrong number of arguments. This is where I defer to the Guile compiler experts. -- Taylan