Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
mbj committed Oct 30, 2024
1 parent 2c14a45 commit 4082af9
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 129 deletions.
16 changes: 16 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# v0.13.0 unreleased

Significant unparser upgrade. Mutant now:

* Avoids emitting mutations that do not round trip against unparsers API.
* Does not emit mutations anymore that are prone to not round tripping.

This change generates less mutations, and currently slightly increases boot time.
But the number of mutations that are hitting the test suite is much lower so it should balance.

Also its a good step towards parallel mutation generation reducing boot times.

This release removes all mutations that modify the local variable scope, mostly as these are
prone to not round trip via unparser. Unused local variables are now also reported by ruby / rubocop
so mutant does not have to spend dynamic analysis capabilty on these anymore.

# v0.12.5 unreleased

* [#1458](https://github.com/mbj/mutant/pull/1458)
Expand Down
4 changes: 0 additions & 4 deletions lib/mutant/mutation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ def insert(kernel)
end
end

# Rendered mutation diff
#
# @return [String, nil]
# the diff, if present
def diff
Unparser::Diff.build(original_source, source)
end
Expand Down
10 changes: 1 addition & 9 deletions lib/mutant/mutator/node/argument.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,7 @@ class Argument < self

private

def dispatch
emit_name_mutation
end

def emit_name_mutation
return if skip?
emit_name(:"#{UNDERSCORE}#{name}")
end
def dispatch; end

def skip?
name.start_with?(UNDERSCORE)
Expand All @@ -42,7 +35,6 @@ class Optional < self
private

def dispatch
emit_name_mutation
emit_required_mutation
emit_default_mutations
end
Expand Down
13 changes: 0 additions & 13 deletions lib/mutant/mutator/node/arguments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,11 @@ class Arguments < self
private

def dispatch
emit_argument_presence
emit_argument_mutations
emit_mlhs_expansion
emit_procarg0_removal
end

def emit_argument_presence
emit_type unless removed_block_arg?(EMPTY_ARRAY) || forward_arg?

children.each_with_index do |removed, index|
new_arguments = children.dup
new_arguments.delete_at(index)
unless forward_type?(removed) || removed_block_arg?(new_arguments) || only_mlhs?(new_arguments)
emit_type(*new_arguments)
end
end
end

def forward_type?(removed)
n_forward_arg?(removed) || n_restarg?(removed) || n_kwrestarg?(removed)
end
Expand Down
8 changes: 7 additions & 1 deletion lib/mutant/mutator/node/block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ def mutate_body
emit_body(N_RAISE)

return unless body
emit(body) unless body_has_control?

emit_body_promotion

emit_body_mutations do |node|
!(n_nil?(node) && unconditional_loop?)
end
Expand All @@ -45,6 +47,10 @@ def body_has_control?
false
end

def emit_body_promotion
emit(body) if !body_has_control? && fix_me_argument_need_to_be_empty_on_block)
end

def mutate_body_receiver
return if n_lambda?(send) || !n_send?(body)

Expand Down
10 changes: 9 additions & 1 deletion lib/mutant/subject.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,22 @@ def mutations
Mutation::Evil
.from_node(subject: self, node: wrap_node(mutant))
.either(
->(validation) { $stderr.puts("generated invalid mutation: #{validation.report}") },
->(validation) { report_violation(mutant, validation) },
aggregate.method(:<<)
)
end
)
end
memoize :mutations

def report_violation(mutant, validation)
mutation = Mutation::Evil.new(subject: self, node: wrap_node(mutant), source: validation.original_source.from_right)
puts mutation.diff.colorized_diff
puts validation.report
fail
end
private :report_violation

def inline_disabled?
config.inline_disable
end
Expand Down
21 changes: 0 additions & 21 deletions meta/block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,16 @@
singleton_mutations
mutation 'foo'
mutation 'foo { |a, b| raise }'
mutation 'foo { |a, _b| }'
mutation 'foo { |_a, b| }'
mutation 'foo { |a, | }'
mutation 'foo { |b, | }'
mutation 'foo { || }'
end

Mutant::Meta::Example.add :block do
source 'foo { |(a, b), c| }'

singleton_mutations
mutation 'foo { || }'
mutation 'foo { |a, b, c| }'
mutation 'foo { |(a, b), c| raise }'
mutation 'foo { |(a), c| }'
mutation 'foo { |(b), c| }'
mutation 'foo { |c, | }'
mutation 'foo { |(_a, b), c| }'
mutation 'foo { |(a, _b), c| }'
mutation 'foo { |(a, b), _c| }'
mutation 'foo'
end

Expand All @@ -56,22 +46,11 @@
mutation 'foo {}'
end

Mutant::Meta::Example.add :block do
source 'foo { |_a| }'

singleton_mutations
mutation 'foo { || }'
mutation 'foo { |_a| raise }'
mutation 'foo'
end

Mutant::Meta::Example.add :block do
source 'foo { |a| }'

singleton_mutations
mutation 'foo { || }'
mutation 'foo { |a| raise }'
mutation 'foo { |_a| }'
mutation 'foo'
end

Expand Down
2 changes: 0 additions & 2 deletions meta/block_pass.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@
Mutant::Meta::Example.add :block_pass do
source 'def foo(a, &); foo(&); end'

mutation 'def foo(&); foo(&); end'
mutation 'def foo(_a, &); foo(&); end'
mutation 'def foo(a, &); end'
mutation 'def foo(a, &); foo; end'
mutation 'def foo(a, &); nil; end'
Expand Down
1 change: 0 additions & 1 deletion meta/blockarg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@

singleton_mutations
mutation 'foo { |&bar| raise }'
mutation 'foo {}'
mutation 'foo'
end
54 changes: 0 additions & 54 deletions meta/def.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,6 @@
Mutant::Meta::Example.add :def do
source 'def foo(a, b); end'

# Deletion of each argument
mutation 'def foo(a); end'
mutation 'def foo(b); end'

# Deletion of all arguments
mutation 'def foo; end'

# Rename each argument
mutation 'def foo(_a, b); end'
mutation 'def foo(a, _b); end'

# Mutation of body
mutation 'def foo(a, b); raise; end'
mutation 'def foo(a, b); super; end'
Expand All @@ -87,51 +76,23 @@
Mutant::Meta::Example.add :def do
source 'def foo(a, b = nil); true; end'

mutation 'def foo(_a, b = nil); true; end'
mutation 'def foo(a, b = nil); end'
mutation 'def foo; true; end'
mutation 'def foo(a, b = nil); raise; end'
mutation 'def foo(a, b = nil); false; end'
mutation 'def foo(a); true; end'
mutation 'def foo(a, b = nil); b = nil; true; end'
mutation 'def foo(b = nil); true; end'
mutation 'def foo(a, _b = nil); true; end'
mutation 'def foo(a, b); true; end'
mutation 'def foo(a, b = nil); super; end'
end

Mutant::Meta::Example.add :def, :arg do
source 'def foo(_unused); end'

mutation 'def foo(_unused); raise; end'
mutation 'def foo; end'
mutation 'def foo(_unused); super; end'
end

Mutant::Meta::Example.add :def do
source 'def foo(_unused = true); end'

mutation 'def foo(_unused = false); end'
mutation 'def foo(_unused = true); raise; end'
mutation 'def foo(_unused); end'
mutation 'def foo; end'
mutation 'def foo(_unused = true); super; end'
end

