Skip to content

Commit 6e61d01

Browse files
authored
Merge pull request #2914 from swiftwasm/main
[pull] swiftwasm from main
2 parents 5ed6739 + 4faa397 commit 6e61d01

File tree

47 files changed

+498
-184
lines changed

Some content is hidden

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

47 files changed

+498
-184
lines changed

include/swift/ABI/Task.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -519,17 +519,12 @@ class YieldingAsyncContext : public AsyncContext {
519519
TaskContinuationFunction * __ptrauth_swift_async_context_yield
520520
YieldToParent;
521521

522-
/// The executor that the parent context needs to be yielded to on.
523-
ExecutorRef YieldToParentExecutor;
524-
525522
YieldingAsyncContext(AsyncContextFlags flags,
526523
TaskContinuationFunction *resumeParent,
527524
TaskContinuationFunction *yieldToParent,
528-
ExecutorRef yieldToParentExecutor,
529525
AsyncContext *parent)
530526
: AsyncContext(flags, resumeParent, parent),
531-
YieldToParent(yieldToParent),
532-
YieldToParentExecutor(yieldToParentExecutor) {}
527+
YieldToParent(yieldToParent) {}
533528

534529
static bool classof(const AsyncContext *context) {
535530
return context->Flags.getKind() == AsyncContextKind::Yielding;

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ ERROR(error_unsupported_target_os, none,
3636
ERROR(error_unsupported_target_arch, none,
3737
"unsupported target architecture: '%0'", (StringRef))
3838

39+
ERROR(error_unknown_library_level, none,
40+
"unknown library level '%0', "
41+
"expected one of 'api', 'spi' or 'other'", (StringRef))
42+
3943
ERROR(error_unsupported_opt_for_target, none,
4044
"unsupported option '%0' for target '%1'", (StringRef, StringRef))
4145

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2843,6 +2843,9 @@ WARNING(warn_implementation_only_conflict,none,
28432843
(Identifier))
28442844
NOTE(implementation_only_conflict_here,none,
28452845
"imported as implementation-only here", ())
2846+
WARNING(warn_public_import_of_private_module,none,
2847+
"private module %0 is imported publicly from the public module %1",
2848+
(Identifier, Identifier))
28462849

28472850
ERROR(implementation_only_decl_non_override,none,
28482851
"'@_implementationOnly' can only be used on overrides", ())

include/swift/AST/Module.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ namespace swift {
5656
class FileUnit;
5757
class FuncDecl;
5858
class InfixOperatorDecl;
59+
enum class LibraryLevel : uint8_t;
5960
class LinkLibrary;
6061
class ModuleLoader;
6162
class NominalTypeDecl;
@@ -462,6 +463,9 @@ class ModuleDecl : public DeclContext, public TypeDecl {
462463
Bits.ModuleDecl.RawResilienceStrategy = unsigned(strategy);
463464
}
464465

466+
/// Distribution level of the module.
467+
LibraryLevel getLibraryLevel() const;
468+
465469
/// Returns true if this module was or is being compiled for testing.
466470
bool hasIncrementalInfo() const { return Bits.ModuleDecl.HasIncrementalInfo; }
467471
void setHasIncrementalInfo(bool enabled = true) {

include/swift/AST/TypeCheckRequests.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2753,6 +2753,24 @@ class HasImplementationOnlyImportsRequest
27532753
bool isCached() const { return true; }
27542754
};
27552755

2756+
/// Get the library level of a module.
2757+
class ModuleLibraryLevelRequest
2758+
: public SimpleRequest<ModuleLibraryLevelRequest,
2759+
LibraryLevel(const ModuleDecl *),
2760+
RequestFlags::Cached> {
2761+
public:
2762+
using SimpleRequest::SimpleRequest;
2763+
2764+
private:
2765+
friend SimpleRequest;
2766+
2767+
LibraryLevel evaluate(Evaluator &evaluator, const ModuleDecl *module) const;
2768+
2769+
public:
2770+
// Cached.
2771+
bool isCached() const { return true; }
2772+
};
2773+
27562774
class ResolveTypeRequest
27572775
: public SimpleRequest<ResolveTypeRequest,
27582776
Type(const TypeResolution *, TypeRepr *,

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ SWIFT_REQUEST(TypeChecker, HasDynamicCallableAttributeRequest,
126126
bool(CanType), Cached, NoLocationInfo)
127127
SWIFT_REQUEST(TypeChecker, HasImplementationOnlyImportsRequest,
128128
bool(SourceFile *), Cached, NoLocationInfo)
129+
SWIFT_REQUEST(TypeChecker, ModuleLibraryLevelRequest,
130+
LibraryLevel(ModuleDecl *), Cached, NoLocationInfo)
129131
SWIFT_REQUEST(TypeChecker, InferredGenericSignatureRequest,
130132
GenericSignature (ModuleDecl *, const GenericSignatureImpl *,
131133
GenericParamSource,

include/swift/Basic/LangOptions.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@ namespace swift {
5555
Complete,
5656
};
5757

58+
/// Access or distribution level of a library.
59+
enum class LibraryLevel : uint8_t {
60+
/// Application Programming Interface that is publicly distributed so
61+
/// public decls are really public and only @_spi decls are SPI.
62+
API,
63+
64+
/// System Programming Interface that has restricted distribution
65+
/// all decls in the module are considered to be SPI including public ones.
66+
SPI,
67+
68+
/// The library has some other undefined distribution.
69+
Other
70+
};
71+
5872
/// A collection of options that affect the language dialect and
5973
/// provide compiler debugging facilities.
6074
class LangOptions final {
@@ -306,6 +320,9 @@ namespace swift {
306320
/// Objective-C-derived classes and 'dynamic' members.
307321
bool EnableSwift3ObjCInference = false;
308322

323+
/// Access or distribution level of the whole module being parsed.
324+
LibraryLevel LibraryLevel = LibraryLevel::Other;
325+
309326
/// Warn about cases where Swift 3 would infer @objc but later versions
310327
/// of Swift do not.
311328
Swift3ObjCInferenceWarnings WarnSwift3ObjCInference =

include/swift/Option/FrontendOptions.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,11 @@ def disable_swift3_objc_inference :
433433
Flags<[FrontendOption, HelpHidden]>,
434434
HelpText<"Disable Swift 3's @objc inference rules for NSObject-derived classes and 'dynamic' members (emulates Swift 4 behavior)">;
435435

436+
def library_level : Separate<["-"], "library-level">,
437+
MetaVarName<"<level>">,
438+
Flags<[FrontendOption]>,
439+
HelpText<"Library distribution level 'api', 'spi' or 'other' (the default)">;
440+
436441
def enable_implicit_dynamic : Flag<["-"], "enable-implicit-dynamic">,
437442
Flags<[FrontendOption, NoInteractiveOption, HelpHidden]>,
438443
HelpText<"Add 'dynamic' to all declarations">;

include/swift/Strings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ constexpr static BuiltinNameStringLiteral BUILTIN_TYPE_NAME_JOB = {
124124
"Builtin.Job"};
125125
/// The name of the Builtin type for ExecutorRef
126126
constexpr static BuiltinNameStringLiteral BUILTIN_TYPE_NAME_EXECUTOR = {
127-
"Builtin.ExecutorRef"};
127+
"Builtin.Executor"};
128128
/// The name of the Builtin type for DefaultActorStorage
129129
constexpr static BuiltinNameStringLiteral BUILTIN_TYPE_NAME_DEFAULTACTORSTORAGE = {
130130
"Builtin.DefaultActorStorage"};

include/swift/Syntax/RawSyntax.h

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -218,31 +218,41 @@ class RawSyntax final
218218
}
219219

220220
/// Constructor for creating layout nodes.
221-
/// If the node has been allocated inside the bump allocator of a
222-
/// \c SyntaxArena, that arena must be passed as \p Arena to retain the node's
223-
/// underlying storage.
221+
/// \p Children is an iterator that provides the child \c RawSyntax nodes.
222+
/// It is only traversed once.
223+
/// \p NumChildren is the number of elements provided by the \p Children
224+
/// iterator.
224225
/// If \p NodeId is \c None, the next free NodeId is used, if it is passed,
225226
/// the caller needs to assure that the node ID has not been used yet.
226-
RawSyntax(SyntaxKind Kind, ArrayRef<const RawSyntax *> Layout,
227-
size_t TextLength, SourcePresence Presence,
227+
template <typename ChildrenIteratorType>
228+
RawSyntax(SyntaxKind Kind, ChildrenIteratorType ChildrenIt,
229+
uint32_t NumChildren, SourcePresence Presence,
228230
const RC<SyntaxArena> &Arena, llvm::Optional<SyntaxNodeId> NodeId)
229-
: Arena(Arena.get()), TextLength(uint32_t(TextLength)),
231+
: Arena(Arena.get()), TextLength(0 /*computed in body*/),
230232
Presence(Presence), IsToken(false),
231-
Bits(LayoutData{uint32_t(Layout.size()),
232-
/*TotalSubNodeCount=*/0, /*set in body*/
233-
Kind}) {
233+
Bits(LayoutData{NumChildren,
234+
/*TotalSubNodeCount=*/0 /*computed in body*/, Kind}) {
234235
assert(Arena && "RawSyntax nodes must always be allocated in an arena");
235236
assert(
236237
Kind != SyntaxKind::Token &&
237238
"'token' syntax node must be constructed with dedicated constructor");
238239

239-
for (auto Child : Layout) {
240+
const RawSyntax **TrailingChildren =
241+
getTrailingObjects<const RawSyntax *>();
242+
for (uint32_t I = 0; I < NumChildren;
243+
++I, ++ChildrenIt, ++TrailingChildren) {
244+
const RawSyntax *Child = *ChildrenIt;
240245
if (Child) {
246+
// Compute TextLength and TotalSubNodeCount of this node in place.
247+
TextLength += Child->getTextLength();
241248
Bits.Layout.TotalSubNodeCount += Child->getTotalSubNodeCount() + 1;
249+
242250
// If the child is stored in a different arena, it needs to stay alive
243251
// as long as this node's arena is alive.
244252
Arena->addChildArena(Child->Arena);
245253
}
254+
255+
*TrailingChildren = Child;
246256
}
247257

248258
if (NodeId.hasValue()) {
@@ -251,10 +261,6 @@ class RawSyntax final
251261
} else {
252262
this->NodeId = NextFreeNodeId++;
253263
}
254-
255-
// Initialize layout data.
256-
std::uninitialized_copy(Layout.begin(), Layout.end(),
257-
getTrailingObjects<const RawSyntax *>());
258264
}
259265

260266
/// Constructor for creating token nodes
@@ -311,28 +317,26 @@ class RawSyntax final
311317
/// @{
312318

313319
/// Make a raw "layout" syntax node.
320+
template <typename ChildrenIteratorType>
314321
static const RawSyntax *
315-
make(SyntaxKind Kind, ArrayRef<const RawSyntax *> Layout, size_t TextLength,
322+
make(SyntaxKind Kind, ChildrenIteratorType ChildrenIt, size_t NumChildren,
316323
SourcePresence Presence, const RC<SyntaxArena> &Arena,
317324
llvm::Optional<SyntaxNodeId> NodeId = llvm::None) {
318325
assert(Arena && "RawSyntax nodes must always be allocated in an arena");
319-
auto size = totalSizeToAlloc<const RawSyntax *>(Layout.size());
326+
auto size = totalSizeToAlloc<const RawSyntax *>(NumChildren);
320327
void *data = Arena->Allocate(size, alignof(RawSyntax));
321328
return new (data)
322-
RawSyntax(Kind, Layout, TextLength, Presence, Arena, NodeId);
329+
RawSyntax(Kind, ChildrenIt, NumChildren, Presence, Arena, NodeId);
323330
}
324331

332+
/// Convenience constructor to create a raw "layout" syntax node from an
333+
/// \c llvm::ArrayRef containing the children.
325334
static const RawSyntax *
326-
makeAndCalcLength(SyntaxKind Kind, ArrayRef<const RawSyntax *> Layout,
327-
SourcePresence Presence, const RC<SyntaxArena> &Arena,
328-
llvm::Optional<SyntaxNodeId> NodeId = llvm::None) {
329-
size_t TextLength = 0;
330-
for (auto Child : Layout) {
331-
if (Child) {
332-
TextLength += Child->getTextLength();
333-
}
334-
}
335-
return make(Kind, Layout, TextLength, Presence, Arena, NodeId);
335+
make(SyntaxKind Kind, llvm::ArrayRef<const RawSyntax *> Children,
336+
SourcePresence Presence, const RC<SyntaxArena> &Arena,
337+
llvm::Optional<SyntaxNodeId> NodeId = llvm::None) {
338+
return make(Kind, Children.begin(), Children.size(), Presence, Arena,
339+
NodeId);
336340
}
337341

338342
/// Make a raw "token" syntax node.
@@ -367,7 +371,7 @@ class RawSyntax final
367371
/// Make a missing raw "layout" syntax node.
368372
static const RawSyntax *missing(SyntaxKind Kind,
369373
const RC<SyntaxArena> &Arena) {
370-
return make(Kind, {}, /*TextLength=*/0, SourcePresence::Missing, Arena);
374+
return make(Kind, {}, SourcePresence::Missing, Arena);
371375
}
372376

373377
/// Make a missing raw "token" syntax node.

include/swift/Syntax/Serialization/SyntaxDeserialization.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ template <> struct MappingTraits<const swift::RawSyntax *> {
199199
StringRef nodeIdString;
200200
in.mapRequired("id", nodeIdString);
201201
unsigned nodeId = std::atoi(nodeIdString.data());
202-
value = swift::RawSyntax::makeAndCalcLength(kind, layout, presence,
203-
input->Arena, nodeId);
202+
value =
203+
swift::RawSyntax::make(kind, layout, presence, input->Arena, nodeId);
204204
}
205205
}
206206
};

include/swift/Syntax/SyntaxCollection.h

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,11 @@ class SyntaxCollection : public Syntax {
6060
private:
6161
static RC<const SyntaxData> makeData(std::initializer_list<Element> &Elements,
6262
const RC<SyntaxArena> &Arena) {
63-
std::vector<const RawSyntax *> List;
64-
List.reserve(Elements.size());
65-
for (auto &Elt : Elements)
66-
List.push_back(Elt.getRaw());
67-
auto Raw = RawSyntax::makeAndCalcLength(CollectionKind, List,
68-
SourcePresence::Present, Arena);
63+
auto RawElements = llvm::map_iterator(
64+
Elements.begin(),
65+
[](const Element &Elt) -> const RawSyntax * { return Elt.getRaw(); });
66+
auto Raw = RawSyntax::make(CollectionKind, RawElements, Elements.size(),
67+
SourcePresence::Present, Arena);
6968
return SyntaxData::makeRoot(AbsoluteRawSyntax::forRoot(Raw));
7069
}
7170

@@ -121,9 +120,8 @@ class SyntaxCollection : public Syntax {
121120
NewLayout.reserve(OldLayout.size() + 1);
122121
std::copy(OldLayout.begin(), OldLayout.end(), back_inserter(NewLayout));
123122
NewLayout.push_back(E.getRaw());
124-
auto Raw = RawSyntax::makeAndCalcLength(CollectionKind, NewLayout,
125-
getRaw()->getPresence(),
126-
getRaw()->getArena());
123+
auto Raw = RawSyntax::make(CollectionKind, NewLayout,
124+
getRaw()->getPresence(), getRaw()->getArena());
127125
return SyntaxCollection<CollectionKind, Element>(Data->replacingSelf(Raw));
128126
}
129127

@@ -133,9 +131,8 @@ class SyntaxCollection : public Syntax {
133131
SyntaxCollection<CollectionKind, Element> removingLast() const {
134132
assert(!empty());
135133
auto NewLayout = getRaw()->getLayout().drop_back();
136-
auto Raw = RawSyntax::makeAndCalcLength(CollectionKind, NewLayout,
137-
getRaw()->getPresence(),
138-
getRaw()->getArena());
134+
auto Raw = RawSyntax::make(CollectionKind, NewLayout,
135+
getRaw()->getPresence(), getRaw()->getArena());
139136
return SyntaxCollection<CollectionKind, Element>(Data->replacingSelf(Raw));
140137
}
141138

@@ -146,9 +143,8 @@ class SyntaxCollection : public Syntax {
146143
std::vector<const RawSyntax *> NewLayout = {E.getRaw()};
147144
std::copy(OldLayout.begin(), OldLayout.end(),
148145
std::back_inserter(NewLayout));
149-
auto Raw = RawSyntax::makeAndCalcLength(CollectionKind, NewLayout,
150-
getRaw()->getPresence(),
151-
getRaw()->getArena());
146+
auto Raw = RawSyntax::make(CollectionKind, NewLayout,
147+
getRaw()->getPresence(), getRaw()->getArena());
152148
return SyntaxCollection<CollectionKind, Element>(Data->replacingSelf(Raw));
153149
}
154150

@@ -158,9 +154,8 @@ class SyntaxCollection : public Syntax {
158154
SyntaxCollection<CollectionKind, Element> removingFirst() const {
159155
assert(!empty());
160156
auto NewLayout = getRaw()->getLayout().drop_front();
161-
auto Raw = RawSyntax::makeAndCalcLength(CollectionKind, NewLayout,
162-
getRaw()->getPresence(),
163-
getRaw()->getArena());
157+
auto Raw = RawSyntax::make(CollectionKind, NewLayout,
158+
getRaw()->getPresence(), getRaw()->getArena());
164159
return SyntaxCollection<CollectionKind, Element>(Data->replacingSelf(Raw));
165160
}
166161

@@ -179,9 +174,8 @@ class SyntaxCollection : public Syntax {
179174
NewLayout.push_back(E.getRaw());
180175
std::copy(OldLayout.begin() + i, OldLayout.end(),
181176
std::back_inserter(NewLayout));
182-
auto Raw = RawSyntax::makeAndCalcLength(CollectionKind, NewLayout,
183-
getRaw()->getPresence(),
184-
getRaw()->getArena());
177+
auto Raw = RawSyntax::make(CollectionKind, NewLayout,
178+
getRaw()->getPresence(), getRaw()->getArena());
185179
return SyntaxCollection<CollectionKind, Element>(Data->replacingSelf(Raw));
186180
}
187181

@@ -192,16 +186,15 @@ class SyntaxCollection : public Syntax {
192186
auto iterator = NewLayout.begin();
193187
std::advance(iterator, i);
194188
NewLayout.erase(iterator);
195-
auto Raw = RawSyntax::makeAndCalcLength(CollectionKind, NewLayout,
196-
getRaw()->getPresence(),
197-
getRaw()->getArena());
189+
auto Raw = RawSyntax::make(CollectionKind, NewLayout,
190+
getRaw()->getPresence(), getRaw()->getArena());
198191
return SyntaxCollection<CollectionKind, Element>(Data->replacingSelf(Raw));
199192
}
200193

201194
/// Return an empty syntax collection of this type.
202195
SyntaxCollection<CollectionKind, Element> cleared() const {
203-
auto Raw = RawSyntax::makeAndCalcLength(
204-
CollectionKind, {}, getRaw()->getPresence(), getRaw()->getArena());
196+
auto Raw = RawSyntax::make(CollectionKind, {}, getRaw()->getPresence(),
197+
getRaw()->getArena());
205198
return SyntaxCollection<CollectionKind, Element>(Data->replacingSelf(Raw));
206199
}
207200

lib/AST/Builtins.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ Type swift::getBuiltinType(ASTContext &Context, StringRef Name) {
8585
return Context.TheJobType;
8686
if (Name == "DefaultActorStorage")
8787
return Context.TheDefaultActorStorageType;
88+
if (Name == "Executor")
89+
return Context.TheExecutorType;
8890
if (Name == "NativeObject")
8991
return Context.TheNativeObjectType;
9092
if (Name == "BridgeObject")

0 commit comments

Comments
 (0)