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

add immutable-vector, immutable-vector-copy, etc. #789

Merged
merged 10 commits into from
Jan 24, 2024
Merged

Conversation

mflatt
Copy link
Contributor

@mflatt mflatt commented Jan 6, 2024

Based on a suggestion and initial work from @owaddell, extract the immutable-vector addition from #596, and then add immutable-vector-copy and friends. The motivation for the additions is the same as for vector-copy and company: to implement persistent data structures, but where you want to enforce immutability and maybe enable optimizations.

The changes include cp0 rules to combine vector-construction operations, such as turning (vector->immutable-vector (vector-append (vector x y) '#(3))) into (immutable-vector x y 3).

It turns out that (immutable-vector-copy x) and (immutable-vector-append x) are both equivalent to (vector->immutable-vector x). This PR doesn't try to prune the API, although it's possible that we would have left out vector->immutable-vector if immutable-vector-copy existed in the first place.

Copy link
Contributor

@burgerrg burgerrg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These procedures make immutable vectors much easier to use, thanks!

@owaddell
Copy link
Contributor

owaddell commented Jan 8, 2024

I'd like to extend the inline handler for vector-append and immutable-vector-append slightly to handle the following:

(define (expand-segments segments)
  (let ([n (vector-length segments)])
    (immutable-vector-append segments (make-vector n #f))))

Right now cptypes doesn't recognize that n will be a safe argument for make-vector, so it doesn't switch to #3%make-vector. @gus-massa are you interested in helping refine cptypes to handle this?

Current work-in-progress patch to cpprims.ss: patch.txt

@mflatt
Copy link
Contributor Author

mflatt commented Jan 13, 2024

This PR now pulls in @owaddell's improvements. There's no cptypes changes, yet, and those might be best considered in a new PR.

csug/objects.stex Outdated Show resolved Hide resolved
csug/objects.stex Outdated Show resolved Hide resolved
@mflatt
Copy link
Contributor Author

mflatt commented Jan 20, 2024

More improvements from @owaddell now added.

owaddell-beckman and others added 10 commits January 24, 2024 11:56
(but edited by mflatt to sync with cptypes and such)
Includes cp0 rules to combine vector-construction operations,
such as `(vector->immutable-vector (vector-append (vector x y) '#(3)))`
to `(immutable-vector x y 3)`.
extend cpprim slightly to handle
(immutable-vector-append vec1 (make-vector n e)) and
(immutable-vector-append (make-vector n e) vec1)
@mflatt mflatt merged commit c081296 into cisco:main Jan 24, 2024
13 checks passed
mflatt added a commit to mflatt/ChezScheme that referenced this pull request Jan 24, 2024
A follow-up to c081296, this commit adjusts the cp0 change to
prefer an existing case instead of the new one. This order still
passes the new test, it passes old ones with a small adjustment, and
it passes Racket tests that are similar to "cp0.ms" tests.

Meanwhile, c081296 should have noted the PR (cisco#789) it squashes and
some author information that was lost in the squash:
Co-authored-by: R. Kent Dybvig <dyb@scheme.com>
mflatt pushed a commit to mflatt/ChezScheme that referenced this pull request Jan 25, 2024
A follow-up to c081296, this commit adjusts the cp0 change to avoid
skipping the variable-dropping rewrite when the `begin` rotation
applies. This combination passes the new test, passes old tests with
small adjustments, and allows Racket to pass some tests that are
similar to "cp0.ms" tests.

Meanwhile, c081296 should have noted the PR (cisco#789) it squashes and
some author information that was lost in the squash:
Co-authored-by: R. Kent Dybvig <dyb@scheme.com>
mflatt added a commit that referenced this pull request Jan 31, 2024
A follow-up to c081296, this commit adjusts the cp0 change to avoid
skipping the variable-dropping rewrite when the `begin` rotation
applies. This combination passes the new test, passes old tests with
small adjustments, and allows Racket to pass some tests that are
similar to "cp0.ms" tests.

Meanwhile, c081296 should have noted the PR (#789) it squashes and
some author information that was lost in the squash:
Co-authored-by: R. Kent Dybvig <dyb@scheme.com>

Co-authored-by: Oscar Waddell <owaddell@beckman.com>
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 this pull request may close these issues.

4 participants