@@ -653,16 +653,16 @@ static Type getResultType(TypeChecker &TC, FuncDecl *fn, Type resultType) {
653
653
}
654
654
655
655
bool TypeChecker::validateGenericFuncSignature (AbstractFunctionDecl *func) {
656
+ bool invalid = false ;
657
+
656
658
// Create the archetype builder.
657
659
ArchetypeBuilder builder = createArchetypeBuilder (func->getParentModule ());
658
660
659
661
// Type check the function declaration, treating all generic type
660
662
// parameters as dependent, unresolved.
661
663
DependentGenericTypeResolver dependentResolver (builder);
662
- if (checkGenericFuncSignature (*this , &builder, func, dependentResolver)) {
663
- func->overwriteType (ErrorType::get (Context));
664
- return true ;
665
- }
664
+ if (checkGenericFuncSignature (*this , &builder, func, dependentResolver))
665
+ invalid = true ;
666
666
667
667
// If this triggered a recursive validation, back out: we're done.
668
668
// FIXME: This is an awful hack.
@@ -677,10 +677,8 @@ bool TypeChecker::validateGenericFuncSignature(AbstractFunctionDecl *func) {
677
677
// function signature and type-check it again, completely.
678
678
revertGenericFuncSignature (func);
679
679
CompleteGenericTypeResolver completeResolver (*this , builder);
680
- if (checkGenericFuncSignature (*this , nullptr , func, completeResolver)) {
681
- func->overwriteType (ErrorType::get (Context));
682
- return true ;
683
- }
680
+ if (checkGenericFuncSignature (*this , nullptr , func, completeResolver))
681
+ invalid = true ;
684
682
685
683
// The generic function signature is complete and well-formed. Determine
686
684
// the type of the generic function.
@@ -694,6 +692,32 @@ bool TypeChecker::validateGenericFuncSignature(AbstractFunctionDecl *func) {
694
692
// Collect the requirements placed on the generic parameter types.
695
693
SmallVector<Requirement, 4 > requirements;
696
694
collectRequirements (builder, allGenericParams, requirements);
695
+
696
+ auto sig = GenericSignature::get (allGenericParams, requirements);
697
+
698
+ // Debugging of the archetype builder and generic signature generation.
699
+ if (sig && Context.LangOpts .DebugGenericSignatures ) {
700
+ func->dumpRef (llvm::errs ());
701
+ llvm::errs () << " \n " ;
702
+ builder.dump (llvm::errs ());
703
+ llvm::errs () << " Generic signature: " ;
704
+ sig->print (llvm::errs ());
705
+ llvm::errs () << " \n " ;
706
+ llvm::errs () << " Canonical generic signature: " ;
707
+ sig->getCanonicalSignature ()->print (llvm::errs ());
708
+ llvm::errs () << " \n " ;
709
+ llvm::errs () << " Canonical generic signature for mangling: " ;
710
+ sig->getCanonicalManglingSignature (*func->getParentModule ())
711
+ ->print (llvm::errs ());
712
+ llvm::errs () << " \n " ;
713
+ }
714
+
715
+ func->setGenericSignature (sig);
716
+
717
+ if (invalid) {
718
+ func->overwriteType (ErrorType::get (Context));
719
+ return true ;
720
+ }
697
721
698
722
// Compute the function type.
699
723
Type funcTy;
@@ -742,25 +766,6 @@ bool TypeChecker::validateGenericFuncSignature(AbstractFunctionDecl *func) {
742
766
patterns = storedPatterns;
743
767
}
744
768
745
- auto sig = GenericSignature::get (allGenericParams, requirements);
746
-
747
- // Debugging of the archetype builder and generic signature generation.
748
- if (Context.LangOpts .DebugGenericSignatures ) {
749
- func->dumpRef (llvm::errs ());
750
- llvm::errs () << " \n " ;
751
- builder.dump (llvm::errs ());
752
- llvm::errs () << " Generic signature: " ;
753
- sig->print (llvm::errs ());
754
- llvm::errs () << " \n " ;
755
- llvm::errs () << " Canonical generic signature: " ;
756
- sig->getCanonicalSignature ()->print (llvm::errs ());
757
- llvm::errs () << " \n " ;
758
- llvm::errs () << " Canonical generic signature for mangling: " ;
759
- sig->getCanonicalManglingSignature (*func->getParentModule ())
760
- ->print (llvm::errs ());
761
- llvm::errs () << " \n " ;
762
- }
763
-
764
769
bool hasSelf = func->getDeclContext ()->isTypeContext ();
765
770
for (unsigned i = 0 , e = patterns.size (); i != e; ++i) {
766
771
Type argTy;
0 commit comments