invalid memory error from parameter with contracted guard

23 views
Skip to first unread message

David Storrs

unread,
Jun 23, 2021, 10:31:08 PM6/23/21
to Racket Users
I'm seeing an "invalid memory reference.  Some debugging context lost" error when using a parameter that has a guard function AND the guard function is user-defined AND the guard function has a contract on it.  What is the right place to file this aside from the list?

Demonstration:

#lang racket/base

(require racket/contract)

(define p1 (make-parameter ""))
(displayln "before set p1")
(p1 "ok")
(displayln "before read p1")
(p1)

(define/contract p2 (parameter/c string?) (make-parameter ""))
(displayln "before set p2")
(p2 "ok")
(displayln "before read p2")
(p2)


(define/contract p3 (parameter/c string? integer?) (make-parameter "7" string->number ))
(displayln "before set p3")
(p3 "8")
(displayln "before read p3")
(p3)

(define (uncontracted-string->number v)
  (string->number v))

(define/contract (contracted-string->number v)
  (-> string? number?)
  (string->number v))

(define/contract p4  (parameter/c string? integer?)  (make-parameter "7" uncontracted-string->number))
(displayln "before set p4")
(p4 "8")
(displayln "before read p4")
(p4)

(define/contract p5  (parameter/c string? integer?)  (make-parameter "7" contracted-string->number))
(displayln "before set p5")
(p5 "8")
(displayln "before read p5")
(p5) ; invalid memory reference.  Some debugging context lost                                      






Gustavo Massaccesi

unread,
Jun 23, 2021, 11:04:44 PM6/23/21
to David Storrs, Racket Users
The list is fine, but sometimes messages are forgotten because it's difficult to track them.

If you have a GitHub account, it's better to post is as an issue in https://github.com/racket/racket

Gustavo


--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/CAE8gKoegLAOk9mHjKRNAJniki_6DHXJeOKcjPFa75vPkJqemjw%40mail.gmail.com.

Matthew Flatt

unread,
Jun 23, 2021, 11:53:50 PM6/23/21
to David Storrs, Racket Users
Hi David,

Thanks for the report! This is fixed for the next release and in
the current snapshots.

The repair was commit

cb959879de21406571fb0127ded88c54e171c0eb

See also https://github.com/racket/racket/issues/3865


Matthew

David Storrs

unread,
Jun 24, 2021, 9:55:53 AM6/24/21
to Matthew Flatt, Racket Users
Great! You're the best, Matt.  What was the issue, if it's simple enough to explain?

Matthew Flatt

unread,
Jun 24, 2021, 10:04:09 AM6/24/21
to David Storrs, Racket Users
Procedures with contracts are usually implemented by structs that have
`prop:procedure`. Those applicable structs are not procedures from Chez
Scheme's perspective. So, in the "Rumble" layer that bridges Chez
Scheme and Racket, care must be taken to use a special `|#%app|` form
instead of direct function application when the function to call might
be from the Racket layer and implemented as an applicable struct.

Parameters are implemented in the Rumble layer, but applying a
parameter's guard procedure didn't use `|#%app|` as it should have. The
repair was to add `|#%app|`.

David Storrs

unread,
Jun 24, 2021, 12:00:36 PM6/24/21
to Matthew Flatt, Racket Users
Got it. Thank you.
Reply all
Reply to author
Forward
0 new messages