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

JuliaLang / julia / #38002

06 Feb 2025 06:14AM UTC coverage: 20.322% (-2.4%) from 22.722%
#38002

push

local

web-flow
bpart: Fully switch to partitioned semantics (#57253)

This is the final PR in the binding partitions series (modulo bugs and
tweaks), i.e. it closes #54654 and thus closes #40399, which was the
original design sketch.

This thus activates the full designed semantics for binding partitions,
in particular allowing safe replacement of const bindings. It in
particular allows struct redefinitions. This thus closes
timholy/Revise.jl#18 and also closes #38584.

The biggest semantic change here is probably that this gets rid of the
notion of "resolvedness" of a binding. Previously, a lot of the behavior
of our implementation depended on when bindings were "resolved", which
could happen at basically an arbitrary point (in the compiler, in REPL
completion, in a different thread), making a lot of the semantics around
bindings ill- or at least implementation-defined. There are several
related issues in the bugtracker, so this closes #14055 closes #44604
closes #46354 closes #30277

It is also the last step to close #24569.
It also supports bindings for undef->defined transitions and thus closes
#53958 closes #54733 - however, this is not activated yet for
performance reasons and may need some further optimization.

Since resolvedness no longer exists, we need to replace it with some
hopefully more well-defined semantics. I will describe the semantics
below, but before I do I will make two notes:

1. There are a number of cases where these semantics will behave
slightly differently than the old semantics absent some other task going
around resolving random bindings.
2. The new behavior (except for the replacement stuff) was generally
permissible under the old semantics if the bindings happened to be
resolved at the right time.

With all that said, there are essentially three "strengths" of bindings:

1. Implicit Bindings: Anything implicitly obtained from `using Mod`, "no
binding", plus slightly more exotic corner cases around conflicts

2. Weakly declared bindin... (continued)

11 of 111 new or added lines in 7 files covered. (9.91%)

1273 existing lines in 68 files now uncovered.

9908 of 48755 relevant lines covered (20.32%)

105126.48 hits per line

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

21.62
/base/bool.jl
1
# This file is a part of Julia. License is MIT: https://julialang.org/license
2

3
# promote Bool to any other numeric type
4
promote_rule(::Type{Bool}, ::Type{T}) where {T<:Number} = T
×
5

6
typemin(::Type{Bool}) = false
×
7
typemax(::Type{Bool}) = true
×
8

9
## boolean operations ##
10

11
"""
12
    !(x)
13

14
Boolean not. Implements [three-valued logic](https://en.wikipedia.org/wiki/Three-valued_logic),
15
returning [`missing`](@ref) if `x` is `missing`.
16

17
See also [`~`](@ref) for bitwise not.
18

19
# Examples
20
```jldoctest
21
julia> !true
22
false
23

24
julia> !false
25
true
26

27
julia> !missing
28
missing
29

30
julia> .![true false true]
31
1×3 BitMatrix:
32
 0  1  0
33
```
34
"""
35
!(x::Bool) = not_int(x)
15,102,437✔
36

37
(~)(x::Bool) = !x
×
38
(&)(x::Bool, y::Bool) = and_int(x, y)
85,605,762✔
39
(|)(x::Bool, y::Bool) = or_int(x, y)
6,425,748✔
40

41
"""
42
    xor(x, y)
43
    ⊻(x, y)
44

45
Bitwise exclusive or of `x` and `y`. Implements
46
[three-valued logic](https://en.wikipedia.org/wiki/Three-valued_logic),
47
returning [`missing`](@ref) if one of the arguments is `missing`.
48

49
The infix operation `a ⊻ b` is a synonym for `xor(a,b)`, and
50
`⊻` can be typed by tab-completing `\\xor` or `\\veebar` in the Julia REPL.
51

52
# Examples
53
```jldoctest
54
julia> xor(true, false)
55
true
56

57
julia> xor(true, true)
58
false
59

60
julia> xor(true, missing)
61
missing
62

63
julia> false ⊻ false
64
false
65

66
julia> [true; true; false] .⊻ [true; false; false]
67
3-element BitVector:
68
 0
69
 1
70
 0
71
```
72
"""
73
xor(x::Bool, y::Bool) = (x != y)
2✔
74

75
"""
76
    nand(x, y)
77
    ⊼(x, y)
78

79
Bitwise nand (not and) of `x` and `y`. Implements
80
[three-valued logic](https://en.wikipedia.org/wiki/Three-valued_logic),
81
returning [`missing`](@ref) if one of the arguments is `missing`.
82

83
The infix operation `a ⊼ b` is a synonym for `nand(a,b)`, and
84
`⊼` can be typed by tab-completing `\\nand` or `\\barwedge` in the Julia REPL.
85

86
# Examples
87
```jldoctest
88
julia> nand(true, false)
89
true
90

91
julia> nand(true, true)
92
false
93

94
julia> nand(true, missing)
95
missing
96

97
julia> false ⊼ false
98
true
99

100
julia> [true; true; false] .⊼ [true; false; false]
101
3-element BitVector:
102
 0
103
 1
104
 1
105
```
106
"""
107
nand(x...) = ~(&)(x...)
×
108

109
"""
110
    nor(x, y)
111
    ⊽(x, y)
112

113
Bitwise nor (not or) of `x` and `y`. Implements
114
[three-valued logic](https://en.wikipedia.org/wiki/Three-valued_logic),
115
returning [`missing`](@ref) if one of the arguments is `missing` and the
116
other is not `true`.
117

118
The infix operation `a ⊽ b` is a synonym for `nor(a,b)`, and
119
`⊽` can be typed by tab-completing `\\nor` or `\\barvee` in the Julia REPL.
120

121
# Examples
122
```jldoctest
123
julia> nor(true, false)
124
false
125

126
julia> nor(true, true)
127
false
128

129
julia> nor(true, missing)
130
false
131

132
julia> false ⊽ false
133
true
134

135
julia> false ⊽ missing
136
missing
137

138
julia> [true; true; false] .⊽ [true; false; false]
139
3-element BitVector:
140
 0
141
 0
142
 1
143
```
144
"""
145
nor(x...) = ~(|)(x...)
×
146

147
>>(x::Bool, c::UInt) = Int(x) >> c
×
UNCOV
148
<<(x::Bool, c::UInt) = Int(x) << c
×
149
>>>(x::Bool, c::UInt) = Int(x) >>> c
×
150

151
signbit(x::Bool) = false
×
152
sign(x::Bool) = x
×
153
abs(x::Bool) = x
×
154
abs2(x::Bool) = x
×
155
iszero(x::Bool) = !x
×
156
isone(x::Bool) = x
×
157

158
<(x::Bool, y::Bool) = y&!x
983✔
159
<=(x::Bool, y::Bool) = y|!x
7,276✔
160

161
## do arithmetic as Int ##
162

163
+(x::Bool) =  Int(x)
×
164
-(x::Bool) = -Int(x)
×
165

166
+(x::Bool, y::Bool) = Int(x) + Int(y)
259✔
167
-(x::Bool, y::Bool) = Int(x) - Int(y)
×
168
*(x::Bool, y::Bool) = x & y
×
169
^(x::Bool, y::Bool) = x | !y
×
170
^(x::Integer, y::Bool) = ifelse(y, x, one(x))
×
171

172
# preserve -0.0 in `false + -0.0`
173
function +(x::Bool, y::T)::promote_type(Bool,T) where T<:AbstractFloat
×
174
    return ifelse(x, oneunit(y) + y, y)
×
175
end
176
+(y::AbstractFloat, x::Bool) = x + y
×
177

178
# make `false` a "strong zero": false*NaN == 0.0
179
function *(x::Bool, y::T)::promote_type(Bool,T) where T<:AbstractFloat
180
    return ifelse(x, y, copysign(zero(y), y))
×
181
end
182
*(y::AbstractFloat, x::Bool) = x * y
×
183

184
div(x::Bool, y::Bool) = y ? x : throw(DivideError())
×
185
rem(x::Bool, y::Bool) = y ? false : throw(DivideError())
×
186
mod(x::Bool, y::Bool) = rem(x,y)
×
187

188
Bool(x::Real) = x==0 ? false : x==1 ? true : throw(InexactError(:Bool, Bool, x))
89,766✔
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