typeprof 0.21.6 → 0.21.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1d207fe000797f7326bd569640296801ff8047d8261b2461f22c744899753641
4
- data.tar.gz: ec87c3c228fc1326739f11fc6aaa63c4d5db46ad66bec55aab46d11d09953a50
3
+ metadata.gz: 6586977939af7be53d8c86c57f992569abffac1f011e7a435ea248835fabb5be
4
+ data.tar.gz: fec9babce50e7c23b31d053a137d7b16c9481ab51bc694d5ba1bf9fd720f63e2
5
5
  SHA512:
6
- metadata.gz: b6acf621b74c3468b14986c8c8616d0d6fc30a4e610dcf817ef550cc302d008cf916ea34f721a7e06038b48c77097e83a16f2e27233e93b18465f69288da4561
7
- data.tar.gz: 1c80d8d54c9cda86819eac0aec7b47393f01423a6506946240ebdef40b02ad90bae4c69c43ced7906ecc60945b85fee2baefc8c0aa717a8b95c570f9c25adcf4
6
+ metadata.gz: b49afd59c81f251f6526f4f297773983cad6e4ead9ffeff659d1257a5c0138f2b3f8016197fc5537b5bf1a53bebb1382bf3385ce377441a9bbff0f5852e0ac07
7
+ data.tar.gz: 3603cff083f9db951648cbc8069c017a42057eb6242963879634f7a0e64633632cb21e4bb51988f4a7d99e30de61e670e953409b64b6cc6bac5bbd771049666c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- typeprof (0.21.6)
4
+ typeprof (0.21.7)
5
5
  rbs (>= 1.8.1)
6
6
 
7
7
  GEM
@@ -11,7 +11,7 @@ GEM
11
11
  docile (1.4.0)
12
12
  power_assert (2.0.1)
13
13
  rake (13.0.1)
14
- rbs (3.0.1)
14
+ rbs (3.0.2)
15
15
  simplecov (0.21.2)
16
16
  docile (~> 1.1)
17
17
  simplecov-html (~> 0.11)
@@ -2231,6 +2231,34 @@ module TypeProf
2231
2231
  merge_env(ep.next, env)
2232
2232
  end
2233
2233
 
2234
+ private def ruby_3_3_keywords?
2235
+ @ruby_3_3_keywords ||=
2236
+ RubyVM::InstructionSequence.compile("foo(*a, **b)").to_a.last[-2][1][:orig_argc] == 2
2237
+ end
2238
+
2239
+ private def type_to_keywords(ty, ep)
2240
+ case ty
2241
+ when Type::Hash
2242
+ ty.elems.to_keywords
2243
+ when Type::Union
2244
+ hash_elems = nil
2245
+ ty.elems&.each do |(container_kind, base_type), elems|
2246
+ if container_kind == Type::Hash
2247
+ elems.to_keywords
2248
+ hash_elems = hash_elems ? hash_elems.union(elems) : elems
2249
+ end
2250
+ end
2251
+ if hash_elems
2252
+ hash_elems.to_keywords
2253
+ else
2254
+ { nil => Type.any }
2255
+ end
2256
+ else
2257
+ warn(ep, "non hash is passed to **kwarg?") unless ty == Type.any
2258
+ { nil => Type.any }
2259
+ end
2260
+ end
2261
+
2234
2262
  private def setup_actual_arguments(kind, operands, ep, env)
2235
2263
  opt, blk_iseq = operands
2236
2264
  flags = opt[:flag]
@@ -2284,42 +2312,33 @@ module TypeProf
2284
2312
  blk_ty = new_blk_ty
2285
2313
 
2286
2314
  if flag_args_splat
