Skip to content

Commit 4768d01

Browse files
committed
[ast] Hide CapturedValue(OpaqueValueExpr *) so that it only can be used by TypeLowering.
The reason why I am doing this is before this commit despite the fact that CapturedValue was only used by TypeLowering, this constructor was exposed to the entire rest of the compiler. This made it so that other code (like the AbstractClosureExpr::getIsolationCrossing() that I added in the previous series of commits) would have to handle that API even though there was nothing to handle just in case someone added something in the future. Rather than create such a burden on the rest of the compiler, in this commit, we instead hide said constructor and make it only accessible from TypeLowering. This creates a barrier from new uses appearing in AST and make it reasonable for code in the AST that will never see things from TypeLowering (like the ACE API I mentioned above) just assert on that case without needing to worry about additional uses cropping in easily by mistake.
1 parent f077e4a commit 4768d01

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

include/swift/AST/CaptureInfo.h

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,18 @@
2525

2626
namespace swift {
2727
class CapturedValue;
28-
}
28+
} // namespace swift
29+
30+
namespace swift {
31+
namespace Lowering {
32+
class TypeConverter;
33+
} // namespace Lowering
34+
} // namespace swift
2935

3036
namespace llvm {
3137
class raw_ostream;
3238
template <> struct DenseMapInfo<swift::CapturedValue>;
33-
}
39+
} // namespace llvm
3440

3541
namespace swift {
3642
class ValueDecl;
@@ -41,6 +47,8 @@ class VarDecl;
4147
/// CapturedValue includes both the declaration being captured, along with flags
4248
/// that indicate how it is captured.
4349
class CapturedValue {
50+
friend class Lowering::TypeConverter;
51+
4452
public:
4553
using Storage =
4654
llvm::PointerIntPair<llvm::PointerUnion<ValueDecl*, OpaqueValueExpr*>, 2,
@@ -69,9 +77,17 @@ class CapturedValue {
6977
CapturedValue(ValueDecl *Val, unsigned Flags, SourceLoc Loc)
7078
: Value(Val, Flags), Loc(Loc) {}
7179

72-
CapturedValue(OpaqueValueExpr *Val, unsigned Flags)
80+
private:
81+
// This is only used in TypeLowering when forming Lowered Capture
82+
// Info. OpaqueValueExpr captured value should never show up in the AST
83+
// itself.
84+
//
85+
// NOTE: AbstractClosureExpr::getIsolationCrossing relies upon this and
86+
// asserts that it never sees one of these.
87+
explicit CapturedValue(OpaqueValueExpr *Val, unsigned Flags)
7388
: Value(Val, Flags), Loc(SourceLoc()) {}
7489

90+
public:
7591
static CapturedValue getDynamicSelfMetadata() {
7692
return CapturedValue((ValueDecl *)nullptr, 0, SourceLoc());
7793
}

lib/AST/Expr.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2942,10 +2942,10 @@ void AbstractClosureExpr::getIsolationCrossing(
29422942

29432943
auto declIsolation = swift::getActorIsolation(capture.getDecl());
29442944

2945-
// Then see if we have an opaque value.
2946-
if (auto *opaqueValue = capture.getOpaqueValue()) {
2947-
continue;
2948-
}
2945+
// Assert that we do not have an opaque value capture. These only appear in
2946+
// TypeLowering and should never appear in the AST itself.
2947+
assert(!capture.getOpaqueValue() &&
2948+
"This should only be created in TypeLowering");
29492949

29502950
// If our decl is actor isolated...
29512951
if (declIsolation.isActorIsolated()) {

0 commit comments

Comments
 (0)