From unknown Fri Jun 13 11:30:45 2025 X-Loop: help-debbugs@gnu.org Subject: bug#75216: Miscompilation of code with numeric predicates Resent-From: "Thompson, David" Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Tue, 31 Dec 2024 00:18:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 75216 X-GNU-PR-Package: guile X-GNU-PR-Keywords: To: 75216@debbugs.gnu.org X-Debbugs-Original-To: bug-guile@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.173560424931678 (code B ref -1); Tue, 31 Dec 2024 00:18:02 +0000 Received: (at submit) by debbugs.gnu.org; 31 Dec 2024 00:17:29 +0000 Received: from localhost ([127.0.0.1]:60484 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tSPwu-0008Er-Rp for submit@debbugs.gnu.org; Mon, 30 Dec 2024 19:17:29 -0500 Received: from lists.gnu.org ([209.51.188.17]:56210) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tSPwr-0008Ei-DL for submit@debbugs.gnu.org; Mon, 30 Dec 2024 19:17:27 -0500 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 1tSPwq-00028F-Dn for bug-guile@gnu.org; Mon, 30 Dec 2024 19:17:24 -0500 Received: from mail-qt1-x831.google.com ([2607:f8b0:4864:20::831]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tSPwo-0001Qh-Gs for bug-guile@gnu.org; Mon, 30 Dec 2024 19:17:24 -0500 Received: by mail-qt1-x831.google.com with SMTP id d75a77b69052e-467838e75ffso116310131cf.3 for ; Mon, 30 Dec 2024 16:17:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=worcester.edu; s=google; t=1735604240; x=1736209040; darn=gnu.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=8dE2fS4nfKJ2yWQDv/R7KdPGRaL3K4JN6Qc9W7077BE=; b=Q8CqG4wVyyuuDX+v8ZAsH/a7+34cglfbzYy09M2o5uZnp8b+F+KXo31RLeYmj0SBY5 xWWLk7F6M5mTRtrmkhLOl+OfJTj/dxvgRQe7OlHzxMXw+bKg0uRyccUJtw1ou+xC1eYj fhKq5t0Nh0g8i69iu+UrXt0wFfTyzNbtiga4Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735604240; x=1736209040; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=8dE2fS4nfKJ2yWQDv/R7KdPGRaL3K4JN6Qc9W7077BE=; b=o3zV9fAVlrBsT77sy67ndv6HRiH9UFNvvUy7dBay5ioTZIdMtoNpAVHYlb8ChRR4R1 rL5cR24iW4n/vYnIUqWpui8FTYdJhDjzh7IeHls63uh4+cW4STTY17cabkm2/aPU9xFI UCYl3bAsP14Ye3QKE4/TTw963lCkPnNiff4HBcvkw5kV5rw4m4TITjb/aVIDdMsP6R0v aKJdkwjAa7g4N369aF947mMTfROaL2Uu+bF97OX1TMyN1o3CuaE2nXPlU1m3eBAd/qq+ cjA58TE5hvDCXx25vPmrkcBzKz9eGt3EJM74g8XolcbZRA8YYTUnOiAsEX3cQAkEq2tx vsLw== X-Gm-Message-State: AOJu0YzPzyyHS8jmVnV6Mmrky+eZe9eU+gHuFUchTww1/TOlaa7cZnBG IzZ9ruJTuiaz7wZcbSE1BPZY4+fA9vMquCQPVRdpcwYsaSOEL1GsDppy/OSPEXIubfRkwuYGXQq OFulKUY4N8BGscNLP2jOfG1gfDCTfptquDkKHD5NKVS7DFZK13go= X-Gm-Gg: ASbGnct+jLaifyIu8SPZobURCXnFy70PZfTPQo/gFBxem6jEFb2BT7h7yLVh8OJUYOP yiD5VtPEt/qoYZHp6H4QCO9VTNunrcHH42q8blot5sxP5hTLCBOZK X-Google-Smtp-Source: AGHT+IHi6w1YQWxa1GLV1MI+jcghvelTKrimJxD41LMTWu5lob3bAsc/1HzJINI3rhxweCJIL8vy6LqpVfzF4tCZv7g= X-Received: by 2002:ac8:57d2:0:b0:467:53c8:756a with SMTP id d75a77b69052e-46a4a8e83f6mr646196511cf.26.1735604238833; Mon, 30 Dec 2024 16:17:18 -0800 (PST) MIME-Version: 1.0 From: "Thompson, David" Date: Mon, 30 Dec 2024 19:17:08 -0500 Message-ID: Content-Type: text/plain; charset="UTF-8" Received-SPF: pass client-ip=2607:f8b0:4864:20::831; envelope-from=dthompson2@worcester.edu; helo=mail-qt1-x831.google.com 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, 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-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 (--) Consider this contrived procedure: (define (foo x) (cond ((integer? x) 42) ((and (number? x) (inexact? x)) 69) (else 138))) This procedure is kind of silly but it resembles some real world code I was debugging today. A call of (foo 8.2) should return 69 and indeed it does so on Guile 3.0.9. Not so on Guile 3.0.10 where it returns 138. The bytecode generated on 3.0.9 vs. 3.0.10 is very different, ~80 instructions vs. ~40, respectively. I suspected a bug in the type inference pass or related code and after a 'git bisect' it seems that is indeed the case: 55256ab33f14cd75778f089c5d96ea42f5b44397 is the first bad commit commit 55256ab33f14cd75778f089c5d96ea42f5b44397 Author: Andy Wingo Date: Fri Sep 15 15:21:26 2023 +0200 Better compilation for rational?, exact?, and so on These numeric predicates now have CPS branching primcalls, which allows type inference and folding to reduce them to less-strong instructions. * module/language/cps/effects-analysis.scm (heap-numbers-equal?): Put all the number predicates together. None have type checks. * module/language/cps/guile-vm/lower-primcalls.scm (define-branching-primcall-alias): New helper. (complex?): Same as number?. * module/language/cps/guile-vm/lower-primcalls.scm (real?) (rational?, integer?, exact-integer?, exact?, inexact?): Define lowerers. * module/language/cps/type-fold.scm (number?, complex?, real?) (rational?, integer?, exact-integer?, exact?, inexact?): Add folders and reducers for all of these. * module/language/cps/type.scm (number?, complex?, real?) (rational?, integer?, exact-integer?, exact?, inexact?): Add type inference for these. * module/language/tree-il/compile-cps.scm (convert): Add number? checks before exact? and inexact?. Remove the eager lowering of exact-integer?; instead rely on folders. * module/language/tree-il/cps-primitives.scm (number?, complex?) (real?, rational?, integer?, exact-integer?, exact?, inexact?): Add primitive decls. Define as "number-type-predicates?", meaning they need a number? guard. - Dave From unknown Fri Jun 13 11:30:45 2025 X-Loop: help-debbugs@gnu.org Subject: bug#75216: Miscompilation of code with numeric predicates Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Fri, 28 Feb 2025 20:23:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 75216 X-GNU-PR-Package: guile X-GNU-PR-Keywords: To: "Thompson, David" Cc: 75216@debbugs.gnu.org Received: via spool by 75216-submit@debbugs.gnu.org id=B75216.174077414926790 (code B ref 75216); Fri, 28 Feb 2025 20:23:01 +0000 Received: (at 75216) by debbugs.gnu.org; 28 Feb 2025 20:22:29 +0000 Received: from localhost ([127.0.0.1]:53455 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1to6sO-0006xw-Ab for submit@debbugs.gnu.org; Fri, 28 Feb 2025 15:22:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42584) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1to6sL-0006x3-1V for 75216@debbugs.gnu.org; Fri, 28 Feb 2025 15:22:26 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1to6sF-0002st-Ko; Fri, 28 Feb 2025 15:22:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To: From; bh=8PUdIUpwD0cST8O6pQnAkHI1EjP0b6+C7tYT/wxKXdg=; b=VEvcehT3hi5gerjdkT+i 56O6Bg7NnjqQwn0q4+BPWVhvjvQCv+g7lBwKWqEn7LahE9TUlBMRWYUuVhybdokpUKJj8VMuAoHHP n36Bx3W5/E2U+TGIl0zGuRtcFjRBIAd4ooztkyJZKU5RmlezyFtgDtOqfenIrH3VJZ7/bWTgo47/m wSdfcOusG5LUVBpcIbDKD4sn/MvZsDPJwCZuacVJDLmKo5U5nf9tDAq2UL2cNyppcJIzgeHhPDs/O haeiM7TrmQtVcUlqXo2P6QtpnTbTnfYQbv3G4x5oYzOn73eZhJtBj0ziz0ocNVsIabP7B6+/TYEJc xKvZ6RAfRNmF7g==; From: Ludovic =?UTF-8?Q?Court=C3=A8s?= In-Reply-To: (David Thompson's message of "Mon, 30 Dec 2024 19:17:08 -0500") References: Date: Fri, 28 Feb 2025 21:22:05 +0100 Message-ID: <87tt8dq0pe.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) 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: -3.3 (---) "Thompson, David" skribis: > Consider this contrived procedure: > > (define (foo x) > (cond > ((integer? x) 42) > ((and (number? x) (inexact? x)) 69) > (else 138))) > > This procedure is kind of silly but it resembles some real world code > I was debugging today. A call of (foo 8.2) should return 69 and > indeed it does so on Guile 3.0.9. Not so on Guile 3.0.10 where it > returns 138. Bug confirmed on c8a169d38825d5a21da5392b355ca5fc9f33fa55 (post 3.0.10). Ludo=E2=80=99.