Skip to content

Commit d6a1173

Browse files
authored
Merge branch 'main' into wip-fix-for-real-ptr-auth
2 parents 7305efa + 10f0f61 commit d6a1173

File tree

109 files changed

+934
-56
lines changed

Some content is hidden

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

109 files changed

+934
-56
lines changed

SwiftCompilerSources/Sources/AST/Declarations.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ final public class TopLevelCodeDecl: Decl {}
124124

125125
final public class ImportDecl: Decl {}
126126

127+
final public class UsingDecl: Decl {}
128+
127129
final public class PrecedenceGroupDecl: Decl {}
128130

129131
final public class MissingDecl: Decl {}

SwiftCompilerSources/Sources/AST/Registration.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public func registerAST() {
3636
registerDecl(ExtensionDecl.self)
3737
registerDecl(TopLevelCodeDecl.self)
3838
registerDecl(ImportDecl.self)
39+
registerDecl(UsingDecl.self)
3940
registerDecl(PrecedenceGroupDecl.self)
4041
registerDecl(MissingDecl.self)
4142
registerDecl(MissingMemberDecl.self)

SwiftCompilerSources/Sources/Optimizer/ModulePasses/MandatoryPerformanceOptimizations.swift

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private func optimizeFunctionsTopDown(using worklist: inout FunctionWorklist,
6464
// We need handle this case with a function signature optimization.
6565
removeMetatypeArgumentsInCallees(of: f, moduleContext)
6666

67-
worklist.addCallees(of: f)
67+
worklist.addCallees(of: f, moduleContext)
6868
}
6969
}
7070

@@ -496,29 +496,41 @@ fileprivate struct FunctionWorklist {
496496
return
497497
}
498498

