Skip to content

Commit 19f0e1d

Browse files
authored
Merge pull request #4091 from swiftwasm/main
[pull] swiftwasm from main
2 parents 433ad32 + 648d256 commit 19f0e1d

File tree

84 files changed

+427
-245
lines changed

Some content is hidden

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

84 files changed

+427
-245
lines changed

SwiftCompilerSources/Sources/SIL/Instruction.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,10 @@ final public class DeallocStackInst : Instruction, UnaryInstruction {
208208
}
209209
}
210210

211+
final public class DeallocStackRefInst : Instruction, UnaryInstruction {
212+
public var allocRef: AllocRefInst { operand as! AllocRefInst }
213+
}
214+
211215
final public class CondFailInst : Instruction, UnaryInstruction {
212216
public override var mayTrap: Bool { true }
213217

SwiftCompilerSources/Sources/SIL/Registration.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public func registerSILClasses() {
4242
register(EndAccessInst.self)
4343
register(EndBorrowInst.self)
4444
register(DeallocStackInst.self)
45+
register(DeallocStackRefInst.self)
4546
register(CondFailInst.self)
4647
register(FixLifetimeInst.self)
4748
register(DebugValueInst.self)

docs/ABI/Mangling.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,15 +737,17 @@ implementation details of a function type.
737737
::
738738

739739
#if SWIFT_VERSION >= 5.1
740-
type ::= 'Qr' // opaque result type (of current decl)
740+
type ::= 'Qr' // opaque result type (of current decl, used for the first opaque type parameter only)
741+
type ::= 'QR' INDEX // same as above, for subsequent opaque type parameters, INDEX is the ordinal -1
741742
type ::= opaque-type-decl-name bound-generic-args 'Qo' INDEX // opaque type
742743

743744
opaque-type-decl-name ::= entity 'QO' // opaque result type of specified decl
744745
#endif
745746

746747
#if SWIFT_VERSION >= 5.4
747-
type ::= 'Qu' // opaque result type (of current decl)
748+
type ::= 'Qu' // opaque result type (of current decl, first param)
748749
// used for ObjC class runtime name purposes.
750+
type ::= 'QU' INDEX
749751
#endif
750752

751753
Opaque return types have a special short representation in the mangling of

docs/SIL.rst

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3143,8 +3143,8 @@ optional ``objc`` attribute indicates that the object should be
31433143
allocated using Objective-C's allocation methods (``+allocWithZone:``).
31443144

31453145
The optional ``stack`` attribute indicates that the object can be allocated
3146-
on the stack instead on the heap. In this case the instruction must have
3147-
balanced with a ``dealloc_ref [stack]`` instruction to mark the end of the
3146+
on the stack instead on the heap. In this case the instruction must be
3147+
balanced with a ``dealloc_stack_ref`` instruction to mark the end of the
31483148
object's lifetime.
31493149
Note that the ``stack`` attribute only specifies that stack allocation is
31503150
possible. The final decision on stack allocation is done during llvm IR
@@ -3381,13 +3381,25 @@ project_box
33813381

33823382
Given a ``@box T`` reference, produces the address of the value inside the box.
33833383

3384+
dealloc_stack_ref
3385+
`````````````````
3386+
::
3387+
3388+
sil-instruction ::= 'dealloc_stack_ref' sil-operand
3389+
3390+
dealloc_stack_ref %0 : $T
3391+
// $T must be a class type
3392+
// %0 must be an 'alloc_ref [stack]' instruction
3393+
3394+
Marks the deallocation of the stack space for an ``alloc_ref [stack]``.
3395+
33843396
dealloc_ref
33853397
```````````
33863398
::
33873399

3388-
sil-instruction ::= 'dealloc_ref' ('[' 'stack' ']')? sil-operand
3400+
sil-instruction ::= 'dealloc_ref' sil-operand
33893401

3390-
dealloc_ref [stack] %0 : $T
3402+
dealloc_ref %0 : $T
33913403
// $T must be a class type
33923404

33933405
Deallocates an uninitialized class type instance, bypassing the reference

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,6 +1514,9 @@ ERROR(access_control_extension_open,none,
15141514
ERROR(access_control_open_bad_decl,none,
15151515
"only classes and overridable class members can be declared 'open';"
15161516
" use 'public'", ())
1517+
WARNING(access_control_non_objc_open_member,none,
1518+
"non-'@objc' %0 in extensions cannot be overridden; use 'public' instead",
1519+
(DescriptiveDeclKind))
15171520

15181521
ERROR(invalid_decl_attribute,none,
15191522
"'%0' attribute cannot be applied to this declaration", (DeclAttribute))

include/swift/Demangling/DemangleNodes.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,5 +329,8 @@ NODE(AsyncSuspendResumePartialFunction)
329329
// Added in Swift 5.6
330330
NODE(AccessibleFunctionRecord)
331331

332+
// Added in Swift 5.7
333+
NODE(OpaqueReturnTypeIndexed)
334+
332335
#undef CONTEXT_NODE
333336
#undef NODE

include/swift/SIL/SILBuilder.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2005,10 +2005,14 @@ class SILBuilder {
20052005
return insert(new (getModule())
20062006
DeallocStackInst(getSILDebugLocation(Loc), operand));
20072007
}
2008-
DeallocRefInst *createDeallocRef(SILLocation Loc, SILValue operand,
2009-
bool canBeOnStack) {
2008+
DeallocStackRefInst *createDeallocStackRef(SILLocation Loc,
2009+
SILValue operand) {
2010+
return insert(new (getModule())
2011+
DeallocStackRefInst(getSILDebugLocation(Loc), operand));
2012+
}
2013+
DeallocRefInst *createDeallocRef(SILLocation Loc, SILValue operand) {
20102014
return insert(new (getModule()) DeallocRefInst(
2011-
getSILDebugLocation(Loc), operand, canBeOnStack));
2015+
getSILDebugLocation(Loc), operand));
20122016
}
20132017
DeallocPartialRefInst *createDeallocPartialRef(SILLocation Loc,
20142018
SILValue operand,

include/swift/SIL/SILCloner.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2488,8 +2488,16 @@ SILCloner<ImplClass>::visitDeallocRefInst(DeallocRefInst *Inst) {
24882488
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
24892489
recordClonedInstruction(
24902490
Inst, getBuilder().createDeallocRef(getOpLocation(Inst->getLoc()),
2491-
getOpValue(Inst->getOperand()),
2492-
Inst->canAllocOnStack()));
2491+
getOpValue(Inst->getOperand())));
2492+
}
2493+
2494+
template<typename ImplClass>
2495+
void
2496+
SILCloner<ImplClass>::visitDeallocStackRefInst(DeallocStackRefInst *Inst) {
2497+
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
2498+
recordClonedInstruction(
2499+
Inst, getBuilder().createDeallocStackRef(getOpLocation(Inst->getLoc()),
2500+
getOpValue(Inst->getOperand())));
24932501
}
24942502

24952503
template<typename ImplClass>

include/swift/SIL/SILInstruction.h

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7619,6 +7619,18 @@ class DeallocStackInst :
76197619
: UnaryInstructionBase(DebugLoc, operand) {}
76207620
};
76217621

