Skip to content

Commit 0ced358

Browse files
stepanchegfacebook-github-bot
authored andcommitted
Make TyUser public
Summary: Following diff D48893103 uses it to implement proper `Provider` type. Reviewed By: ianlevesque Differential Revision: D48893454 fbshipit-source-id: 6144de8d3fdfaa65a086fdeb8cca00c0cfe385b3
1 parent 5423492 commit 0ced358

File tree

7 files changed

+32
-11
lines changed

7 files changed

+32
-11
lines changed

starlark/src/typing/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,13 @@ pub use oracle::traits::OracleSeq;
5757
pub use oracle::traits::TypingBinOp;
5858
pub use oracle::traits::TypingOracle;
5959
pub use oracle::traits::TypingUnOp;
60+
pub use starlark_value::TyStarlarkValue;
6061
pub use structs::TyStruct;
6162
pub use ty::Approximation;
6263
pub use ty::Ty;
6364
pub use ty::TyName;
6465
pub use typecheck::AstModuleTypecheck;
6566
pub use typecheck::TypeMap;
67+
pub use user::TyUser;
68+
pub use user::TyUserFields;
69+
pub use user::TyUserIndex;

starlark/src/typing/starlark_value.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ impl Ord for TyStarlarkValue {
131131
}
132132

133133
impl TyStarlarkValue {
134-
pub(crate) const fn new<'v, T: StarlarkValue<'v>>() -> TyStarlarkValue {
134+
/// Create a type instance from an implementation of `StarlarkValue`.
135+
pub const fn new<'v, T: StarlarkValue<'v>>() -> TyStarlarkValue {
135136
TyStarlarkValue {
136137
vtable: &TyStarlarkValueVTableGet::<T::Canonical>::VTABLE,
137138
}

starlark/src/typing/user.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ enum TyUserError {
5656

5757
/// Types of `[]` operator.
5858
#[derive(Allocative, Debug)]
59-
pub(crate) struct TyUserIndex {
59+
pub struct TyUserIndex {
6060
/// Type of index argument.
6161
pub(crate) index: Ty,
6262
/// Type of result.
@@ -65,27 +65,36 @@ pub(crate) struct TyUserIndex {
6565

6666
/// Fields of the struct.
6767
#[derive(Allocative, Debug, Ord, PartialOrd, Eq, PartialEq, Hash)]
68-
pub(crate) struct TyUserFields {
68+
pub struct TyUserFields {
6969
/// Known fields.
70-
pub(crate) known: SortedMap<String, Ty>,
70+
pub known: SortedMap<String, Ty>,
7171
/// Are there unknown fields?
7272
/// Unknown fields are possible if this type represents an abstract type like a provider.
73-
pub(crate) unknown: bool,
73+
pub unknown: bool,
7474
}
7575

7676
impl TyUserFields {
77-
pub(crate) fn no_fields() -> TyUserFields {
77+
/// No fields.
78+
pub fn no_fields() -> TyUserFields {
7879
TyUserFields {
7980
known: SortedMap::new(),
8081
unknown: false,
8182
}
8283
}
84+
85+
/// All fields are not known.
86+
pub fn unknown() -> TyUserFields {
87+
TyUserFields {
88+
known: SortedMap::new(),
89+
unknown: true,
90+
}
91+
}
8392
}
8493

8594
/// Type description for arbitrary type.
8695
#[derive(Allocative, Debug, derive_more::Display)]
8796
#[display(fmt = "{}", name)]
88-
pub(crate) struct TyUser {
97+
pub struct TyUser {
8998
name: String,
9099
/// Base type for this custom type, e.g. generic record for record with known fields.
91100
base: TyStarlarkValue,
@@ -101,7 +110,8 @@ pub(crate) struct TyUser {
101110
}
102111

103112
impl TyUser {
104-
pub(crate) fn new(
113+
/// Constructor.
114+
pub fn new(
105115
name: String,
106116
base: TyStarlarkValue,
107117
matcher: Option<TypeMatcherFactory>,

starlark/src/values/types/type_instance_id.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ use crate as starlark;
2828
#[derive(
2929
Debug, Copy, Clone, Dupe, Hash, Eq, PartialEq, Ord, PartialOrd, Allocative, Freeze
3030
)]
31-
pub(crate) struct TypeInstanceId(u64);
31+
pub struct TypeInstanceId(u64);
3232

3333
impl TypeInstanceId {
34-
pub(crate) fn gen() -> TypeInstanceId {
34+
/// Generate a new unique identifier.
35+
pub fn gen() -> TypeInstanceId {
3536
static LAST_ID: AtomicU64 = AtomicU64::new(0);
3637
TypeInstanceId(LAST_ID.fetch_add(1, atomic::Ordering::SeqCst) + 1)
3738
}

starlark/src/values/typing/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ pub mod macro_refs;
2525
pub(crate) mod never;
2626
pub(crate) mod type_compiled;
2727

28+
pub use crate::values::types::type_instance_id::TypeInstanceId;
2829
pub use crate::values::typing::callable::StarlarkCallable;
2930
pub use crate::values::typing::iter::StarlarkIter;
3031
pub use crate::values::typing::never::StarlarkNever;
32+
pub use crate::values::typing::type_compiled::matcher::TypeMatcher;
33+
pub use crate::values::typing::type_compiled::type_matcher_factory::TypeMatcherFactory;

starlark/src/values/typing/type_compiled/matcher.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use crate::values::Value;
2727
/// Runtime type matcher. E.g. when `isinstance(1, int)` is called,
2828
/// implementation of `TypeMatcher` for `int` is used.
2929
pub trait TypeMatcher: Allocative + Debug + Clone + Sized + Send + Sync + 'static {
30+
/// Check if the value matches the type.
3031
fn matches(&self, value: Value) -> bool;
3132
/// True if this matcher matches any value.
3233
fn is_wildcard(&self) -> bool {

starlark/src/values/typing/type_compiled/type_matcher_factory.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ pub struct TypeMatcherFactory {
5656
}
5757

5858
impl TypeMatcherFactory {
59-
pub(crate) fn new(matcher: impl TypeMatcher) -> TypeMatcherFactory {
59+
/// Create a new `TypeMatcherFactory` from a `TypeMatcher`.
60+
pub fn new(matcher: impl TypeMatcher) -> TypeMatcherFactory {
6061
TypeMatcherFactory {
6162
factory: Arc::new(TypeMatcherFactoryImpl { matcher }),
6263
}

0 commit comments

Comments
 (0)