@@ -38,11 +38,10 @@ struct FlatteningState
3838 map:: ArgumentMap
3939 nvariables:: Int
4040 nequations:: Int
41- new_argtypes:: Vector{Any}
4241end
4342
4443function FlatteningState (compact:: IncrementalCompact , settings:: Settings , map:: ArgumentMap )
45- FlatteningState (compact, settings, deepcopy (map), length (map. variables), length (map. equations), Any[] )
44+ FlatteningState (compact, settings, deepcopy (map), length (map. variables), length (map. equations))
4645end
4746
4847function next_variable! (state:: FlatteningState )
@@ -55,16 +54,24 @@ function next_equation!(state::FlatteningState)
5554 return state. nequations - length (state. map. equations)
5655end
5756
57+ function flatten_arguments! (state:: FlatteningState )
58+ argtypes = copy (state. compact. ir. argtypes)
59+ empty! (state. compact. ir. argtypes) # will be recomputed during flattening
60+ args = flatten_arguments! (state, argtypes)
61+ if args != = nothing
62+ @assert isempty (state. map. variables)
63+ @assert isempty (state. map. equations)
64+ end
65+ return args
66+ end
67+
5868function flatten_arguments! (state:: FlatteningState , argtypes:: Vector{Any} )
5969 args = Any[]
60- # push!(state.new_argtypes, argtypes[1])
6170 for argt in argtypes
6271 arg = flatten_argument! (state, argt)
6372 arg === nothing && return nothing
6473 push! (args, arg)
6574 end
66- @assert isempty (state. map. variables)
67- @assert isempty (state. map. equations)
6875 return args
6976end
7077
@@ -76,7 +83,7 @@ function flatten_argument!(state::FlatteningState, @nospecialize(argt))
7683 elseif Base. issingletontype (argt)
7784 return argt. instance
7885 elseif isprimitivetype (argt)
79- push! (state. new_argtypes , argt)
86+ push! (state. compact . ir . argtypes , argt)
8087 return Argument (next_variable! (state))
8188 elseif argt === equation
8289 eq = next_equation! (state)
0 commit comments