Skip to content

Commit

Permalink
Added two more specs for raise inference. IssueID michaeledgar#2.
Browse files Browse the repository at this point in the history
Adding lots of type annotations for the builtins, further pushing
me toward pulling in a lot of Rubinius.
  • Loading branch information
Michael Edgar committed Jul 26, 2011
1 parent 2b5118b commit a172091
Show file tree
Hide file tree
Showing 8 changed files with 264 additions and 28 deletions.
6 changes: 2 additions & 4 deletions lib/laser/analysis/control_flow/yield_properties.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,8 @@ def potential_block_calls(block_value = nil)
elsif aliases.include?(insn.block_operand)
insn.possible_methods.each do |method|
yield_type = method.yield_type
if block_value.nil? && (yield_type == :required || yield_type == :foolish)
calls << insn
break
elsif !block_value.nil? && (yield_type == :required || yield_type == :optional)
if block_value.nil? && (yield_type == :required || yield_type == :foolish) ||
!block_value.nil? && (yield_type == :required || yield_type == :optional)
calls << insn
break
end
Expand Down
5 changes: 4 additions & 1 deletion lib/laser/analysis/laser_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,16 @@ def annotated_raise_frequency
annotations['raises'].select(&:literal?).map(&:literal).each do |literal|
return Frequency[literal] if !literal || Symbol === literal
end
nil
end
end

def raises
if annotations['raises'].any?
types = annotations['raises'].select(&:type?)
types.map { |note| note.type } if types.any?
if types.any?
Types::UnionType.new(types.map { |note| note.type })
end
end
end
end
Expand Down
10 changes: 10 additions & 0 deletions lib/laser/standard_library/bignum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def &(num)
# overload: (Float) -> Float=
# overload: (Fixnum) -> Fixnum= | Bignum=
# overload: (Bignum) -> Fixnum= | Bignum=
# raises: never
def *(num)
end
# pure: true
Expand All @@ -31,6 +32,7 @@ def -(num)
# pure: true
# builtin: true
# returns: Fixnum= | Bignum=
# raises: never
def -@
end
# pure: true
Expand Down Expand Up @@ -97,6 +99,7 @@ def ^(num)
# pure: true
# builtin: true
# returns: Fixnum= | Bignum=
# raises: never
def abs
end
# pure: true
Expand All @@ -120,6 +123,7 @@ def eql?(other)
# pure: true
# builtin: true
# returns: Boolean
# raises: never
def even?
end
# pure: true
Expand All @@ -129,6 +133,7 @@ def fdiv(num)
# pure: true
# builtin: true
# returns: Fixnum= | Bignum=
# raises: never
def magnitude
end
# pure: true
Expand All @@ -139,6 +144,7 @@ def modulo(num)
# pure: true
# builtin: true
# returns: Boolean
# raises: never
def odd?
end
# pure: true
Expand All @@ -148,16 +154,19 @@ def remainder(other)
# pure: true
# builtin: true
# returns: Fixnum= | Bignum=
# raises: never
def size
end
# pure: true
# builtin: true
# returns: Float
# raises: never
def to_f
end
# pure: true
# builtin: true
# returns: String
# raises: never
def to_s
end
# pure: true
Expand All @@ -168,6 +177,7 @@ def |(num)
# pure: true
# builtin: true
# returns: Fixnum= | Bignum=
# raises: never
def ~
end
end
9 changes: 9 additions & 0 deletions lib/laser/standard_library/class_definitions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,15 @@ def puts(*to_put)
def block_given?
end
alias iterator? block_given?
# builtin: true
# raises: never
# pure: false
# predictable: false
# overload: () -> Float
# overload: Fixnum= -> Fixnum= | Bignum=
# overload: Bignum= -> Fixnum= | Bignum=
def rand(n=nil)
end
end

require 'basic_object'
Expand Down
12 changes: 12 additions & 0 deletions lib/laser/standard_library/fixnum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def &(num)
# overload: (Float) -> Float=
# overload: (Fixnum) -> Fixnum= | Bignum=
# overload: (Bignum) -> Fixnum= | Bignum=
# raises: never
def *(num)
end
# pure: true
Expand All @@ -31,6 +32,7 @@ def -(num)
# pure: true
# builtin: true
# returns: Fixnum= | Bignum=
# raises: never
def -@
end
# pure: true
Expand Down Expand Up @@ -96,6 +98,7 @@ def ^(num)
# pure: true
# builtin: true
# returns: Fixnum= | Bignum=
# raises: never
def abs
end
# pure: true
Expand All @@ -110,6 +113,7 @@ def divmod(other)
# pure: true
# builtin: true
# returns: Boolean
# raises: never
def even?
end
# pure: true
Expand All @@ -119,6 +123,7 @@ def fdiv(num)
# pure: true
# builtin: true
# returns: Fixnum= | Bignum=
# raises: never
def magnitude
end
# pure: true
Expand All @@ -128,31 +133,37 @@ def modulo(num)
# pure: true
# builtin: true
# returns: Boolean
# raises: never
def odd?
end
# pure: true
# builtin: true
# returns: Fixnum= | Bignum=
# raises: never
def size
end
# pure: true
# builtin: true
# returns: Fixnum= | Bignum=
# raises: never
def succ
end
# pure: true
# builtin: true
# returns: Float
# raises: never
def to_f
end
# pure: true
# builtin: true
# returns: String
# raises: never
def to_s
end
# pure: true
# builtin: true
# returns: Boolean
# raises: never
def zero?
end
# pure: true
Expand All @@ -163,6 +174,7 @@ def |(num)
# pure: true
# builtin: true
# returns: Fixnum= | Bignum=
# raises: never
def ~
end
end
Loading

0 comments on commit a172091

Please sign in to comment.