499-
mutating func addCallees(of function: Function) {
499+
mutating func addCallees(of function: Function, _ context: ModulePassContext) {
500500
for inst in function.instructions {
501501
switch inst {
502-
case let apply as ApplySite:
503-
if let callee = apply.referencedFunction {
504-
pushIfNotVisited(callee)
502+
case let fri as FunctionRefInst:
503+
pushIfNotVisited(fri.referencedFunction)
504+
case let alloc as AllocRefInst:
505+
if context.options.enableEmbeddedSwift {
506+
addVTableMethods(forClassType: alloc.type, context)
505507
}
506-
case let bi as BuiltinInst:
507-
switch bi.id {
508-
case .Once, .OnceWithContext:
509-
if let fri = bi.operands[1].value as? FunctionRefInst {
510-
pushIfNotVisited(fri.referencedFunction)
508+
case let metatype as MetatypeInst:
509+
if context.options.enableEmbeddedSwift {
510+
let instanceType = metatype.type.loweredInstanceTypeOfMetatype(in: function)
511+
if instanceType.isClass {
512+
addVTableMethods(forClassType: instanceType, context)
511513
}
512-
break;
513-
default:
514-
break
515514
}
515+
516516
default:
517517
break
518518
}
519519
}
520520
}
521521

522+
mutating func addVTableMethods(forClassType classType: Type, _ context: ModulePassContext) {
523+
guard let vtable = classType.isGenericAtAnyLevel ?
524+
context.lookupSpecializedVTable(for: classType) :
525+
context.lookupVTable(for: classType.nominal!)
526+
else {
527+
return
528+
}
529+
for entry in vtable.entries where !entry.implementation.isGeneric {
530+
pushIfNotVisited(entry.implementation)
531+
}
532+
}
533+
522534
mutating func addWitnessMethods(of witnessTable: WitnessTable) {
523535
for entry in witnessTable.entries {
524536
if case .method(_, let witness) = entry,

include/swift/AST/ASTBridging.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,6 +1744,19 @@ BridgedImportDecl BridgedImportDecl_createParsed(
17441744
BridgedSourceLoc cImportKeywordLoc, BridgedImportKind cImportKind,
17451745
BridgedSourceLoc cImportKindLoc, BridgedArrayRef cImportPathElements);
17461746

1747+
enum ENUM_EXTENSIBILITY_ATTR(open) BridgedUsingSpecifier {
1748+
BridgedUsingSpecifierMainActor,
1749+
BridgedUsingSpecifierNonisolated,
1750+
};
1751+
1752+
SWIFT_NAME("BridgedUsingDecl.createParsed(_:declContext:usingKeywordLoc:"
1753+
"specifierLoc:specifier:)")
1754+
BridgedUsingDecl BridgedUsingDecl_createParsed(BridgedASTContext cContext,
1755+
BridgedDeclContext cDeclContext,
1756+
BridgedSourceLoc usingKeywordLoc,
1757+
BridgedSourceLoc specifierLoc,
1758+
BridgedUsingSpecifier specifier);
1759+
17471760
SWIFT_NAME("BridgedSubscriptDecl.createParsed(_:declContext:staticLoc:"
17481761
"staticSpelling:subscriptKeywordLoc:genericParamList:parameterList:"
17491762
"arrowLoc:returnType:genericWhereClause:)")

include/swift/AST/Decl.h

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ enum class DescriptiveDeclKind : uint8_t {
213213
OpaqueResultType,
214214
OpaqueVarType,
215215
Macro,
216-
MacroExpansion
216+
MacroExpansion,
217+
Using
217218
};
218219

219220
/// Describes which spelling was used in the source for the 'static' or 'class'
@@ -267,6 +268,16 @@ static_assert(uint8_t(SelfAccessKind::LastSelfAccessKind) <
267268
"Self Access Kind is too small to fit in SelfAccess kind bits. "
268269
"Please expand ");
269270

271+
enum class UsingSpecifier : uint8_t {
272+
MainActor,
273+
Nonisolated,
274+
LastSpecifier = Nonisolated,
275+
};
276+
enum : unsigned {
277+
NumUsingSpecifierBits =
278+
countBitsUsed(static_cast<unsigned>(UsingSpecifier::LastSpecifier))
279+
};
280+
270281
/// Diagnostic printing of \c SelfAccessKind.
271282
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, SelfAccessKind SAK);
272283

@@ -827,6 +838,10 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl>, public Swi
827838
NumPathElements : 8
828839
);
829840

841+
SWIFT_INLINE_BITFIELD(UsingDecl, Decl, NumUsingSpecifierBits,
842+
Specifier : NumUsingSpecifierBits
843+
);
844+
830845
SWIFT_INLINE_BITFIELD(ExtensionDecl, Decl, 4+1,
831846
/// An encoding of the default and maximum access level for this extension.
832847
/// The value 4 corresponds to AccessLevel::Public
@@ -9737,6 +9752,34 @@ class MacroExpansionDecl : public Decl, public FreestandingMacroExpansion {
97379752
}
97389753
};
97399754

9755+
/// UsingDecl - This represents a single `using` declaration, e.g.:
9756+
/// using @MainActor
9757+
class UsingDecl : public Decl {
9758+
friend class Decl;
9759+
9760+
private:
9761+
SourceLoc UsingLoc, SpecifierLoc;
9762+
9763+
UsingDecl(SourceLoc usingLoc, SourceLoc specifierLoc,
9764+
UsingSpecifier specifier, DeclContext *parent);
9765+
9766+
public:
9767+
UsingSpecifier getSpecifier() const {
9768+
return static_cast<UsingSpecifier>(Bits.UsingDecl.Specifier);
9769+
}
9770+
9771+
std::string getSpecifierName() const;
9772+
9773+
SourceLoc getLocFromSource() const { return UsingLoc; }
9774+
SourceRange getSourceRange() const { return {UsingLoc, SpecifierLoc}; }
9775+
9776+
static UsingDecl *create(ASTContext &ctx, SourceLoc usingLoc,
9777+
SourceLoc specifierLoc, UsingSpecifier specifier,
9778+
DeclContext *parent);
9779+
9780+
static bool classof(const Decl *D) { return D->getKind() == DeclKind::Using; }
9781+
};
9782+
97409783
inline void
97419784
AbstractStorageDecl::overwriteSetterAccess(AccessLevel accessLevel) {
97429785
Accessors.setInt(accessLevel);

include/swift/AST/DeclExportabilityVisitor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ class DeclExportabilityVisitor
158158
UNREACHABLE(MissingMember);
159159
UNREACHABLE(GenericTypeParam);
160160
UNREACHABLE(Param);
161+
UNREACHABLE(Using);
161162

162163
#undef UNREACHABLE
163164

include/swift/AST/DeclNodes.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ DECL(Missing, Decl)
190190
DECL(MissingMember, Decl)
191191
DECL(PatternBinding, Decl)
192192
DECL(EnumCase, Decl)
193+
DECL(Using, Decl)
193194

194195
ABSTRACT_DECL(Operator, Decl)
195196
OPERATOR_DECL(InfixOperator, OperatorDecl)

include/swift/AST/DiagnosticsParse.def

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2187,5 +2187,14 @@ ERROR(nonisolated_nonsending_expected_rparen,PointsToFirstBadToken,
21872187
ERROR(nonisolated_nonsending_repeated,none,
21882188
"parameter may have at most one 'nonisolated(nonsending)' specifier", ())
21892189

2190+
//------------------------------------------------------------------------------
2191+
// MARK: using @<attribute> or using <identifier>
2192+
//------------------------------------------------------------------------------
2193+
ERROR(using_decl_invalid_specifier,PointsToFirstBadToken,
2194+
"default isolation can only be set to '@MainActor' or 'nonisolated'",
2195+
())
2196+
ERROR(experimental_using_decl_disabled,PointsToFirstBadToken,
2197+
"'using' is an experimental feature that is currently disabled", ())
2198+
21902199
#define UNDEFINE_DIAGNOSTIC_MACROS
21912200
#include "DefineDiagnosticMacros.h"

include/swift/AST/DiagnosticsSema.def

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8293,8 +8293,8 @@ ERROR(lifetime_dependence_immortal_alone, none,
82938293
"cannot specify any other dependence source along with immortal", ())
82948294
ERROR(lifetime_dependence_invalid_inherit_escapable_type, none,
82958295
"cannot copy the lifetime of an Escapable type, use "
8296-
"'@lifetime(borrow %0)' instead",
8297-
(StringRef))
8296+
"'@lifetime(%1%0)' instead",
8297+
(StringRef, StringRef))
82988298
ERROR(lifetime_dependence_cannot_use_parsed_borrow_consuming, none,
82998299
"invalid use of %0 dependence with %1 ownership",
83008300
(StringRef, StringRef))
@@ -8782,5 +8782,13 @@ ERROR(extensible_attr_on_internal_type,none,
87828782
ERROR(pre_enum_extensibility_without_extensible,none,
87838783
"%0 can only be used together with '@extensible' attribute", (DeclAttribute))
87848784

8785+
//===----------------------------------------------------------------------===//
8786+
// MARK: `using` declaration
8787+
//===----------------------------------------------------------------------===//
8788+
ERROR(invalid_redecl_of_file_isolation,none,
8789+
"invalid redeclaration of file-level default actor isolation", ())
8790+
NOTE(invalid_redecl_of_file_isolation_prev,none,
8791+
"default isolation was previously declared here", ())
8792+
87858793
#define UNDEFINE_DIAGNOSTIC_MACROS
87868794
#include "DefineDiagnosticMacros.h"

include/swift/AST/SourceFile.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class GeneratedSourceInfo;
3232
class PersistentParserState;
3333
struct SourceFileExtras;
3434
class Token;
35+
enum class DefaultIsolation : uint8_t;
3536

3637
/// Kind of import affecting how a decl can be reexported.
3738
///
@@ -690,6 +691,11 @@ class SourceFile final : public FileUnit {
690691
DelayedParserState = std::move(state);
691692
}
692693

694+
/// Retrieve default action isolation to be used for this source file.
695+
/// It's determine based on on top-level `using <<isolation>>` declaration
696+
/// found in the file.
697+
std::optional<DefaultIsolation> getDefaultIsolation() const;
698+
693699
SWIFT_DEBUG_DUMP;
694700
void
695701
dump(raw_ostream &os,

0 commit comments

Comments
 (0)