2287
- # assert !flag_args_kwarg
2288
- rest_ty = aargs.last
2289
- aargs = aargs[0..-2]
2290
- if flag_args_kw_splat
2291
- # XXX: The types contained in ActualArguments are expected to be all local types.
2292
- # This "globalize_type" breaks the invariant, and violates the assertion of Union#globalize that asserts @elems be nil.
2293
- # To fix this issue fundamentally, ActualArguments should keep all arguments as-is (as like the VM does),
2294
- # and globalize some types on the on-demand bases.
2295
- ty = globalize_type(rest_ty, env, ep)
2296
- if ty.is_a?(Type::Array)
2297
- _, (ty,) = ty.elems.take_last(1)
2298
- case ty
2299
- when Type::Hash
2300
- kw_tys = ty.elems.to_keywords
2301
- when Type::Union
2302
- hash_elems = nil
2303
- ty.elems&.each do |(container_kind, base_type), elems|
2304
- if container_kind == Type::Hash
2305
- elems.to_keywords
2306
- hash_elems = hash_elems ? hash_elems.union(elems) : elems
2307
- end
2308
- end
2309
- if hash_elems
2310
- kw_tys = hash_elems.to_keywords
2311
- else
2312
- kw_tys = { nil => Type.any }
2313
- end
2315
+ if ruby_3_3_keywords?
2316
+ if flag_args_kw_splat
2317
+ kw_tys = type_to_keywords(globalize_type(aargs[-1], env, ep), ep)
2318
+ aargs = aargs[0..-2]
2319
+ else
2320
+ kw_tys = {}
2321
+ end
2322
+ rest_ty = aargs.last
2323
+ aargs = aargs[0..-2]
2324
+ else
2325
+ rest_ty = aargs.last
2326
+ aargs = aargs[0..-2]
2327
+ if flag_args_kw_splat
2328
+ # XXX: The types contained in ActualArguments are expected to be all local types.
2329
+ # This "globalize_type" breaks the invariant, and violates the assertion of Union#globalize that asserts @elems be nil.
2330
+ # To fix this issue fundamentally, ActualArguments should keep all arguments as-is (as like the VM does),
2331
+ # and globalize some types on the on-demand bases.
2332
+ ty = globalize_type(rest_ty, env, ep)
2333
+ if ty.is_a?(Type::Array)
2334
+ _, (ty,) = ty.elems.take_last(1)
2335
+ kw_tys = type_to_keywords(ty, ep)
2314
2336
  else
2315
- warn(ep, "non hash is passed to **kwarg?") unless ty == Type.any
2316
- kw_tys = { nil => Type.any }
2337
+ raise NotImplementedError
2317
2338
  end
2318
2339
  else
2319
- raise NotImplementedError
2340
+ kw_tys = {}
2320
2341
  end
2321
- else
2322
- kw_tys = {}
2323
2342
  end
2324
2343
  aargs = ActualArguments.new(aargs, rest_ty, kw_tys, blk_ty)
2325
2344
  elsif flag_args_kw_splat
@@ -117,6 +117,12 @@ module TypeProf
117
117
  ty = Type::Array.new(Type::Array::Elements.new([], msig.rest_ty), Type::Instance.new(Type::Builtin[:ary]))
118
118
  ty = ty.substitute(cur_subst, Config.current.options[:type_depth_limit]).remove_type_vars
119
119
  nenv, rest_ty = scratch.localize_type(ty, nenv, callee_ep, alloc_site2)
120
+ # TODO: handle a case where rest_start is not found
121
+ nenv = nenv.local_update(rest_start, rest_ty)
122
+ elsif rest_start
123
+ alloc_site2 = alloc_site.add_id(idx += 1)
124
+ ty = Type::Array.new(Type::Array::Elements.new([], Type.any), Type::Instance.new(Type::Builtin[:ary]))
125
+ nenv, rest_ty = scratch.localize_type(ty, nenv, callee_ep, alloc_site2)
120
126
  nenv = nenv.local_update(rest_start, rest_ty)
121
127
  end
122
128
  if msig.post_tys
@@ -146,6 +152,11 @@ module TypeProf
146
152
  ty = ty.substitute(cur_subst, Config.current.options[:type_depth_limit]).remove_type_vars
147
153
  nenv, ty = scratch.localize_type(ty, nenv, callee_ep, alloc_site2)
148
154
  nenv = nenv.local_update(kw_rest, ty)
155
+ elsif kw_rest
156
+ alloc_site2 = alloc_site.add_id(:**)
157
+ ty = Type.gen_hash {}
158
+ nenv, ty = scratch.localize_type(ty, nenv, callee_ep, alloc_site2)
159
+ nenv = nenv.local_update(kw_rest, ty)
149
160
  end
150
161
  nenv = nenv.local_update(block_start, msig.blk_ty) if block_start
151
162
 
@@ -1,3 +1,3 @@
1
1
  module TypeProf
2
- VERSION = "0.21.6"
2
+ VERSION = "0.21.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typeprof
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.21.6
4
+ version: 0.21.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yusuke Endoh
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-28 00:00:00.000000000 Z
11
+ date: 2023-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rbs
@@ -74,7 +74,7 @@ licenses:
74
74
  metadata:
75
75
  homepage_uri: https://github.com/ruby/typeprof
76
76
  source_code_uri: https://github.com/ruby/typeprof
77
- post_install_message:
77
+ post_install_message:
78
78
  rdoc_options: []
79
79
  require_paths:
80
80
  - lib
@@ -90,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
90
  version: '0'
91
91
  requirements: []
92
92
  rubygems_version: 3.5.0.dev
93
- signing_key:
93
+ signing_key:
94
94
  specification_version: 4
95
95
  summary: TypeProf is a type analysis tool for Ruby code based on abstract interpretation
96
96
  test_files: []