wwt / SwiftCurrent

A library for managing complex workflows in Swift
https://wwt.github.io/SwiftCurrent/
Apache License 2.0
307 stars 19 forks source link

Intermediate Representation Generator #176

Closed morganzellers closed 2 years ago

morganzellers commented 2 years ago

Linked Issue:

Checklist:

morganzellers commented 2 years ago

Separating some things out in prep to get this past a spike phase

morganzellers commented 2 years ago

Notes for tomorrow:

Need to check inside enums better Need to be able to find parent name Formatting output Consider some actual objects instead of packing things around in dictionaries?

morganzellers commented 2 years ago

Was able to better check embedded types and link conforming types with their parents in a rough pass sort of way.

Currently getting this output:

Checking WorkflowDecodable...
extensions conforming to WorkflowDecodable:
- [FooName]
protocols conforming to WorkflowDecodable:
- [FRToo]
- [FooToo]
- [ScrewWithMorgan]
structs conforming to WorkflowDecodable:
- [Namespace.MyType]
Checking FRToo...
structs conforming to FRToo:
- [LoginView]
Checking FooToo...
structs conforming to FooToo:
- [FooView]
Checking ScrewWithMorgan...
structs conforming to ScrewWithMorgan:
- [Lulz]

From these:

final class FooName: View {
    var _workflowPointer: AnyFlowRepresentable?
    var body: some View { Text("Foo") }
}

extension FooName: FlowRepresentable, WorkflowDecodable {
    static var flowRepresentableName: String {
        "FooName"
    }

    static func metadataFactory(launchStyle: LaunchStyle, flowPersistence: @escaping (AnyWorkflow.PassedArgs) -> FlowPersistence) -> FlowRepresentableMetadata {
        FlowRepresentableMetadata(Self.self, launchStyle: launchStyle, flowPersistence: flowPersistence)
    }
}

protocol FRToo: FlowRepresentable, WorkflowDecodable {
}

protocol FooToo: FlowRepresentable, WorkflowDecodable {
}

enum Namespace {
    struct MyType: FlowRepresentable, WorkflowDecodable { /* ... */ }
}

protocol ScrewWithMorgan: WorkflowDecodable { }

struct Lulz: FlowRepresentable, ScrewWithMorgan { /* ... */ }

struct FooView: View, FooToo {
    static var flowRepresentableName: String {
        "FooView"
    }

    static func metadataFactory(launchStyle: LaunchStyle, flowPersistence: @escaping (AnyWorkflow.PassedArgs) -> FlowPersistence) -> FlowRepresentableMetadata {
        FlowRepresentableMetadata(Self.self, launchStyle: launchStyle, flowPersistence: flowPersistence)
    }

    var _workflowPointer: AnyFlowRepresentable?

    var body: some View {
        Text("Woo")
    }
}

struct LoginView: View, FRToo {
....
morganzellers commented 2 years ago

Have lately been trying to find a good (efficient) way to find that FooThreeView conforms to WorkflowDecodable in this example:

protocol FooToo: FlowRepresentable, WorkflowDecodable { }

protocol FooThree: FooToo { }

struct FooThreeView: View, FooThree { }

With the current (non-efficient) approach, finding this conformance requires passing over the files a second time in order to find conforming types.

Next, I'm moving to:

morganzellers commented 2 years ago

Work here was moved to the swiftcurrent-ir-generator branch and a new Pull Request (#186) has been opened. Closing this PR.