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

Make length for Date ranges type stable #20839

Merged
merged 1 commit into from
Mar 1, 2017
Merged

Conversation

omus
Copy link
Member

@omus omus commented Feb 28, 2017

On 32-bit systems the length method for a StepRange{<:TimeType} was type instable:

julia> @code_warntype length(Date(2014):Dates.Day(1):Date(2015))
Variables:
  #self#::Base.#length
  r::StepRange{Date,Base.Dates.Day}

Body:
  begin 
      unless (Base.and_int)((Base.not_int)(((Core.getfield)(r::StepRange{Date,Base.Dates.Day},:start)::Date === (Core.getfield)(r::StepRange{Date,Base.Dates.Day},:stop)::Date)::Bool)::Bool,(Base.not_int)(((Base.slt_int)((Base.sext_int)(Int64,0)::Int64,(Core.getfield)((Core.getfield)(r::StepRange{Date,Base.Dates.Day},:step)::Base.Dates.Day,:value)::Int64)::Bool === (Base.slt_int)((Core.getfield)((Core.getfield)((Core.getfield)((Core.getfield)(r::StepRange{Date,Base.Dates.Day},:start)::Date,:instant)::Base.Dates.UTInstant{Base.Dates.Day},:periods)::Base.Dates.Day,:value)::Int64,(Core.getfield)((Core.getfield)((Core.getfield)((Core.getfield)(r::StepRange{Date,Base.Dates.Day},:stop)::Date,:instant)::Base.Dates.UTInstant{Base.Dates.Day},:periods)::Base.Dates.Day,:value)::Int64)::Bool)::Bool)::Bool)::Bool goto 3
      return 0
      3: 
      SSAValue(0) = $(Expr(:invoke, MethodInstance for len(::Date, ::Date, ::Base.Dates.Day), :(Base.Dates.len), :((Core.getfield)(r,:start)::Date), :((Core.getfield)(r,:stop)::Date), :((Core.getfield)(r,:step)::Base.Dates.Day)))
      return (Base.add_int)(SSAValue(0),(Base.sext_int)(Int64,1)::Int64)::Int64
  end::Union{Int32,Int64}

@omus omus added system:32-bit Affects only 32-bit systems dates Dates, times, and the Dates stdlib module labels Feb 28, 2017
@tkelman
Copy link
Contributor

tkelman commented Feb 28, 2017

how many types do we have give Int64 lengths on 32 bit?

@omus
Copy link
Member Author

omus commented Feb 28, 2017

I'm not sure. Anything that uses a type larger than Int32 will probably return an Int64 or larger:

On 32-bit:

julia> typeof(length(Int64(1):Int64(2)))
Int64

julia> typeof(length(Int64(1)//2:1//4:1))
Int64

julia> typeof(length(Int128(1):Int128(2)))
Int128

julia> typeof(length(UInt16(1):UInt16(2)))
Int32

julia> typeof(length(UInt32(1):UInt32(2)))
UInt32

@ararslan ararslan requested a review from quinnj February 28, 2017 17:50
@tkelman tkelman merged commit b0d2220 into master Mar 1, 2017
@tkelman tkelman deleted the cv/date-range-stable-length branch March 1, 2017 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dates Dates, times, and the Dates stdlib module system:32-bit Affects only 32-bit systems
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants