Skip to content

monomorphization+inlining sometimes leads to undefined functions #1417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
stylewarning opened this issue Mar 19, 2025 · 1 comment
Open

Comments

@stylewarning
Copy link
Member

Disable specialization, and compile a file containing:

(in-package #:coalton-user)

(named-readtables:in-readtable coalton:coalton)

(coalton-toplevel
  (inline) (monomorphize)
  (declare f (UFix -> (:t -> :t -> Boolean) -> (UFix -> :t) -> :t))
  (define (f n better? func)
    (assert (< 0 n))
    (rec % ((i 1) (best (func 0)))
      (cond
        ((== i n)
         best)
        (True
         (let ((candidate (func i)))
           (if (better? candidate best)
               (% (1+ i) candidate)
               (% (1+ i) best))))))))

(coalton-toplevel
  (define (g)
    (f 10 < (fn (x) x))))

In the processing of g, you will get a warning akin to:

; caught COMMON-LISP:STYLE-WARNING:
;   undefined function: COALTON-USER::|<#3626|

This does not happen if:

  1. They're in the same coalton-toplevel.
  2. They're compiled separately with C-c-c.
  3. (monomorphize) is removed.
  4. (inline) is removed.

The issue seems to be that g contains a function named |<#X|, but f had defined |<#Y| for some Y.

@stylewarning
Copy link
Member Author

If I remove the readtable setting, the issue also goes away. Quizzically, putting a break in the monomorphizer tells me f is being monomorphized twice, once in ordiinary processing, and a second time when a code deletion note is being issued. Very weird but also not surprising given we hijack #\(.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant