Skip to content

insufficient constant propagation for unit exponentiation with floating-point exponent #787

@DylanMMarques

Description

@DylanMMarques

Hello, I found a use case where uconvertrp becomes type instable:

using Unitful, Unitful.DefaultSymbols
function tmp(a, b)
           uconvertp(NoUnits, a * (b ^ (3/2)))
end

julia> @code_warntype tmp(10u"dB/cm^(3/2)", 10cm)
MethodInstance for tmp(::Quantity{Gain{Unitful.LogInfo{:Decibel, 10, 10}, :?, Int64}, 𝐋^-3/2, Unitful.FreeUnits{(cm^-3/2,), 𝐋^-3/2, nothing}}, ::Quantity{Int64, 𝐋, Un
itful.FreeUnits{(cm,), 𝐋, nothing}})
  from tmp(a, b) @ Main REPL[61]:1
Arguments
  #self#::Core.Const(Main.tmp)
  a::Quantity{Gain{Unitful.LogInfo{:Decibel, 10, 10}, :?, Int64}, 𝐋^-3/2, Unitful.FreeUnits{(cm^-3/2,), 𝐋^-3/2, nothing}}
  b::Quantity{Int64, 𝐋, Unitful.FreeUnits{(cm,), 𝐋, nothing}}
Body::Any
1%1 = Main.uconvertp::Core.Const(Unitful.uconvertp)
│   %2 = Main.NoUnits::Core.Const()
│   %3 = Main.:*::Core.Const(*)
│   %4 = Main.:^::Core.Const(^)
│   %5 = (3 / 2)::Core.Const(1.5)
│   %6 = (%4)(b, %5)::Any%7 = (%3)(a, %6)::Any%8 = (%1)(%2, %7)::Any
└──      return %8

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions