Skip to content

Commit 9593fde

Browse files
stepanchegfacebook-github-bot
authored andcommitted
Remove TypingOracle::subtype
Summary: `TyName` now only intersect if they are equal. Reviewed By: ianlevesque Differential Revision: D48935199 fbshipit-source-id: 8cfb8a73ef66ec294d1210616fc507ddc2d7ca65
1 parent 8f92f5e commit 9593fde

File tree

4 files changed

+1
-39
lines changed

4 files changed

+1
-39
lines changed

starlark/src/eval/compiler/module.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ impl<'v> Compiler<'v, '_, '_> {
174174
let oracle = TypingOracleCtx {
175175
oracle: &OracleAny,
176176
codemap: &self.codemap,
177-
typecheck_mode: TypecheckMode::Compiler,
178177
};
179178
let module_var_types = self.mk_module_var_types();
180179
for top in stmts.iter_mut() {

starlark/src/typing/oracle/ctx.rs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ use crate::typing::function::Arg;
3131
use crate::typing::function::Param;
3232
use crate::typing::function::ParamMode;
3333
use crate::typing::function::TyFunction;
34-
use crate::typing::mode::TypecheckMode;
3534
use crate::typing::starlark_value::TyStarlarkValue;
3635
use crate::typing::tuple::TyTuple;
3736
use crate::typing::Ty;
@@ -82,22 +81,9 @@ enum TypingOracleCtxError {
8281
pub struct TypingOracleCtx<'a> {
8382
pub(crate) oracle: &'a dyn TypingOracle,
8483
pub(crate) codemap: &'a CodeMap,
85-
pub(crate) typecheck_mode: TypecheckMode,
8684
}
8785

8886
impl<'a> TypingOracleCtx<'a> {
89-
pub(crate) fn subtype(&self, require: &TyName, got: &TyName) -> bool {
90-
match self.typecheck_mode {
91-
TypecheckMode::Lint => self.oracle.subtype(require, got),
92-
TypecheckMode::Compiler => {
93-
// Compiler typechecker does not have oracle,
94-
// so it does not know anything about opaque types.
95-
// This code should go away when we get rid of `Ty::name`.
96-
true
97-
}
98-
}
99-
}
100-
10187
pub(crate) fn mk_error(&self, span: Span, err: impl Into<anyhow::Error>) -> TypingError {
10288
TypingError::new(err.into(), span, self.codemap)
10389
}
@@ -833,10 +819,6 @@ impl<'a> TypingOracleCtx<'a> {
833819
false
834820
}
835821

836-
fn intersects_name(&self, x: &TyName, y: &TyName) -> bool {
837-
x == y || self.subtype(x, y) || self.subtype(y, x)
838-
}
839-
840822
pub(crate) fn intersects_basic(&self, x: &TyBasic, y: &TyBasic) -> bool {
841823
x == y || self.intersects_one_side(x, y) || self.intersects_one_side(y, x)
842824
}
@@ -846,7 +828,7 @@ impl<'a> TypingOracleCtx<'a> {
846828
fn intersects_one_side(&self, x: &TyBasic, y: &TyBasic) -> bool {
847829
match (x, y) {
848830
(TyBasic::Any, _) => true,
849-
(TyBasic::Name(x), TyBasic::Name(y)) => self.intersects_name(x, y),
831+
(TyBasic::Name(x), TyBasic::Name(y)) => x == y,
850832
(TyBasic::Name(_), TyBasic::Custom(_)) => true,
851833
(TyBasic::Name(_), TyBasic::StarlarkValue(_)) => true,
852834
(TyBasic::Name(x), y) => Some(x.as_str()) == y.as_name(),

starlark/src/typing/oracle/traits.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,6 @@ pub trait TypingOracle {
100100
fn attribute(&self, _ty: &TyName, _attr: &str) -> Option<Result<Ty, ()>> {
101101
None
102102
}
103-
104-
/// If we require the first type, but got the second type, is that OK?
105-
/// Usually its OK if the requirement is a subtype of the one we got.
106-
fn subtype(&self, require: &TyName, got: &TyName) -> bool {
107-
false
108-
}
109103
}
110104

111105
/// Declare that there are no attributes, usually used at the end of a [`Vec`].
@@ -128,10 +122,6 @@ impl<T: TypingOracle> TypingOracle for OracleSeq<T> {
128122
fn attribute(&self, ty: &TyName, attr: &str) -> Option<Result<Ty, ()>> {
129123
self.0.iter().find_map(|oracle| oracle.attribute(ty, attr))
130124
}
131-
132-
fn subtype(&self, require: &TyName, got: &TyName) -> bool {
133-
self.0.iter().any(|oracle| oracle.subtype(require, got))
134-
}
135125
}
136126

137127
pub(crate) struct OracleAny;
@@ -144,18 +134,10 @@ impl<'a, T: TypingOracle + ?Sized> TypingOracle for &'a T {
144134
fn attribute(&self, ty: &TyName, attr: &str) -> Option<Result<Ty, ()>> {
145135
(*self).attribute(ty, attr)
146136
}
147-
148-
fn subtype(&self, require: &TyName, got: &TyName) -> bool {
149-
(*self).subtype(require, got)
150-
}
151137
}
152138

153139
impl<T: TypingOracle + ?Sized> TypingOracle for Box<T> {
154140
fn attribute(&self, ty: &TyName, attr: &str) -> Option<Result<Ty, ()>> {
155141
self.as_ref().attribute(ty, attr)
156142
}
157-
158-
fn subtype(&self, require: &TyName, got: &TyName) -> bool {
159-
self.as_ref().subtype(require, got)
160-
}
161143
}

starlark/src/typing/typecheck.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,6 @@ impl AstModuleTypecheck for AstModule {
214214
let oracle = TypingOracleCtx {
215215
codemap: &codemap,
216216
oracle,
217-
typecheck_mode: TypecheckMode::Lint,
218217
};
219218

220219
let mut approximations = Vec::new();

0 commit comments

Comments
 (0)