Class: TypeProf::Type::Hash::Elements
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Instance Chain:
|
|
Inherits: | Object |
Defined in: | lib/typeprof/container-type.rb |
Overview
Class Method Summary
- .dummy_elements
- .new(map_tys) ⇒ Elements constructor
Instance Attribute Summary
- #map_tys readonly
Instance Method Summary
- #[](key_ty)
- #each_free_type_variable(&blk)
- #globalize(env, visited, depth)
- #include_untyped?(scratch) ⇒ Boolean
- #limit_size(limit)
- #localize(env, alloc_site, depth)
- #match?(other) ⇒ Boolean
- #pretty_print(q)
- #screen_name(scratch)
- #squash
- #substitute(subst, depth)
- #to_keywords
- #to_local_type(id, base_ty)
- #union(other)
- #update(idx, ty)
Constructor Details
.new(map_tys) ⇒ Elements
# File 'lib/typeprof/container-type.rb', line 605
def initialize(map_tys) map_tys.each do |k_ty, v_ty| raise unless k_ty.is_a?(Type) raise unless v_ty.is_a?(Type) raise if k_ty.is_a?(Type::Union) raise if k_ty.is_a?(Type::Local) raise if k_ty.is_a?(Type::Array) raise if k_ty.is_a?(Type::Hash) end @map_tys = map_tys end
Class Method Details
.dummy_elements
[ GitHub ]Instance Attribute Details
#map_tys (readonly)
[ GitHub ]# File 'lib/typeprof/container-type.rb', line 621
attr_reader :map_tys
Instance Method Details
#[](key_ty)
[ GitHub ]#each_free_type_variable(&blk)
[ GitHub ]# File 'lib/typeprof/container-type.rb', line 717
def each_free_type_variable(&blk) @map_tys.each do |k, v| k.each_free_type_variable(&blk) v.each_free_type_variable(&blk) end end
#globalize(env, visited, depth)
[ GitHub ]
#include_untyped?(scratch) ⇒ Boolean
# File 'lib/typeprof/container-type.rb', line 810
def include_untyped?(scratch) @map_tys.each do |key, val| return true if key.include_untyped?(scratch) return true if val.include_untyped?(scratch) end false end
#limit_size(limit)
[ GitHub ]#localize(env, alloc_site, depth)
[ GitHub ]
#match?(other) ⇒ Boolean
# File 'lib/typeprof/container-type.rb', line 697
def match?(other) subst = nil other.map_tys.each do |k1, v1| subst2 = nil @map_tys.each do |k0, v0| subst3 = Type.match?(k0, k1) if subst3 subst4 = Type.match?(v0, v1) if subst4 subst2 = Type.merge_substitution(subst2, subst3) subst2 = Type.merge_substitution(subst2, subst4) end end end return nil unless subst2 subst = Type.merge_substitution(subst, subst2) end subst end
#pretty_print(q)
[ GitHub ]# File 'lib/typeprof/container-type.rb', line 682
def pretty_print(q) q.group(9, "Elements[", "]") do q.seplist(@map_tys) do |k_ty, v_ty| q.group do q.pp k_ty q.text '=>' q.group(1) do q.breakable '' q.pp v_ty end end end end end
#screen_name(scratch)
[ GitHub ]# File 'lib/typeprof/container-type.rb', line 663
def screen_name(scratch) if !@map_tys.empty? && @map_tys.all? {|k_ty,| k_ty.is_a?(Type::Symbol) } s = @map_tys.map do |k_ty, v_ty| v = v_ty.screen_name(scratch) "#{ k_ty.sym }: #{ v }" end.join(", ") "{#{ s }}" else k_ty = v_ty = Type.bot @map_tys.each do |k, v| k_ty = k_ty.union(k) v_ty = v_ty.union(v) end k_ty = k_ty.screen_name(scratch) v_ty = v_ty.screen_name(scratch) "Hash[#{ k_ty }, #{ v_ty }]" end end
#squash
[ GitHub ]#substitute(subst, depth)
[ GitHub ]# File 'lib/typeprof/container-type.rb', line 724
def substitute(subst, depth) map_tys = {} @map_tys.each do |k_ty_orig, v_ty_orig| k_ty = k_ty_orig.substitute(subst, depth) v_ty = v_ty_orig.substitute(subst, depth) k_ty.each_child_global do |k_ty| # This is a temporal hack to mitigate type explosion k_ty = Type.any if k_ty.is_a?(Type::Array) k_ty = Type.any if k_ty.is_a?(Type::Hash) if map_tys[k_ty] map_tys[k_ty] = map_tys[k_ty].union(v_ty) else map_tys[k_ty] = v_ty end end end Elements.new(map_tys) end
#to_keywords
[ GitHub ]# File 'lib/typeprof/container-type.rb', line 794
def to_keywords kw_tys = {} @map_tys.each do |key_ty, val_ty| if key_ty.is_a?(Type::Symbol) kw_tys[key_ty.sym] = val_ty else all_val_ty = Type.bot @map_tys.each do |_key_ty, val_ty| all_val_ty = all_val_ty.union(val_ty) end return { nil => all_val_ty } end end kw_tys end
#to_local_type(id, base_ty)
[ GitHub ]#union(other)
[ GitHub ]# File 'lib/typeprof/container-type.rb', line 778
def union(other) return self if self == other raise "Array::Elements merge Hash::Elements" if other.is_a?(Array::Elements) map_tys = @map_tys.dup other.map_tys.each do |k_ty, v_ty| if map_tys[k_ty] map_tys[k_ty] = map_tys[k_ty].union(v_ty) else map_tys[k_ty] = v_ty end end Elements.new(map_tys) end
#update(idx, ty)
[ GitHub ]# File 'lib/typeprof/container-type.rb', line 762
def update(idx, ty) map_tys = @map_tys.dup idx.each_child_global do |idx| # This is a temporal hack to mitigate type explosion idx = Type.any if idx.is_a?(Type::Array) idx = Type.any if idx.is_a?(Type::Hash) if map_tys[idx] map_tys[idx] = map_tys[idx].union(ty) else map_tys[idx] = ty end end Elements.new(map_tys) end