Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting compilation warning during precompile #133

Closed
djsegal opened this issue Apr 17, 2018 · 3 comments
Closed

Getting compilation warning during precompile #133

djsegal opened this issue Apr 17, 2018 · 3 comments

Comments

@djsegal
Copy link

djsegal commented Apr 17, 2018

I use the following line of code in one of my packages:

const atm_conversion =
  uconvert(u"atm", 1e20u"keV/m^3") / 1u"atm"

However, this gives the following warnings on the initial compile:

WARNING: eval from module Unitful to FusionSystems:
Expr(:call, :^, Unitful.FreeUnits{(Unitful.Unit{:Meter, Unitful.Dimensions{(Unitful.Dimension{:Length}(power=Base.Rational{Int64}(num=1, den=1)),)}}(tens=0, power=Base.Rational{Int64}(num=1, den=1)),), Unitful.Dimensions{(Unitful.Dimension{:Length}(power=Base.Rational{Int64}(num=1, den=1)),)}}(), 3)::Any
  ** incremental compilation may be broken for this module **

WARNING: eval from module Unitful to FusionSystems:
Expr(:call, :/, Unitful.FreeUnits{(Unitful.Unit{:eV, Unitful.Dimensions{(Unitful.Dimension{:Length}(power=Base.Rational{Int64}(num=2, den=1)), Unitful.Dimension{:Mass}(power=Base.Rational{Int64}(num=1, den=1)), Unitful.Dimension{:Time}(power=Base.Rational{Int64}(num=-2, den=1)))}}(tens=3, power=Base.Rational{Int64}(num=1, den=1)),), Unitful.Dimensions{(Unitful.Dimension{:Length}(power=Base.Rational{Int64}(num=2, den=1)), Unitful.Dimension{:Mass}(power=Base.Rational{Int64}(num=1, den=1)), Unitful.Dimension{:Time}(power=Base.Rational{Int64}(num=-2, den=1)))}}(), Unitful.FreeUnits{(Unitful.Unit{:Meter, Unitful.Dimensions{(Unitful.Dimension{:Length}(power=Base.Rational{Int64}(num=1, den=1)),)}}(tens=0, power=Base.Rational{Int64}(num=3, den=1)),), Unitful.Dimensions{(Unitful.Dimension{:Length}(power=Base.Rational{Int64}(num=3, den=1)),)}}())::Any
  ** incremental compilation may be broken for this module **

How do I prevent it?

@ajkeller34
Copy link
Collaborator

The issue is that @u_str is dynamic and looks through registered modules to see what unit symbols are available at the time the macro is expanded. As a result, @u_str doesn't play well with precompilation. It is more explicit if slightly more annoying to write Unitful.atm instead of u"atm", which indicates that you want Unitful's definition of atm even if you've registered some other modules that may define their own atm. I've verified that this will compile:

const atm_conversion =
  uconvert(Unitful.atm, 1e20*Unitful.keV/Unitful.m^3) / (Unitful.atm)

const wb_conversion =
  uconvert(Unitful.Wb, Unitful.µ0 * 1*Unitful.MA*Unitful.m) / Unitful.Wb

This point could use some better documentation if you're up for a PR.

@rafaqz
Copy link
Contributor

rafaqz commented Aug 29, 2018

I just started getting these now that 0.7 does automatic precompilation. I have some files with a few hundred unit declarations, each with 1-4 units. Adding hundreds of Unitful. isn't a great solution to this problem!

How about a second string macro that is Unitful specific and precompilation friendly?

U"m*s^-1"

Otherwise it's using Unitful: m, s, mol, mmol, kg, g ...

@pjabardo
Copy link

I will take a look tonight or tomorrow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants