Skip to content

Commit

Permalink
first prototype of tracing checks
Browse files Browse the repository at this point in the history
when run is_stable_method(m,trace_scfg), you get a text file
checks/$m.name with types that were tried when checking type stability
  • Loading branch information
ulysses4ever committed Dec 3, 2023
1 parent ae53bd0 commit 095a9f1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/StabilityCheck.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export @stable, @stable!, @stable!_nop,
SkippedUnionAlls, UnboundedUnionAlls, SkipMandatory,
Stb, Uns,
UConstr, UConstrExist, AnyParam, VarargParam, TcFail, OutOfFuel, GenericMethod,
SearchCfg, build_typesdb_scfg, default_scfg,
SearchCfg, build_typesdb_scfg, default_scfg, trace_scfg,

# Utils
split_method # mostly for testing
Expand Down Expand Up @@ -124,6 +124,12 @@ is_stable_method(m::Method, scfg :: SearchCfg = default_scfg) :: StCheck = begin
@debug "is_stable_method: $m"
global stepCount = 0

# trace TS checks and store to a file
if scfg.trace_checks
mkpath("checks")
fchecks = open("checks/$(m.name)", "w")
end

# preemptively load types DB if available: we may need to sample
# unbounded exists any minute
if scfg.typesDBcfg.use_types_db
Expand All @@ -143,10 +149,16 @@ is_stable_method(m::Method, scfg :: SearchCfg = default_scfg) :: StCheck = begin
# and party if we're concrete
@debug "is_stable_method: check against signature (2a)"
try
scfg.trace_checks &&
println(fchecks, sig_types)
if is_stable_call(func, sig_types)
scfg.trace_checks &&
close(fchecks)
return Stb(1)
end
catch e
scfg.trace_checks &&
close(fchecks)
return TcFail(sig_types, e)
end

Expand Down Expand Up @@ -187,17 +199,23 @@ is_stable_method(m::Method, scfg :: SearchCfg = default_scfg) :: StCheck = begin

# the actual stability check
try
scfg.trace_checks &&
println(fchecks, ts)
if ! is_stable_call(func, ts)
push!(unst, ts)
if scfg.failfast
break
end
end
catch e
scfg.trace_checks &&
close(fchecks)
return TcFail(ts, e)
end
end

scfg.trace_checks &&
close(fchecks)
result isa OutOfFuel &&
return result
return if isempty(unst)
Expand Down
5 changes: 5 additions & 0 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ Base.@kwdef struct SearchCfg

typesDBcfg :: TypesDBCfg = TypesDBCfg()
# ^--- Parameters of the types DB.

trace_checks :: Bool = false
# ^-- create a file recording all type stability checks of a method
end

#
Expand All @@ -131,6 +134,8 @@ default_scfg = SearchCfg()

fast_scfg = SearchCfg(fuel=30)

trace_scfg = SearchCfg(trace_checks=true)

build_typesdb_scfg(inFile = intypesCsvFileDefault; sample_count :: Int = 100000) = begin
tdbFull = typesDB(inFile)
sampleCountActual = min(length(tdbFull),sample_count)
Expand Down

0 comments on commit 095a9f1

Please sign in to comment.