Skip to content

Commit

Permalink
Refactoring all-user-methods analyses to their own module.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Edgar committed Aug 27, 2011
1 parent d0a421d commit 9e79c5f
Show file tree
Hide file tree
Showing 171 changed files with 231 additions and 207 deletions.
4 changes: 2 additions & 2 deletions lib/laser.rb
Expand Up @@ -94,7 +94,7 @@ def self.debug?

require 'laser/analysis/visitor'
require 'laser/analysis/annotations'
require 'laser/analysis/unused_methods'
require 'laser/analysis/method_analysis/method_analysis'
# Runners
require 'laser/runner'
require 'laser/rake/task'
Expand All @@ -105,4 +105,4 @@ def self.debug?
require 'laser/version'
# All methods created from the stdlib should never be marked as unused.
Laser::Analysis::Bootstrap.load_standard_library
# override info needs stdlib methods to be instantiated
# override info needs stdlib methods to be instantiated
2 changes: 1 addition & 1 deletion lib/laser/analysis/annotations.rb
Expand Up @@ -92,4 +92,4 @@ def self.add_computed_property(name, &blk)

Dir[File.expand_path(File.join(File.dirname(__FILE__), 'annotations', '**', '*.rb'))].each do |file|
load file
end
end
Expand Up @@ -63,4 +63,4 @@ def extract_comments(text)
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/laser/analysis/annotations/node_pointers_annotation.rb
Expand Up @@ -33,4 +33,4 @@ def default_visit(node)
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/laser/analysis/annotations/runtime_annotation.rb
Expand Up @@ -52,4 +52,4 @@ def visit_with_runtime(*nodes, new_runtime)
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/laser/analysis/argument_expansion.rb
Expand Up @@ -129,4 +129,4 @@ def node_constant_values(node)
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/laser/analysis/arity.rb
Expand Up @@ -31,4 +31,4 @@ def compatible?(other)
ANY = Arity.new(0..Float::INFINITY)
end
end
end
end
2 changes: 1 addition & 1 deletion lib/laser/analysis/bindings.rb
Expand Up @@ -141,4 +141,4 @@ def is_block?
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/laser/analysis/bootstrap/bootstrap.rb
Expand Up @@ -307,4 +307,4 @@ def self.stub_global_type(name, type)
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/laser/analysis/bootstrap/dispatch_results.rb
Expand Up @@ -189,4 +189,4 @@ def fails_dispatch(raise_type)
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/laser/analysis/bootstrap/laser_class.rb
Expand Up @@ -99,4 +99,4 @@ def inspect
end
end
end
end
end
15 changes: 8 additions & 7 deletions lib/laser/analysis/bootstrap/laser_method.rb
Expand Up @@ -67,6 +67,13 @@ def argument_annotations
end
end

# Combines all known return types for this method into one union type.
def combined_return_type
Types::UnionType.new(@type_instantiations.keys.map do |argtypes|
return_type_for_types(*argtypes)
end)
end

def yield_type
return annotated_yield_usage if annotated_yield_usage
return @yield_type if @yield_type
Expand Down Expand Up @@ -173,12 +180,6 @@ def check_return_type_against_expectations(return_type)
@proc.ast_node.add_error(ImproperOverrideTypeError.new(
"All methods named #{self.name} should return a subtype of #{expectation.inspect}",
@proc.ast_node))
elsif self.name.end_with?('?')
if !Types.subtype?(return_type, Types::BOOL_OR_NIL)
@proc.ast_node.add_error(ImproperOverrideTypeError.new(
"All methods whose name ends in ? should return a subtype of TrueClass | FalseClass | NilClass",
@proc.ast_node))
end
end
end

