Skip to content

Commit

Permalink
fix fuel more; fix parameters setting at types DB creation
Browse files Browse the repository at this point in the history
  • Loading branch information
ulysses4ever committed Sep 8, 2023
1 parent b8ec07c commit 06d0b56
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 22 deletions.
48 changes: 35 additions & 13 deletions src/enumeration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,18 @@ all_subtypes(ts::Vector, scfg :: SearchCfg, result :: Channel) = begin
isconc = all(is_concrete_type, tv)
if isconc
@debug "[ all_subtypes ] concrete"
put!(result, tv)

# Manage fuel w.r.t. reaching concrete types
global stepCount
stepCount += 1
@debug "[ all_subtypes ]" stepCount scfg.fuel
if stepCount > scfg.fuel
put!(result, OutOfFuel())
scfg.failfast &&
break
else
put!(result, tv)
end
# otherwise, get some subtypes, add to worklist, loop
else
@debug "[ all_subtypes ] abstract"
Expand Down Expand Up @@ -122,22 +133,33 @@ end
direct_subtypes1(t::Any, scfg :: SearchCfg) = begin
@debug "direct_subtypes1: $t"

# it is hear where we decided to manage fuel
# It is here where we decided to manage fuel w.r.t. traversing lattice.
# There's another point, which has to do with reaching concrete types,
# inside all_subtypes
global stepCount
stepCount += 1
@debug "direct_subtypes1" stepCount scfg.fuel
stepCount > scfg.fuel && return nothing

if t isa UnionAll
ss_first = subtype_unionall(t, scfg)
elseif t isa Union
ss_first = subtype_union(t)
elseif is_concrete_type(t)
[t]
elseif t == Any # if Any got here, we're asked to sample
scfg.typesDBcfg.types_db
else
subtypes(t)
end
ss = subtypes(t)

res =
# NOTE: the order of if-branches is important
if t == Any # if Any got here, we're asked to sample
scfg.typesDBcfg.types_db
elseif !isempty(ss) # we try to crawl nominal hierarchy all the way first
ss
elseif t isa UnionAll
subtype_unionall(t, scfg)
elseif t isa Union
subtype_union(t)
elseif is_concrete_type(t)
[t]
else
@assert false "direct_subtypes1: can't subtype $t (should not happen)"
end
# @info "" res
return res
end

#
Expand Down
10 changes: 6 additions & 4 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Base.@kwdef struct SearchCfg
failfast :: Bool = true
# ^--- exit when find the first counterexample

fuel :: Int = 100 #typemax(Int)
fuel :: Int = 1000 #typemax(Int)
# ^--- search fuel, i.e. how many types we want to enumerate before give up

typesDBcfg :: TypesDBCfg = TypesDBCfg()
Expand All @@ -132,10 +132,12 @@ default_scfg = SearchCfg()
fast_scfg = SearchCfg(fuel=30)

build_typesdb_scfg(inFile = intypesCsvFileDefault; sample_count :: Int = 100000) = begin
tdbFull = typesDB(inFile)
sampleCountActual = min(length(tdbFull),sample_count)
tdb = tdbFull[1:sampleCountActual]
scfg = @set default_scfg.typesDBcfg.use_types_db = true
scfg = @set scfg.typesDBcfg.types_db = typesDB(inFile)[1:min(end,sample_count)]
scfg = @set scfg.typesDBcfg.sample_count = sample_count
scfg = @set scfg.fuel = length(scfg.typesDBcfg.types_db)
scfg = @set scfg.typesDBcfg.types_db = tdb
scfg = @set scfg.typesDBcfg.sample_count = length(tdb)
scfg
end

Expand Down
1 change: 1 addition & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ is_stable_call(@nospecialize(f :: Function), @nospecialize(ts :: Vector)) = begi
end
(_ #=code=#, res_type) = ct[1] # we ought to have just one method body, I think
res = is_concrete_type(res_type)
# @info "[ is_stable_call ]" res_type
#print_stable_check(f,ts,res_type,res)
res
end
Expand Down
11 changes: 6 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -290,14 +290,15 @@ end
# See also "Special (Any, Varargs, Generic)" testset above.
#
typesdb_cfg = build_typesdb_scfg("merged-small.csv")
@test Stb(1) == is_stable_method((@which id1(1)), typesdb_cfg)
@test Stb(3) == is_stable_method((@which id1(1)), typesdb_cfg)
# We count fuel in a tricky way: it's
# number of calls to direct_subtypes1 + number of concrete
# tuple types (corresponding to signatures).
# The example DB has 2 types.

myplus(x,y)=x+y
res = is_stable_method((@which id1(1)), typesdb_cfg)
@info res
@test Stb(1) == res # 1 is weird but that's how we count fuel:
# number of calls to direct_subtypes1, and that one returns
# the types DB in whole at once
@test Stb(3) == res
end

module ImportBase; import Base.push!; push!(::Int)=1; end
Expand Down

0 comments on commit 06d0b56

Please sign in to comment.