Skip to content

Commit 8521fe2

Browse files
committed
juliatypes.jl: code simplifications
1 parent 6c574b7 commit 8521fe2

File tree

1 file changed

+14
-43
lines changed

1 file changed

+14
-43
lines changed

examples/juliatypes.jl

Lines changed: 14 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -244,52 +244,23 @@ end
244244
issub(x, y, env) = (x === y)
245245
issub(x::Ty, y::Ty, env) = (x === y) || x === BottomT
246246

247-
function discover_Lunion(a::UnionT, env)
247+
function union_issub(a::UnionT, b::Ty, env)
248248
if env.Ldepth > length(env.Lunions)
249249
# at a new nesting depth, begin by just counting unions
250250
env.Lnew += 1
251251
return true
252252
end
253-
return false
254-
end
255-
256-
function discover_Runion(b::UnionT, env)
257-
if env.Rdepth > length(env.Runions)
258-
env.Rnew += 1
259-
return true
260-
end
261-
return false
262-
end
263-
264-
function issub(a::UnionT, b::UnionT, env)
265-
a === b && return true
266-
if discover_Lunion(a, env) | discover_Runion(b, env)
267-
return true
268-
end
269-
L = env.Lunions[env.Ldepth]; L.i += 1
270-
R = env.Runions[env.Rdepth]; R.i += 1
271-
env.Ldepth += 1
272-
env.Rdepth += 1
273-
ans = issub(a.((L.idxs&(1<<L.i)!=0) + 1), b.((R.idxs&(1<<R.i)!=0) + 1), env)
274-
env.Rdepth -= 1
275-
env.Ldepth -= 1
276-
return ans
277-
end
278-
279-
function issub(a::UnionT, t::Ty, env)
280-
if discover_Lunion(a, env)
281-
return true
282-
end
283253
L = env.Lunions[env.Ldepth]; L.i += 1
284254
env.Ldepth += 1
285-
ans = issub(a.((L.idxs&(1<<L.i)!=0) + 1), t, env)
255+
ans = issub(a.((L.idxs&(1<<L.i)!=0) + 1), b, env)
286256
env.Ldepth -= 1
287257
return ans
288258
end
289259

290-
function issub(a::Ty, b::UnionT, env)
260+
function issub_union(a::Ty, b::UnionT, env)
291261
a === BottomT && return true
292-
if discover_Runion(b, env)
262+
if env.Rdepth > length(env.Runions)
263+
env.Rnew += 1
293264
return true
294265
end
295266
R = env.Runions[env.Rdepth]; R.i += 1
@@ -299,6 +270,10 @@ function issub(a::Ty, b::UnionT, env)
299270
return ans
300271
end
301272

273+
issub(a::UnionT, b::UnionT, env) = a === b || union_issub(a, b, env)
274+
issub(a::UnionT, b::Ty, env) = union_issub(a, b, env)
275+
issub(a::Ty, b::UnionT, env) = issub_union(a, b, env)
276+
302277
function issub(a::TagT, b::TagT, env)
303278
a === b && return true
304279
b === AnyT && return true
@@ -308,10 +283,8 @@ function issub(a::TagT, b::TagT, env)
308283
return issub(super(a), b, env)
309284
end
310285
if a.name === TupleName
311-
va = a.vararg
312-
vb = b.vararg
313-
la = length(a.params)
314-
lb = length(b.params)
286+
va, vb = a.vararg, b.vararg
287+
la, lb = length(a.params), length(b.params)
315288
if va && (!vb || la < lb)
316289
return false
317290
end
@@ -350,8 +323,7 @@ function issub(a::Var, b::Ty, env)
350323
# invariant position. So just return true when checking the "flipped"
351324
# direction B<:A.
352325
aa.right && return true
353-
d = env.depth
354-
if d != aa.depth # && d > 1 ???
326+
if env.depth != aa.depth # && env.depth > 1 ???
355327
# Var <: non-Var can only be true when there are no invariant
356328
# constructors between the UnionAll and this occurrence of Var.
357329
return false
@@ -364,12 +336,11 @@ function issub(a::Var, b::Var, env)
364336
aa = env.vars[a]
365337
aa.right && return true
366338
bb = env.vars[b]
367-
d = env.depth
368-
if aa.depth != bb.depth # && d > 1 ???
339+
if aa.depth != bb.depth # && env.depth > 1 ???
369340
# Vars must occur at same depth
370341
return false
371342
end
372-
if d > bb.depth
343+
if env.depth > bb.depth
373344
# if there are invariant constructors between a UnionAll and
374345
# this occurrence of Var, then we have an equality constraint on Var.
375346
if isa(bb.ub,Var)

0 commit comments

Comments
 (0)