GNU bug report logs - #75216
Miscompilation of code with numeric predicates

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: guile; Reported by: "Thompson, David" <dthompson2@HIDDEN>; dated Tue, 31 Dec 2024 00:18:02 UTC; Maintainer for guile is bug-guile@HIDDEN.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 31 Dec 2024 00:17:29 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Dec 30 19:17:29 2024
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>
Subject: Miscompilation of code with numeric predicates
To: bug-guile@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-Debbugs-Envelope-To: submit
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




Acknowledgement sent to "Thompson, David" <dthompson2@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-guile@HIDDEN. Full text available.
Report forwarded to bug-guile@HIDDEN:
bug#75216; Package guile. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Sun, 12 Jan 2025 05:45:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.