Skip to content

[WIP] Enhance -assume-single-threaded option #7421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 52 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
e144637
Update the checkout script configuration for LLDB changes
Feb 8, 2017
f38f8ae
[AST] PotentialArchetype's ConcreteTypeSource is in the Representative.
huonw Feb 8, 2017
4491c84
[AST] Store and serialize a protocol's requirement signature.
huonw Feb 2, 2017
857e4c5
[AST] Use the requirement signature in the ArchetypeBuilder.
huonw Feb 6, 2017
9c19347
[AST] Concretize nested potential archetypes on demand.
huonw Feb 7, 2017
618505e
Clean up handling of CMark library dependency.
Feb 6, 2017
4f98a1e
Sema: Treat the implicit RawRepresentable conformance for enums as `S…
jckarter Feb 8, 2017
80d1c94
[AST] Diagnose recursive requirements whenever they appear.
huonw Feb 9, 2017
041d81f
[Sema] Conformances only need to be verified as used once.
huonw Feb 9, 2017
8d9f736
[Parse] Fix crash in conditional compilation parsing (#7331)
jtbandes Feb 9, 2017
4eb87a3
Python lint update-checkout
hughbe Feb 8, 2017
72251fc
Python lint scale-test
hughbe Feb 8, 2017
22009b2
Python lint line-directive
hughbe Feb 8, 2017
a7ac299
Python lint coverage-query-db
hughbe Feb 8, 2017
77e587b
Python lint coverage-generate-data
hughbe Feb 8, 2017
88160d2
Python lint build-script
hughbe Feb 8, 2017
b73c85d
42 * 42 is 1764, not 1746.
avjinder Feb 9, 2017
a58548d
[CMake] Make SWIFT_HAVE_LIBXML an option.
DougGregor Feb 9, 2017
aeac04d
Support for Open Existentials that do no take an address
Feb 7, 2017
5524bae
[sil] Define SILFunctionType::isNoReturnFunction().
gottesmm Feb 9, 2017
c24261f
[sil] Add a new API SILModule::isNoReturnBuiltinOrIntrinsic(Identifier).
gottesmm Feb 9, 2017
b443352
[Preset] Disable LLDB tests from PR testing and Swift package preset.…
shahmishal Feb 9, 2017
05011d2
[Update checkout] Use master branch for sub projects in master-next s…
shahmishal Feb 9, 2017
21bbcc5
[AST] Delete unnecessary generic environment use in ArchetypeBuilder.
huonw Feb 9, 2017
d9253d3
fix docs build failure for open_existential_opaque
Feb 9, 2017
1ca036d
Mangling: isSwiftSymbol should get a null terminated string rather th…
eeckstein Feb 9, 2017
df926bc
[Archetype builder] Refactor same-type requirement checking slightly.
DougGregor Feb 9, 2017
a473fcd
[Archetype builder] Use addSameTypeRequirement() for concrete type co…
DougGregor Feb 9, 2017
8cd280c
[AST] Don't recursively match DependentMemberTypes.
DougGregor Feb 9, 2017
a4f3c87
[Archetype builder] Perform structural matching of same-type constrai…
DougGregor Feb 9, 2017
028dfaf
[Archetype builder] Allow one to directly express constraints X<T> ==…
DougGregor Feb 9, 2017
b3c17f7
[AST] Maintain type sugar in TypeMatcher.
DougGregor Feb 9, 2017
06c8f5b
[Serialization] Add an assert to try to catch a crash.
jrose-apple Feb 9, 2017
534b9c3
[Serialization] Fix a PrettyStackTraceEntry typo.
jrose-apple Feb 9, 2017
3e78662
[Archetype builder] Improve crash diagnostics for nondeterministic fa…
DougGregor Feb 10, 2017
7bb88e6
[Serialization] Fail fast w/ debug information if a parameter has a b…
DougGregor Feb 10, 2017
423a747
Merge remote-tracking branch 'upstream/master'
mtake Feb 10, 2017
eb7bf91
Extend the scope of -assume-single-threaded option to value types
mtake Feb 13, 2017
17e0d40
Change free-standing functions to member functions
mtake Feb 14, 2017
9a7e2f2
A single runtime that initializes the atomicity with an environment v…
mtake Feb 15, 2017
30fd5a1
Flip the logic in the previous commit (#7421)
mtake Feb 15, 2017
934ae85
A single compiler which initializes the default atomicity with an env…
mtake Feb 15, 2017
e8d8333
Stop using COMMON_C_FLAGS to configure swift compiler as well as swif…
mtake Feb 15, 2017
e043819
Enhance -assume-single-threaded option (#7421)
mtake Feb 13, 2017
1c2db74
Merge branch 'enhance-assume-single-threaded' of github.com:mtake/swi…
mtake Feb 16, 2017
a3880c0
Extend the scope of -assume-single-threaded option to value types
mtake Feb 13, 2017
2b86594
Change free-standing functions to member functions
mtake Feb 14, 2017
a4d4a86
A single runtime that initializes the atomicity with an environment v…
mtake Feb 15, 2017
c5bee03
Flip the logic in the previous commit (#7421)
mtake Feb 15, 2017
af1df67
A single compiler which initializes the default atomicity with an env…
mtake Feb 15, 2017
9ce74ba
Stop using COMMON_C_FLAGS to configure swift compiler as well as swif…
mtake Feb 15, 2017
b008d29
Merge branch 'enhance-assume-single-threaded' of github.com:mtake/swi…
mtake Feb 16, 2017
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: 4 additions & 1 deletion include/swift/AST/SILOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "llvm/ADT/StringRef.h"
#include <string>
#include <climits>
#include <cstdlib>

namespace swift {

Expand Down Expand Up @@ -121,7 +122,9 @@ class SILOptions {
bool AssumeUnqualifiedOwnershipWhenParsing = false;

/// Assume that code will be executed in a single-threaded environment.
bool AssumeSingleThreaded = false;
/// TODO: return to false when we can pass "-Xfrontend -assume-single-threaded"
/// to swift compiler while building standard library.
bool AssumeSingleThreaded = std::getenv("SWIFT_ASSUME_SINGLE_THREADED");
};

} // end namespace swift
Expand Down
23 changes: 23 additions & 0 deletions include/swift/Runtime/HeapObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,16 @@ SWIFT_RT_ENTRY_VISIBILITY
void swift_unownedRelease(HeapObject *value)
SWIFT_CC(RegisterPreservingCC);

/// Increment the weak/unowned retain count.
SWIFT_RT_ENTRY_VISIBILITY
void swift_nonatomic_unownedRetain(HeapObject *value)
SWIFT_CC(RegisterPreservingCC);

/// Decrement the weak/unowned retain count.
SWIFT_RT_ENTRY_VISIBILITY
void swift_nonatomic_unownedRelease(HeapObject *value)
SWIFT_CC(RegisterPreservingCC);

/// Increment the weak/unowned retain count by n.
SWIFT_RT_ENTRY_VISIBILITY
void swift_unownedRetain_n(HeapObject *value, int n)
Expand All @@ -540,13 +550,26 @@ SWIFT_RT_ENTRY_VISIBILITY
void swift_unownedRetainStrong(HeapObject *value)
SWIFT_CC(RegisterPreservingCC);

/// Increment the strong retain count of an object, aborting if it has
/// been deallocated.
SWIFT_RT_ENTRY_VISIBILITY
void swift_nonatomic_unownedRetainStrong(HeapObject *value)
SWIFT_CC(RegisterPreservingCC);

/// Increment the strong retain count of an object which may have been
/// deallocated, aborting if it has been deallocated, and decrement its
/// weak/unowned reference count.
SWIFT_RT_ENTRY_VISIBILITY
void swift_unownedRetainStrongAndRelease(HeapObject *value)
SWIFT_CC(RegisterPreservingCC);

/// Increment the strong retain count of an object which may have been
/// deallocated, aborting if it has been deallocated, and decrement its
/// weak/unowned reference count.
SWIFT_RT_ENTRY_VISIBILITY
void swift_nonatomic_unownedRetainStrongAndRelease(HeapObject *value)
SWIFT_CC(RegisterPreservingCC);

/// Aborts if the object has been deallocated.
SWIFT_RUNTIME_EXPORT
void swift_unownedCheck(HeapObject *value);
Expand Down
28 changes: 28 additions & 0 deletions include/swift/Runtime/RuntimeFunctions.def
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,20 @@ FUNCTION(NativeUnownedRelease, swift_unownedRelease, RegisterPreservingCC,
ARGS(RefCountedPtrTy),
ATTRS(NoUnwind))

// void swift_nonatomic_unownedRetain(void *ptr);
FUNCTION(NonAtomicNativeUnownedRetain, swift_nonatomic_unownedRetain,
RegisterPreservingCC,
RETURNS(VoidTy),
ARGS(RefCountedPtrTy),
ATTRS(NoUnwind))

// void swift_nonatomic_unownedRelease(void *ptr);
FUNCTION(NonAtomicNativeUnownedRelease, swift_nonatomic_unownedRelease,
RegisterPreservingCC,
RETURNS(VoidTy),
ARGS(RefCountedPtrTy),
ATTRS(NoUnwind))

// void swift_unownedRetain_n(void *ptr, int32_t n);
FUNCTION(UnownedRetainN, swift_unownedRetain_n,
RegisterPreservingCC,
Expand All @@ -389,13 +403,27 @@ FUNCTION(NativeStrongRetainUnowned, swift_unownedRetainStrong, RegisterPreservin
ARGS(RefCountedPtrTy),
ATTRS(NoUnwind))

// void swift_nonatomic_unownedRetainStrong(void *ptr);
FUNCTION(NonAtomicNativeStrongRetainUnowned, swift_nonatomic_unownedRetainStrong,
RegisterPreservingCC,
RETURNS(VoidTy),
ARGS(RefCountedPtrTy),
ATTRS(NoUnwind))

// void swift_unownedRetainStrongAndRelease(void *ptr);
FUNCTION(NativeStrongRetainAndUnownedRelease,
swift_unownedRetainStrongAndRelease, RegisterPreservingCC,
RETURNS(VoidTy),
ARGS(RefCountedPtrTy),
ATTRS(NoUnwind))

// void swift_nonatomic_unownedRetainStrongAndRelease(void *ptr);
FUNCTION(NonAtomicNativeStrongRetainAndUnownedRelease,
swift_nonatomic_unownedRetainStrongAndRelease, RegisterPreservingCC,
RETURNS(VoidTy),
ARGS(RefCountedPtrTy),
ATTRS(NoUnwind))

// void swift_weakDestroy(WeakReference *object);
FUNCTION(NativeWeakDestroy, swift_weakDestroy, DefaultCC,
RETURNS(VoidTy),
Expand Down
5 changes: 5 additions & 0 deletions include/swift/SIL/SILBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -1512,6 +1512,11 @@ class SILBuilder {
// Memory management helpers
//===--------------------------------------------------------------------===//

/// Returns the default atomicity of the module.
Atomicity getDefaultAtomicity() {
return getModule().isDefaultAtomic() ? Atomicity::Atomic : Atomicity::NonAtomic;
}

/// Try to fold a destroy_addr operation into the previous instructions, or
/// generate an explicit one if that fails. If this inserts a new
/// instruction, it returns it, otherwise it returns null.
Expand Down
5 changes: 5 additions & 0 deletions include/swift/SIL/SILModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,11 @@ class SILModule {

/// Returns true if the builtin or intrinsic is no-return.
bool isNoReturnBuiltinOrIntrinsic(Identifier Name);

/// Returns true if the default atomicity of the module is Atomic.
bool isDefaultAtomic() const {
return ! getOptions().AssumeSingleThreaded;
}
};

inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const SILModule &M){
Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/GenClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ static bool getInstanceSizeByMethod(IRGenFunction &IGF,

// Retain 'self' if necessary.
if (fnType->getParameters()[0].isConsumed()) {
IGF.emitNativeStrongRetain(selfValue);
IGF.emitNativeStrongRetain(selfValue, IGF.getDefaultAtomicity());
}

// Adjust down to the defining subclass type if necessary.
Expand Down
24 changes: 12 additions & 12 deletions lib/IRGen/GenEnum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1279,7 +1279,7 @@ namespace {
assert(TIK >= Loadable);
Explosion tmp;
loadAsTake(IGF, addr, tmp);
copy(IGF, tmp, e, Atomicity::Atomic);
copy(IGF, tmp, e, IGF.getDefaultAtomicity());
}

void assign(IRGenFunction &IGF, Explosion &e, Address addr) const override {
Expand All @@ -1289,7 +1289,7 @@ namespace {
loadAsTake(IGF, addr, old);
initialize(IGF, e, addr);
if (!isPOD(ResilienceExpansion::Maximal))
consume(IGF, old, Atomicity::Atomic);
consume(IGF, old, IGF.getDefaultAtomicity());
}

void initialize(IRGenFunction &IGF, Explosion &e, Address addr)
Expand Down Expand Up @@ -1501,7 +1501,7 @@ namespace {
Explosion payloadCopy;
auto &loadableTI = getLoadablePayloadTypeInfo();
loadableTI.unpackFromEnumPayload(IGF, payload, payloadValue, 0);
loadableTI.copy(IGF, payloadValue, payloadCopy, Atomicity::Atomic);
loadableTI.copy(IGF, payloadValue, payloadCopy, IGF.getDefaultAtomicity());
(void)payloadCopy.claimAll(); // FIXME: repack if not bit-identical
}

Expand Down Expand Up @@ -1534,7 +1534,7 @@ namespace {
Explosion payloadValue;
auto &loadableTI = getLoadablePayloadTypeInfo();
loadableTI.unpackFromEnumPayload(IGF, payload, payloadValue, 0);
loadableTI.consume(IGF, payloadValue, Atomicity::Atomic);
loadableTI.consume(IGF, payloadValue, IGF.getDefaultAtomicity());
}

IGF.Builder.CreateBr(endBB);
Expand Down Expand Up @@ -2206,7 +2206,7 @@ namespace {
llvm::Value *ptr) const {
switch (CopyDestroyKind) {
case NullableRefcounted:
IGF.emitStrongRetain(ptr, Refcounting, Atomicity::Atomic);
IGF.emitStrongRetain(ptr, Refcounting, IGF.getDefaultAtomicity());
return;
case POD:
case Normal:
Expand All @@ -2230,7 +2230,7 @@ namespace {
llvm::Value *ptr) const {
switch (CopyDestroyKind) {
case NullableRefcounted:
IGF.emitStrongRelease(ptr, Refcounting, Atomicity::Atomic);
IGF.emitStrongRelease(ptr, Refcounting, IGF.getDefaultAtomicity());
return;
case POD:
case Normal:
Expand Down Expand Up @@ -2915,7 +2915,7 @@ namespace {
projectPayloadValue(IGF, parts.payload, tagIndex, lti, value);

Explosion tmp;
lti.copy(IGF, value, tmp, Atomicity::Atomic);
lti.copy(IGF, value, tmp, IGF.getDefaultAtomicity());
(void)tmp.claimAll(); // FIXME: repack if not bit-identical
});

Expand All @@ -2940,7 +2940,7 @@ namespace {
Explosion value;
projectPayloadValue(IGF, parts.payload, tagIndex, lti, value);

lti.consume(IGF, value, Atomicity::Atomic);
lti.consume(IGF, value, IGF.getDefaultAtomicity());
});

IGF.Builder.CreateRetVoid();
Expand Down Expand Up @@ -3117,7 +3117,7 @@ namespace {
llvm::Value *ptr) const {
switch (CopyDestroyKind) {
case TaggedRefcounted:
IGF.emitStrongRetain(ptr, Refcounting, Atomicity::Atomic);
IGF.emitStrongRetain(ptr, Refcounting, IGF.getDefaultAtomicity());
return;
case POD:
case BitwiseTakable:
Expand All @@ -3143,7 +3143,7 @@ namespace {
llvm::Value *ptr) const {
switch (CopyDestroyKind) {
case TaggedRefcounted:
IGF.emitStrongRelease(ptr, Refcounting, Atomicity::Atomic);
IGF.emitStrongRelease(ptr, Refcounting, IGF.getDefaultAtomicity());
return;
case POD:
case BitwiseTakable:
Expand Down Expand Up @@ -4058,7 +4058,7 @@ namespace {

loadAsTake(IGF, dest, tmpOld);
initialize(IGF, tmpSrc, dest);
consume(IGF, tmpOld, Atomicity::Atomic);
consume(IGF, tmpOld, IGF.getDefaultAtomicity());
return;
}

Expand Down Expand Up @@ -4252,7 +4252,7 @@ namespace {
if (TI->isLoadable()) {
Explosion tmp;
loadAsTake(IGF, addr, tmp);
consume(IGF, tmp, Atomicity::Atomic);
consume(IGF, tmp, IGF.getDefaultAtomicity());
return;
}

Expand Down
31 changes: 18 additions & 13 deletions lib/IRGen/GenExistential.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ class ScalarExistentialTypeInfoBase :
Explosion &out) const override {
// Load the instance pointer, which is unknown-refcounted.
llvm::Value *instance = asDerived().loadValue(IGF, address);
asDerived().emitValueRetain(IGF, instance, Atomicity::Atomic);
asDerived().emitValueRetain(IGF, instance, IGF.getDefaultAtomicity());
out.add(instance);

// Load the witness table pointers.
Expand All @@ -772,7 +772,7 @@ class ScalarExistentialTypeInfoBase :
Address instanceAddr = asDerived().projectValue(IGF, address);
llvm::Value *old = IGF.Builder.CreateLoad(instanceAddr);
IGF.Builder.CreateStore(e.claimNext(), instanceAddr);
asDerived().emitValueRelease(IGF, old, Atomicity::Atomic);
asDerived().emitValueRelease(IGF, old, IGF.getDefaultAtomicity());

// Store the witness table pointers.
asDerived().emitStoreOfTables(IGF, e, address);
Expand Down Expand Up @@ -821,7 +821,7 @@ class ScalarExistentialTypeInfoBase :

void destroy(IRGenFunction &IGF, Address addr, SILType T) const override {
llvm::Value *value = asDerived().loadValue(IGF, addr);
asDerived().emitValueRelease(IGF, value, Atomicity::Atomic);
asDerived().emitValueRelease(IGF, value, IGF.getDefaultAtomicity());
}

void packIntoEnumPayload(IRGenFunction &IGF,
Expand Down Expand Up @@ -937,12 +937,12 @@ class LoadableUnownedClassExistentialTypeInfo final

void emitValueRetain(IRGenFunction &IGF, llvm::Value *value,
Atomicity atomicity) const {
IGF.emitUnownedRetain(value, Refcounting);
IGF.emitUnownedRetain(value, Refcounting, atomicity);
}

void emitValueRelease(IRGenFunction &IGF, llvm::Value *value,
Atomicity atomicity) const {
IGF.emitUnownedRelease(value, Refcounting);
IGF.emitUnownedRelease(value, Refcounting, atomicity);
}

void emitValueFixLifetime(IRGenFunction &IGF, llvm::Value *value) const {
Expand Down Expand Up @@ -1077,24 +1077,29 @@ class ClassExistentialTypeInfo final
(void)e.claim(getNumStoredProtocols());
}

void strongRetainUnowned(IRGenFunction &IGF, Explosion &e) const override {
IGF.emitStrongRetainUnowned(e.claimNext(), Refcounting);
void strongRetainUnowned(IRGenFunction &IGF, Explosion &e,
Atomicity atomicity) const override {
IGF.emitStrongRetainUnowned(e.claimNext(), Refcounting, atomicity);
(void)e.claim(getNumStoredProtocols());
}

void strongRetainUnownedRelease(IRGenFunction &IGF,
Explosion &e) const override {
IGF.emitStrongRetainAndUnownedRelease(e.claimNext(), Refcounting);
Explosion &e,
Atomicity atomicity) const override {
IGF.emitStrongRetainAndUnownedRelease(e.claimNext(), Refcounting,
atomicity);
(void)e.claim(getNumStoredProtocols());
}

void unownedRetain(IRGenFunction &IGF, Explosion &e) const override {
IGF.emitUnownedRetain(e.claimNext(), Refcounting);
void unownedRetain(IRGenFunction &IGF, Explosion &e,
Atomicity atomicity) const override {
IGF.emitUnownedRetain(e.claimNext(), Refcounting, atomicity);
(void)e.claim(getNumStoredProtocols());
}

void unownedRelease(IRGenFunction &IGF, Explosion &e) const override {
IGF.emitUnownedRelease(e.claimNext(), Refcounting);
void unownedRelease(IRGenFunction &IGF, Explosion &e,
Atomicity atomicity) const override {
IGF.emitUnownedRelease(e.claimNext(), Refcounting, atomicity);
(void)e.claim(getNumStoredProtocols());
}

Expand Down
Loading