Skip to content

Commit dadf301

Browse files
ktosoxedin
authored andcommitted
cleanups
1 parent 870c712 commit dadf301

18 files changed

+40
-97
lines changed

include/swift/AST/Decl.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2258,9 +2258,6 @@ class ValueDecl : public Decl {
22582258
/// Whether this declaration produces an implicitly unwrapped
22592259
/// optional result.
22602260
unsigned isIUO : 1;
2261-
//
2262-
// /// Whether this declaration is a witness to an ad-hoc requirement.
2263-
// unsigned isAdHocRequirementWitness : 1;
22642261
} LazySemanticInfo = { };
22652262

22662263
friend class DynamicallyReplacedDeclRequest;
@@ -2598,14 +2595,6 @@ class ValueDecl : public Decl {
25982595
/// Returns true if this decl can be found by id-style dynamic lookup.
25992596
bool canBeAccessedByDynamicLookup() const;
26002597

2601-
// /// Set whether this declaration is a witness to an ad-hoc requirement or not.
2602-
// void setIsAdHocRequirementWitness(bool value);
2603-
//
2604-
// /// Whether this declaration is a witness to an ad-hoc requirement.
2605-
// bool isAdHocRequirementWitness() const {
2606-
// return LazySemanticInfo.isAdHocRequirementWitness;
2607-
// }
2608-
26092598
/// Returns true if this declaration has an implicitly unwrapped optional
26102599
/// result. The precise meaning depends on the declaration kind:
26112600
/// - for properties, the value is IUO

include/swift/AST/DiagnosticsParse.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,8 @@ ERROR(expected_sil_function_type, none,
680680
"sil function expected to have SIL function type", ())
681681
ERROR(sil_dynamically_replaced_func_not_found,none,
682682
"dynamically replaced function not found %0", (Identifier))
683+
ERROR(sil_adhoc_requirement_witness_func_not_found,none,
684+
"ad-hoc requirement witness function not found %0", (Identifier))
683685
ERROR(sil_specialize_target_func_not_found,none,
684686
"_specialize target function not found %0", (Identifier))
685687
ERROR(sil_availability_expected_version,none,

include/swift/SIL/SILDeclRef.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -555,12 +555,7 @@ struct SILDeclRef {
555555

556556
bool canBeDynamicReplacement() const;
557557

558-
// /// True if the function was a witness to an ad-hoc requirement.
559-
// /// Useful in order to e.g. not optimize away the function even
560-
// /// if it seems not-used to the optimizer based on information in SIL.
561-
// bool isAdHocRequirementWitness() const;
562-
563-
bool isAutoDiffDerivativeFunction() const {
558+
bool isAutoDiffDerivativeFunction() const {
564559
return pointer.is<AutoDiffDerivativeFunctionIdentifier *>() &&
565560
pointer.get<AutoDiffDerivativeFunctionIdentifier *>() != nullptr;
566561
}

include/swift/SIL/SILFunction.h

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ enum IsDynamicallyReplaceable_t {
5555
IsNotDynamic,
5656
IsDynamic
5757
};
58-
//enum IsAdHocRequirementWitness_t {
59-
// IsNotAdHocWitness,
60-
// IsAdHocWitness
61-
//};
6258
enum IsExactSelfClass_t {
6359
IsNotExactSelfClass,
6460
IsExactSelfClass,
@@ -216,14 +212,16 @@ class SILFunction
216212
/// @_dynamicReplacement(for:) function.
217213
SILFunction *ReplacedFunction = nullptr;
218214

219-
/// Ad-hoc requirements may need to be retained explicitly, such that they
220-
/// do not get optimized away as it might seem tha they are un-used.
215+
/// This SILFunction REFerences an ad-hoc protocol requirement witness in
216+
/// order to keep it alive, such that it main be obtained in IRGen. Without
217+
/// this explicit reference, the witness would seem not-used, and not be
218+
/// accessible for IRGen.
221219
///
222-
/// Specifically, e.g. the DistributedTargetInvocationDecoder's
223-
/// 'decodeNextArgument' must be retained, as it is only used from IRGen
220+
/// Specifically, one such case is the DistributedTargetInvocationDecoder's
221+
/// 'decodeNextArgument' which must be retained, as it is only used from IRGen
224222
/// and such, appears as-if unused in SIL and would get optimized away.
225-
// TODO: rename: referenced ad hoc requirement witnesses
226-
SILFunction *AdHocRequirementFunction = nullptr;
223+
// TODO: Consider making this a general "references adhoc functions" and make it an array?
224+
SILFunction *RefAdHocRequirementFunction = nullptr;
227225

228226
Identifier ObjCReplacementFor;
229227

@@ -363,9 +361,6 @@ class SILFunction
363361
/// The function is in a statically linked module.
364362
unsigned IsStaticallyLinked : 1;
365363

366-
// /// The function is a witness to an ad-hoc requirement.
367-
// unsigned IsAdHocRequirementWitness : 1;
368-
369364
static void
370365
validateSubclassScope(SubclassScope scope, IsThunk_t isThunk,
371366
const GenericSpecializationInformation *genericInfo) {
@@ -490,28 +485,25 @@ class SILFunction
490485
ReplacedFunction = nullptr;
491486
}
492487

493-
SILFunction *getUsedAdHocRequirementWitnessFunction() const {
494-
return AdHocRequirementFunction;
488+
SILFunction *getReferencedAdHocRequirementWitnessFunction() const {
489+
return RefAdHocRequirementFunction;
495490
}
496491
// Marks that this `SILFunction` uses the passed in ad-hoc protocol
497492
// requirement witness `f` and therefore must retain it explicitly,
498493
// otherwise we might not be able to get a reference to it.
499-
void setUsedAdHocRequirementWitnessFunction(SILFunction *f) {
500-
assert(AdHocRequirementFunction == nullptr && "already set");
501-
502-
fprintf(stderr, "[%s:%d] (%s) SET AD HOC WITNESS [%s] ON [%s]\n", __FILE__, __LINE__, __FUNCTION__, f->getName().str().c_str(), this->getName().str().c_str());
503-
f->dump();
494+
void setReferencedAdHocRequirementWitnessFunction(SILFunction *f) {
495+
assert(RefAdHocRequirementFunction == nullptr && "already set");
504496

505497
if (f == nullptr)
506498
return;
507-
AdHocRequirementFunction = f;
508-
AdHocRequirementFunction->incrementRefCount();
499+
RefAdHocRequirementFunction = f;
500+
RefAdHocRequirementFunction->incrementRefCount();
509501
}
510-
void dropAdHocRequirementFunction() {
511-
if (!AdHocRequirementFunction)
502+
void dropReferencedAdHocRequirementWitnessFunction() {
503+
if (!RefAdHocRequirementFunction)
512504
return;
513-
AdHocRequirementFunction->decrementRefCount();
514-
AdHocRequirementFunction = nullptr;
505+
RefAdHocRequirementFunction->decrementRefCount();
506+
RefAdHocRequirementFunction = nullptr;
515507
}
516508

517509
bool hasObjCReplacement() const {
@@ -789,15 +781,6 @@ class SILFunction
789781
assert(!Transparent || !IsDynamicReplaceable);
790782
}
791783

792-
/// Returns whether this function implementation can be dynamically replaced.
793-
// IsAdHocRequirementWitness_t isAdHocRequirementWitness() const {
794-
// return IsAdHocRequirementWitness_t(IsAdHocRequirementWitness);
795-
// }
796-
// void setIsAdHocRequirementWitness(IsAdHocRequirementWitness_t value = IsAdHocWitness) {
797-
// IsAdHocRequirementWitness = value;
798-
// assert(!IsDynamicReplaceable);
799-
// }
800-
801784
IsExactSelfClass_t isExactSelfClass() const {
802785
return IsExactSelfClass_t(ExactSelfClass);
803786
}

lib/AST/Decl.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3167,10 +3167,6 @@ void ValueDecl::setIsDynamic(bool value) {
31673167
LazySemanticInfo.isDynamic = value;
31683168
}
31693169

3170-
//void ValueDecl::setIsAdHocRequirementWitness(bool value) {
3171-
// LazySemanticInfo.isAdHocRequirementWitness = true;
3172-
//}
3173-
31743170
ValueDecl *ValueDecl::getDynamicallyReplacedDecl() const {
31753171
return evaluateOrDefault(getASTContext().evaluator,
31763172
DynamicallyReplacedDeclRequest{

lib/SIL/IR/SILDeclRef.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,14 +1382,6 @@ bool SILDeclRef::canBeDynamicReplacement() const {
13821382
return true;
13831383
}
13841384

1385-
//bool SILDeclRef::isAdHocRequirementWitness() const {
1386-
// auto decl = getDecl();
1387-
// if (!decl)
1388-
// return false;
1389-
//
1390-
// return decl->isAdHocRequirementWitness();
1391-
//}
1392-
13931385
bool SILDeclRef::isDynamicallyReplaceable() const {
13941386
// The non-foreign entry of a @dynamicReplacement(for:) of @objc method in a
13951387
// generic class can't be a dynamically replaced.

lib/SIL/IR/SILFunctionBuilder.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,6 @@ void SILFunctionBuilder::addFunctionAttributes(
223223
}
224224

225225
if (constant.isDistributedThunk()) {
226-
fprintf(stderr, "[%s:%d] (%s) IS DIST THUNK!\n", __FILE__, __LINE__, __FUNCTION__);
227-
constant.dump();
228-
229226
auto *actor = decl->getDeclContext()->getSelfNominalTypeDecl();
230227
if (actor && actor->isDistributedActor()) {
231228
auto &C = decl->getASTContext();
@@ -241,9 +238,7 @@ void SILFunctionBuilder::addFunctionAttributes(
241238
decoderTy->getAnyNominal());
242239
auto decodeRef = SILDeclRef(decodeFunc);
243240
auto *adHocWitness = getOrCreateDeclaration(decodeFunc, decodeRef);
244-
F->setUsedAdHocRequirementWitnessFunction(adHocWitness);
245-
246-
F->dump();
241+
F->setReferencedAdHocRequirementWitnessFunction(adHocWitness);
247242
}
248243
}
249244
}

lib/SIL/IR/SILModule.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ SILModule::~SILModule() {
138138
for (SILFunction &F : *this) {
139139
F.dropAllReferences();
140140
F.dropDynamicallyReplacedFunction();
141-
F.dropAdHocRequirementFunction();
141+
F.dropReferencedAdHocRequirementWitnessFunction();
142142
F.clearSpecializeAttrs();
143143
}
144144

@@ -468,7 +468,7 @@ void SILModule::eraseFunction(SILFunction *F) {
468468
// (References are not needed anymore.)
469469
F->clear();
470470
F->dropDynamicallyReplacedFunction();
471-
F->dropAdHocRequirementFunction();
471+
F->dropReferencedAdHocRequirementWitnessFunction();
472472
// Drop references for any _specialize(target:) functions.
473473
F->clearSpecializeAttrs();
474474
}

lib/SIL/IR/SILPrinter.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2983,11 +2983,10 @@ void SILFunction::print(SILPrintContext &PrintCtx) const {
29832983
OS << "\"] ";
29842984
}
29852985

2986-
if (auto *usedFunc = getUsedAdHocRequirementWitnessFunction()) {
2987-
OS << "[used_adhoc_requirement_witness \"";
2986+
if (auto *usedFunc = getReferencedAdHocRequirementWitnessFunction()) {
2987+
OS << "[ref_adhoc_requirement_witness \"";
29882988
OS << usedFunc->getName();
29892989
OS << "\"] ";
2990-
fprintf(stderr, "[%s:%d] (%s) PRINTED THE used_adhoc_requirement_witness...\n", __FILE__, __LINE__, __FUNCTION__);
29912990
}
29922991

29932992
if (hasObjCReplacement()) {

lib/SIL/Parser/ParseSIL.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,8 +1090,7 @@ static bool parseDeclSILOptional(bool *isTransparent,
10901090

10911091
SP.P.parseToken(tok::r_square, diag::expected_in_attribute_list);
10921092
continue;
1093-
} else if (usedAdHocRequirementWitness && SP.P.Tok.getText() == "used_adhoc_requirement_witness") {
1094-
fprintf(stderr, "[%s:%d] (%s) PARSING THE... used_adhoc_requirement_witness\n", __FILE__, __LINE__, __FUNCTION__);
1093+
} else if (usedAdHocRequirementWitness && SP.P.Tok.getText() == "ref_adhoc_requirement_witness") {
10951094
SP.P.consumeToken(tok::identifier);
10961095
if (SP.P.Tok.getKind() != tok::string_literal) {
10971096
SP.P.diagnose(SP.P.Tok, diag::expected_in_attribute_list);
@@ -1102,7 +1101,7 @@ static bool parseDeclSILOptional(bool *isTransparent,
11021101
SILFunction *Func = M.lookUpFunction(witnessFunc.str());
11031102
if (!Func) {
11041103
Identifier Id = SP.P.Context.getIdentifier(witnessFunc);
1105-
SP.P.diagnose(SP.P.Tok, diag::sil_dynamically_replaced_func_not_found, // FIXME: bettererror
1104+
SP.P.diagnose(SP.P.Tok, diag::sil_adhoc_requirement_witness_func_not_found,
11061105
Id);
11071106
return true;
11081107
}
@@ -6401,10 +6400,7 @@ bool SILParserState::parseDeclSIL(Parser &P) {
64016400
FunctionState.F->setIsExactSelfClass(isExactSelfClass);
64026401
FunctionState.F->setDynamicallyReplacedFunction(
64036402
DynamicallyReplacedFunction);
6404-
if (AdHocWitnessFunction) {
6405-
fprintf(stderr, "[%s:%d] (%s) PARSED AdHocWitnessFunction\n", __FILE__, __LINE__, __FUNCTION__);
6406-
}
6407-
FunctionState.F->setUsedAdHocRequirementWitnessFunction(
6403+
FunctionState.F->setReferencedAdHocRequirementWitnessFunction(
64086404
AdHocWitnessFunction);
64096405
if (!objCReplacementFor.empty())
64106406
FunctionState.F->setObjCReplacement(objCReplacementFor);

lib/Sema/TypeCheckDistributed.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,8 @@ static AbstractFunctionDecl *findDistributedAdHocRequirement(
7272

7373
for (auto value : decl->lookupDirect(identifier)) {
7474
auto func = dyn_cast<AbstractFunctionDecl>(value);
75-
if (func && matchFn(func)) {
76-
// In order to prevent an "unused" (from SIL's perspective) function
77-
// from being optimized away, we mark it as an ad-hoc requirement witness
78-
// which is then picked up in SIL and causes the function to be retained.
79-
// fprintf(stderr, "[%s:%d] (%s) FOUND ADHOC WITNESS: %s\n", __FILE__, __LINE__, __FUNCTION__, func->getNameStr().str().c_str());
80-
//
81-
// func->setIsAdHocRequirementWitness(true);
75+
if (func && matchFn(func))
8276
return func;
83-
}
8477
}
8578

8679
return nullptr;

lib/Serialization/DeserializeSIL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ SILDeserializer::readSILFunctionChecked(DeclID FID, SILFunction *existingFn,
680680
if (!replacedObjectiveCFunc.empty())
681681
fn->setObjCReplacement(replacedObjectiveCFunc);
682682
if (usedAdHocWitnessFunction)
683-
fn->setUsedAdHocRequirementWitnessFunction(usedAdHocWitnessFunction);
683+
fn->setReferencedAdHocRequirementWitnessFunction(usedAdHocWitnessFunction);
684684
if (clangNodeOwner)
685685
fn->setClangNodeOwner(clangNodeOwner);
686686
for (auto ID : SemanticsIDs) {

lib/Serialization/ModuleFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5656
/// describe what change you made. The content of this comment isn't important;
5757
/// it just ensures a conflict if two people change the module format.
5858
/// Don't worry about adhering to the 80-column limit for this line.
59-
const uint16_t SWIFTMODULE_VERSION_MINOR = 687; // AdHocRequirementWitness info in SILFunctionLayout
59+
const uint16_t SWIFTMODULE_VERSION_MINOR = 687; // RefAdHocRequirementFunction info in SILFunctionLayout
6060

6161
/// A standard hash seed used for all string hashes in a serialized module.
6262
///

lib/Serialization/SILFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ namespace sil_block {
284284
BCFixed<1>, // is distributed
285285
TypeIDField, // SILFunctionType
286286
DeclIDField, // SILFunction name or 0 (replaced function)
287-
DeclIDField, // SILFunction name or 0 (used ad-hoc requirement witness function) // NEW
287+
DeclIDField, // SILFunction name or 0 (used ad-hoc requirement witness function)
288288
GenericSignatureIDField,
289289
DeclIDField, // ClangNode owner
290290
BCArray<IdentifierIDField> // Semantics Attribute

lib/Serialization/SerializeSIL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ void SILSerializer::writeSILFunction(const SILFunction &F, bool DeclOnly) {
468468
}
469469

470470
IdentifierID usedAdHocWitnessFunctionID = 0;
471-
if (auto *fun = F.getUsedAdHocRequirementWitnessFunction()) {
471+
if (auto *fun = F.getReferencedAdHocRequirementWitnessFunction()) {
472472
addReferencedSILFunction(fun, true);
473473
usedAdHocWitnessFunctionID = S.addUniquedStringRef(fun->getName());
474474
}

test/Distributed/Inputs/FakeDistributedActorSystems.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,9 @@ public struct FakeInvocationEncoder : DistributedTargetInvocationEncoder {
304304

305305
// === decoding --------------------------------------------------------------
306306

307+
// !!! WARNING !!!
308+
// This is a 'final class' on purpose, to see that we retain the ad-hoc witness
309+
// for 'decodeNextArgument'; Do not change it to just a class!
307310
@available(SwiftStdlib 5.7, *)
308311
public final class FakeInvocationDecoder: DistributedTargetInvocationDecoder {
309312
public typealias SerializationRequirement = Codable

test/Distributed/distributed_actor_accessor_thunks_64bit.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %target-swift-frontend-emit-module -emit-module-path %t/FakeDistributedActorSystems.swiftmodule -module-name FakeDistributedActorSystems -disable-availability-checking %S/Inputs/FakeDistributedActorSystems.swift
3-
// RUN: %target-swift-frontend -module-name distributed_actor_accessors -emit-irgen -disable-availability-checking -I %t 2>&1 %s | %IRGenFileCheck %s -check-prefix CHECK-%target-import-type
3+
// RUN: %target-swift-frontend -module-name distributed_actor_accessors -emit-irgen -disable-availability-checking -I %t 2>&1 %s | %IRGenFileCheck %s -check-prefix CHECK-%target-import-type --dump-input=always
44

55
// UNSUPPORTED: back_deploy_concurrency
66
// REQUIRES: concurrency

test/SILGen/distributed_thunk.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-emit-silgen %s -enable-experimental-distributed -disable-availability-checking | %FileCheck %s --dump-input=fail
1+
// RUN: %target-swift-emit-silgen %s -enable-experimental-distributed -disable-availability-checking | %FileCheck %s
22
// REQUIRES: concurrency
33
// REQUIRES: distributed
44

@@ -9,7 +9,7 @@ distributed actor DA {
99
}
1010

1111
extension DA {
12-
// CHECK-LABEL: sil hidden [thunk] [distributed] [ossa] @$s17distributed_thunk2DAC1fyyYaKFTE : $@convention(method) @async (@guaranteed DA) -> @error Error
12+
// CHECK-LABEL: sil hidden [thunk] [distributed] [ref_adhoc_requirement_witness "$s11Distributed29LocalTestingInvocationDecoderC18decodeNextArgumentxyKSeRzSERzlF"] [ossa] @$s17distributed_thunk2DAC1fyyYaKFTE : $@convention(method) @async (@guaranteed DA) -> @error Error {
1313
// CHECK: function_ref @swift_distributed_actor_is_remote
1414

1515
// Call the actor function

0 commit comments

Comments
 (0)