Skip to content
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

flvector? and fxvector? are missing equal-always? support #4983

Closed
rocketnia opened this issue Apr 25, 2024 · 6 comments · Fixed by #4984
Closed

flvector? and fxvector? are missing equal-always? support #4983

rocketnia opened this issue Apr 25, 2024 · 6 comments · Fixed by #4984

Comments

@rocketnia
Copy link
Contributor

What version of Racket are you using?
8.12 [cs]

What program did you run?

Welcome to Racket v8.12 [cs].
> (require racket/flonum)
> (define foo (flvector 1.0 2.0 3.0))
> (define bar (flvector 1.0 2.0 3.0))
> foo
(flvector 1.0 2.0 3.0)
> bar
(flvector 1.0 2.0 3.0)
> (equal-always? foo bar)
#t
> (flvector-set! foo 1 20.0)
> foo
(flvector 1.0 20.0 3.0)
> bar
(flvector 1.0 2.0 3.0)
> (equal-always? foo bar)
#f

And the same thing for fxvectors:

> (require racket/fixnum)
> (define bar (fxvector 1 2 3))
> (define foo (fxvector 1 2 3))
> foo
(fxvector 1 2 3)
> bar
(fxvector 1 2 3)
> (equal-always? foo bar)
#t
> (fxvector-set! foo 1 20)
> foo
(fxvector 1 20 3)
> bar
(fxvector 1 2 3)
> (equal-always? foo bar)
#f

What should have happened?

Generally, for types that are defined with attention to equal-always? support, the result of equal-always? doesn't vary when a value is mutated. Since flvectors and fxvectors are mutable, they should only be equal-always? if they're eq?, similarly to mutable strings or vectors.

Alternatively, some mutation operations could be considered to be part of an unsafe API, like unsafe-set-immutable-car!. If that's what flvector-set! and fxvector-set! are considered to be, the present behavior may be correct. But that's not the impression I get from the documentation; I think these were simply types whose equality behavior was overlooked when equal-always? was introduced.

@usaoc
Copy link
Contributor

usaoc commented Apr 26, 2024

On top of this: extflonum vectors (I think) and stencil vectors.

@AlexKnauth
Copy link
Member

I think this is because it's falling back on Chez Scheme's flvector and fxvector equality.

Perhaps it shouldn't fall back on that when the mode is chaperone-of? or equal-always?.

@AlexKnauth
Copy link
Member

I started a branch to work on this here:
https://github.com/AlexKnauth/racket/tree/equal-always-flvector-fxvector

I'll want to add tests before I make it a full PR though.

@AlexKnauth
Copy link
Member

I've made a PR here:
#4984

@AlexKnauth
Copy link
Member

AlexKnauth commented Apr 26, 2024

@usaoc

On top of this: extflonum vectors (I think) and stencil vectors.

Stencil vectors are fixed in #4984, but I can't test whether extflvectors are broken or not because I get "extflvector: unsupported on this platform". What would be needed to test that?

@mflatt
Copy link
Member

mflatt commented Apr 26, 2024

Extflvectors are supported only on x86/x86_64 BC.

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

Successfully merging a pull request may close this issue.

4 participants