Skip to content

Commit 2f4ee5f

Browse files
Merge pull request #5391 from swiftwasm/main
[pull] swiftwasm from main
2 parents bde203a + 49e50a5 commit 2f4ee5f

File tree

136 files changed

+2335
-779
lines changed

Some content is hidden

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

136 files changed

+2335
-779
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,10 @@ option(SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY
610610
"Enable build of the Swift concurrency module"
611611
FALSE)
612612

613+
option(SWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP
614+
"Enable experimental C++ interop modules"
615+
FALSE)
616+
613617
option(SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED
614618
"Enable experimental distributed actors and functions"
615619
FALSE)

include/swift/AST/Decl.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5742,6 +5742,16 @@ class VarDecl : public AbstractStorageDecl {
57425742
return false;
57435743
}
57445744

5745+
/// Return the initializer that will initializer this VarDecl at runtime.
5746+
/// This is equivalent to `getParentInitializer()`, but returns `null` if the
5747+
/// initializer itself was subsumed, e.g., by a macro or property wrapper.
5748+
Expr *getParentExecutableInitializer() const;
5749+
5750+
/// Whether this variable has an initializer that will be code-generated.
5751+
bool isParentExecutabledInitialized() const {
5752+
return getParentExecutableInitializer() != nullptr;
5753+
}
5754+
57455755
// Return whether this VarDecl has an initial value, either by checking
57465756
// if it has an initializer in its parent pattern binding or if it has
57475757
// the @_hasInitialValue attribute.

include/swift/AST/DiagnosticsCommon.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ ERROR(unknown_attribute,none,
223223
NOTE(in_macro_expansion,none,
224224
"in expansion of macro %0 here", (DeclName))
225225
ERROR(macro_experimental,none,
226-
"%0 macros are an experimental feature that is not enabled (%1)",
226+
"%0 macros are an experimental feature that is not enabled %select{|(%1)}1",
227227
(StringRef, StringRef))
228228
ERROR(ambiguous_macro_reference,none,
229229
"ambiguous reference to macro %0", (DeclName))

include/swift/AST/DiagnosticsParse.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,8 @@ ERROR(operator_decl_no_fixity,none,
461461
"operator must be declared as 'prefix', 'postfix', or 'infix'", ())
462462
ERROR(operator_decl_expected_precedencegroup, none,
463463
"expected precedence group name after ':' in operator declaration", ())
464-
464+
ERROR(operator_decl_should_not_contain_other_attributes, none,
465+
"unexpected attribute %0 in operator declaration", (StringRef))
465466
WARNING(operator_decl_remove_designated_types,none,
466467
"designated types are no longer used by the compiler; please remove "
467468
"the designated type list from this operator declaration", ())

include/swift/AST/MacroDeclaration.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,13 @@ enum class MacroRole: uint32_t {
5858
/// A freestanding macro that expands to expressions, statements and
5959
/// declarations in a code block.
6060
CodeItem = 0x80,
61+
62+
// NOTE: When adding a new macro role, also add it to `getAllMacroRoles`.
6163
};
6264

65+
/// Returns an enumeratable list of all macro roles.
66+
std::vector<MacroRole> getAllMacroRoles();
67+
6368
/// The contexts in which a particular macro declaration can be used.
6469
using MacroRoles = OptionSet<MacroRole>;
6570

@@ -83,6 +88,9 @@ bool isAttachedMacro(MacroRoles contexts);
8388

8489
MacroRoles getAttachedMacroRoles();
8590

91+
/// Checks if the macro is supported or guarded behind an experimental flag.
92+
bool isMacroSupported(MacroRole role, ASTContext &ctx);
93+
8694
enum class MacroIntroducedDeclNameKind {
8795
Named,
8896
Overloaded,

include/swift/AST/MacroDiscriminatorContext.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ struct MacroDiscriminatorContext
3131
static MacroDiscriminatorContext getParentOf(
3232
SourceLoc loc, DeclContext *origDC
3333
);
34+
35+
/// Return the innermost declaration context that is suitable for
36+
/// use in identifying a macro.
37+
static DeclContext *getInnermostMacroContext(DeclContext *dc);
3438
};
3539

3640
}

include/swift/AST/SourceFile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ class SourceFile final : public FileUnit {
496496
collectLinkLibraries(ModuleDecl::LinkLibraryCallback callback) const override;
497497

498498
Identifier getDiscriminatorForPrivateDecl(const Decl *D) const override;
499-
Identifier getPrivateDiscriminator() const { return PrivateDiscriminator; }
499+
Identifier getPrivateDiscriminator(bool createIfMissing = false) const;
500500
Optional<ExternalSourceLocs::RawLocs>
501501
getExternalRawLocsForDecl(const Decl *D) const override;
502502

include/swift/AST/TypeCheckRequests.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3930,6 +3930,26 @@ class ExpandMacroExpansionDeclRequest
39303930
void noteCycleStep(DiagnosticEngine &diags) const;
39313931
};
39323932

3933+
/// Expand a 'MacroExpansionExpr',
3934+
class ExpandMacroExpansionExprRequest
3935+
: public SimpleRequest<ExpandMacroExpansionExprRequest,
3936+
Optional<unsigned>(MacroExpansionExpr *),
3937+
RequestFlags::Cached> {
3938+
public:
3939+
using SimpleRequest::SimpleRequest;
3940+
3941+
private:
3942+
friend SimpleRequest;
3943+
3944+
Optional<unsigned>
3945+
evaluate(Evaluator &evaluator, MacroExpansionExpr *mee) const;
3946+
3947+
public:
3948+
bool isCached() const { return true; }
3949+
void diagnoseCycle(DiagnosticEngine &diags) const;
3950+
void noteCycleStep(DiagnosticEngine &diags) const;
3951+
};
3952+
39333953
/// Expand all accessor macros attached to the given declaration.
39343954
///
39353955
/// Produces the set of macro expansion buffer IDs.

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,9 @@ SWIFT_REQUEST(TypeChecker, ExternalMacroDefinitionRequest,
439439
SWIFT_REQUEST(TypeChecker, ExpandMacroExpansionDeclRequest,
440440
ArrayRef<Decl *>(MacroExpansionDecl *),
441441
Cached, NoLocationInfo)
442+
SWIFT_REQUEST(TypeChecker, ExpandMacroExpansionExprRequest,
443+
ArrayRef<Decl *>(MacroExpansionExpr *),
444+
Cached, NoLocationInfo)
442445
SWIFT_REQUEST(TypeChecker, ExpandMemberAttributeMacros,
443446
ArrayRef<unsigned>(Decl *),
444447
Cached, NoLocationInfo)

include/swift/Frontend/ModuleInterfaceSupport.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#define SWIFT_COMPILER_VERSION_KEY "swift-compiler-version"
2222
#define SWIFT_MODULE_FLAGS_KEY "swift-module-flags"
2323
#define SWIFT_MODULE_FLAGS_IGNORABLE_KEY "swift-module-flags-ignorable"
24+
#define SWIFT_MODULE_FLAGS_IGNORABLE_PRIVATE_KEY "swift-module-flags-ignorable-private"
2425

2526
namespace swift {
2627

@@ -50,6 +51,10 @@ struct ModuleInterfaceOptions {
5051
/// ignored by the earlier version of the compiler.
5152
std::string IgnorableFlags;
5253

54+
/// Ignorable flags that should only be printed in .private.swiftinterface file;
55+
/// e.g. -package-name PACKAGE_ID
56+
std::string IgnorablePrivateFlags;
57+
5358
/// Print for a private swiftinterface file, SPI decls and attributes.
5459
bool PrintPrivateInterfaceContent = false;
5560

include/swift/IDE/CompletionLookup.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,11 +581,12 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
581581

582582
static bool canUseAttributeOnDecl(DeclAttrKind DAK, bool IsInSil,
583583
bool IsConcurrencyEnabled,
584-
Optional<DeclKind> DK);
584+
Optional<DeclKind> DK, StringRef Name);
585585

586586
void getAttributeDeclCompletions(bool IsInSil, Optional<DeclKind> DK);
587587

588-
void getAttributeDeclParamCompletions(DeclAttrKind AttrKind, int ParamIndex);
588+
void getAttributeDeclParamCompletions(CustomSyntaxAttributeKind AttrKind,
589+
int ParamIndex);
589590

590591
void getTypeAttributeKeywordCompletions();
591592

include/swift/Option/Options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ namespace options {
4242
SwiftAPIDigesterOption = (1 << 17),
4343
NewDriverOnlyOption = (1 << 18),
4444
ModuleInterfaceOptionIgnorable = (1 << 19),
45+
ModuleInterfaceOptionIgnorablePrivate = (1 << 20),
4546
};
4647

4748
enum ID {

include/swift/Option/Options.td

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ def ModuleInterfaceOption : OptionFlag;
5656
// The option can be safely ignored by the older compiler.
5757
def ModuleInterfaceOptionIgnorable : OptionFlag;
5858

59+
// The option should be written into a .private.swiftinterface module interface file,
60+
// and read/parsed from there when reconstituting a .swiftmodule from it.
61+
// The option can be safely ignored by the older compiler.
62+
def ModuleInterfaceOptionIgnorablePrivate : OptionFlag;
63+
5964
// The option causes the output of a supplementary output, or is the path option
6065
// for a supplementary output. E.g., `-emit-module` and `-emit-module-path`.
6166
def SupplementaryOutput : OptionFlag;
@@ -530,7 +535,7 @@ def module_abi_name : Separate<["-"], "module-abi-name">,
530535
Flags<[FrontendOption, ModuleInterfaceOption]>,
531536
HelpText<"ABI name to use for the contents of this module">;
532537
def package_name : Separate<["-"], "package-name">,
533-
Flags<[FrontendOption, ModuleInterfaceOptionIgnorable]>,
538+
Flags<[FrontendOption, ModuleInterfaceOptionIgnorablePrivate]>,
534539
HelpText<"Name of the package the module belongs to">;
535540
def export_as : Separate<["-"], "export-as">,
536541
Flags<[FrontendOption, ModuleInterfaceOptionIgnorable]>,

include/swift/Parse/IDEInspectionCallbacks.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ enum class ObjCSelectorContext {
2929
SetterSelector
3030
};
3131

32+
/// Attributes that have syntax which can't be modelled using a function call.
33+
/// This can't be \c DeclAttrKind because '@freestandig' and '@attached' have
34+
/// the same attribute kind but take different macro roles as arguemnts.
35+
enum class CustomSyntaxAttributeKind {
36+
Available,
37+
FreestandingMacro,
38+
AttachedMacro,
39+
};
40+
3241
/// Parser's interface to code completion.
3342
class CodeCompletionCallbacks {
3443
protected:
@@ -185,7 +194,7 @@ class CodeCompletionCallbacks {
185194

186195
/// Complete the parameters in attribute, for instance, version specifier for
187196
/// @available.
188-
virtual void completeDeclAttrParam(DeclAttrKind DK, int Index) {};
197+
virtual void completeDeclAttrParam(CustomSyntaxAttributeKind DK, int Index){};
189198

190199
/// Complete 'async' and 'throws' at effects specifier position.
191200
virtual void completeEffectsSpecifier(bool hasAsync, bool hasThrows) {};

include/swift/Parse/Parser.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,9 +1019,10 @@ class Parser {
10191019
PatternBindingInitializer *initContext);
10201020

10211021
/// Parse the optional modifiers before a declaration.
1022-
bool parseDeclModifierList(DeclAttributes &Attributes, SourceLoc &StaticLoc,
1023-
StaticSpellingKind &StaticSpelling,
1024-
bool isFromClangAttribute = false);
1022+
ParserStatus parseDeclModifierList(DeclAttributes &Attributes,
1023+
SourceLoc &StaticLoc,
1024+
StaticSpellingKind &StaticSpelling,
1025+
bool isFromClangAttribute = false);
10251026

10261027
/// Parse an availability attribute of the form
10271028
/// @available(*, introduced: 1.0, deprecated: 3.1).
@@ -1133,9 +1134,9 @@ class Parser {
11331134
ParserResult<CustomAttr> parseCustomAttribute(
11341135
SourceLoc atLoc, PatternBindingInitializer *&initContext);
11351136

1136-
bool parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
1137-
DeclAttrKind DK,
1138-
bool isFromClangAttribute = false);
1137+
ParserStatus parseNewDeclAttribute(DeclAttributes &Attributes,
1138+
SourceLoc AtLoc, DeclAttrKind DK,
1139+
bool isFromClangAttribute = false);
11391140

11401141
/// Parse a version tuple of the form x[.y[.z]]. Returns true if there was
11411142
/// an error parsing.

include/swift/Refactoring/RefactoringKinds.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ CURSOR_REFACTORING(AddAsyncWrapper, "Add Async Wrapper", add.async-wrapper)
6666

6767
CURSOR_REFACTORING(ExpandMacro, "Expand Macro", expand.macro)
6868

69+
CURSOR_REFACTORING(InlineMacro, "Inline Macro", inline.macro)
70+
6971
RANGE_REFACTORING(ExtractExpr, "Extract Expression", extract.expr)
7072

7173
RANGE_REFACTORING(ExtractFunction, "Extract Method", extract.function)

lib/AST/ASTMangler.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3845,6 +3845,8 @@ std::string ASTMangler::mangleRuntimeAttributeGeneratorEntity(
38453845
void ASTMangler::appendMacroExpansionContext(
38463846
SourceLoc loc, DeclContext *origDC
38473847
) {
3848+
origDC = MacroDiscriminatorContext::getInnermostMacroContext(origDC);
3849+
38483850
if (loc.isInvalid())
38493851
return appendContext(origDC, StringRef());
38503852

@@ -3992,10 +3994,41 @@ void ASTMangler::appendMacroExpansionOperator(
39923994
}
39933995
}
39943996

3997+
static StringRef getPrivateDiscriminatorIfNecessary(
3998+
const MacroExpansionExpr *expansion) {
3999+
auto dc = MacroDiscriminatorContext::getInnermostMacroContext(
4000+
expansion->getDeclContext());
4001+
auto decl = dc->getAsDecl();
4002+
if (decl && !decl->isOutermostPrivateOrFilePrivateScope())
4003+
return StringRef();
4004+
4005+
// Mangle non-local private declarations with a textual discriminator
4006+
// based on their enclosing file.
4007+
auto topLevelSubcontext = dc->getModuleScopeContext();
4008+
SourceFile *sf = dyn_cast<SourceFile>(topLevelSubcontext);
4009+
if (!sf)
4010+
return StringRef();
4011+
4012+
Identifier discriminator =
4013+
sf->getPrivateDiscriminator(/*createIfMissing=*/true);
4014+
assert(!discriminator.empty());
4015+
assert(!isNonAscii(discriminator.str()) &&
4016+
"discriminator contains non-ASCII characters");
4017+
(void)&isNonAscii;
4018+
assert(!clang::isDigit(discriminator.str().front()) &&
4019+
"not a valid identifier");
4020+
return discriminator.str();
4021+
}
4022+
39954023
std::string ASTMangler::mangleMacroExpansion(
39964024
const MacroExpansionExpr *expansion) {
39974025
beginMangling();
39984026
appendMacroExpansionContext(expansion->getLoc(), expansion->getDeclContext());
4027+
auto privateDiscriminator = getPrivateDiscriminatorIfNecessary(expansion);
4028+
if (!privateDiscriminator.empty()) {
4029+
appendIdentifier(privateDiscriminator);
4030+
appendOperator("Ll");
4031+
}
39994032
appendMacroExpansionOperator(
40004033
expansion->getMacroName().getBaseName().userFacingName(),
40014034
MacroRole::Expression,

0 commit comments

Comments
 (0)