Skip to content

Commit 8b361fb

Browse files
authored
Merge pull request #3622 from swiftwasm/maxd/main-merge
Resolve conflicts with upstream `main`
2 parents c8ec069 + b6fdce6 commit 8b361fb

Some content is hidden

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

45 files changed

+740
-185
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
//===------------------ SwiftSyntaxCDataTypes.h -------------------*- C -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
// There are two copies of this file in the Swift compiler repository and in //
13+
// the SwiftSyntax repository. They need to always share the same contents. //
14+
// //
15+
// The reason behind this is that the SwiftSyntax module should be able to //
16+
// build with no dependencies to the compiler repo (in particular not //
17+
// _InternalSwiftSyntaxParser) so that it can be used for code generation //
18+
// without a matching toolchain. But to make SwiftSyntax parsing efficient, //
19+
// we need to create RawSyntax nodes from the C nodes without any conversion //
20+
// and thus SwiftSyntax needs to have knowledge about the layout of these C //
21+
// types. Thus the two copies of the file. The equality of these files is //
22+
// checked in CI (verify the source matches) and at runtime by //
23+
// SwiftSyntaxParser (verify that a hash generated from the layouts matches) //
24+
//===----------------------------------------------------------------------===//
25+
26+
#ifndef SWIFT_C_SYNTAX_C_DATA_TYPES_H
27+
#define SWIFT_C_SYNTAX_C_DATA_TYPES_H
28+
29+
#include <stdbool.h>
30+
31+
/// Offset+length in UTF8 bytes.
32+
typedef struct {
33+
uint32_t offset;
34+
uint32_t length;
35+
} swiftparse_range_t;
36+
37+
typedef uint8_t swiftparse_trivia_kind_t;
38+
typedef uint8_t swiftparse_token_kind_t;
39+
typedef uint16_t swiftparse_syntax_kind_t;
40+
41+
/// This is for the client to provide an opaque pointer that the parser will
42+
/// associate with a syntax node.
43+
typedef void *swiftparse_client_node_t;
44+
45+
typedef struct {
46+
/// The length in source this trivia piece occupies, in UTF8 bytes.
47+
uint32_t length;
48+
swiftparse_trivia_kind_t kind;
49+
} swiftparse_trivia_piece_t;
50+
51+
typedef struct {
52+
const swiftparse_trivia_piece_t *leading_trivia;
53+
const swiftparse_trivia_piece_t *trailing_trivia;
54+
uint16_t leading_trivia_count;
55+
uint16_t trailing_trivia_count;
56+
swiftparse_token_kind_t kind;
57+
/// Represents the range for the node, including trivia.
58+
swiftparse_range_t range;
59+
} swiftparse_token_data_t;
60+
61+
typedef struct {
62+
const swiftparse_client_node_t *nodes;
63+
uint32_t nodes_count;
64+
} swiftparse_layout_data_t;
65+
66+
typedef struct {
67+
union {
68+
swiftparse_token_data_t token_data;
69+
swiftparse_layout_data_t layout_data;
70+
};
71+
/// The syntax kind. A value of '0' means this is a token node.
72+
swiftparse_syntax_kind_t kind;
73+
bool present;
74+
} swiftparse_syntax_node_t;
75+
76+
#endif

include/swift-c/SyntaxParser/SwiftSyntaxParser.h

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -75,52 +75,7 @@
7575

7676
SWIFTPARSE_BEGIN_DECLS
7777

