Skip to content

IRGen: Note use of types in conditional requirements of protocol conformances #32213

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

Conversation

aschwaighofer
Copy link
Contributor

It is possible for the only mention of a conditional requirement to appear in
the protocol conformance record which is too late for lazy metadata type
emission.

SR-12891
rdar://63819461

@aschwaighofer
Copy link
Contributor Author

@swift-ci Please test

@@ -2114,6 +2114,46 @@ static bool isConstantWitnessTable(SILWitnessTable *wt) {
return true;
}

static void noteUseOfTypeMetadataInConditionalRequirements(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why isn't this handled by emitting those mangled names in the witness table?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the witness table:

private enum E {
}

private protocol P {
  associatedtype AT
}

private struct S<A, B> {
  init()
}

extension S : P where A == E {
  typealias AT = B
}
sil_witness_table private <A, B where A == E> S<A, B>: P module ProtoCrash {
  associated_type AT: B
}

Which mangled names are you referring to?

Copy link
Contributor Author

@aschwaighofer aschwaighofer Jun 5, 2020

Choose a reason for hiding this comment

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

Here is the ordering of code:

    // Emit the module contents.                                                
    irgen.emitGlobalTopLevel(linkerDirectives);    
...
    // Okay, emit any definitions that we suddenly need.                        
    irgen.emitLazyDefinitions();                                                
                                                                                
    // Register our info with the runtime if needed.                            
    if (Opts.UseJIT) {                                                          
      IGM.emitBuiltinReflectionMetadata();                                      
      IGM.emitRuntimeRegistration();                                            
    } else {                                                                    
      // Emit protocol conformances into a section we can recognize at runtime. 
      // In JIT mode these are manually registered above.                       
      IGM.emitSwiftProtocols();                                                 
      IGM.emitProtocolConformances();

IGM.emitProtocolConformances will create typerefs (which note the use of type metadata) but this is too late because we already have emitted the lazy metadata definitions.

Copy link
Contributor

Choose a reason for hiding this comment

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

Does it work if you emit the lazy definitions after protocol conformances?

We might need a loop to pump this until it stops adding new lazy definitions. I'm thinking of a case where emitting conditional requirements triggers lazy metadata emission, which triggers emitting another witness table, and so on.

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 moved emission of individual protocol conformances into witness table emission which happens before emitting lazy definitions (and as part of lazy definition emission).

@swift-ci
Copy link
Contributor

swift-ci commented Jun 5, 2020

Build failed
Swift Test Linux Platform
Git Sha - 81836bd6ca8b70586c3c87aed97ea5dbf0b5ae07

@aschwaighofer
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

swift-ci commented Jun 8, 2020

Build failed
Swift Test Linux Platform
Git Sha - 81836bd6ca8b70586c3c87aed97ea5dbf0b5ae07

@swift-ci
Copy link
Contributor

swift-ci commented Jun 8, 2020

Build failed
Swift Test OS X Platform
Git Sha - 81836bd6ca8b70586c3c87aed97ea5dbf0b5ae07

@aschwaighofer
Copy link
Contributor Author

@swift-ci Please test windows

@aschwaighofer
Copy link
Contributor Author

@swift-ci Please test source compatibility

It is possible that the only mention of metadata happens as part of protocol conformannce emission.
This ordering makes sure we emit this metadata.

SR-12891
rdar://63819461
@aschwaighofer aschwaighofer force-pushed the note_use_of_type_metadata_in_conditional_reqts branch from d4ae4a7 to 7997183 Compare June 9, 2020 19:44
@aschwaighofer
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

swift-ci commented Jun 9, 2020

Build failed
Swift Test Linux Platform
Git Sha - d4ae4a747d810af11205f4e1dc4eca120cbfa014

@swift-ci
Copy link
Contributor

swift-ci commented Jun 9, 2020

Build failed
Swift Test OS X Platform
Git Sha - d4ae4a747d810af11205f4e1dc4eca120cbfa014

@aschwaighofer
Copy link
Contributor Author

@swift-ci Please test

@aschwaighofer
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 7997183

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 7997183

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.

3 participants