Runtime assertions for Ruby literal.fun
ruby
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix issue with constraint allocations (#273)

authored by

Joel Drapper and committed by
GitHub
58a94a85 3589dea4

+30 -6
+18 -2
.github/workflows/ruby.yml
··· 23 23 fail-fast: false 24 24 matrix: 25 25 ruby-version: ${{ fromJson(needs.ruby-versions.outputs.versions) }} 26 - 27 26 steps: 28 27 - uses: actions/checkout@v3 29 28 - name: Set up Ruby ··· 34 33 bundler-args: --without development 35 34 - name: Quickdraw tests 36 35 run: bundle exec qt -t 1 "./test/**/*.test.rb" 36 + allocations_test: 37 + runs-on: ubuntu-latest 38 + strategy: 39 + fail-fast: false 40 + matrix: 41 + ruby-version: 42 + ["3.2", "3.3", "3.4", "head", "truffleruby", "truffleruby-head"] 43 + steps: 44 + - uses: actions/checkout@v3 45 + - name: Set up Ruby 46 + uses: ruby/setup-ruby@v1 47 + with: 48 + ruby-version: ${{ matrix.ruby-version }} 49 + bundler-cache: true # runs 'bundle install' and caches installed gems automatically 50 + bundler-args: --without development 51 + - name: Test allocations 52 + run: bundle exec ./allocations_test.rb 37 53 rubocop: 38 54 runs-on: ubuntu-latest 39 55 strategy: 40 56 matrix: 41 - ruby-version: ['3.3'] 57 + ruby-version: ["3.4"] 42 58 steps: 43 59 - uses: actions/checkout@v3 44 60 - name: Set up Ruby
+1 -1
.ruby-version
··· 1 - 3.3.0 1 + 3.4.1
+1
.tool-versions
··· 1 + ruby 3.4.1
-1
Gemfile
··· 8 8 gem "benchmark-ips" 9 9 10 10 group :development do 11 - gem "solargraph", platform: :ruby 12 11 gem "rubocop", platform: :ruby 13 12 gem "ruby-lsp", platform: :ruby 14 13 gem "simplecov", platform: :ruby
+3
allocations_test.rb
··· 4 4 # NOTE: This is not a quickdraw test becuase it needs to be run in a single thread. 5 5 6 6 require "literal" 7 + require "set" 8 + 7 9 include Literal::Types 8 10 9 11 def count_allocations ··· 13 15 end 14 16 15 17 def count_warm_allocations(&) 18 + count_allocations(&) 16 19 count_allocations(&) 17 20 count_allocations(&) 18 21 end
+7 -2
lib/literal/types/constraint_type.rb
··· 25 25 i += 1 26 26 end 27 27 28 + result = true 29 + 28 30 @property_constraints.each do |a, t| 29 - return false unless t === value.public_send(a) 31 + # We intentionally don’t return early here becuase it triggers an allocation. 32 + if result && !(t === value.public_send(a)) 33 + result = false 34 + end 30 35 rescue NoMethodError => e 31 36 raise unless e.name == a && e.receiver == value 32 37 return false 33 38 end 34 39 35 - true 40 + result 36 41 end 37 42 38 43 def >=(other)