Skip to content

Commit 656a56c

Browse files
Merge pull request #4338 from swiftwasm/main
[pull] swiftwasm from main
2 parents b855062 + 0d4e041 commit 656a56c

File tree

65 files changed

+1223
-149
lines changed

Some content is hidden

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

65 files changed

+1223
-149
lines changed

benchmark/single-source/NSStringConversion.swift

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,21 @@ public let benchmarks = [
102102
BenchmarkInfo(name: "NSStringConversion.MutableCopy.Rebridge.LongUTF8",
103103
runFunction: run_NSStringConversion_longNonASCII_rebridgeMutable,
104104
tags: [.validation, .api, .String, .bridging],
105-
setUpFunction: { mutableTest = "Thë qüick bröwn föx jumps over the lazy dög" } )
105+
setUpFunction: { mutableTest = "Thë qüick bröwn föx jumps over the lazy dög" } ),
106+
BenchmarkInfo(name: "NSStringConversion.InlineBuffer.UTF8",
107+
runFunction: run_NSStringConversion_inlineBuffer,
108+
tags: [.validation, .api, .String, .bridging],
109+
setUpFunction: {
110+
mutableTest = Array(repeating: "제10회 유니코드 국제 회의가 1997년 3월 10일부터 12일까지 독일의 마인즈에서 열립니다. 지금 등록하십시오. 이 회의에서는 업계 전반의 전문가들이 함께 모여 다음과 같은 분야를 다룹니다. - 인터넷과 유니코드, 국제화와 지역화, 운영 체제와 응용 프로그램에서 유니코드의 구현, 글꼴, 문자 배열, 다국어 컴퓨팅.세계를 향한 대화, 유니코드로 하십시오. 제10회 유니코드 국제 회의가 1997년 3월 10일부터 12일까지 독일의 마인즈에서 열립니다. 지금 등록하십시오. 이 회의에서는 업계 전반의 전문가들이 함께 모여 다음과 같은 분야를 다룹니다. 세계를 향한 대화, 유니코드로 하십시오.", count: 256).joined(separator: "")
111+
}
112+
),
113+
BenchmarkInfo(name: "NSStringConversion.InlineBuffer.ASCII",
114+
runFunction: run_NSStringConversion_inlineBuffer,
115+
tags: [.validation, .api, .String, .bridging],
116+
setUpFunction: {
117+
mutableTest = Array(repeating: "The 10th Unicode International Conference will be held from March 10 to 12, 1997 in Mainz, Germany. Register now. The conference brings together experts from across the industry, covering areas such as: - Internet and Unicode, internationalization and localization, implementation of Unicode in operating systems and applications, fonts, character arrays, multilingual computing. Dialogue to the world, do Unicode. The 10th Unicode International Conference will be held from March 10 to 12, 1997 in Mainz, Germany. Register now. The conference brings together experts from across the industry, covering areas such as: Dialogue to the world, do it in Unicode.", count: 256).joined(separator: "")
118+
}
119+
)
106120
]
107121

108122
public func run_NSStringConversion(_ n: Int) {
@@ -227,4 +241,24 @@ public func run_NSStringConversion_longNonASCII_rebridgeMutable(_ n: Int) {
227241
innerMutableRebridge(mutableTest, n, 300)
228242
}
229243

244+
public func run_NSStringConversion_inlineBuffer(_ n: Int) {
245+
withUnsafeTemporaryAllocation(
246+
of: CFStringInlineBuffer.self,
247+
capacity: 1
248+
) { bufferPtr in
249+
let buffer = bufferPtr.baseAddress!
250+
for _ in 0 ..< n {
251+
var result = UInt64(0)
252+
let bridged = mutableTest as NSString as CFString
253+
let len = CFStringGetLength(bridged)
254+
CFStringInitInlineBuffer(bridged, buffer, CFRangeMake(0, len))
255+
for i in 0 ..< CFStringGetLength(bridged) {
256+
let char = CFStringGetCharacterFromInlineBuffer(buffer, i)
257+
result += UInt64(char)
258+
}
259+
blackHole(result)
260+
}
261+
}
262+
}
263+
230264
#endif

include/swift/AST/ActorIsolation.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,19 @@ class ActorIsolation {
109109

110110
bool isIndependent() const { return kind == Independent; }
111111

112+
bool isActorIsolated() const {
113+
switch (getKind()) {
114+
case ActorInstance:
115+
case GlobalActor:
116+
case GlobalActorUnsafe:
117+
return true;
118+
119+
case Unspecified:
120+
case Independent:
121+
return false;
122+
}
123+
}
124+
112125
NominalTypeDecl *getActor() const {
113126
assert(getKind() == ActorInstance);
114127
return actor;

include/swift/AST/DiagnosticsSema.def

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6112,6 +6112,15 @@ WARNING(result_builder_missing_limited_availability, none,
61126112
ERROR(result_builder_static_buildblock, none,
61136113
"result builder must provide at least one static 'buildBlock' "
61146114
"method", ())
6115+
ERROR(result_builder_static_buildblock_or_buildpartialblock, none,
6116+
"result builder must provide at least one static 'buildBlock' "
6117+
"method, or both 'buildPartialBlock(first:)' and "
6118+
"'buildPartialBlock(accumulated:next:)'", ())
6119+
ERROR(result_builder_missing_available_buildpartialblock, none,
6120+
"result builder %0 does not implement any 'buildBlock' or a combination "
6121+
"of 'buildPartialBlock(first:)' and "
6122+
"'buildPartialBlock(accumulated:next:)' with sufficient availability for "
6123+
"this call site", (Type))
61156124
NOTE(result_builder_non_static_buildblock, none,
61166125
"did you mean to make instance method 'buildBlock' static?", ())
61176126
NOTE(result_builder_buildblock_enum_case, none,

include/swift/AST/KnownIdentifiers.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ IDENTIFIER(allKeys)
2828
IDENTIFIER(alloc)
2929
IDENTIFIER(allocWithZone)
3030
IDENTIFIER(allZeros)
31+
IDENTIFIER(accumulated)
3132
IDENTIFIER(ActorType)
3233
IDENTIFIER(Any)
3334
IDENTIFIER(ArrayLiteralElement)
@@ -41,6 +42,7 @@ IDENTIFIER(buildFinalResult)
4142
IDENTIFIER(buildIf)
4243
IDENTIFIER(buildLimitedAvailability)
4344
IDENTIFIER(buildOptional)
45+
IDENTIFIER(buildPartialBlock)
4446
IDENTIFIER(callAsFunction)
4547
IDENTIFIER(Change)
4648
IDENTIFIER_WITH_NAME(code_, "_code")

include/swift/Basic/Features.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,7 @@ SUPPRESSIBLE_LANGUAGE_FEATURE(SpecializeAttributeWithAvailability, 0, "@_special
7575
LANGUAGE_FEATURE(BuiltinAssumeAlignment, 0, "Builtin.assumeAlignment", true)
7676
SUPPRESSIBLE_LANGUAGE_FEATURE(UnsafeInheritExecutor, 0, "@_unsafeInheritExecutor", true)
7777
SUPPRESSIBLE_LANGUAGE_FEATURE(PrimaryAssociatedTypes, 0, "Primary associated types", true)
78+
SUPPRESSIBLE_LANGUAGE_FEATURE(UnavailableFromAsync, 0, "@_unavailableFromAsync", true)
79+
7880
#undef SUPPRESSIBLE_LANGUAGE_FEATURE
7981
#undef LANGUAGE_FEATURE

lib/AST/ASTPrinter.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3002,6 +3002,19 @@ static void suppressingFeaturePrimaryAssociatedTypes(PrintOptions &options,
30023002
options.PrintPrimaryAssociatedTypes = originalPrintPrimaryAssociatedTypes;
30033003
}
30043004

3005+
static bool usesFeatureUnavailableFromAsync(Decl *decl) {
3006+
return decl->getAttrs().hasAttribute<UnavailableFromAsyncAttr>();
3007+
}
3008+
3009+
static void
3010+
suppressingFeatureUnavailableFromAsync(PrintOptions &options,
3011+
llvm::function_ref<void()> action) {
3012+
unsigned originalExcludeAttrCount = options.ExcludeAttrList.size();
3013+
options.ExcludeAttrList.push_back(DAK_UnavailableFromAsync);
3014+
action();
3015+
options.ExcludeAttrList.resize(originalExcludeAttrCount);
3016+
}
3017+
30053018
/// Suppress the printing of a particular feature.
30063019
static void suppressingFeature(PrintOptions &options, Feature feature,
30073020
llvm::function_ref<void()> action) {

lib/ClangImporter/ImportType.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,12 @@ namespace {
546546
return importFunctionPointerLikeType(*type, pointeeType);
547547
}
548548

549+
// Currently, we can't generate thunks for references to dependent types
550+
// because there's no way to cast without a copy (without writing the SIL
551+
// manually).
552+
if (pointeeQualType->isDependentType())
553+
return Type();
554+
549555
if (Impl.isOverAligned(pointeeQualType)) {
550556
return importOverAlignedFunctionPointerLikeType(*type, Impl);
551557
}
@@ -1857,6 +1863,17 @@ ImportedType ClangImporter::Implementation::importFunctionParamsAndReturnType(
18571863
dyn_cast<clang::TemplateTypeParmType>(clangDecl->getReturnType())) {
18581864
importedType = {findGenericTypeInGenericDecls(templateType, genericParams),
18591865
false};
1866+
} else if ((isa<clang::PointerType>(clangDecl->getReturnType()) ||
1867+
isa<clang::ReferenceType>(clangDecl->getReturnType())) &&
1868+
isa<clang::TemplateTypeParmType>(clangDecl->getReturnType()->getPointeeType())) {
1869+
auto pointeeType = clangDecl->getReturnType()->getPointeeType();
1870+
auto templateParamType = cast<clang::TemplateTypeParmType>(pointeeType);
1871+
PointerTypeKind pointerKind = pointeeType.getQualifiers().hasConst()
1872+
? PTK_UnsafePointer
1873+
: PTK_UnsafeMutablePointer;
1874+
auto genericType =
1875+
findGenericTypeInGenericDecls(templateParamType, genericParams);
1876+
importedType = {genericType->wrapInPointer(pointerKind), false};
18601877
} else if (!(isa<clang::RecordType>(clangDecl->getReturnType()) ||
18611878
isa<clang::TemplateSpecializationType>(clangDecl->getReturnType())) ||
18621879
// TODO: we currently don't lazily load operator return types, but

lib/FrontendTool/TBD.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,27 @@ bool swift::writeTBD(ModuleDecl *M, StringRef OutputFilename,
5656
return false;
5757
}
5858

59+
/// Determine if a symbol name is ignored when validating the TBD's contents
60+
/// against the IR's.
61+
///
62+
/// \param name The name of the symbol in question.
63+
/// \param IRModule The module being validated.
64+
///
65+
/// \returns Whether or not the presence or absence of the symbol named \a name
66+
/// should be ignored (instead of potentially producing a diagnostic.)
67+
static bool isSymbolIgnored(const StringRef& name,
68+
const llvm::Module &IRModule) {
69+
if (llvm::Triple(IRModule.getTargetTriple()).isOSWindows()) {
70+
// (SR-15938) Error when referencing #dsohandle in a Swift test on Windows
71+
// On Windows, ignore the lack of __ImageBase in the TBD file.
72+
if (name == "__ImageBase") {
73+
return true;
74+
}
75+
}
76+
77+
return false;
78+
}
79+
5980
static bool validateSymbols(DiagnosticEngine &diags,
6081
const std::vector<std::string> &symbols,
6182
const llvm::Module &IRModule,
@@ -77,6 +98,11 @@ static bool validateSymbols(DiagnosticEngine &diags,
7798
// with what TBDGen created.
7899
auto unmangledName = nameValue.getKey();
79100

101+
if (isSymbolIgnored(unmangledName, IRModule)) {
102+
// This symbol should not affect validation. Skip it.
103+
continue;
104+
}
105+
80106
SmallString<128> name;
81107
llvm::Mangler::getNameWithPrefix(name, unmangledName,
82108
IRModule.getDataLayout());

lib/IDE/CodeCompletion.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks {
283283
static void addSelectorModifierKeywords(CodeCompletionResultSink &sink) {
284284
auto addKeyword = [&](StringRef Name, CodeCompletionKeywordKind Kind) {
285285
CodeCompletionResultBuilder Builder(sink, CodeCompletionResultKind::Keyword,
286-
SemanticContextKind::None, {});
286+
SemanticContextKind::None);
287287
Builder.setKeywordKind(Kind);
288288
Builder.addTextChunk(Name);
289289
Builder.addCallParameterColon();
@@ -646,7 +646,7 @@ static void addKeyword(CodeCompletionResultSink &Sink, StringRef Name,
646646
StringRef TypeAnnotation = "",
647647
CodeCompletionFlair Flair = {}) {
648648
CodeCompletionResultBuilder Builder(Sink, CodeCompletionResultKind::Keyword,
649-
SemanticContextKind::None, {});
649+
SemanticContextKind::None);
650650
Builder.setKeywordKind(Kind);
651651
Builder.addKeyword(Name);
652652
Builder.addFlair(Flair);
@@ -868,7 +868,7 @@ static void addSuperKeyword(CodeCompletionResultSink &Sink, DeclContext *DC) {
868868
return;
869869

870870
CodeCompletionResultBuilder Builder(Sink, CodeCompletionResultKind::Keyword,
871-
SemanticContextKind::CurrentNominal, {});
871+
SemanticContextKind::CurrentNominal);
872872
if (auto *AFD = dyn_cast<AbstractFunctionDecl>(DC)) {
873873
if (AFD->getOverriddenDecl() != nullptr) {
874874
Builder.addFlair(CodeCompletionFlairBit::CommonKeywordAtCurrentPosition);
@@ -886,7 +886,7 @@ static void addOpaqueTypeKeyword(CodeCompletionResultSink &Sink) {
886886

887887
static void addAnyTypeKeyword(CodeCompletionResultSink &Sink, Type T) {
888888
CodeCompletionResultBuilder Builder(Sink, CodeCompletionResultKind::Keyword,
889-
SemanticContextKind::None, {});
889+
SemanticContextKind::None);
890890
Builder.setKeywordKind(CodeCompletionKeywordKind::None);
891891
Builder.addKeyword("Any");
892892
Builder.addTypeAnnotation(T, PrintOptions());
@@ -1040,7 +1040,7 @@ static void addPoundDirectives(CodeCompletionResultSink &Sink) {
10401040
nullptr) {
10411041
CodeCompletionResultBuilder Builder(Sink,
10421042
CodeCompletionResultKind::Keyword,
1043-
SemanticContextKind::None, {});
1043+
SemanticContextKind::None);
10441044
Builder.addBaseName(name);
10451045
Builder.setKeywordKind(K);
10461046
if (consumer)
@@ -1100,7 +1100,7 @@ static void addPlatformConditions(CodeCompletionResultSink &Sink) {
11001100
Sink, CodeCompletionResultKind::Pattern,
11011101
// FIXME: SemanticContextKind::CurrentModule is not correct.
11021102
// Use 'None' (and fix prioritization) or introduce a new context.
1103-
SemanticContextKind::CurrentModule, {});
1103+
SemanticContextKind::CurrentModule);
11041104
Builder.addFlair(CodeCompletionFlairBit::ExpressionSpecific);
11051105
Builder.addBaseName(Name);
11061106
Builder.addLeftParen();
@@ -1150,7 +1150,7 @@ static void addConditionalCompilationFlags(ASTContext &Ctx,
11501150
Sink, CodeCompletionResultKind::Keyword,
11511151
// FIXME: SemanticContextKind::CurrentModule is not correct.
11521152
// Use 'None' (and fix prioritization) or introduce a new context.
1153-
SemanticContextKind::CurrentModule, {});
1153+
SemanticContextKind::CurrentModule);
11541154
Builder.addFlair(CodeCompletionFlairBit::ExpressionSpecific);
11551155
Builder.addTextChunk(Flag);
11561156
}

lib/IDE/CodeCompletionResultBuilder.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ class CodeCompletionResultBuilder {
4949
SmallVector<CodeCompletionString::Chunk, 4> Chunks;
5050
llvm::PointerUnion<const ModuleDecl *, const clang::Module *>
5151
CurrentModule;
52-
ExpectedTypeContext declTypeContext;
5352
bool Cancelled = false;
5453
ContextFreeNotRecommendedReason ContextFreeNotRecReason =
5554
ContextFreeNotRecommendedReason::None;
@@ -90,10 +89,8 @@ class CodeCompletionResultBuilder {
9089
public:
9190
CodeCompletionResultBuilder(CodeCompletionResultSink &Sink,
9291
CodeCompletionResultKind Kind,
93-
SemanticContextKind SemanticContext,
94-
const ExpectedTypeContext &declTypeContext)
95-
: Sink(Sink), Kind(Kind), SemanticContext(SemanticContext),
96-
declTypeContext(declTypeContext) {}
92+
SemanticContextKind SemanticContext)
93+
: Sink(Sink), Kind(Kind), SemanticContext(SemanticContext) {}
9794

9895
~CodeCompletionResultBuilder() {
9996
finishResult();

0 commit comments

Comments
 (0)