Skip to content

Commit 5f9e4b5

Browse files
committed
Revert "Merge pull request #62 from JuliaDebug/configurable-norequire"
This reverts commit e4af191, reversing changes made to d61d111.
1 parent e4af191 commit 5f9e4b5

File tree

3 files changed

+16
-35
lines changed

3 files changed

+16
-35
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "LoweredCodeUtils"
22
uuid = "6f1432cf-f94c-5a45-995e-cdbf5db27b0b"
33
authors = ["Tim Holy <[email protected]>"]
4-
version = "1.3.0"
4+
version = "1.2.9"
55

66
[deps]
77
JuliaInterpreter = "aa1ae85d-cabe-5617-a682-6adf51b2e16a"

src/codeedges.jl

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -577,52 +577,34 @@ function lines_required(idx::Int, src::CodeInfo, edges::CodeEdges; kwargs...)
577577
isrequired = falses(length(edges.preds))
578578
isrequired[idx] = true
579579
objs = Set{Union{Symbol,GlobalRef}}()
580-
return lines_required!(isrequired, objs, src, edges; kwargs...)
580+
return lines_required!(isrequired, src, edges; kwargs...)
581581
end
582582

583583
"""
584-
lines_required!(isrequired::AbstractVector{Bool}, src::CodeInfo, edges::CodeEdges;
585-
norequire = ())
584+
lines_required!(isrequired::AbstractVector{Bool}, src::CodeInfo, edges::CodeEdges; exclude_named_typedefs::Bool=false)
586585
587586
Like `lines_required`, but where `isrequired[idx]` has already been set to `true` for all statements
588587
that you know you need to evaluate. All other statements should be marked `false` at entry.
589588
On return, the complete set of required statements will be marked `true`.
590589
591-
`norequire` keyword argument specifies statements (represented as iterator of `Int`s) that
592-
should _not_ be marked as a requirement.
593-
For example, use `norequire = LoweredCodeUtils.exclude_named_typedefs(src, edges)` if you're
594-
extracting method signatures and not evaluating new definitions.
590+
Use `exclude_named_typedefs=true` if you're extracting method signatures and not evaluating new definitions.
595591
"""
596592
function lines_required!(isrequired::AbstractVector{Bool}, src::CodeInfo, edges::CodeEdges; kwargs...)
597593
objs = Set{Union{Symbol,GlobalRef}}()
598594
return lines_required!(isrequired, objs, src, edges; kwargs...)
599595
end
600596