7622+
/// Like DeallocStackInst, but for `alloc_ref [stack]`.
7623+
class DeallocStackRefInst
7624+
: public UnaryInstructionBase<SILInstructionKind::DeallocStackRefInst,
7625+
DeallocationInst> {
7626+
friend SILBuilder;
7627+
7628+
DeallocStackRefInst(SILDebugLocation DebugLoc, SILValue Operand)
7629+
: UnaryInstructionBase(DebugLoc, Operand) {}
7630+
public:
7631+
AllocRefInst *getAllocRef() { return cast<AllocRefInst>(getOperand()); }
7632+
};
7633+
76227634
/// Deallocate memory for a reference type instance from a destructor or
76237635
/// failure path of a constructor.
76247636
///
@@ -7632,21 +7644,8 @@ class DeallocRefInst :
76327644
DeallocationInst> {
76337645
friend SILBuilder;
76347646

7635-
private:
7636-
DeallocRefInst(SILDebugLocation DebugLoc, SILValue Operand,
7637-
bool canBeOnStack = false)
7638-
: UnaryInstructionBase(DebugLoc, Operand) {
7639-
SILNode::Bits.DeallocRefInst.OnStack = canBeOnStack;
7640-
}
7641-
7642-
public:
7643-
bool canAllocOnStack() const {
7644-
return SILNode::Bits.DeallocRefInst.OnStack;
7645-
}
7646-
7647-
void setStackAllocatable(bool OnStack) {
7648-
SILNode::Bits.DeallocRefInst.OnStack = OnStack;
7649-
}
7647+
DeallocRefInst(SILDebugLocation DebugLoc, SILValue Operand)
7648+
: UnaryInstructionBase(DebugLoc, Operand) { }
76507649
};
76517650

76527651
/// Deallocate memory for a reference type instance from a failure path of a

include/swift/SIL/SILNode.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,6 @@ class alignas(8) SILNode :
218218
Length : 32
219219
);
220220

