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

JuliaLang / julia / #37474

pending completion
#37474

push

local

web-flow
irinterp: Allow setting all IR flags (#48993)

Currently, `IR_FLAG_NOTHROW` is the only flag that irinterp is allowed to
set on statements, under the assumption that in order for a call to
be irinterp-eligible, it must have been proven `:foldable`, thus `:effect_free`,
and thus `IR_FLAG_EFFECT_FREE` was assumed to have been set. That reasoning
was sound at the time this code was written, but have since introduced
`EFFECT_FREE_IF_INACCESSIBLEMEMONLY`, which breaks the reasoning that
an `:effect_free` inference for the whole function implies the flag on
every statement. As a result, we were failing to DCE otherwise dead
statements if the IR came from irinterp.

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

70258 of 82316 relevant lines covered (85.35%)

32461773.51 hits per line

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

22.62
/stdlib/LibGit2/src/oid.jl
1
# This file is a part of Julia. License is MIT: https://julialang.org/license
2

3
"""
4
    GitHash(ptr::Ptr{UInt8})
5

6
Construct a `GitHash` from a pointer to `UInt8` data containing the bytes of the
7
SHA-1 hash. The constructor throws an error if the pointer is null, i.e. equal to
8
`C_NULL`.
9
"""
10
function GitHash(ptr::Ptr{UInt8})
18✔
11
    if ptr == C_NULL
18✔
12
        throw(ArgumentError("NULL pointer passed to GitHash() constructor"))
×
13
    end
14
    ensure_initialized()
18✔
15
    oid_ptr = Ref(GitHash())
18✔
16
    @check ccall((:git_oid_fromraw, :libgit2), Cint,
18✔
17
                 (Ptr{GitHash}, Ptr{UInt8}), oid_ptr, ptr)
18
    return oid_ptr[]
18✔
19
end
20

21
"""
22
    GitHash(id::Vector{UInt8})
23

24
Construct a `GitHash` from a vector of $OID_RAWSZ bytes.
25
"""
26
function GitHash(id::Array{UInt8,1})
×
27
    if length(id) != OID_RAWSZ
×
28
        throw(ArgumentError("invalid raw buffer size"))
×
29
    end
30
    return GitHash(pointer(id))
×
31
end
32

33
"""
34
    GitHash(id::AbstractString)
35

36
Construct a `GitHash` from a string of $OID_HEXSZ hexadecimal digits.
37
"""
38
function GitHash(id::AbstractString)
×
39
    bstr = String(id)
×
40
    len = sizeof(bstr)
×
41
    if len < OID_HEXSZ
×
42
        throw(ArgumentError("Input string is too short, use `GitShortHash` for partial hashes"))
×
43
    end
44
    ensure_initialized()
×
45
    oid_ptr = Ref{GitHash}()
×
46
    @check ccall((:git_oid_fromstrn, :libgit2), Cint,
×
47
              (Ptr{GitHash}, Ptr{UInt8}, Csize_t), oid_ptr, bstr, len)
48
    return oid_ptr[]
×
49
end
50

51
"""
52
    GitShortHash(buf::Buffer)
53

54
Construct a `GitShortHash` from the data stored in the given [`Buffer`](@ref).
55
"""
56
function GitShortHash(buf::Buffer)
×
57
    ensure_initialized()
×
58
    oid_ptr = Ref{GitHash}()
×
59
    @check ccall((:git_oid_fromstrn, :libgit2), Cint,
×
60
              (Ptr{GitHash}, Ptr{UInt8}, Csize_t), oid_ptr, buf.ptr, buf.size)
61
    GitShortHash(oid_ptr[], buf.size)
×
62
end
63

64
"""
65
    GitShortHash(id::AbstractString)
66

67
Construct a `GitShortHash` from a string of at most $OID_HEXSZ hexadecimal digits.
68
"""
69
function GitShortHash(id::AbstractString)
×
70
    ensure_initialized()
×
71
    bstr = String(id)
×
72
    len = sizeof(bstr)
×
73
    oid_ptr = Ref{GitHash}()
×
74
    @check ccall((:git_oid_fromstrn, :libgit2), Cint,
×
75
              (Ptr{GitHash}, Ptr{UInt8}, Csize_t), oid_ptr, bstr, len)
76
    GitShortHash(oid_ptr[], len)
×
77
end
78

79
"""
80
    @githash_str -> AbstractGitHash
81

82
Construct a git hash object from the given string, returning a `GitShortHash` if
83
the string is shorter than $OID_HEXSZ hexadecimal digits, otherwise a `GitHash`.
84

85
# Examples
86
```jldoctest
87
julia> LibGit2.githash"d114feb74ce633"
88
GitShortHash("d114feb74ce633")
89

90
julia> LibGit2.githash"d114feb74ce63307afe878a5228ad014e0289a85"
91
GitHash("d114feb74ce63307afe878a5228ad014e0289a85")
92
```
93
"""
94
macro githash_str(id)
95
    bstr = String(id)
96
    if sizeof(bstr) < OID_HEXSZ
97
        GitShortHash(id)
98
    else
99
        GitHash(id)
100
    end
101
end
102

103

104
"""
105
    GitHash(ref::GitReference)
106

107
Get the identifier (`GitHash`) of the object referred to by the direct reference
108
`ref`. Note: this does not work for symbolic references; in such cases use
109
`GitHash(repo::GitRepo, ref_name::AbstractString)` instead.
110
"""
111
function GitHash(ref::GitReference)
18✔
112
    isempty(ref) && return GitHash()
18✔
113
    reftype(ref) != Consts.REF_OID && return GitHash()
18✔
114
    ensure_initialized()
18✔
115
    GC.@preserve ref begin
18✔
116
        oid_ptr = ccall((:git_reference_target, :libgit2), Ptr{UInt8}, (Ptr{Cvoid},), ref.ptr)
18✔
117
        oid_ptr == C_NULL && return GitHash()
18✔
118
        oid = GitHash(oid_ptr)
18✔
119
    end
120
    return oid
18✔
121
end
122

123

124
"""
125
    GitHash(repo::GitRepo, ref_name::AbstractString)
126

127
Get the identifier (`GitHash`) of the object referred to by reference specified by
128
`ref_name`.
129
"""
130
function GitHash(repo::GitRepo, ref_name::AbstractString)
×
131
    isempty(repo) && return GitHash()
×
132
    ensure_initialized()
×
133
    oid_ptr  = Ref(GitHash())
×
134
    @check ccall((:git_reference_name_to_id, :libgit2), Cint,
×
135
                    (Ptr{GitHash}, Ptr{Cvoid}, Cstring),
136
                     oid_ptr, repo.ptr, ref_name)
137
    return oid_ptr[]
×
138
end
139

140
"""
141
    GitHash(obj::GitObject)
142

143
Get the identifier (`GitHash`) of `obj`.
144
"""
145
function GitHash(obj::GitObject)
×
146
    ensure_initialized()
×
147
    GitHash(ccall((:git_object_id, :libgit2), Ptr{UInt8}, (Ptr{Cvoid},), obj.ptr))
×
148
end
149

150
==(obj1::GitObject, obj2::GitObject) = GitHash(obj1) == GitHash(obj2)
×
151

152
"""
153
    GitShortHash(obj::GitObject)
154

155
Get a shortened identifier (`GitShortHash`) of `obj`. The minimum length (in characters)
156
is determined by the `core.abbrev` config option, and will be of sufficient length to
157
unambiguously identify the object in the repository.
158
"""
159
function GitShortHash(obj::GitObject)
×
160
    ensure_initialized()
×
161
    buf_ref = Ref(Buffer())
×
162
    @check ccall((:git_object_short_id, :libgit2), Cint,
×
163
                 (Ptr{Buffer},Ptr{Cvoid}), buf_ref, obj.ptr)
164
    sid = GitShortHash(buf_ref[])
×
165
    free(buf_ref)
×
166
    return sid
×
167
end
168

169
"""
170
    raw(id::GitHash) -> Vector{UInt8}
171

172
Obtain the raw bytes of the [`GitHash`](@ref) as a vector of length $OID_RAWSZ.
173
"""
174
raw(id::GitHash) = collect(id.val)
×
175

176
function Base.print(io::IO, id::GitHash)
18✔
177
    for i in id.val
18✔
178
        print(io, string(i, base = 16, pad = 2))
360✔
179
    end
360✔
180
end
181
Base.string(id::GitShortHash) = string(id.hash)[1:id.len]
×
182

183
Base.show(io::IO, id::GitHash) = print(io, "GitHash(\"$(string(id))\")")
×
184
Base.show(io::IO, id::GitShortHash) = print(io, "GitShortHash(\"$(string(id))\")")
×
185

186
Base.hash(id::GitHash, h::UInt) = hash(id.val, h)
×
187

188
function Base.cmp(id1::GitHash, id2::GitHash)
×
189
    ensure_initialized()
×
190
    Int(ccall((:git_oid_cmp, :libgit2), Cint,
×
191
              (Ptr{GitHash}, Ptr{GitHash}),
192
              Ref(id1), Ref(id2)))
193
end
194
function Base.cmp(id1::GitShortHash, id2::GitShortHash)
×
195
    ensure_initialized()
×
196
    # shortened hashes appear at the beginning of the order, i.e.
197
    # 000 < 01 < 010 < 011 < 0112
198
    c = Int(ccall((:git_oid_ncmp, :libgit2), Cint,
×
199
                  (Ptr{GitHash}, Ptr{GitHash}, Csize_t),
200
                  Ref(id1.hash), Ref(id2.hash), min(id1.len, id2.len)))
201
    return c == 0 ? cmp(id1.len, id2.len) : c
×
202
end
203
Base.cmp(id1::GitHash, id2::GitShortHash) = cmp(GitShortHash(id1, OID_HEXSZ), id2)
×
204
Base.cmp(id1::GitShortHash, id2::GitHash) = cmp(id1, GitShortHash(id2, OID_HEXSZ))
×
205

206
==(id1::GitHash, id2::GitHash) = cmp(id1, id2) == 0
×
207
Base.isless(id1::AbstractGitHash, id2::AbstractGitHash)  = cmp(id1, id2) < 0
×
208

209
"""
210
    iszero(id::GitHash) -> Bool
211

212
Determine whether all hexadecimal digits of the given [`GitHash`](@ref) are zero.
213
"""
214
function iszero(id::GitHash)
×
215
    for i in 1:OID_RAWSZ
×
216
        id.val[i] != zero(UInt8) && return false
×
217
    end
×
218
    return true
×
219
end
220

221
Base.zero(::Type{GitHash}) = GitHash()
×
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