@@ -366,11 +366,18 @@ function val_from_byref_if_mixed(B::LLVM.IRBuilder, gutils::GradientUtils, @nosp
366366 end
367367end
368368
369- function ref_if_mixed (val:: VT ) where {VT}
370- if active_reg_inner (Core. Typeof (val), (), nothing , Val (true )) == ActiveState
371- return Ref (val)
369+ @generated function ref_if_mixed (val:: VT ) where VT
370+ areg = active_reg_inner (VT, (), nothing , Val (true ))
371+ if areg == ActiveState || areg == MixedState
372+ quote
373+ Base. @_inline_meta
374+ Ref (val)
375+ end
372376 else
373- return val
377+ quote
378+ Base. @_inline_meta
379+ val
380+ end
374381 end
375382end
376383
@@ -380,15 +387,13 @@ function byref_from_val_if_mixed(B::LLVM.IRBuilder, @nospecialize(val::LLVM.Valu
380387 if ! legal
381388 legal, TT, _ = abs_typeof (val, true )
382389 act = active_reg_inner (TT, (), world)
383- if act == AnyState
390+ if legal && act == AnyState
384391 return val
385392 end
386- if ! legal
387- return emit_apply_generic! (B, [unsafe_to_llvm (B, ref_if_mixed), val])
388- end
393+ return emit_apply_generic! (B, LLVM. Value[unsafe_to_llvm (B, ref_if_mixed), val])
389394 end
390395 act = active_reg_inner (TT, (), world)
391-
396+
392397 if act == ActiveState || act == MixedState
393398 obj = emit_allocobj! (B, Base. RefValue{TT})
394399 lty = convert (LLVMType, TT)
0 commit comments