Mutant::Meta::Example.add :def do
source 'def foo(a = 0, b = 0); end'
mutation 'def foo(a = 0, _b = 0); end'
mutation 'def foo(_a = 0, b = 0); end'
mutation 'def foo(a = 0, b = 1); end'
mutation 'def foo(a = 0, b = -1); end'
mutation 'def foo(a = 0, b = nil); end'
mutation 'def foo(a = -1, b = 0); end'
mutation 'def foo(a = nil, b = 0); end'
mutation 'def foo(a = 1, b = 0); end'
mutation 'def foo(a = 0); end'
mutation 'def foo(b = 0); end'
mutation 'def foo(a, b = 0); end'
mutation 'def foo; end'
mutation 'def foo(a = 0, b = 0); a = 0; end'
mutation 'def foo(a = 0, b = 0); b = 0; end'
mutation 'def foo(a = 0, b = 0); raise; end'
Expand All @@ -142,9 +103,7 @@
source 'def foo(a = true); end'

mutation 'def foo(a); end'
mutation 'def foo(); end'
mutation 'def foo(a = false); end'
mutation 'def foo(_a = true); end'
mutation 'def foo(a = true); raise; end'
mutation 'def foo(a = true); a = true; end'
mutation 'def foo(a = true); super; end'
Expand Down Expand Up @@ -172,17 +131,6 @@
Mutant::Meta::Example.add :def do
source 'def self.foo(a, b); end'

# Deletion of each argument
mutation 'def self.foo(a); end'
mutation 'def self.foo(b); end'

# Deletion of all arguments
mutation 'def self.foo; end'

# Rename each argument
mutation 'def self.foo(_a, b); end'
mutation 'def self.foo(a, _b); end'

# Mutation of body
mutation 'def self.foo(a, b); raise; end'
mutation 'def self.foo(a, b); super; end'
Expand Down Expand Up @@ -278,10 +226,8 @@
Mutant::Meta::Example.add :def do
source 'def foo(a, ...); end'

mutation 'def foo(_a, ...); end'
mutation 'def foo(a, ...); raise; end'
mutation 'def foo(a, ...); super; end'
mutation 'def foo(...); end'
end

Mutant::Meta::Example.add :def, :send do
Expand Down
2 changes: 0 additions & 2 deletions meta/kwarg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
Mutant::Meta::Example.add :kwarg do
source 'def foo(bar:); end'

mutation 'def foo; end'
mutation 'def foo(bar:); raise; end'
mutation 'def foo(bar:); super; end'
mutation 'def foo(_bar:); end'
end
2 changes: 0 additions & 2 deletions meta/kwoptarg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
Mutant::Meta::Example.add :kwarg do
source 'def foo(bar: baz); end'

mutation 'def foo; end'
mutation 'def foo(bar: baz); raise; end'
mutation 'def foo(bar: baz); super; end'
mutation 'def foo(bar: nil); end'
mutation 'def foo(bar:); end'
mutation 'def foo(_bar: baz); end'
end
19 changes: 0 additions & 19 deletions meta/procarg_zero.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,6 @@

singleton_mutations
mutation 'foo { |a| raise }'
mutation 'foo { |_a| }'
mutation 'foo { }'
mutation 'foo'
end

Mutant::Meta::Example.add :procarg0 do
source 'foo { |_a| }'

singleton_mutations
mutation 'foo { |_a| raise }'
mutation 'foo { }'
mutation 'foo'
end

Expand All @@ -24,8 +13,6 @@

singleton_mutations
mutation 'foo { |(a)| raise }'
mutation 'foo { |(_a)| }'
mutation 'foo { }'
mutation 'foo'
end

Expand All @@ -35,9 +22,6 @@
singleton_mutations
mutation 'foo { |a, b| }'
mutation 'foo { |(a, b)| raise }'
mutation 'foo { |(_a, b)| }'
mutation 'foo { |(a, _b)| }'
mutation 'foo { }'
mutation 'foo'
end

Expand All @@ -46,7 +30,6 @@

singleton_mutations
mutation 'foo { |(*)| raise }'
mutation 'foo { }'
mutation 'foo'
end

Expand All @@ -56,7 +39,5 @@
singleton_mutations
mutation 'foo { |a, (*)| }'
mutation 'foo { |(a, (*))| raise }'
mutation 'foo { |(_a, (*))| }'
mutation 'foo { }'
mutation 'foo'
end

0 comments on commit 4082af9

Please sign in to comment.