78-
//=== Syntax Data Types ---------------------------------------------------===//
79-
80-
/// Offset+length in UTF8 bytes.
81-
typedef struct {
82-
uint32_t offset;
83-
uint32_t length;
84-
} swiftparse_range_t;
85-
86-
typedef uint8_t swiftparse_trivia_kind_t;
87-
typedef uint8_t swiftparse_token_kind_t;
88-
typedef uint16_t swiftparse_syntax_kind_t;
89-
90-
/// This is for the client to provide an opaque pointer that the parser will
91-
/// associate with a syntax node.
92-
typedef void *swiftparse_client_node_t;
93-
94-
typedef struct {
95-
/// The length in source this trivia piece occupies, in UTF8 bytes.
96-
uint32_t length;
97-
swiftparse_trivia_kind_t kind;
98-
} swiftparse_trivia_piece_t;
99-
100-
typedef struct {
101-
const swiftparse_trivia_piece_t *leading_trivia;
102-
const swiftparse_trivia_piece_t *trailing_trivia;
103-
uint16_t leading_trivia_count;
104-
uint16_t trailing_trivia_count;
105-
swiftparse_token_kind_t kind;
106-
/// Represents the range for the node, including trivia.
107-
swiftparse_range_t range;
108-
} swiftparse_token_data_t;
109-
110-
typedef struct {
111-
const swiftparse_client_node_t *nodes;
112-
uint32_t nodes_count;
113-
} swiftparse_layout_data_t;
114-
115-
typedef struct {
116-
union {
117-
swiftparse_token_data_t token_data;
118-
swiftparse_layout_data_t layout_data;
119-
};
120-
/// The syntax kind. A value of '0' means this is a token node.
121-
swiftparse_syntax_kind_t kind;
122-
bool present;
123-
} swiftparse_syntax_node_t;
78+
#include "SwiftSyntaxCDataTypes.h"
12479

12580
//=== Parser Functions ----------------------------------------------------===//
12681

include/swift/AST/DiagnosticsParse.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,6 +1747,9 @@ ERROR(unsupported_platform_condition_expression,none,
17471747
"unexpected platform condition "
17481748
"(expected 'os', 'arch', or 'swift')",
17491749
())
1750+
ERROR(platform_condition_expected_argument,none,
1751+
"expected argument to platform condition",
1752+
())
17501753
ERROR(platform_condition_expected_one_argument,none,
17511754
"expected only one argument to platform condition",
17521755
())

