@@ -1056,7 +1056,7 @@ then save an assertion that new size is equal to old.
10561056function saveonesize (ind, long, store:: NamedTuple )
10571057 if ! haskey (store. dict, ind)
10581058 store. dict[ind] = long
1059- else
1059+ elseif store . dict[ind] != long # no need to save identical expressions
10601060 if isa (ind, Symbol)
10611061 str = " range of index $ind must agree"
10621062 push! (store. assert, :( $ (store. dict[ind]) == $ long || throw (ArgumentError ($ str))) )
@@ -1067,17 +1067,15 @@ end
10671067
10681068function findsizes (store:: NamedTuple , call:: CallInfo )
10691069 out = []
1070- # if :assert in call.flags
10711070 append! (out, store. assert)
10721071 empty! (store. assert)
1073- # end
10741072 if length (store. need) > 0
10751073 sizes = sizeinfer (store, call)
10761074 sz_list = map (szwrap, store. need)
10771075 push! (out, :( local ($ (sz_list... ),) = ($ (sizes... ),) ) )
10781076 end
10791077 append! (out, store. mustassert) # NB do this after calling sizeinfer()
1080- out
1078+ unique! ( out)
10811079end
10821080
10831081function sizeinfer (store:: NamedTuple , call:: CallInfo )
@@ -1165,10 +1163,13 @@ end
11651163"""
11661164 A = maybepush(ex, store, :name)
11671165If `ex` is not just a symbol, then it pushes `:(Asym = ex)` into `store.main`
1168- and returns `Asym`.
1166+ and returns `Asym`. Unless this already has a name, in which case it returns that.
11691167"""
11701168maybepush (s:: Symbol , any... ) = s
1171- function maybepush (ex:: Expr , store:: NamedTuple , name:: Symbol = :A ) # TODO make this look for same?
1169+ function maybepush (ex:: Expr , store:: NamedTuple , name:: Symbol = :A )
1170+ for prev in store. main
1171+ @capture (prev, local sym_ = $ ex) && return sym
1172+ end
11721173 Asym = gensym (name)
11731174 push! (store. main, :( local $ Asym = $ ex ) )
11741175 return Asym
0 commit comments