Skip to content

Commit 6a13750

Browse files
elliotttjez
andauthored
Remove non_forcing_is_a? (sorbet#9540)
* Remove non_forcing_is_a? * Suggestions from review * Update website/docs/non-forcing-constants.md Co-authored-by: Jake Zimmerman <[email protected]> --------- Co-authored-by: Jake Zimmerman <[email protected]>
1 parent e901841 commit 6a13750

File tree

20 files changed

+56
-471
lines changed

20 files changed

+56
-471
lines changed

core/errors/resolver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ constexpr ErrorClass ExperimentalAttachedClass{5056, StrictLevel::False};
6464
// constexpr ErrorClass GeneratedDeprecated{5056, StrictLevel::False};
6565
constexpr ErrorClass StaticAbstractModuleMethod{5057, StrictLevel::False};
6666
constexpr ErrorClass AttachedClassAsParam{5058, StrictLevel::False};
67-
constexpr ErrorClass LazyResolve{5059, StrictLevel::False};
67+
// constexpr ErrorClass LazyResolve{5059, StrictLevel::False};
6868
constexpr ErrorClass GenericTypeParamBoundMismatch{5060, StrictLevel::False};
6969
constexpr ErrorClass PrivateConstantReferenced{5061, StrictLevel::True};
7070
constexpr ErrorClass InvalidRequiredAncestor{5062, StrictLevel::True};

core/tools/generate_names.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ NameDef names[] = {
170170
{"declareSealed", "sealed!"},
171171
{"revealType", "reveal_type"},
172172
{"absurd"},
173-
{"nonForcingIsA_p", "non_forcing_is_a?"},
174173
{"valid_p", "valid?"},
175174
{"recursivelyValid_p", "recursively_valid?"},
176175
{"subtypeOf_p", "subtype_of?"},

gems/sorbet-runtime/lib/sorbet-runtime.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,5 @@ module T::Private::Types; end
115115
require_relative 'types/props/generated_code_validation'
116116

117117
require_relative 'types/struct'
118-
require_relative 'types/non_forcing_constants'
119118

120119
require_relative 'types/compatibility_patches'

gems/sorbet-runtime/lib/types/non_forcing_constants.rb

Lines changed: 0 additions & 55 deletions
This file was deleted.

gems/sorbet-runtime/lib/types/types/typed_set.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,13 @@ def name
1414

1515
# overrides Base
1616
def recursively_valid?(obj)
17-
# Re-implements non_forcing_is_a?
1817
return false if Object.autoload?(:Set) # Set is meant to be autoloaded but not yet loaded, this value can't be a Set
1918
return false unless Object.const_defined?(:Set) # Set is not loaded yet
2019
obj.is_a?(Set) && super
2120
end
2221

2322
# overrides Base
2423
def valid?(obj)
25-
# Re-implements non_forcing_is_a?
2624
return false if Object.autoload?(:Set) # Set is meant to be autoloaded but not yet loaded, this value can't be a Set
2725
return false unless Object.const_defined?(:Set) # Set is not loaded yet
2826
obj.is_a?(Set)
@@ -41,7 +39,6 @@ def initialize
4139
end
4240

4341
def valid?(obj)
44-
# Re-implements non_forcing_is_a?
4542
return false if Object.autoload?(:Set) # Set is meant to be autoloaded but not yet loaded, this value can't be a Set
4643
return false unless Object.const_defined?(:Set) # Set is not loaded yet
4744
obj.is_a?(Set)

gems/sorbet-runtime/test/types/non_forcing_constants.rb

Lines changed: 0 additions & 99 deletions
This file was deleted.

infer/environment.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,6 @@ void Environment::updateKnowledge(core::Context ctx, cfg::LocalRef local, core::
624624
return;
625625
}
626626

627-
// TODO(jez) We should probably update this to be aware of T::NonForcingConstants.non_forcing_is_a?
628627
if (send->fun == core::Names::kindOf_p() || send->fun == core::Names::isA_p() ||
629628
send->fun == core::Names::instanceOf_p()) {
630629
const auto &klassType = send->args[0].type;

rbi/sorbet/t.rbi

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -485,9 +485,3 @@ module T::Utils::Nilable
485485
}
486486
def self.get_underlying_type_object(prop_type); end
487487
end
488-
489-
module T::NonForcingConstants
490-
# See <https://sorbet.org/docs/non-forcing-constants> for full docs.
491-
sig {params(val: BasicObject, klass: String).returns(T::Boolean)}
492-
def self.non_forcing_is_a?(val, klass); end
493-
end

resolver/resolver.cc

Lines changed: 0 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -2536,107 +2536,6 @@ class ResolveTypeMembersAndFieldsWalk {
25362536
}
25372537
}
25382538

2539-
void validateNonForcingIsA(core::Context ctx, const ast::Send &send) {
2540-
constexpr string_view method = "T::NonForcingConstants.non_forcing_is_a?";
2541-
2542-
if (send.numPosArgs() != 2) {
2543-
return;
2544-
}
2545-
2546-
auto numKwArgs = send.numKwArgs();
2547-
if (numKwArgs > 1) {
2548-
return;
2549-
}
2550-
2551-
auto stringLoc = send.getPosArg(1).loc();
2552-
2553-
auto literalNode = ast::cast_tree<ast::Literal>(send.getPosArg(1));
2554-
if (literalNode == nullptr) {
2555-
if (auto e = ctx.beginError(stringLoc, core::errors::Resolver::LazyResolve)) {
2556-
e.setHeader("`{}` only accepts string literals", method);
2557-
}
2558-
return;
2559-
}
2560-
2561-
if (!core::isa_type<core::NamedLiteralType>(literalNode->value)) {
2562-
if (auto e = ctx.beginError(stringLoc, core::errors::Resolver::LazyResolve)) {
2563-
e.setHeader("`{}` only accepts string literals", method);
2564-
}
2565-
return;
2566-
}
2567-
2568-
auto literal = core::cast_type_nonnull<core::NamedLiteralType>(literalNode->value);
2569-
if (literal.kind != core::NamedLiteralType::Kind::String) {
2570-
// Infer will report a type error
2571-
return;
2572-
}
2573-
2574-
auto shortName = literal.name.shortName(ctx);
2575-
if (shortName.empty()) {
2576-
if (auto e = ctx.beginError(stringLoc, core::errors::Resolver::LazyResolve)) {
2577-
e.setHeader("The string given to `{}` must not be empty", method);
2578-
}
2579-
return;
2580-
}
2581-
2582-
// If this string _begins_ with `::`, then the first fragment will be an empty string; in multiple places
2583-
// below, we'll check to find out whether the first part is `""` or not, which means we're testing whether
2584-
// the string did or did not begin with `::`.
2585-
vector<string_view> parts = absl::StrSplit(shortName, "::");
2586-
2587-
core::SymbolRef current;
2588-
for (auto part : parts) {
2589-
if (!current.exists()) {
2590-
current = core::Symbols::root();
2591-
2592-
// First iteration
2593-
if (part != "") {
2594-
if (auto e = ctx.beginError(stringLoc, core::errors::Resolver::LazyResolve)) {
2595-
e.setHeader("The string given to `{}` must be an absolute constant reference that "
2596-
"starts with `{}`",
2597-
method, "::");
2598-
}
2599-
return;
2600-
}
2601-
continue;
2602-
}
2603-
2604-
auto member = ctx.state.lookupNameConstant(part);
2605-
if (!member.exists()) {
2606-
if (auto e = ctx.beginError(stringLoc, core::errors::Resolver::LazyResolve)) {
2607-
auto prettyCurrent = current == core::Symbols::root() ? "" : "::" + current.show(ctx);
2608-
auto pretty = fmt::format("{}::{}", prettyCurrent, part);
2609-
e.setHeader("Unable to resolve constant `{}`", pretty);
2610-
}
2611-
return;
2612-
}
2613-
2614-
core::SymbolRef newCurrent;
2615-
if (current.isClassOrModule()) {
2616-
newCurrent = current.asClassOrModuleRef().data(ctx)->findMember(ctx, member);
2617-
}
2618-
if (!newCurrent.exists()) {
2619-
if (auto e = ctx.beginError(stringLoc, core::errors::Resolver::LazyResolve)) {
2620-
auto prettyCurrent = current == core::Symbols::root() ? "" : "::" + current.show(ctx);
2621-
auto pretty = fmt::format("{}::{}", prettyCurrent, part);
2622-
e.setHeader("Unable to resolve constant `{}`", pretty);
2623-
}
2624-
return;
2625-
}
2626-
current = newCurrent;
2627-
}
2628-
2629-
ENFORCE(current.exists(), "Loop invariant violated");
2630-
2631-
if (!current.isClassOrModule()) {
2632-
if (auto e = ctx.beginError(stringLoc, core::errors::Resolver::LazyResolve)) {
2633-
e.setHeader("The string given to `{}` must resolve to a class or module", method);
2634-
e.addErrorLine(current.loc(ctx), "Resolved to this constant");
2635-
}
2636-
return;
2637-
}
2638-
}
2639-
26402539
core::ClassOrModuleRef methodOwner(core::Context ctx) {
26412540
core::ClassOrModuleRef owner = ctx.owner.enclosingClass(ctx);
26422541
if (owner == core::Symbols::root()) {
@@ -2868,9 +2767,6 @@ class ResolveTypeMembersAndFieldsWalk {
28682767
}
28692768
return;
28702769
}
2871-
case core::Names::nonForcingIsA_p().rawId():
2872-
validateNonForcingIsA(ctx, send);
2873-
return;
28742770
default:
28752771
return;
28762772
}

0 commit comments

Comments
 (0)