Expand Down Expand Up @@ -284,4 +285,4 @@ def refine_arity(new_arity)
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/laser/analysis/bootstrap/laser_module.rb
Expand Up @@ -404,4 +404,4 @@ def module_function(*args)
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/laser/analysis/bootstrap/laser_module_copy.rb
Expand Up @@ -71,4 +71,4 @@ def instance_methods(include_superclass = true)
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/laser/analysis/bootstrap/laser_object.rb
Expand Up @@ -66,4 +66,4 @@ def instance_variable_set(var, value)
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/laser/analysis/bootstrap/laser_proc.rb
Expand Up @@ -152,4 +152,4 @@ def raises
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/laser/analysis/bootstrap/laser_singleton_class.rb
Expand Up @@ -41,4 +41,4 @@ def get_instance(scope=nil)
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/laser/analysis/comments.rb
Expand Up @@ -32,4 +32,4 @@ def annotation_map
@map = annotations.inject(initial) { |acc, note| acc[note.name] << note; acc }
end
end
end
end
2 changes: 1 addition & 1 deletion lib/laser/analysis/control_flow.rb
Expand Up @@ -26,4 +26,4 @@ def self.perform_cfg_analysis(tree, text, opts={})
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/laser/analysis/control_flow/alias_analysis.rb
Expand Up @@ -28,4 +28,4 @@ def value_aliases(value_to_match)
end
end # ControlFlow
end # Analysis
end #
end #
2 changes: 1 addition & 1 deletion lib/laser/analysis/control_flow/basic_block.rb
Expand Up @@ -102,4 +102,4 @@ def instructions
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/laser/analysis/control_flow/cfg_builder.rb
Expand Up @@ -2503,4 +2503,4 @@ def start_block(block)
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/laser/analysis/control_flow/cfg_instruction.rb
Expand Up @@ -187,4 +187,4 @@ def operand_range
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/laser/analysis/control_flow/constant_propagation.rb
Expand Up @@ -654,4 +654,4 @@ def validate_tuple_expectation(instruction)
end # ConstantPropagation
end # ControlFlow
end # Analysis
end #
end #
2 changes: 1 addition & 1 deletion lib/laser/analysis/control_flow/control_flow_graph.rb
Expand Up @@ -372,4 +372,4 @@ def kill_unexecuted_edges(remove=false)
end
end
end
end
end
Expand Up @@ -18,4 +18,4 @@ def guaranteed_super_on_success?
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/laser/analysis/control_flow/lifetime_analysis.rb
Expand Up @@ -88,4 +88,4 @@ def find_live_visited(current, visit, live)
end # module LifetimeAnalysis
end # module ControlFlow
end # module Analysis
end # module Laser
end # module Laser
2 changes: 1 addition & 1 deletion lib/laser/analysis/control_flow/method_call_search.rb
Expand Up @@ -22,4 +22,4 @@ def find_method_calls(method_to_find, opts)
end
end # ControlFlow
end # Analysis
end #
end #
2 changes: 1 addition & 1 deletion lib/laser/analysis/control_flow/raise_properties.rb
Expand Up @@ -22,4 +22,4 @@ def find_raise_frequency
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/laser/analysis/control_flow/simulation.rb
Expand Up @@ -387,4 +387,4 @@ def simulate_module_eval(receiver, args, block)
end # Simulation
end # ControlFlow
end # Analysis
end # Laser
end # Laser
Expand Up @@ -182,4 +182,4 @@ def new_ssa_name(temp)
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/laser/analysis/control_flow/unreachability_analysis.rb
Expand Up @@ -54,4 +54,4 @@ def dfs_for_dead_code(node)
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/laser/analysis/control_flow/unused_variables.rb
Expand Up @@ -88,4 +88,4 @@ def killable_with_unused_target?(insn)
end
end # ControlFlow
end # Analysis
end #
end #
2 changes: 1 addition & 1 deletion lib/laser/analysis/control_flow/yield_properties.rb
Expand Up @@ -100,4 +100,4 @@ def potential_block_calls(block_value = nil, opts)
end
end # ControlFlow
end # Analysis
end #
end #
2 changes: 1 addition & 1 deletion lib/laser/analysis/errors.rb
Expand Up @@ -136,4 +136,4 @@ class DiscardedRHSError < Laser::Error
class UnassignedLHSError < Laser::Error
severity SIMPLE_ERROR
end
end
end
2 changes: 1 addition & 1 deletion lib/laser/analysis/laser_utils.rb
Expand Up @@ -15,4 +15,4 @@ def normal_class_for(arg)
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/laser/analysis/lexical_analysis.rb
Expand Up @@ -169,4 +169,4 @@ def _split_body_with_raw_token(body, token)
return body[0,max], body[max..-1]
end
end
end
end
26 changes: 26 additions & 0 deletions lib/laser/analysis/method_analysis/method_analysis.rb
@@ -0,0 +1,26 @@
require_relative 'unused_methods'
module Laser
module Analysis
# General-purpose method analysis functions.
module MethodAnalysis
extend UnusedMethodDetection
def self.each_user_method
return enum_for(__method__) unless block_given?
classes = Set[]
Analysis::ProtocolRegistry.class_protocols.each do |key, klass|
if should_analyze?(klass) && !classes.include?(klass)
classes << klass
klass.__all_instance_methods(false).each do |name|
yield klass.instance_method(name)
end
end
end
end

def self.should_analyze?(klass)
!(Analysis::LaserSingletonClass === klass) ||
klass < ClassRegistry['Module']
end
end
end
end
11 changes: 11 additions & 0 deletions lib/laser/analysis/method_analysis/unused_methods.rb
@@ -0,0 +1,11 @@
module Laser
module Analysis
module UnusedMethodDetection
def unused_methods
each_user_method.reject do |method|
method.dispatched? || method.builtin || method.special
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/laser/analysis/method_call.rb
Expand Up @@ -65,4 +65,4 @@ def arg_node
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/laser/analysis/override_safety_info.rb
Expand Up @@ -76,4 +76,4 @@ class << self
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/laser/analysis/protocol_registry.rb
Expand Up @@ -27,4 +27,4 @@ def self.[](class_name)
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/laser/analysis/scope.rb
Expand Up @@ -115,4 +115,4 @@ def lookup_local(str)
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/laser/analysis/sexp.rb
Expand Up @@ -156,4 +156,4 @@ def method_call
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/laser/analysis/sexp_analysis.rb
Expand Up @@ -37,4 +37,4 @@ def find_sexps(type, tree = self.parse(self.body))
result
end
end
end
end
2 changes: 1 addition & 1 deletion lib/laser/analysis/sexp_extensions/constant_extraction.rb
Expand Up @@ -112,4 +112,4 @@ def constant_value
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/laser/analysis/sexp_extensions/source_location.rb
Expand Up @@ -161,4 +161,4 @@ def text_at(location, offset, length)
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/laser/analysis/sexp_extensions/type_inference.rb
Expand Up @@ -44,4 +44,4 @@ def expr_type
end
end
end
end
end

0 comments on commit 9e79c5f

Please sign in to comment.