Skip to content

Commit 11c046f

Browse files
Merge pull request #5411 from swiftwasm/main
[pull] swiftwasm from main
2 parents 325598f + 08c4646 commit 11c046f

File tree

172 files changed

+3072
-1249
lines changed

Some content is hidden

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

172 files changed

+3072
-1249
lines changed

Diff for: docs/ABI/Mangling.rst

+2
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ are always non-polymorphic ``<impl-function-type>`` types.
301301
VALUE-WITNESS-KIND ::= 'ug' // getEnumTag
302302
VALUE-WITNESS-KIND ::= 'up' // destructiveProjectEnumData
303303
VALUE-WITNESS-KIND ::= 'ui' // destructiveInjectEnumTag
304+
VALUE-WITNESS-KIND ::= 'et' // getEnumTagSinglePayload
305+
VALUE-WITNESS-KIND ::= 'st' // storeEnumTagSinglePayload
304306

305307
``<VALUE-WITNESS-KIND>`` differentiates the kinds of value
306308
witness functions for a type.

Diff for: docs/HowToGuides/GettingStarted.md

+15-6
Original file line numberDiff line numberDiff line change
@@ -463,25 +463,34 @@ Now that you have made some changes, you will need to rebuild...
463463
464464
### Incremental builds with Ninja
465465
466-
To rebuild the compiler:
466+
Subsequent steps in this and the next subsections are specific to the platform you're building on, so we'll try to detect it first and reuse as a shell variable:
467+
467468
```sh
468-
ninja -C ../build/Ninja-RelWithDebInfoAssert/swift-macosx-$(uname -m) bin/swift-frontend
469+
platform=$([[ $(uname) == Darwin ]] && echo macosx || echo linux)
469470
```
470471
471-
To rebuild everything, including the standard library:
472+
After setting that variable you can rebuild the compiler incrementally with this command:
472473
```sh
473-
ninja -C ../build/Ninja-RelWithDebInfoAssert/swift-macosx-$(uname -m)
474+
ninja -C ../build/Ninja-RelWithDebInfoAssert/swift-$(platform)-$(uname -m) bin/swift-frontend
474475
```
475476
477+
To rebuild everything that has its sources located in the `swift` repository, including the standard library:
478+
```sh
479+
ninja -C ../build/Ninja-RelWithDebInfoAssert/swift-$(platform)-$(uname -m)
480+
```
481+
482+
Similarly, you can rebuild other projects like Foundation or Dispatch by substituting their respective subdirectories in the commands above.
483+
476484
### Spot checking an incremental build
477485
478486
As a quick test, go to `lib/Basic/Version.cpp` and tweak the version
479487
printing code slightly. Next, do an incremental build as above. This incremental
480488
build should be much faster than the from-scratch build at the beginning.
481-
Now check if the version string has been updated:
489+
Now check if the version string has been updated (assumes you have `platform` shell variable
490+
defined as specified in the previous subsection:
482491
483492
```sh
484-
../build/Ninja-RelWithDebInfoAssert/swift-macosx-$(uname -m)/bin/swift-frontend --version
493+
../build/Ninja-RelWithDebInfoAssert/swift-$(platform)-$(uname -m)/bin/swift-frontend --version
485494
```
486495
487496
This should print your updated version string.

Diff for: include/swift/AST/CASTBridging.h

+3
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,9 @@ void Plugin_setCapability(PluginHandle handle, PluginCapabilityPtr data);
313313
/// Get a capability data set by \c Plugin_setCapability .
314314
PluginCapabilityPtr _Nullable Plugin_getCapability(PluginHandle handle);
315315

316+
/// Get the executable file path of the plugin.
317+
const char *Plugin_getExecutableFilePath(PluginHandle handle);
318+
316319
/// Lock the plugin. Clients should lock it during sending and recving the
317320
/// response.
318321
void Plugin_lock(PluginHandle handle);

Diff for: include/swift/AST/DiagnosticsSIL.def

+12
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,18 @@ ERROR(noimplicitcopy_used_on_generic_or_existential, none,
735735
"@_noImplicitCopy can not be used on a generic or existential typed "
736736
"binding or a nominal type containing such typed things", ())
737737

738+
// forget statement
739+
ERROR(forget_nontrivial_storage,none,
740+
"can only 'forget' type %0 if it contains trivially-destroyed "
741+
"stored properties at this time",
742+
(Type))
743+
NOTE(forget_nontrivial_storage_note,none,
744+
"type %0 cannot be trivially destroyed",
745+
(Type))
746+
NOTE(forget_nontrivial_implicit_storage_note,none,
747+
"type %0 implicitly contains %1 which cannot be trivially destroyed",
748+
(Type, Type))
749+
738750
// move only checker diagnostics
739751
ERROR(sil_moveonlychecker_owned_value_consumed_more_than_once, none,
740752
"'%0' consumed more than once", (StringRef))

Diff for: include/swift/AST/DiagnosticsSema.def

+17
Original file line numberDiff line numberDiff line change
@@ -1694,6 +1694,14 @@ ERROR(expose_enum_case_type_to_cxx,none,
16941694
"enum %0 can not be represented in C++ as one of its cases has an associated value with type that can't be represented in C++", (ValueDecl *))
16951695
ERROR(expose_enum_case_tuple_to_cxx,none,
16961696
"enum %0 can not yet be represented in C++ as one of its cases has multiple associated values", (ValueDecl *))
1697+
ERROR(expose_protocol_to_cxx_unsupported,none,
1698+
"protocol %0 can not yet be represented in C++", (ValueDecl *))
1699+
ERROR(expose_move_only_to_cxx,none,
1700+
"move-only %0 %1 can not yet be represented in C++", (DescriptiveDeclKind, ValueDecl *))
1701+
ERROR(unexposed_other_decl_in_cxx,none,
1702+
"%0 %1 is not yet exposed to C++", (DescriptiveDeclKind, ValueDecl *))
1703+
ERROR(unsupported_other_decl_in_cxx,none,
1704+
"Swift %0 %1 cannot be represented in C++", (DescriptiveDeclKind, ValueDecl *))
16971705

16981706
ERROR(attr_methods_only,none,
16991707
"only methods can be declared %0", (DeclAttribute))
@@ -4599,9 +4607,16 @@ ERROR(opaque_type_var_no_underlying_type,none,
45994607
"property declares an opaque return type, but cannot infer the "
46004608
"underlying type from its initializer expression", ())
46014609

4610+
4611+
//------------------------------------------------------------------------------
4612+
// MARK: Forget Statement
4613+
//------------------------------------------------------------------------------
46024614
ERROR(forget_wrong_context_decl,none,
46034615
"'forget' statement cannot appear in %0",
46044616
(DescriptiveDeclKind))
4617+
ERROR(forget_no_deinit,none,
4618+
"'forget' has no effect for type %0 unless it has a deinitializer",
4619+
(Type))
46054620
ERROR(forget_wrong_context_closure,none,
46064621
"'forget' statement cannot appear in closure",
46074622
())
@@ -7128,6 +7143,8 @@ ERROR(ownership_specifier_copyable,none,
71287143
ERROR(self_ownership_specifier_copyable,none,
71297144
"%0 is not yet valid on %1s in a Copyable type",
71307145
(SelfAccessKind, DescriptiveDeclKind))
7146+
ERROR(ownership_specifier_nonescaping_closure,none,
7147+
"'%0' cannot be applied to nonescaping closure", (StringRef))
71317148

71327149
//------------------------------------------------------------------------------
71337150
// MARK: Runtime discoverable attributes (@runtimeMetadata)

Diff for: include/swift/AST/KnownDecls.def

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ FUNC_DECL(DiagnoseUnexpectedError, "_unexpectedError")
6868
FUNC_DECL(DiagnoseUnexpectedNilOptional, "_diagnoseUnexpectedNilOptional")
6969
FUNC_DECL(DiagnoseUnexpectedEnumCase, "_diagnoseUnexpectedEnumCase")
7070
FUNC_DECL(DiagnoseUnexpectedEnumCaseValue, "_diagnoseUnexpectedEnumCaseValue")
71+
FUNC_DECL(DiagnoseUnavailableCodeReached, "_diagnoseUnavailableCodeReached")
7172

7273
FUNC_DECL(GetErrorEmbeddedNSError, "_getErrorEmbeddedNSError")
7374

Diff for: include/swift/AST/PluginRegistry.h

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#ifndef SWIFT_PLUGIN_REGISTRY_H
1313
#define SWIFT_PLUGIN_REGISTRY_H
1414

15+
#include "swift/Basic/StringExtras.h"
1516
#include "llvm/ADT/ArrayRef.h"
1617
#include "llvm/ADT/StringMap.h"
1718
#include "llvm/ADT/StringRef.h"
@@ -139,6 +140,10 @@ class LoadedExecutablePlugin {
139140

140141
llvm::sys::procid_t getPid() { return Process->pid; }
141142

143+
NullTerminatedStringRef getExecutablePath() {
144+
return {ExecutablePath.c_str(), ExecutablePath.size()};
145+
}
146+
142147
const void *getCapability() { return capability; };
143148
void setCapability(const void *newValue) { capability = newValue; };
144149

Diff for: include/swift/AST/SwiftNameTranslation.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
#ifndef SWIFT_NAME_TRANSLATION_H
1414
#define SWIFT_NAME_TRANSLATION_H
1515

16-
#include "swift/AST/Identifier.h"
1716
#include "swift/AST/AttrKind.h"
17+
#include "swift/AST/DiagnosticEngine.h"
18+
#include "swift/AST/Identifier.h"
1819

1920
namespace swift {
2021
class ValueDecl;
@@ -76,8 +77,13 @@ enum RepresentationError {
7677
UnrepresentableIndirectEnum,
7778
UnrepresentableEnumCaseType,
7879
UnrepresentableEnumCaseTuple,
80+
UnrepresentableProtocol,
81+
UnrepresentableMoveOnly,
7982
};
8083

84+
/// Constructs a diagnostic that describes the given C++ representation error.
85+
Diagnostic diagnoseRepresenationError(RepresentationError error, ValueDecl *vd);
86+
8187
struct DeclRepresentation {
8288
RepresentationKind kind;
8389
llvm::Optional<RepresentationError> error;

Diff for: include/swift/Basic/LangOptions.h

+6
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ namespace swift {
112112
/// resulting binary by default in this mode.
113113
None,
114114

115+
/// Stub out code associated with unavailable declarations.
116+
///
117+
/// For example, the bodies of unavailable functions should be compiled as
118+
/// if they just contained a call to fatalError().
119+
Stub,
120+
115121
/// Avoid generating any code for unavailable declarations.
116122
///
117123
/// NOTE: This optimization can be ABI breaking for a library evolution

Diff for: include/swift/IDE/CompletionLookup.h

+6
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,12 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
324324

325325
bool isUnresolvedMemberIdealType(Type Ty);
326326

327+
/// Creates a \c CodeCompletionResultBuilder in this lookup’s sink and sets
328+
/// the current expected type context in it
329+
CodeCompletionResultBuilder
330+
makeResultBuilder(CodeCompletionResultKind kind,
331+
SemanticContextKind semanticContext) const;
332+
327333
void addValueBaseName(CodeCompletionResultBuilder &Builder,
328334
DeclBaseName Name);
329335

Diff for: include/swift/SIL/ApplySite.h

+6
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,12 @@ class ApplySite {
241241
FOREACH_IMPL_RETURN(isCalleeKnownProgramTerminationPoint());
242242
}
243243

244+
/// Returns true if the callee function is annotated with
245+
/// @_semantics("unavailable_code_reached")
246+
bool isCalleeUnavailableCodeReached() const {
247+
FOREACH_IMPL_RETURN(isCalleeUnavailableCodeReached());
248+
}
249+
244250
/// Check if this is a call of a never-returning function.
245251
bool isCalleeNoReturn() const { FOREACH_IMPL_RETURN(isCalleeNoReturn()); }
246252

Diff for: include/swift/SIL/SILInstruction.h

+8
Original file line numberDiff line numberDiff line change
@@ -2777,6 +2777,14 @@ class ApplyInstBase<Impl, Base, false> : public Base {
27772777
return calleeFn->hasSemanticsAttr(SEMANTICS_PROGRAMTERMINATION_POINT);
27782778
}
27792779

2780+
/// Returns true if the callee function is annotated with
2781+
/// @_semantics("unavailable_code_reached")
2782+
bool isCalleeUnavailableCodeReached() const {
2783+
auto calleeFn = getCalleeFunction();
2784+
if (!calleeFn) return false;
2785+
return calleeFn->hasSemanticsAttr(SEMANTICS_UNAVAILABLE_CODE_REACHED);
2786+
}
2787+
27802788
/// True if this application has generic substitutions.
27812789
bool hasSubstitutions() const {
27822790
return Substitutions.hasAnySubstitutableParams();

Diff for: include/swift/SIL/SILModule.h

+4
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,10 @@ LLVM_LIBRARY_VISIBILITY bool usesObjCAllocator(ClassDecl *theClass);
10871087
/// A declaration may not require lowering if, for example, it is annotated as
10881088
/// unavailable and optimization settings allow it to be omitted.
10891089
LLVM_LIBRARY_VISIBILITY bool shouldSkipLowering(Decl *D);
1090+
1091+
/// Returns true if SIL/IR lowering for the given declaration should produce
1092+
/// a stub that traps at runtime because the code ought to be unreachable.
1093+
LLVM_LIBRARY_VISIBILITY bool shouldLowerToUnavailableCodeStub(Decl *D);
10901094
} // namespace Lowering
10911095

10921096
/// Apply the given function to each ABI member of \c D skipping the members

Diff for: include/swift/SILOptimizer/PassManager/Passes.def

+3
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ PASS(AccessMarkerElimination, "access-marker-elim",
112112
"Access Marker Elimination.")
113113
PASS(AddressLowering, "address-lowering",
114114
"SIL Address Lowering")
115+
PASS(EarlyAllocBoxToStack, "early-allocbox-to-stack",
116+
"Stack Promotion of Box Objects. Doesn't attempt to promote noncopyable "
117+
"types captured by escaping closures")
115118
PASS(AllocBoxToStack, "allocbox-to-stack",
116119
"Stack Promotion of Box Objects")
117120
IRGEN_PASS(AllocStackHoisting, "alloc-stack-hoisting",

Diff for: include/swift/Strings.h

+3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ constexpr static const StringLiteral SEMANTICS_PROGRAMTERMINATION_POINT =
6060
constexpr static const StringLiteral SEMANTICS_DEFAULT_ACTOR =
6161
"defaultActor";
6262

63+
constexpr static const StringLiteral SEMANTICS_UNAVAILABLE_CODE_REACHED =
64+
"unavailable_code_reached";
65+
6366
constexpr static const StringLiteral DEFAULT_ACTOR_STORAGE_FIELD_NAME =
6467
"$defaultActor";
6568

Diff for: lib/AST/ASTContext.cpp

+1-21
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,6 @@ struct ASTContext::Implementation {
430430
llvm::DenseMap<Type, InOutType*> InOutTypes;
431431
llvm::DenseMap<std::pair<Type, void*>, DependentMemberType *>
432432
DependentMemberTypes;
433-
llvm::DenseMap<void *, PlaceholderType *> PlaceholderTypes;
434433
llvm::DenseMap<Type, DynamicSelfType *> DynamicSelfTypes;
435434
llvm::DenseMap<std::pair<EnumDecl*, Type>, EnumType*> EnumTypes;
436435
llvm::DenseMap<std::pair<StructDecl*, Type>, StructType*> StructTypes;
@@ -3125,27 +3124,8 @@ Type ErrorType::get(Type originalType) {
31253124

31263125
Type PlaceholderType::get(ASTContext &ctx, Originator originator) {
31273126
assert(originator);
3128-
3129-
auto hasTypeVariables = [&]() -> bool {
3130-
if (originator.is<TypeVariableType *>())
3131-
return true;
3132-
3133-
if (auto *depTy = originator.dyn_cast<DependentMemberType *>())
3134-
return depTy->hasTypeVariable();
3135-
3136-
return false;
3137-
}();
3138-
auto arena = hasTypeVariables ? AllocationArena::ConstraintSolver
3139-
: AllocationArena::Permanent;
3140-
3141-
auto &cache = ctx.getImpl().getArena(arena).PlaceholderTypes;
3142-
auto &entry = cache[originator.getOpaqueValue()];
3143-
if (entry)
3144-
return entry;
3145-
3146-
entry = new (ctx, arena)
3127+
return new (ctx, AllocationArena::Permanent)
31473128
PlaceholderType(ctx, originator, RecursiveTypeProperties::HasPlaceholder);
3148-
return entry;
31493129
}
31503130

31513131
BuiltinIntegerType *BuiltinIntegerType::get(BuiltinIntegerWidth BitWidth,

Diff for: lib/AST/CASTBridging.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,11 @@ void Plugin_setCapability(PluginHandle handle, PluginCapabilityPtr data) {
642642
plugin->setCapability(data);
643643
}
644644

645+
const char *Plugin_getExecutableFilePath(PluginHandle handle) {
646+
auto *plugin = static_cast<LoadedExecutablePlugin *>(handle);
647+
return plugin->getExecutablePath().data();
648+
}
649+
645650
void Plugin_lock(PluginHandle handle) {
646651
auto *plugin = static_cast<LoadedExecutablePlugin *>(handle);
647652
plugin->lock();

Diff for: lib/AST/DocComment.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ StringRef SemanticBriefCommentRequest::evaluate(Evaluator &evaluator,
577577
const Decl *D) const {
578578
// Perform a walk over the potential providers of the brief comment,
579579
// retrieving the first one we come across.
580-
CommentProviderFinder finder(getDirectBriefComment);
580+
CommentProviderFinder<StringRef> finder(getDirectBriefComment);
581581
auto result = finder.findCommentProvider(D);
582582
return result ? result->first : StringRef();
583583
}

Diff for: lib/AST/PluginRegistry.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ LoadedExecutablePlugin::PluginProcess::~PluginProcess() {
178178

179179
LoadedExecutablePlugin::~LoadedExecutablePlugin() {
180180
// Let ASTGen to cleanup things.
181-
this->cleanup();
181+
if (this->cleanup)
182+
this->cleanup();
182183
}
183184

184185
ssize_t LoadedExecutablePlugin::PluginProcess::read(void *buf,

Diff for: lib/AST/SwiftNameTranslation.cpp

+48
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "swift/AST/SwiftNameTranslation.h"
1818
#include "swift/AST/ASTContext.h"
1919
#include "swift/AST/Decl.h"
20+
#include "swift/AST/DiagnosticsSema.h"
2021
#include "swift/AST/LazyResolver.h"
2122
#include "swift/AST/Module.h"
2223
#include "swift/AST/ParameterList.h"
@@ -163,6 +164,9 @@ swift::cxx_translation::getNameForCxx(const ValueDecl *VD,
163164
if (customNamesOnly)
164165
return StringRef();
165166

167+
if (isa<ConstructorDecl>(VD))
168+
return "init";
169+
166170
if (auto *mod = dyn_cast<ModuleDecl>(VD)) {
167171
if (mod->isStdlibModule())
168172
return "swift";
@@ -220,6 +224,11 @@ swift::cxx_translation::getDeclRepresentation(const ValueDecl *VD) {
220224
genericSignature = AFD->getGenericSignature().getCanonicalSignature();
221225
}
222226
if (const auto *typeDecl = dyn_cast<NominalTypeDecl>(VD)) {
227+
if (isa<ProtocolDecl>(typeDecl))
228+
return {Unsupported, UnrepresentableProtocol};
229+
// Swift's consume semantics are not yet supported in C++.
230+
if (typeDecl->isMoveOnly())
231+
return {Unsupported, UnrepresentableMoveOnly};
223232
if (typeDecl->isGeneric()) {
224233
if (isa<ClassDecl>(VD))
225234
return {Unsupported, UnrepresentableGeneric};
@@ -283,3 +292,42 @@ bool swift::cxx_translation::isVisibleToCxx(const ValueDecl *VD,
283292
}
284293
return false;
285294
}
295+
296+
Diagnostic
297+
swift::cxx_translation::diagnoseRepresenationError(RepresentationError error,
298+
ValueDecl *vd) {
299+
switch (error) {
300+
case UnrepresentableObjC:
301+
return Diagnostic(diag::expose_unsupported_objc_decl_to_cxx,
302+
vd->getDescriptiveKind(), vd);
303+
case UnrepresentableAsync:
304+
return Diagnostic(diag::expose_unsupported_async_decl_to_cxx,
305+
vd->getDescriptiveKind(), vd);
306+
case UnrepresentableIsolatedInActor:
307+
return Diagnostic(diag::expose_unsupported_actor_isolated_to_cxx,
308+
vd->getDescriptiveKind(), vd);
309+
case UnrepresentableRequiresClientEmission:
310+
return Diagnostic(diag::expose_unsupported_client_emission_to_cxx,
311+
vd->getDescriptiveKind(), vd);
312+
case UnrepresentableGeneric:
313+
return Diagnostic(diag::expose_generic_decl_to_cxx,
314+
vd->getDescriptiveKind(), vd);
315+
case UnrepresentableGenericRequirements:
316+
return Diagnostic(diag::expose_generic_requirement_to_cxx,
317+
vd->getDescriptiveKind(), vd);
318+
case UnrepresentableThrows:
319+
return Diagnostic(diag::expose_throwing_to_cxx, vd->getDescriptiveKind(),
320+
vd);
321+
case UnrepresentableIndirectEnum:
322+
return Diagnostic(diag::expose_indirect_enum_cxx, vd);
323+
case UnrepresentableEnumCaseType:
324+
return Diagnostic(diag::expose_enum_case_type_to_cxx, vd);
325+
case UnrepresentableEnumCaseTuple:
326+
return Diagnostic(diag::expose_enum_case_tuple_to_cxx, vd);
327+
case UnrepresentableProtocol:
328+
return Diagnostic(diag::expose_protocol_to_cxx_unsupported, vd);
329+
case UnrepresentableMoveOnly:
330+
return Diagnostic(diag::expose_move_only_to_cxx, vd->getDescriptiveKind(),
331+
vd);
332+
}
333+
}

0 commit comments

Comments
 (0)