Skip to content

Commit 0f8e6cc

Browse files
Merge pull request #4346 from swiftwasm/main
[pull] swiftwasm from main
2 parents fd19441 + e25b822 commit 0f8e6cc

File tree

109 files changed

+1440
-678
lines changed

Some content is hidden

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

109 files changed

+1440
-678
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,10 +742,14 @@ else()
742742
endif()
743743
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64")
744744
set(SWIFT_HOST_VARIANT_ARCH_default "powerpc64")
745+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc")
746+
set(SWIFT_HOST_VARIANT_ARCH_default "powerpc")
745747
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64le")
746748
set(SWIFT_HOST_VARIANT_ARCH_default "powerpc64le")
747749
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "s390x")
748750
set(SWIFT_HOST_VARIANT_ARCH_default "s390x")
751+
elseif("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "armv5|armv5te")
752+
set(SWIFT_HOST_VARIANT_ARCH_default "armv5")
749753
# FIXME: Only matches v6l/v7l - by far the most common variants
750754
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv6l")
751755
set(SWIFT_HOST_VARIANT_ARCH_default "armv6")

benchmark/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ set(SWIFT_BENCH_MODULES
196196
single-source/WordCount
197197
single-source/XorLoop
198198
cxx-source/CreateObjects
199+
cxx-source/ReadAccessor
199200
)
200201

201202
set(SWIFT_MULTISOURCE_SWIFT_BENCHES
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Subscripts.swift - Very brief description
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2022 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+
///
13+
/// This is a simple test that reads a non trivial C++ struct using an imported
14+
/// subscript thousands of times.
15+
///
16+
// -----------------------------------------------------------------------------
17+
18+
import TestsUtils
19+
import CxxSubscripts
20+
21+
var vec : TwoDimensionalVector?
22+
23+
public let benchmarks = [
24+
BenchmarkInfo(
25+
name: "ReadAccessor",
26+
runFunction: run_ReadAccessor,
27+
tags: [.validation, .bridging],
28+
setUpFunction: {
29+
vec = initVector()
30+
})
31+
]
32+
33+
@inline(never)
34+
public func run_ReadAccessor(_ N: Int) {
35+
for i in 0...N {
36+
for j in 0..<100 {
37+
#if os(Linux)
38+
let row = vec![UInt(j)];
39+
#else
40+
let row = vec![j];
41+
#endif
42+
for k in 0..<1_000 {
43+
#if os(Linux)
44+
let element = row[UInt(k)];
45+
#else
46+
let element = row[k];
47+
#endif
48+
blackHole(element)
49+
}
50+
}
51+
}
52+
}

benchmark/utils/CxxTests/Subscripts.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef BENCHMARK_SUBSCRIPTS_H
2+
#define BENCHMARK_SUBSCRIPTS_H
3+
#include <vector>
4+
5+
using TwoDimensionalVector = std::vector<std::vector<int>>;
6+
7+
inline TwoDimensionalVector initVector() { return {100, std::vector<int>{1000, 0}}; }
8+
9+
#endif
10+

benchmark/utils/CxxTests/module.modulemap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@ module CxxCreateObjects {
22
header "CreateObjects.h"
33
requires cplusplus
44
}
5+
6+
module CxxSubscripts {
7+
header "Subscripts.h"
8+
requires cplusplus
9+
}

benchmark/utils/main.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ import RangeAssignment
152152
import RangeIteration
153153
import RangeOverlaps
154154
import RangeReplaceableCollectionPlusDefault
155+
import ReadAccessor
155156
import RecursiveOwnedParameter
156157
import ReduceInto
157158
import RemoveWhere
@@ -332,6 +333,7 @@ register(RangeAssignment.benchmarks)
332333
register(RangeIteration.benchmarks)
333334
register(RangeOverlaps.benchmarks)
334335
register(RangeReplaceableCollectionPlusDefault.benchmarks)
336+
register(ReadAccessor.benchmarks)
335337
register(RecursiveOwnedParameter.benchmarks)
336338
register(ReduceInto.benchmarks)
337339
register(RemoveWhere.benchmarks)

cmake/modules/AddSwift.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ function(_add_host_variant_link_flags target)
344344
target_link_libraries(${target} PRIVATE
345345
pthread
346346
dl)
347-
if("${SWIFT_HOST_VARIANT_ARCH}" MATCHES "armv6|armv7|i686")
347+
if("${SWIFT_HOST_VARIANT_ARCH}" MATCHES "armv5|armv6|armv7|i686")
348348
target_link_libraries(${target} PRIVATE atomic)
349349
endif()
350350
elseif(SWIFT_HOST_VARIANT_SDK STREQUAL FREEBSD)

cmake/modules/AddSwiftUnittests.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function(add_swift_unittest test_dirname)
3737
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64")
3838
target_compile_options(${test_dirname} PRIVATE
3939
-march=core2)
40-
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "armv6|armv7|i686")
40+
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "armv5|armv6|armv7|i686")
4141
set_property(TARGET "${test_dirname}" APPEND PROPERTY LINK_LIBRARIES
4242
"atomic")
4343
endif()

cmake/modules/SwiftConfigureSDK.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,11 @@ macro(configure_sdk_unix name architectures)
324324
endif()
325325

326326
if("${prefix}" STREQUAL "LINUX")
327-
if(arch MATCHES "(armv6|armv7)")
327+
if(arch MATCHES "(armv5)")
328+
set(SWIFT_SDK_LINUX_ARCH_${arch}_TRIPLE "${arch}-unknown-linux-gnueabi")
329+
elseif(arch MATCHES "(armv6|armv7)")
328330
set(SWIFT_SDK_LINUX_ARCH_${arch}_TRIPLE "${arch}-unknown-linux-gnueabihf")
329-
elseif(arch MATCHES "(aarch64|i686|powerpc64|powerpc64le|s390x|x86_64)")
331+
elseif(arch MATCHES "(aarch64|i686|powerpc|powerpc64|powerpc64le|s390x|x86_64)")
330332
set(SWIFT_SDK_LINUX_ARCH_${arch}_TRIPLE "${arch}-unknown-linux-gnu")
331333
else()
332334
message(FATAL_ERROR "unknown arch for ${prefix}: ${arch}")

cmake/modules/SwiftSetIfArchBitness.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ function(set_if_arch_bitness var_name)
99
if("${SIA_ARCH}" STREQUAL "i386" OR
1010
"${SIA_ARCH}" STREQUAL "i686" OR
1111
"${SIA_ARCH}" STREQUAL "x86" OR
12+
"${SIA_ARCH}" STREQUAL "armv5" OR
1213
"${SIA_ARCH}" STREQUAL "armv6" OR
1314
"${SIA_ARCH}" STREQUAL "armv7" OR
1415
"${SIA_ARCH}" STREQUAL "armv7k" OR
1516
"${SIA_ARCH}" STREQUAL "arm64_32" OR
1617
"${SIA_ARCH}" STREQUAL "armv7s" OR
17-
"${SIA_ARCH}" STREQUAL "wasm32")
18+
"${SIA_ARCH}" STREQUAL "wasm32" OR
19+
"${SIA_ARCH}" STREQUAL "powerpc")
1820
set("${var_name}" "${SIA_CASE_32_BIT}" PARENT_SCOPE)
1921
elseif("${SIA_ARCH}" STREQUAL "x86_64" OR
2022
"${SIA_ARCH}" STREQUAL "amd64" OR

include/swift/AST/Availability.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ class AvailabilityContext {
220220
/// deployment target.
221221
static AvailabilityContext forDeploymentTarget(ASTContext &Ctx);
222222

223+
/// Creates a context that imposes the constraints of the ASTContext's
224+
/// inlining target (i.e. minimum inlining version).
225+
static AvailabilityContext forInliningTarget(ASTContext &Ctx);
226+
223227
/// Creates a context that imposes no constraints.
224228
///
225229
/// \see isAlwaysAvailable

include/swift/AST/KnownStdlibTypes.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ KNOWN_STDLIB_TYPE_DECL(String, NominalTypeDecl, 0)
4949
KNOWN_STDLIB_TYPE_DECL(StaticString, NominalTypeDecl, 0)
5050
KNOWN_STDLIB_TYPE_DECL(Substring, NominalTypeDecl, 0)
5151
KNOWN_STDLIB_TYPE_DECL(Array, NominalTypeDecl, 1)
52-
KNOWN_STDLIB_TYPE_DECL(_ContiguousArrayStorage, NominalTypeDecl, 1)
52+
KNOWN_STDLIB_TYPE_DECL(_ContiguousArrayStorage, ClassDecl, 1)
5353
KNOWN_STDLIB_TYPE_DECL(Set, NominalTypeDecl, 1)
5454
KNOWN_STDLIB_TYPE_DECL(Sequence, NominalTypeDecl, 1)
5555
KNOWN_STDLIB_TYPE_DECL(Dictionary, NominalTypeDecl, 2)

include/swift/AST/TypeRefinementContext.h

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ class TypeRefinementContext : public ASTAllocated<TypeRefinementContext> {
5858
/// function declaration or the contents of a class declaration).
5959
Decl,
6060

61+
/// The context was introduced by a resilience boundary; that is, we are in
62+
/// a module with library evolution enabled and the parent context's
63+
/// contents can be visible to the module's clients, but this context's
64+
/// contents are not.
65+
ResilienceBoundary,
66+
6167
/// The context was introduced for the Then branch of an IfStmt.
6268
IfStmtThenBranch,
6369

@@ -102,7 +108,10 @@ class TypeRefinementContext : public ASTAllocated<TypeRefinementContext> {
102108

103109
public:
104110
IntroNode(SourceFile *SF) : IntroReason(Reason::Root), SF(SF) {}
105-
IntroNode(Decl *D) : IntroReason(Reason::Decl), D(D) {}
111+
IntroNode(Decl *D, Reason introReason = Reason::Decl)
112+
: IntroReason(introReason), D(D) {
113+
(void)getAsDecl(); // check that assertion succeeds
114+
}
106115
IntroNode(IfStmt *IS, bool IsThen) :
107116
IntroReason(IsThen ? Reason::IfStmtThenBranch : Reason::IfStmtElseBranch),
108117
IS(IS) {}
@@ -122,7 +131,8 @@ class TypeRefinementContext : public ASTAllocated<TypeRefinementContext> {
122131
}
123132

124133
Decl *getAsDecl() const {
125-
assert(IntroReason == Reason::Decl);
134+
assert(IntroReason == Reason::Decl ||
135+
IntroReason == Reason::ResilienceBoundary);
126136
return D;
127137
}
128138

@@ -182,7 +192,14 @@ class TypeRefinementContext : public ASTAllocated<TypeRefinementContext> {
182192
const AvailabilityContext &Info,
183193
const AvailabilityContext &ExplicitInfo,
184194
SourceRange SrcRange);
185-
195+
196+
/// Create a refinement context for the given declaration.
197+
static TypeRefinementContext *
198+
createForResilienceBoundary(ASTContext &Ctx, Decl *D,
199+
TypeRefinementContext *Parent,
200+
const AvailabilityContext &Info,
201+
SourceRange SrcRange);
202+
186203
/// Create a refinement context for the Then branch of the given IfStmt.
187204
static TypeRefinementContext *
188205
createForIfStmtThen(ASTContext &Ctx, IfStmt *S, TypeRefinementContext *Parent,

include/swift/Basic/LangOptions.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ namespace swift {
134134
/// The SDK canonical name, if known.
135135
std::string SDKName;
136136

137+
/// The lowest target OS version that code in this module may be inlined
138+
/// into. In resilient modules, this should match the minimum
139+
/// deployment target of the *first* resilient version of the module, since
140+
/// clients may need to interoperate with versions as far back as that
141+
/// deployment target.
142+
llvm::VersionTuple MinimumInliningTargetVersion;
143+
137144
/// The alternate name to use for the entry point instead of main.
138145
std::string entryPointFunctionName = "main";
139146

include/swift/Basic/Platform.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ namespace swift {
5555
bool triplesAreValidForZippering(const llvm::Triple &target,
5656
const llvm::Triple &targetVariant);
5757

58+
const Optional<llvm::VersionTuple>
59+
minimumABIStableOSVersionForTriple(const llvm::Triple &triple);
60+
5861
/// Returns true if the given triple represents an OS that has all the
5962
/// "built-in" ABI-stable libraries (stdlib and _Concurrency)
6063
/// (eg. in /usr/lib/swift).

include/swift/Frontend/DiagnosticVerifier.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class DiagnosticVerifier : public DiagnosticConsumer {
132132
/// unexpected ones.
133133
Result verifyFile(unsigned BufferID);
134134

135-
bool checkForFixIt(const ExpectedFixIt &Expected,
135+
bool checkForFixIt(const std::vector<ExpectedFixIt> &ExpectedAlts,
136136
const CapturedDiagnosticInfo &D, unsigned BufferID) const;
137137

138138
// Render the verifier syntax for a given set of fix-its.

include/swift/Option/Options.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,11 @@ def disable_clang_target : Flag<["-"], "disable-clang-target">,
11561156
Flags<[NewDriverOnlyOption]>,
11571157
HelpText<"Disable a separately specified target triple for Clang instance to use">;
11581158

1159+
def min_inlining_target_version : Separate<["-"], "target-min-inlining-version">,
1160+
Flags<[FrontendOption, ModuleInterfaceOptionIgnorable]>,
1161+
HelpText<"Require inlinable code with no '@available' attribute to back-deploy "
1162+
"to this version of the '-target' OS">;
1163+
11591164
def profile_generate : Flag<["-"], "profile-generate">,
11601165
Flags<[FrontendOption, NoInteractiveOption]>,
11611166
HelpText<"Generate instrumented code to collect execution counts">;

lib/APIDigester/ModuleAnalyzerNodes.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2244,7 +2244,6 @@ struct ConstExprInfo {
22442244

22452245
class ConstExtractor: public ASTWalker {
22462246
SDKContext &SCtx;
2247-
ASTContext &Ctx;
22482247
SourceManager &SM;
22492248
std::vector<ConstExprInfo> allConsts;
22502249

@@ -2328,7 +2327,7 @@ class ConstExtractor: public ASTWalker {
23282327
return { true, E };
23292328
}
23302329
public:
2331-
ConstExtractor(SDKContext &SCtx, ASTContext &Ctx): SCtx(SCtx), Ctx(Ctx),
2330+
ConstExtractor(SDKContext &SCtx, ASTContext &Ctx): SCtx(SCtx),
23322331
SM(Ctx.SourceMgr) {}
23332332
void extract(ModuleDecl *MD) { MD->walk(*this); }
23342333
std::vector<ConstExprInfo> &getAllConstValues() { return allConsts; }

lib/AST/Availability.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ AvailabilityContext AvailabilityContext::forDeploymentTarget(ASTContext &Ctx) {
3030
VersionRange::allGTE(Ctx.LangOpts.getMinPlatformVersion()));
3131
}
3232

33+
AvailabilityContext AvailabilityContext::forInliningTarget(ASTContext &Ctx) {
34+
return AvailabilityContext(
35+
VersionRange::allGTE(Ctx.LangOpts.MinimumInliningTargetVersion));
36+
}
37+
3338
namespace {
3439

3540
/// The inferred availability required to access a group of declarations

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3330,7 +3330,6 @@ Type GenericSignatureBuilder::getCanonicalTypeParameter(Type type) {
33303330
Type currentType = genericParamType;
33313331
SmallVector<AssociatedTypeDecl *, 4> path(initialPath.getPath().begin(),
33323332
initialPath.getPath().end());
3333-
bool simplified = false;
33343333
do {
33353334
CanType currentAnchor = currentType->getCanonicalType();
33363335
if (auto rootNode = Impl->getRewriteTreeRootIfPresent(currentAnchor)) {
@@ -3366,7 +3365,6 @@ Type GenericSignatureBuilder::getCanonicalTypeParameter(Type type) {
33663365
}
33673366

33683367
// Move back to the beginning; we may have opened up other rewrites.
3369-
simplified = true;
33703368
startIndex = 0;
33713369
currentType = genericParamType;
33723370
continue;

lib/AST/NameLookup.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2174,7 +2174,6 @@ directReferencesForIdentTypeRepr(Evaluator &evaluator,
21742174
DeclContext *dc) {
21752175
DirectlyReferencedTypeDecls current;
21762176

2177-
bool firstComponent = true;
21782177
for (const auto &component : ident->getComponentRange()) {
21792178
// If we already set a declaration, use it.
21802179
if (auto typeDecl = component->getBoundDecl()) {
@@ -2194,7 +2193,6 @@ directReferencesForIdentTypeRepr(Evaluator &evaluator,
21942193
if (current.empty())
21952194
return current;
21962195

2197-
firstComponent = false;
21982196
continue;
21992197
}
22002198

0 commit comments

Comments
 (0)