include/swift/Basic/LangOptions.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,14 +230,6 @@ namespace swift {
230230
/// Keep comments during lexing and attach them to declarations.
231231
bool AttachCommentsToDecls = false;
232232

233-
/// Whether to include initializers when code-completing a postfix
234-
/// expression.
235-
bool CodeCompleteInitsInPostfixExpr = false;
236-
237-
/// Whether to use heuristics to decide whether to show call-pattern
238-
/// completions.
239-
bool CodeCompleteCallPatternHeuristics = false;
240-
241233
///
242234
/// Flags for use by tests
243235
///

include/swift/IDE/CodeCompletion.h

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,13 @@ struct CodeCompletionResultSink {
947947
/// Whether to emit object literals if desired.
948948
bool includeObjectLiterals = true;
949949

950+
/// Whether to emit type initializers in addition to type names in expression
951+
/// position.
952+
bool addInitsToTopLevel = false;
953+
954+
/// Whether to perform "call pettern heuristics".
955+
bool enableCallPatternHeuristics = false;
956+
950957
std::vector<CodeCompletionResult *> Results;
951958

952959
/// A single-element cache for module names stored in Allocator, keyed by a
@@ -1021,7 +1028,23 @@ class CodeCompletionContext {
10211028
void setIncludeObjectLiterals(bool flag) {
10221029
CurrentResults.includeObjectLiterals = flag;
10231030
}
1024-
bool includeObjectLiterals() { return CurrentResults.includeObjectLiterals; }
1031+
bool includeObjectLiterals() const {
1032+
return CurrentResults.includeObjectLiterals;
1033+
}
1034+
1035+
void setAddInitsToTopLevel(bool flag) {
1036+
CurrentResults.addInitsToTopLevel = flag;
1037+
}
1038+
bool getAddInitsToTopLevel() const {
1039+
return CurrentResults.addInitsToTopLevel;
1040+
}
1041+
1042+
void setCallPatternHeuristics(bool flag) {
1043+
CurrentResults.enableCallPatternHeuristics = flag;
1044+
}
1045+
bool getCallPatternHeuristics() const {
1046+
return CurrentResults.enableCallPatternHeuristics;
1047+
}
10251048

10261049
/// Allocate a string owned by the code completion context.
10271050
StringRef copyString(StringRef Str);

include/swift/IDE/CodeCompletionCache.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class CodeCompletionCache {
4242
bool ResultsHaveLeadingDot;
4343
bool ForTestableLookup;
4444
bool ForPrivateImportLookup;
45-
bool CodeCompleteInitsInPostfixExpr;
45+
bool AddInitsInToplevel;
4646
bool Annotated;
4747

4848
friend bool operator==(const Key &LHS, const Key &RHS) {
@@ -52,7 +52,8 @@ class CodeCompletionCache {
5252
LHS.ResultsHaveLeadingDot == RHS.ResultsHaveLeadingDot &&
5353
LHS.ForTestableLookup == RHS.ForTestableLookup &&
5454
LHS.ForPrivateImportLookup == RHS.ForPrivateImportLookup &&
55-
LHS.CodeCompleteInitsInPostfixExpr == RHS.CodeCompleteInitsInPostfixExpr;
55+
LHS.AddInitsInToplevel == RHS.AddInitsInToplevel &&
56+
LHS.Annotated == RHS.Annotated;
5657
}
5758
};
5859

@@ -123,6 +124,7 @@ struct DenseMapInfo<swift::ide::CodeCompletionCache::Key> {
123124
H ^= std::hash<bool>()(Val.ResultsHaveLeadingDot);
124125
H ^= std::hash<bool>()(Val.ForTestableLookup);
125126
H ^= std::hash<bool>()(Val.ForPrivateImportLookup);
127+
H ^= std::hash<bool>()(Val.AddInitsInToplevel);
126128
H ^= std::hash<bool>()(Val.Annotated);
127129
return static_cast<unsigned>(H);
128130
}

lib/AST/GenericSignature.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ Type GenericSignatureImpl::getSuperclassBound(Type type) const {
539539

540540
auto computeViaRQM = [&]() {
541541
auto *machine = getRequirementMachine();
542-
return machine->getSuperclassBound(type);
542+
return machine->getSuperclassBound(type, getGenericParams());
543543
};
544544

545545
auto &ctx = getASTContext();
@@ -772,7 +772,7 @@ Type GenericSignatureImpl::getConcreteType(Type type) const {
772772

773773
auto computeViaRQM = [&]() {
774774
auto *machine = getRequirementMachine();
775-
return machine->getConcreteType(type);
775+
return machine->getConcreteType(type, getGenericParams());
776776
};
777777

778778
auto &ctx = getASTContext();

lib/AST/RequirementMachine/GenericSignatureQueries.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ RequirementMachine::getRequiredProtocols(Type depType) const {
139139
return result;
140140
}
141141

142-
Type RequirementMachine::getSuperclassBound(Type depType) const {
142+
Type RequirementMachine::
143+
getSuperclassBound(Type depType,
144+
TypeArrayView<GenericTypeParamType> genericParams) const {
143145
auto term = Context.getMutableTermForType(depType->getCanonicalType(),
144146
/*proto=*/nullptr);
145147
System.simplify(term);
@@ -153,7 +155,7 @@ Type RequirementMachine::getSuperclassBound(Type depType) const {
153155
return Type();
154156

155157
auto &protos = System.getProtocols();
156-
return props->getSuperclassBound({ }, term, protos, Context);
158+
return props->getSuperclassBound(genericParams, term, protos, Context);
157159
}
158160

159161
bool RequirementMachine::isConcreteType(Type depType) const {
@@ -169,7 +171,9 @@ bool RequirementMachine::isConcreteType(Type depType) const {
169171
return props->isConcreteType();
170172
}
171173

172-
Type RequirementMachine::getConcreteType(Type depType) const {
174+
Type RequirementMachine::
175+
getConcreteType(Type depType,
176+
TypeArrayView<GenericTypeParamType> genericParams) const {
173177
auto term = Context.getMutableTermForType(depType->getCanonicalType(),
174178
/*proto=*/nullptr);
175179
System.simplify(term);
@@ -183,7 +187,7 @@ Type RequirementMachine::getConcreteType(Type depType) const {
183187
return Type();
184188

185189
auto &protos = System.getProtocols();
186-
return props->getConcreteType({ }, term, protos, Context);
190+
return props->getConcreteType(genericParams, term, protos, Context);
187191
}
188192

189193
bool RequirementMachine::areSameTypeParameterInContext(Type depType1,

lib/AST/RequirementMachine/RequirementMachine.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,11 @@ class RequirementMachine final {
9898
LayoutConstraint getLayoutConstraint(Type depType) const;
9999
bool requiresProtocol(Type depType, const ProtocolDecl *proto) const;
100100
GenericSignature::RequiredProtocols getRequiredProtocols(Type depType) const;
101-
Type getSuperclassBound(Type depType) const;
101+
Type getSuperclassBound(Type depType,
102+
TypeArrayView<GenericTypeParamType> genericParams) const;
102103
bool isConcreteType(Type depType) const;
103-
Type getConcreteType(Type depType) const;
104+
Type getConcreteType(Type depType,
105+
TypeArrayView<GenericTypeParamType> genericParams) const;
104106
bool areSameTypeParameterInContext(Type depType1, Type depType2) const;
105107
bool isCanonicalTypeInContext(Type type) const;
106108
Type getCanonicalTypeInContext(Type type,

lib/DriverTool/autolink_extract_main.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,13 @@ extractLinkerFlagsFromObjectFile(const llvm::object::ObjectFile *ObjectFile,
147147
return false;
148148
}
149149

150-
/// Look inside the object file 'WasmObjectFile' and append any linker flags found in
151-
/// its ".swift1_autolink_entries" section to 'LinkerFlags'.
152-
/// Return 'true' if there was an error, and 'false' otherwise.
150+
/// Look inside the object file 'WasmObjectFile' and append any linker flags
151+
/// found in its ".swift1_autolink_entries" section to 'LinkerFlags'. Return
152+
/// 'true' if there was an error, and 'false' otherwise.
153153
static bool
154154
extractLinkerFlagsFromObjectFile(const llvm::object::WasmObjectFile *ObjectFile,
155155
std::vector<std::string> &LinkerFlags,
156156
CompilerInstance &Instance) {
157-
158157
// Search for the data segment we hold autolink entries in
159158
for (const llvm::object::WasmSegment &Segment : ObjectFile->dataSegments()) {
160159
if (Segment.Data.Name == ".swift1_autolink_entries") {
@@ -164,7 +163,7 @@ extractLinkerFlagsFromObjectFile(const llvm::object::WasmObjectFile *ObjectFile,
164163
// the set.
165164
llvm::SmallVector<llvm::StringRef, 4> SplitFlags;
166165
SegmentData.split(SplitFlags, llvm::StringRef("\0", 1), -1,
167-
/*KeepEmpty=*/false);
166+
/*KeepEmpty=*/false);
168167
for (const auto &Flag : SplitFlags)
169168
LinkerFlags.push_back(Flag.str());
170169
}
@@ -182,7 +181,8 @@ static bool extractLinkerFlags(const llvm::object::Binary *Bin,
182181
std::vector<std::string> &LinkerFlags) {
183182
if (auto *ObjectFile = llvm::dyn_cast<llvm::object::ELFObjectFileBase>(Bin)) {
184183
return extractLinkerFlagsFromObjectFile(ObjectFile, LinkerFlags, Instance);
185-
} else if (auto *ObjectFile = llvm::dyn_cast<llvm::object::WasmObjectFile>(Bin)) {
184+
} else if (auto *ObjectFile =
185+
llvm::dyn_cast<llvm::object::WasmObjectFile>(Bin)) {
186186
return extractLinkerFlagsFromObjectFile(ObjectFile, LinkerFlags, Instance);
187187
} else if (auto *Archive = llvm::dyn_cast<llvm::object::Archive>(Bin)) {
188188
llvm::Error Error = llvm::Error::success();

0 commit comments

Comments
 (0)