Skip to content

Commit 6b949a2

Browse files
authored
Merge pull request #1038 from swiftwasm/release/5.3
[pull] swiftwasm-release/5.3 from release/5.3
2 parents 7922165 + 7b01206 commit 6b949a2

File tree

62 files changed

+997
-135
lines changed

Some content is hidden

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

62 files changed

+997
-135
lines changed

include/swift/AST/Decl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5217,6 +5217,12 @@ class VarDecl : public AbstractStorageDecl {
52175217
Optional<PropertyWrapperMutability>
52185218
getPropertyWrapperMutability() const;
52195219

5220+
/// Returns whether this property is the backing storage property or a storage
5221+
/// wrapper for wrapper instance's projectedValue. If this property is
5222+
/// neither, then it returns `None`.
5223+
Optional<PropertyWrapperSynthesizedPropertyKind>
5224+
getPropertyWrapperSynthesizedPropertyKind() const;
5225+
52205226
/// Retrieve the backing storage property for a property that has an
52215227
/// attached property wrapper.
52225228
///

include/swift/AST/DiagnosticsSema.def

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ ERROR(could_not_find_value_dynamic_member_corrected,none,
7171
ERROR(could_not_find_value_dynamic_member,none,
7272
"value of type %0 has no dynamic member %2 using key path from root type %1",
7373
(Type, Type, DeclNameRef))
74+
ERROR(cannot_infer_contextual_keypath_type_specify_root,none,
75+
"cannot infer key path type from context; consider explicitly specifying a root type", ())
76+
ERROR(cannot_infer_keypath_root_anykeypath_context,none,
77+
"'AnyKeyPath' does not provide enough context for root type to be inferred; "
78+
"consider explicitly specifying a root type", ())
7479

7580
ERROR(could_not_find_type_member,none,
7681
"type %0 has no member %1", (Type, DeclNameRef))
@@ -552,6 +557,9 @@ ERROR(expr_keypath_mutating_getter,none,
552557
ERROR(expr_keypath_static_member,none,
553558
"%select{key path|dynamic key path member lookup}1 cannot refer to static member %0",
554559
(DeclName, bool))
560+
ERROR(expr_keypath_enum_case,none,
561+
"%select{key path|dynamic key path member lookup}1 cannot refer to enum case %0",
562+
(DeclName, bool))
555563
ERROR(expr_keypath_empty,none,
556564
"empty key path does not refer to a property", ())
557565
ERROR(expr_unsupported_objc_key_path_component,none,
@@ -755,12 +763,20 @@ ERROR(invalid_redecl,none,"invalid redeclaration of %0", (DeclName))
755763
ERROR(invalid_redecl_init,none,
756764
"invalid redeclaration of synthesized %select{|memberwise }1%0",
757765
(DeclName, bool))
766+
ERROR(invalid_redecl_implicit,none,
767+
"invalid redeclaration of synthesized "
768+
"%select{%0|implementation for protocol requirement}1 %2",
769+
(DescriptiveDeclKind, bool, DeclName))
758770
WARNING(invalid_redecl_swift5_warning,none,
759771
"redeclaration of %0 is deprecated and will be an error in Swift 5",
760772
(DeclName))
761773

762774
NOTE(invalid_redecl_prev,none,
763775
"%0 previously declared here", (DeclName))
776+
NOTE(invalid_redecl_implicit_wrapper,none,
777+
"%0 synthesized for property wrapper "
778+
"%select{projected value|backing storage}1",
779+
(DeclName, bool))
764780

765781
ERROR(ambiguous_type_base,none,
766782
"%0 is ambiguous for type lookup in this context", (DeclNameRef))

include/swift/AST/Expr.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4214,9 +4214,7 @@ class DefaultArgumentExpr final : public Expr {
42144214
DefaultArgsOwner(defaultArgsOwner), ParamIndex(paramIndex), Loc(loc),
42154215
ContextOrCallerSideExpr(dc) { }
42164216

4217-
SourceRange getSourceRange() const { return {}; }
4218-
4219-
SourceLoc getArgumentListLoc() const { return Loc; }
4217+
SourceRange getSourceRange() const { return Loc; }
42204218

42214219
ConcreteDeclRef getDefaultArgsOwner() const {
42224220
return DefaultArgsOwner;

include/swift/SIL/SILDeclRef.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include "swift/AST/ClangNode.h"
2323
#include "swift/AST/TypeAlignments.h"
24+
#include "swift/SIL/SILLinkage.h"
2425
#include "llvm/ADT/Hashing.h"
2526
#include "llvm/ADT/DenseMap.h"
2627
#include "llvm/ADT/PointerUnion.h"
@@ -42,7 +43,6 @@ namespace swift {
4243
class ASTContext;
4344
class ClassDecl;
4445
class SILFunctionType;
45-
enum class SILLinkage : unsigned char;
4646
enum IsSerialized_t : unsigned char;
4747
enum class SubclassScope : unsigned char;
4848
class SILModule;
@@ -413,6 +413,22 @@ inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, SILDeclRef C) {
413413
return OS;
414414
}
415415

416+
// FIXME: This should not be necessary, but it looks like visibility rules for
417+
// extension members are slightly bogus, and so some protocol witness thunks
418+
// need to be public.
419+
//
420+
// We allow a 'public' member of an extension to witness a public
421+
// protocol requirement, even if the extended type is not public;
422+
// then SILGen gives the member private linkage, ignoring the more
423+
// visible access level it was given in the AST.
424+
inline bool
425+
fixmeWitnessHasLinkageThatNeedsToBePublic(SILDeclRef witness) {
426+
auto witnessLinkage = witness.getLinkage(ForDefinition);
427+
return !hasPublicVisibility(witnessLinkage)
428+
&& (!hasSharedVisibility(witnessLinkage)
429+
|| !witness.isSerialized());
430+
}
431+
416432
} // end swift namespace
417433

418434
namespace llvm {

include/swift/SIL/SILLinkage.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -265,20 +265,6 @@ inline SILLinkage effectiveLinkageForClassMember(SILLinkage linkage,
265265
return linkage;
266266
}
267267

268-
// FIXME: This should not be necessary, but it looks like visibility rules for
269-
// extension members are slightly bogus, and so some protocol witness thunks
270-
// need to be public.
271-
//
272-
// We allow a 'public' member of an extension to witness a public
273-
// protocol requirement, even if the extended type is not public;
274-
// then SILGen gives the member private linkage, ignoring the more
275-
// visible access level it was given in the AST.
276-
inline bool
277-
fixmeWitnessHasLinkageThatNeedsToBePublic(SILLinkage witnessLinkage) {
278-
return !hasPublicVisibility(witnessLinkage) &&
279-
!hasSharedVisibility(witnessLinkage);
280-
}
281-
282268
} // end swift namespace
283269

284270
#endif

lib/AST/ASTDemangler.cpp

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -597,20 +597,35 @@ Type ASTBuilder::createGenericTypeParameterType(unsigned depth,
597597

598598
Type ASTBuilder::createDependentMemberType(StringRef member,
599599
Type base) {
600-
if (!base->isTypeParameter())
601-
return Type();
600+
auto identifier = Ctx.getIdentifier(member);
601+
602+
if (auto *archetype = base->getAs<ArchetypeType>()) {
603+
if (archetype->hasNestedType(identifier))
604+
return archetype->getNestedType(identifier);
605+
606+
}
607+
608+
if (base->isTypeParameter()) {
609+
return DependentMemberType::get(base, identifier);
610+
}
602611

603-
return DependentMemberType::get(base, Ctx.getIdentifier(member));
612+
return Type();
604613
}
605614

606615
Type ASTBuilder::createDependentMemberType(StringRef member,
607616
Type base,
608617
ProtocolDecl *protocol) {
609-
if (!base->isTypeParameter())
610-
return Type();
618+
auto identifier = Ctx.getIdentifier(member);
611619

612-
if (auto assocType = protocol->getAssociatedType(Ctx.getIdentifier(member)))
613-
return DependentMemberType::get(base, assocType);
620+
if (auto *archetype = base->getAs<ArchetypeType>()) {
621+
if (archetype->hasNestedType(identifier))
622+
return archetype->getNestedType(identifier);
623+
}
624+
625+
if (base->isTypeParameter()) {
626+
if (auto assocType = protocol->getAssociatedType(identifier))
627+
return DependentMemberType::get(base, assocType);
628+
}
614629

615630
return Type();
616631
}

lib/AST/Decl.cpp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5950,6 +5950,17 @@ VarDecl::getPropertyWrapperMutability() const {
59505950
None);
59515951
}
59525952

5953+
Optional<PropertyWrapperSynthesizedPropertyKind>
5954+
VarDecl::getPropertyWrapperSynthesizedPropertyKind() const {
5955+
if (getOriginalWrappedProperty(
5956+
PropertyWrapperSynthesizedPropertyKind::Backing))
5957+
return PropertyWrapperSynthesizedPropertyKind::Backing;
5958+
if (getOriginalWrappedProperty(
5959+
PropertyWrapperSynthesizedPropertyKind::StorageWrapper))
5960+
return PropertyWrapperSynthesizedPropertyKind::StorageWrapper;
5961+
return None;
5962+
}
5963+
59535964
VarDecl *VarDecl::getPropertyWrapperBackingProperty() const {
59545965
return getPropertyWrapperBackingPropertyInfo().backingVar;
59555966
}
@@ -6473,9 +6484,13 @@ ParamDecl::getDefaultValueStringRepresentation(
64736484
return getASTContext().SourceMgr.extractText(charRange);
64746485
}
64756486

6476-
// If there is no parent initializer, we used the default initializer.
6477-
auto parentInit = original->getParentInitializer();
6478-
if (!parentInit) {
6487+
// If there is no initial wrapped value, we used the default initializer.
6488+
Expr *wrappedValue = nullptr;
6489+
if (auto *parentInit = original->getParentInitializer())
6490+
if (auto *placeholder = findWrappedValuePlaceholder(parentInit))
6491+
wrappedValue = placeholder->getOriginalWrappedValue();
6492+
6493+
if (!wrappedValue) {
64796494
if (auto type = original->getPropertyWrapperBackingPropertyType()) {
64806495
if (auto nominal = type->getAnyNominal()) {
64816496
scratch.clear();
@@ -6490,9 +6505,8 @@ ParamDecl::getDefaultValueStringRepresentation(
64906505
return ".init()";
64916506
}
64926507

6493-
auto init =
6494-
findWrappedValuePlaceholder(parentInit)->getOriginalWrappedValue();
6495-
return extractInlinableText(getASTContext().SourceMgr, init, scratch);
6508+
auto &sourceMgr = getASTContext().SourceMgr;
6509+
return extractInlinableText(sourceMgr, wrappedValue, scratch);
64966510
}
64976511
}
64986512

lib/AST/Expr.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,10 @@ SourceRange TupleExpr::getSourceRange() const {
12721272
} else {
12731273
// Scan backwards for a valid source loc.
12741274
for (Expr *expr : llvm::reverse(getElements())) {
1275+
// Default arguments are located at the start of their parent tuple, so
1276+
// skip over them.
1277+
if (isa<DefaultArgumentExpr>(expr))
1278+
continue;
12751279
end = expr->getEndLoc();
12761280
if (end.isValid()) {
12771281
break;

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2522,7 +2522,13 @@ static void concretizeNestedTypeFromConcreteParent(
25222522
GenericSignatureBuilder &builder) {
25232523
auto parentEquiv = parent->getEquivalenceClassIfPresent();
25242524
assert(parentEquiv && "can't have a concrete type without an equiv class");
2525+
2526+
bool isSuperclassConstrained = false;
25252527
auto concreteParent = parentEquiv->concreteType;
2528+
if (!concreteParent) {
2529+
isSuperclassConstrained = true;
2530+
concreteParent = parentEquiv->superclass;
2531+
}
25262532
assert(concreteParent &&
25272533
"attempting to resolve concrete nested type of non-concrete PA");
25282534

@@ -2544,8 +2550,14 @@ static void concretizeNestedTypeFromConcreteParent(
25442550
"No conformance requirement");
25452551
const RequirementSource *parentConcreteSource = nullptr;
25462552
for (const auto &constraint : parentEquiv->conformsTo.find(proto)->second) {
2547-
if (constraint.source->kind == RequirementSource::Concrete) {
2548-
parentConcreteSource = constraint.source;
2553+
if (!isSuperclassConstrained) {
2554+
if (constraint.source->kind == RequirementSource::Concrete) {
2555+
parentConcreteSource = constraint.source;
2556+
}
2557+
} else {
2558+
if (constraint.source->kind == RequirementSource::Superclass) {
2559+
parentConcreteSource = constraint.source;
2560+
}
25492561
}
25502562
}
25512563

@@ -4264,6 +4276,15 @@ bool GenericSignatureBuilder::updateSuperclass(
42644276
for (const auto &conforms : equivClass->conformsTo) {
42654277
(void)resolveSuperConformance(type, conforms.first);
42664278
}
4279+
4280+
// Eagerly resolve any existing nested types to their concrete forms (others
4281+
// will be "concretized" as they are constructed, in getNestedType).
4282+
for (auto equivT : equivClass->members) {
4283+
for (auto nested : equivT->getNestedTypes()) {
4284+
concretizeNestedTypeFromConcreteParent(equivT, nested.second.front(),
4285+
*this);
4286+
}
4287+
}
42674288
};
42684289

42694290
// If we haven't yet recorded a superclass constraint for this equivalence
@@ -7156,6 +7177,12 @@ void GenericSignatureBuilder::dump(llvm::raw_ostream &out) {
71567177
pa->dump(out, &Context.SourceMgr, 2);
71577178
}
71587179
out << "\n";
7180+
7181+
out << "Equivalence classes:\n";
7182+
for (auto &equiv : Impl->EquivalenceClasses) {
7183+
equiv.dump(out, this);
7184+
}
7185+
out << "\n";
71597186
}
71607187

71617188
void GenericSignatureBuilder::addGenericSignature(GenericSignature sig) {

lib/Frontend/ModuleInterfaceSupport.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,12 +344,18 @@ class InheritedProtocolCollector {
344344
/// in \p map.
345345
///
346346
/// \sa recordConditionalConformances
347-
static void collectSkippedConditionalConformances(PerTypeMap &map,
348-
const Decl *D) {
347+
static void collectSkippedConditionalConformances(
348+
PerTypeMap &map,
349+
const Decl *D,
350+
const PrintOptions &printOptions) {
349351
auto *extension = dyn_cast<ExtensionDecl>(D);
350352
if (!extension || !extension->isConstrainedExtension())
351353
return;
352354

355+
// Skip SPI extensions in the public interface.
356+
if (!printOptions.PrintSPIs && extension->isSPI())
357+
return;
358+
353359
const NominalTypeDecl *nominal = extension->getExtendedNominal();
354360
if (!isPublicOrUsableFromInline(nominal))
355361
return;
@@ -496,8 +502,9 @@ bool swift::emitSwiftInterface(raw_ostream &out,
496502

497503
if (!D->shouldPrintInContext(printOptions) ||
498504
!printOptions.shouldPrint(D)) {
505+
499506
InheritedProtocolCollector::collectSkippedConditionalConformances(
500-
inheritedProtocolMap, D);
507+
inheritedProtocolMap, D, printOptions);
501508
continue;
502509
}
503510

lib/IDE/CodeCompletion.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6196,6 +6196,8 @@ void CodeCompletionCallbacksImpl::doneParsing() {
61966196
break;
61976197
}
61986198

6199+
llvm::SmallPtrSet<Identifier, 8> seenModuleNames;
6200+
61996201
for (auto &Request: Lookup.RequestedCachedResults) {
62006202
// Use the current SourceFile as the DeclContext so that we can use it to
62016203
// perform qualified lookup, and to get the correct visibility for
@@ -6248,7 +6250,9 @@ void CodeCompletionCallbacksImpl::doneParsing() {
62486250
return; // already handled.
62496251
RequestedModules.push_back({std::move(K), TheModule,
62506252
Request.OnlyTypes, Request.OnlyPrecedenceGroups});
6251-
if (Request.IncludeModuleQualifier)
6253+
6254+
if (Request.IncludeModuleQualifier &&
6255+
seenModuleNames.insert(TheModule->getName()).second)
62526256
Lookup.addModuleName(TheModule);
62536257
}
62546258
};
@@ -6263,8 +6267,10 @@ void CodeCompletionCallbacksImpl::doneParsing() {
62636267
Lookup.getToplevelCompletions(Request.OnlyTypes);
62646268

62656269
// Add the qualifying module name
6266-
if (Request.IncludeModuleQualifier)
6267-
Lookup.addModuleName(CurDeclContext->getParentModule());
6270+
auto curModule = CurDeclContext->getParentModule();
6271+
if (Request.IncludeModuleQualifier &&
6272+
seenModuleNames.insert(curModule->getName()).second)
6273+
Lookup.addModuleName(curModule);
62686274

62696275
// Add results for all imported modules.
62706276
ModuleDecl::ImportFilter ImportFilter;

0 commit comments

Comments
 (0)