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

UniStr constructor is not type stable #64

Open
bkamins opened this issue Mar 10, 2018 · 2 comments
Open

UniStr constructor is not type stable #64

bkamins opened this issue Mar 10, 2018 · 2 comments

Comments

@bkamins
Copy link

bkamins commented Mar 10, 2018

This probably will be a problem when dynamically constructing UniStr:

julia> @code_warntype Strs.UniStr("1")
Variables:
  str::String

Body:
  begin
      # meta: location D:\DEV\Julia\Strs.jl\src\encode.jl convert 82
      Core.SSAValue(1) = $(Expr(:invoke, MethodInstance for _str(::String), :(Main.Strs._str), :(str)))::Any
      # meta: pop location
      return Core.SSAValue(1)
  end::Any
@ScottPJones
Copy link
Member

Since UniStr is a Union, it can't ever be type stable, however I may be able to annotate the return so that it knows that it is the UniStr union type, or at least Str, and not just Any.

@bkamins
Copy link
Author

bkamins commented Mar 11, 2018

This is what I mean. UniStr type should be identified as a return type - only then - inside functions we can hope to have "small union" benefit (i.e. we construct a UniStr and then use it in the same function - now we need barrier functions to have it properly type-inferred in hot loops).
Probably some benchmarking is needed here as simply annotating the return value of constructor might also harm performance.

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

2 participants