X-Loop: help-debbugs@HIDDEN Subject: bug#75216: Miscompilation of code with numeric predicates Resent-From: "Thompson, David" <dthompson2@HIDDEN> Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> Resent-CC: bug-guile@HIDDEN Resent-Date: Tue, 31 Dec 2024 00:18:02 +0000 Resent-Message-ID: <handler.75216.B.173560424931678 <at> debbugs.gnu.org> Resent-Sender: help-debbugs@HIDDEN X-GNU-PR-Message: report 75216 X-GNU-PR-Package: guile X-GNU-PR-Keywords: To: 75216 <at> debbugs.gnu.org X-Debbugs-Original-To: bug-guile@HIDDEN Received: via spool by submit <at> 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 <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1tSPwu-0008Er-Rp for submit <at> 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 <dthompson2@HIDDEN>) id 1tSPwr-0008Ei-DL for submit <at> 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 <dthompson2@HIDDEN>) id 1tSPwq-00028F-Dn for bug-guile@HIDDEN; 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 <dthompson2@HIDDEN>) id 1tSPwo-0001Qh-Gs for bug-guile@HIDDEN; Mon, 30 Dec 2024 19:17:24 -0500 Received: by mail-qt1-x831.google.com with SMTP id d75a77b69052e-467838e75ffso116310131cf.3 for <bug-guile@HIDDEN>; 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" <dthompson2@HIDDEN> Date: Mon, 30 Dec 2024 19:17:08 -0500 Message-ID: <CAJ=RwfaJ0tAZwbU77jNhHYbf4fzmt7k3q=+cB1JAzUi4zO9_rg@HIDDEN> Content-Type: text/plain; charset="UTF-8" Received-SPF: pass client-ip=2607:f8b0:4864:20::831; envelope-from=dthompson2@HIDDEN; 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 <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> 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 <wingo@HIDDEN> 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
Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) Content-Type: text/plain; charset=utf-8 X-Loop: help-debbugs@HIDDEN From: help-debbugs@HIDDEN (GNU bug Tracking System) To: "Thompson, David" <dthompson2@HIDDEN> Subject: bug#75216: Acknowledgement (Miscompilation of code with numeric predicates) Message-ID: <handler.75216.B.173560424931678.ack <at> debbugs.gnu.org> References: <CAJ=RwfaJ0tAZwbU77jNhHYbf4fzmt7k3q=+cB1JAzUi4zO9_rg@HIDDEN> X-Gnu-PR-Message: ack 75216 X-Gnu-PR-Package: guile Reply-To: 75216 <at> debbugs.gnu.org Date: Tue, 31 Dec 2024 00:18:02 +0000 Thank you for filing a new bug report with debbugs.gnu.org. This is an automatically generated reply to let you know your message has been received. Your message is being forwarded to the package maintainers and other interested parties for their attention; they will reply in due course. Your message has been sent to the package maintainer(s): bug-guile@HIDDEN If you wish to submit further information on this problem, please send it to 75216 <at> debbugs.gnu.org. Please do not send mail to help-debbugs@HIDDEN unless you wish to report a problem with the Bug-tracking system. --=20 75216: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D75216 GNU Bug Tracking System Contact help-debbugs@HIDDEN with problems
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997 nCipher Corporation Ltd,
1994-97 Ian Jackson.