Skip to content

Commit a0e58a7

Browse files
authored
Merge pull request #960 from swiftwasm/master
[pull] swiftwasm from master
2 parents a0e45cd + a554f08 commit a0e58a7

File tree

16 files changed

+116
-75
lines changed

16 files changed

+116
-75
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,8 @@ function(is_darwin_based_sdk sdk_name out_var)
9090
endfunction()
9191

9292
# Usage:
93-
# _add_host_variant_c_compile_link_flags(
94-
# RESULT_VAR_NAME result_var_name
95-
# )
96-
function(_add_host_variant_c_compile_link_flags)
97-
set(oneValueArgs RESULT_VAR_NAME)
98-
cmake_parse_arguments(CFLAGS
99-
""
100-
"${oneValueArgs}"
101-
""
102-
${ARGN})
103-
104-
set(result ${${CFLAGS_RESULT_VAR_NAME}})
105-
93+
# _add_host_variant_c_compile_link_flags(name)
94+
function(_add_host_variant_c_compile_link_flags name)
10695
is_darwin_based_sdk("${SWIFT_HOST_VARIANT_SDK}" IS_DARWIN)
10796
if(IS_DARWIN)
10897
set(DEPLOYMENT_VERSION "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_DEPLOYMENT_VERSION}")
@@ -113,49 +102,45 @@ function(_add_host_variant_c_compile_link_flags)
113102
get_target_triple(target target_variant "${SWIFT_HOST_VARIANT_SDK}" "${SWIFT_HOST_VARIANT_ARCH}"
114103
MACCATALYST_BUILD_FLAVOR ""
115104
DEPLOYMENT_VERSION "${DEPLOYMENT_VERSION}")
116-
list(APPEND result "-target" "${target}")
105+
target_compile_options(${name} PRIVATE -target;${target})
117106
endif()
118107

119108
set(_sysroot
120109
"${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${SWIFT_HOST_VARIANT_ARCH}_PATH}")
121110
if(IS_DARWIN)
122-
list(APPEND result "-isysroot" "${_sysroot}")
111+
target_compile_options(${name} PRIVATE -isysroot;${_sysroot})
123112
elseif(NOT SWIFT_COMPILER_IS_MSVC_LIKE AND NOT "${_sysroot}" STREQUAL "/")
124-
list(APPEND result "--sysroot=${_sysroot}")
113+
target_compile_options(${name} PRIVATE --sysroot=${_sysroot})
125114
endif()
126115

127116
if(SWIFT_HOST_VARIANT_SDK STREQUAL ANDROID)
128117
# lld can handle targeting the android build. However, if lld is not
129118
# enabled, then fallback to the linker included in the android NDK.
130119
if(NOT SWIFT_ENABLE_LLD_LINKER)
131120
swift_android_tools_path(${SWIFT_HOST_VARIANT_ARCH} tools_path)
132-
list(APPEND result "-B" "${tools_path}")
121+
target_compile_options(${name} PRIVATE -B${tools_path})
133122
endif()
134123
endif()
135124

136125
if(IS_DARWIN)
137126
# We collate -F with the framework path to avoid unwanted deduplication
138127
# of options by target_compile_options -- this way no undesired
139128
# side effects are introduced should a new search path be added.
140-
list(APPEND result
141-
"-arch" "${SWIFT_HOST_VARIANT_ARCH}"
129+
target_compile_options(${name} PRIVATE
130+
-arch ${SWIFT_HOST_VARIANT_ARCH}
142131
"-F${SWIFT_SDK_${SWIFT_HOST_VARIANT_ARCH}_PATH}/../../../Developer/Library/Frameworks"
143132
"-m${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_VERSION_MIN_NAME}-version-min=${DEPLOYMENT_VERSION}")
144133
endif()
145134

146135
_compute_lto_flag("${SWIFT_TOOLS_ENABLE_LTO}" _lto_flag_out)
147136
if (_lto_flag_out)
148-
list(APPEND result "${_lto_flag_out}")
137+
target_compile_options(${name} PRIVATE ${_lto_flag_out})
149138
endif()
150-
151-
set("${CFLAGS_RESULT_VAR_NAME}" "${result}" PARENT_SCOPE)
152139
endfunction()
153140

154141

155142
function(_add_host_variant_c_compile_flags target)
156-
_add_host_variant_c_compile_link_flags(RESULT_VAR_NAME result)
157-
target_compile_options(${target} PRIVATE
158-
${result})
143+
_add_host_variant_c_compile_link_flags(${target})
159144

160145
is_build_type_optimized("${CMAKE_BUILD_TYPE}" optimized)
161146
if(optimized)
@@ -318,9 +303,7 @@ function(_add_host_variant_c_compile_flags target)
318303
endfunction()
319304

320305
function(_add_host_variant_link_flags target)
321-
_add_host_variant_c_compile_link_flags(RESULT_VAR_NAME result)
322-
target_link_options(${target} PRIVATE
323-
${result})
306+
_add_host_variant_c_compile_link_flags(${target})
324307

325308
if(SWIFT_HOST_VARIANT_SDK STREQUAL LINUX)
326309
target_link_libraries(${target} PRIVATE

include/swift/Parse/Parser.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -494,13 +494,7 @@ class Parser {
494494
~BacktrackingScope();
495495
bool willBacktrack() const { return Backtrack; }
496496

497-
void cancelBacktrack() {
498-
Backtrack = false;
499-
SynContext->setTransparent();
500-
SynContext.reset();
501-
DT.commit();
502-
TempReceiver.shouldTransfer = true;
503-
}
497+
void cancelBacktrack();
504498
};
505499

506500
/// RAII object that, when it is destructed, restores the parser and lexer to

include/swift/Parse/SyntaxParsingContext.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,9 @@ class alignas(1 << SyntaxAlignInBits) SyntaxParsingContext {
326326
IsBacktracking = true;
327327
}
328328

329+
/// Cancels backtracking state from the top of the context stack until `this` context.
330+
void cancelBacktrack();
331+
329332
bool isBacktracking() const { return IsBacktracking; }
330333

331334
void setShouldDefer(bool Value = true) { ShouldDefer = Value; }

include/swift/SILOptimizer/Differentiation/AdjointValue.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "swift/AST/Decl.h"
2222
#include "swift/SIL/SILValue.h"
2323
#include "llvm/ADT/ArrayRef.h"
24+
#include "llvm/Support/Debug.h"
2425

2526
namespace swift {
2627
namespace autodiff {

lib/Parse/ParseDecl.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5531,7 +5531,14 @@ ParserStatus Parser::parseGetSet(ParseDeclOptions Flags,
55315531
parseImplicitGetter();
55325532
return makeParserSuccess();
55335533
}
5534-
IsFirstAccessor = false;
5534+
if (IsFirstAccessor) {
5535+
// Continue parsing without backtracking so we can re-use previously
5536+
// parsed nodes for incremental re-parsing, but avoid destructing
5537+
// `backtrack` because its syntax context isn't at the top of the stack at
5538+
// this point.
5539+
backtrack->cancelBacktrack();
5540+
IsFirstAccessor = false;
5541+
}
55355542

55365543
// For now, immediately reject illegal accessors in protocols just to
55375544
// avoid having to deal with them everywhere.

lib/Parse/Parser.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,19 @@ swift::Parser::BacktrackingScope::~BacktrackingScope() {
222222
}
223223
}
224224

225+
void swift::Parser::BacktrackingScope::cancelBacktrack() {
226+
if (!Backtrack)
227+
return;
228+
229+
Backtrack = false;
230+
SynContext->cancelBacktrack();
231+
SynContext->setTransparent();
232+
if (SynContext->isTopOfContextStack())
233+
SynContext.reset();
234+
DT.commit();
235+
TempReceiver.shouldTransfer = true;
236+
}
237+
225238
/// Tokenizes a string literal, taking into account string interpolation.
226239
static void getStringPartTokens(const Token &Tok, const LangOptions &LangOpts,
227240
const SourceManager &SM,

lib/Parse/SyntaxParsingContext.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,39 @@ SyntaxParsingContext::SyntaxParsingContext(SyntaxParsingContext *&CtxtHolder,
4646
getStorage().reserve(128);
4747
}
4848

49+
void SyntaxParsingContext::cancelBacktrack() {
50+
SyntaxParsingContext *curr = CtxtHolder;
51+
while (true) {
52+
curr->IsBacktracking = false;
53+
if (curr == this) {
54+
break;
55+
}
56+
curr = curr->getParent();
57+
}
58+
}
59+
4960
size_t SyntaxParsingContext::lookupNode(size_t LexerOffset, SourceLoc Loc) {
5061
if (!Enabled)
5162
return 0;
5263

64+
// Avoid doing lookup for a previous parsed node when we are in backtracking
65+
// mode. This is because if the parser library client give us a node pointer
66+
// and we discard it due to backtracking then we are violating this invariant:
67+
//
68+
// The parser guarantees that any \c swiftparse_client_node_t, given to the
69+
// parser by \c swiftparse_node_handler_t or \c swiftparse_node_lookup_t,
70+
// will be returned back to the client.
71+
//
72+
// which will end up likely creating a memory leak for the client because
73+
// the semantics is that the parser accepts ownership of the object that the
74+
// node pointer represents.
75+
//
76+
// Note that the fact that backtracking mode is disabling incremental parse
77+
// node re-use is another reason that we should keep backtracking state as
78+
// minimal as possible.
79+
if (isBacktracking())
80+
return 0;
81+
5382
assert(getStorage().size() == Offset &&
5483
"Cannot do lookup if nodes have already been gathered");
5584
assert(Mode == AccumulationMode::CreateSyntax &&

lib/Sema/TypeCheckPattern.cpp

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ filterForEnumElement(DeclContext *DC, SourceLoc UseLoc,
7979
EnumElementDecl *foundElement = nullptr;
8080
VarDecl *foundConstant = nullptr;
8181

82-
for (LookupResultEntry result : foundElements) {
82+
for (const LookupResultEntry &result : foundElements) {
8383
ValueDecl *e = result.getValueDecl();
8484
assert(e);
8585
if (e->isInvalid()) {
@@ -1315,39 +1315,6 @@ Pattern *TypeChecker::coercePatternToType(ContextualPattern pattern,
13151315
EEP->getLoc());
13161316
if (!elt) {
13171317
if (!type->hasError()) {
1318-
// Lowercasing of Swift.Optional's cases is handled in the
1319-
// standard library itself, not through the clang importer,
1320-
// so we have to do this check here. Additionally, .Some
1321-
// isn't a static VarDecl, so the existing mechanics in
1322-
// extractEnumElement won't work.
1323-
if (type->getAnyNominal() == Context.getOptionalDecl()) {
1324-
if (EEP->getName().isSimpleName("None") ||
1325-
EEP->getName().isSimpleName("Some")) {
1326-
SmallString<4> Rename;
1327-
camel_case::toLowercaseWord(EEP->getName()
1328-
.getBaseIdentifier().str(),
1329-
Rename);
1330-
diags.diagnose(
1331-
EEP->getLoc(), diag::availability_decl_unavailable_rename,
1332-
/*"getter" prefix*/ 2, EEP->getName().getBaseName(),
1333-
/*replaced*/ false, /*special kind*/ 0, Rename.str(),
1334-
/*message*/ StringRef())
1335-
.fixItReplace(EEP->getLoc(), Rename.str());
1336-
1337-
return nullptr;
1338-
}
1339-
1340-
// If we have the original expression parse tree, try reinterpreting
1341-
// it as an expr-pattern if enum element lookup failed, since `.foo`
1342-
// could also refer to a static member of the context type.
1343-
} else if (EEP->hasUnresolvedOriginalExpr()) {
1344-
P = new (Context) ExprPattern(EEP->getUnresolvedOriginalExpr(),
1345-
nullptr, nullptr);
1346-
return coercePatternToType(
1347-
pattern.forSubPattern(P, /*retainTopLevel=*/true), type,
1348-
options);
1349-
}
1350-
13511318
// If we have an optional type, let's try to see if the case
13521319
// exists in its base type and if it does then synthesize an
13531320
// OptionalSomePattern that wraps the case. This uses recursion
@@ -1369,6 +1336,15 @@ Pattern *TypeChecker::coercePatternToType(ContextualPattern pattern,
13691336
EEP->getName(), type);
13701337
return nullptr;
13711338
}
1339+
} else if (EEP->hasUnresolvedOriginalExpr()) {
1340+
// If we have the original expression parse tree, try reinterpreting
1341+
// it as an expr-pattern if enum element lookup failed, since `.foo`
1342+
// could also refer to a static member of the context type.
1343+
P = new (Context) ExprPattern(EEP->getUnresolvedOriginalExpr(),
1344+
nullptr, nullptr);
1345+
return coercePatternToType(
1346+
pattern.forSubPattern(P, /*retainTopLevel=*/true), type,
1347+
options);
13721348
}
13731349
}
13741350
}

stdlib/public/Differentiation/ArrayDifferentiation.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ extension Array where Element: Differentiable {
262262
//===----------------------------------------------------------------------===//
263263

264264
extension Array where Element: Differentiable {
265+
@inlinable
265266
@differentiable(wrt: (self, initialResult))
266267
public func differentiableReduce<Result: Differentiable>(
267268
_ initialResult: Result,
@@ -270,7 +271,7 @@ extension Array where Element: Differentiable {
270271
reduce(initialResult, nextPartialResult)
271272
}
272273

273-
@usableFromInline
274+
@inlinable
274275
@derivative(of: differentiableReduce)
275276
internal func _vjpDifferentiableReduce<Result: Differentiable>(
276277
_ initialResult: Result,
@@ -310,14 +311,15 @@ extension Array where Element: Differentiable {
310311
}
311312

312313
extension Array where Element: Differentiable {
314+
@inlinable
313315
@differentiable(wrt: self)
314316
public func differentiableMap<Result: Differentiable>(
315317
_ body: @differentiable (Element) -> Result
316318
) -> [Result] {
317319
map(body)
318320
}
319321

320-
@usableFromInline
322+
@inlinable
321323
@derivative(of: differentiableMap)
322324
internal func _vjpDifferentiableMap<Result: Differentiable>(
323325
_ body: @differentiable (Element) -> Result

stdlib/toolchain/Compatibility51/Concurrent.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <iterator>
2121
#include <algorithm>
2222
#include <atomic>
23+
#include <cassert>
2324
#include <functional>
2425
#include <pthread.h>
2526
#include <stdint.h>

0 commit comments

Comments
 (0)