Skip to content

Commit 87d4c8b

Browse files
authored
Test: prune old LA based on ENV variable (#1335)
This PR prunes the old `LinearAlgebra` module based on an environment variable that is set in `.ci/run_tests.jl`. Hopefully, this would mean that tests that are being run without this environment variable would run as expected without precompilation issues. The goal of this PR is to ensure that when julia is being built with the master branch of `LinearAlgebra`, the tests would work without the need for pruning (i.e., we want to fix the test failures in JuliaLang/julia#58242). This would also mean that to run the tests locally, one would need to set the `JULIA_PRUNE_OLD_LA` environment variable to `true`.
1 parent ea8e858 commit 87d4c8b

File tree

5 files changed

+104
-60
lines changed

5 files changed

+104
-60
lines changed

.ci/run_tests.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@ end
66

77
proj = abspath(joinpath(@__DIR__, ".."))
88
cmd = """Base.runtests(["LinearAlgebra"]; propagate_project=true, ncores=$ncores)"""
9-
withenv("JULIA_NUM_THREADS" => 1) do
10-
run(`$(Base.julia_cmd()) --project=$proj --compiled-modules=existing -e $cmd`)
11-
end
9+
run(addenv(`$(Base.julia_cmd()) --project=$proj --compiled-modules=existing -e $cmd`,
10+
"JULIA_NUM_THREADS" => 1, "JULIA_PRUNE_OLD_LA" => true))

README.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,37 @@ This package performs some type piracy and is also included in the sysimage, whi
3737
To use a development version of this package, you can choose one of the following methods:
3838

3939
1. **Change the UUID in the project file and load the package:**
40-
This approach will produce warnings and may lead to method ambiguities between the development version and the one in the sysimage, but it can be used for basic experimentation.
40+
41+
Change the UUID line in `Project.toml` as
42+
```diff
43+
- uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
44+
+ uuid = "27e2e46d-f89d-539d-b4ee-838fcccc9c8e"
45+
```
46+
47+
Start `julia` as
48+
```console
49+
JULIA_PRUNE_OLD_LA=true julia +nightly --compiled-modules=existing --project
50+
```
51+
where it is assumed that one is already within the `LinearAlgebra` directory (otherwise, adjust
52+
the project path accordingly). The `julia +nightly` command above assumes that `juliaup` is being used
53+
to launch `julia`, but one may substitute this with the path to the julia executable.
54+
55+
Within the `julia` session, load the `LinearAlgebra` module after pruning the one in the sysimage. This may be done as
56+
```julia
57+
include("test/prune_old_LA.jl") && using LinearAlgebra
58+
```
59+
60+
Note that loading the test files in the REPL will automatically carry out the pruning to ensure that the development version of the package is used in the tests.
61+
62+
If you are contributing to the repo using this method, it may be convenient to ignore the local changes to `Project.toml` by running
63+
```console
64+
git update-index --skip-worktree Project.toml
65+
```
4166

4267
2. **Build Julia with the custom `LinearAlgebra` commit:**
43-
Modify the commit in `stdlib/LinearAlgebra.version` and build Julia.
68+
69+
Modify the commit in [`stdlib/LinearAlgebra.version`](https://github.com/JuliaLang/julia/blob/master/stdlib/LinearAlgebra.version) and build Julia. This requires one to push the development branch
70+
to `GitHub` or an equivalent platform.
4471

4572
3. **Build a custom sysimage with the new `LinearAlgebra`:**
4673
- Install `PackageCompiler`.

docs/make.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
include("../test/prune_old_LA.jl")
1+
withenv("JULIA_PRUNE_OLD_LA" => "true") do
2+
include("../test/prune_old_LA.jl")
3+
end
24

35
using LinearAlgebra
46
using Documenter: DocMeta, makedocs, deploydocs, HTML

test/bitarray.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# This file is a part of Julia. License is MIT: https://julialang.org/license
2+
3+
module TestBitArray
4+
15
isdefined(Main, :pruned_old_LA) || @eval Main include("prune_old_LA.jl")
26

37
using LinearAlgebra, Test, Random
@@ -95,3 +99,5 @@ b2 = bitrand(v1)
9599

96100
b1 = bitrand(n1, n1)
97101
@check_bit_operation diag(b1)
102+
103+
end # module

test/prune_old_LA.jl

Lines changed: 64 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,58 @@
1-
methods_to_delete =
2-
[
3-
:adjoint
4-
:transpose
5-
:inv
6-
:literal_pow
7-
:\
8-
:/
9-
:isapprox
10-
:copyto!
11-
:*
12-
:muladd
13-
:copyto!
14-
:isone
15-
:kron!
16-
:kron
17-
:^
18-
:exp
19-
:cis
20-
:log
21-
:sqrt
22-
:cbrt
23-
:inv
24-
:cos
25-
:sin
26-
:sincos
27-
:tan
28-
:cosh
29-
:sinh
30-
:tanh
31-
:acos
32-
:asin
33-
:atan
34-
:acosh
35-
:asinh
36-
:atanh
37-
:sec
38-
:sech
39-
:csc
40-
:csch
41-
:cot
42-
:coth
43-
:asec
44-
:asech
45-
:acsc
46-
:acot
47-
:acoth
48-
:acsch
49-
]
50-
511
let
52-
LA = get(Base.loaded_modules, Base.PkgId(Base.UUID("37e2e46d-f89d-539d-b4ee-838fcccc9c8e"), "LinearAlgebra"), nothing)
53-
if LA !== nothing
2+
methods_to_delete =
3+
[
4+
:adjoint
5+
:transpose
6+
:inv
7+
:literal_pow
8+
:\
9+
:/
10+
:isapprox
11+
:copyto!
12+
:*
13+
:muladd
14+
:copyto!
15+
:isone
16+
:kron!
17+
:kron
18+
:^
19+
:exp
20+
:cis
21+
:log
22+
:sqrt
23+
:cbrt
24+
:inv
25+
:cos
26+
:sin
27+
:sincos
28+
:tan
29+
:cosh
30+
:sinh
31+
:tanh
32+
:acos
33+
:asin
34+
:atan
35+
:acosh
36+
:asinh
37+
:atanh
38+
:sec
39+
:sech
40+
:csc
41+
:csch
42+
:cot
43+
:coth
44+
:asec
45+
:asech
46+
:acsc
47+
:acot
48+
:acoth
49+
:acsch
50+
]
51+
52+
prune_old_LA = parse(Bool, get(ENV, "JULIA_PRUNE_OLD_LA", "false"))
53+
LinalgSysImg = Base.PkgId(Base.UUID("37e2e46d-f89d-539d-b4ee-838fcccc9c8e"), "LinearAlgebra")
54+
LA = get(Base.loaded_modules, LinalgSysImg, nothing)
55+
if LA !== nothing && prune_old_LA
5456
@assert hasmethod(*, Tuple{Matrix{Float64}, Matrix{Float64}})
5557
for methss in methods_to_delete
5658
meths = getglobal(Base, methss)
@@ -61,9 +63,17 @@ let
6163
end
6264
end
6365
end
64-
Base.unreference_module(Base.PkgId(Base.UUID("37e2e46d-f89d-539d-b4ee-838fcccc9c8e"), "LinearAlgebra"))
6566
end
6667

67-
@assert !hasmethod(*, Tuple{Matrix{Float64}, Matrix{Float64}})
68+
# check in a separate block to ensure that the latest world age is used
69+
let
70+
prune_old_LA = parse(Bool, get(ENV, "JULIA_PRUNE_OLD_LA", "false"))
71+
LinalgSysImg = Base.PkgId(Base.UUID("37e2e46d-f89d-539d-b4ee-838fcccc9c8e"), "LinearAlgebra")
72+
LA = get(Base.loaded_modules, LinalgSysImg, nothing)
73+
if LA !== nothing && prune_old_LA
74+
@assert !hasmethod(*, Tuple{Matrix{Float64}, Matrix{Float64}})
75+
end
76+
prune_old_LA && Base.unreference_module(LinalgSysImg)
77+
end
6878

6979
pruned_old_LA = true

0 commit comments

Comments
 (0)