221-
SWIFT_INLINE_BITFIELD(DeallocRefInst, DeallocationInst, 1,
222-
OnStack : 1
223-
);
224-
225221
// Ensure that AllocBoxInst bitfield does not overflow.
226222
IBWTO_BITFIELD_EMPTY(AllocBoxInst, AllocationInst);
227223
// Ensure that AllocExistentialBoxInst bitfield does not overflow.

include/swift/SIL/SILNodes.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,8 @@ ABSTRACT_INST(TermInst, SILInstruction)
808808
ABSTRACT_INST(DeallocationInst, SILInstruction)
809809
BRIDGED_NON_VALUE_INST(DeallocStackInst, dealloc_stack,
810810
DeallocationInst, MayHaveSideEffects, DoesNotRelease)
811+
BRIDGED_NON_VALUE_INST(DeallocStackRefInst, dealloc_stack_ref,
812+
DeallocationInst, MayHaveSideEffects, DoesNotRelease)
811813
BRIDGED_NON_VALUE_INST(DeallocRefInst, dealloc_ref,
812814
DeallocationInst, MayHaveSideEffects, DoesNotRelease)
813815
NON_VALUE_INST(DeallocPartialRefInst, dealloc_partial_ref,

include/swift/SILOptimizer/Utils/ValueLifetime.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ class ValueLifetimeAnalysis {
197197
(hasUsersBeforeDef || bb != getDefValueParentBlock());
198198
}
199199

200-
/// Checks if there is a dealloc_ref inside the value's live range.
200+
/// Checks if there is a dealloc_ref or dealloc_stack_ref inside the
201+
/// value's live range.
201202
bool containsDeallocRef(const FrontierImpl &frontier);
202203

203204
/// For debug dumping.

lib/AST/ASTMangler.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -831,9 +831,11 @@ std::string ASTMangler::mangleOpaqueTypeDecl(const OpaqueTypeDecl *decl) {
831831
}
832832

833833
std::string ASTMangler::mangleOpaqueTypeDecl(const ValueDecl *decl) {
834-
DWARFMangling = true;
835834
OptimizeProtocolNames = false;
836-
return mangleDeclAsUSR(decl, MANGLING_PREFIX_STR);
835+
836+
beginMangling();
837+
appendEntity(decl);
838+
return finalize();
837839
}
838840

839841
std::string ASTMangler::mangleGenericSignature(const GenericSignature sig) {
@@ -1318,7 +1320,10 @@ void ASTMangler::appendType(Type type, GenericSignature sig,
13181320
auto opaqueDecl = opaqueType->getDecl();
13191321
if (opaqueDecl->getNamingDecl() == forDecl) {
13201322
assert(opaqueType->getSubstitutions().isIdentity());
1321-
return appendOperator("Qr");
1323+
if (opaqueType->getOrdinal() == 0)
1324+
return appendOperator("Qr");
1325+
1326+
return appendOperator("QR", Index(opaqueType->getOrdinal() - 1));
13221327
}
13231328

13241329
// Otherwise, try to substitute it.
@@ -1358,7 +1363,8 @@ void ASTMangler::appendType(Type type, GenericSignature sig,
13581363
addTypeSubstitution(nestedType, sig);
13591364
return;
13601365
}
1361-
1366+
1367+
// FIXME: Never actually used.
13621368
appendType(nestedType->getParent(), sig, forDecl);
13631369
appendIdentifier(nestedType->getName().str());
13641370
appendOperator("Qa");

lib/AST/Decl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2943,7 +2943,9 @@ TypeRepr *ValueDecl::getOpaqueResultTypeRepr() const {
29432943

29442944
OpaqueTypeDecl *ValueDecl::getOpaqueResultTypeDecl() const {
29452945
if (getOpaqueResultTypeRepr() == nullptr) {
2946-
if (isa<ModuleDecl>(this))
2946+
if (!isa<VarDecl>(this) &&
2947+
!isa<FuncDecl>(this) &&
2948+
!isa<SubscriptDecl>(this))
29472949
return nullptr;
29482950
auto file = cast<FileUnit>(getDeclContext()->getModuleScopeContext());
29492951
// Don't look up when the decl is from source, otherwise a cycle will happen.

lib/ClangImporter/ImportDecl.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9866,13 +9866,21 @@ void ClangImporter::Implementation::loadAllMembersOfRecordDecl(
98669866
llvm::SmallVector<Decl *, 16> members;
98679867
for (const clang::Decl *m : clangRecord->decls()) {
98689868
auto nd = dyn_cast<clang::NamedDecl>(m);
9869+
if (!nd)
9870+
continue;
9871+
98699872
// Currently, we don't import unnamed bitfields.
98709873
if (isa<clang::FieldDecl>(m) &&
98719874
cast<clang::FieldDecl>(m)->isUnnamedBitfield())
98729875
continue;
98739876

9874-
if (nd && nd == nd->getCanonicalDecl() &&
9875-
nd->getDeclContext() == clangRecord &&
9877+
// Make sure we always pull in record fields. Everything else had better
9878+
// be canonical. Note that this check mostly catches nested C++ types since
9879+
// we import nested C struct types by C's usual convention of chucking them
9880+
// into the global namespace.
9881+
const bool isCanonicalInContext =
9882+
(isa<clang::FieldDecl>(nd) || nd == nd->getCanonicalDecl());
9883+
if (isCanonicalInContext && nd->getDeclContext() == clangRecord &&
98769884
isVisibleClangEntry(nd))
98779885
insertMembersAndAlternates(nd, members);
98789886
}

lib/Demangling/Demangler.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2206,6 +2206,12 @@ NodePointer Demangler::demangleArchetype() {
22062206
case 'r': {
22072207
return createType(createNode(Node::Kind::OpaqueReturnType));
22082208
}
2209+
case 'R': {
2210+
int ordinal = demangleIndex();
2211+
if (ordinal < 0)
2212+
return NULL;
2213+
return createType(createNode(Node::Kind::OpaqueReturnTypeIndexed, ordinal));
2214+
}
22092215

22102216
case 'x': {
22112217
NodePointer T = demangleAssociatedTypeSimple(nullptr);

lib/Demangling/NodePrinter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ class NodePrinter {
568568
case Node::Kind::OpaqueType:
569569
case Node::Kind::OpaqueTypeDescriptorSymbolicReference:
570570
case Node::Kind::OpaqueReturnType:
571+
case Node::Kind::OpaqueReturnTypeIndexed:
571572
case Node::Kind::OpaqueReturnTypeOf:
572573
case Node::Kind::CanonicalSpecializedGenericMetaclass:
573574
case Node::Kind::CanonicalSpecializedGenericTypeMetadataAccessFunction:
@@ -2817,6 +2818,7 @@ NodePointer NodePrinter::print(NodePointer Node, unsigned depth,
28172818
Printer << ")";
28182819
return nullptr;
28192820
case Node::Kind::OpaqueReturnType:
2821+
case Node::Kind::OpaqueReturnTypeIndexed:
28202822
Printer << "some";
28212823
return nullptr;
28222824
case Node::Kind::OpaqueReturnTypeOf:

lib/Demangling/OldDemangler.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2078,6 +2078,13 @@ class OldDemangler {
20782078
// Special mangling for opaque return type.
20792079
return Factory.createNode(Node::Kind::OpaqueReturnType);
20802080
}
2081+
if (Mangled.nextIf('U')) {
2082+
// Special mangling for opaque return type.
2083+
Node::IndexType ordinal;
2084+
if (!demangleIndex(ordinal, depth))
2085+
return nullptr;
2086+
return Factory.createNode(Node::Kind::OpaqueReturnTypeIndexed, ordinal);
2087+
}
20812088
return demangleArchetypeType(depth + 1);
20822089
}
20832090
if (c == 'q') {

lib/Demangling/OldRemangler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2643,6 +2643,11 @@ ManglingError Remangler::mangleOpaqueReturnType(Node *node, unsigned depth) {
26432643
Buffer << "Qu";
26442644
return ManglingError::Success;
26452645
}
2646+
ManglingError Remangler::mangleOpaqueReturnTypeIndexed(Node *node, unsigned depth) {
2647+
Buffer << "QU";
2648+
mangleIndex(node->getIndex());
2649+
return ManglingError::Success;
2650+
}
26462651
ManglingError Remangler::mangleOpaqueReturnTypeOf(Node *node,
26472652
EntityContext &ctx,
26482653
unsigned depth) {

lib/Demangling/Remangler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3280,6 +3280,11 @@ ManglingError Remangler::mangleOpaqueReturnType(Node *node, unsigned depth) {
32803280
Buffer << "Qr";
32813281
return ManglingError::Success;
32823282
}
3283+
ManglingError Remangler::mangleOpaqueReturnTypeIndexed(Node *node, unsigned depth) {
3284+
Buffer << "QR";
3285+
mangleIndex(node->getIndex());
3286+
return ManglingError::Success;
3287+
}
32833288
ManglingError Remangler::mangleOpaqueReturnTypeOf(Node *node, unsigned depth) {
32843289
RETURN_IF_ERROR(mangle(node->getChild(0), depth + 1));
32853290
Buffer << "QO";

0 commit comments

Comments
 (0)