Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
504b76a
[Macros] Add test using observer accessors (didSet/willSet) with Obse…
DougGregor Jun 17, 2023
b08eb62
Rename SinkAddressProjections::projections -> SinkAddressProjections:…
meg-gupta May 31, 2023
56629e1
Verify we don't have any address phis
meg-gupta May 31, 2023
37d8586
Update SILSSAUpdater::areIdentical to check for SILArgument
meg-gupta Jun 21, 2023
46bed7c
Add SinkAddressProjections::newProjections
meg-gupta Jun 21, 2023
1e89ad6
Sink address projections in ArrayPropertyOpt so that there are no add…
meg-gupta Jun 21, 2023
7964918
[cxx-interop] Fix sema lookup scope so we find NSNotification interfa…
zoecarver May 31, 2023
7216be1
[cxx-interop] A little macros fix; breadcrumbs for future fixes.
zoecarver May 31, 2023
7d47cb9
[cxx-interop] fix how we import CF types.
zoecarver May 31, 2023
e5ece81
[Freestanding] Remove uses of stat() and dlsym().
al45tair Jun 23, 2023
92fd8da
[FieldSensitivePL] Fixed use-before-def handling.
nate-chandler Jun 20, 2023
7c1e5ec
[SIL] NFC: Added debug printing of block ids.
nate-chandler Jun 23, 2023
7322ccb
[FieldSensitivePL] NFC: Added unit tests.
nate-chandler Jun 19, 2023
9606a9a
[ASTPrinter] Stop unnecessary escaping of `init` in macro role attrib…
DougGregor Jun 23, 2023
e89fdd3
Requestify the computation of the list of memberwise initialized prop…
DougGregor Jun 22, 2023
a1464cf
Correctly remove properties subsumed by init accessors from memberwis…
DougGregor Jun 22, 2023
7ed59e1
Reimplement InitAccessorPropertiesRequest on top of MemberwiseInitPro…
DougGregor Jun 22, 2023
2114833
[nfc] Fix notification test
zoecarver Jun 8, 2023
6da1df2
Merge pull request #66825 from meg-gupta/addressphilast
meg-gupta Jun 23, 2023
31e0252
Make sure we query `hasInitAccessor` before looking for the init acce…
DougGregor Jun 23, 2023
4b1a1e7
Merge pull request #66889 from DougGregor/init-accessor-stop-escaping…
DougGregor Jun 23, 2023
8eff2e8
[LifetimeExtension] Handle use-before-def.
nate-chandler Jun 23, 2023
ff7aa3c
[LifetimeExtension] Fixed reinit collection.
nate-chandler Jun 23, 2023
e197c00
Merge pull request #66883 from al45tair/eng/PR-111214571
al45tair Jun 23, 2023
606db01
Merge pull request #66730 from DougGregor/observable-willset-didset
DougGregor Jun 23, 2023
995c41c
Merge pull request #66826 from nate-chandler/rdar110862719
swift-ci Jun 23, 2023
3ddab3e
Merge pull request #66897 from zoecarver/fix-scope-when-lookup
zoecarver Jun 23, 2023
a44c77d
Merge pull request #66867 from DougGregor/requestify-member-init-prop…
DougGregor Jun 24, 2023
270089f
[IRGen+Runtime] Layout string getEnumTag for fixed size enums subset …
drexin Jun 24, 2023
0a2defe
[Concurrency] Fix code snippet on task group docs
ktoso Jun 24, 2023
98d895d
Merge pull request #66892 from nate-chandler/rdar111221183
nate-chandler Jun 24, 2023
253d8fb
[IRGen+Runtime] Add getEnumTag for layout strings on generic single p…
drexin Jun 24, 2023
da34a4e
Merge pull request #66912 from apple/ktoso-patch-15
ktoso Jun 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,11 @@ option(SWIFT_THREADING_PACKAGE
Valid package names are 'pthreads', 'darwin', 'linux', 'win32', 'c11', 'none'
or the empty string for the SDK default.")

option(SWIFT_THREADING_HAS_DLSYM
"Enable the use of the dlsym() function. This gets used to provide TSan
support on some platforms."
TRUE)

option(SWIFT_ENABLE_MACCATALYST
"Build the Standard Library and overlays with MacCatalyst support"
FALSE)
Expand Down
9 changes: 8 additions & 1 deletion cmake/modules/AddSwiftUnittests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,19 @@ function(add_swift_unittest test_dirname)
endif()

# some headers switch their inline implementations based on
# SWIFT_STDLIB_SINGLE_THREADED_CONCURRENCY and
# SWIFT_STDLIB_SINGLE_THREADED_CONCURRENCY, SWIFT_STDLIB_HAS_DLSYM and
# SWIFT_THREADING_PACKAGE definitions
if(SWIFT_STDLIB_SINGLE_THREADED_CONCURRENCY)
target_compile_definitions("${test_dirname}" PRIVATE
SWIFT_STDLIB_SINGLE_THREADED_CONCURRENCY)
endif()
if(SWIFT_STDLIB_HAS_DLSYM)
target_compile_definitions("${test_dirname}" PRIVATE
"SWIFT_STDLIB_HAS_DLSYM=1")
else()
target_compile_definitions("${test_dirname}" PRIVATE
"SWIFT_STDLIB_HAS_DLSYM=0")
endif()

string(TOUPPER "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_THREADING_PACKAGE}" _threading_package)
target_compile_definitions("${test_dirname}" PRIVATE
Expand Down
4 changes: 4 additions & 0 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -3995,6 +3995,10 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
/// this type.
ArrayRef<VarDecl *> getInitAccessorProperties() const;

/// Return a collection of all properties that will be part of the memberwise
/// initializer.
ArrayRef<VarDecl *> getMemberwiseInitProperties() const;

/// Establish a mapping between properties that could be iniitalized
/// via other properties by means of init accessors. This mapping is
/// one-to-many because we allow intersecting `initializes(...)`.
Expand Down
16 changes: 15 additions & 1 deletion include/swift/AST/DeclContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -850,9 +850,23 @@ class IterableDeclContext {
HasNestedClassDeclarations = 1;
}

/// Retrieve the set of members in this context.
/// Retrieve the current set of members in this context.
///
/// NOTE: This operation is an alias of \c getCurrentMembers() that is considered
/// deprecated. Most clients should not use this or \c getCurrentMembers(), but
/// instead should use one of the projections of members that provides a semantic
/// view, e.g., \c getParsedMembers(), \c getABIMembers(), \c getAllMembers(), and so
/// on.
DeclRange getMembers() const;

/// Retrieve the current set of members in this context, without triggering the
/// creation of new members via code synthesis, macro expansion, etc.
///
/// This operation should only be used in narrow places where any side-effect
/// producing operations have been done earlier. For the most part, this means that
/// it should only be used in the implementation of
DeclRange getCurrentMembers() const;

/// Get the members that were syntactically present in the source code,
/// and will not contain any members that are implicitly synthesized by
/// the implementation.
Expand Down
22 changes: 22 additions & 0 deletions include/swift/AST/TypeCheckRequests.h
Original file line number Diff line number Diff line change
Expand Up @@ -1693,6 +1693,28 @@ class InitAccessorPropertiesRequest :
bool isCached() const { return true; }
};

/// Request to obtain a list of properties that will be reflected in the parameters of a
/// memberwise initializer.
class MemberwiseInitPropertiesRequest :
public SimpleRequest<MemberwiseInitPropertiesRequest,
ArrayRef<VarDecl *>(NominalTypeDecl *),
RequestFlags::Cached> {
public:
using SimpleRequest::SimpleRequest;

private:
friend SimpleRequest;

ArrayRef<VarDecl *>
evaluate(Evaluator &evaluator, NominalTypeDecl *decl) const;

// Evaluation.
bool evaluate(Evaluator &evaluator, AbstractStorageDecl *decl) const;

public:
bool isCached() const { return true; }
};

class HasStorageRequest :
public SimpleRequest<HasStorageRequest,
bool(AbstractStorageDecl *),
Expand Down
3 changes: 3 additions & 0 deletions include/swift/AST/TypeCheckerTypeIDZone.def
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ SWIFT_REQUEST(TypeChecker, StoredPropertiesRequest,
SWIFT_REQUEST(TypeChecker, InitAccessorPropertiesRequest,
ArrayRef<VarDecl *>(NominalTypeDecl *),
Cached, NoLocationInfo)
SWIFT_REQUEST(TypeChecker, MemberwiseInitPropertiesRequest,
ArrayRef<VarDecl *>(NominalTypeDecl *),
Cached, NoLocationInfo)
SWIFT_REQUEST(TypeChecker, StructuralTypeRequest, Type(TypeAliasDecl *), Cached,
NoLocationInfo)
SWIFT_REQUEST(TypeChecker, SuperclassTypeRequest,
Expand Down
5 changes: 1 addition & 4 deletions include/swift/AST/TypeMemberVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ class TypeMemberVisitor : public DeclVisitor<ImplClass, RetTy> {

/// A convenience method to visit all the members.
void visitMembers(NominalTypeDecl *D) {
for (Decl *member : D->getMembers()) {
member->visitAuxiliaryDecls([&](Decl *decl) {
asImpl().visit(decl);
});
for (Decl *member : D->getAllMembers()) {
asImpl().visit(member);
}
}
Expand Down
23 changes: 22 additions & 1 deletion include/swift/Runtime/RuntimeFunctions.def
Original file line number Diff line number Diff line change
Expand Up @@ -2315,6 +2315,16 @@ FUNCTION(GenericInitWithTake,
ATTRS(NoUnwind),
EFFECT(Refcounting))

// unsigned swift_enumFn_getEnumTag(swift::OpaqueValue *address,
// const Metadata *metadata);
FUNCTION(EnumFnGetEnumTag,
swift_enumFn_getEnumTag,
C_CC, AlwaysAvailable,
RETURNS(Int32Ty),
ARGS(Int8PtrTy, TypeMetadataPtrTy),
ATTRS(NoUnwind),
EFFECT(NoEffect))

// unsigned swift_multiPayloadEnumGeneric_getEnumTag(opaque* address,
// const Metadata *type);
FUNCTION(MultiPayloadEnumGenericGetEnumTag,
Expand All @@ -2325,7 +2335,18 @@ FUNCTION(MultiPayloadEnumGenericGetEnumTag,
ATTRS(NoUnwind),
EFFECT(NoEffect))

// void swift_generic_instantiateLayoutString(const uint8_t* layoutStr, Metadata* type);
// unsigned swift_singlePayloadEnumGeneric_getEnumTag(swift::OpaqueValue *address,
// const Metadata *metadata);
FUNCTION(SinglePayloadEnumGenericGetEnumTag,
swift_singlePayloadEnumGeneric_getEnumTag,
C_CC, AlwaysAvailable,
RETURNS(Int32Ty),
ARGS(Int8PtrTy, TypeMetadataPtrTy),
ATTRS(NoUnwind),
EFFECT(NoEffect))

// void swift_generic_instantiateLayoutString(const uint8_t* layoutStr,
// Metadata* type);
FUNCTION(GenericInstantiateLayoutString,
swift_generic_instantiateLayoutString,
C_CC, AlwaysAvailable,
Expand Down
55 changes: 48 additions & 7 deletions include/swift/SIL/FieldSensitivePrunedLiveness.h
Original file line number Diff line number Diff line change
Expand Up @@ -571,19 +571,22 @@ class FieldSensitivePrunedLiveBlocks {
}

/// Update this liveness result for a single use.
IsLive updateForUse(SILInstruction *user, unsigned bitNo) {
IsLive updateForUse(SILInstruction *user, unsigned bitNo,
bool isUserBeforeDef) {
assert(isInitialized());
auto *block = user->getParent();
auto liveness = getBlockLiveness(block, bitNo);
if (liveness != Dead)
return liveness;
if (!isUserBeforeDef) {
auto liveness = getBlockLiveness(block, bitNo);
if (liveness != Dead)
return liveness;
}
computeScalarUseBlockLiveness(block, bitNo);
return getBlockLiveness(block, bitNo);
}

/// Update this range of liveness results for a single use.
void updateForUse(SILInstruction *user, unsigned startBitNo,
unsigned endBitNo,
unsigned endBitNo, SmallBitVector const &useBeforeDefBits,
SmallVectorImpl<IsLive> &resultingLiveness);

IsLive getBlockLiveness(SILBasicBlock *bb, unsigned bitNo) const {
Expand Down Expand Up @@ -854,10 +857,12 @@ class FieldSensitivePrunedLiveness {
/// Also for flexibility, \p affectedAddress must be a derived projection from
/// the base that \p user is affecting.
void updateForUse(SILInstruction *user, TypeTreeLeafTypeRange span,
bool lifetimeEnding);
bool lifetimeEnding,
SmallBitVector const &useBeforeDefBits);

void updateForUse(SILInstruction *user, SmallBitVector const &bits,
bool lifetimeEnding);
bool lifetimeEnding,
SmallBitVector const &useBeforeDefBits);

void getBlockLiveness(SILBasicBlock *bb, TypeTreeLeafTypeRange span,
SmallVectorImpl<FieldSensitivePrunedLiveBlocks::IsLive>
Expand Down Expand Up @@ -1160,6 +1165,12 @@ class FieldSensitiveSSAPrunedLiveRange
return def.first->getParentBlock() == block && def.second->contains(bit);
}

template <typename Iterable>
void isUserBeforeDef(SILInstruction *user, Iterable const &iterable,
SmallBitVector &useBeforeDefBits) const {
assert(useBeforeDefBits.none());
}

void
findBoundariesInBlock(SILBasicBlock *block, unsigned bitNo, bool isLiveOut,
FieldSensitivePrunedLivenessBoundary &boundary) const;
Expand Down Expand Up @@ -1243,6 +1254,36 @@ class FieldSensitiveMultiDefPrunedLiveRange
});
}

bool isDefBlock(SILBasicBlock *block, SmallBitVector const &bits) const {
assert(isInitialized());
auto iter = defBlocks.find(block);
if (!iter)
return false;
return llvm::any_of(*iter, [&](TypeTreeLeafTypeRange storedSpan) {
return storedSpan.intersects(bits);
});
}

/// Return true if \p user occurs before the first def in the same basic
/// block. In classical liveness dataflow terms, gen/kill conditions over all
/// users in 'bb' are:
///
/// Gen(bb) |= !isDefBlock(bb) || isUserBeforeDef(bb)
/// Kill(bb) &= isDefBlock(bb) && !isUserBeforeDef(bb)
///
/// If 'bb' has no users, it is neither a Gen nor Kill. Otherwise, Gen and
/// Kill are complements.
bool isUserBeforeDef(SILInstruction *user, unsigned element) const;
template <typename Iterable>
void isUserBeforeDef(SILInstruction *user, Iterable const &iterable,
SmallBitVector &useBeforeDefBits) const {
for (auto bit : iterable) {
if (isUserBeforeDef(user, bit)) {
useBeforeDefBits.set(bit);
}
}
}

bool isDef(SILInstruction *inst, unsigned bit) const {
assert(isInitialized());
auto iter = defs.find(cast<SILNode>(inst));
Expand Down
11 changes: 11 additions & 0 deletions include/swift/SIL/SILBasicBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,17 @@ public SwiftObjectHeader {

void printAsOperand(raw_ostream &OS, bool PrintType = true);

#ifndef NDEBUG
/// Print the ID of the block, bbN.
void dumpID() const;

/// Print the ID of the block with \p OS, bbN.
void printID(llvm::raw_ostream &OS) const;

/// Print the ID of the block with \p Ctx, bbN.
void printID(SILPrintContext &Ctx) const;
#endif

/// getSublistAccess() - returns pointer to member of instruction list
static InstListType SILBasicBlock::*getSublistAccess() {
return &SILBasicBlock::InstList;
Expand Down
9 changes: 8 additions & 1 deletion include/swift/SILOptimizer/Utils/BasicBlockOptUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,20 @@ bool canCloneTerminator(TermInst *termInst);
/// BasicBlockCloner handles this internally.
class SinkAddressProjections {
// Projections ordered from last to first in the chain.
SmallVector<SingleValueInstruction *, 4> projections;
SmallVector<SingleValueInstruction *, 4> oldProjections;
// Cloned projections to avoid address phis.
SmallVectorImpl<SingleValueInstruction *> *newProjections;
SmallSetVector<SILValue, 4> inBlockDefs;

// Transient per-projection data for use during cloning.
SmallVector<Operand *, 4> usesToReplace;
llvm::SmallDenseMap<SILBasicBlock *, Operand *, 4> firstBlockUse;

public:
SinkAddressProjections(
SmallVectorImpl<SingleValueInstruction *> *newProjections = nullptr)
: newProjections(newProjections) {}

/// Check for an address projection chain ending at \p inst. Return true if
/// the given instruction is successfully analyzed.
///
Expand All @@ -163,6 +169,7 @@ class SinkAddressProjections {
ArrayRef<SILValue> getInBlockDefs() const {
return inBlockDefs.getArrayRef();
}

/// Clone the chain of projections at their use sites.
///
/// Return true if anything was done.
Expand Down
6 changes: 5 additions & 1 deletion include/swift/Threading/ThreadSanitizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@

namespace swift {

#if defined(_WIN32) || defined(__wasi__) || !__has_include(<dlfcn.h>)
#if SWIFT_THREADING_NONE \
|| defined(_WIN32) || defined(__wasi__) \
|| !__has_include(<dlfcn.h>) \
|| (defined(SWIFT_STDLIB_HAS_DLSYM) && !SWIFT_STDLIB_HAS_DLSYM)

#define SWIFT_THREADING_TSAN_SUPPORT 0

Expand All @@ -35,6 +38,7 @@ template <typename T> T *acquire(T *ptr) { return ptr; }
template <typename T> T *release(T *ptr) { return ptr; }

} // namespace tsan

#else

#define SWIFT_THREADING_TSAN_SUPPORT 1
Expand Down
5 changes: 3 additions & 2 deletions lib/AST/Attr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1392,8 +1392,9 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
SmallString<32> buffer;
StringRef nameText = name.getName().getString(buffer);
bool shouldEscape =
escapeKeywordInContext(nameText, PrintNameContext::Normal) ||
nameText == "$";
!name.getName().isSpecial() &&
(escapeKeywordInContext(nameText, PrintNameContext::Normal) ||
nameText == "$");
Printer << "(";
if (shouldEscape)
Printer << "`";
Expand Down
16 changes: 14 additions & 2 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4924,6 +4924,16 @@ NominalTypeDecl::getInitAccessorProperties() const {
{});
}

ArrayRef<VarDecl *>
NominalTypeDecl::getMemberwiseInitProperties() const {
auto &ctx = getASTContext();
auto mutableThis = const_cast<NominalTypeDecl *>(this);
return evaluateOrDefault(
ctx.evaluator,
MemberwiseInitPropertiesRequest{mutableThis},
{});
}

void NominalTypeDecl::collectPropertiesInitializableByInitAccessors(
std::multimap<VarDecl *, VarDecl *> &result) const {
for (auto *property : getInitAccessorProperties()) {
Expand Down Expand Up @@ -7181,8 +7191,10 @@ bool VarDecl::isMemberwiseInitialized(bool preferDeclaredProperties) const {
// If this is a computed property with `init` accessor, it's
// memberwise initializable when it could be used to initialize
// other stored properties.
if (auto *init = getAccessor(AccessorKind::Init))
return init->getAttrs().hasAttribute<InitializesAttr>();
if (hasInitAccessor()) {
if (auto *init = getAccessor(AccessorKind::Init))
return init->getAttrs().hasAttribute<InitializesAttr>();
}

// If this is a computed property, it's not memberwise initialized unless
// the caller has asked for the declared properties and it is either a
Expand Down
4 changes: 4 additions & 0 deletions lib/AST/DeclContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,10 @@ DeclRange IterableDeclContext::getCurrentMembersWithoutLoading() const {
}

DeclRange IterableDeclContext::getMembers() const {
return getCurrentMembers();
}

DeclRange IterableDeclContext::getCurrentMembers() const {
loadAllMembers();

return getCurrentMembersWithoutLoading();
Expand Down
2 changes: 1 addition & 1 deletion lib/ClangImporter/ClangAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ clang::TypedefNameDecl *importer::findSwiftNewtype(const clang::NamedDecl *decl,
clang::LookupResult lookupResult(clangSema, notificationName,
clang::SourceLocation(),
clang::Sema::LookupOrdinaryName);
if (!clangSema.LookupName(lookupResult, nullptr))
if (!clangSema.LookupName(lookupResult, clangSema.TUScope))
return nullptr;
auto nsDecl = lookupResult.getAsSingle<clang::TypedefNameDecl>();
if (!nsDecl)
Expand Down
2 changes: 1 addition & 1 deletion lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2757,7 +2757,7 @@ ClangImporter::Implementation::lookupTypedef(clang::DeclarationName name) {
clang::SourceLocation(),
clang::Sema::LookupOrdinaryName);

if (sema.LookupName(lookupResult, /*scope=*/nullptr)) {
if (sema.LookupName(lookupResult, sema.TUScope)) {
for (auto decl : lookupResult) {
if (auto typedefDecl =
dyn_cast<clang::TypedefNameDecl>(decl->getUnderlyingDecl()))
Expand Down
Loading