Skip to content

Commit 33617e2

Browse files
authored
Merge pull request #3075 from swiftwasm/maxd/main-merge
Resolve conflicts with the main branch
2 parents ee21d4f + 668ddeb commit 33617e2

Some content is hidden

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

54 files changed

+1726
-247
lines changed

CHANGELOG.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,24 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
66
Swift 5.5
77
---------
88

9+
* Type names are no longer allowed as an argument to a subscript parameter that expects a metatype type
10+
11+
```swift
12+
struct MyValue {
13+
}
14+
15+
struct MyStruct {
16+
subscript(a: MyValue.Type) -> Int { get { ... } }
17+
}
18+
19+
func test(obj: MyStruct) {
20+
let _ = obj[MyValue]
21+
}
22+
```
23+
24+
Accepting subscripts with `MyValue` as an argument was an oversight because `MyValue` requires explicit `.self`
25+
to reference its metatype, so correct syntax would be to use `obj[MyValue.self]`.
26+
927
* [SE-0310][]:
1028

1129
Read-only computed properties and subscripts can now define their `get` accessor to be `async` and/or `throws`, by writing one or both of those keywords between the `get` and `{`. Thus, these members can now make asynchronous calls or throw errors in the process of producing a value:
@@ -49,7 +67,6 @@ Swift 5.5
4967
}
5068
```
5169

52-
5370
* [SE-0306][]:
5471

5572
Swift 5.5 includes support for actors, a new kind of type that isolates its instance data to protect it from concurrent access. Accesses to an actor's instance declarations from outside the must be asynchronous:

include/swift/ABI/Metadata.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2906,8 +2906,13 @@ class TargetGenericEnvironment
29062906
uint16_t, GenericParamDescriptor, GenericRequirementDescriptor>;
29072907
friend TrailingObjects;
29082908

2909+
#if !defined(_MSC_VER) || _MSC_VER >= 1920
29092910
template<typename T>
29102911
using OverloadToken = typename TrailingObjects::template OverloadToken<T>;
2912+
#else
2913+
// MSVC 2017 trips parsing an using of an using, of a variadic template
2914+
#define OverloadToken typename TrailingObjects::template OverloadToken
2915+
#endif
29112916

29122917
size_t numTrailingObjects(OverloadToken<uint16_t>) const {
29132918
return Flags.getNumGenericParameterLevels();
@@ -2921,6 +2926,10 @@ class TargetGenericEnvironment
29212926
return Flags.getNumGenericRequirements();
29222927
}
29232928

2929+
#if defined(_MSC_VER) && _MSC_VER < 1920
2930+
#undef OverloadToken
2931+
#endif
2932+
29242933
GenericEnvironmentFlags Flags;
29252934

29262935
public:
@@ -2982,8 +2991,13 @@ class TrailingGenericContextObjects<TargetSelf<Runtime>,
29822991
FollowingTrailingObjects...>;
29832992
friend TrailingObjects;
29842993

2994+
#if !defined(_MSC_VER) || _MSC_VER >= 1920
29852995
template<typename T>
29862996
using OverloadToken = typename TrailingObjects::template OverloadToken<T>;
2997+
#else
2998+
// MSVC 2017 trips parsing an using of an using, of a variadic template
2999+
#define OverloadToken typename TrailingObjects::template OverloadToken
3000+
#endif
29873001

29883002
const Self *asSelf() const {
29893003
return static_cast<const Self *>(this);
@@ -3047,6 +3061,11 @@ class TrailingGenericContextObjects<TargetSelf<Runtime>,
30473061
size_t numTrailingObjects(OverloadToken<GenericRequirementDescriptor>) const {
30483062
return asSelf()->isGeneric() ? getGenericContextHeader().NumRequirements : 0;
30493063
}
3064+
3065+
#if defined(_MSC_VER) && _MSC_VER < 1920
3066+
#undef OverloadToken
3067+
#endif
3068+
30503069
};
30513070

30523071
/// Reference to a generic context.

include/swift/AST/DiagnosticConsumer.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ struct DiagnosticInfo {
4545
DiagnosticKind Kind;
4646
StringRef FormatString;
4747
ArrayRef<DiagnosticArgument> FormatArgs;
48+
StringRef Category;
4849

4950
/// Only used when directing diagnostics to different outputs.
5051
/// In batch mode a diagnostic may be
@@ -85,13 +86,13 @@ struct DiagnosticInfo {
8586

8687
DiagnosticInfo(DiagID ID, SourceLoc Loc, DiagnosticKind Kind,
8788
StringRef FormatString,
88-
ArrayRef<DiagnosticArgument> FormatArgs,
89+
ArrayRef<DiagnosticArgument> FormatArgs, StringRef Category,
8990
SourceLoc BufferIndirectlyCausingDiagnostic,
9091
ArrayRef<DiagnosticInfo *> ChildDiagnosticInfo,
9192
ArrayRef<CharSourceRange> Ranges, ArrayRef<FixIt> FixIts,
9293
bool IsChildNote)
9394
: ID(ID), Loc(Loc), Kind(Kind), FormatString(FormatString),
94-
FormatArgs(FormatArgs),
95+
FormatArgs(FormatArgs), Category(Category),
9596
BufferIndirectlyCausingDiagnostic(BufferIndirectlyCausingDiagnostic),
9697
ChildDiagnosticInfo(ChildDiagnosticInfo), Ranges(Ranges),
9798
FixIts(FixIts), IsChildNote(IsChildNote) {}

include/swift/AST/DiagnosticEngine.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,10 @@ namespace swift {
10131013
/// option.
10141014
bool isDiagnosticPointsToFirstBadToken(DiagID id) const;
10151015

1016+
/// \returns true if the diagnostic is an API digester API or ABI breakage
1017+
/// diagnostic.
1018+
bool isAPIDigesterBreakageDiagnostic(DiagID id) const;
1019+
10161020
/// \returns true if any diagnostic consumer gave an error while invoking
10171021
//// \c finishProcessing.
10181022
bool finishProcessing();

include/swift/AST/DiagnosticsClangImporter.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,7 @@ WARNING(import_multiple_mainactor_attr,none,
8787
"this attribute for global actor '%0' is invalid; the declaration already has attribute for global actor '%1'",
8888
(StringRef, StringRef))
8989

90+
ERROR(module_map_not_found, none, "module map file '%0' not found", (StringRef))
91+
9092
#define UNDEFINE_DIAGNOSTIC_MACROS
9193
#include "DefineDiagnosticMacros.h"

include/swift/AST/DiagnosticsModuleDiffer.def

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,73 +20,73 @@
2020
#define DEFINE_DIAGNOSTIC_MACROS
2121
#include "DefineDiagnosticMacros.h"
2222

23-
ERROR(generic_sig_change,none,"%0 has generic signature change from %1 to %2", (StringRef, StringRef, StringRef))
23+
ERROR(generic_sig_change,APIDigesterBreakage,"%0 has generic signature change from %1 to %2", (StringRef, StringRef, StringRef))
2424

25-
ERROR(raw_type_change,none,"%0(%1) is now %2 representable", (StringRef, StringRef, StringRef))
25+
ERROR(raw_type_change,APIDigesterBreakage,"%0(%1) is now %2 representable", (StringRef, StringRef, StringRef))
2626

27-
ERROR(removed_decl,none,"%0 has been removed%select{| (deprecated)}1", (StringRef, bool))
27+
ERROR(removed_decl,APIDigesterBreakage,"%0 has been removed%select{| (deprecated)}1", (StringRef, bool))
2828

29-
ERROR(moved_decl,none,"%0 has been moved to %1", (StringRef, StringRef))
29+
ERROR(moved_decl,APIDigesterBreakage,"%0 has been moved to %1", (StringRef, StringRef))
3030

31-
ERROR(renamed_decl,none,"%0 has been renamed to %1", (StringRef, StringRef))
31+
ERROR(renamed_decl,APIDigesterBreakage,"%0 has been renamed to %1", (StringRef, StringRef))
3232

33-
ERROR(decl_type_change,none,"%0 has %1 type change from %2 to %3", (StringRef, StringRef, StringRef, StringRef))
33+
ERROR(decl_type_change,APIDigesterBreakage,"%0 has %1 type change from %2 to %3", (StringRef, StringRef, StringRef, StringRef))
3434

35-
ERROR(decl_attr_change,none,"%0 changes from %1 to %2", (StringRef, StringRef, StringRef))
35+
ERROR(decl_attr_change,APIDigesterBreakage,"%0 changes from %1 to %2", (StringRef, StringRef, StringRef))
3636

37-
ERROR(decl_new_attr,none,"%0 is now %1", (StringRef, StringRef))
37+
ERROR(decl_new_attr,APIDigesterBreakage,"%0 is now %1", (StringRef, StringRef))
3838

39-
ERROR(decl_reorder,none,"%0 in a non-resilient type changes position from %1 to %2", (StringRef, unsigned, unsigned))
39+
ERROR(decl_reorder,APIDigesterBreakage,"%0 in a non-resilient type changes position from %1 to %2", (StringRef, unsigned, unsigned))
4040

41-
ERROR(decl_added,none,"%0 is added to a non-resilient type", (StringRef))
41+
ERROR(decl_added,APIDigesterBreakage,"%0 is added to a non-resilient type", (StringRef))
4242

43-
ERROR(var_has_fixed_order_change,none,"%0 is %select{now|no longer}1 a stored property", (StringRef, bool))
43+
ERROR(var_has_fixed_order_change,APIDigesterBreakage,"%0 is %select{now|no longer}1 a stored property", (StringRef, bool))
4444

45-
ERROR(func_has_fixed_order_change,none,"%0 is %select{now|no longer}1 a non-final instance function", (StringRef, bool))
45+
ERROR(func_has_fixed_order_change,APIDigesterBreakage,"%0 is %select{now|no longer}1 a non-final instance function", (StringRef, bool))
4646

47-
ERROR(default_arg_removed,none,"%0 has removed default argument from %1", (StringRef, StringRef))
47+
ERROR(default_arg_removed,APIDigesterBreakage,"%0 has removed default argument from %1", (StringRef, StringRef))
4848

49-
ERROR(conformance_removed,none,"%0 has removed %select{conformance to|inherited protocol}2 %1", (StringRef, StringRef, bool))
49+
ERROR(conformance_removed,APIDigesterBreakage,"%0 has removed %select{conformance to|inherited protocol}2 %1", (StringRef, StringRef, bool))
5050

51-
ERROR(conformance_added,none,"%0 has added inherited protocol %1", (StringRef, StringRef))
51+
ERROR(conformance_added,APIDigesterBreakage,"%0 has added inherited protocol %1", (StringRef, StringRef))
5252

53-
ERROR(existing_conformance_added,none,"%0 has added a conformance to an existing protocol %1", (StringRef, StringRef))
53+
ERROR(existing_conformance_added,APIDigesterBreakage,"%0 has added a conformance to an existing protocol %1", (StringRef, StringRef))
5454

55-
ERROR(default_associated_type_removed,none,"%0 has removed default type %1", (StringRef, StringRef))
55+
ERROR(default_associated_type_removed,APIDigesterBreakage,"%0 has removed default type %1", (StringRef, StringRef))
5656

57-
ERROR(protocol_req_added,none,"%0 has been added as a protocol requirement", (StringRef))
57+
ERROR(protocol_req_added,APIDigesterBreakage,"%0 has been added as a protocol requirement", (StringRef))
5858

59-
ERROR(super_class_removed,none,"%0 has removed its super class %1", (StringRef, StringRef))
59+
ERROR(super_class_removed,APIDigesterBreakage,"%0 has removed its super class %1", (StringRef, StringRef))
6060

61-
ERROR(super_class_changed,none,"%0 has changed its super class from %1 to %2", (StringRef, StringRef, StringRef))
61+
ERROR(super_class_changed,APIDigesterBreakage,"%0 has changed its super class from %1 to %2", (StringRef, StringRef, StringRef))
6262

63-
ERROR(decl_kind_changed,none,"%0 has been changed to a %1", (StringRef, StringRef))
63+
ERROR(decl_kind_changed,APIDigesterBreakage,"%0 has been changed to a %1", (StringRef, StringRef))
6464

65-
ERROR(optional_req_changed,none,"%0 is %select{now|no longer}1 an optional requirement", (StringRef, bool))
65+
ERROR(optional_req_changed,APIDigesterBreakage,"%0 is %select{now|no longer}1 an optional requirement", (StringRef, bool))
6666

67-
ERROR(no_longer_open,none,"%0 is no longer open for subclassing", (StringRef))
67+
ERROR(no_longer_open,APIDigesterBreakage,"%0 is no longer open for subclassing", (StringRef))
6868

69-
ERROR(func_type_escaping_changed,none,"%0 has %select{removed|added}2 @escaping in %1", (StringRef, StringRef, bool))
69+
ERROR(func_type_escaping_changed,APIDigesterBreakage,"%0 has %select{removed|added}2 @escaping in %1", (StringRef, StringRef, bool))
7070

71-
ERROR(func_self_access_change,none,"%0 has self access kind changing from %1 to %2", (StringRef, StringRef, StringRef))
71+
ERROR(func_self_access_change,APIDigesterBreakage,"%0 has self access kind changing from %1 to %2", (StringRef, StringRef, StringRef))
7272

73-
ERROR(param_ownership_change,none,"%0 has %1 changing from %2 to %3", (StringRef, StringRef, StringRef, StringRef))
73+
ERROR(param_ownership_change,APIDigesterBreakage,"%0 has %1 changing from %2 to %3", (StringRef, StringRef, StringRef, StringRef))
7474

75-
ERROR(type_witness_change,none,"%0 has type witness type for %1 changing from %2 to %3", (StringRef, StringRef, StringRef, StringRef))
75+
ERROR(type_witness_change,APIDigesterBreakage,"%0 has type witness type for %1 changing from %2 to %3", (StringRef, StringRef, StringRef, StringRef))
7676

77-
ERROR(decl_new_witness_table_entry,none,"%0 now requires%select{| no}1 new witness table entry", (StringRef, bool))
77+
ERROR(decl_new_witness_table_entry,APIDigesterBreakage,"%0 now requires%select{| no}1 new witness table entry", (StringRef, bool))
7878

79-
ERROR(new_decl_without_intro,none,"%0 is a new API without @available attribute", (StringRef))
79+
ERROR(new_decl_without_intro,APIDigesterBreakage,"%0 is a new API without @available attribute", (StringRef))
8080

81-
ERROR(objc_name_change,none,"%0 has ObjC name change from %1 to %2", (StringRef, StringRef, StringRef))
81+
ERROR(objc_name_change,APIDigesterBreakage,"%0 has ObjC name change from %1 to %2", (StringRef, StringRef, StringRef))
8282

83-
ERROR(desig_init_added,none,"%0 has been added as a designated initializer to an open class", (StringRef))
83+
ERROR(desig_init_added,APIDigesterBreakage,"%0 has been added as a designated initializer to an open class", (StringRef))
8484

85-
ERROR(added_invisible_designated_init,none,"%0 has new designated initializers that are not visible to clients", (StringRef))
85+
ERROR(added_invisible_designated_init,APIDigesterBreakage,"%0 has new designated initializers that are not visible to clients", (StringRef))
8686

87-
ERROR(not_inheriting_convenience_inits,none,"%0 no longer inherits convenience inits from its superclass", (StringRef))
87+
ERROR(not_inheriting_convenience_inits,APIDigesterBreakage,"%0 no longer inherits convenience inits from its superclass", (StringRef))
8888

89-
ERROR(enum_case_added,none,"%0 has been added as a new enum case", (StringRef))
89+
ERROR(enum_case_added,APIDigesterBreakage,"%0 has been added as a new enum case", (StringRef))
9090

9191
WARNING(cannot_read_allowlist,none,"cannot read breakage allowlist at '%0'", (StringRef))
9292

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,9 @@ ERROR(cannot_convert_argument_value_anyobject,none,
425425
(Type, Type))
426426
ERROR(cannot_convert_argument_value_nil,none,
427427
"'nil' is not compatible with expected argument type %0", (Type))
428+
NOTE(note_incompatible_argument_value_nil_at_pos,none,
429+
"'nil' is not compatible with expected argument type %0 at position #%1",
430+
(Type, unsigned))
428431

429432
ERROR(cannot_convert_condition_value,none,
430433
"cannot convert value of type %0 to expected condition type %1",

include/swift/AST/NameLookup.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -555,9 +555,7 @@ class FindLocalVal : public StmtVisitor<FindLocalVal> {
555555
VisibleDeclConsumer &Consumer)
556556
: SM(SM), Loc(Loc), Consumer(Consumer) {}
557557

558-
void checkValueDecl(ValueDecl *D, DeclVisibilityKind Reason) {
559-
Consumer.foundDecl(D, Reason);
560-
}
558+
void checkValueDecl(ValueDecl *D, DeclVisibilityKind Reason);
561559

562560
void checkPattern(const Pattern *Pat, DeclVisibilityKind Reason);
563561

include/swift/Sema/ConstraintSystem.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4994,6 +4994,13 @@ class ConstraintSystem {
49944994
/// diagnostic.
49954995
void maybeProduceFallbackDiagnostic(SolutionApplicationTarget target) const;
49964996

4997+
/// Check whether given AST node represents an argument of an application
4998+
/// of some sort (call, operator invocation, subscript etc.)
4999+
/// and return AST node representing and argument index. E.g. for regular
5000+
/// calls `test(42)` passing `42` should return node representing
5001+
/// entire call and index `0`.
5002+
Optional<std::pair<Expr *, unsigned>> isArgumentExpr(Expr *expr);
5003+
49975004
SWIFT_DEBUG_DUMP;
49985005
SWIFT_DEBUG_DUMPER(dump(Expr *));
49995006

lib/AST/DiagnosticEngine.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,25 @@ enum class DiagnosticOptions {
5252

5353
/// After a fatal error subsequent diagnostics are suppressed.
5454
Fatal,
55+
56+
/// An API or ABI breakage diagnostic emitted by the API digester.
57+
APIDigesterBreakage,
5558
};
5659
struct StoredDiagnosticInfo {
5760
DiagnosticKind kind : 2;
5861
bool pointsToFirstBadToken : 1;
5962
bool isFatal : 1;
63+
bool isAPIDigesterBreakage : 1;
6064

6165
constexpr StoredDiagnosticInfo(DiagnosticKind k, bool firstBadToken,
62-
bool fatal)
63-
: kind(k), pointsToFirstBadToken(firstBadToken), isFatal(fatal) {}
66+
bool fatal, bool isAPIDigesterBreakage)
67+
: kind(k), pointsToFirstBadToken(firstBadToken), isFatal(fatal),
68+
isAPIDigesterBreakage(isAPIDigesterBreakage) {}
6469
constexpr StoredDiagnosticInfo(DiagnosticKind k, DiagnosticOptions opts)
6570
: StoredDiagnosticInfo(k,
6671
opts == DiagnosticOptions::PointsToFirstBadToken,
67-
opts == DiagnosticOptions::Fatal) {}
72+
opts == DiagnosticOptions::Fatal,
73+
opts == DiagnosticOptions::APIDigesterBreakage) {}
6874
};
6975

7076
// Reproduce the DiagIDs, as we want both the size and access to the raw ids
@@ -316,6 +322,10 @@ bool DiagnosticEngine::isDiagnosticPointsToFirstBadToken(DiagID ID) const {
316322
return storedDiagnosticInfos[(unsigned) ID].pointsToFirstBadToken;
317323
}
318324

325+
bool DiagnosticEngine::isAPIDigesterBreakageDiagnostic(DiagID ID) const {
326+
return storedDiagnosticInfos[(unsigned)ID].isAPIDigesterBreakage;
327+
}
328+
319329
bool DiagnosticEngine::finishProcessing() {
320330
bool hadError = false;
321331
for (auto &Consumer : Consumers) {
@@ -1092,11 +1102,17 @@ DiagnosticEngine::diagnosticInfoForDiagnostic(const Diagnostic &diagnostic) {
10921102
}
10931103
}
10941104

1105+
// Currently, only API digester diagnostics are assigned a category.
1106+
StringRef Category;
1107+
if (isAPIDigesterBreakageDiagnostic(diagnostic.getID()))
1108+
Category = "api-digester-breaking-change";
1109+
10951110
return DiagnosticInfo(
10961111
diagnostic.getID(), loc, toDiagnosticKind(behavior),
10971112
diagnosticStringFor(diagnostic.getID(), getPrintDiagnosticNames()),
1098-
diagnostic.getArgs(), getDefaultDiagnosticLoc(), /*child note info*/ {},
1099-
diagnostic.getRanges(), diagnostic.getFixIts(), diagnostic.isChildNote());
1113+
diagnostic.getArgs(), Category, getDefaultDiagnosticLoc(),
1114+
/*child note info*/ {}, diagnostic.getRanges(), diagnostic.getFixIts(),
1115+
diagnostic.isChildNote());
11001116
}
11011117

11021118
void DiagnosticEngine::emitDiagnostic(const Diagnostic &diagnostic) {

0 commit comments

Comments
 (0)