Skip to content

Commit 4334279

Browse files
committed
[nfc] clean and jot down some TODOs
1 parent bbbf4e7 commit 4334279

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

include/swift/AST/Types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5776,7 +5776,7 @@ class ProtocolCompositionType final : public TypeBase,
57765776
private llvm::TrailingObjects<ProtocolCompositionType, Type> {
57775777
friend TrailingObjects;
57785778

5779-
// TODO: this could probably be folded into the existing Bits field
5779+
// TODO(kavon): this could probably be folded into the existing Bits field
57805780
// or we could just store the InverseType's in the Members array.
57815781
InvertibleProtocolSet Inverses;
57825782

lib/AST/RequirementMachine/RequirementLowering.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@
159159
#include "swift/AST/TypeRepr.h"
160160
#include "llvm/ADT/SmallVector.h"
161161
#include "llvm/ADT/SetVector.h"
162-
#include "swift/Basic/Defer.h"
163162
#include "Diagnostics.h"
164163
#include "RewriteContext.h"
165164
#include "NameLookup.h"
@@ -779,6 +778,19 @@ void swift::rewriting::expandDefaultRequirements(ASTContext &ctx,
779778
if (!ctx.LangOpts.hasFeature(Feature::NoncopyableGenerics))
780779
return;
781780

781+
// TODO(kavon): we can be more efficient in two ways:
782+
// 1. Instead of allocating space in this map for each target to describe
783+
// defaults, which are much more common, we use the set to track inverses
784+
// only so that the more common case has no overhead beyond just adding
785+
// the defaults. This should yield a constant-time improvement.
786+
//
787+
// 2. Instead of searching the _entire_ results vector for inverses, we can
788+
// take advantage of the fact that the requirements appended by nesting
789+
// level. Thus, we could get an iterator position for the start of the
790+
// removal search, which would be the end of the `result` vector before
791+
// requirements for the current subjects got pushed there. This should
792+
// yield a O(|result|^2) -> O(|result|) performance improvement.
793+
782794
llvm::DenseMap<CanType, InvertibleProtocolSet> defaults;
783795
for (auto subject : subjects)
784796
defaults.insert({ subject->getCanonicalType(),
@@ -811,8 +823,6 @@ void swift::rewriting::expandDefaultRequirements(ASTContext &ctx,
811823
return true;
812824
}
813825

814-
// TODO: check for redundant inverses.
815-
816826
// Apply the inverse to the subject's defaults.
817827
defaults[subject].remove(inverse->getInverseKind());
818828

0 commit comments

Comments
 (0)