On Mon, Dec 21, 2020 at 7:30 PM Robby Findler <[email protected]>
wrote:

> Is Typed Racket able to prove that your use of unsafe accessors is
> actually safe?
>

On a similar note, my understanding is that, even without types, in a
program like this:
#lang racket
(struct cell (val))
(λ (x)
  (if (cell? x)
      (cell-val x)
      ...))
the compiler can optimize the use of `cell-val` guarded by `cell?` to omit
the redundant check. I think the optimized version should be as good as
`unsafe-struct-ref`.

If that's the case, the only extra invariant for `unsafe-struct*-ref` is
that it does not work on impersonators (including chaperones, IIUC). If you
need the extra performance, I think you can get it safely by declaring your
structs as `#:authentic` (or equivalently adding `prop:authentic`), which
will cause the struct types involved not to support impersonators:
`impersonate-struct` and similar functions will raise exceptions. On the
other hand, if you need to support impersonators, then it really is unsafe
to use `unsafe-struct*-ref`.

-Philip

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/010001768888c2ba-c84b6b21-d30d-488f-b4ad-43878e96f06d-000000%40email.amazonses.com.

Reply via email to