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

JuliaLang / julia / #37591

pending completion
#37591

push

local

web-flow
Allocation Profiler: Types for all allocations (#50337)

Pass the types to the allocator functions.

-------

Before this PR, we were missing the types for allocations in two cases:

1. allocations from codegen
2. allocations in `gc_managed_realloc_`

The second one is easy: those are always used for buffers, right?

For the first one: we extend the allocation functions called from
codegen, to take the type as a parameter, and set the tag there.

I kept the old interfaces around, since I think that they cannot be
removed due to supporting legacy code?

------

An example of the generated code:
```julia
  %ptls_field6 = getelementptr inbounds {}**, {}*** %4, i64 2
  %13 = bitcast {}*** %ptls_field6 to i8**
  %ptls_load78 = load i8*, i8** %13, align 8
  %box = call noalias nonnull dereferenceable(32) {}* @ijl_gc_pool_alloc_typed(i8* %ptls_load78, i32 1184, i32 32, i64 4366152144) #7
```

Fixes #43688.
Fixes #45268.

Co-authored-by: Valentin Churavy <vchuravy@users.noreply.github.com>

72755 of 84117 relevant lines covered (86.49%)

22738368.36 hits per line

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

86.24
/stdlib/Markdown/src/parse/util.jl
1
# This file is a part of Julia. License is MIT: https://julialang.org/license
2

3
macro dotimes(n, body)
4
    quote
5
        for i = 1:$(esc(n))
42,050✔
6
            $(esc(body))
23,665✔
7
        end
26,305✔
8
    end
9
end
10

11
const whitespace = " \t\r"
12

13
"""
14
Skip any leading whitespace. Returns io.
15
"""
16
function skipwhitespace(io::IO; newlines = true)
110,544✔
17
    while !eof(io) && (peek(io, Char) in whitespace || (newlines && peek(io) == UInt8('\n')))
138,777✔
18
        read(io, Char)
28,247✔
19
    end
28,247✔
20
    return io
55,272✔
21
end
22

23
"""
24
Skip any leading blank lines. Returns the number skipped.
25
"""
26
function skipblank(io::IO)
37,066✔
27
    start = position(io)
37,066✔
28
    i = 0
×
29
    for c in readeach(io, Char)
69,942✔
30
        c == '\n' && (start = position(io); i+=1; continue)
52,057✔
31
        c == '\r' && (start = position(io); i+=1; continue)
46,171✔
32
        c in whitespace || break
46,171✔
33
    end
31,624✔
34
    seek(io, start)
37,066✔
35
    return i
37,066✔
36
end
37

38
"""
39
Return true if the line contains only (and, unless allowempty,
40
at least one of) the characters given.
41
"""
42
function linecontains(io::IO, chars; allow_whitespace = true,
63,740✔
43
                                     eat = true,
44
                                     allowempty = false)
45
    start = position(io)
31,870✔
46
    l = readline(io)
31,870✔
47
    length(l) == 0 && return allowempty
31,870✔
48

49
    result = allowempty
×
50
    for c in l
41,203✔
51
        c in whitespace && (allow_whitespace ? continue : (result = false; break))
21,417✔
52
        c in chars && (result = true; continue)
20,601✔
53
        result = false; break
20,601✔
54
    end
1,628✔
55
    !(result && eat) && seek(io, start)
20,602✔
56
    return result
20,602✔
57
end
58

59
blankline(io::IO; eat = true) =
63,740✔
60
    linecontains(io, "",
61
                 allow_whitespace = true,
62
                 allowempty = true,
63
                 eat = eat)
64

65
"""
66
Test if the stream starts with the given string.
67
`eat` specifies whether to advance on success (true by default).
68
`padding` specifies whether leading whitespace should be ignored.
69
"""
70
function startswith(stream::IO, s::AbstractString; eat = true, padding = false, newlines = true)
633,456✔
71
    start = position(stream)
316,728✔
72
    padding && skipwhitespace(stream, newlines = newlines)
316,728✔
73
    result = true
×
74
    for char in s
633,456✔
75
        !eof(stream) && read(stream, Char) == char ||
346,441✔
76
            (result = false; break)
×
77
    end
89,296✔
78
    !(result && eat) && seek(stream, start)
316,728✔
79
    return result
316,728✔
80
end
81

82
function startswith(stream::IO, c::AbstractChar; eat = true)
429,641✔
83
    if !eof(stream) && peek(stream) == UInt8(c)
214,489✔
84
        eat && read(stream, Char)
43,204✔
85
        return true
43,204✔
86
    else
87
        return false
171,285✔
88
    end
89
end
90

91
function startswith(stream::IO, ss::Vector{<:AbstractString}; kws...)
×
92
    any(s->startswith(stream, s; kws...), ss)
×
93
end
94

95
function startswith(stream::IO, r::Regex; eat = true, padding = false)
109,650✔
96
    @assert Base.startswith(r.pattern, "^")
54,825✔
97
    start = position(stream)
54,825✔
98
    padding && skipwhitespace(stream)
54,825✔
99
    line = readline(stream)
54,825✔
100
    seek(stream, start)
54,825✔
101
    m = match(r, line)
54,825✔
102
    m === nothing && return ""
54,825✔
103
    eat && @dotimes length(m.match) read(stream, Char)
21,364✔
104
    return m.match
21,364✔
105
end
106

107
"""
108
Executes the block of code, and if the return value is `nothing`,
109
returns the stream to its initial position.
110
"""
111
function withstream(f, stream)
83,173✔
112
    pos = position(stream)
307,869✔
113
    result = f()
336,515✔
114
    (result ≡ nothing || result ≡ false) && seek(stream, pos)
307,869✔
115
    return result
307,869✔
116
end
117

118
"""
119
Consume the standard allowed markdown indent of
120
three spaces. Returns false if there are more than
121
three present.
122
"""
123
function eatindent(io::IO, n = 3)
×
124
    withstream(io) do
120,400✔
125
        m = 0
×
126
        while startswith(io, ' ') m += 1 end
146,117✔
127
        return m <= n
60,200✔
128
    end
129
end
130

131
"""
132
Read the stream until startswith(stream, delim)
133
The delimiter is consumed but not included.
134
Returns nothing and resets the stream if delim is
135
not found.
136
"""
137
function readuntil(stream::IO, delimiter; newlines = false, match = nothing)
26,422✔
138
    withstream(stream) do
26,258✔
139
        buffer = IOBuffer()
26,258✔
140
        count = 0
128✔
141
        while !eof(stream)
246,523✔
142
            if startswith(stream, delimiter)
247,055✔
143
                if count == 0
6,506✔
144
                    return String(take!(buffer))
26,174✔
145
                else
146
                    count -= 1
42✔
147
                    write(buffer, delimiter)
42✔
148
                    continue
42✔
149
                end
150
            end
151
            char = read(stream, Char)
220,223✔
152
            char == match && (count += 1)
62,040✔
153
            !newlines && char == '\n' && break
220,223✔
154
            write(buffer, char)
220,223✔
155
        end
220,349✔
156
    end
157
end
158

159
# TODO: refactor this. If we're going to assume
160
# the delimiter is a single character + a minimum
161
# repeat we may as well just pass that into the
162
# function.
163

164
"""
165
Parse a symmetrical delimiter which wraps words.
166
i.e. `*word word*` but not `*word * word`.
167
`repeat` specifies whether the delimiter can be repeated.
168
Escaped delimiters are not yet supported.
169
"""
170
function parse_inline_wrapper(stream::IO, delimiter::AbstractString; rep = false)
23,630✔
171
    delimiter, nmin = string(delimiter[1]), length(delimiter)
23,630✔
172
    withstream(stream) do
11,815✔
173
        if position(stream) >= 1
11,815✔
174
            # check the previous byte isn't a delimiter
175
            skip(stream, -1)
6,490✔
176
            (read(stream, Char) in delimiter) && return nothing
6,490✔
177
        end
178
        n = nmin
11,815✔
179
        startswith(stream, delimiter^n) || return nothing
23,353✔
180
        while startswith(stream, delimiter); n += 1; end
277✔
181
        !rep && n > nmin && return nothing
277✔
182
        !eof(stream) && peek(stream, Char) in whitespace && return nothing
277✔
183

184
        buffer = IOBuffer()
249✔
185
        for char in readeach(stream, Char)
498✔
186
            write(buffer, char)
2,607✔
187
            if !(char in whitespace || char == '\n' || char in delimiter) && startswith(stream, delimiter^n)
5,004✔
188
                trailing = 0
×
189
                while startswith(stream, delimiter); trailing += 1; end
187✔
190
                trailing == 0 && return String(take!(buffer))
187✔
191
                write(buffer, delimiter ^ (n + trailing))
×
192
            end
193
        end
2,420✔
194
    end
195
end
196

197
function showrest(io::IO)
×
198
    start = position(io)
×
199
    show(read(io, String))
×
200
    println()
×
201
    seek(io, start)
×
202
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