Skip to content

Commit 5a196c7

Browse files
authored
Merge pull request #1560 from swiftwasm/maxd/fix-5.3
Fix CI issues in the 5.3 branch
2 parents bf51b9a + 63d94c8 commit 5a196c7

File tree

121 files changed

+3054
-938
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+3054
-938
lines changed

include/swift/AST/Decl.h

+2
Original file line numberDiff line numberDiff line change
@@ -3594,6 +3594,8 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
35943594
/// initializer.
35953595
bool hasDefaultInitializer() const;
35963596

3597+
bool isTypeErasedGenericClass() const;
3598+
35973599
/// Retrieves the synthesized zero parameter default initializer for this
35983600
/// declaration, or \c nullptr if it doesn't have one.
35993601
ConstructorDecl *getDefaultInitializer() const;

include/swift/AST/DiagnosticsSema.def

+12
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,12 @@ ERROR(extra_trailing_closure_in_call,none,
11741174
ERROR(trailing_closure_bad_param,none,
11751175
"trailing closure passed to parameter of type %0 that does not "
11761176
"accept a closure", (Type))
1177+
WARNING(unlabeled_trailing_closure_deprecated,none,
1178+
"backward matching of the unlabeled trailing closure is deprecated; label the argument with %0 to suppress this warning",
1179+
(Identifier))
1180+
NOTE(decl_multiple_defaulted_closure_parameters,none,
1181+
"%0 contains defaulted closure parameters %1 and %2",
1182+
(DeclName, Identifier, Identifier))
11771183
NOTE(candidate_with_extraneous_args,none,
11781184
"candidate %0 requires %1 argument%s1, "
11791185
"but %2 %select{were|was}3 %select{provided|used in closure body}4",
@@ -2678,6 +2684,12 @@ ERROR(decl_from_hidden_module,none,
26782684
"%select{%3 has been imported as implementation-only|"
26792685
"it is an SPI imported from %3}4",
26802686
(DescriptiveDeclKind, DeclName, unsigned, Identifier, unsigned))
2687+
WARNING(decl_from_hidden_module_warn,none,
2688+
"cannot use %0 %1 %select{in SPI|as property wrapper in SPI|"
2689+
"in an extension with public or '@usableFromInline' members|"
2690+
"in an extension with conditional conformances}2; "
2691+
"%select{%3 has been imported as implementation-only}4",
2692+
(DescriptiveDeclKind, DeclName, unsigned, Identifier, unsigned))
26812693
ERROR(conformance_from_implementation_only_module,none,
26822694
"cannot use conformance of %0 to %1 %select{here|as property wrapper here|"
26832695
"in an extension with public or '@usableFromInline' members|"

include/swift/AST/Type.h

+6
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ class CanType : public Type {
389389
static bool isExistentialTypeImpl(CanType type);
390390
static bool isAnyExistentialTypeImpl(CanType type);
391391
static bool isObjCExistentialTypeImpl(CanType type);
392+
static bool isTypeErasedGenericClassTypeImpl(CanType type);
392393
static CanType getOptionalObjectTypeImpl(CanType type);
393394
static CanType getReferenceStorageReferentImpl(CanType type);
394395
static CanType getWithoutSpecifierTypeImpl(CanType type);
@@ -475,6 +476,11 @@ class CanType : public Type {
475476
return isObjCExistentialTypeImpl(*this);
476477
}
477478

479+
// Is this an ObjC generic class.
480+
bool isTypeErasedGenericClassType() const {
481+
return isTypeErasedGenericClassTypeImpl(*this);
482+
}
483+
478484
ClassDecl *getClassOrBoundGenericClass() const; // in Types.h
479485
StructDecl *getStructOrBoundGenericStruct() const; // in Types.h
480486
EnumDecl *getEnumOrBoundGenericEnum() const; // in Types.h

include/swift/AST/Types.h

+5
Original file line numberDiff line numberDiff line change
@@ -3484,6 +3484,7 @@ END_CAN_TYPE_WRAPPER(FunctionType, AnyFunctionType)
34843484
/// has a default argument.
34853485
struct ParameterListInfo {
34863486
SmallBitVector defaultArguments;
3487+
SmallBitVector acceptsUnlabeledTrailingClosures;
34873488

34883489
public:
34893490
ParameterListInfo() { }
@@ -3494,6 +3495,10 @@ struct ParameterListInfo {
34943495
/// Whether the parameter at the given index has a default argument.
34953496
bool hasDefaultArgument(unsigned paramIdx) const;
34963497

3498+
/// Whether the parameter accepts an unlabeled trailing closure argument
3499+
/// according to the "forward-scan" rule.
3500+
bool acceptsUnlabeledTrailingClosureArgument(unsigned paramIdx) const;
3501+
34973502
/// Retrieve the number of non-defaulted parameters.
34983503
unsigned numNonDefaultedParameters() const {
34993504
return defaultArguments.count();

include/swift/Basic/LangOptions.h

+11
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,14 @@ namespace swift {
250250
/// Build the ASTScope tree lazily
251251
bool LazyASTScopes = true;
252252

253+
/// Whether to enable the "fuzzy" forward-scanning behavior for trailing
254+
/// closure matching, which skips over defaulted closure parameters
255+
/// to match later (non-defaulted) closure parameters
256+
///
257+
/// This is a backward-compatibility hack for unlabeled trailing closures,
258+
/// to be disabled in Swift 6+.
259+
bool EnableFuzzyForwardScanTrailingClosureMatching = true;
260+
253261
/// Use Clang function types for computing canonical types.
254262
/// If this option is false, the clang function types will still be computed
255263
/// but will not be used for checking type equality.
@@ -350,6 +358,9 @@ namespace swift {
350358
/// If set to \c false, fall back to the legacy manual reference name tracking code.
351359
bool EnableRequestBasedIncrementalDependencies = true;
352360

361+
/// Load swiftmodule files in memory as volatile and avoid mmap.
362+
bool EnableVolatileModules = false;
363+
353364
/// Sets the target we are building for and updates platform conditions
354365
/// to match.
355366
///

include/swift/Basic/Platform.h

-5
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,6 @@ namespace swift {
7171
/// Returns the platform Kind for Darwin triples.
7272
DarwinPlatformKind getDarwinPlatformKind(const llvm::Triple &triple);
7373

74-
/// Maps an arbitrary platform to its non-simulator equivalent.
75-
///
76-
/// If \p platform is not a simulator platform, it will be returned as is.
77-
DarwinPlatformKind getNonSimulatorPlatform(DarwinPlatformKind platform);
78-
7974
/// Returns the architecture component of the path for a given target triple.
8075
///
8176
/// Typically this is used for mapping the architecture component of the

include/swift/Option/FrontendOptions.td

+3
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,9 @@ def warn_long_expression_type_checking_EQ : Joined<["-"], "warn-long-expression-
455455
def Rmodule_interface_rebuild : Flag<["-"], "Rmodule-interface-rebuild">,
456456
HelpText<"Emits a remark if an imported module needs to be re-compiled from its module interface">;
457457

458+
def enable_volatile_modules : Flag<["-"], "enable-volatile-modules">,
459+
HelpText<"Load Swift modules in memory">;
460+
458461
def solver_expression_time_threshold_EQ : Joined<["-"], "solver-expression-time-threshold=">;
459462

460463
def solver_disable_shrink :

include/swift/Option/Options.td

+10
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,16 @@ def enable_experimental_concise_pound_file : Flag<["-"],
519519
Flags<[FrontendOption, ModuleInterfaceOption]>,
520520
HelpText<"Enable experimental concise '#file' identifier">;
521521

522+
def disable_fuzzy_forward_scan_trailing_closure_matching : Flag<["-"],
523+
"disable-fuzzy-forward-scan-trailing-closure-matching">,
524+
Flags<[FrontendOption]>,
525+
HelpText<"Disable fuzzy forward-scan trailing closure matching">;
526+
527+
def enable_fuzzy_forward_scan_trailing_closure_matching : Flag<["-"],
528+
"enable-fuzzy-forward-scan-trailing-closure-matching">,
529+
Flags<[FrontendOption]>,
530+
HelpText<"Enable fuzzy forward-scan trailing closure matching">;
531+
522532
// Diagnostic control options
523533
def suppress_warnings : Flag<["-"], "suppress-warnings">,
524534
Flags<[FrontendOption]>,

include/swift/Runtime/RuntimeFunctions.def

+1-1
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,7 @@ FUNCTION(ConformsToProtocol,
11721172

11731173
// bool swift_isClassType(type*);
11741174
FUNCTION(IsClassType,
1175-
swift_isClassType, C_CC, AlwaysAvailable,
1175+
swift_isClassType, SwiftCC, AlwaysAvailable,
11761176
RETURNS(Int1Ty),
11771177
ARGS(TypeMetadataPtrTy),
11781178
ATTRS(ZExt, NoUnwind, ReadNone))

lib/AST/Decl.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -4190,6 +4190,14 @@ bool NominalTypeDecl::hasDefaultInitializer() const {
41904190
false);
41914191
}
41924192

4193+
bool NominalTypeDecl::isTypeErasedGenericClass() const {
4194+
// ObjC classes are type erased.
4195+
// TODO: Unless they have magic methods...
4196+
if (auto clas = dyn_cast<ClassDecl>(this))
4197+
return clas->hasClangNode() && clas->isGenericContext();
4198+
return false;
4199+
}
4200+
41934201
ConstructorDecl *NominalTypeDecl::getDefaultInitializer() const {
41944202
if (!hasDefaultInitializer())
41954203
return nullptr;

lib/AST/Expr.cpp

+17-3
Original file line numberDiff line numberDiff line change
@@ -1271,15 +1271,29 @@ SourceRange TupleExpr::getSourceRange() const {
12711271
return { SourceLoc(), SourceLoc() };
12721272
} else {
12731273
// Scan backwards for a valid source loc.
1274+
bool hasSingleTrailingClosure = hasTrailingClosure();
12741275
for (Expr *expr : llvm::reverse(getElements())) {
12751276
// Default arguments are located at the start of their parent tuple, so
12761277
// skip over them.
12771278
if (isa<DefaultArgumentExpr>(expr))
12781279
continue;
1279-
end = expr->getEndLoc();
1280-
if (end.isValid()) {
1281-
break;
1280+
1281+
SourceLoc newEnd = expr->getEndLoc();
1282+
if (newEnd.isInvalid())
1283+
continue;
1284+
1285+
// There is a quirk with the backward scan logic for trailing
1286+
// closures that can cause arguments to be flipped. If there is a
1287+
// single trailing closure, only stop when the "end" point we hit comes
1288+
// after the close parenthesis (if there is one).
1289+
if (end.isInvalid() ||
1290+
end.getOpaquePointerValue() < newEnd.getOpaquePointerValue()) {
1291+
end = newEnd;
12821292
}
1293+
1294+
if (!hasSingleTrailingClosure || RParenLoc.isInvalid() ||
1295+
RParenLoc.getOpaquePointerValue() < end.getOpaquePointerValue())
1296+
break;
12831297
}
12841298
}
12851299
} else {

lib/AST/Type.cpp

+63-6
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,12 @@ bool CanType::isObjCExistentialTypeImpl(CanType type) {
350350
return type.getExistentialLayout().isObjC();
351351
}
352352

353+
bool CanType::isTypeErasedGenericClassTypeImpl(CanType type) {
354+
if (auto nom = type->getAnyNominal())
355+
return nom->isTypeErasedGenericClass();
356+
return false;
357+
}
358+
353359
bool TypeBase::isSpecialized() {
354360
Type t = getCanonicalType();
355361

@@ -822,6 +828,32 @@ Type TypeBase::replaceCovariantResultType(Type newResultType,
822828
return FunctionType::get(inputType, resultType, fnType->getExtInfo());
823829
}
824830

831+
/// Whether this parameter accepts an unlabeled trailing closure argument
832+
/// using the more-restrictive forward-scan rule.
833+
static bool allowsUnlabeledTrailingClosureParameter(const ParamDecl *param) {
834+
// inout parameters never allow an unlabeled trailing closure.
835+
if (param->isInOut())
836+
return false;
837+
838+
Type paramType = param->isVariadic() ? param->getVarargBaseTy()
839+
: param->getInterfaceType();
840+
paramType = paramType->getRValueType()->lookThroughAllOptionalTypes();
841+
842+
// For autoclosure parameters, look through the autoclosure result type
843+
// to get the actual argument type.
844+
if (param->isAutoClosure()) {
845+
auto fnType = paramType->getAs<AnyFunctionType>();
846+
if (!fnType)
847+
return false;
848+
849+
paramType = fnType->getResult()->lookThroughAllOptionalTypes();
850+
}
851+
852+
// After lookup through all optional types, this parameter allows an
853+
// unlabeled trailing closure if it is (structurally) a function type.
854+
return paramType->is<AnyFunctionType>();
855+
}
856+
825857
ParameterListInfo::ParameterListInfo(
826858
ArrayRef<AnyFunctionType::Param> params,
827859
const ValueDecl *paramOwner,
@@ -831,7 +863,7 @@ ParameterListInfo::ParameterListInfo(
831863
// No parameter owner means no parameter list means no default arguments
832864
// - hand back the zeroed bitvector.
833865
//
834-
// FIXME: We ought to not request default argument info in this case.
866+
// FIXME: We ought to not request paramer list info in this case.
835867
if (!paramOwner)
836868
return;
837869

@@ -865,12 +897,21 @@ ParameterListInfo::ParameterListInfo(
865897
if (params.size() != paramList->size())
866898
return;
867899

868-
// Note which parameters have default arguments and/or function builders.
900+
// Now we have enough information to determine which parameters accept
901+
// unlabled trailing closures.
902+
acceptsUnlabeledTrailingClosures.resize(params.size());
903+
904+
// Note which parameters have default arguments and/or accept unlabeled
905+
// trailing closure arguments with the forward-scan rule.
869906
for (auto i : range(0, params.size())) {
870907
auto param = paramList->get(i);
871908
if (param->isDefaultArgument()) {
872909
defaultArguments.set(i);
873910
}
911+
912+
if (allowsUnlabeledTrailingClosureParameter(param)) {
913+
acceptsUnlabeledTrailingClosures.set(i);
914+
}
874915
}
875916
}
876917

@@ -879,6 +920,12 @@ bool ParameterListInfo::hasDefaultArgument(unsigned paramIdx) const {
879920
: false;
880921
}
881922

923+
bool ParameterListInfo::acceptsUnlabeledTrailingClosureArgument(
924+
unsigned paramIdx) const {
925+
return paramIdx >= acceptsUnlabeledTrailingClosures.size() ||
926+
acceptsUnlabeledTrailingClosures[paramIdx];
927+
}
928+
882929
/// Turn a param list into a symbolic and printable representation that does not
883930
/// include the types, something like (_:, b:, c:)
884931
std::string swift::getParamListAsString(ArrayRef<AnyFunctionType::Param> params) {
@@ -4261,17 +4308,27 @@ case TypeKind::Id:
42614308
case TypeKind::SILFunction: {
42624309
auto fnTy = cast<SILFunctionType>(base);
42634310
bool changed = false;
4264-
4311+
auto hasTypeErasedGenericClassType = [](Type ty) -> bool {
4312+
return ty.findIf([](Type subType) -> bool {
4313+
if (subType->getCanonicalType().isTypeErasedGenericClassType())
4314+
return true;
4315+
else
4316+
return false;
4317+
});
4318+
};
42654319
auto updateSubs = [&](SubstitutionMap &subs) -> bool {
42664320
// This interface isn't suitable for updating the substitution map in a
42674321
// substituted SILFunctionType.
42684322
// TODO(SILFunctionType): Is it suitable for any SILFunctionType??
42694323
SmallVector<Type, 4> newReplacements;
42704324
for (Type type : subs.getReplacementTypes()) {
42714325
auto transformed = type.transformRec(fn);
4272-
assert((type->isEqual(transformed)
4273-
|| (type->hasTypeParameter() && transformed->hasTypeParameter()))
4274-
&& "Substituted SILFunctionType can't be transformed into a concrete type");
4326+
assert((type->isEqual(transformed) ||
4327+
(type->hasTypeParameter() && transformed->hasTypeParameter()) ||
4328+
(hasTypeErasedGenericClassType(type) &&
4329+
hasTypeErasedGenericClassType(transformed))) &&
4330+
"Substituted SILFunctionType can't be transformed into a "
4331+
"concrete type");
42754332
newReplacements.push_back(transformed->getCanonicalType());
42764333
if (!type->isEqual(transformed))
42774334
changed = true;

lib/Basic/Platform.cpp

-17
Original file line numberDiff line numberDiff line change
@@ -131,23 +131,6 @@ DarwinPlatformKind swift::getDarwinPlatformKind(const llvm::Triple &triple) {
131131
llvm_unreachable("Unsupported Darwin platform");
132132
}
133133

134-
DarwinPlatformKind swift::getNonSimulatorPlatform(DarwinPlatformKind platform) {
135-
switch (platform) {
136-
case DarwinPlatformKind::MacOS:
137-
return DarwinPlatformKind::MacOS;
138-
case DarwinPlatformKind::IPhoneOS:
139-
case DarwinPlatformKind::IPhoneOSSimulator:
140-
return DarwinPlatformKind::IPhoneOS;
141-
case DarwinPlatformKind::TvOS:
142-
case DarwinPlatformKind::TvOSSimulator:
143-
return DarwinPlatformKind::TvOS;
144-
case DarwinPlatformKind::WatchOS:
145-
case DarwinPlatformKind::WatchOSSimulator:
146-
return DarwinPlatformKind::WatchOS;
147-
}
148-
llvm_unreachable("Unsupported Darwin platform");
149-
}
150-
151134
static StringRef getPlatformNameForDarwin(const DarwinPlatformKind platform) {
152135
switch (platform) {
153136
case DarwinPlatformKind::MacOS:

lib/Driver/DarwinToolChains.cpp

+3-14
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,9 @@ toolchains::Darwin::constructInvocation(const InterpretJobAction &job,
8989
}
9090

9191
static StringRef
92-
getDarwinLibraryNameSuffixForTriple(const llvm::Triple &triple,
93-
bool distinguishSimulator = true) {
92+
getDarwinLibraryNameSuffixForTriple(const llvm::Triple &triple) {
9493
const DarwinPlatformKind kind = getDarwinPlatformKind(triple);
95-
const DarwinPlatformKind effectiveKind =
96-
distinguishSimulator ? kind : getNonSimulatorPlatform(kind);
97-
switch (effectiveKind) {
94+
switch (kind) {
9895
case DarwinPlatformKind::MacOS:
9996
return "osx";
10097
case DarwinPlatformKind::IPhoneOS:
@@ -622,14 +619,6 @@ toolchains::Darwin::addDeploymentTargetArgs(ArgStringList &Arguments,
622619
micro = firstMacARM64e.getSubminor().getValueOr(0);
623620
}
624621

625-
// Temporary hack: adjust macOS version passed to the linker from
626-
// 11 down to 10.16, but only for x86.
627-
if (triple.isX86() && major == 11) {
628-
major = 10;
629-
minor = 16;
630-
micro = 0;
631-
}
632-
633622
break;
634623
case DarwinPlatformKind::IPhoneOS:
635624
case DarwinPlatformKind::IPhoneOSSimulator:
@@ -754,7 +743,7 @@ toolchains::Darwin::constructInvocation(const DynamicLinkJobAction &job,
754743
llvm::sys::path::append(
755744
CompilerRTPath,
756745
Twine("libclang_rt.") +
757-
getDarwinLibraryNameSuffixForTriple(Triple, /*simulator*/false) +
746+
getDarwinLibraryNameSuffixForTriple(Triple) +
758747
".a");
759748
if (llvm::sys::fs::exists(CompilerRTPath))
760749
Arguments.push_back(context.Args.MakeArgString(CompilerRTPath));

lib/Driver/ToolChains.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI,
252252
inputArgs.AddLastArg(arguments, options::OPT_disable_parser_lookup);
253253
inputArgs.AddLastArg(arguments,
254254
options::OPT_enable_experimental_concise_pound_file);
255+
inputArgs.AddLastArg(
256+
arguments,
257+
options::OPT_enable_fuzzy_forward_scan_trailing_closure_matching,
258+
options::OPT_disable_fuzzy_forward_scan_trailing_closure_matching);
255259
inputArgs.AddLastArg(arguments,
256260
options::OPT_verify_incremental_dependencies);
257261

0 commit comments

Comments
 (0)