16
16
#include " DeserializationErrors.h"
17
17
#include " SILFormat.h"
18
18
19
+ #include " SILSerializationFunctionBuilder.h"
19
20
#include " swift/AST/GenericSignature.h"
20
21
#include " swift/AST/PrettyStackTrace.h"
21
22
#include " swift/AST/ProtocolConformance.h"
24
25
#include " swift/SIL/SILArgument.h"
25
26
#include " swift/SIL/SILBuilder.h"
26
27
#include " swift/SIL/SILDebugScope.h"
27
- #include " swift/SIL/SILFunctionBuilder.h"
28
28
#include " swift/SIL/SILModule.h"
29
29
#include " swift/SIL/SILUndef.h"
30
30
#include " swift/Serialization/BCReadingExtras.h"
@@ -326,18 +326,6 @@ static SILType getSILType(Type Ty, SILValueCategory Category) {
326
326
Category);
327
327
}
328
328
329
- // / Helper function to create a bogus SILFunction to appease error paths.
330
- static SILFunction *createBogusSILFunction (SILModule &M,
331
- StringRef name,
332
- SILType type) {
333
- SourceLoc loc;
334
- SILFunctionBuilder builder (M);
335
- return builder.createFunction (
336
- SILLinkage::Private, name, type.castTo <SILFunctionType>(), nullptr ,
337
- RegularLocation (loc), IsNotBare, IsNotTransparent, IsNotSerialized,
338
- ProfileCounter (), IsNotThunk, SubclassScope::NotApplicable);
339
- }
340
-
341
329
// / Helper function to find a SILFunction, given its name and type.
342
330
SILFunction *SILDeserializer::getFuncForReference (StringRef name,
343
331
SILType type) {
@@ -360,9 +348,16 @@ SILFunction *SILDeserializer::getFuncForReference(StringRef name,
360
348
361
349
// FIXME: check for matching types.
362
350
363
- // Always return something of the right type.
364
- if (!fn) fn = createBogusSILFunction (SILMod, name, type);
365
- return fn;
351
+ // At this point, if fn is set, we know that we have a good function to use.
352
+ if (fn)
353
+ return fn;
354
+
355
+ // Otherwise, create a function declaration with the right type and a bogus
356
+ // source location. This ensures that we can at least parse the rest of the
357
+ // SIL.
358
+ SourceLoc sourceLoc;
359
+ SILSerializationFunctionBuilder builder (SILMod);
360
+ return builder.createDeclaration (name, type, RegularLocation (sourceLoc));
366
361
}
367
362
368
363
// / Helper function to find a SILFunction, given its name and type.
@@ -550,18 +545,18 @@ SILDeserializer::readSILFunctionChecked(DeclID FID, SILFunction *existingFn,
550
545
linkage == SILLinkage::PublicNonABI) {
551
546
fn->setLinkage (SILLinkage::SharedExternal);
552
547
}
553
-
554
- // Otherwise, create a new function.
555
548
} else {
556
- SILFunctionBuilder builder (SILMod);
557
- fn = builder.createFunction (
558
- linkage.getValue (), name, ty.castTo <SILFunctionType>(), nullptr , loc,
559
- IsNotBare, IsTransparent_t (isTransparent == 1 ),
560
- IsSerialized_t (isSerialized), ProfileCounter (), IsThunk_t (isThunk),
561
- SubclassScope::NotApplicable, (Inline_t)inlineStrategy);
549
+ // Otherwise, create a new function.
550
+ SILSerializationFunctionBuilder builder (SILMod);
551
+ fn = builder.createDeclaration (name, ty, loc);
552
+ fn->setLinkage (linkage.getValue ());
553
+ fn->setTransparent (IsTransparent_t (isTransparent == 1 ));
554
+ fn->setSerialized (IsSerialized_t (isSerialized));
555
+ fn->setThunk (IsThunk_t (isThunk));
556
+ fn->setInlineStrategy (Inline_t (inlineStrategy));
562
557
fn->setGlobalInit (isGlobal == 1 );
563
- fn->setEffectsKind (( EffectsKind) effect);
564
- fn->setOptimizationMode (( OptimizationMode) optimizationMode);
558
+ fn->setEffectsKind (EffectsKind ( effect) );
559
+ fn->setOptimizationMode (OptimizationMode ( optimizationMode) );
565
560
fn->setWeakLinked (isWeakLinked);
566
561
if (clangNodeOwner)
567
562
fn->setClangNodeOwner (clangNodeOwner);
0 commit comments