Skip to content

Commit b1ea1ae

Browse files
Merge pull request #4615 from swiftwasm/release/5.7
[pull] swiftwasm-release/5.7 from release/5.7
2 parents f2d9287 + 1c222a8 commit b1ea1ae

36 files changed

+952
-416
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3788,8 +3788,6 @@ ERROR(protocol_declares_unknown_primary_assoc_type,none,
37883788
(Identifier, Type))
37893789
ERROR(protocol_declares_duplicate_primary_assoc_type,none,
37903790
"duplicate primary associated type name %0", (Identifier))
3791-
ERROR(parameterized_protocol_not_supported,none,
3792-
"protocol type with type arguments can only be used as a generic constraint", ())
37933791
ERROR(protocol_does_not_have_primary_assoc_type,none,
37943792
"cannot specialize protocol type %0", (Type))
37953793
ERROR(parameterized_protocol_type_argument_count_mismatch,none,

include/swift/AST/FileUnit.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ class FileUnit : public DeclContext, public ASTAllocated<FileUnit> {
5555
/// Returns the synthesized file for this source file, if it exists.
5656
SynthesizedFileUnit *getSynthesizedFile() const;
5757

58+
/// Returns the synthesized file for this source file, creating one and
59+
/// inserting it into the module if it does not exist.
60+
///
61+
/// \warning Because this function mutates the parent module's list of files,
62+
/// it will invalidate the iterators of any upstream callers of
63+
/// \c ModuleDecl::getFiles().
5864
SynthesizedFileUnit &getOrCreateSynthesizedFile();
5965

6066
/// Look up a (possibly overloaded) value set at top-level scope

include/swift/AST/Types.h

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6752,38 +6752,6 @@ inline TypeBase *TypeBase::getDesugaredType() {
67526752
return cast<SugarType>(this)->getSinglyDesugaredType()->getDesugaredType();
67536753
}
67546754

6755-
inline bool TypeBase::hasSimpleTypeRepr() const {
6756-
// NOTE: Please keep this logic in sync with TypeRepr::isSimple().
6757-
switch (getKind()) {
6758-
case TypeKind::Function:
6759-
case TypeKind::GenericFunction:
6760-
return false;
6761-
6762-
case TypeKind::Metatype:
6763-
return !cast<const AnyMetatypeType>(this)->hasRepresentation();
6764-
6765-
case TypeKind::ExistentialMetatype:
6766-
case TypeKind::Existential:
6767-
return false;
6768-
6769-
case TypeKind::OpaqueTypeArchetype:
6770-
case TypeKind::OpenedArchetype:
6771-
return false;
6772-
6773-
case TypeKind::ProtocolComposition: {
6774-
// 'Any', 'AnyObject' and single protocol compositions are simple
6775-
auto composition = cast<const ProtocolCompositionType>(this);
6776-
auto memberCount = composition->getMembers().size();
6777-
if (composition->hasExplicitAnyObject())
6778-
return memberCount == 0;
6779-
return memberCount <= 1;
6780-
}
6781-
6782-
default:
6783-
return true;
6784-
}
6785-
}
6786-
67876755
} // end namespace swift
67886756

67896757
namespace llvm {

include/swift/SILOptimizer/Utils/Existential.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace swift {
3333
/// When successfull, ConcreteExistentialInfo can be used to determine the
3434
/// concrete type of the opened existential.
3535
struct OpenedArchetypeInfo {
36-
ArchetypeType *OpenedArchetype = nullptr;
36+
OpenedArchetypeType *OpenedArchetype = nullptr;
3737
// The opened value.
3838
SingleValueInstruction *OpenedArchetypeValue;
3939
// The existential value.

lib/AST/DiagnosticEngine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ static void formatDiagnosticArgument(StringRef Modifier,
737737
llvm::SmallString<256> AkaText;
738738
llvm::raw_svector_ostream OutAka(AkaText);
739739

740-
OutAka << getAkaTypeForDisplay(type);
740+
getAkaTypeForDisplay(type)->print(OutAka, printOptions);
741741
Out << llvm::format(FormatOpts.AKAFormatString.c_str(),
742742
typeName.c_str(), AkaText.c_str());
743743
} else {

lib/AST/DistributedDecl.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,12 +491,14 @@ bool AbstractFunctionDecl::isDistributedActorSystemRemoteCall(bool isVoidReturn)
491491
return false;
492492
}
493493

494-
// --- Check parameter: invocation InvocationEncoder
495-
// FIXME: NOT INOUT, but we crash today if not
494+
// --- Check parameter: invocation: inout InvocationEncoder
496495
auto invocationParam = params->get(2);
497496
if (invocationParam->getArgumentName() != C.Id_invocation) {
498497
return false;
499498
}
499+
if (!invocationParam->isInOut()) {
500+
return false;
501+
}
500502

501503
// --- Check parameter: throwing: Err.Type
502504
auto thrownTypeParam = params->get(3);

lib/AST/Module.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3055,6 +3055,15 @@ SynthesizedFileUnit &FileUnit::getOrCreateSynthesizedFile() {
30553055
return *thisSynth;
30563056
SynthesizedFile = new (getASTContext()) SynthesizedFileUnit(*this);
30573057
SynthesizedFileAndKind.setPointer(SynthesizedFile);
3058+
// FIXME: Mutating the module in-flight is not a good idea. Any
3059+
// callers above us in the stack that are iterating over
3060+
// the module's files will have their iterators invalidated. There's
3061+
// a strong chance that whatever analysis led to this function being
3062+
// called is doing just that!
3063+
//
3064+
// Instead we ought to just call ModuleDecl::clearLookupCache() here
3065+
// and patch out the places looking for synthesized files hanging off of
3066+
// source files.
30583067
getParentModule()->addFile(*SynthesizedFile);
30593068
}
30603069
return *SynthesizedFile;

lib/AST/Type.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6222,6 +6222,46 @@ bool TypeBase::isForeignReferenceType() {
62226222
return false;
62236223
}
62246224

6225+
bool TypeBase::hasSimpleTypeRepr() const {
6226+
// NOTE: Please keep this logic in sync with TypeRepr::isSimple().
6227+
switch (getKind()) {
6228+
case TypeKind::Function:
6229+
case TypeKind::GenericFunction:
6230+
return false;
6231+
6232+
case TypeKind::Metatype:
6233+
return !cast<const AnyMetatypeType>(this)->hasRepresentation();
6234+
6235+
case TypeKind::ExistentialMetatype:
6236+
case TypeKind::Existential:
6237+
return false;
6238+
6239+
case TypeKind::OpaqueTypeArchetype:
6240+
case TypeKind::OpenedArchetype:
6241+
return false;
6242+
6243+
case TypeKind::ProtocolComposition: {
6244+
// 'Any', 'AnyObject' and single protocol compositions are simple
6245+
auto composition = cast<const ProtocolCompositionType>(this);
6246+
auto memberCount = composition->getMembers().size();
6247+
if (composition->hasExplicitAnyObject())
6248+
return memberCount == 0;
6249+
return memberCount <= 1;
6250+
}
6251+
6252+
case TypeKind::GenericTypeParam: {
6253+
if (auto *decl = cast<const GenericTypeParamType>(this)->getDecl()) {
6254+
return !decl->isOpaqueType();
6255+
}
6256+
6257+
return true;
6258+
}
6259+
6260+
default:
6261+
return true;
6262+
}
6263+
}
6264+
62256265
bool CanType::isForeignReferenceType() {
62266266
if (auto *classDecl = getPointer()->lookThroughAllOptionalTypes()->getClassOrBoundGenericClass())
62276267
return classDecl->isForeignReferenceType();

lib/Frontend/Frontend.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,8 +1166,13 @@ bool CompilerInstance::loadPartialModulesAndImplicitImports(
11661166
bool CompilerInstance::forEachFileToTypeCheck(
11671167
llvm::function_ref<bool(SourceFile &)> fn) {
11681168
if (isWholeModuleCompilation()) {
1169-
for (auto fileName : getMainModule()->getFiles()) {
1170-
auto *SF = dyn_cast<SourceFile>(fileName);
1169+
// FIXME: Do not refactor this to use an iterator as long as
1170+
// ModuleDecl::addFile is called during Sema. Synthesized files pushed
1171+
// during semantic analysis will cause iterator invalidation here.
1172+
// See notes in SourceFile::getOrCreateSynthesizedFile() for more.
1173+
unsigned i = 0;
1174+
while (i < getMainModule()->getFiles().size()) {
1175+
auto *SF = dyn_cast<SourceFile>(getMainModule()->getFiles()[i++]);
11711176
if (!SF) {
11721177
continue;
11731178
}

lib/FrontendTool/FrontendTool.cpp

Lines changed: 84 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,57 +2092,8 @@ int swift::performFrontend(ArrayRef<const char *> Args,
20922092
PDC.setSuppressOutput(true);
20932093
}
20942094

2095-
// Because the serialized diagnostics consumer is initialized here,
2096-
// diagnostics emitted above, within CompilerInvocation::parseArgs, are never
2097-
// serialized. This is a non-issue because, in nearly all cases, frontend
2098-
// arguments are generated by the driver, not directly by a user. The driver
2099-
// is responsible for emitting diagnostics for its own errors. See SR-2683
2100-
// for details.
2101-
std::unique_ptr<DiagnosticConsumer> SerializedConsumerDispatcher =
2102-
createSerializedDiagnosticConsumerIfNeeded(
2103-
Invocation.getFrontendOptions().InputsAndOutputs);
2104-
if (SerializedConsumerDispatcher)
2105-
Instance->addDiagnosticConsumer(SerializedConsumerDispatcher.get());
2106-
2107-
std::unique_ptr<DiagnosticConsumer> FixItsConsumer =
2108-
createJSONFixItDiagnosticConsumerIfNeeded(Invocation);
2109-
if (FixItsConsumer)
2110-
Instance->addDiagnosticConsumer(FixItsConsumer.get());
2111-
2112-
if (Invocation.getDiagnosticOptions().UseColor)
2113-
PDC.forceColors();
2114-
2115-
PDC.setPrintEducationalNotes(
2116-
Invocation.getDiagnosticOptions().PrintEducationalNotes);
2117-
2118-
PDC.setFormattingStyle(
2119-
Invocation.getDiagnosticOptions().PrintedFormattingStyle);
2120-
2121-
if (Invocation.getFrontendOptions().PrintStats) {
2122-
llvm::EnableStatistics();
2123-
}
2124-
2125-
const DiagnosticOptions &diagOpts = Invocation.getDiagnosticOptions();
2126-
bool verifierEnabled = diagOpts.VerifyMode != DiagnosticOptions::NoVerify;
2127-
2128-
std::string InstanceSetupError;
2129-
if (Instance->setup(Invocation, InstanceSetupError)) {
2130-
return finishDiagProcessing(1, /*verifierEnabled*/ false);
2131-
}
2132-
2133-
// The compiler instance has been configured; notify our observer.
2134-
if (observer) {
2135-
observer->configuredCompiler(*Instance);
2136-
}
2137-
2138-
if (verifierEnabled) {
2139-
// Suppress printed diagnostic output during the compile if the verifier is
2140-
// enabled.
2141-
PDC.setSuppressOutput(true);
2142-
}
2143-
2144-
if (Invocation.getFrontendOptions().FrontendParseableOutput) {
2145-
const auto &IO = Invocation.getFrontendOptions().InputsAndOutputs;
2095+
auto emitParseableBeganMessage = [&Invocation, &Args]() {
2096+
const auto &IO = Invocation.getFrontendOptions().InputsAndOutputs;
21462097
const auto OSPid = getpid();
21472098
const auto ProcInfo = sys::TaskProcessInformation(OSPid);
21482099

@@ -2171,27 +2122,9 @@ int swift::performFrontend(ArrayRef<const char *> Args,
21712122
constructDetailedTaskDescription(Invocation, IO.getAllInputs(), Args),
21722123
OSPid, ProcInfo);
21732124
}
2174-
}
2175-
2176-
int ReturnValue = 0;
2177-
bool HadError = performCompile(*Instance, ReturnValue, observer);
2178-
2179-
if (verifierEnabled) {
2180-
DiagnosticEngine &diags = Instance->getDiags();
2181-
if (diags.hasFatalErrorOccurred() &&
2182-
!Invocation.getDiagnosticOptions().ShowDiagnosticsAfterFatalError) {
2183-
diags.resetHadAnyError();
2184-
PDC.setSuppressOutput(false);
2185-
diags.diagnose(SourceLoc(), diag::verify_encountered_fatal);
2186-
HadError = true;
2187-
}
2188-
}
2189-
2190-
auto r = finishDiagProcessing(HadError ? 1 : ReturnValue, verifierEnabled);
2191-
if (auto *StatsReporter = Instance->getStatsReporter())
2192-
StatsReporter->noteCurrentProcessExitStatus(r);
2125+
};
21932126

2194-
if (Invocation.getFrontendOptions().FrontendParseableOutput) {
2127+
auto emitParseableFinishedMessage = [&Invocation, &Args, &FileSpecificDiagnostics](int ExitStatus) {
21952128
const auto &IO = Invocation.getFrontendOptions().InputsAndOutputs;
21962129
const auto OSPid = getpid();
21972130
const auto ProcInfo = sys::TaskProcessInformation(OSPid);
@@ -2217,7 +2150,7 @@ int swift::performFrontend(ArrayRef<const char *> Args,
22172150

22182151
emitFinishedMessage(llvm::errs(),
22192152
mapFrontendInvocationToAction(Invocation),
2220-
JoinedDiags.str(), r, Pid - idx, ProcInfo);
2153+
JoinedDiags.str(), ExitStatus, Pid - idx, ProcInfo);
22212154
return false;
22222155
});
22232156
} else {
@@ -2234,10 +2167,88 @@ int swift::performFrontend(ArrayRef<const char *> Args,
22342167
std::ostream_iterator<std::string>(JoinedDiags, Delim));
22352168
emitFinishedMessage(llvm::errs(),
22362169
mapFrontendInvocationToAction(Invocation),
2237-
JoinedDiags.str(), r, OSPid, ProcInfo);
2170+
JoinedDiags.str(), ExitStatus, OSPid, ProcInfo);
22382171
}
2172+
};
2173+
2174+
// Because the serialized diagnostics consumer is initialized here,
2175+
// diagnostics emitted above, within CompilerInvocation::parseArgs, are never
2176+
// serialized. This is a non-issue because, in nearly all cases, frontend
2177+
// arguments are generated by the driver, not directly by a user. The driver
2178+
// is responsible for emitting diagnostics for its own errors. See SR-2683
2179+
// for details.
2180+
std::unique_ptr<DiagnosticConsumer> SerializedConsumerDispatcher =
2181+
createSerializedDiagnosticConsumerIfNeeded(
2182+
Invocation.getFrontendOptions().InputsAndOutputs);
2183+
if (SerializedConsumerDispatcher)
2184+
Instance->addDiagnosticConsumer(SerializedConsumerDispatcher.get());
2185+
2186+
std::unique_ptr<DiagnosticConsumer> FixItsConsumer =
2187+
createJSONFixItDiagnosticConsumerIfNeeded(Invocation);
2188+
if (FixItsConsumer)
2189+
Instance->addDiagnosticConsumer(FixItsConsumer.get());
2190+
2191+
if (Invocation.getDiagnosticOptions().UseColor)
2192+
PDC.forceColors();
2193+
2194+
PDC.setPrintEducationalNotes(
2195+
Invocation.getDiagnosticOptions().PrintEducationalNotes);
2196+
2197+
PDC.setFormattingStyle(
2198+
Invocation.getDiagnosticOptions().PrintedFormattingStyle);
2199+
2200+
if (Invocation.getFrontendOptions().PrintStats) {
2201+
llvm::EnableStatistics();
22392202
}
22402203

2204+
2205+
if (Invocation.getFrontendOptions().FrontendParseableOutput)
2206+
emitParseableBeganMessage();
2207+
2208+
const DiagnosticOptions &diagOpts = Invocation.getDiagnosticOptions();
2209+
bool verifierEnabled = diagOpts.VerifyMode != DiagnosticOptions::NoVerify;
2210+
2211+
std::string InstanceSetupError;
2212+
if (Instance->setup(Invocation, InstanceSetupError)) {
2213+
int ReturnCode = 1;
2214+
if (Invocation.getFrontendOptions().FrontendParseableOutput)
2215+
emitParseableFinishedMessage(ReturnCode);
2216+
2217+
return finishDiagProcessing(ReturnCode, /*verifierEnabled*/ false);
2218+
}
2219+
2220+
// The compiler instance has been configured; notify our observer.
2221+
if (observer) {
2222+
observer->configuredCompiler(*Instance);
2223+
}
2224+
2225+
if (verifierEnabled) {
2226+
// Suppress printed diagnostic output during the compile if the verifier is
2227+
// enabled.
2228+
PDC.setSuppressOutput(true);
2229+
}
2230+
2231+
int ReturnValue = 0;
2232+
bool HadError = performCompile(*Instance, ReturnValue, observer);
2233+
2234+
if (verifierEnabled) {
2235+
DiagnosticEngine &diags = Instance->getDiags();
2236+
if (diags.hasFatalErrorOccurred() &&
2237+
!Invocation.getDiagnosticOptions().ShowDiagnosticsAfterFatalError) {
2238+
diags.resetHadAnyError();
2239+
PDC.setSuppressOutput(false);
2240+
diags.diagnose(SourceLoc(), diag::verify_encountered_fatal);
2241+
HadError = true;
2242+
}
2243+
}
2244+
2245+
auto r = finishDiagProcessing(HadError ? 1 : ReturnValue, verifierEnabled);
2246+
if (auto *StatsReporter = Instance->getStatsReporter())
2247+
StatsReporter->noteCurrentProcessExitStatus(r);
2248+
2249+
if (Invocation.getFrontendOptions().FrontendParseableOutput)
2250+
emitParseableFinishedMessage(r);
2251+
22412252
return r;
22422253
}
22432254

0 commit comments

Comments
 (0)