Skip to content

Commit f99904a

Browse files
committed
Eliminate the useless flag -enable-experimental-collection-casts.
This eliminates a pile of now-dead code in: * The type checker, where we no longer have special cases for bridging conversions * The expression ASTs, where we no longer need to distinguish bridging collection up/down casts * SILGen, which no longer uses Still to come is the removal of the _(set|dictionary)Bridge(From|To)ObjectiveC(Conditional)? entrypoints from the standard library. They're still used by some tests.
1 parent 51529ae commit f99904a

20 files changed

+57
-383
lines changed

include/swift/AST/Expr.h

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,8 @@ enum class CheckedCastKind : unsigned {
8181
ArrayDowncast,
8282
// A downcast from a dictionary type to another dictionary type.
8383
DictionaryDowncast,
84-
// A downcast from a dictionary type to another dictionary type that
85-
// requires bridging.
86-
DictionaryDowncastBridged,
8784
// A downcast from a set type to another set type.
8885
SetDowncast,
89-
// A downcast from a set type to another set type that requires bridging.
90-
SetDowncastBridged,
9186
/// A downcast from an object of class or Objective-C existential
9287
/// type to its bridged value type.
9388
BridgeFromObjectiveC,
@@ -392,9 +387,8 @@ class alignas(8) Expr {
392387
class CollectionUpcastConversionExprBitfields {
393388
friend class CollectionUpcastConversionExpr;
394389
unsigned : NumExprBits;
395-
unsigned BridgesToObjC : 1;
396390
};
397-
enum { NumCollectionUpcastConversionExprBits = NumExprBits + 1 };
391+
enum { NumCollectionUpcastConversionExprBits = NumExprBits + 0 };
398392
static_assert(NumCollectionUpcastConversionExprBits <= 32, "fits in an unsigned");
399393

400394
class ObjCSelectorExprBitfields {
@@ -2938,19 +2932,12 @@ class CollectionUpcastConversionExpr : public ImplicitConversionExpr {
29382932
public:
29392933
CollectionUpcastConversionExpr(Expr *subExpr, Type type,
29402934
ConversionPair keyConversion,
2941-
ConversionPair valueConversion,
2942-
bool bridgesToObjC)
2935+
ConversionPair valueConversion)
29432936
: ImplicitConversionExpr(
29442937
ExprKind::CollectionUpcastConversion, subExpr, type),
29452938
KeyConversion(keyConversion), ValueConversion(valueConversion) {
29462939
assert((!KeyConversion || ValueConversion)
29472940
&& "key conversion without value conversion");
2948-
CollectionUpcastConversionExprBits.BridgesToObjC = bridgesToObjC;
2949-
}
2950-
2951-
/// Whether this upcast bridges the source elements to Objective-C.
2952-
bool bridgesToObjC() const {
2953-
return CollectionUpcastConversionExprBits.BridgesToObjC;
29542941
}
29552942

29562943
/// Returns the expression that should be used to perform a

include/swift/AST/KnownDecls.def

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,12 @@ FUNC_DECL(ArrayForceCast, "_arrayForceCast")
2323
FUNC_DECL(ArrayConditionalCast, "_arrayConditionalCast")
2424

2525
FUNC_DECL(DictionaryUpCast, "_dictionaryUpCast")
26-
FUNC_DECL(DictionaryBridgeToObjectiveC, "_dictionaryBridgeToObjectiveC")
2726
FUNC_DECL(DictionaryDownCast, "_dictionaryDownCast")
2827
FUNC_DECL(DictionaryDownCastConditional, "_dictionaryDownCastConditional")
29-
FUNC_DECL(DictionaryBridgeFromObjectiveC,
30-
"_dictionaryBridgeFromObjectiveC")
31-
FUNC_DECL(DictionaryBridgeFromObjectiveCConditional,
32-
"_dictionaryBridgeFromObjectiveCConditional")
3328

3429
FUNC_DECL(SetUpCast, "_setUpCast")
35-
FUNC_DECL(SetBridgeToObjectiveC, "_setBridgeToObjectiveC")
3630
FUNC_DECL(SetDownCast, "_setDownCast")
3731
FUNC_DECL(SetDownCastConditional, "_setDownCastConditional")
38-
FUNC_DECL(SetBridgeFromObjectiveC, "_setBridgeFromObjectiveC")
39-
FUNC_DECL(SetBridgeFromObjectiveCConditional, "_setBridgeFromObjectiveCConditional")
4032

4133
FUNC_DECL(ConvertPointerToPointerArgument,
4234
"_convertPointerToPointerArgument")

include/swift/Basic/LangOptions.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,6 @@ namespace swift {
137137
/// \brief Enable experimental nested generic types feature.
138138
bool EnableExperimentalNestedGenericTypes = false;
139139

140-
/// \brief Enable generalized collection casting.
141-
bool EnableExperimentalCollectionCasts = true;
142-
143140
/// Should we check the target OSs of serialized modules to see that they're
144141
/// new enough?
145142
bool EnableTargetOSChecking = true;

include/swift/Option/FrontendOptions.td

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,6 @@ def enable_experimental_nested_generic_types :
227227
Flag<["-"], "enable-experimental-nested-generic-types">,
228228
HelpText<"Enable experimental support for nested generic types">;
229229

230-
def enable_experimental_collection_casts :
231-
Flag<["-"], "enable-experimental-collection-casts">,
232-
HelpText<"Enable experimental support for general collection casting">;
233-
234230
def disable_availability_checking : Flag<["-"],
235231
"disable-availability-checking">,
236232
HelpText<"Disable checking for potentially unavailable APIs">;

lib/AST/ASTDumper.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,8 +1936,6 @@ class PrintExpr : public ExprVisitor<PrintExpr> {
19361936
}
19371937
void visitCollectionUpcastConversionExpr(CollectionUpcastConversionExpr *E) {
19381938
printCommon(E, "collection_upcast_expr");
1939-
if (E->bridgesToObjC())
1940-
OS << " bridges_to_objc";
19411939
OS << '\n';
19421940
printRec(E->getSubExpr());
19431941
if (auto keyConversion = E->getKeyConversion()) {

lib/AST/ASTPrinter.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4398,12 +4398,8 @@ StringRef swift::getCheckedCastKindName(CheckedCastKind kind) {
43984398
return "array_downcast";
43994399
case CheckedCastKind::DictionaryDowncast:
44004400
return "dictionary_downcast";
4401-
case CheckedCastKind::DictionaryDowncastBridged:
4402-
return "dictionary_downcast_bridged";
44034401
case CheckedCastKind::SetDowncast:
44044402
return "set_downcast";
4405-
case CheckedCastKind::SetDowncastBridged:
4406-
return "set_downcast_bridged";
44074403
case CheckedCastKind::BridgeFromObjectiveC:
44084404
return "bridge_from_objc";
44094405
}

lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -741,9 +741,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
741741
Opts.EnableExperimentalNestedGenericTypes |=
742742
Args.hasArg(OPT_enable_experimental_nested_generic_types);
743743

744-
Opts.EnableExperimentalCollectionCasts |=
745-
Args.hasArg(OPT_enable_experimental_collection_casts);
746-
747744
Opts.DisableAvailabilityChecking |=
748745
Args.hasArg(OPT_disable_availability_checking);
749746
if (FrontendOpts.InputKind == InputFileKind::IFK_SIL)

lib/SILGen/SILGenDynamicCast.cpp

Lines changed: 13 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,7 @@ static RValue emitCollectionDowncastExpr(SILGenFunction &SGF,
290290
SILLocation loc,
291291
Type destType,
292292
SGFContext C,
293-
bool conditional,
294-
bool bridgesFromObjC) {
295-
if (SGF.getASTContext().LangOpts.EnableExperimentalCollectionCasts)
296-
bridgesFromObjC = false;
297-
293+
bool conditional) {
298294
// Compute substitutions for the intrinsic call.
299295
auto fromCollection = cast<BoundGenericStructType>(
300296
sourceType->getCanonicalType());
@@ -307,21 +303,13 @@ static RValue emitCollectionDowncastExpr(SILGenFunction &SGF,
307303
fn = conditional ? SGF.SGM.getArrayConditionalCast(loc)
308304
: SGF.SGM.getArrayForceCast(loc);
309305
} else if (fromCollection->getDecl() == ctx.getDictionaryDecl()) {
310-
fn = bridgesFromObjC
311-
? (conditional
312-
? SGF.SGM.getDictionaryBridgeFromObjectiveCConditional(loc)
313-
: SGF.SGM.getDictionaryBridgeFromObjectiveC(loc))
314-
: (conditional
315-
? SGF.SGM.getDictionaryDownCastConditional(loc)
316-
: SGF.SGM.getDictionaryDownCast(loc));
306+
fn = (conditional
307+
? SGF.SGM.getDictionaryDownCastConditional(loc)
308+
: SGF.SGM.getDictionaryDownCast(loc));
317309
} else if (fromCollection->getDecl() == ctx.getSetDecl()) {
318-
fn = bridgesFromObjC
319-
? (conditional
320-
? SGF.SGM.getSetBridgeFromObjectiveCConditional(loc)
321-
: SGF.SGM.getSetBridgeFromObjectiveC(loc))
322-
: (conditional
323-
? SGF.SGM.getSetDownCastConditional(loc)
324-
: SGF.SGM.getSetDownCast(loc));
310+
fn = (conditional
311+
? SGF.SGM.getSetDownCastConditional(loc)
312+
: SGF.SGM.getSetDownCast(loc));
325313
} else {
326314
llvm_unreachable("unsupported collection upcast kind");
327315
}
@@ -402,17 +390,11 @@ RValue Lowering::emitUnconditionalCheckedCast(SILGenFunction &SGF,
402390
// entry points.
403391
if (castKind == CheckedCastKind::ArrayDowncast ||
404392
castKind == CheckedCastKind::DictionaryDowncast ||
405-
castKind == CheckedCastKind::DictionaryDowncastBridged ||
406-
castKind == CheckedCastKind::SetDowncast ||
407-
castKind == CheckedCastKind::SetDowncastBridged) {
408-
bool bridgesFromObjC
409-
= (castKind == CheckedCastKind::DictionaryDowncastBridged ||
410-
castKind == CheckedCastKind::SetDowncastBridged);
393+
castKind == CheckedCastKind::SetDowncast) {
411394
ManagedValue operandMV = SGF.emitRValueAsSingleValue(operand);
412395
return emitCollectionDowncastExpr(SGF, operandMV, operand->getType(), loc,
413396
targetType, C,
414-
/*conditional=*/false,
415-
bridgesFromObjC);
397+
/*conditional=*/false);
416398
}
417399

418400
CheckedCastEmitter emitter(SGF, loc, operand->getType(),
@@ -438,16 +420,10 @@ RValue Lowering::emitConditionalCheckedCast(SILGenFunction &SGF,
438420
// entry points.
439421
if (castKind == CheckedCastKind::ArrayDowncast ||
440422
castKind == CheckedCastKind::DictionaryDowncast ||
441-
castKind == CheckedCastKind::DictionaryDowncastBridged ||
442-
castKind == CheckedCastKind::SetDowncast ||
443-
castKind == CheckedCastKind::SetDowncastBridged) {
444-
bool bridgesFromObjC
445-
= (castKind == CheckedCastKind::DictionaryDowncastBridged ||
446-
castKind == CheckedCastKind::SetDowncastBridged);
423+
castKind == CheckedCastKind::SetDowncast) {
447424
return emitCollectionDowncastExpr(SGF, operand, operandType, loc,
448425
resultObjectType, C,
449-
/*conditional=*/true,
450-
bridgesFromObjC);
426+
/*conditional=*/true);
451427
}
452428

453429
operand = adjustForConditionalCheckedCastOperand(loc, operand,
@@ -554,18 +530,12 @@ SILValue Lowering::emitIsa(SILGenFunction &SGF, SILLocation loc,
554530
// Handle collection downcasts separately.
555531
if (castKind == CheckedCastKind::ArrayDowncast ||
556532
castKind == CheckedCastKind::DictionaryDowncast ||
557-
castKind == CheckedCastKind::DictionaryDowncastBridged ||
558-
castKind == CheckedCastKind::SetDowncast ||
559-
castKind == CheckedCastKind::SetDowncastBridged) {
560-
bool bridgesFromObjC
561-
= (castKind == CheckedCastKind::DictionaryDowncastBridged ||
562-
castKind == CheckedCastKind::SetDowncastBridged);
533+
castKind == CheckedCastKind::SetDowncast) {
563534
ManagedValue operandMV = SGF.emitRValueAsSingleValue(operand);
564535
ManagedValue optValue = emitCollectionDowncastExpr(
565536
SGF, operandMV, operand->getType(), loc,
566537
targetType,
567-
SGFContext(), /*conditional=*/true,
568-
bridgesFromObjC)
538+
SGFContext(), /*conditional=*/true)
569539
.getAsSingleValue(SGF, loc);
570540

571541
// Materialize the input.

lib/SILGen/SILGenExpr.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -978,21 +978,15 @@ visitCollectionUpcastConversionExpr(CollectionUpcastConversionExpr *E,
978978
auto toCollection = cast<BoundGenericStructType>(
979979
E->getType()->getCanonicalType());
980980

981-
bool bridgesToObjC = E->bridgesToObjC();
982-
if (SGF.getASTContext().LangOpts.EnableExperimentalCollectionCasts)
983-
bridgesToObjC = false;
984-
985981
// Get the intrinsic function.
986982
auto &ctx = SGF.getASTContext();
987983
FuncDecl *fn = nullptr;
988984
if (fromCollection->getDecl() == ctx.getArrayDecl()) {
989985
fn = SGF.SGM.getArrayForceCast(loc);
990986
} else if (fromCollection->getDecl() == ctx.getDictionaryDecl()) {
991-
fn = bridgesToObjC ? SGF.SGM.getDictionaryBridgeToObjectiveC(loc)
992-
: SGF.SGM.getDictionaryUpCast(loc);
987+
fn = SGF.SGM.getDictionaryUpCast(loc);
993988
} else if (fromCollection->getDecl() == ctx.getSetDecl()) {
994-
fn = bridgesToObjC ? SGF.SGM.getSetBridgeToObjectiveC(loc)
995-
: SGF.SGM.getSetUpCast(loc);
989+
fn = SGF.SGM.getSetUpCast(loc);
996990
} else {
997991
llvm_unreachable("unsupported collection upcast kind");
998992
}

lib/Sema/CSApply.cpp

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3008,9 +3008,7 @@ namespace {
30083008
break;
30093009
case CheckedCastKind::ArrayDowncast:
30103010
case CheckedCastKind::DictionaryDowncast:
3011-
case CheckedCastKind::DictionaryDowncastBridged:
30123011
case CheckedCastKind::SetDowncast:
3013-
case CheckedCastKind::SetDowncastBridged:
30143012
case CheckedCastKind::BridgeFromObjectiveC:
30153013
// Valid checks.
30163014
expr->setCastKind(castKind);
@@ -3035,9 +3033,7 @@ namespace {
30353033
if (fromOptionals.size() != toOptionals.size() ||
30363034
castKind == CheckedCastKind::ArrayDowncast ||
30373035
castKind == CheckedCastKind::DictionaryDowncast ||
3038-
castKind == CheckedCastKind::DictionaryDowncastBridged ||
3039-
castKind == CheckedCastKind::SetDowncast ||
3040-
castKind == CheckedCastKind::SetDowncastBridged) {
3036+
castKind == CheckedCastKind::SetDowncast) {
30413037
auto toOptType = OptionalType::get(toType);
30423038
ConditionalCheckedCastExpr *cast
30433039
= new (tc.Context) ConditionalCheckedCastExpr(
@@ -3282,9 +3278,7 @@ namespace {
32823278
// Valid casts.
32833279
case CheckedCastKind::ArrayDowncast:
32843280
case CheckedCastKind::DictionaryDowncast:
3285-
case CheckedCastKind::DictionaryDowncastBridged:
32863281
case CheckedCastKind::SetDowncast:
3287-
case CheckedCastKind::SetDowncastBridged:
32883282
case CheckedCastKind::ValueCast:
32893283
case CheckedCastKind::BridgeFromObjectiveC:
32903284
expr->setCastKind(castKind);
@@ -3351,9 +3345,7 @@ namespace {
33513345
// Valid casts.
33523346
case CheckedCastKind::ArrayDowncast:
33533347
case CheckedCastKind::DictionaryDowncast:
3354-
case CheckedCastKind::DictionaryDowncastBridged:
33553348
case CheckedCastKind::SetDowncast:
3356-
case CheckedCastKind::SetDowncastBridged:
33573349
case CheckedCastKind::ValueCast:
33583350
case CheckedCastKind::BridgeFromObjectiveC:
33593351
expr->setCastKind(castKind);
@@ -5150,16 +5142,13 @@ buildElementConversion(ExprRewriter &rewriter,
51505142
ConstraintLocatorBuilder locator,
51515143
unsigned typeArgIndex) {
51525144
// We don't need this stuff unless we've got generalized casts.
5153-
auto &ctx = rewriter.cs.getASTContext();
5154-
if (!ctx.LangOpts.EnableExperimentalCollectionCasts)
5155-
return {};
5156-
51575145
Type srcType = srcCollectionType->castTo<BoundGenericType>()
51585146
->getGenericArgs()[typeArgIndex];
51595147
Type destType = destCollectionType->castTo<BoundGenericType>()
51605148
->getGenericArgs()[typeArgIndex];
51615149

51625150
// Build the conversion.
5151+
ASTContext &ctx = rewriter.getConstraintSystem().getASTContext();
51635152
auto opaque = new (ctx) OpaqueValueExpr(SourceLoc(), srcType);
51645153
auto conversion =
51655154
rewriter.coerceToType(opaque, destType,
@@ -5324,11 +5313,8 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
53245313
buildElementConversion(*this, expr->getType(), toType, locator, 0);
53255314

53265315
// Form the upcast.
5327-
bool isBridged = !cs.getBaseTypeForArrayType(fromType.getPointer())
5328-
->isBridgeableObjectType();
53295316
return new (tc.Context) CollectionUpcastConversionExpr(expr, toType,
5330-
{}, conv,
5331-
isBridged);
5317+
{}, conv);
53325318
}
53335319

53345320
case ConversionRestrictionKind::HashableToAnyHashable: {
@@ -5375,11 +5361,9 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
53755361
Type sourceKey, sourceValue;
53765362
std::tie(sourceKey, sourceValue) = *cs.isDictionaryType(expr->getType());
53775363

5378-
bool isBridged = !sourceKey->isBridgeableObjectType() ||
5379-
!sourceValue->isBridgeableObjectType();
53805364
return new (tc.Context) CollectionUpcastConversionExpr(expr, toType,
5381-
keyConv, valueConv,
5382-
isBridged);
5365+
keyConv,
5366+
valueConv);
53835367
}
53845368

53855369
case ConversionRestrictionKind::SetUpcast: {
@@ -5393,11 +5377,8 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
53935377
auto conv =
53945378
buildElementConversion(*this, expr->getType(), toType, locator, 0);
53955379

5396-
bool isBridged = !cs.getBaseTypeForSetType(fromType.getPointer())
5397-
->isBridgeableObjectType();
53985380
return new (tc.Context) CollectionUpcastConversionExpr(expr, toType,
5399-
{}, conv,
5400-
isBridged);
5381+
{}, conv);
54015382
}
54025383

54035384
case ConversionRestrictionKind::InoutToPointer: {
@@ -6700,9 +6681,7 @@ bool ConstraintSystem::applySolutionFix(Expr *expr,
67006681
// Valid casts.
67016682
case CheckedCastKind::ArrayDowncast:
67026683
case CheckedCastKind::DictionaryDowncast:
6703-
case CheckedCastKind::DictionaryDowncastBridged:
67046684
case CheckedCastKind::SetDowncast:
6705-
case CheckedCastKind::SetDowncastBridged:
67066685
case CheckedCastKind::ValueCast:
67076686
case CheckedCastKind::BridgeFromObjectiveC:
67086687
TC.diagnose(coerceExpr->getLoc(), diag::missing_forced_downcast,

lib/Sema/CSRanking.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ void ConstraintSystem::increaseScore(ScoreKind kind) {
6464
case SK_CollectionUpcastConversion:
6565
log << "collection upcast conversion";
6666
break;
67-
case SK_CollectionBridgedConversion:
68-
log << "collection bridged conversion";
69-
break;
7067

7168
case SK_ValueToOptional:
7269
log << "value to optional";

0 commit comments

Comments
 (0)