• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

JuliaLang / julia / #37937

17 Oct 2024 09:19PM UTC coverage: 87.661% (-0.1%) from 87.779%
#37937

push

local

web-flow
Fix triu/tril for partly initialized matrices (#55312)

This fixes
```julia
julia> using LinearAlgebra, StaticArrays

julia> M = Matrix{BigInt}(undef, 2, 2); M[1,1] = M[2,2] = M[1,2] = 3;

julia> S = SizedMatrix{2,2}(M)
2×2 SizedMatrix{2, 2, BigInt, 2, Matrix{BigInt}} with indices SOneTo(2)×SOneTo(2):
   3     3
 #undef  3

julia> triu(S)
ERROR: UndefRefError: access to undefined reference
Stacktrace:
 [1] getindex
   @ ./essentials.jl:907 [inlined]
 [2] getindex
   @ ~/.julia/packages/StaticArrays/MSJcA/src/SizedArray.jl:92 [inlined]
 [3] copyto_unaliased!
   @ ./abstractarray.jl:1086 [inlined]
 [4] copyto!(dest::SizedMatrix{2, 2, BigInt, 2, Matrix{BigInt}}, src::SizedMatrix{2, 2, BigInt, 2, Matrix{BigInt}})
   @ Base ./abstractarray.jl:1066
 [5] copymutable
   @ ./abstractarray.jl:1200 [inlined]
 [6] triu(M::SizedMatrix{2, 2, BigInt, 2, Matrix{BigInt}})
   @ LinearAlgebra ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/LinearAlgebra/src/generic.jl:413
 [7] top-level scope
   @ REPL[11]:1
```
After this PR:
```julia
julia> triu(S)
2×2 SizedMatrix{2, 2, BigInt, 2, Matrix{BigInt}} with indices SOneTo(2)×SOneTo(2):
 3  3
 0  3
```
Only the indices that need to be copied are accessed, and the others are
written to without being read.

20 of 20 new or added lines in 1 file covered. (100.0%)

573 existing lines in 13 files now uncovered.

79111 of 90247 relevant lines covered (87.66%)

17057704.24 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/stdlib/REPL/src/Pkg_beforeload.jl
1
## Pkg stuff needed before Pkg has loaded
2

3
const Pkg_pkgid = Base.PkgId(Base.UUID("44cfe95a-1eb2-52ea-b672-e2afdf69b78f"), "Pkg")
4

UNCOV
5
function load_pkg()
×
6
    REPLExt = Base.require_stdlib(Pkg_pkgid, "REPLExt")
×
7
    @lock Base.require_lock begin
×
8
        # require_stdlib does not guarantee that the `__init__` of the package is done when loading is done async
9
        # but we need to wait for the repl mode to be set up
UNCOV
10
        lock = get(Base.package_locks, Base.PkgId(REPLExt), nothing)
×
11
        lock !== nothing && wait(lock[2])
×
12
    end
13
    return REPLExt
×
14
end
15

16
## Below here copied/tweaked from Pkg Types.jl so that the dummy Pkg prompt
17
# can populate the env correctly before Pkg loads
18

UNCOV
19
function safe_realpath(path)
×
20
    isempty(path) && return path
×
21
    if ispath(path)
×
22
        try
×
23
            return realpath(path)
×
24
        catch
UNCOV
25
            return path
×
26
        end
27
    end
UNCOV
28
    a, b = splitdir(path)
×
29
    return joinpath(safe_realpath(a), b)
×
30
end
31

UNCOV
32
function find_project_file(env::Union{Nothing,String}=nothing)
×
33
    project_file = nothing
×
34
    if env isa Nothing
×
35
        project_file = Base.active_project()
×
36
        project_file === nothing && return nothing # in the Pkg version these are pkgerrors
×
37
    elseif startswith(env, '@')
×
38
        project_file = Base.load_path_expand(env)
×
39
        project_file === nothing && return nothing
×
40
    elseif env isa String
×
41
        if isdir(env)
×
42
            isempty(readdir(env)) || return nothing
×
43
            project_file = joinpath(env, Base.project_names[end])
×
44
        else
UNCOV
45
            project_file = endswith(env, ".toml") ? abspath(env) :
×
46
                abspath(env, Base.project_names[end])
47
        end
48
    end
UNCOV
49
    @assert project_file isa String &&
×
50
        (isfile(project_file) || !ispath(project_file) ||
51
         isdir(project_file) && isempty(readdir(project_file)))
UNCOV
52
    return safe_realpath(project_file)
×
53
end
54

UNCOV
55
function find_root_base_project(start_project::String)
×
56
    project_file = start_project
×
57
    while true
×
58
        base_project_file = Base.base_project(project_file)
×
59
        base_project_file === nothing && return project_file
×
60
        project_file = base_project_file
×
61
    end
×
62
end
63

UNCOV
64
function relative_project_path(project_file::String, path::String)
×
65
    # compute path relative the project
66
    # realpath needed to expand symlinks before taking the relative path
UNCOV
67
    return relpath(safe_realpath(abspath(path)), safe_realpath(dirname(project_file)))
×
68
end
69

UNCOV
70
function projname(project_file::String)
×
71
    if isfile(project_file)
×
72
        name = try
×
73
            # The `nothing` here means that this TOML parser does not return proper Dates.jl
74
            # objects - but that's OK since we're just checking the name here.
UNCOV
75
            p = Base.TOML.Parser{nothing}()
×
76
            Base.TOML.reinit!(p, read(project_file, String); filepath=project_file)
×
77
            proj = Base.TOML.parse(p)
×
78
            get(proj, "name", nothing)
×
79
        catch
UNCOV
80
            nothing
×
81
        end
82
    else
UNCOV
83
        name = nothing
×
84
    end
UNCOV
85
    if name === nothing
×
86
        name = basename(dirname(project_file))
×
87
    end
UNCOV
88
    for depot in Base.DEPOT_PATH
×
89
        envdir = joinpath(depot, "environments")
×
90
        if startswith(safe_realpath(project_file), safe_realpath(envdir))
×
91
            return "@" * name
×
92
        end
UNCOV
93
    end
×
94
    return name
×
95
end
96

97
prev_project_file = nothing
98
prev_project_timestamp = nothing
99
prev_prefix = ""
100

UNCOV
101
function Pkg_promptf()
×
102
    global prev_project_timestamp, prev_prefix, prev_project_file
×
103
    project_file = find_project_file()
×
104
    prefix = ""
×
105
    if project_file !== nothing
×
106
        if prev_project_file == project_file && prev_project_timestamp == mtime(project_file)
×
107
            prefix = prev_prefix
×
108
        else
UNCOV
109
            project_name = projname(project_file)
×
110
            if project_name !== nothing
×
111
                root = find_root_base_project(project_file)
×
112
                rootname = projname(root)
×
113
                if root !== project_file
×
114
                    path_prefix = "/" * dirname(relative_project_path(root, project_file))
×
115
                else
UNCOV
116
                    path_prefix = ""
×
117
                end
UNCOV
118
                if textwidth(rootname) > 30
×
119
                    rootname = first(rootname, 27) * "..."
×
120
                end
UNCOV
121
                prefix = "($(rootname)$(path_prefix)) "
×
122
                prev_prefix = prefix
×
123
                prev_project_timestamp = mtime(project_file)
×
124
                prev_project_file = project_file
×
125
            end
126
        end
127
    end
128
    # Note no handling of Pkg.offline, as the Pkg version does here
UNCOV
129
    return "$(prefix)$(PKG_PROMPT)"
×
130
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc