Skip to content

Random: show method for MersenneTwister: invalidation resistance #57913

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

Merged

Conversation

nsajko
Copy link
Contributor

@nsajko nsajko commented Mar 27, 2025

Avoid using or constructing the vector with nonconcrete element type.

Should make the sysimage more resistant to method invalidation.

Avoid using or constructing the vector with nonconcrete element type.

Should make the sysimage more resistant to method invalidation.
@nsajko nsajko added randomness Random number generation and the Random stdlib display and printing Aesthetics and correctness of printed representations of objects. invalidations labels Mar 27, 2025
Copy link
Member

@topolarity topolarity left a comment

Choose a reason for hiding this comment

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

Sounds like a good change to me - printing immediately instead of accumulating in a temporary vector seems right

Copy link
Member

@topolarity topolarity left a comment

Choose a reason for hiding this comment

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

I think using ", " instead of sep might also be clearer, but it's a matter of taste at that point

@nsajko
Copy link
Contributor Author

nsajko commented Mar 28, 2025

The PR prevents these method invalidations:

{   
    "method_instance": {
        "method": "join(io::IO, iterator, delim) @ Base strings/io.jl:342",
        "method_instance": "MethodInstance for join(::IOBuffer, ::Vector{Integer}, ::String)"
    },
    "children": [
        {   
            "method_instance": {
                "method": "show(io::IO, rng::Random.MersenneTwister) @ Random ~/tmp/jl/jl/nightly/share/julia/stdlib/v1.13/Random/src/RNGs.jl:143",
                "method_instance": "MethodInstance for show(::IOBuffer, ::Random.MersenneTwister)"
            },
            "children": [
                {   
                    "method_instance": {
                        "method": "print(io::IO, x) @ Base strings/io.jl:32",
                        "method_instance": "MethodInstance for print(::IOBuffer, ::Random.MersenneTwister)"
                    },
                    "children": [
                        {   
                            "method_instance": {
                                "method": "print_to_string(xs...) @ Base strings/io.jl:136",
                                "method_instance": "MethodInstance for Base.print_to_string(::String, ::Random.MersenneTwister, ::String)"
                            },
                            "children": [
                                {   
                                    "method_instance": {
                                        "method": "string(xs...) @ Base strings/io.jl:189",
                                        "method_instance": "MethodInstance for string(::String, ::Random.MersenneTwister, ::String)"
                                    },
                                    "children": [
                                        {   
                                            "method_instance": {
                                                "method": "_advance_n!(r::Random.MersenneTwister, n::Int64, work::Vector{Float64}) @ Random ~/tmp/jl/jl/nightly/share/julia/stdlib/v1.13/Random/src/RNGs.jl:783",
                                                "method_instance": "MethodInstance for Random._advance_n!(::Random.MersenneTwister, ::Int64, ::Vector{Float64})"
                                            },
                                            "children": [
                                            ]
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                }
            ]
        }
    ]
}

@topolarity topolarity merged commit 8e03cb1 into JuliaLang:master Mar 28, 2025
7 checks passed
@topolarity
Copy link
Member

Thanks @nsajko !

@nsajko nsajko deleted the invalidations_show_MersenneTwister branch March 28, 2025 11:35
@nsajko nsajko added backport 1.10 Change should be backported to the 1.10 release backport 1.11 Change should be backported to release-1.11 backport 1.12 Change should be backported to release-1.12 labels Mar 28, 2025
KristofferC pushed a commit that referenced this pull request Mar 31, 2025
#57913)

Avoid using or constructing the vector with nonconcrete element type.

Should make the sysimage more resistant to method invalidation.

(cherry picked from commit 8e03cb1)
@KristofferC KristofferC mentioned this pull request Mar 31, 2025
36 tasks
KristofferC pushed a commit that referenced this pull request Mar 31, 2025
#57913)

Avoid using or constructing the vector with nonconcrete element type.

Should make the sysimage more resistant to method invalidation.

(cherry picked from commit 8e03cb1)
@KristofferC KristofferC mentioned this pull request Mar 31, 2025
71 tasks
KristofferC pushed a commit that referenced this pull request Mar 31, 2025
#57913)

Avoid using or constructing the vector with nonconcrete element type.

Should make the sysimage more resistant to method invalidation.

(cherry picked from commit 8e03cb1)
KristofferC pushed a commit that referenced this pull request Mar 31, 2025
#57913)

Avoid using or constructing the vector with nonconcrete element type.

Should make the sysimage more resistant to method invalidation.

(cherry picked from commit 8e03cb1)
KristofferC pushed a commit that referenced this pull request Mar 31, 2025
#57913)

Avoid using or constructing the vector with nonconcrete element type.

Should make the sysimage more resistant to method invalidation.

(cherry picked from commit 8e03cb1)
@KristofferC KristofferC mentioned this pull request Apr 4, 2025
51 tasks
@KristofferC KristofferC removed backport 1.12 Change should be backported to release-1.12 backport 1.11 Change should be backported to release-1.11 labels Apr 9, 2025
@KristofferC KristofferC mentioned this pull request Jun 4, 2025
75 tasks
KristofferC pushed a commit that referenced this pull request Jun 5, 2025
#57913)

Avoid using or constructing the vector with nonconcrete element type.

Should make the sysimage more resistant to method invalidation.

(cherry picked from commit 8e03cb1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 1.10 Change should be backported to the 1.10 release display and printing Aesthetics and correctness of printed representations of objects. invalidations randomness Random number generation and the Random stdlib
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants