Skip to content

Commit 1f7fb77

Browse files
Merge pull request #5220 from swiftwasm/main
[pull] swiftwasm from main
2 parents 4251e81 + a06e4d4 commit 1f7fb77

File tree

95 files changed

+1571
-281
lines changed

Some content is hidden

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

95 files changed

+1571
-281
lines changed

benchmark/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ set(SWIFT_BENCH_MODULES
201201
single-source/WordCount
202202
single-source/XorLoop
203203
cxx-source/CreateObjects
204+
cxx-source/CxxSetToCollection
204205
cxx-source/CxxVectorSum
205206
cxx-source/ReadAccessor
206207
)
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//===--- CxxSetToCollection.swift -----------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2012 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 benchmark that tracks how quickly Swift can convert a C++ set
14+
// to a Swift collection.
15+
16+
import TestsUtils
17+
18+
#if SWIFT_PACKAGE
19+
// FIXME: Needs fix for https://github.com/apple/swift/issues/61547.
20+
21+
public let benchmarks = [BenchmarkInfo]()
22+
23+
#else
24+
25+
import CxxStdlibPerformance
26+
import Cxx
27+
28+
public let benchmarks = [
29+
BenchmarkInfo(
30+
name: "CxxSetU32.to.Array",
31+
runFunction: run_CxxSetOfU32_to_Array,
32+
tags: [.validation, .bridging, .cxxInterop],
33+
setUpFunction: makeSetOnce),
34+
BenchmarkInfo(
35+
name: "CxxSetU32.to.Set",
36+
runFunction: run_CxxSetOfU32_to_Set,
37+
tags: [.validation, .bridging, .cxxInterop],
38+
setUpFunction: makeSetOnce),
39+
]
40+
41+
func makeSetOnce() {
42+
initSet(setSize)
43+
}
44+
45+
let setSize = 1_000
46+
47+
@inline(never)
48+
public func run_CxxSetOfU32_to_Array(_ n: Int) {
49+
for _ in 0..<n {
50+
blackHole(Array(set))
51+
}
52+
}
53+
54+
@inline(never)
55+
public func run_CxxSetOfU32_to_Set(_ n: Int) {
56+
for _ in 0..<n {
57+
blackHole(Set(set))
58+
}
59+
}
60+
61+
#endif

benchmark/scripts/Benchmark_Driver

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -627,16 +627,26 @@ class BenchmarkDoctor(object):
627627
@staticmethod
628628
def _constant_memory_use(measurements):
629629
select = BenchmarkDoctor._select
630+
name = measurements["name"]
631+
632+
memory_uses = [
633+
[r.mem_pages for r in i_series if r.mem_pages is not None]
634+
for i_series in [select(measurements, num_iters=i) for i in [1, 2]]
635+
]
636+
memory_uses = [m for m in memory_uses if m]
637+
if not memory_uses:
638+
BenchmarkDoctor.log_memory.info(
639+
"unable to compute memory footprint of '%s'",
640+
name,
641+
)
642+
return
643+
630644
(min_i1, max_i1), (min_i2, max_i2) = [
631645
(min(memory_use), max(memory_use))
632-
for memory_use in [
633-
[r.mem_pages for r in i_series]
634-
for i_series in [select(measurements, num_iters=i) for i in [1, 2]]
635-
]
646+
for memory_use in memory_uses
636647
]
637648
range_i1, range_i2 = max_i1 - min_i1, max_i2 - min_i2
638649
normal_range = 15 # pages
639-
name = measurements["name"]
640650
more_info = False
641651

642652
if abs(min_i1 - min_i2) > max(range_i1, range_i2, normal_range):

benchmark/utils/CxxTests/CxxStdlibPerformance.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
#include <cstdint>
44
#include <vector>
5+
#include <set>
56

67
using VectorOfU32 = std::vector<uint32_t>;
8+
using SetOfU32 = std::set<uint32_t>;
79

810
static inline VectorOfU32 vec;
11+
static inline SetOfU32 set;
912

1013
inline void initVector(size_t size) {
1114
if (!vec.empty()) {
@@ -17,11 +20,25 @@ inline void initVector(size_t size) {
1720
}
1821
}
1922

23+
inline void initSet(size_t size) {
24+
if (!set.empty()) {
25+
return;
26+
}
27+
for (size_t i = 0; i < size; ++i) {
28+
set.insert(uint32_t(i));
29+
}
30+
}
31+
2032
inline VectorOfU32 makeVector32(size_t size) {
2133
initVector(size);
2234
return vec;
2335
}
2436

37+
inline SetOfU32 makeSet32(size_t size) {
38+
initSet(size);
39+
return set;
40+
}
41+
2542
inline uint32_t testVector32Sum(size_t vectorSize, size_t iters) {
2643
auto vector = makeVector32(vectorSize);
2744
auto sum = uint32_t(0);

benchmark/utils/main.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import ClassArrayGetter
5151
import CodableTest
5252
import Combos
5353
import CreateObjects
54+
import CxxSetToCollection
5455
import CxxVectorSum
5556
import DataBenchmarks
5657
import DeadArray
@@ -237,6 +238,7 @@ register(CodableTest.benchmarks)
237238
register(Combos.benchmarks)
238239
register(ClassArrayGetter.benchmarks)
239240
register(CreateObjects.benchmarks)
241+
register(CxxSetToCollection.benchmarks)
240242
register(CxxVectorSum.benchmarks)
241243
register(DataBenchmarks.benchmarks)
242244
register(DeadArray.benchmarks)

docs/SIL.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6022,7 +6022,7 @@ an `inject_enum_addr`_ instruction::
60226022
entry(%0 : $*AddressOnlyEnum, %1 : $*AddressOnlyType):
60236023
// Store the data argument for the case.
60246024
%2 = init_enum_data_addr %0 : $*AddressOnlyEnum, #AddressOnlyEnum.HasData!enumelt
6025-
copy_addr [take] %2 to [init] %1 : $*AddressOnlyType
6025+
copy_addr [take] %1 to [init] %2 : $*AddressOnlyType
60266026
// Inject the tag.
60276027
inject_enum_addr %0 : $*AddressOnlyEnum, #AddressOnlyEnum.HasData!enumelt
60286028
return

include/swift-c/DependencyScan/DependencyScan.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,9 @@ swiftscan_compiler_supported_features_query();
303303
//=== Target-Info Functions -----------------------------------------------===//
304304
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
305305
swiftscan_compiler_target_info_query(swiftscan_scan_invocation_t invocation);
306+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
307+
swiftscan_compiler_target_info_query_v2(swiftscan_scan_invocation_t invocation,
308+
const char *main_executable_path);
306309

307310
//=== Scanner Functions ---------------------------------------------------===//
308311

include/swift/AST/DiagnosticsSema.def

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3351,6 +3351,14 @@ ERROR(attr_incompatible_with_non_final,none,
33513351
"'%0' cannot be applied to a non-final %1",
33523352
(DeclAttribute, DescriptiveDeclKind))
33533353

3354+
ERROR(attr_incompatible_with_override,none,
3355+
"'%0' cannot be combined with 'override'",
3356+
(DeclAttribute))
3357+
3358+
ERROR(attr_incompatible_with_objc,none,
3359+
"'%0' must not be used on an '@objc' %1",
3360+
(DeclAttribute, DescriptiveDeclKind))
3361+
33543362
ERROR(final_not_on_accessors,none,
33553363
"'final' cannot be applied to accessors, it must be put on the "
33563364
"%select{var|let|subscript}0", (unsigned))
@@ -6696,7 +6704,7 @@ ERROR(concurrency_task_to_thread_model_global_actor_annotation,none,
66966704
(TypeRepr*, StringRef))
66976705

66986706
ERROR(moveOnly_not_allowed_here,none,
6699-
"'moveOnly' may only be applied to classes, structs, and enums", ())
6707+
"'moveOnly' only applies to structs or enums", ())
67006708
ERROR(move_expression_not_passed_lvalue,none,
67016709
"'move' can only be applied to lvalues", ())
67026710
ERROR(borrow_expression_not_passed_lvalue,none,

include/swift/AST/MacroDeclaration.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ bool macroIntroducedNameRequiresArgument(MacroIntroducedDeclNameKind kind);
6666
StringRef getMacroIntroducedDeclNameString(
6767
MacroIntroducedDeclNameKind kind);
6868

69+
class CustomAttr;
70+
71+
/// Perform lookup to determine whether the given custom attribute refers to
72+
/// a macro declaration, and populate the \c macros vector with the lookup
73+
/// results that are attached macros.
74+
void findMacroForCustomAttr(CustomAttr *attr, DeclContext *dc,
75+
llvm::TinyPtrVector<ValueDecl *> &macros);
76+
6977
class MacroIntroducedDeclName {
7078
public:
7179
using Kind = MacroIntroducedDeclNameKind;

include/swift/AST/PrintOptions.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,16 @@ struct PrintOptions {
533533
/// parameter.
534534
bool PrintSpecializeAttributeWithAvailability = true;
535535

536+
/// Whether to always desugar array types from `[base_type]` to `Array<base_type>`
537+
bool AlwaysDesugarArraySliceTypes = false;
538+
539+
/// Whether to always desugar dictionary types
540+
/// from `[key_type:value_type]` to `Dictionary<key_type,value_type>`
541+
bool AlwaysDesugarDictionaryTypes = false;
542+
543+
/// Whether to always desugar optional types from `base_type?` to `Optional<base_type>`
544+
bool AlwaysDesugarOptionalTypes = false;
545+
536546
/// \see ShouldQualifyNestedDeclarations
537547
enum class QualifyNestedDeclarations {
538548
Never,

include/swift/AST/TypeCheckRequests.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3128,6 +3128,24 @@ class CheckRedeclarationRequest
31283128
evaluator::SideEffect) const;
31293129
};
31303130

3131+
/// Resolve a given custom attribute to an attached macro declaration.
3132+
class ResolveAttachedMacroRequest
3133+
: public SimpleRequest<ResolveAttachedMacroRequest,
3134+
MacroDecl *(CustomAttr *, DeclContext *),
3135+
RequestFlags::Cached> {
3136+
public:
3137+
using SimpleRequest::SimpleRequest;
3138+
3139+
private:
3140+
friend SimpleRequest;
3141+
3142+
MacroDecl *
3143+
evaluate(Evaluator &evaluator, CustomAttr *attr, DeclContext *dc) const;
3144+
3145+
public:
3146+
bool isCached() const { return true; }
3147+
};
3148+
31313149
class ResolveTypeEraserTypeRequest
31323150
: public SimpleRequest<ResolveTypeEraserTypeRequest,
31333151
Type (ProtocolDecl *, TypeEraserAttr *),

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,9 @@ SWIFT_REQUEST(TypeChecker, PreCheckResultBuilderRequest,
340340
SWIFT_REQUEST(TypeChecker, ResolveImplicitMemberRequest,
341341
evaluator::SideEffect(NominalTypeDecl *, ImplicitMemberAction),
342342
Uncached, NoLocationInfo)
343+
SWIFT_REQUEST(TypeChecker, ResolveAttachedMacroRequest,
344+
MacroDecl *(CustomAttr *, DeclContext *),
345+
Cached, NoLocationInfo)
343346
SWIFT_REQUEST(TypeChecker, ResolveTypeEraserTypeRequest,
344347
Type(ProtocolDecl *, TypeEraserAttr *),
345348
SeparatelyCached, NoLocationInfo)

include/swift/Basic/DiagnosticOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class DiagnosticOptions {
3232
VerifyAndApplyFixes
3333
} VerifyMode = NoVerify;
3434

35-
enum FormattingStyle { LLVM, Swift };
35+
enum FormattingStyle { LLVM, Swift, SwiftSyntax };
3636

3737
/// Indicates whether to allow diagnostics for \c <unknown> locations if
3838
/// \c VerifyMode is not \c NoVerify.

include/swift/Basic/Features.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ EXPERIMENTAL_FEATURE(VariadicGenerics, false)
103103
EXPERIMENTAL_FEATURE(NamedOpaqueTypes, false)
104104
EXPERIMENTAL_FEATURE(FlowSensitiveConcurrencyCaptures, false)
105105
EXPERIMENTAL_FEATURE(MoveOnly, false)
106+
EXPERIMENTAL_FEATURE(MoveOnlyClasses, false)
106107
EXPERIMENTAL_FEATURE(OneWayClosureParameters, false)
107108
EXPERIMENTAL_FEATURE(TypeWitnessSystemInference, false)
108109
EXPERIMENTAL_FEATURE(LayoutPrespecialization, false)

include/swift/Basic/LangOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ namespace swift {
366366

367367
/// Enable early skipping deserialization of decls that are marked as
368368
/// unsafe to read.
369-
bool EnableDeserializationSafety = false;
369+
bool EnableDeserializationSafety = true;
370370

371371
/// Whether to enable the new operator decl and precedencegroup lookup
372372
/// behavior. This is a staging flag, and will be removed in the future.

include/swift/DependencyScan/DependencyScanningTool.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ class DependencyScannerDiagnosticCollectingConsumer : public DiagnosticConsumer
4848

4949
/// Given a set of arguments to a print-target-info frontend tool query, produce the
5050
/// JSON target info.
51-
llvm::ErrorOr<swiftscan_string_ref_t> getTargetInfo(ArrayRef<const char *> Command);
51+
llvm::ErrorOr<swiftscan_string_ref_t> getTargetInfo(ArrayRef<const char *> Command,
52+
const char *main_executable_path);
5253

5354
/// The high-level implementation of the dependency scanner that runs on
5455
/// an individual worker thread.

include/swift/Frontend/PrintingDiagnosticConsumer.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ class PrintingDiagnosticConsumer : public DiagnosticConsumer {
4545
SmallVector<std::string, 1> BufferedEducationalNotes;
4646
bool SuppressOutput = false;
4747

48+
/// swift-syntax rendering
49+
void *queuedDiagnostics = nullptr;
50+
void *queuedSourceFile = nullptr;
51+
unsigned queuedDiagnosticsBufferID;
52+
StringRef queuedBufferName;
53+
4854
public:
4955
PrintingDiagnosticConsumer(llvm::raw_ostream &stream = llvm::errs());
5056
~PrintingDiagnosticConsumer();

0 commit comments

Comments
 (0)