Skip to content

Revert "Optimizer/IRGen: allow enums in static initializers of globals" #66170

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

Closed
wants to merge 1 commit into from
Closed
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 @@ -16,11 +16,9 @@ swift_compiler_sources(Optimizer
SimplifyDebugStep.swift
SimplifyDestructure.swift
SimplifyGlobalValue.swift
SimplifyInitEnumDataAddr.swift
SimplifyLoad.swift
SimplifyPartialApply.swift
SimplifyStrongRetainRelease.swift
SimplifyStructExtract.swift
SimplifyTupleExtract.swift
SimplifyUncheckedEnumData.swift
SimplifyValueToBridgeObject.swift)
SimplifyUncheckedEnumData.swift)

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ struct FunctionPassContext : MutatingContext {
var notifyInstructionChanged: (Instruction) -> () { return { inst in } }

func continueWithNextSubpassRun(for inst: Instruction? = nil) -> Bool {
return _bridged.continueWithNextSubpassRun(inst.bridged)
let bridgedInst = OptionalBridgedInstruction(inst?.bridged.obj)
return _bridged.continueWithNextSubpassRun(bridgedInst)
}

func createSimplifyContext(preserveDebugInfo: Bool, notifyInstructionChanged: @escaping (Instruction) -> ()) -> SimplifyContext {
Expand Down
15 changes: 3 additions & 12 deletions SwiftCompilerSources/Sources/SIL/Builder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public struct Builder {
return notifyNew(cast.getAs(UpcastInst.self))
}

public func createLoad(fromAddress: Value, ownership: LoadInst.Ownership) -> LoadInst {
public func createLoad(fromAddress: Value, ownership: LoadInst.LoadOwnership) -> LoadInst {
let load = bridged.createLoad(fromAddress.bridged, ownership.rawValue)
return notifyNew(load.getAs(LoadInst.self))
}
Expand Down Expand Up @@ -184,12 +184,6 @@ public struct Builder {
let ued = bridged.createUncheckedEnumData(enumVal.bridged, caseIndex, resultType.bridged)
return notifyNew(ued.getAs(UncheckedEnumDataInst.self))
}

public func createEnum(caseIndex: Int, payload: Value?, enumType: Type) -> EnumInst {
let enumInst = bridged.createEnum(caseIndex, payload.bridged, enumType.bridged)
return notifyNew(enumInst.getAs(EnumInst.self))
}

@discardableResult
public func createSwitchEnum(enum enumVal: Value,
cases: [(Int, BasicBlock)],
Expand Down Expand Up @@ -231,23 +225,20 @@ public struct Builder {
return notifyNew(bridged.createGlobalValue(global.bridged).getAs(GlobalValueInst.self))
}

@discardableResult
public func createStruct(type: Type, elements: [Value]) -> StructInst {
let structInst = elements.withBridgedValues { valuesRef in
return bridged.createStruct(type.bridged, valuesRef)
}
return notifyNew(structInst.getAs(StructInst.self))
}

@discardableResult
public func createTuple(type: Type, elements: [Value]) -> TupleInst {
let tuple = elements.withBridgedValues { valuesRef in
return bridged.createTuple(type.bridged, valuesRef)
}
return notifyNew(tuple.getAs(TupleInst.self))
}

@discardableResult
public func createStore(source: Value, destination: Value, ownership: StoreInst.Ownership) -> StoreInst {
let store = bridged.createStore(source.bridged, destination.bridged, ownership.rawValue)
return notifyNew(store.getAs(StoreInst.self))
}
}
1 change: 0 additions & 1 deletion SwiftCompilerSources/Sources/SIL/GlobalVariable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ extension Instruction {
return !fri.referencedFunction.isAsync
case is StructInst,
is TupleInst,
is EnumInst,
is IntegerLiteralInst,
is FloatLiteralInst,
is ObjectInst,
Expand Down
39 changes: 7 additions & 32 deletions SwiftCompilerSources/Sources/SIL/Instruction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,6 @@ extension OptionalBridgedInstruction {
}
}

extension Optional where Wrapped == Instruction {
public var bridged: OptionalBridgedInstruction {
OptionalBridgedInstruction(self?.bridged.obj)
}
}

public class SingleValueInstruction : Instruction, Value {
final public var definingInstruction: Instruction? { self }

Expand Down Expand Up @@ -228,23 +222,11 @@ extension StoringInstruction {

final public class StoreInst : Instruction, StoringInstruction {
// must match with enum class StoreOwnershipQualifier
public enum Ownership: Int {
public enum StoreOwnership: Int {
case unqualified = 0, initialize = 1, assign = 2, trivial = 3

public init(for type: Type, in function: Function, initialize: Bool) {
if function.hasOwnership {
if type.isTrivial(in: function) {
self = .trivial
} else {
self = initialize ? .initialize : .assign
}
} else {
self = .unqualified
}
}
}
public var destinationOwnership: Ownership {
Ownership(rawValue: bridged.StoreInst_getStoreOwnership())!
public var destinationOwnership: StoreOwnership {
StoreOwnership(rawValue: bridged.StoreInst_getStoreOwnership())!
}
}

Expand Down Expand Up @@ -325,7 +307,6 @@ final public class DestroyAddrInst : Instruction, UnaryInstruction {
}

final public class InjectEnumAddrInst : Instruction, UnaryInstruction, EnumInstruction {
public var `enum`: Value { operand.value }
public var caseIndex: Int { bridged.InjectEnumAddrInst_caseIndex() }
}

Expand Down Expand Up @@ -370,11 +351,11 @@ final public class LoadInst : SingleValueInstruction, UnaryInstruction {
public var address: Value { operand.value }

// must match with enum class LoadOwnershipQualifier
public enum Ownership: Int {
public enum LoadOwnership: Int {
case unqualified = 0, take = 1, copy = 2, trivial = 3
}
public var ownership: Ownership {
Ownership(rawValue: bridged.LoadInst_getLoadOwnership())!
public var ownership: LoadOwnership {
LoadOwnership(rawValue: bridged.LoadInst_getLoadOwnership())!
}
}

Expand Down Expand Up @@ -407,10 +388,6 @@ final public class UncheckedAddrCastInst : SingleValueInstruction, UnaryInstruct
public var fromAddress: Value { operand.value }
}

final public class UncheckedTrivialBitCastInst : SingleValueInstruction, UnaryInstruction {
public var fromValue: Value { operand.value }
}

final public
class RawPointerToRefInst : SingleValueInstruction, UnaryInstruction {
public var pointer: Value { operand.value }
Expand Down Expand Up @@ -649,9 +626,7 @@ final public
class ObjCMetatypeToObjectInst : SingleValueInstruction, UnaryInstruction {}

final public
class ValueToBridgeObjectInst : SingleValueInstruction, UnaryInstruction {
public var value: Value { return operand.value }
}
class ValueToBridgeObjectInst : SingleValueInstruction, UnaryInstruction {}

final public
class MarkDependenceInst : SingleValueInstruction {
Expand Down
1 change: 0 additions & 1 deletion SwiftCompilerSources/Sources/SIL/Registration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ public func registerSILClasses() {
register(UpcastInst.self)
register(UncheckedRefCastInst.self)
register(UncheckedAddrCastInst.self)
register(UncheckedTrivialBitCastInst.self)
register(MarkMustCheckInst.self)
register(ObjectInst.self)
register(RawPointerToRefInst.self)
Expand Down
4 changes: 0 additions & 4 deletions SwiftCompilerSources/Sources/SIL/Type.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ public struct Type : CustomStringConvertible, NoReflectionChildren {
return !bridged.isNonTrivialOrContainsRawPointer(function.bridged.getFunction())
}

public func isLoadable(in function: Function) -> Bool {
return bridged.isLoadable(function.bridged.getFunction())
}

public func isReferenceCounted(in function: Function) -> Bool {
return bridged.isReferenceCounted(function.bridged.getFunction())
}
Expand Down
6 changes: 0 additions & 6 deletions SwiftCompilerSources/Sources/SIL/Value.swift
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,3 @@ final class PlaceholderValue : Value {
extension OptionalBridgedValue {
public var value: Value? { obj.getAs(AnyObject.self) as? Value }
}

extension Optional where Wrapped == Value {
public var bridged: OptionalBridgedValue {
OptionalBridgedValue(obj: self?.bridged.obj)
}
}
21 changes: 0 additions & 21 deletions include/swift/SIL/SILBridging.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,6 @@ struct BridgedValue {

struct OptionalBridgedValue {
OptionalSwiftObject obj;

swift::SILValue getSILValue() const {
if (obj)
return static_cast<swift::ValueBase *>(obj);
return swift::SILValue();
}
};

inline swift::ValueOwnershipKind castToOwnership(BridgedValue::Ownership ownership) {
Expand Down Expand Up @@ -1179,14 +1173,6 @@ struct BridgedBuilder{
en->getType().getEnumElement(caseIdx), resultType)};
}

SWIFT_IMPORT_UNSAFE
BridgedInstruction createEnum(SwiftInt caseIdx, OptionalBridgedValue payload,
swift::SILType resultType) const {
swift::EnumElementDecl *caseDecl = resultType.getEnumElement(caseIdx);
swift::SILValue pl = payload.getSILValue();
return {builder().createEnum(regularLoc(), pl, caseDecl, resultType)};
}

SWIFT_IMPORT_UNSAFE
BridgedInstruction createBranch(BridgedBasicBlock destBlock, BridgedValueArray arguments) const {
llvm::SmallVector<swift::SILValue, 16> argValues;
Expand Down Expand Up @@ -1226,13 +1212,6 @@ struct BridgedBuilder{
llvm::SmallVector<swift::SILValue, 16> elementValues;
return {builder().createTuple(regularLoc(), type, elements.getValues(elementValues))};
}

SWIFT_IMPORT_UNSAFE
BridgedInstruction createStore(BridgedValue src, BridgedValue dst,
SwiftInt ownership) const {
return {builder().createStore(regularLoc(), src.getSILValue(), dst.getSILValue(),
(swift::StoreOwnershipQualifier)ownership)};
}
};

// AST bridging
Expand Down
2 changes: 0 additions & 2 deletions include/swift/SIL/SILType.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,6 @@ class SILType {
return !isAddressOnly(F);
}

bool isLoadable(const SILFunction *f) const { return isLoadable(*f); }

/// True if either:
/// 1) The type, or the referenced type of an address type, is loadable.
/// 2) The SIL Module conventions uses lowered addresses
Expand Down
Loading