Skip to content

AST: Fix ReplaceOpaqueTypesWithUnderlyingTypes to consider the current resilience expansion in non resilient mode #70770

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 11, 2024

Conversation

aschwaighofer
Copy link
Contributor

When we decide which access level we can allow for types we need to consider the resilience expansion context. 'internal' visibility cannot be allowed to be looked through in inlineable code as an external module does not have visiblity to such a symbol.

rdar://119725428

…t resilience expansion in non resilient mode

When we decide which access level we can allow for types we need to
consider the resilience expansion context. 'internal' visibility cannot
be allowed to be looked through in inlineable code as an external
module does not have visiblity to such a symbol.

rdar://119725428
@aschwaighofer
Copy link
Contributor Author

@swift-ci test

@@ -1056,7 +1057,8 @@ static bool canSubstituteTypeInto(Type ty, const DeclContext *dc,

case OpaqueSubstitutionKind::SubstituteNonResilientModule:
// Can't access types that are not public from a different module.
if (dc->getParentModule() == typeDecl->getDeclContext()->getParentModule())
if (dc->getParentModule() == typeDecl->getDeclContext()->getParentModule() &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this condition is the same as if (typeDecl->isResilient(contextExpansion)) no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe so:

We arrive at this if statement with the assumption SubstituteNonResilientModule (the naming decl of the opaque type is in a non-resilient module).

This means thetypeDecl->isResilient(dc->getParentModule(), contextExpansion) code would return false if dc->getParentModule() == typeDecl->getDeclContext()->getParentModule() and contextExpansion == ResilienceExpansion::Maximal.

bool NominalTypeDecl::isResilient() const {                                     
  if (!isFormallyResilient())                                                   
    return false;                                                               
                                                                                
  return getModuleContext()->isResilient(); // would also return false but we don't get here
} 
bool NominalTypeDecl::isResilient(ModuleDecl *M,                                
                                  ResilienceExpansion expansion) const {        
  switch (expansion) {                                                          
  case ResilienceExpansion::Minimal:                                            
    return isResilient();                                                        
  case ResilienceExpansion::Maximal:                                            
    // We can access declarations from the same module                          
    // non-resiliently in a maximal context.                                             
    if (M == getModuleContext()) {                                              
      return false;                    // <<< === will return false                                                  
    }
    ...                                                                
    // Otherwise, we have to access the declaration resiliently if it's         
    // resilient anywhere.                                                      
    return isResilient();                                                       
  } 

Copy link
Contributor

@slavapestov slavapestov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants