Skip to content

Commit

Permalink
first stroke at the new report template comparing noDB to DB
Browse files Browse the repository at this point in the history
the report looks reasonable for Multisets

also couple bugs fixed, based on Flux experience
  • Loading branch information
ulysses4ever committed Sep 8, 2023
1 parent 2bc84af commit f644520
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 14 deletions.
2 changes: 1 addition & 1 deletion scripts/aggregate.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash

ADD_HEAD='1i Module,Methods,Stable,Unstable,Partial,Any,Vararg,Generic,TcFail,NoFuel'
ADD_HEAD='1i Module,MethodsGood,Stable,Unstable,NoFuel,DBStableDiff,DBUnstableDiff,DBNoFuelDiff'

find . -maxdepth 2 -name "*-agg.txt" -exec cat {} + | sort | sed "$ADD_HEAD" > aggregate.csv
8 changes: 4 additions & 4 deletions src/StabilityCheck.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ is_stable_module_aux(mod::Module, root::Module, seen::Set{Module}, scfg::SearchC
our_methods_of_function(evsym, mod)))
catch e
if e isa UndefVarError
@warn "Module $mod exports symbol $sym but it's undefined"
# showerror(stdout, e)
@warn "Module $mod contains symbol $sym but we can't evaluate it"
showerror(stdout, e)
# not our problem, so proceed as usual
elseif e isa CantSplitMethod
@warn "Can't process method with no canonical instance:\n$m"
Expand Down Expand Up @@ -156,7 +156,7 @@ is_stable_method(m::Method, scfg :: SearchCfg = default_scfg) :: StCheck = begin
@debug "is_stable_method: any, vararg checks"
Any sig_types && ! scfg.typesDBcfg.use_types_db &&
return AnyParam()
any(t -> is_vararg(t), sig_types) &&
any(t -> has_vararg(t), sig_types) &&
return VarargParam()
# TODO:

Expand Down Expand Up @@ -201,7 +201,7 @@ is_stable_method(m::Method, scfg :: SearchCfg = default_scfg) :: StCheck = begin
result isa OutOfFuel &&
return result
return if isempty(unst)
if isempty(skipexists)
if isempty(skipexists) # TODO: kill skipexist, we don't use it
Stb(stepCount)
else
UConstrExist(stepCount, skipexists)
Expand Down
11 changes: 8 additions & 3 deletions src/enumeration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,13 @@ has_unboundeded_exist(tv :: JlSignature) = begin
end

# Shortcut: well-known underconstrained types that we want to avoid
# for which we will return NoFuel eventually
# for which we will return NoFuel eventually.
# Varargs, Tuple, Function, etc.
blocklist = [Function]
is_vararg(t) = isa(t, Core.TypeofVararg)
to_avoid(t) = is_vararg(t) || any(b -> t <: b, blocklist)
has_vararg(t) = occursin("Vararg", "$t") || # crude but works
t == Tuple # ~ Tuple{Vararg{Any}}
to_avoid(t) = has_vararg(t) ||
any(b -> t <: b, blocklist)

#
# direct_subtypes: JlSignature, SearchCfg -> [Union{JlSignature, SkippedUnionAlls}]
Expand Down Expand Up @@ -155,6 +158,8 @@ direct_subtypes1(t::Any, scfg :: SearchCfg) = begin
subtype_union(t)
elseif is_concrete_type(t)
[t]
elseif t <: Tuple
direct_subtypes(Vector{Any}([t.parameters...]), scfg)
else
@assert false "direct_subtypes1: can't subtype $t (should not happen)"
end
Expand Down
38 changes: 32 additions & 6 deletions src/report.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,47 @@ prepCsv(mcs::StCheckResults) :: StCheckResultsCsv = map(prepCsvCheck, mcs)
#


#
# Record of aggregated results. One Julia module turns into one instance of it.
# Note: If you change it, you probably need to update scripts/aggregate.sh
#
# NOTE: If you change it, you probably need to update scripts/aggregate.sh and
# the two functions right below.
#
struct AgStats
methCnt :: Int64
stbCnt :: Int64
unsCnt :: Int64
parCnt :: Int64
anyCnt :: Int64
vaCnt :: Int64
gen :: Int64
genCnt :: Int64
tcfCnt :: Int64
nofCnt :: Int64
end

showAgStats(pkg::String, ags::AgStats) :: String =
"$pkg,$(ags.methCnt),$(ags.stbCnt),$(ags.unsCnt),$(ags.parCnt),$(ags.anyCnt)," *
"$(ags.vaCnt),$(ags.gen),$(ags.tcfCnt),$(ags.nofCnt)\n"
showAgStatsDB(pkg::String, agsNoDb::AgStats, agsDb::AgStats) :: String = begin
@assert agsNoDb.parCnt == 0
@assert agsDb.parCnt == 0

# @info agsDb
methGood = agsNoDb.methCnt - agsNoDb.tcfCnt - agsNoDb.genCnt
noFuel = agsNoDb.vaCnt + agsNoDb.nofCnt + agsNoDb.anyCnt
noFuelDb = agsDb.vaCnt + agsDb.nofCnt + agsDb.anyCnt

# $(agsNoDb.methCnt), # should this be in? makes the table noisier...
"$pkg,$(methGood)," *
"$(agsNoDb.stbCnt),$(agsNoDb.unsCnt),$(noFuel)," *
"$(agsDb.stbCnt - agsNoDb.stbCnt),$(agsDb.unsCnt - agsNoDb.unsCnt),$(noFuelDb - noFuel)" *
"\n"
end

showAgStats(pkg::String, ags::AgStats) :: String = begin
@assert ags.parCnt == 0
methGood = ags.methCnt - ags.tcfCnt - ags.genCnt
noFuel = ags.vaCnt + ags.nofCnt + ags.anyCnt
"$pkg,$(ags.methCnt), $(methGood)," *
"$(ags.stbCnt),$(ags.unsCnt),$(noFuel)\n"
end

aggregateStats(mcs::StCheckResults) :: AgStats = AgStats(
# TODO: this is a lot of passes over mcs; should rewrite into one loop
Expand Down Expand Up @@ -128,6 +152,7 @@ aggregateStats(mcs::StCheckResults) :: AgStats = AgStats(
checkModule(m::Module, out::String="."; pkg::String="$m")= begin
scfg = build_typesdb_scfg(sample_count=10)
checkRes = is_stable_module(m, scfg)
checkResNoDb = is_stable_module(m)

# raw, to allow load it back up for debugging purposes
# CSV.write(joinpath(out, "$m-raw.csv"), checkRes)
Expand All @@ -140,7 +165,8 @@ checkModule(m::Module, out::String="."; pkg::String="$m")= begin
# aggregate
aggrepname = joinpath(out, "$pkg-agg.txt")
@info "Generating and writing out aggregated report to $aggrepname"
write(aggrepname, showAgStats(pkg, aggregateStats(checkRes)))
write(aggrepname,
showAgStatsDB(pkg, aggregateStats(checkResNoDb), aggregateStats(checkRes)))
return ()
end

Expand Down
1 change: 1 addition & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ end
# Note: Follows definition used in @code_warntype (cf. `warntype_type_printer` in:
# julia/stdlib/InteractiveUtils/src/codeview.jl)
is_concrete_type(@nospecialize(ty)) = begin
ty == DataType && return true
if ty isa Type && (!Base.isdispatchelem(ty) || ty == Core.Box)
if ty isa Union && is_expected_union(ty)
true # this is a "mild" problem, so we round up to "stable"
Expand Down

0 comments on commit f644520

Please sign in to comment.