|
10 | 10 | //
|
11 | 11 | //===----------------------------------------------------------------------===//
|
12 | 12 |
|
| 13 | +#include "SILParserFunctionBuilder.h" |
13 | 14 | #include "swift/AST/ASTWalker.h"
|
14 | 15 | #include "swift/AST/ExistentialLayout.h"
|
15 | 16 | #include "swift/AST/GenericEnvironment.h"
|
|
26 | 27 | #include "swift/SIL/SILArgument.h"
|
27 | 28 | #include "swift/SIL/SILBuilder.h"
|
28 | 29 | #include "swift/SIL/SILDebugScope.h"
|
29 |
| -#include "swift/SIL/SILFunctionBuilder.h" |
30 | 30 | #include "swift/SIL/SILModule.h"
|
31 | 31 | #include "swift/SIL/SILUndef.h"
|
32 | 32 | #include "swift/SIL/TypeLowering.h"
|
@@ -517,93 +517,78 @@ bool SILParser::diagnoseProblems() {
|
517 | 517 |
|
518 | 518 | /// getGlobalNameForDefinition - Given a definition of a global name, look
|
519 | 519 | /// it up and return an appropriate SIL function.
|
520 |
| -SILFunction *SILParser::getGlobalNameForDefinition(Identifier Name, |
521 |
| - CanSILFunctionType Ty, |
522 |
| - SourceLoc Loc) { |
| 520 | +SILFunction *SILParser::getGlobalNameForDefinition(Identifier name, |
| 521 | + CanSILFunctionType ty, |
| 522 | + SourceLoc sourceLoc) { |
| 523 | + SILParserFunctionBuilder builder(SILMod); |
| 524 | + auto silLoc = RegularLocation(sourceLoc); |
| 525 | + |
523 | 526 | // Check to see if a function of this name has been forward referenced. If so
|
524 | 527 | // complete the forward reference.
|
525 |
| - auto It = TUState.ForwardRefFns.find(Name); |
526 |
| - if (It != TUState.ForwardRefFns.end()) { |
527 |
| - SILFunction *Fn = It->second.first; |
528 |
| - |
| 528 | + auto iter = TUState.ForwardRefFns.find(name); |
| 529 | + if (iter != TUState.ForwardRefFns.end()) { |
| 530 | + SILFunction *fn = iter->second.first; |
| 531 | + |
529 | 532 | // Verify that the types match up.
|
530 |
| - if (Fn->getLoweredFunctionType() != Ty) { |
531 |
| - P.diagnose(Loc, diag::sil_value_use_type_mismatch, Name.str(), |
532 |
| - Fn->getLoweredFunctionType(), Ty); |
533 |
| - P.diagnose(It->second.second, diag::sil_prior_reference); |
534 |
| - auto loc = RegularLocation(Loc); |
535 |
| - SILFunctionBuilder builder(SILMod); |
536 |
| - Fn = builder.createFunction(SILLinkage::Private, "", Ty, nullptr, loc, |
537 |
| - IsNotBare, IsNotTransparent, IsNotSerialized); |
538 |
| - Fn->setDebugScope(new (SILMod) SILDebugScope(loc, Fn)); |
| 533 | + if (fn->getLoweredFunctionType() != ty) { |
| 534 | + P.diagnose(sourceLoc, diag::sil_value_use_type_mismatch, name.str(), |
| 535 | + fn->getLoweredFunctionType(), ty); |
| 536 | + P.diagnose(iter->second.second, diag::sil_prior_reference); |
| 537 | + fn = builder.createFunctionForForwardReference("" /*name*/, ty, silLoc); |
539 | 538 | }
|
540 |
| - |
541 |
| - assert(Fn->isExternalDeclaration() && "Forward defns cannot have bodies!"); |
542 |
| - TUState.ForwardRefFns.erase(It); |
| 539 | + |
| 540 | + assert(fn->isExternalDeclaration() && "Forward defns cannot have bodies!"); |
| 541 | + TUState.ForwardRefFns.erase(iter); |
543 | 542 |
|
544 | 543 | // Move the function to this position in the module.
|
545 |
| - SILMod.getFunctionList().remove(Fn); |
546 |
| - SILMod.getFunctionList().push_back(Fn); |
| 544 | + // |
| 545 | + // FIXME: Should we move this functionality into SILParserFunctionBuilder? |
| 546 | + SILMod.getFunctionList().remove(fn); |
| 547 | + SILMod.getFunctionList().push_back(fn); |
547 | 548 |
|
548 |
| - return Fn; |
| 549 | + return fn; |
549 | 550 | }
|
550 |
| - |
551 |
| - auto loc = RegularLocation(Loc); |
| 551 | + |
552 | 552 | // If we don't have a forward reference, make sure the function hasn't been
|
553 | 553 | // defined already.
|
554 |
| - if (SILMod.lookUpFunction(Name.str()) != nullptr) { |
555 |
| - P.diagnose(Loc, diag::sil_value_redefinition, Name.str()); |
556 |
| - SILFunctionBuilder builder(SILMod); |
557 |
| - auto *fn = |
558 |
| - builder.createFunction(SILLinkage::Private, "", Ty, nullptr, loc, |
559 |
| - IsNotBare, IsNotTransparent, IsNotSerialized); |
560 |
| - fn->setDebugScope(new (SILMod) SILDebugScope(loc, fn)); |
561 |
| - return fn; |
| 554 | + if (SILMod.lookUpFunction(name.str()) != nullptr) { |
| 555 | + P.diagnose(sourceLoc, diag::sil_value_redefinition, name.str()); |
| 556 | + return builder.createFunctionForForwardReference("" /*name*/, ty, silLoc); |
562 | 557 | }
|
563 | 558 |
|
564 | 559 | // Otherwise, this definition is the first use of this name.
|
565 |
| - SILFunctionBuilder builder(SILMod); |
566 |
| - auto *fn = |
567 |
| - builder.createFunction(SILLinkage::Private, Name.str(), Ty, nullptr, loc, |
568 |
| - IsNotBare, IsNotTransparent, IsNotSerialized); |
569 |
| - fn->setDebugScope(new (SILMod) SILDebugScope(loc, fn)); |
570 |
| - return fn; |
| 560 | + return builder.createFunctionForForwardReference(name.str(), ty, silLoc); |
571 | 561 | }
|
572 | 562 |
|
573 |
| - |
574 |
| - |
575 | 563 | /// getGlobalNameForReference - Given a reference to a global name, look it
|
576 | 564 | /// up and return an appropriate SIL function.
|
577 |
| -SILFunction *SILParser::getGlobalNameForReference(Identifier Name, |
578 |
| - CanSILFunctionType Ty, |
579 |
| - SourceLoc Loc, |
580 |
| - bool IgnoreFwdRef) { |
581 |
| - auto loc = RegularLocation(Loc); |
582 |
| - |
| 565 | +SILFunction *SILParser::getGlobalNameForReference(Identifier name, |
| 566 | + CanSILFunctionType funcTy, |
| 567 | + SourceLoc sourceLoc, |
| 568 | + bool ignoreFwdRef) { |
| 569 | + SILParserFunctionBuilder builder(SILMod); |
| 570 | + auto silLoc = RegularLocation(sourceLoc); |
| 571 | + |
583 | 572 | // Check to see if we have a function by this name already.
|
584 |
| - if (SILFunction *FnRef = SILMod.lookUpFunction(Name.str())) { |
| 573 | + if (SILFunction *fn = SILMod.lookUpFunction(name.str())) { |
585 | 574 | // If so, check for matching types.
|
586 |
| - if (FnRef->getLoweredFunctionType() != Ty) { |
587 |
| - P.diagnose(Loc, diag::sil_value_use_type_mismatch, |
588 |
| - Name.str(), FnRef->getLoweredFunctionType(), Ty); |
589 |
| - SILFunctionBuilder builder(SILMod); |
590 |
| - FnRef = |
591 |
| - builder.createFunction(SILLinkage::Private, "", Ty, nullptr, loc, |
592 |
| - IsNotBare, IsNotTransparent, IsNotSerialized); |
593 |
| - FnRef->setDebugScope(new (SILMod) SILDebugScope(loc, FnRef)); |
| 575 | + if (fn->getLoweredFunctionType() == funcTy) { |
| 576 | + return fn; |
594 | 577 | }
|
595 |
| - return FnRef; |
| 578 | + |
| 579 | + P.diagnose(sourceLoc, diag::sil_value_use_type_mismatch, name.str(), |
| 580 | + fn->getLoweredFunctionType(), funcTy); |
| 581 | + |
| 582 | + return builder.createFunctionForForwardReference("" /*name*/, funcTy, |
| 583 | + silLoc); |
596 | 584 | }
|
597 | 585 |
|
598 | 586 | // If we didn't find a function, create a new one - it must be a forward
|
599 | 587 | // reference.
|
600 |
| - SILFunctionBuilder builder(SILMod); |
601 |
| - auto *Fn = |
602 |
| - builder.createFunction(SILLinkage::Private, Name.str(), Ty, nullptr, loc, |
603 |
| - IsNotBare, IsNotTransparent, IsNotSerialized); |
604 |
| - Fn->setDebugScope(new (SILMod) SILDebugScope(loc, Fn)); |
605 |
| - TUState.ForwardRefFns[Name] = { Fn, IgnoreFwdRef ? SourceLoc() : Loc }; |
606 |
| - return Fn; |
| 588 | + auto *fn = |
| 589 | + builder.createFunctionForForwardReference(name.str(), funcTy, silLoc); |
| 590 | + TUState.ForwardRefFns[name] = {fn, ignoreFwdRef ? SourceLoc() : sourceLoc}; |
| 591 | + return fn; |
607 | 592 | }
|
608 | 593 |
|
609 | 594 |
|
|
0 commit comments