rbs-relaxed 3.9.0.1
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 +7 -0
- data/.github/dependabot.yml +22 -0
- data/.github/workflows/comments.yml +35 -0
- data/.github/workflows/dependabot.yml +30 -0
- data/.github/workflows/ruby.yml +82 -0
- data/.github/workflows/typecheck.yml +38 -0
- data/.github/workflows/windows.yml +43 -0
- data/.gitignore +23 -0
- data/.rubocop.yml +68 -0
- data/BSDL +22 -0
- data/CHANGELOG.md +1868 -0
- data/COPYING +56 -0
- data/README.md +203 -0
- data/Rakefile +417 -0
- data/Steepfile +44 -0
- data/config.yml +313 -0
- data/core/array.rbs +4062 -0
- data/core/basic_object.rbs +375 -0
- data/core/binding.rbs +150 -0
- data/core/builtin.rbs +277 -0
- data/core/class.rbs +220 -0
- data/core/comparable.rbs +171 -0
- data/core/complex.rbs +786 -0
- data/core/constants.rbs +96 -0
- data/core/data.rbs +415 -0
- data/core/dir.rbs +981 -0
- data/core/encoding.rbs +1371 -0
- data/core/enumerable.rbs +2405 -0
- data/core/enumerator/product.rbs +92 -0
- data/core/enumerator.rbs +630 -0
- data/core/env.rbs +6 -0
- data/core/errno.rbs +673 -0
- data/core/errors.rbs +760 -0
- data/core/exception.rbs +485 -0
- data/core/false_class.rbs +82 -0
- data/core/fiber.rbs +550 -0
- data/core/fiber_error.rbs +11 -0
- data/core/file.rbs +2936 -0
- data/core/file_test.rbs +331 -0
- data/core/float.rbs +1151 -0
- data/core/gc.rbs +644 -0
- data/core/global_variables.rbs +184 -0
- data/core/hash.rbs +1861 -0
- data/core/integer.rbs +1413 -0
- data/core/io/buffer.rbs +984 -0
- data/core/io/wait.rbs +70 -0
- data/core/io.rbs +3406 -0
- data/core/kernel.rbs +3096 -0
- data/core/marshal.rbs +207 -0
- data/core/match_data.rbs +635 -0
- data/core/math.rbs +729 -0
- data/core/method.rbs +386 -0
- data/core/module.rbs +1704 -0
- data/core/nil_class.rbs +209 -0
- data/core/numeric.rbs +818 -0
- data/core/object.rbs +110 -0
- data/core/object_space/weak_key_map.rbs +166 -0
- data/core/object_space.rbs +190 -0
- data/core/proc.rbs +868 -0
- data/core/process.rbs +2296 -0
- data/core/ractor.rbs +1068 -0
- data/core/random.rbs +237 -0
- data/core/range.rbs +1107 -0
- data/core/rational.rbs +531 -0
- data/core/rb_config.rbs +88 -0
- data/core/rbs/unnamed/argf.rbs +1229 -0
- data/core/rbs/unnamed/env_class.rbs +1209 -0
- data/core/rbs/unnamed/random.rbs +293 -0
- data/core/refinement.rbs +59 -0
- data/core/regexp.rbs +1930 -0
- data/core/ruby_vm.rbs +765 -0
- data/core/rubygems/basic_specification.rbs +6 -0
- data/core/rubygems/config_file.rbs +38 -0
- data/core/rubygems/dependency_installer.rbs +6 -0
- data/core/rubygems/errors.rbs +176 -0
- data/core/rubygems/installer.rbs +15 -0
- data/core/rubygems/path_support.rbs +6 -0
- data/core/rubygems/platform.rbs +7 -0
- data/core/rubygems/request_set.rbs +49 -0
- data/core/rubygems/requirement.rbs +148 -0
- data/core/rubygems/rubygems.rbs +1171 -0
- data/core/rubygems/source_list.rbs +15 -0
- data/core/rubygems/specification.rbs +23 -0
- data/core/rubygems/stream_ui.rbs +5 -0
- data/core/rubygems/uninstaller.rbs +10 -0
- data/core/rubygems/version.rbs +294 -0
- data/core/set.rbs +621 -0
- data/core/signal.rbs +100 -0
- data/core/string.rbs +3583 -0
- data/core/struct.rbs +667 -0
- data/core/symbol.rbs +475 -0
- data/core/thread.rbs +1765 -0
- data/core/thread_group.rbs +79 -0
- data/core/time.rbs +1762 -0
- data/core/trace_point.rbs +477 -0
- data/core/true_class.rbs +98 -0
- data/core/unbound_method.rbs +329 -0
- data/core/warning.rbs +87 -0
- data/docs/CONTRIBUTING.md +106 -0
- data/docs/architecture.md +110 -0
- data/docs/collection.md +192 -0
- data/docs/data_and_struct.md +86 -0
- data/docs/gem.md +57 -0
- data/docs/rbs_by_example.md +309 -0
- data/docs/repo.md +125 -0
- data/docs/sigs.md +167 -0
- data/docs/stdlib.md +147 -0
- data/docs/syntax.md +910 -0
- data/docs/tools.md +17 -0
- data/exe/rbs +7 -0
- data/ext/rbs_extension/extconf.rb +15 -0
- data/ext/rbs_extension/lexer.c +2728 -0
- data/ext/rbs_extension/lexer.h +179 -0
- data/ext/rbs_extension/lexer.re +147 -0
- data/ext/rbs_extension/lexstate.c +175 -0
- data/ext/rbs_extension/location.c +325 -0
- data/ext/rbs_extension/location.h +85 -0
- data/ext/rbs_extension/main.c +33 -0
- data/ext/rbs_extension/parser.c +2973 -0
- data/ext/rbs_extension/parser.h +18 -0
- data/ext/rbs_extension/parserstate.c +397 -0
- data/ext/rbs_extension/parserstate.h +163 -0
- data/ext/rbs_extension/rbs_extension.h +31 -0
- data/ext/rbs_extension/unescape.c +32 -0
- data/goodcheck.yml +91 -0
- data/include/rbs/constants.h +82 -0
- data/include/rbs/ruby_objs.h +72 -0
- data/include/rbs/util/rbs_constant_pool.h +219 -0
- data/include/rbs.h +7 -0
- data/lib/rbs/ancestor_graph.rb +92 -0
- data/lib/rbs/annotate/annotations.rb +199 -0
- data/lib/rbs/annotate/formatter.rb +92 -0
- data/lib/rbs/annotate/rdoc_annotator.rb +400 -0
- data/lib/rbs/annotate/rdoc_source.rb +131 -0
- data/lib/rbs/annotate.rb +8 -0
- data/lib/rbs/ast/annotation.rb +29 -0
- data/lib/rbs/ast/comment.rb +29 -0
- data/lib/rbs/ast/declarations.rb +467 -0
- data/lib/rbs/ast/directives.rb +49 -0
- data/lib/rbs/ast/members.rb +451 -0
- data/lib/rbs/ast/type_param.rb +225 -0
- data/lib/rbs/ast/visitor.rb +137 -0
- data/lib/rbs/buffer.rb +67 -0
- data/lib/rbs/builtin_names.rb +58 -0
- data/lib/rbs/cli/colored_io.rb +48 -0
- data/lib/rbs/cli/diff.rb +83 -0
- data/lib/rbs/cli/validate.rb +357 -0
- data/lib/rbs/cli.rb +1223 -0
- data/lib/rbs/collection/cleaner.rb +38 -0
- data/lib/rbs/collection/config/lockfile.rb +92 -0
- data/lib/rbs/collection/config/lockfile_generator.rb +218 -0
- data/lib/rbs/collection/config.rb +81 -0
- data/lib/rbs/collection/installer.rb +32 -0
- data/lib/rbs/collection/sources/base.rb +14 -0
- data/lib/rbs/collection/sources/git.rb +258 -0
- data/lib/rbs/collection/sources/local.rb +81 -0
- data/lib/rbs/collection/sources/rubygems.rb +48 -0
- data/lib/rbs/collection/sources/stdlib.rb +50 -0
- data/lib/rbs/collection/sources.rb +38 -0
- data/lib/rbs/collection.rb +16 -0
- data/lib/rbs/constant.rb +28 -0
- data/lib/rbs/definition.rb +401 -0
- data/lib/rbs/definition_builder/ancestor_builder.rb +620 -0
- data/lib/rbs/definition_builder/method_builder.rb +254 -0
- data/lib/rbs/definition_builder.rb +845 -0
- data/lib/rbs/diff.rb +125 -0
- data/lib/rbs/environment/use_map.rb +77 -0
- data/lib/rbs/environment.rb +829 -0
- data/lib/rbs/environment_loader.rb +173 -0
- data/lib/rbs/environment_walker.rb +155 -0
- data/lib/rbs/errors.rb +645 -0
- data/lib/rbs/factory.rb +18 -0
- data/lib/rbs/file_finder.rb +28 -0
- data/lib/rbs/location_aux.rb +138 -0
- data/lib/rbs/locator.rb +243 -0
- data/lib/rbs/method_type.rb +143 -0
- data/lib/rbs/namespace.rb +125 -0
- data/lib/rbs/parser/lex_result.rb +15 -0
- data/lib/rbs/parser/token.rb +23 -0
- data/lib/rbs/parser_aux.rb +114 -0
- data/lib/rbs/prototype/helpers.rb +140 -0
- data/lib/rbs/prototype/node_usage.rb +99 -0
- data/lib/rbs/prototype/rb.rb +840 -0
- data/lib/rbs/prototype/rbi.rb +641 -0
- data/lib/rbs/prototype/runtime/helpers.rb +59 -0
- data/lib/rbs/prototype/runtime/reflection.rb +19 -0
- data/lib/rbs/prototype/runtime/value_object_generator.rb +279 -0
- data/lib/rbs/prototype/runtime.rb +667 -0
- data/lib/rbs/repository.rb +127 -0
- data/lib/rbs/resolver/constant_resolver.rb +219 -0
- data/lib/rbs/resolver/type_name_resolver.rb +91 -0
- data/lib/rbs/sorter.rb +198 -0
- data/lib/rbs/substitution.rb +83 -0
- data/lib/rbs/subtractor.rb +201 -0
- data/lib/rbs/test/errors.rb +80 -0
- data/lib/rbs/test/guaranteed.rb +30 -0
- data/lib/rbs/test/hook.rb +212 -0
- data/lib/rbs/test/observer.rb +19 -0
- data/lib/rbs/test/setup.rb +84 -0
- data/lib/rbs/test/setup_helper.rb +50 -0
- data/lib/rbs/test/tester.rb +167 -0
- data/lib/rbs/test/type_check.rb +435 -0
- data/lib/rbs/test.rb +112 -0
- data/lib/rbs/type_alias_dependency.rb +100 -0
- data/lib/rbs/type_alias_regularity.rb +126 -0
- data/lib/rbs/type_name.rb +109 -0
- data/lib/rbs/types.rb +1596 -0
- data/lib/rbs/unit_test/convertibles.rb +176 -0
- data/lib/rbs/unit_test/spy.rb +138 -0
- data/lib/rbs/unit_test/type_assertions.rb +347 -0
- data/lib/rbs/unit_test/with_aliases.rb +143 -0
- data/lib/rbs/unit_test.rb +6 -0
- data/lib/rbs/validator.rb +186 -0
- data/lib/rbs/variance_calculator.rb +189 -0
- data/lib/rbs/vendorer.rb +71 -0
- data/lib/rbs/version.rb +5 -0
- data/lib/rbs/writer.rb +424 -0
- data/lib/rbs.rb +94 -0
- data/lib/rdoc/discover.rb +20 -0
- data/lib/rdoc_plugin/parser.rb +163 -0
- data/rbs-relaxed.gemspec +48 -0
- data/schema/annotation.json +14 -0
- data/schema/comment.json +26 -0
- data/schema/decls.json +326 -0
- data/schema/function.json +87 -0
- data/schema/location.json +56 -0
- data/schema/members.json +266 -0
- data/schema/methodType.json +50 -0
- data/schema/typeParam.json +36 -0
- data/schema/types.json +317 -0
- data/sig/ancestor_builder.rbs +163 -0
- data/sig/ancestor_graph.rbs +60 -0
- data/sig/annotate/annotations.rbs +102 -0
- data/sig/annotate/formatter.rbs +24 -0
- data/sig/annotate/rdoc_annotater.rbs +82 -0
- data/sig/annotate/rdoc_source.rbs +30 -0
- data/sig/annotation.rbs +27 -0
- data/sig/buffer.rbs +32 -0
- data/sig/builtin_names.rbs +44 -0
- data/sig/cli/colored_io.rbs +15 -0
- data/sig/cli/diff.rbs +21 -0
- data/sig/cli/validate.rbs +43 -0
- data/sig/cli.rbs +87 -0
- data/sig/collection/cleaner.rbs +13 -0
- data/sig/collection/config/lockfile.rbs +74 -0
- data/sig/collection/config/lockfile_generator.rbs +66 -0
- data/sig/collection/config.rbs +46 -0
- data/sig/collection/installer.rbs +17 -0
- data/sig/collection/sources.rbs +214 -0
- data/sig/collection.rbs +4 -0
- data/sig/comment.rbs +26 -0
- data/sig/constant.rbs +21 -0
- data/sig/declarations.rbs +267 -0
- data/sig/definition.rbs +173 -0
- data/sig/definition_builder.rbs +165 -0
- data/sig/diff.rbs +28 -0
- data/sig/directives.rbs +77 -0
- data/sig/environment.rbs +279 -0
- data/sig/environment_loader.rbs +111 -0
- data/sig/environment_walker.rbs +65 -0
- data/sig/errors.rbs +405 -0
- data/sig/factory.rbs +5 -0
- data/sig/file_finder.rbs +28 -0
- data/sig/location.rbs +110 -0
- data/sig/locator.rbs +58 -0
- data/sig/manifest.yaml +7 -0
- data/sig/members.rbs +258 -0
- data/sig/method_builder.rbs +84 -0
- data/sig/method_types.rbs +58 -0
- data/sig/namespace.rbs +146 -0
- data/sig/parser.rbs +100 -0
- data/sig/prototype/helpers.rbs +27 -0
- data/sig/prototype/node_usage.rbs +20 -0
- data/sig/prototype/rb.rbs +96 -0
- data/sig/prototype/rbi.rbs +75 -0
- data/sig/prototype/runtime.rbs +182 -0
- data/sig/rbs.rbs +21 -0
- data/sig/rdoc/rbs.rbs +67 -0
- data/sig/repository.rbs +85 -0
- data/sig/resolver/constant_resolver.rbs +92 -0
- data/sig/resolver/context.rbs +34 -0
- data/sig/resolver/type_name_resolver.rbs +35 -0
- data/sig/shims/bundler.rbs +38 -0
- data/sig/shims/enumerable.rbs +5 -0
- data/sig/shims/rubygems.rbs +19 -0
- data/sig/sorter.rbs +41 -0
- data/sig/substitution.rbs +48 -0
- data/sig/subtractor.rbs +37 -0
- data/sig/test/errors.rbs +52 -0
- data/sig/test/guranteed.rbs +9 -0
- data/sig/test/type_check.rbs +19 -0
- data/sig/test.rbs +82 -0
- data/sig/type_alias_dependency.rbs +53 -0
- data/sig/type_alias_regularity.rbs +98 -0
- data/sig/type_param.rbs +110 -0
- data/sig/typename.rbs +79 -0
- data/sig/types.rbs +579 -0
- data/sig/unit_test/convertibles.rbs +154 -0
- data/sig/unit_test/spy.rbs +30 -0
- data/sig/unit_test/type_assertions.rbs +196 -0
- data/sig/unit_test/with_aliases.rbs +136 -0
- data/sig/use_map.rbs +35 -0
- data/sig/util.rbs +9 -0
- data/sig/validator.rbs +63 -0
- data/sig/variance_calculator.rbs +87 -0
- data/sig/vendorer.rbs +51 -0
- data/sig/version.rbs +3 -0
- data/sig/visitor.rbs +47 -0
- data/sig/writer.rbs +127 -0
- data/src/constants.c +153 -0
- data/src/ruby_objs.c +795 -0
- data/src/util/rbs_constant_pool.c +342 -0
- data/stdlib/abbrev/0/abbrev.rbs +66 -0
- data/stdlib/abbrev/0/array.rbs +26 -0
- data/stdlib/base64/0/base64.rbs +355 -0
- data/stdlib/benchmark/0/benchmark.rbs +452 -0
- data/stdlib/bigdecimal/0/big_decimal.rbs +1629 -0
- data/stdlib/bigdecimal-math/0/big_math.rbs +119 -0
- data/stdlib/bigdecimal-math/0/manifest.yaml +2 -0
- data/stdlib/cgi/0/core.rbs +1285 -0
- data/stdlib/cgi/0/manifest.yaml +3 -0
- data/stdlib/coverage/0/coverage.rbs +263 -0
- data/stdlib/csv/0/csv.rbs +3776 -0
- data/stdlib/csv/0/manifest.yaml +3 -0
- data/stdlib/date/0/date.rbs +1585 -0
- data/stdlib/date/0/date_time.rbs +616 -0
- data/stdlib/date/0/time.rbs +26 -0
- data/stdlib/dbm/0/dbm.rbs +421 -0
- data/stdlib/delegate/0/delegator.rbs +184 -0
- data/stdlib/delegate/0/kernel.rbs +47 -0
- data/stdlib/delegate/0/simple_delegator.rbs +96 -0
- data/stdlib/did_you_mean/0/did_you_mean.rbs +343 -0
- data/stdlib/digest/0/digest.rbs +577 -0
- data/stdlib/erb/0/erb.rbs +532 -0
- data/stdlib/etc/0/etc.rbs +865 -0
- data/stdlib/fileutils/0/fileutils.rbs +1734 -0
- data/stdlib/find/0/find.rbs +49 -0
- data/stdlib/forwardable/0/forwardable.rbs +268 -0
- data/stdlib/io-console/0/io-console.rbs +414 -0
- data/stdlib/ipaddr/0/ipaddr.rbs +428 -0
- data/stdlib/json/0/json.rbs +1916 -0
- data/stdlib/kconv/0/kconv.rbs +166 -0
- data/stdlib/logger/0/formatter.rbs +45 -0
- data/stdlib/logger/0/log_device.rbs +100 -0
- data/stdlib/logger/0/logger.rbs +796 -0
- data/stdlib/logger/0/manifest.yaml +2 -0
- data/stdlib/logger/0/period.rbs +17 -0
- data/stdlib/logger/0/severity.rbs +34 -0
- data/stdlib/minitest/0/kernel.rbs +42 -0
- data/stdlib/minitest/0/minitest/abstract_reporter.rbs +52 -0
- data/stdlib/minitest/0/minitest/assertion.rbs +17 -0
- data/stdlib/minitest/0/minitest/assertions.rbs +590 -0
- data/stdlib/minitest/0/minitest/backtrace_filter.rbs +23 -0
- data/stdlib/minitest/0/minitest/bench_spec.rbs +102 -0
- data/stdlib/minitest/0/minitest/benchmark.rbs +259 -0
- data/stdlib/minitest/0/minitest/composite_reporter.rbs +25 -0
- data/stdlib/minitest/0/minitest/compress.rbs +13 -0
- data/stdlib/minitest/0/minitest/error_on_warning.rbs +3 -0
- data/stdlib/minitest/0/minitest/expectation.rbs +2 -0
- data/stdlib/minitest/0/minitest/expectations.rbs +21 -0
- data/stdlib/minitest/0/minitest/guard.rbs +64 -0
- data/stdlib/minitest/0/minitest/mock.rbs +64 -0
- data/stdlib/minitest/0/minitest/parallel/executor.rbs +46 -0
- data/stdlib/minitest/0/minitest/parallel/test/class_methods.rbs +5 -0
- data/stdlib/minitest/0/minitest/parallel/test.rbs +3 -0
- data/stdlib/minitest/0/minitest/parallel.rbs +2 -0
- data/stdlib/minitest/0/minitest/pride_io.rbs +62 -0
- data/stdlib/minitest/0/minitest/pride_lol.rbs +19 -0
- data/stdlib/minitest/0/minitest/progress_reporter.rbs +11 -0
- data/stdlib/minitest/0/minitest/reportable.rbs +53 -0
- data/stdlib/minitest/0/minitest/reporter.rbs +5 -0
- data/stdlib/minitest/0/minitest/result.rbs +28 -0
- data/stdlib/minitest/0/minitest/runnable.rbs +163 -0
- data/stdlib/minitest/0/minitest/skip.rbs +6 -0
- data/stdlib/minitest/0/minitest/spec/dsl/instance_methods.rbs +48 -0
- data/stdlib/minitest/0/minitest/spec/dsl.rbs +129 -0
- data/stdlib/minitest/0/minitest/spec.rbs +11 -0
- data/stdlib/minitest/0/minitest/statistics_reporter.rbs +81 -0
- data/stdlib/minitest/0/minitest/summary_reporter.rbs +18 -0
- data/stdlib/minitest/0/minitest/test/lifecycle_hooks.rbs +92 -0
- data/stdlib/minitest/0/minitest/test.rbs +69 -0
- data/stdlib/minitest/0/minitest/unexpected_error.rbs +12 -0
- data/stdlib/minitest/0/minitest/unexpected_warning.rbs +6 -0
- data/stdlib/minitest/0/minitest/unit/test_case.rbs +3 -0
- data/stdlib/minitest/0/minitest/unit.rbs +4 -0
- data/stdlib/minitest/0/minitest.rbs +115 -0
- data/stdlib/monitor/0/monitor.rbs +363 -0
- data/stdlib/mutex_m/0/mutex_m.rbs +104 -0
- data/stdlib/net-http/0/manifest.yaml +3 -0
- data/stdlib/net-http/0/net-http.rbs +5552 -0
- data/stdlib/net-protocol/0/manifest.yaml +2 -0
- data/stdlib/net-protocol/0/net-protocol.rbs +56 -0
- data/stdlib/net-smtp/0/manifest.yaml +2 -0
- data/stdlib/net-smtp/0/net-smtp.rbs +55 -0
- data/stdlib/nkf/0/nkf.rbs +402 -0
- data/stdlib/objspace/0/objspace.rbs +487 -0
- data/stdlib/observable/0/observable.rbs +217 -0
- data/stdlib/open-uri/0/manifest.yaml +4 -0
- data/stdlib/open-uri/0/open-uri.rbs +393 -0
- data/stdlib/open3/0/open3.rbs +147 -0
- data/stdlib/openssl/0/manifest.yaml +3 -0
- data/stdlib/openssl/0/openssl.rbs +12113 -0
- data/stdlib/optparse/0/optparse.rbs +1725 -0
- data/stdlib/pathname/0/pathname.rbs +1406 -0
- data/stdlib/pp/0/manifest.yaml +2 -0
- data/stdlib/pp/0/pp.rbs +300 -0
- data/stdlib/prettyprint/0/prettyprint.rbs +383 -0
- data/stdlib/pstore/0/pstore.rbs +603 -0
- data/stdlib/psych/0/core_ext.rbs +12 -0
- data/stdlib/psych/0/dbm.rbs +237 -0
- data/stdlib/psych/0/manifest.yaml +3 -0
- data/stdlib/psych/0/psych.rbs +402 -0
- data/stdlib/psych/0/store.rbs +59 -0
- data/stdlib/pty/0/pty.rbs +237 -0
- data/stdlib/rdoc/0/code_object.rbs +51 -0
- data/stdlib/rdoc/0/comment.rbs +59 -0
- data/stdlib/rdoc/0/context.rbs +153 -0
- data/stdlib/rdoc/0/markup.rbs +117 -0
- data/stdlib/rdoc/0/parser.rbs +56 -0
- data/stdlib/rdoc/0/rdoc.rbs +391 -0
- data/stdlib/rdoc/0/ri.rbs +17 -0
- data/stdlib/rdoc/0/store.rbs +48 -0
- data/stdlib/rdoc/0/top_level.rbs +97 -0
- data/stdlib/resolv/0/manifest.yaml +3 -0
- data/stdlib/resolv/0/resolv.rbs +1830 -0
- data/stdlib/ripper/0/ripper.rbs +1648 -0
- data/stdlib/securerandom/0/securerandom.rbs +62 -0
- data/stdlib/shellwords/0/shellwords.rbs +229 -0
- data/stdlib/singleton/0/singleton.rbs +131 -0
- data/stdlib/socket/0/addrinfo.rbs +666 -0
- data/stdlib/socket/0/basic_socket.rbs +590 -0
- data/stdlib/socket/0/constants.rbs +2295 -0
- data/stdlib/socket/0/ip_socket.rbs +92 -0
- data/stdlib/socket/0/socket.rbs +4157 -0
- data/stdlib/socket/0/socket_error.rbs +5 -0
- data/stdlib/socket/0/tcp_server.rbs +192 -0
- data/stdlib/socket/0/tcp_socket.rbs +79 -0
- data/stdlib/socket/0/udp_socket.rbs +133 -0
- data/stdlib/socket/0/unix_server.rbs +169 -0
- data/stdlib/socket/0/unix_socket.rbs +172 -0
- data/stdlib/stringio/0/stringio.rbs +567 -0
- data/stdlib/strscan/0/string_scanner.rbs +1627 -0
- data/stdlib/tempfile/0/tempfile.rbs +479 -0
- data/stdlib/time/0/time.rbs +432 -0
- data/stdlib/timeout/0/timeout.rbs +81 -0
- data/stdlib/tmpdir/0/tmpdir.rbs +69 -0
- data/stdlib/tsort/0/cyclic.rbs +5 -0
- data/stdlib/tsort/0/interfaces.rbs +20 -0
- data/stdlib/tsort/0/tsort.rbs +409 -0
- data/stdlib/uri/0/common.rbs +582 -0
- data/stdlib/uri/0/file.rbs +118 -0
- data/stdlib/uri/0/ftp.rbs +13 -0
- data/stdlib/uri/0/generic.rbs +1108 -0
- data/stdlib/uri/0/http.rbs +104 -0
- data/stdlib/uri/0/https.rbs +14 -0
- data/stdlib/uri/0/ldap.rbs +230 -0
- data/stdlib/uri/0/ldaps.rbs +14 -0
- data/stdlib/uri/0/mailto.rbs +92 -0
- data/stdlib/uri/0/rfc2396_parser.rbs +189 -0
- data/stdlib/uri/0/rfc3986_parser.rbs +2 -0
- data/stdlib/uri/0/ws.rbs +13 -0
- data/stdlib/uri/0/wss.rbs +9 -0
- data/stdlib/yaml/0/manifest.yaml +2 -0
- data/stdlib/yaml/0/yaml.rbs +1 -0
- data/stdlib/zlib/0/buf_error.rbs +10 -0
- data/stdlib/zlib/0/data_error.rbs +10 -0
- data/stdlib/zlib/0/deflate.rbs +210 -0
- data/stdlib/zlib/0/error.rbs +20 -0
- data/stdlib/zlib/0/gzip_file/crc_error.rbs +12 -0
- data/stdlib/zlib/0/gzip_file/error.rbs +23 -0
- data/stdlib/zlib/0/gzip_file/length_error.rbs +12 -0
- data/stdlib/zlib/0/gzip_file/no_footer.rbs +11 -0
- data/stdlib/zlib/0/gzip_file.rbs +156 -0
- data/stdlib/zlib/0/gzip_reader.rbs +293 -0
- data/stdlib/zlib/0/gzip_writer.rbs +166 -0
- data/stdlib/zlib/0/inflate.rbs +180 -0
- data/stdlib/zlib/0/mem_error.rbs +10 -0
- data/stdlib/zlib/0/need_dict.rbs +13 -0
- data/stdlib/zlib/0/stream_end.rbs +11 -0
- data/stdlib/zlib/0/stream_error.rbs +11 -0
- data/stdlib/zlib/0/version_error.rbs +11 -0
- data/stdlib/zlib/0/zlib.rbs +449 -0
- data/stdlib/zlib/0/zstream.rbs +200 -0
- metadata +532 -0
data/lib/rbs/types.rb
ADDED
@@ -0,0 +1,1596 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RBS
|
4
|
+
module Types
|
5
|
+
module NoFreeVariables
|
6
|
+
def free_variables(set = Set.new)
|
7
|
+
set
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module NoSubst
|
12
|
+
def sub(s)
|
13
|
+
self
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
module NoTypeName
|
18
|
+
def map_type_name(&)
|
19
|
+
self
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module EmptyEachType
|
24
|
+
def each_type
|
25
|
+
if block_given?
|
26
|
+
# nop
|
27
|
+
else
|
28
|
+
enum_for :each_type
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def map_type(&block)
|
33
|
+
if block
|
34
|
+
_ = self
|
35
|
+
else
|
36
|
+
enum_for(:map_type)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
module Bases
|
42
|
+
class Base
|
43
|
+
attr_reader :location
|
44
|
+
|
45
|
+
def initialize(location:)
|
46
|
+
@location = location
|
47
|
+
end
|
48
|
+
|
49
|
+
def ==(other)
|
50
|
+
other.is_a?(self.class)
|
51
|
+
end
|
52
|
+
|
53
|
+
def hash
|
54
|
+
self.class.hash
|
55
|
+
end
|
56
|
+
|
57
|
+
alias eql? ==
|
58
|
+
|
59
|
+
include NoFreeVariables
|
60
|
+
include NoSubst
|
61
|
+
include EmptyEachType
|
62
|
+
include NoTypeName
|
63
|
+
|
64
|
+
def to_json(state = _ = nil)
|
65
|
+
klass = to_s.to_sym
|
66
|
+
{ class: klass, location: location }.to_json(state)
|
67
|
+
end
|
68
|
+
|
69
|
+
def to_s(level = 0)
|
70
|
+
case self
|
71
|
+
when Types::Bases::Bool
|
72
|
+
'bool'
|
73
|
+
when Types::Bases::Void
|
74
|
+
'void'
|
75
|
+
when Types::Bases::Any
|
76
|
+
raise
|
77
|
+
when Types::Bases::Nil
|
78
|
+
'nil'
|
79
|
+
when Types::Bases::Top
|
80
|
+
'top'
|
81
|
+
when Types::Bases::Bottom
|
82
|
+
'bot'
|
83
|
+
when Types::Bases::Self
|
84
|
+
'self'
|
85
|
+
when Types::Bases::Instance
|
86
|
+
'instance'
|
87
|
+
when Types::Bases::Class
|
88
|
+
'class'
|
89
|
+
else
|
90
|
+
raise "Unexpected base type: #{inspect}"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def has_self_type?
|
95
|
+
self.is_a?(Types::Bases::Self)
|
96
|
+
end
|
97
|
+
|
98
|
+
def has_classish_type?
|
99
|
+
self.is_a?(Bases::Instance) || self.is_a?(Bases::Class)
|
100
|
+
end
|
101
|
+
|
102
|
+
def with_nonreturn_void?
|
103
|
+
self.is_a?(Bases::Void)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
class Bool < Base; end
|
108
|
+
class Void < Base; end
|
109
|
+
class Any < Base
|
110
|
+
def initialize(location:, todo: false)
|
111
|
+
super(location: location)
|
112
|
+
todo! if todo
|
113
|
+
end
|
114
|
+
|
115
|
+
def to_s(level=0)
|
116
|
+
@string || "untyped"
|
117
|
+
end
|
118
|
+
|
119
|
+
# @deprecated: this method is now called from the constructor, do not call it from outside
|
120
|
+
def todo!
|
121
|
+
@string = '__todo__'
|
122
|
+
self
|
123
|
+
end
|
124
|
+
end
|
125
|
+
class Nil < Base; end
|
126
|
+
class Top < Base; end
|
127
|
+
class Bottom < Base; end
|
128
|
+
class Self < Base; end
|
129
|
+
class Instance < Base
|
130
|
+
def sub(s)
|
131
|
+
s.apply(self)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
class Class < Base; end
|
135
|
+
end
|
136
|
+
|
137
|
+
class Variable
|
138
|
+
attr_reader :name
|
139
|
+
attr_reader :location
|
140
|
+
|
141
|
+
include NoTypeName
|
142
|
+
|
143
|
+
def initialize(name:, location:)
|
144
|
+
@name = name
|
145
|
+
@location = location
|
146
|
+
end
|
147
|
+
|
148
|
+
def ==(other)
|
149
|
+
other.is_a?(Variable) && other.name == name
|
150
|
+
end
|
151
|
+
|
152
|
+
alias eql? ==
|
153
|
+
|
154
|
+
def hash
|
155
|
+
self.class.hash ^ name.hash
|
156
|
+
end
|
157
|
+
|
158
|
+
def free_variables(set = Set.new)
|
159
|
+
set.tap do
|
160
|
+
set << name
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
def to_json(state = _ = nil)
|
165
|
+
{ class: :variable, name: name, location: location }.to_json(state)
|
166
|
+
end
|
167
|
+
|
168
|
+
def sub(s)
|
169
|
+
s.apply(self)
|
170
|
+
end
|
171
|
+
|
172
|
+
def self.build(v)
|
173
|
+
case v
|
174
|
+
when Symbol
|
175
|
+
new(name: v, location: nil)
|
176
|
+
when Array
|
177
|
+
v.map {|x| new(name: x, location: nil) }
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
@@count = 0
|
182
|
+
def self.fresh(v = :T)
|
183
|
+
@@count = @@count + 1
|
184
|
+
new(name: :"#{v}@#{@@count}", location: nil)
|
185
|
+
end
|
186
|
+
|
187
|
+
def to_s(level = 0)
|
188
|
+
name.to_s
|
189
|
+
end
|
190
|
+
|
191
|
+
include EmptyEachType
|
192
|
+
|
193
|
+
def has_self_type?
|
194
|
+
false
|
195
|
+
end
|
196
|
+
|
197
|
+
def has_classish_type?
|
198
|
+
false
|
199
|
+
end
|
200
|
+
|
201
|
+
def with_nonreturn_void?
|
202
|
+
false
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
class ClassSingleton
|
207
|
+
attr_reader :name
|
208
|
+
attr_reader :location
|
209
|
+
|
210
|
+
def initialize(name:, location:)
|
211
|
+
@name = name
|
212
|
+
@location = location
|
213
|
+
end
|
214
|
+
|
215
|
+
def ==(other)
|
216
|
+
other.is_a?(ClassSingleton) && other.name == name
|
217
|
+
end
|
218
|
+
|
219
|
+
alias eql? ==
|
220
|
+
|
221
|
+
def hash
|
222
|
+
self.class.hash ^ name.hash
|
223
|
+
end
|
224
|
+
|
225
|
+
include NoFreeVariables
|
226
|
+
include NoSubst
|
227
|
+
|
228
|
+
def to_json(state = _ = nil)
|
229
|
+
{ class: :class_singleton, name: name, location: location }.to_json(state)
|
230
|
+
end
|
231
|
+
|
232
|
+
def to_s(level = 0)
|
233
|
+
"singleton(#{name})"
|
234
|
+
end
|
235
|
+
|
236
|
+
include EmptyEachType
|
237
|
+
|
238
|
+
def map_type_name(&)
|
239
|
+
ClassSingleton.new(
|
240
|
+
name: yield(name, location, self),
|
241
|
+
location: location
|
242
|
+
)
|
243
|
+
end
|
244
|
+
|
245
|
+
def has_self_type?
|
246
|
+
false
|
247
|
+
end
|
248
|
+
|
249
|
+
def has_classish_type?
|
250
|
+
false
|
251
|
+
end
|
252
|
+
|
253
|
+
def with_nonreturn_void?
|
254
|
+
false
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
module Application
|
259
|
+
attr_reader :name
|
260
|
+
attr_reader :args
|
261
|
+
|
262
|
+
def ==(other)
|
263
|
+
other.is_a?(self.class) && other.name == name && other.args == args
|
264
|
+
end
|
265
|
+
|
266
|
+
alias eql? ==
|
267
|
+
|
268
|
+
def hash
|
269
|
+
name.hash ^ args.hash
|
270
|
+
end
|
271
|
+
|
272
|
+
def free_variables(set = Set.new)
|
273
|
+
set.tap do
|
274
|
+
args.each do |arg|
|
275
|
+
arg.free_variables(set)
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
def to_s(level = 0)
|
281
|
+
if args.empty?
|
282
|
+
name.to_s
|
283
|
+
else
|
284
|
+
"#{name}[#{args.join(", ")}]"
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
def each_type(&block)
|
289
|
+
if block
|
290
|
+
args.each(&block)
|
291
|
+
else
|
292
|
+
enum_for :each_type
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
def has_self_type?
|
297
|
+
each_type.any? {|type| type.has_self_type? }
|
298
|
+
end
|
299
|
+
|
300
|
+
def has_classish_type?
|
301
|
+
each_type.any? {|type| type.has_classish_type? }
|
302
|
+
end
|
303
|
+
|
304
|
+
def with_nonreturn_void?
|
305
|
+
each_type.any? do |type|
|
306
|
+
if type.is_a?(Bases::Void)
|
307
|
+
# `void` in immediate generics parameter is allowed
|
308
|
+
false
|
309
|
+
else
|
310
|
+
type.with_nonreturn_void?
|
311
|
+
end
|
312
|
+
end
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
316
|
+
class Interface
|
317
|
+
attr_reader :location
|
318
|
+
|
319
|
+
include Application
|
320
|
+
|
321
|
+
def initialize(name:, args:, location:)
|
322
|
+
@name = name
|
323
|
+
@args = args
|
324
|
+
@location = location
|
325
|
+
end
|
326
|
+
|
327
|
+
def to_json(state = _ = nil)
|
328
|
+
{ class: :interface, name: name, args: args, location: location }.to_json(state)
|
329
|
+
end
|
330
|
+
|
331
|
+
def sub(s)
|
332
|
+
return self if s.empty?
|
333
|
+
|
334
|
+
self.class.new(name: name,
|
335
|
+
args: args.map {|ty| ty.sub(s) },
|
336
|
+
location: location)
|
337
|
+
end
|
338
|
+
|
339
|
+
def map_type_name(&block)
|
340
|
+
Interface.new(
|
341
|
+
name: yield(name, location, self),
|
342
|
+
args: args.map {|type| type.map_type_name(&block) },
|
343
|
+
location: location
|
344
|
+
)
|
345
|
+
end
|
346
|
+
|
347
|
+
def map_type(&block)
|
348
|
+
if block
|
349
|
+
Interface.new(
|
350
|
+
name: name,
|
351
|
+
args: args.map {|type| yield type },
|
352
|
+
location: location
|
353
|
+
)
|
354
|
+
else
|
355
|
+
enum_for(:map_type)
|
356
|
+
end
|
357
|
+
end
|
358
|
+
end
|
359
|
+
|
360
|
+
class ClassInstance
|
361
|
+
attr_reader :location
|
362
|
+
|
363
|
+
include Application
|
364
|
+
|
365
|
+
def initialize(name:, args:, location:)
|
366
|
+
@name = name
|
367
|
+
@args = args
|
368
|
+
@location = location
|
369
|
+
end
|
370
|
+
|
371
|
+
def to_json(state = _ = nil)
|
372
|
+
{ class: :class_instance, name: name, args: args, location: location }.to_json(state)
|
373
|
+
end
|
374
|
+
|
375
|
+
def sub(s)
|
376
|
+
return self if s.empty?
|
377
|
+
|
378
|
+
self.class.new(name: name,
|
379
|
+
args: args.map {|ty| ty.sub(s) },
|
380
|
+
location: location)
|
381
|
+
end
|
382
|
+
|
383
|
+
def map_type_name(&block)
|
384
|
+
ClassInstance.new(
|
385
|
+
name: yield(name, location, self),
|
386
|
+
args: args.map {|type| type.map_type_name(&block) },
|
387
|
+
location: location
|
388
|
+
)
|
389
|
+
end
|
390
|
+
|
391
|
+
def map_type(&block)
|
392
|
+
if block
|
393
|
+
ClassInstance.new(
|
394
|
+
name: name,
|
395
|
+
args: args.map {|type| yield type },
|
396
|
+
location: location
|
397
|
+
)
|
398
|
+
else
|
399
|
+
enum_for :map_type
|
400
|
+
end
|
401
|
+
end
|
402
|
+
end
|
403
|
+
|
404
|
+
class Alias
|
405
|
+
attr_reader :location
|
406
|
+
|
407
|
+
include Application
|
408
|
+
|
409
|
+
def initialize(name:, args:, location:)
|
410
|
+
@name = name
|
411
|
+
@args = args
|
412
|
+
@location = location
|
413
|
+
end
|
414
|
+
|
415
|
+
def to_json(state = _ = nil)
|
416
|
+
{ class: :alias, name: name, args: args, location: location }.to_json(state)
|
417
|
+
end
|
418
|
+
|
419
|
+
def sub(s)
|
420
|
+
return self if s.empty?
|
421
|
+
|
422
|
+
Alias.new(name: name, args: args.map {|ty| ty.sub(s) }, location: location)
|
423
|
+
end
|
424
|
+
|
425
|
+
def map_type_name(&block)
|
426
|
+
Alias.new(
|
427
|
+
name: yield(name, location, self),
|
428
|
+
args: args.map {|arg| arg.map_type_name(&block) },
|
429
|
+
location: location
|
430
|
+
)
|
431
|
+
end
|
432
|
+
|
433
|
+
def map_type(&block)
|
434
|
+
if block
|
435
|
+
Alias.new(
|
436
|
+
name: name,
|
437
|
+
args: args.map {|type| yield type },
|
438
|
+
location: location
|
439
|
+
)
|
440
|
+
else
|
441
|
+
enum_for :map_type
|
442
|
+
end
|
443
|
+
end
|
444
|
+
end
|
445
|
+
|
446
|
+
class Tuple
|
447
|
+
attr_reader :types
|
448
|
+
attr_reader :location
|
449
|
+
|
450
|
+
def initialize(types:, location:)
|
451
|
+
@types = types
|
452
|
+
@location = location
|
453
|
+
end
|
454
|
+
|
455
|
+
def ==(other)
|
456
|
+
other.is_a?(Tuple) && other.types == types
|
457
|
+
end
|
458
|
+
|
459
|
+
alias eql? ==
|
460
|
+
|
461
|
+
def hash
|
462
|
+
self.class.hash ^ types.hash
|
463
|
+
end
|
464
|
+
|
465
|
+
def free_variables(set = Set.new)
|
466
|
+
set.tap do
|
467
|
+
types.each do |type|
|
468
|
+
type.free_variables set
|
469
|
+
end
|
470
|
+
end
|
471
|
+
end
|
472
|
+
|
473
|
+
def to_json(state = _ = nil)
|
474
|
+
{ class: :tuple, types: types, location: location }.to_json(state)
|
475
|
+
end
|
476
|
+
|
477
|
+
def sub(s)
|
478
|
+
return self if s.empty?
|
479
|
+
|
480
|
+
self.class.new(types: types.map {|ty| ty.sub(s) },
|
481
|
+
location: location)
|
482
|
+
end
|
483
|
+
|
484
|
+
def to_s(level = 0)
|
485
|
+
if types.empty?
|
486
|
+
"[ ]"
|
487
|
+
else
|
488
|
+
"[ #{types.join(", ")} ]"
|
489
|
+
end
|
490
|
+
end
|
491
|
+
|
492
|
+
def each_type(&block)
|
493
|
+
if block
|
494
|
+
types.each(&block)
|
495
|
+
else
|
496
|
+
enum_for :each_type
|
497
|
+
end
|
498
|
+
end
|
499
|
+
|
500
|
+
def map_type_name(&block)
|
501
|
+
Tuple.new(
|
502
|
+
types: types.map {|type| type.map_type_name(&block) },
|
503
|
+
location: location
|
504
|
+
)
|
505
|
+
end
|
506
|
+
|
507
|
+
def map_type(&block)
|
508
|
+
if block
|
509
|
+
Tuple.new(
|
510
|
+
types: types.map {|type| yield type },
|
511
|
+
location: location
|
512
|
+
)
|
513
|
+
else
|
514
|
+
enum_for :map_type
|
515
|
+
end
|
516
|
+
end
|
517
|
+
|
518
|
+
def has_self_type?
|
519
|
+
each_type.any? {|type| type.has_self_type? }
|
520
|
+
end
|
521
|
+
|
522
|
+
def has_classish_type?
|
523
|
+
each_type.any? {|type| type.has_classish_type? }
|
524
|
+
end
|
525
|
+
|
526
|
+
def with_nonreturn_void?
|
527
|
+
each_type.any? {|type| type.with_nonreturn_void? }
|
528
|
+
end
|
529
|
+
end
|
530
|
+
|
531
|
+
class Record
|
532
|
+
attr_reader :all_fields, :fields, :optional_fields
|
533
|
+
attr_reader :location
|
534
|
+
|
535
|
+
def initialize(all_fields: nil, fields: nil, location:)
|
536
|
+
case
|
537
|
+
when fields && all_fields.nil?
|
538
|
+
@all_fields = fields.transform_values { |v| [v, true] }
|
539
|
+
@fields = fields
|
540
|
+
@optional_fields = {}
|
541
|
+
when all_fields && fields.nil?
|
542
|
+
@all_fields = all_fields
|
543
|
+
@fields = {}
|
544
|
+
@optional_fields = {}
|
545
|
+
all_fields.each do |(k, (v, required))|
|
546
|
+
if required
|
547
|
+
@fields[k] = v
|
548
|
+
else
|
549
|
+
@optional_fields[k] = v
|
550
|
+
end
|
551
|
+
end
|
552
|
+
else
|
553
|
+
raise ArgumentError, "only one of `:fields` or `:all_fields` is required"
|
554
|
+
end
|
555
|
+
|
556
|
+
@location = location
|
557
|
+
end
|
558
|
+
|
559
|
+
def ==(other)
|
560
|
+
other.is_a?(Record) && other.fields == fields && other.optional_fields == optional_fields
|
561
|
+
end
|
562
|
+
|
563
|
+
alias eql? ==
|
564
|
+
|
565
|
+
def hash
|
566
|
+
self.class.hash ^ all_fields.hash
|
567
|
+
end
|
568
|
+
|
569
|
+
def free_variables(set = Set.new)
|
570
|
+
set.tap do
|
571
|
+
fields.each_value do |type|
|
572
|
+
type.free_variables set
|
573
|
+
end
|
574
|
+
optional_fields.each_value do |type|
|
575
|
+
type.free_variables set
|
576
|
+
end
|
577
|
+
end
|
578
|
+
end
|
579
|
+
|
580
|
+
def to_json(state = _ = nil)
|
581
|
+
{ class: :record, fields: fields, optional_fields: optional_fields, location: location }.to_json(state)
|
582
|
+
end
|
583
|
+
|
584
|
+
def sub(s)
|
585
|
+
return self if s.empty?
|
586
|
+
|
587
|
+
self.class.new(
|
588
|
+
all_fields: all_fields.transform_values {|ty, required| [ty.sub(s), required] },
|
589
|
+
location: location
|
590
|
+
)
|
591
|
+
end
|
592
|
+
|
593
|
+
def to_s(level = 0)
|
594
|
+
return "{ }" if all_fields.empty?
|
595
|
+
|
596
|
+
fields = all_fields.map do |key, (type, required)|
|
597
|
+
field = if key.is_a?(Symbol) && key.match?(/\A[A-Za-z_][A-Za-z_0-9]*\z/)
|
598
|
+
"#{key}: #{type}"
|
599
|
+
else
|
600
|
+
"#{key.inspect} => #{type}"
|
601
|
+
end
|
602
|
+
|
603
|
+
field = "?#{field}" unless required
|
604
|
+
field
|
605
|
+
end
|
606
|
+
"{ #{fields.join(", ")} }"
|
607
|
+
end
|
608
|
+
|
609
|
+
def each_type(&block)
|
610
|
+
if block
|
611
|
+
fields.each_value(&block)
|
612
|
+
optional_fields.each_value(&block)
|
613
|
+
else
|
614
|
+
enum_for :each_type
|
615
|
+
end
|
616
|
+
end
|
617
|
+
|
618
|
+
def map_type_name(&block)
|
619
|
+
Record.new(
|
620
|
+
all_fields: all_fields.transform_values {|ty, required| [ty.map_type_name(&block), required] },
|
621
|
+
location: location
|
622
|
+
)
|
623
|
+
end
|
624
|
+
|
625
|
+
def map_type(&block)
|
626
|
+
if block
|
627
|
+
Record.new(
|
628
|
+
all_fields: all_fields.transform_values {|type, required| [yield(type), required] },
|
629
|
+
location: location
|
630
|
+
)
|
631
|
+
else
|
632
|
+
enum_for :map_type
|
633
|
+
end
|
634
|
+
end
|
635
|
+
|
636
|
+
def has_self_type?
|
637
|
+
each_type.any? {|type| type.has_self_type? }
|
638
|
+
end
|
639
|
+
|
640
|
+
def has_classish_type?
|
641
|
+
each_type.any? {|type| type.has_classish_type? }
|
642
|
+
end
|
643
|
+
|
644
|
+
def with_nonreturn_void?
|
645
|
+
each_type.any? {|type| type.with_nonreturn_void? }
|
646
|
+
end
|
647
|
+
end
|
648
|
+
|
649
|
+
class Optional
|
650
|
+
attr_reader :type
|
651
|
+
attr_reader :location
|
652
|
+
|
653
|
+
def initialize(type:, location:)
|
654
|
+
@type = type
|
655
|
+
@location = location
|
656
|
+
end
|
657
|
+
|
658
|
+
def ==(other)
|
659
|
+
other.is_a?(Optional) && other.type == type
|
660
|
+
end
|
661
|
+
|
662
|
+
alias eql? ==
|
663
|
+
|
664
|
+
def hash
|
665
|
+
self.class.hash ^ type.hash
|
666
|
+
end
|
667
|
+
|
668
|
+
def free_variables(set = Set.new)
|
669
|
+
type.free_variables(set)
|
670
|
+
end
|
671
|
+
|
672
|
+
def to_json(state = _ = nil)
|
673
|
+
{ class: :optional, type: type, location: location }.to_json(state)
|
674
|
+
end
|
675
|
+
|
676
|
+
def sub(s)
|
677
|
+
return self if s.empty?
|
678
|
+
|
679
|
+
self.class.new(type: type.sub(s), location: location)
|
680
|
+
end
|
681
|
+
|
682
|
+
def to_s(level = 0)
|
683
|
+
case t = type
|
684
|
+
when RBS::Types::Literal
|
685
|
+
case t.literal
|
686
|
+
when Symbol
|
687
|
+
return "#{type.to_s(1)} ?"
|
688
|
+
end
|
689
|
+
when RBS::Types::Proc
|
690
|
+
return "(#{type.to_s(1)})?"
|
691
|
+
end
|
692
|
+
|
693
|
+
"#{type.to_s(1)}?"
|
694
|
+
end
|
695
|
+
|
696
|
+
def each_type
|
697
|
+
if block_given?
|
698
|
+
yield type
|
699
|
+
else
|
700
|
+
enum_for :each_type
|
701
|
+
end
|
702
|
+
end
|
703
|
+
|
704
|
+
def map_type_name(&block)
|
705
|
+
Optional.new(
|
706
|
+
type: type.map_type_name(&block),
|
707
|
+
location: location
|
708
|
+
)
|
709
|
+
end
|
710
|
+
|
711
|
+
def map_type(&block)
|
712
|
+
if block
|
713
|
+
Optional.new(
|
714
|
+
type: yield(type),
|
715
|
+
location: location
|
716
|
+
)
|
717
|
+
else
|
718
|
+
enum_for :map_type
|
719
|
+
end
|
720
|
+
end
|
721
|
+
|
722
|
+
def has_self_type?
|
723
|
+
each_type.any? {|type| type.has_self_type? }
|
724
|
+
end
|
725
|
+
|
726
|
+
def has_classish_type?
|
727
|
+
each_type.any? {|type| type.has_classish_type? }
|
728
|
+
end
|
729
|
+
|
730
|
+
def with_nonreturn_void?
|
731
|
+
each_type.any? {|type| type.with_nonreturn_void? }
|
732
|
+
end
|
733
|
+
end
|
734
|
+
|
735
|
+
class Union
|
736
|
+
attr_reader :types
|
737
|
+
attr_reader :location
|
738
|
+
|
739
|
+
def initialize(types:, location:)
|
740
|
+
@types = types
|
741
|
+
@location = location
|
742
|
+
end
|
743
|
+
|
744
|
+
def ==(other)
|
745
|
+
other.is_a?(Union) && other.types == types
|
746
|
+
end
|
747
|
+
|
748
|
+
alias eql? ==
|
749
|
+
|
750
|
+
def hash
|
751
|
+
self.class.hash ^ types.hash
|
752
|
+
end
|
753
|
+
|
754
|
+
def free_variables(set = Set.new)
|
755
|
+
set.tap do
|
756
|
+
types.each do |type|
|
757
|
+
type.free_variables set
|
758
|
+
end
|
759
|
+
end
|
760
|
+
end
|
761
|
+
|
762
|
+
def to_json(state = _ = nil)
|
763
|
+
{ class: :union, types: types, location: location }.to_json(state)
|
764
|
+
end
|
765
|
+
|
766
|
+
def sub(s)
|
767
|
+
return self if s.empty?
|
768
|
+
|
769
|
+
self.class.new(types: types.map {|ty| ty.sub(s) },
|
770
|
+
location: location)
|
771
|
+
end
|
772
|
+
|
773
|
+
def to_s(level = 0)
|
774
|
+
strs = types.map do |ty|
|
775
|
+
case ty
|
776
|
+
when Intersection
|
777
|
+
ty.to_s([1, level].max)
|
778
|
+
else
|
779
|
+
ty.to_s
|
780
|
+
end
|
781
|
+
end
|
782
|
+
|
783
|
+
if level > 0
|
784
|
+
"(#{strs.join(" | ")})"
|
785
|
+
else
|
786
|
+
strs.join(" | ")
|
787
|
+
end
|
788
|
+
end
|
789
|
+
|
790
|
+
def each_type(&block)
|
791
|
+
if block
|
792
|
+
types.each(&block)
|
793
|
+
else
|
794
|
+
enum_for :each_type
|
795
|
+
end
|
796
|
+
end
|
797
|
+
|
798
|
+
def map_type(&block)
|
799
|
+
if block
|
800
|
+
Union.new(types: types.map(&block), location: location)
|
801
|
+
else
|
802
|
+
enum_for :map_type
|
803
|
+
end
|
804
|
+
end
|
805
|
+
|
806
|
+
def map_type_name(&block)
|
807
|
+
Union.new(
|
808
|
+
types: types.map {|type| type.map_type_name(&block) },
|
809
|
+
location: location
|
810
|
+
)
|
811
|
+
end
|
812
|
+
|
813
|
+
def has_self_type?
|
814
|
+
each_type.any? {|type| type.has_self_type? }
|
815
|
+
end
|
816
|
+
|
817
|
+
def has_classish_type?
|
818
|
+
each_type.any? {|type| type.has_classish_type? }
|
819
|
+
end
|
820
|
+
|
821
|
+
def with_nonreturn_void?
|
822
|
+
each_type.any? {|type| type.with_nonreturn_void? }
|
823
|
+
end
|
824
|
+
end
|
825
|
+
|
826
|
+
class Intersection
|
827
|
+
attr_reader :types
|
828
|
+
attr_reader :location
|
829
|
+
|
830
|
+
def initialize(types:, location:)
|
831
|
+
@types = types
|
832
|
+
@location = location
|
833
|
+
end
|
834
|
+
|
835
|
+
def ==(other)
|
836
|
+
other.is_a?(Intersection) && other.types == types
|
837
|
+
end
|
838
|
+
|
839
|
+
alias eql? ==
|
840
|
+
|
841
|
+
def hash
|
842
|
+
self.class.hash ^ types.hash
|
843
|
+
end
|
844
|
+
|
845
|
+
def free_variables(set = Set.new)
|
846
|
+
set.tap do
|
847
|
+
types.each do |type|
|
848
|
+
type.free_variables set
|
849
|
+
end
|
850
|
+
end
|
851
|
+
end
|
852
|
+
|
853
|
+
def to_json(state = _ = nil)
|
854
|
+
{ class: :intersection, types: types, location: location }.to_json(state)
|
855
|
+
end
|
856
|
+
|
857
|
+
def sub(s)
|
858
|
+
return self if s.empty?
|
859
|
+
|
860
|
+
self.class.new(types: types.map {|ty| ty.sub(s) },
|
861
|
+
location: location)
|
862
|
+
end
|
863
|
+
|
864
|
+
def to_s(level = 0)
|
865
|
+
strs = types.map {|ty| ty.to_s(2) }
|
866
|
+
if level > 0
|
867
|
+
"(#{strs.join(" & ")})"
|
868
|
+
else
|
869
|
+
strs.join(" & ")
|
870
|
+
end
|
871
|
+
end
|
872
|
+
|
873
|
+
def each_type(&block)
|
874
|
+
if block
|
875
|
+
types.each(&block)
|
876
|
+
else
|
877
|
+
enum_for :each_type
|
878
|
+
end
|
879
|
+
end
|
880
|
+
|
881
|
+
def map_type(&block)
|
882
|
+
if block
|
883
|
+
Intersection.new(types: types.map(&block), location: location)
|
884
|
+
else
|
885
|
+
enum_for :map_type
|
886
|
+
end
|
887
|
+
end
|
888
|
+
|
889
|
+
def map_type_name(&block)
|
890
|
+
Intersection.new(
|
891
|
+
types: types.map {|type| type.map_type_name(&block) },
|
892
|
+
location: location
|
893
|
+
)
|
894
|
+
end
|
895
|
+
|
896
|
+
def has_self_type?
|
897
|
+
each_type.any? {|type| type.has_self_type? }
|
898
|
+
end
|
899
|
+
|
900
|
+
def has_classish_type?
|
901
|
+
each_type.any? {|type| type.has_classish_type? }
|
902
|
+
end
|
903
|
+
|
904
|
+
def with_nonreturn_void?
|
905
|
+
each_type.any? {|type| type.with_nonreturn_void? }
|
906
|
+
end
|
907
|
+
end
|
908
|
+
|
909
|
+
class Function
|
910
|
+
class Param
|
911
|
+
attr_reader :type
|
912
|
+
attr_reader :name
|
913
|
+
attr_reader :location
|
914
|
+
|
915
|
+
def initialize(type:, name:, location: nil)
|
916
|
+
@type = type
|
917
|
+
@name = name
|
918
|
+
@location = location
|
919
|
+
end
|
920
|
+
|
921
|
+
def ==(other)
|
922
|
+
other.is_a?(Param) && other.type == type && other.name == name
|
923
|
+
end
|
924
|
+
|
925
|
+
alias eql? ==
|
926
|
+
|
927
|
+
def hash
|
928
|
+
self.class.hash ^ type.hash ^ name.hash
|
929
|
+
end
|
930
|
+
|
931
|
+
def map_type(&block)
|
932
|
+
if block
|
933
|
+
Param.new(name: name, type: yield(type), location: location)
|
934
|
+
else
|
935
|
+
enum_for :map_type
|
936
|
+
end
|
937
|
+
end
|
938
|
+
|
939
|
+
def to_json(state = _ = nil)
|
940
|
+
{ type: type, name: name }.to_json(state)
|
941
|
+
end
|
942
|
+
|
943
|
+
def to_s
|
944
|
+
if name
|
945
|
+
if name.match?(/\A[a-zA-Z0-9_]+\z/)
|
946
|
+
"#{type} #{name}"
|
947
|
+
else
|
948
|
+
"#{type} `#{name}`"
|
949
|
+
end
|
950
|
+
else
|
951
|
+
"#{type}"
|
952
|
+
end
|
953
|
+
end
|
954
|
+
end
|
955
|
+
|
956
|
+
attr_reader :required_positionals
|
957
|
+
attr_reader :optional_positionals
|
958
|
+
attr_reader :rest_positionals
|
959
|
+
attr_reader :trailing_positionals
|
960
|
+
attr_reader :required_keywords
|
961
|
+
attr_reader :optional_keywords
|
962
|
+
attr_reader :rest_keywords
|
963
|
+
attr_reader :return_type
|
964
|
+
|
965
|
+
def initialize(required_positionals:, optional_positionals:, rest_positionals:, trailing_positionals:, required_keywords:, optional_keywords:, rest_keywords:, return_type:)
|
966
|
+
@return_type = return_type
|
967
|
+
@required_positionals = required_positionals
|
968
|
+
@optional_positionals = optional_positionals
|
969
|
+
@rest_positionals = rest_positionals
|
970
|
+
@trailing_positionals = trailing_positionals
|
971
|
+
@required_keywords = required_keywords
|
972
|
+
@optional_keywords = optional_keywords
|
973
|
+
@rest_keywords = rest_keywords
|
974
|
+
end
|
975
|
+
|
976
|
+
def ==(other)
|
977
|
+
other.is_a?(Function) &&
|
978
|
+
other.required_positionals == required_positionals &&
|
979
|
+
other.optional_positionals == optional_positionals &&
|
980
|
+
other.rest_positionals == rest_positionals &&
|
981
|
+
other.trailing_positionals == trailing_positionals &&
|
982
|
+
other.required_keywords == required_keywords &&
|
983
|
+
other.optional_keywords == optional_keywords &&
|
984
|
+
other.rest_keywords == rest_keywords &&
|
985
|
+
other.return_type == return_type
|
986
|
+
end
|
987
|
+
|
988
|
+
alias eql? ==
|
989
|
+
|
990
|
+
def hash
|
991
|
+
self.class.hash ^
|
992
|
+
required_positionals.hash ^
|
993
|
+
optional_positionals.hash ^
|
994
|
+
rest_positionals.hash ^
|
995
|
+
trailing_positionals.hash ^
|
996
|
+
required_keywords.hash ^
|
997
|
+
optional_keywords.hash ^
|
998
|
+
rest_keywords.hash ^
|
999
|
+
return_type.hash
|
1000
|
+
end
|
1001
|
+
|
1002
|
+
def free_variables(set = Set.new)
|
1003
|
+
set.tap do
|
1004
|
+
required_positionals.each do |param|
|
1005
|
+
param.type.free_variables(set)
|
1006
|
+
end
|
1007
|
+
optional_positionals.each do |param|
|
1008
|
+
param.type.free_variables(set)
|
1009
|
+
end
|
1010
|
+
rest_positionals&.yield_self do |param|
|
1011
|
+
param.type.free_variables(set)
|
1012
|
+
end
|
1013
|
+
trailing_positionals.each do |param|
|
1014
|
+
param.type.free_variables(set)
|
1015
|
+
end
|
1016
|
+
required_keywords.each_value do |param|
|
1017
|
+
param.type.free_variables(set)
|
1018
|
+
end
|
1019
|
+
optional_keywords.each_value do |param|
|
1020
|
+
param.type.free_variables(set)
|
1021
|
+
end
|
1022
|
+
rest_keywords&.yield_self do |param|
|
1023
|
+
param.type.free_variables(set)
|
1024
|
+
end
|
1025
|
+
|
1026
|
+
return_type.free_variables(set)
|
1027
|
+
end
|
1028
|
+
end
|
1029
|
+
|
1030
|
+
def map_type(&block)
|
1031
|
+
if block
|
1032
|
+
Function.new(
|
1033
|
+
required_positionals: amap(required_positionals) {|param| param.map_type(&block) },
|
1034
|
+
optional_positionals: amap(optional_positionals) {|param| param.map_type(&block) },
|
1035
|
+
rest_positionals: rest_positionals&.yield_self {|param| param.map_type(&block) },
|
1036
|
+
trailing_positionals: amap(trailing_positionals) {|param| param.map_type(&block) },
|
1037
|
+
required_keywords: hmapv(required_keywords) {|param| param.map_type(&block) },
|
1038
|
+
optional_keywords: hmapv(optional_keywords) {|param| param.map_type(&block) },
|
1039
|
+
rest_keywords: rest_keywords&.yield_self {|param| param.map_type(&block) },
|
1040
|
+
return_type: yield(return_type)
|
1041
|
+
)
|
1042
|
+
else
|
1043
|
+
enum_for :map_type
|
1044
|
+
end
|
1045
|
+
end
|
1046
|
+
|
1047
|
+
def amap(array, &block)
|
1048
|
+
if array.empty?
|
1049
|
+
_ = array
|
1050
|
+
else
|
1051
|
+
array.map(&block)
|
1052
|
+
end
|
1053
|
+
end
|
1054
|
+
|
1055
|
+
def hmapv(hash, &block)
|
1056
|
+
if hash.empty?
|
1057
|
+
_ = hash
|
1058
|
+
else
|
1059
|
+
hash.transform_values(&block)
|
1060
|
+
end
|
1061
|
+
end
|
1062
|
+
|
1063
|
+
def map_type_name(&block)
|
1064
|
+
map_type do |type|
|
1065
|
+
type.map_type_name(&block)
|
1066
|
+
end
|
1067
|
+
end
|
1068
|
+
|
1069
|
+
def each_type
|
1070
|
+
if block_given?
|
1071
|
+
required_positionals.each {|param| yield param.type }
|
1072
|
+
optional_positionals.each {|param| yield param.type }
|
1073
|
+
rest_positionals&.yield_self {|param| yield param.type }
|
1074
|
+
trailing_positionals.each {|param| yield param.type }
|
1075
|
+
required_keywords.each_value {|param| yield param.type }
|
1076
|
+
optional_keywords.each_value {|param| yield param.type }
|
1077
|
+
rest_keywords&.yield_self {|param| yield param.type }
|
1078
|
+
yield(return_type)
|
1079
|
+
else
|
1080
|
+
enum_for :each_type
|
1081
|
+
end
|
1082
|
+
end
|
1083
|
+
|
1084
|
+
def each_param(&block)
|
1085
|
+
if block
|
1086
|
+
required_positionals.each(&block)
|
1087
|
+
optional_positionals.each(&block)
|
1088
|
+
rest_positionals&.yield_self(&block)
|
1089
|
+
trailing_positionals.each(&block)
|
1090
|
+
required_keywords.each_value(&block)
|
1091
|
+
optional_keywords.each_value(&block)
|
1092
|
+
rest_keywords&.yield_self(&block)
|
1093
|
+
else
|
1094
|
+
enum_for :each_param
|
1095
|
+
end
|
1096
|
+
end
|
1097
|
+
|
1098
|
+
def to_json(state = _ = nil)
|
1099
|
+
{
|
1100
|
+
required_positionals: required_positionals,
|
1101
|
+
optional_positionals: optional_positionals,
|
1102
|
+
rest_positionals: rest_positionals,
|
1103
|
+
trailing_positionals: trailing_positionals,
|
1104
|
+
required_keywords: required_keywords,
|
1105
|
+
optional_keywords: optional_keywords,
|
1106
|
+
rest_keywords: rest_keywords,
|
1107
|
+
return_type: return_type
|
1108
|
+
}.to_json(state)
|
1109
|
+
end
|
1110
|
+
|
1111
|
+
def sub(s)
|
1112
|
+
return self if s.empty?
|
1113
|
+
|
1114
|
+
map_type {|ty| ty.sub(s) }
|
1115
|
+
end
|
1116
|
+
|
1117
|
+
def self.empty(return_type)
|
1118
|
+
Function.new(
|
1119
|
+
required_positionals: [],
|
1120
|
+
optional_positionals: [],
|
1121
|
+
rest_positionals: nil,
|
1122
|
+
trailing_positionals: [],
|
1123
|
+
required_keywords: {},
|
1124
|
+
optional_keywords: {},
|
1125
|
+
rest_keywords: nil,
|
1126
|
+
return_type: return_type
|
1127
|
+
)
|
1128
|
+
end
|
1129
|
+
|
1130
|
+
def with_return_type(type)
|
1131
|
+
Function.new(
|
1132
|
+
required_positionals: required_positionals,
|
1133
|
+
optional_positionals: optional_positionals,
|
1134
|
+
rest_positionals: rest_positionals,
|
1135
|
+
trailing_positionals: trailing_positionals,
|
1136
|
+
required_keywords: required_keywords,
|
1137
|
+
optional_keywords: optional_keywords,
|
1138
|
+
rest_keywords: rest_keywords,
|
1139
|
+
return_type: type
|
1140
|
+
)
|
1141
|
+
end
|
1142
|
+
|
1143
|
+
def update(required_positionals: self.required_positionals, optional_positionals: self.optional_positionals, rest_positionals: self.rest_positionals, trailing_positionals: self.trailing_positionals,
|
1144
|
+
required_keywords: self.required_keywords, optional_keywords: self.optional_keywords, rest_keywords: self.rest_keywords, return_type: self.return_type)
|
1145
|
+
Function.new(
|
1146
|
+
required_positionals: required_positionals,
|
1147
|
+
optional_positionals: optional_positionals,
|
1148
|
+
rest_positionals: rest_positionals,
|
1149
|
+
trailing_positionals: trailing_positionals,
|
1150
|
+
required_keywords: required_keywords,
|
1151
|
+
optional_keywords: optional_keywords,
|
1152
|
+
rest_keywords: rest_keywords,
|
1153
|
+
return_type: return_type
|
1154
|
+
)
|
1155
|
+
end
|
1156
|
+
|
1157
|
+
def empty?
|
1158
|
+
required_positionals.empty? &&
|
1159
|
+
optional_positionals.empty? &&
|
1160
|
+
!rest_positionals &&
|
1161
|
+
trailing_positionals.empty? &&
|
1162
|
+
required_keywords.empty? &&
|
1163
|
+
optional_keywords.empty? &&
|
1164
|
+
!rest_keywords
|
1165
|
+
end
|
1166
|
+
|
1167
|
+
def param_to_s
|
1168
|
+
# @type var params: Array[String]
|
1169
|
+
params = []
|
1170
|
+
|
1171
|
+
params.push(*required_positionals.map(&:to_s))
|
1172
|
+
params.push(*optional_positionals.map {|p| "?#{p}"})
|
1173
|
+
params.push("*#{rest_positionals}") if rest_positionals
|
1174
|
+
params.push(*trailing_positionals.map(&:to_s))
|
1175
|
+
params.push(*required_keywords.map {|name, param| "#{name}: #{param}" })
|
1176
|
+
params.push(*optional_keywords.map {|name, param| "?#{name}: #{param}" })
|
1177
|
+
params.push("**#{rest_keywords}") if rest_keywords
|
1178
|
+
|
1179
|
+
params.join(", ")
|
1180
|
+
end
|
1181
|
+
|
1182
|
+
def return_to_s
|
1183
|
+
return_type.to_s(1)
|
1184
|
+
end
|
1185
|
+
|
1186
|
+
def drop_head
|
1187
|
+
case
|
1188
|
+
when !required_positionals.empty?
|
1189
|
+
[
|
1190
|
+
required_positionals[0],
|
1191
|
+
update(required_positionals: required_positionals.drop(1))
|
1192
|
+
]
|
1193
|
+
when !optional_positionals.empty?
|
1194
|
+
[
|
1195
|
+
optional_positionals[0],
|
1196
|
+
update(optional_positionals: optional_positionals.drop(1))
|
1197
|
+
]
|
1198
|
+
else
|
1199
|
+
raise "Cannot #drop_head"
|
1200
|
+
end
|
1201
|
+
end
|
1202
|
+
|
1203
|
+
def drop_tail
|
1204
|
+
case
|
1205
|
+
when !trailing_positionals.empty?
|
1206
|
+
last = trailing_positionals.last or raise
|
1207
|
+
[
|
1208
|
+
last,
|
1209
|
+
update(trailing_positionals: trailing_positionals.take(trailing_positionals.size - 1))
|
1210
|
+
]
|
1211
|
+
else
|
1212
|
+
raise "Cannot #drop_tail"
|
1213
|
+
end
|
1214
|
+
end
|
1215
|
+
|
1216
|
+
def has_keyword?
|
1217
|
+
if !required_keywords.empty? || !optional_keywords.empty? || rest_keywords
|
1218
|
+
true
|
1219
|
+
else
|
1220
|
+
false
|
1221
|
+
end
|
1222
|
+
end
|
1223
|
+
|
1224
|
+
def has_self_type?
|
1225
|
+
each_type.any? {|type| type.has_self_type? }
|
1226
|
+
end
|
1227
|
+
|
1228
|
+
def has_classish_type?
|
1229
|
+
each_type.any? {|type| type.has_classish_type? }
|
1230
|
+
end
|
1231
|
+
|
1232
|
+
def with_nonreturn_void?
|
1233
|
+
if each_param.any? {|param| param.type.with_nonreturn_void? }
|
1234
|
+
true
|
1235
|
+
else
|
1236
|
+
if return_type.is_a?(Bases::Void)
|
1237
|
+
false
|
1238
|
+
else
|
1239
|
+
return_type.with_nonreturn_void?
|
1240
|
+
end
|
1241
|
+
end
|
1242
|
+
end
|
1243
|
+
end
|
1244
|
+
|
1245
|
+
class UntypedFunction
|
1246
|
+
attr_reader :return_type
|
1247
|
+
|
1248
|
+
def initialize(return_type:)
|
1249
|
+
@return_type = return_type
|
1250
|
+
end
|
1251
|
+
|
1252
|
+
def free_variables(acc = Set.new)
|
1253
|
+
return_type.free_variables(acc)
|
1254
|
+
end
|
1255
|
+
|
1256
|
+
def map_type(&block)
|
1257
|
+
if block
|
1258
|
+
update(return_type: yield(return_type))
|
1259
|
+
else
|
1260
|
+
enum_for :map_type
|
1261
|
+
end
|
1262
|
+
end
|
1263
|
+
|
1264
|
+
def map_type_name(&block)
|
1265
|
+
UntypedFunction.new(
|
1266
|
+
return_type: return_type.map_type_name(&block)
|
1267
|
+
)
|
1268
|
+
end
|
1269
|
+
|
1270
|
+
def each_type(&block)
|
1271
|
+
if block
|
1272
|
+
yield return_type
|
1273
|
+
else
|
1274
|
+
enum_for :each_type
|
1275
|
+
end
|
1276
|
+
end
|
1277
|
+
|
1278
|
+
def each_param(&block)
|
1279
|
+
if block
|
1280
|
+
# noop
|
1281
|
+
else
|
1282
|
+
enum_for :each_param
|
1283
|
+
end
|
1284
|
+
end
|
1285
|
+
|
1286
|
+
def to_json(state = _ = nil)
|
1287
|
+
{
|
1288
|
+
return_type: return_type
|
1289
|
+
}.to_json(state)
|
1290
|
+
end
|
1291
|
+
|
1292
|
+
def sub(subst)
|
1293
|
+
return self if subst.empty?
|
1294
|
+
|
1295
|
+
map_type { _1.sub(subst) }
|
1296
|
+
end
|
1297
|
+
|
1298
|
+
def with_return_type(ty)
|
1299
|
+
update(return_type: ty)
|
1300
|
+
end
|
1301
|
+
|
1302
|
+
def update(return_type: self.return_type)
|
1303
|
+
UntypedFunction.new(return_type: return_type)
|
1304
|
+
end
|
1305
|
+
|
1306
|
+
def empty?
|
1307
|
+
true
|
1308
|
+
end
|
1309
|
+
|
1310
|
+
def has_self_type?
|
1311
|
+
return_type.has_self_type?
|
1312
|
+
end
|
1313
|
+
|
1314
|
+
def has_classish_type?
|
1315
|
+
return_type.has_classish_type?
|
1316
|
+
end
|
1317
|
+
|
1318
|
+
def with_nonreturn_void?
|
1319
|
+
false
|
1320
|
+
end
|
1321
|
+
|
1322
|
+
def param_to_s
|
1323
|
+
"?"
|
1324
|
+
end
|
1325
|
+
|
1326
|
+
def return_to_s
|
1327
|
+
return_type.to_s(1)
|
1328
|
+
end
|
1329
|
+
|
1330
|
+
def ==(other)
|
1331
|
+
other.is_a?(UntypedFunction) && other.return_type == return_type
|
1332
|
+
end
|
1333
|
+
|
1334
|
+
alias eql? ==
|
1335
|
+
|
1336
|
+
def hash
|
1337
|
+
self.class.hash ^ return_type.hash
|
1338
|
+
end
|
1339
|
+
|
1340
|
+
end
|
1341
|
+
|
1342
|
+
class Block
|
1343
|
+
attr_reader :type
|
1344
|
+
attr_reader :required
|
1345
|
+
attr_reader :self_type
|
1346
|
+
|
1347
|
+
def initialize(type:, required:, self_type: nil)
|
1348
|
+
@type = type
|
1349
|
+
@required = required ? true : false
|
1350
|
+
@self_type = self_type
|
1351
|
+
end
|
1352
|
+
|
1353
|
+
def ==(other)
|
1354
|
+
other.is_a?(Block) &&
|
1355
|
+
other.type == type &&
|
1356
|
+
other.required == required &&
|
1357
|
+
other.self_type == self_type
|
1358
|
+
end
|
1359
|
+
|
1360
|
+
def to_json(state = _ = nil)
|
1361
|
+
{
|
1362
|
+
type: type,
|
1363
|
+
required: required,
|
1364
|
+
self_type: self_type
|
1365
|
+
}.to_json(state)
|
1366
|
+
end
|
1367
|
+
|
1368
|
+
def sub(s)
|
1369
|
+
return self if s.empty?
|
1370
|
+
|
1371
|
+
self.class.new(
|
1372
|
+
type: type.sub(s),
|
1373
|
+
required: required,
|
1374
|
+
self_type: self_type&.sub(s)
|
1375
|
+
)
|
1376
|
+
end
|
1377
|
+
|
1378
|
+
def map_type(&block)
|
1379
|
+
Block.new(
|
1380
|
+
required: required,
|
1381
|
+
type: type.map_type(&block),
|
1382
|
+
self_type: self_type ? yield(self_type) : nil
|
1383
|
+
)
|
1384
|
+
end
|
1385
|
+
end
|
1386
|
+
|
1387
|
+
module SelfTypeBindingHelper
|
1388
|
+
module_function
|
1389
|
+
|
1390
|
+
def self_type_binding_to_s(t)
|
1391
|
+
if t
|
1392
|
+
"[self: #{t}] "
|
1393
|
+
else
|
1394
|
+
""
|
1395
|
+
end
|
1396
|
+
end
|
1397
|
+
end
|
1398
|
+
|
1399
|
+
class Proc
|
1400
|
+
attr_reader :type
|
1401
|
+
attr_reader :block
|
1402
|
+
attr_reader :self_type
|
1403
|
+
attr_reader :location
|
1404
|
+
|
1405
|
+
def initialize(location:, type:, block:, self_type: nil)
|
1406
|
+
@type = type
|
1407
|
+
@block = block
|
1408
|
+
@location = location
|
1409
|
+
@self_type = self_type
|
1410
|
+
end
|
1411
|
+
|
1412
|
+
def ==(other)
|
1413
|
+
other.is_a?(Proc) && other.type == type && other.block == block && other.self_type == self_type
|
1414
|
+
end
|
1415
|
+
|
1416
|
+
alias eql? ==
|
1417
|
+
|
1418
|
+
def hash
|
1419
|
+
self.class.hash ^ type.hash ^ block.hash ^ self_type.hash
|
1420
|
+
end
|
1421
|
+
|
1422
|
+
def free_variables(set = Set[])
|
1423
|
+
type.free_variables(set)
|
1424
|
+
block&.type&.free_variables(set)
|
1425
|
+
self_type&.free_variables(set)
|
1426
|
+
set
|
1427
|
+
end
|
1428
|
+
|
1429
|
+
def to_json(state = _ = nil)
|
1430
|
+
{
|
1431
|
+
class: :proc,
|
1432
|
+
type: type,
|
1433
|
+
block: block,
|
1434
|
+
location: location,
|
1435
|
+
self_type: self_type
|
1436
|
+
}.to_json(state)
|
1437
|
+
end
|
1438
|
+
|
1439
|
+
def sub(s)
|
1440
|
+
return self if s.empty?
|
1441
|
+
|
1442
|
+
self.class.new(
|
1443
|
+
type: type.sub(s),
|
1444
|
+
block: block&.sub(s),
|
1445
|
+
self_type: self_type&.sub(s),
|
1446
|
+
location: location
|
1447
|
+
)
|
1448
|
+
end
|
1449
|
+
|
1450
|
+
def to_s(level = 0)
|
1451
|
+
self_binding = SelfTypeBindingHelper.self_type_binding_to_s(self_type)
|
1452
|
+
block_self_binding = SelfTypeBindingHelper.self_type_binding_to_s(block&.self_type)
|
1453
|
+
|
1454
|
+
case
|
1455
|
+
when b = block
|
1456
|
+
if b.required
|
1457
|
+
"^(#{type.param_to_s}) #{self_binding}{ (#{b.type.param_to_s}) #{block_self_binding}-> #{b.type.return_to_s} } -> #{type.return_to_s}"
|
1458
|
+
else
|
1459
|
+
"^(#{type.param_to_s}) #{self_binding}?{ (#{b.type.param_to_s}) #{block_self_binding}-> #{b.type.return_to_s} } -> #{type.return_to_s}"
|
1460
|
+
end
|
1461
|
+
else
|
1462
|
+
"^(#{type.param_to_s}) #{self_binding}-> #{type.return_to_s}"
|
1463
|
+
end
|
1464
|
+
end
|
1465
|
+
|
1466
|
+
def each_type(&block)
|
1467
|
+
if block
|
1468
|
+
type.each_type(&block)
|
1469
|
+
yield self_type if self_type
|
1470
|
+
self.block&.type&.each_type(&block)
|
1471
|
+
if self_type = self.block&.self_type
|
1472
|
+
yield self_type
|
1473
|
+
end
|
1474
|
+
else
|
1475
|
+
enum_for :each_type
|
1476
|
+
end
|
1477
|
+
end
|
1478
|
+
|
1479
|
+
def map_type_name(&block)
|
1480
|
+
Proc.new(
|
1481
|
+
type: type.map_type_name(&block),
|
1482
|
+
block: self.block&.map_type {|type| type.map_type_name(&block) },
|
1483
|
+
self_type: self_type&.map_type_name(&block),
|
1484
|
+
location: location
|
1485
|
+
)
|
1486
|
+
end
|
1487
|
+
|
1488
|
+
def map_type(&block)
|
1489
|
+
if block
|
1490
|
+
Proc.new(
|
1491
|
+
type: type.map_type(&block),
|
1492
|
+
block: self.block&.map_type(&block),
|
1493
|
+
self_type: self_type ? yield(self_type) : nil,
|
1494
|
+
location: location
|
1495
|
+
)
|
1496
|
+
else
|
1497
|
+
enum_for :map_type
|
1498
|
+
end
|
1499
|
+
end
|
1500
|
+
|
1501
|
+
def has_self_type?
|
1502
|
+
each_type.any? {|type| type.has_self_type? }
|
1503
|
+
end
|
1504
|
+
|
1505
|
+
def has_classish_type?
|
1506
|
+
each_type.any? {|type| type.has_classish_type? }
|
1507
|
+
end
|
1508
|
+
|
1509
|
+
def with_nonreturn_void?
|
1510
|
+
if type.with_nonreturn_void? || self_type&.with_nonreturn_void?
|
1511
|
+
true
|
1512
|
+
else
|
1513
|
+
if block = block()
|
1514
|
+
block.type.with_nonreturn_void? || block.self_type&.with_nonreturn_void? || false
|
1515
|
+
else
|
1516
|
+
false
|
1517
|
+
end
|
1518
|
+
end
|
1519
|
+
end
|
1520
|
+
end
|
1521
|
+
|
1522
|
+
class Literal
|
1523
|
+
attr_reader :literal
|
1524
|
+
attr_reader :location
|
1525
|
+
|
1526
|
+
def initialize(literal:, location:)
|
1527
|
+
@literal = literal
|
1528
|
+
@location = location
|
1529
|
+
end
|
1530
|
+
|
1531
|
+
def ==(other)
|
1532
|
+
other.is_a?(Literal) && other.literal == literal
|
1533
|
+
end
|
1534
|
+
|
1535
|
+
alias eql? ==
|
1536
|
+
|
1537
|
+
def hash
|
1538
|
+
self.class.hash ^ literal.hash
|
1539
|
+
end
|
1540
|
+
|
1541
|
+
include NoFreeVariables
|
1542
|
+
include NoSubst
|
1543
|
+
include EmptyEachType
|
1544
|
+
include NoTypeName
|
1545
|
+
|
1546
|
+
def to_json(state = _ = nil)
|
1547
|
+
{ class: :literal, literal: literal.inspect, location: location }.to_json(state)
|
1548
|
+
end
|
1549
|
+
|
1550
|
+
def to_s(level = 0)
|
1551
|
+
literal.inspect
|
1552
|
+
end
|
1553
|
+
|
1554
|
+
def has_self_type?
|
1555
|
+
false
|
1556
|
+
end
|
1557
|
+
|
1558
|
+
def has_classish_type?
|
1559
|
+
false
|
1560
|
+
end
|
1561
|
+
|
1562
|
+
def with_nonreturn_void?
|
1563
|
+
false
|
1564
|
+
end
|
1565
|
+
|
1566
|
+
TABLE = {
|
1567
|
+
"\\a" => "\a",
|
1568
|
+
"\\b" => "\b",
|
1569
|
+
"\\e" => "\033",
|
1570
|
+
"\\f" => "\f",
|
1571
|
+
"\\n" => "\n",
|
1572
|
+
"\\r" => "\r",
|
1573
|
+
"\\s" => " ",
|
1574
|
+
"\\t" => "\t",
|
1575
|
+
"\\v" => "\v",
|
1576
|
+
"\\\"" => "\"",
|
1577
|
+
"\\\'" => "'",
|
1578
|
+
"\\\\" => "\\",
|
1579
|
+
"\\" => ""
|
1580
|
+
}
|
1581
|
+
|
1582
|
+
def self.unescape_string(string, is_double_quote)
|
1583
|
+
if is_double_quote
|
1584
|
+
string.gsub!(/\\([0-9]{1,3})/) { ($1 || "").to_i(8).chr }
|
1585
|
+
string.gsub!(/\\x([0-9a-f]{1,2})/) { ($1 || "").to_i(16).chr }
|
1586
|
+
string.gsub!(/\\u([0-9a-fA-F]{4})/) { ($1 || "").to_i(16).chr(Encoding::UTF_8) }
|
1587
|
+
string.gsub!(/\\[abefnrstv"'\\]?/, TABLE)
|
1588
|
+
string
|
1589
|
+
else
|
1590
|
+
string.gsub!(/\\['\\]/, TABLE)
|
1591
|
+
string
|
1592
|
+
end
|
1593
|
+
end
|
1594
|
+
end
|
1595
|
+
end
|
1596
|
+
end
|