Skip to content

[SIL] Generalize CastingIsolatedConformances to CheckedCastInstOptions #82005

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,14 @@ private extension AllocStackInst {
builder.createCheckedCastAddrBranch(
source: newAlloc, sourceFormalType: concreteFormalType,
destination: cab.destination, targetFormalType: cab.targetFormalType,
isolatedConformances: cab.isolatedConformances,
options: cab.checkedCastOptions,
consumptionKind: cab.consumptionKind,
successBlock: cab.successBlock, failureBlock: cab.failureBlock)
context.erase(instruction: cab)
case let ucca as UnconditionalCheckedCastAddrInst:
let builder = Builder(before: ucca, context)
builder.createUnconditionalCheckedCastAddr(
isolatedConformances: ucca.isolatedConformances,
options: ucca.checkedCastOptions,
source: newAlloc, sourceFormalType: concreteFormalType,
destination: ucca.destination, targetFormalType: ucca.targetFormalType)
context.erase(instruction: ucca)
Expand Down
9 changes: 4 additions & 5 deletions SwiftCompilerSources/Sources/SIL/Builder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public struct Builder {
public func createCheckedCastAddrBranch(
source: Value, sourceFormalType: CanonicalType,
destination: Value, targetFormalType: CanonicalType,
isolatedConformances: CastingIsolatedConformances,
options: CheckedCastInstOptions,
consumptionKind: CheckedCastAddrBranchInst.CastConsumptionKind,
successBlock: BasicBlock,
failureBlock: BasicBlock
Expand All @@ -195,21 +195,20 @@ public struct Builder {

let cast = bridged.createCheckedCastAddrBranch(source.bridged, sourceFormalType.bridged,
destination.bridged, targetFormalType.bridged,
isolatedConformances.bridged,
options.bridged,
bridgedConsumption,
successBlock.bridged, failureBlock.bridged)
return notifyNew(cast.getAs(CheckedCastAddrBranchInst.self))
}

@discardableResult
public func createUnconditionalCheckedCastAddr(
isolatedConformances: CastingIsolatedConformances,
options: CheckedCastInstOptions,
source: Value, sourceFormalType: CanonicalType,
destination: Value, targetFormalType: CanonicalType
) -> UnconditionalCheckedCastAddrInst {
let cast = bridged.createUnconditionalCheckedCastAddr(
isolatedConformances.bridged, source.bridged,
sourceFormalType.bridged,
options.bridged, source.bridged, sourceFormalType.bridged,
destination.bridged, targetFormalType.bridged
)
return notifyNew(cast.getAs(UnconditionalCheckedCastAddrInst.self))
Expand Down
51 changes: 20 additions & 31 deletions SwiftCompilerSources/Sources/SIL/Instruction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -546,12 +546,8 @@ final public class UnconditionalCheckedCastAddrInst : Instruction, SourceDestAdd
public var isInitializationOfDestination: Bool { true }
public override var mayTrap: Bool { true }

public var isolatedConformances: CastingIsolatedConformances {
switch bridged.UnconditionalCheckedCastAddr_getIsolatedConformances() {
case .Allow: .allow
case .Prohibit: .prohibit
@unknown default: fatalError("Unhandled CastingIsolatedConformances")
}
public var checkedCastOptions: CheckedCastInstOptions {
.init(storage: bridged.UnconditionalCheckedCastAddr_getCheckedCastOptions().storage)
}
}

Expand Down Expand Up @@ -1060,12 +1056,8 @@ class UnconditionalCheckedCastInst : SingleValueInstruction, UnaryInstruction {
CanonicalType(bridged: bridged.UnconditionalCheckedCast_getTargetFormalType())
}

public var isolatedConformances: CastingIsolatedConformances {
switch bridged.UnconditionalCheckedCast_getIsolatedConformances() {
case .Allow: .allow
case .Prohibit: .prohibit
@unknown default: fatalError("Unhandled CastingIsolatedConformances")
}
public var checkedCastOptions: CheckedCastInstOptions {
.init(storage: bridged.UnconditionalCheckedCast_getCheckedCastOptions().storage)
}
}

Expand Down Expand Up @@ -1793,16 +1785,21 @@ final public class DynamicMethodBranchInst : TermInst {
final public class AwaitAsyncContinuationInst : TermInst, UnaryInstruction {
}

public struct CheckedCastInstOptions {
var storage: UInt8 = 0

var bridged: BridgedInstruction.CheckedCastInstOptions {
.init(storage: storage)
}

var isolatedConformances: CastingIsolatedConformances {
return (storage & 0x01) != 0 ? .prohibit : .allow
}
}

public enum CastingIsolatedConformances {
case allow
case prohibit

var bridged: BridgedInstruction.CastingIsolatedConformances {
switch self {
case .allow: return .Allow
case .prohibit: return .Prohibit
}
}
}

final public class CheckedCastBranchInst : TermInst, UnaryInstruction {
Expand All @@ -1814,12 +1811,8 @@ final public class CheckedCastBranchInst : TermInst, UnaryInstruction {
bridged.CheckedCastBranch_updateSourceFormalTypeFromOperandLoweredType()
}

public var isolatedConformances: CastingIsolatedConformances {
switch bridged.CheckedCastBranch_getIsolatedConformances() {
case .Allow: return .allow
case .Prohibit: return .prohibit
default: fatalError("Bad CastingIsolatedConformances value")
}
public var checkedCastOptions: CheckedCastInstOptions {
.init(storage: bridged.CheckedCastBranch_getCheckedCastOptions().storage)
}
}

Expand Down Expand Up @@ -1862,12 +1855,8 @@ final public class CheckedCastAddrBranchInst : TermInst {
}
}

public var isolatedConformances: CastingIsolatedConformances {
switch bridged.CheckedCastAddrBranch_getIsolatedConformances() {
case .Allow: .allow
case .Prohibit: .prohibit
@unknown default: fatalError("Unhandled CastingIsolatedConformances")
}
public var checkedCastOptions: CheckedCastInstOptions {
.init(storage: bridged.CheckedCastAddrBranch_getCheckedCastOptions().storage)
}
}

Expand Down
10 changes: 5 additions & 5 deletions include/swift/AST/ProtocolConformance.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class alignas(1 << DeclAlignInBits) ProtocolConformance
Kind : bitmax(NumProtocolConformanceKindBits, 8),

/// Whether the "raw" conformance isolation is "inferred", which applies to most conformances.
IsRawConformanceInferred : 1,
IsRawIsolationInferred : 1,

/// Whether the computed actor isolation is nonisolated.
IsComputedNonisolated : 1
Expand Down Expand Up @@ -205,16 +205,16 @@ class alignas(1 << DeclAlignInBits) ProtocolConformance
ProtocolConformance(ProtocolConformanceKind kind, Type conformingType)
: ConformingType(conformingType) {
Bits.ProtocolConformance.Kind = unsigned(kind);
Bits.ProtocolConformance.IsRawConformanceInferred = false;
Bits.ProtocolConformance.IsRawIsolationInferred = false;
Bits.ProtocolConformance.IsComputedNonisolated = false;
}

bool isRawConformanceInferred() const {
return Bits.ProtocolConformance.IsRawConformanceInferred;
bool isRawIsolationInferred() const {
return Bits.ProtocolConformance.IsRawIsolationInferred;
}

void setRawConformanceInferred(bool value = true) {
Bits.ProtocolConformance.IsRawConformanceInferred = value;
Bits.ProtocolConformance.IsRawIsolationInferred = value;
}

bool isComputedNonisolated() const {
Expand Down
8 changes: 4 additions & 4 deletions include/swift/AST/TypeCheckRequests.h
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ class ConformanceHasEffectRequest :

class RawConformanceIsolationRequest :
public SimpleRequest<RawConformanceIsolationRequest,
std::optional<ActorIsolation>(ProtocolConformance *),
std::optional<ActorIsolation>(NormalProtocolConformance *),
RequestFlags::SeparatelyCached |
RequestFlags::SplitCached> {
public:
Expand All @@ -488,7 +488,7 @@ class RawConformanceIsolationRequest :

// Evaluation.
std::optional<ActorIsolation>
evaluate(Evaluator &evaluator, ProtocolConformance *conformance) const;
evaluate(Evaluator &evaluator, NormalProtocolConformance *conformance) const;

public:
// Separate caching.
Expand All @@ -499,7 +499,7 @@ class RawConformanceIsolationRequest :

class ConformanceIsolationRequest :
public SimpleRequest<ConformanceIsolationRequest,
ActorIsolation(ProtocolConformance *),
ActorIsolation(NormalProtocolConformance *),
RequestFlags::SeparatelyCached |
RequestFlags::SplitCached> {
public:
Expand All @@ -510,7 +510,7 @@ class ConformanceIsolationRequest :

// Evaluation.
ActorIsolation
evaluate(Evaluator &evaluator, ProtocolConformance *conformance) const;
evaluate(Evaluator &evaluator, NormalProtocolConformance *conformance) const;

public:
// Separate caching.
Expand Down
4 changes: 2 additions & 2 deletions include/swift/AST/TypeCheckerTypeIDZone.def
Original file line number Diff line number Diff line change
Expand Up @@ -407,11 +407,11 @@ SWIFT_REQUEST(TypeChecker, ConformanceHasEffectRequest,
bool(EffectKind, ProtocolConformanceRef),
Cached, NoLocationInfo)
SWIFT_REQUEST(TypeChecker, RawConformanceIsolationRequest,
std::optional<ActorIsolation>(ProtocolConformance *),
std::optional<ActorIsolation>(NormalProtocolConformance *),
SeparatelyCached | SplitCached,
NoLocationInfo)
SWIFT_REQUEST(TypeChecker, ConformanceIsolationRequest,
ActorIsolation(ProtocolConformance *),
ActorIsolation(NormalProtocolConformance *),
SeparatelyCached | SplitCached,
NoLocationInfo)
SWIFT_REQUEST(TypeChecker, ResolveTypeRequest,
Expand Down
12 changes: 6 additions & 6 deletions include/swift/SIL/DynamicCasts.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ bool canIRGenUseScalarCheckedCastInstructions(SILModule &M,
/// using a scalar cast operation.
void emitIndirectConditionalCastWithScalar(
SILBuilder &B, ModuleDecl *M, SILLocation loc,
CastingIsolatedConformances isolatedConformances,
CheckedCastInstOptions options,
CastConsumptionKind consumption, SILValue src, CanType sourceType,
SILValue dest, CanType targetType, SILBasicBlock *trueBB,
SILBasicBlock *falseBB, ProfileCounter TrueCount = ProfileCounter(),
Expand Down Expand Up @@ -458,18 +458,18 @@ struct SILDynamicCastInst {
getModule(), getSourceFormalType(), getTargetFormalType());
}

CastingIsolatedConformances getIsolatedConformances() const {
CheckedCastInstOptions getCheckedCastOptions() const {
switch (getKind()) {
case SILDynamicCastKind::CheckedCastAddrBranchInst:
return cast<CheckedCastAddrBranchInst>(inst)->getIsolatedConformances();
return cast<CheckedCastAddrBranchInst>(inst)->getCheckedCastOptions();
case SILDynamicCastKind::CheckedCastBranchInst:
return cast<CheckedCastBranchInst>(inst)->getIsolatedConformances();
return cast<CheckedCastBranchInst>(inst)->getCheckedCastOptions();
case SILDynamicCastKind::UnconditionalCheckedCastAddrInst:
return cast<UnconditionalCheckedCastAddrInst>(inst)
->getIsolatedConformances();
->getCheckedCastOptions();
case SILDynamicCastKind::UnconditionalCheckedCastInst:
return cast<UnconditionalCheckedCastInst>(inst)
->getIsolatedConformances();
->getCheckedCastOptions();
}
}
};
Expand Down
25 changes: 12 additions & 13 deletions include/swift/SIL/SILBridging.h
Original file line number Diff line number Diff line change
Expand Up @@ -716,9 +716,8 @@ struct BridgedInstruction {
CopyOnSuccess
};

enum class CastingIsolatedConformances {
Allow,
Prohibit
struct CheckedCastInstOptions {
uint8_t storage;
};

SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedStringRef CondFailInst_getMessage() const;
Expand Down Expand Up @@ -831,22 +830,22 @@ struct BridgedInstruction {
BRIDGED_INLINE void LoadInst_setOwnership(SwiftInt ownership) const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedCanType UnconditionalCheckedCast_getSourceFormalType() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedCanType UnconditionalCheckedCast_getTargetFormalType() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE CastingIsolatedConformances
UnconditionalCheckedCast_getIsolatedConformances() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE CheckedCastInstOptions
UnconditionalCheckedCast_getCheckedCastOptions() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedCanType UnconditionalCheckedCastAddr_getSourceFormalType() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedCanType UnconditionalCheckedCastAddr_getTargetFormalType() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE CastingIsolatedConformances
UnconditionalCheckedCastAddr_getIsolatedConformances() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE CheckedCastInstOptions
UnconditionalCheckedCastAddr_getCheckedCastOptions() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedBasicBlock CheckedCastBranch_getSuccessBlock() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedBasicBlock CheckedCastBranch_getFailureBlock() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE CastingIsolatedConformances
CheckedCastBranch_getIsolatedConformances() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE CheckedCastInstOptions
CheckedCastBranch_getCheckedCastOptions() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedCanType CheckedCastAddrBranch_getSourceFormalType() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedCanType CheckedCastAddrBranch_getTargetFormalType() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedBasicBlock CheckedCastAddrBranch_getSuccessBlock() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedBasicBlock CheckedCastAddrBranch_getFailureBlock() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE CastingIsolatedConformances
CheckedCastAddrBranch_getIsolatedConformances() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE CheckedCastInstOptions
CheckedCastAddrBranch_getCheckedCastOptions() const;
BRIDGED_INLINE void CheckedCastBranch_updateSourceFormalTypeFromOperandLoweredType() const;
BRIDGED_INLINE CastConsumptionKind CheckedCastAddrBranch_getConsumptionKind() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedSubstitutionMap ApplySite_getSubstitutionMap() const;
Expand Down Expand Up @@ -1176,11 +1175,11 @@ struct BridgedBuilder{
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createCheckedCastAddrBranch(
BridgedValue source, BridgedCanType sourceFormalType,
BridgedValue destination, BridgedCanType targetFormalType,
BridgedInstruction::CastingIsolatedConformances isolatedConformances,
BridgedInstruction::CheckedCastInstOptions options,
BridgedInstruction::CastConsumptionKind consumptionKind,
BridgedBasicBlock successBlock, BridgedBasicBlock failureBlock) const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createUnconditionalCheckedCastAddr(
BridgedInstruction::CastingIsolatedConformances isolatedConformances,
BridgedInstruction::CheckedCastInstOptions options,
BridgedValue source, BridgedCanType sourceFormalType,
BridgedValue destination, BridgedCanType targetFormalType) const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createUncheckedOwnershipConversion(
Expand Down
Loading