601-
function exclude_named_typedefs(src::CodeInfo, edges::CodeEdges)
602-
norequire = BitSet()
603-
i = 1
604-
nstmts = length(src.code)
605-
while i <= nstmts
606-
stmt = rhs(src.code[i])
607-
if istypedef(stmt) && !isanonymous_typedef(stmt::Expr)
608-
r = typedef_range(src, i)
609-
pushall!(norequire, r)
610-
i = last(r)+1
611-
else
612-
i += 1
613-
end
614-
end
615-
return norequire
616-
end
617-
618-
function lines_required!(isrequired::AbstractVector{Bool}, objs, src::CodeInfo, edges::CodeEdges; norequire = ())
597+
function lines_required!(isrequired::AbstractVector{Bool}, objs, src::CodeInfo, edges::CodeEdges; exclude_named_typedefs::Bool=false)
619598
# Do a traveral of "numbered" predecessors
620599
# We'll mostly use generic graph traversal to discover all the lines we need,
621600
# but structs are in a bit of a different category (especially on Julia 1.5+).
622601
# It's easiest to discover these at the beginning.
602+
# Moreover, if we're excluding named type definitions, we'll add them to `norequire`
603+
# to prevent them from being marked.
623604
typedef_blocks, typedef_names = UnitRange{Int}[], Symbol[]
624-
i = 1
605+
norequire = BitSet()
625606
nstmts = length(src.code)
607+
i = 1
626608
while i <= nstmts
627609
stmt = rhs(src.code[i])
628610
if istypedef(stmt) && !isanonymous_typedef(stmt::Expr)
@@ -636,6 +618,9 @@ function lines_required!(isrequired::AbstractVector{Bool}, objs, src::CodeInfo,
636618
isa(name, Symbol) || @show src i r stmt
637619
push!(typedef_names, name::Symbol)
638620
i = last(r)+1
621+
if exclude_named_typedefs && !isanonymous_typedef(stmt)
622+
pushall!(norequire, r)
623+
end
639624
else
640625
i += 1
641626
end
@@ -656,22 +641,19 @@ function lines_required!(isrequired::AbstractVector{Bool}, objs, src::CodeInfo,
656641
iter = 0
657642
while changed
658643
changed = false
659-
660644
# Handle ssa predecessors
661645
for idx = 1:nstmts
662646
if isrequired[idx]
663647
changed |= add_preds!(isrequired, idx, edges, norequire)
664648
end
665649
end
666-
667650
# Handle named dependencies
668651
for (obj, uses) in edges.byname
669652
obj objs && continue
670653
if any(view(isrequired, uses.succs))
671654
changed |= add_obj!(isrequired, objs, obj, edges, norequire)
672655
end
673656
end
674-
675657
# Add control-flow. For any basic block with an evaluated statement inside it,
676658
# check to see if the block has any successors, and if so mark that block's exit statement.
677659
# Likewise, any preceding blocks should have *their* exit statement marked.
@@ -702,7 +684,6 @@ function lines_required!(isrequired::AbstractVector{Bool}, objs, src::CodeInfo,
702684
end
703685
end
704686
end
705-
706687
# So far, everything is generic graph traversal. Now we add some domain-specific information.
707688
# New struct definitions, including their constructors, get spread out over many
708689
# statements. If we're evaluating any of them, it's important to evaluate *all* of them.
@@ -852,7 +833,7 @@ Mark each line of code with its requirement status.
852833
function print_with_code(io::IO, src::CodeInfo, isrequired::AbstractVector{Bool})
853834
nd = ndigits(length(isrequired))
854835
preprint(::IO) = nothing
855-
preprint(io::IO, idx::Int) = (c = isrequired[idx]; printstyled(io, lpad(idx, nd), ' ', c ? "t " : "f "; color = c ? :cyan : :plain))
836+
preprint(io::IO, idx::Int) = print(io, lpad(idx, nd), ' ', isrequired[idx] ? "t " : "f ")
856837
postprint(::IO) = nothing
857838
postprint(io::IO, idx::Int, bbchanged::Bool) = nothing
858839

test/codeedges.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using LoweredCodeUtils
22
using LoweredCodeUtils.JuliaInterpreter
3-
using LoweredCodeUtils: callee_matches, istypedef, exclude_named_typedefs
3+
using LoweredCodeUtils: callee_matches, istypedef
44
using JuliaInterpreter: is_global_ref, is_quotenode
55
using Test
66

@@ -262,7 +262,7 @@ end
262262
frame = Frame(ModEval, ex)
263263
src = frame.framecode.src
264264
edges = CodeEdges(src)
265-
isrequired = minimal_evaluation(stmt->(LoweredCodeUtils.ismethod3(stmt),false), src, edges; norequire=exclude_named_typedefs(src, edges)) # initially mark only the constructor
265+
isrequired = minimal_evaluation(stmt->(LoweredCodeUtils.ismethod3(stmt),false), src, edges; exclude_named_typedefs=true) # initially mark only the constructor
266266
bbs = Core.Compiler.compute_basic_blocks(src.code)
267267
for (iblock, block) in enumerate(bbs.blocks)
268268
r = LoweredCodeUtils.rng(block)
@@ -301,7 +301,7 @@ end
301301
src = thk.args[1]
302302
edges = CodeEdges(src)
303303
idx = findfirst(stmt->Meta.isexpr(stmt, :method), src.code)
304-
lr = lines_required(idx, src, edges; norequire=exclude_named_typedefs(src, edges))
304+
lr = lines_required(idx, src, edges; exclude_named_typedefs=true)
305305
idx = findfirst(stmt->Meta.isexpr(stmt, :(=)) && Meta.isexpr(stmt.args[2], :call) && is_global_ref(stmt.args[2].args[1], Core, :Box), src.code)
306306
@test lr[idx]
307307
# but make sure we don't break primitivetype & abstracttype (https://github.com/timholy/Revise.jl/pull/611)

0 commit comments

Comments
 (0)