Skip to content

Foreign procedures don't get inferred source location in their code info #1020

Description

@williewillus

Example:

(define ff
  (let ([opnd 1.0])
	(lambda (x)
	  (if (flonum? x)
		  (fl+ x opnd)
		  (error 'dummy "not a flonum")))))

(load-shared-object #f)
(define fp
  (foreign-procedure "fabs" (float) float))

(display ff) (newline)
(pretty-print (expand/optimize '(foreign-procedure "fabs" (float) float)))
(display fp) (newline)

Output:

#<procedure ff at test.scm:501>
(let ([#{foreign-addr kdxue5k7vclsg80c1agdzhcra-0} (#2%$foreign-entry
                                                     "fabs")])
  (let ([#{p kdxue5k7vclsg80c1agdzhcra-1} ($foreign-procedure () "fabs"
                                            #{foreign-addr kdxue5k7vclsg80c1agdzhcra-0}
                                            (single-float) single-float)])
    (lambda (#{g0 kdxue5k7vclsg80c1agdzhcra-2})
      (if (#2%flonum? #{g0 kdxue5k7vclsg80c1agdzhcra-2})
          (#2%void)
          (let ([#{who kdxue5k7vclsg80c1agdzhcra-3} 'moi])
            (#2%$oops
              (if #{who kdxue5k7vclsg80c1agdzhcra-3}
                  #{who kdxue5k7vclsg80c1agdzhcra-3}
                  "fabs")
              "invalid foreign-procedure argument ~s"
              #{g0 kdxue5k7vclsg80c1agdzhcra-2})))
      (#{p kdxue5k7vclsg80c1agdzhcra-1}
        #{g0 kdxue5k7vclsg80c1agdzhcra-2}))))
#<procedure fp>

Expected: fp should also have a source location, since the foreign-procedure call also expands to a lambda that gets bound via define.
Geiser in emacs uses the source location of a procedure to support jumping to its definition, so not having that makes it annoying since I can't jump quickly to a symbol f that's been (define f (foreign-procedure ...))-ed.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions