Skip to content

Commit 8969481

Browse files
authored
Merge pull request #2254 from swiftwasm/main
[pull] swiftwasm from main
2 parents b9c7b22 + 887464b commit 8969481

File tree

57 files changed

+1178
-1090
lines changed

Some content is hidden

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

57 files changed

+1178
-1090
lines changed

benchmark/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ set(SWIFT_BENCH_MODULES
189189
single-source/Walsh
190190
single-source/WordCount
191191
single-source/XorLoop
192+
cxx-source/CreateObjects
192193
)
193194

194195
set(SWIFT_MULTISOURCE_SWIFT_BENCHES

benchmark/Package.swift

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ var singleSourceLibraries: [String] = singleSourceLibraryDirs.flatMap {
4949
getSingleSourceLibraries(subDirectory: $0)
5050
}
5151

52+
var cxxSingleSourceLibraryDirs: [String] = ["cxx-source"]
53+
var cxxSingleSourceLibraries: [String] = cxxSingleSourceLibraryDirs.flatMap {
54+
getSingleSourceLibraries(subDirectory: $0)
55+
}
56+
5257
//===---
5358
// Multi Source Libraries
5459
//
@@ -80,6 +85,7 @@ products.append(.library(name: "ObjectiveCTests", type: .static, targets: ["Obje
8085
products.append(.executable(name: "SwiftBench", targets: ["SwiftBench"]))
8186

8287
products += singleSourceLibraries.map { .library(name: $0, type: .static, targets: [$0]) }
88+
products += cxxSingleSourceLibraries.map { .library(name: $0, type: .static, targets: [$0]) }
8389
products += multiSourceLibraries.map {
8490
return .library(name: $0.name, type: .static, targets: [$0.name])
8591
}
@@ -103,13 +109,18 @@ swiftBenchDeps.append(.target(name: "ObjectiveCTests"))
103109
#endif
104110
swiftBenchDeps.append(.target(name: "DriverUtils"))
105111
swiftBenchDeps += singleSourceLibraries.map { .target(name: $0) }
112+
swiftBenchDeps += cxxSingleSourceLibraries.map { .target(name: $0) }
106113
swiftBenchDeps += multiSourceLibraries.map { .target(name: $0.name) }
107114

108115
targets.append(
109116
.target(name: "SwiftBench",
110117
dependencies: swiftBenchDeps,
111118
path: "utils",
112-
sources: ["main.swift"]))
119+
sources: ["main.swift"],
120+
swiftSettings: [.unsafeFlags(["-Xfrontend",
121+
"-enable-cxx-interop",
122+
"-I",
123+
"utils/CxxTests"])]))
113124

114125
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
115126
targets.append(
@@ -139,6 +150,18 @@ targets += singleSourceLibraries.map { name in
139150
sources: ["\(name).swift"])
140151
}
141152

153+
targets += cxxSingleSourceLibraries.map { name in
154+
return .target(
155+
name: name,
156+
dependencies: singleSourceDeps,
157+
path: "cxx-source",
158+
sources: ["\(name).swift"],
159+
swiftSettings: [.unsafeFlags(["-Xfrontend",
160+
"-enable-cxx-interop",
161+
"-I",
162+
"utils/CxxTests"])])
163+
}
164+
142165
targets += multiSourceLibraries.map { lib in
143166
return .target(
144167
name: lib.name,

benchmark/cmake/modules/AddSwiftBenchmarkSuite.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,12 @@ function (swift_benchmark_compile_archopts)
478478
list(APPEND SWIFT_BENCH_OBJFILES "${objfile}")
479479
list(APPEND bench_library_swiftmodules "${swiftmodule}")
480480

481+
# Only set "enable-cxx-interop" for tests in the "cxx-source" directory.
482+
set(cxx_options "")
483+
if ("${module_name_path}" MATCHES ".*cxx-source/.*")
484+
list(APPEND cxx_options "-Xfrontend" "-enable-cxx-interop" "-I" "${srcdir}/utils/CxxTests/")
485+
endif()
486+
481487
if ("${bench_flags}" MATCHES "-whole-module.*")
482488
set(output_option "-o" "${objfile}")
483489
else()
@@ -501,6 +507,7 @@ function (swift_benchmark_compile_archopts)
501507
"-module-name" "${module_name}"
502508
"-emit-module-path" "${swiftmodule}"
503509
"-I" "${objdir}"
510+
${cxx_options}
504511
${output_option}
505512
"${source}")
506513
if (SWIFT_BENCHMARK_EMIT_SIB)
@@ -518,6 +525,7 @@ function (swift_benchmark_compile_archopts)
518525
${SWIFT_BENCHMARK_EXTRA_FLAGS}
519526
"-module-name" "${module_name}"
520527
"-I" "${objdir}"
528+
${cxx_options}
521529
"-emit-sib"
522530
"-o" "${sibfile}"
523531
"${source}")
@@ -582,6 +590,8 @@ function (swift_benchmark_compile_archopts)
582590
"-whole-module-optimization"
583591
"-emit-module" "-module-name" "${module_name}"
584592
"-I" "${objdir}"
593+
"-Xfrontend" "-enable-cxx-interop"
594+
"-I" "${srcdir}/utils/CxxTests/"
585595
"-o" "${objdir}/${module_name}.o"
586596
"${source}")
587597
list(APPEND SWIFT_BENCH_OBJFILES "${objdir}/${module_name}.o")
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//===--- CreateObjects.swift ----------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 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 creates thousands of C++ objects and does nothing
14+
// with them.
15+
16+
import TestsUtils
17+
import CxxCreateObjects
18+
19+
public let CreateObjects = BenchmarkInfo(
20+
name: "CreateObjects",
21+
runFunction: run_CreateObjects,
22+
tags: [.validation, .bridging])
23+
24+
@inline(never)
25+
public func run_CreateObjects(_ N: Int) {
26+
for i in 0...(N * 10_000) {
27+
let x = Int32(i)
28+
let f = CxxLoadableIntWrapper(value: x)
29+
blackHole(f)
30+
}
31+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
struct CxxLoadableIntWrapper {
2+
int value;
3+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module CxxCreateObjects {
2+
header "CreateObjects.h"
3+
}

benchmark/utils/main.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import Chars
4848
import ClassArrayGetter
4949
import Codable
5050
import Combos
51+
import CreateObjects
5152
import DataBenchmarks
5253
import DeadArray
5354
import DevirtualizeProtocolComposition
@@ -236,6 +237,7 @@ registerBenchmark(Chars)
236237
registerBenchmark(Codable)
237238
registerBenchmark(Combos)
238239
registerBenchmark(ClassArrayGetter)
240+
registerBenchmark(CreateObjects)
239241
registerBenchmark(DataBenchmarks)
240242
registerBenchmark(DeadArray)
241243
registerBenchmark(DevirtualizeProtocolComposition)

include/swift/ABI/Task.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ class alignas(2 * alignof(void*)) Job {
127127
return Flags.isAsyncTask();
128128
}
129129

130+
JobPriority getPriority() const {
131+
return Flags.getPriority();
132+
}
133+
130134
/// Run this job.
131135
void run(ExecutorRef currentExecutor);
132136
};

include/swift/AST/DiagnosticsSema.def

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4213,9 +4213,10 @@ ERROR(actor_isolated_concurrent_access,none,
42134213
"actor-isolated %0 %1 is unsafe to reference in code "
42144214
"that may execute concurrently",
42154215
(DescriptiveDeclKind, DeclName))
4216-
NOTE(actor_isolated_method,none,
4217-
"only asynchronous methods can be used outside the actor instance; "
4218-
"do you want to add 'async'?", ())
4216+
NOTE(actor_isolated_sync_func,none,
4217+
"calls to %0 %1 from outside of its actor context are "
4218+
"implicitly asynchronous",
4219+
(DescriptiveDeclKind, DeclName))
42194220
NOTE(actor_mutable_state,none,
42204221
"mutable state is only available within the actor instance", ())
42214222
WARNING(shared_mutable_state_access,none,

include/swift/AST/Expr.h

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,10 @@ class alignas(8) Expr {
334334
NumCaptures : 32
335335
);
336336

337-
SWIFT_INLINE_BITFIELD(ApplyExpr, Expr, 1+1,
337+
SWIFT_INLINE_BITFIELD(ApplyExpr, Expr, 1+1+1,
338338
ThrowsIsSet : 1,
339-
Throws : 1
339+
Throws : 1,
340+
ImplicitlyAsync : 1
340341
);
341342

342343
SWIFT_INLINE_BITFIELD_FULL(CallExpr, ApplyExpr, 1+1+16,
@@ -4308,6 +4309,7 @@ class ApplyExpr : public Expr {
43084309
assert(classof((Expr*)this) && "ApplyExpr::classof out of date");
43094310
assert(validateArg(Arg) && "Arg is not a permitted expr kind");
43104311
Bits.ApplyExpr.ThrowsIsSet = false;
4312+
Bits.ApplyExpr.ImplicitlyAsync = false;
43114313
}
43124314

43134315
public:
@@ -4346,6 +4348,29 @@ class ApplyExpr : public Expr {
43464348
Bits.ApplyExpr.Throws = throws;
43474349
}
43484350

4351+
/// Is this application _implicitly_ required to be an async call?
4352+
/// Note that this is _not_ a check for whether the callee is async!
4353+
/// Only meaningful after complete type-checking.
4354+
///
4355+
/// Generally, this comes up only when we have a non-self call to an actor
4356+
/// instance's synchronous method. Such calls are conceptually treated as if
4357+
/// they are wrapped with an async closure. For example,
4358+
///
4359+
/// act.syncMethod(a, b)
4360+
///
4361+
/// is equivalent to the eta-expanded version of act.syncMethod,
4362+
///
4363+
/// { (a1, b1) async in act.syncMethod(a1, b1) }(a, b)
4364+
///
4365+
/// where the new closure is declared to be async.
4366+
///
4367+
bool implicitlyAsync() const {
4368+
return Bits.ApplyExpr.ImplicitlyAsync;
4369+
}
4370+
void setImplicitlyAsync(bool flag) {
4371+
Bits.ApplyExpr.ImplicitlyAsync = flag;
4372+
}
4373+
43494374
ValueDecl *getCalledValue() const;
43504375

43514376
/// Retrieve the argument labels provided at the call site.

include/swift/Basic/Fingerprint.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class Fingerprint final {
124124
///
125125
/// Very well, LLVM. A default value you shall have.
126126
friend class llvm::yaml::IO;
127-
Fingerprint() : Core{DIGEST_LENGTH, '0'} {}
127+
Fingerprint() : Core(DIGEST_LENGTH, '0') {}
128128
};
129129

130130
void simple_display(llvm::raw_ostream &out, const Fingerprint &fp);

include/swift/Runtime/Concurrency.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
173173
bool swift_task_removeStatusRecord(AsyncTask *task,
174174
TaskStatusRecord *record);
175175

176+
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
177+
JobFlags
178+
swift_task_getJobFlags(AsyncTask* task);
179+
176180
/// This should have the same representation as an enum like this:
177181
/// enum NearestTaskDeadline {
178182
/// case none

include/swift/SIL/SILInstruction.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7689,10 +7689,16 @@ class BranchInst final
76897689
unsigned getNumArgs() const { return getAllOperands().size(); }
76907690
SILValue getArg(unsigned i) const { return getAllOperands()[i].get(); }
76917691

7692+
/// Return the SILPhiArgument for the given operand.
7693+
const SILPhiArgument *getArgForOperand(const Operand *oper) const {
7694+
auto *self = const_cast<BranchInst *>(this);
7695+
return self->getArgForOperand(oper);
7696+
}
7697+
76927698
/// Return the SILPhiArgument for the given operand.
76937699
///
76947700
/// See SILArgument.cpp.
7695-
const SILPhiArgument *getArgForOperand(const Operand *oper) const;
7701+
SILPhiArgument *getArgForOperand(const Operand *oper);
76967702
};
76977703

76987704
/// A conditional branch.

lib/IRGen/GenConstant.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace irgen {
2727
/// Construct a ConstantInt from an IntegerLiteralInst.
2828
llvm::Constant *emitConstantInt(IRGenModule &IGM, IntegerLiteralInst *ILI);
2929

30-
/// Construct a zero from a zero intializer BuiltinInst.
30+
/// Construct a zero from a zero initializer BuiltinInst.
3131
llvm::Constant *emitConstantZero(IRGenModule &IGM, BuiltinInst *Bi);
3232

3333
/// Construct a ConstantFP from a FloatLiteralInst.

lib/IRGen/GenMeta.cpp

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4162,13 +4162,18 @@ namespace {
41624162
ConstantStructBuilder &B)
41634163
: super(IGM, theStruct, B) {}
41644164

4165+
Size getExtraDataSize(StructMetadataLayout &layout) {
4166+
auto extraSize = layout.getSize().getOffsetToEnd() -
4167+
IGM.getOffsetOfStructTypeSpecificMetadataMembers();
4168+
return extraSize;
4169+
}
4170+
41654171
llvm::Value *emitAllocateMetadata(IRGenFunction &IGF,
41664172
llvm::Value *descriptor,
41674173
llvm::Value *arguments,
41684174
llvm::Value *templatePointer) {
41694175
auto &layout = IGM.getMetadataLayout(Target);
4170-
auto extraSize = layout.getSize().getOffsetToEnd()
4171-
- IGM.getOffsetOfStructTypeSpecificMetadataMembers();
4176+
auto extraSize = getExtraDataSize(layout);
41724177
auto extraSizeV = IGM.getSize(extraSize);
41734178

41744179
// Sign the descriptor.
@@ -4236,6 +4241,7 @@ namespace {
42364241
PartialPattern buildExtraDataPattern() {
42374242
ConstantInitBuilder builder(IGM);
42384243
auto init = builder.beginStruct();
4244+
init.setPacked(true);
42394245

42404246
struct Scanner : StructMetadataScanner<Scanner> {
42414247
GenericStructMetadataBuilder &Outer;
@@ -4280,10 +4286,9 @@ namespace {
42804286
Offset zeroingEnd = offsetUpToTrailingFlags
42814287
? layout.getTrailingFlagsOffset()
42824288
: layout.getFieldOffsetVectorOffset();
4283-
return { global,
4284-
zeroingEnd.getStatic()
4285-
- zeroingStart,
4286-
structSize };
4289+
auto offset = zeroingEnd.getStatic() - zeroingStart;
4290+
assert((offset + structSize) == getExtraDataSize(layout));
4291+
return {global, offset, structSize};
42874292
}
42884293

42894294
bool hasCompletionFunction() {
@@ -4559,13 +4564,18 @@ namespace {
45594564
ConstantStructBuilder &B)
45604565
: super(IGM, theEnum, B) {}
45614566

4567+
Size getExtraDataSize(EnumMetadataLayout &layout) {
4568+
auto size = layout.getSize().getOffsetToEnd() -
4569+
IGM.getOffsetOfEnumTypeSpecificMetadataMembers();
4570+
return size;
4571+
}
4572+
45624573
llvm::Value *emitAllocateMetadata(IRGenFunction &IGF,
45634574
llvm::Value *descriptor,
45644575
llvm::Value *arguments,
45654576
llvm::Value *templatePointer) {
45664577
auto &layout = IGM.getMetadataLayout(Target);
4567-
auto extraSize = layout.getSize().getOffsetToEnd()
4568-
- IGM.getOffsetOfEnumTypeSpecificMetadataMembers();
4578+
auto extraSize = getExtraDataSize(layout);
45694579
auto extraSizeV = IGM.getSize(extraSize);
45704580

45714581
// Sign the descriptor.
@@ -4604,6 +4614,7 @@ namespace {
46044614
PartialPattern buildExtraDataPattern() {
46054615
ConstantInitBuilder builder(IGM);
46064616
auto init = builder.beginStruct();
4617+
init.setPacked(true);
46074618

46084619
auto &layout = IGM.getMetadataLayout(Target);
46094620

@@ -4625,10 +4636,9 @@ namespace {
46254636
Offset zeroingEnd = offsetUpToTrailingFlags
46264637
? layout.getTrailingFlagsOffset()
46274638
: layout.getPayloadSizeOffset();
4628-
return { global,
4629-
zeroingEnd.getStatic()
4630-
- zeroingStart,
4631-
structSize };
4639+
auto offset = zeroingEnd.getStatic() - zeroingStart;
4640+
assert((offset + structSize) == getExtraDataSize(layout));
4641+
return {global, offset, structSize};
46324642
}
46334643

46344644
llvm::Constant *emitNominalTypeDescriptor() {

lib/IRGen/IRGenFunction.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,6 @@ Address IRGenFunction::emitTaskAlloc(llvm::Value *size, Alignment alignment) {
495495
auto *call = Builder.CreateCall(IGM.getTaskAllocFn(), {getAsyncTask(), size});
496496
call->setDoesNotThrow();
497497
call->setCallingConv(IGM.SwiftCC);
498-
call->addAttribute(llvm::AttributeList::FunctionIndex,
499-
llvm::Attribute::ReadNone);
500498
auto address = Address(call, alignment);
501499
return address;
502500
}

lib/Parse/ParsePattern.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static ParserStatus parseDefaultArgument(
7070
SourceLoc equalLoc = P.consumeToken();
7171

7272
if (P.SF.Kind == SourceFileKind::Interface) {
73-
// Swift module interfaces don't synthesize inherited intializers and
73+
// Swift module interfaces don't synthesize inherited initializers and
7474
// instead include them explicitly in subclasses. Since the
7575
// \c DefaultArgumentKind of these initializers is \c Inherited, this is
7676
// represented textually as `= super` in the interface.

lib/SIL/IR/SILArgument.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ TermInst *SILPhiArgument::getSingleTerminator() const {
300300
return const_cast<SILBasicBlock *>(predBlock)->getTerminator();
301301
}
302302

303-
const SILPhiArgument *BranchInst::getArgForOperand(const Operand *oper) const {
303+
SILPhiArgument *BranchInst::getArgForOperand(const Operand *oper) {
304304
assert(oper->getUser() == this);
305305
return cast<SILPhiArgument>(
306306
getDestBB()->getArgument(oper->getOperandNumber()));

0 commit comments

Comments
 (0)