20
20
#include " SILFormat.h"
21
21
#include " SILSerializationFunctionBuilder.h"
22
22
23
+ #include " swift/AST/DiagnosticsSIL.h"
23
24
#include " swift/AST/GenericSignature.h"
24
25
#include " swift/AST/PrettyStackTrace.h"
25
26
#include " swift/AST/ProtocolConformance.h"
@@ -392,7 +393,8 @@ SILDeserializer::getSILDifferentiabilityWitnessForReference(
392
393
393
394
// / Helper function to find a SILFunction, given its name and type.
394
395
SILFunction *SILDeserializer::getFuncForReference (StringRef name,
395
- SILType type) {
396
+ SILType type,
397
+ TypeExpansionContext context) {
396
398
// Check to see if we have a function by this name already.
397
399
SILFunction *fn = SILMod.lookUpFunction (name);
398
400
if (!fn) {
@@ -410,11 +412,27 @@ SILFunction *SILDeserializer::getFuncForReference(StringRef name,
410
412
}
411
413
}
412
414
413
- // FIXME: check for matching types.
414
-
415
415
// At this point, if fn is set, we know that we have a good function to use.
416
- if (fn)
416
+ if (fn) {
417
+ SILType fnType = fn->getLoweredTypeInContext (context);
418
+ if (fnType != type &&
419
+ // It can happen that opaque return types cause a mismatch when merging
420
+ // modules, without causing any further assertion failures.
421
+ // TODO: fix the underlying problem
422
+ fnType.hasOpaqueArchetype () == type.hasOpaqueArchetype ()) {
423
+ StringRef fnName = fn->getName ();
424
+ if (auto *dc = fn->getDeclContext ()) {
425
+ if (auto *decl = dyn_cast_or_null<AbstractFunctionDecl>(dc->getAsDecl ()))
426
+ fnName = decl->getNameStr ();
427
+ }
428
+ fn->getModule ().getASTContext ().Diags .diagnose (
429
+ fn->getLocation ().getSourceLoc (),
430
+ diag::deserialize_function_type_mismatch,
431
+ fnName, fnType.getASTType (), type.getASTType ());
432
+ exit (1 );
433
+ }
417
434
return fn;
435
+ }
418
436
419
437
// Otherwise, create a function declaration with the right type and a bogus
420
438
// source location. This ensures that we can at least parse the rest of the
@@ -1969,7 +1987,8 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn,
1969
1987
ResultInst = Builder.createFunctionRef (
1970
1988
Loc,
1971
1989
getFuncForReference (
1972
- FuncName, getSILType (Ty, (SILValueCategory)TyCategory, nullptr )));
1990
+ FuncName, getSILType (Ty, (SILValueCategory)TyCategory, nullptr ),
1991
+ Builder.getTypeExpansionContext ()));
1973
1992
break ;
1974
1993
}
1975
1994
case SILInstructionKind::DynamicFunctionRefInst: {
@@ -1978,7 +1997,8 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn,
1978
1997
ResultInst = Builder.createDynamicFunctionRef (
1979
1998
Loc,
1980
1999
getFuncForReference (
1981
- FuncName, getSILType (Ty, (SILValueCategory)TyCategory, nullptr )));
2000
+ FuncName, getSILType (Ty, (SILValueCategory)TyCategory, nullptr ),
2001
+ Builder.getTypeExpansionContext ()));
1982
2002
break ;
1983
2003
}
1984
2004
case SILInstructionKind::PreviousDynamicFunctionRefInst: {
@@ -1987,7 +2007,8 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn,
1987
2007
ResultInst = Builder.createPreviousDynamicFunctionRef (
1988
2008
Loc,
1989
2009
getFuncForReference (
1990
- FuncName, getSILType (Ty, (SILValueCategory)TyCategory, nullptr )));
2010
+ FuncName, getSILType (Ty, (SILValueCategory)TyCategory, nullptr ),
2011
+ Builder.getTypeExpansionContext ()));
1991
2012
break ;
1992
2013
}
1993
2014
case SILInstructionKind::MarkDependenceInst: {
0 commit comments