@@ -37,6 +37,10 @@ use starlark::environment::Methods;
3737use starlark:: environment:: MethodsBuilder ;
3838use starlark:: environment:: MethodsStatic ;
3939use starlark:: typing:: Ty ;
40+ use starlark:: typing:: TyCustomIndex ;
41+ use starlark:: typing:: TyStarlarkValue ;
42+ use starlark:: typing:: TyUser ;
43+ use starlark:: typing:: TyUserParams ;
4044use starlark:: values:: AllocFrozenValue ;
4145use starlark:: values:: AllocStaticSimple ;
4246use starlark:: values:: AllocValue ;
@@ -64,6 +68,7 @@ use starlark::values::none::NoneOr;
6468use starlark:: values:: starlark_value;
6569use starlark:: values:: starlark_value_as_type:: StarlarkValueAsType ;
6670use starlark:: values:: type_repr:: StarlarkTypeRepr ;
71+ use starlark:: values:: typing:: TypeInstanceId ;
6772
6873use crate :: interpreter:: rule_defs:: provider:: DefaultInfo ;
6974use crate :: interpreter:: rule_defs:: provider:: DefaultInfoCallable ;
@@ -372,6 +377,7 @@ impl FrozenProviderCollection {
372377/// ```
373378#[ starlark_module]
374379fn provider_collection_methods ( builder : & mut MethodsBuilder ) {
380+ #[ starlark( ty_custom_function = super :: dependency:: GetTyIdentity ) ]
375381 fn get < ' v > (
376382 this : & ProviderCollection < ' v > ,
377383 index : Value < ' v > ,
@@ -380,11 +386,38 @@ fn provider_collection_methods(builder: &mut MethodsBuilder) {
380386 }
381387}
382388
389+ static PROVIDER_COLLECTION_TYPE : std:: sync:: LazyLock < Ty > = std:: sync:: LazyLock :: new ( || {
390+ Ty :: custom (
391+ TyUser :: new (
392+ "ProviderCollection" . to_owned ( ) ,
393+ TyStarlarkValue :: new :: < ProviderCollection > ( ) ,
394+ TypeInstanceId :: r#gen ( ) ,
395+ TyUserParams {
396+ index_custom : Some ( TyCustomIndex :: new ( super :: dependency:: GetTyIdentity ) ) ,
397+ ..TyUserParams :: default ( )
398+ } ,
399+ )
400+ . unwrap ( ) ,
401+ )
402+ } ) ;
403+
383404#[ starlark_value( type = "ProviderCollection" ) ]
384405impl < ' v , V : ValueLike < ' v > > StarlarkValue < ' v > for ProviderCollectionGen < V >
385406where
386407 Self : ProvidesStaticType < ' v > ,
387408{
409+ fn get_type_starlark_repr ( ) -> Ty {
410+ PROVIDER_COLLECTION_TYPE . dupe ( )
411+ }
412+
413+ fn eval_type ( & self ) -> Option < Ty > {
414+ Some ( PROVIDER_COLLECTION_TYPE . dupe ( ) )
415+ }
416+
417+ fn typechecker_ty ( & self ) -> Option < Ty > {
418+ Some ( PROVIDER_COLLECTION_TYPE . dupe ( ) )
419+ }
420+
388421 fn at ( & self , index : Value < ' v > , _heap : & ' v Heap ) -> starlark:: Result < Value < ' v > > {
389422 match self . get_impl ( index, GetOp :: At ) ? {
390423 Either :: Left ( v) => Ok ( v) ,
0 commit comments