@@ -21,13 +21,17 @@ class RoutineDefinitionBuilder :
2121 }
2222
2323 fun build (): RoutineDefinition {
24- val comm = Comm .of(this .inputShape, this .outputShape)
24+ val inputShape = this .inputShape
25+ ? : error(" Input shape not specified" )
26+ val outputShape = this .outputShape
27+ ? : error(" Output shape not specified" )
28+ val comm = Comm .of(inputShape, outputShape)
2529 ? : error(" Cannot get Comm from input=$inputShape output=$outputShape " )
2630
27- check(comm.input != Comm .Shape .Void || input.isEmpty()) {
31+ check(comm.input != Comm .Shape .Void || this . input.isEmpty()) {
2832 " Injected input cannot be delivered when input shape is Void"
2933 }
30- check(comm.output != Comm .Shape .Void || output.isEmpty()) {
34+ check(comm.output != Comm .Shape .Void || this . output.isEmpty()) {
3135 " Injected output cannot be delivered when output shape is Void"
3236 }
3337
@@ -36,8 +40,7 @@ class RoutineDefinitionBuilder :
3640 canonicalName = cn,
3741 description = this .description,
3842 metadata = this .metadata.toList(),
39- comm = Comm .of(this .inputShape, this .outputShape)
40- ? : error(" Cannot select Comm mode from input=$inputShape output=$outputShape " ),
43+ comm = comm,
4144 faults = this .faults.mapIndexed { i, it ->
4245 it.get(cn, name = " fault$i " )
4346 },
@@ -79,6 +82,68 @@ operator fun Comm.unaryPlus() {
7982
8083// //////////////////////////////////////
8184
85+ @Marker0
86+ context(ctx: RoutineDefinitionBuilder )
87+ fun voidInput () {
88+ check(ctx.inputShape == null || ctx.inputShape == Comm .Shape .Void ) {
89+ " Input shape conflict: Shape was already set to ${ctx.inputShape} "
90+ }
91+
92+ ctx.inputShape = Comm .Shape .Void
93+ }
94+
95+ @Marker0
96+ context(ctx: RoutineDefinitionBuilder )
97+ fun voidOutput () {
98+ check(ctx.outputShape == null || ctx.outputShape == Comm .Shape .Void ) {
99+ " Output shape conflict: Shape was already set to ${ctx.outputShape} "
100+ }
101+
102+ ctx.outputShape = Comm .Shape .Void
103+ }
104+
105+ @Marker0
106+ context(ctx: RoutineDefinitionBuilder )
107+ fun unaryInput () {
108+ check(ctx.inputShape == null || ctx.inputShape == Comm .Shape .Unary ) {
109+ " Input shape conflict: Shape was already set to ${ctx.inputShape} "
110+ }
111+
112+ ctx.inputShape = Comm .Shape .Unary
113+ }
114+
115+ @Marker0
116+ context(ctx: RoutineDefinitionBuilder )
117+ fun unaryOutput () {
118+ check(ctx.outputShape == null || ctx.outputShape == Comm .Shape .Unary ) {
119+ " Output shape conflict: Shape was already set to ${ctx.outputShape} "
120+ }
121+
122+ ctx.outputShape = Comm .Shape .Unary
123+ }
124+
125+ @Marker0
126+ context(ctx: RoutineDefinitionBuilder )
127+ fun streamInput () {
128+ check(ctx.inputShape == null || ctx.inputShape == Comm .Shape .Stream ) {
129+ " Input shape conflict: Shape was already set to ${ctx.inputShape} "
130+ }
131+
132+ ctx.inputShape = Comm .Shape .Stream
133+ }
134+
135+ @Marker0
136+ context(ctx: RoutineDefinitionBuilder )
137+ fun streamOutput () {
138+ check(ctx.outputShape == null || ctx.outputShape == Comm .Shape .Stream ) {
139+ " Output shape conflict: Shape was already set to ${ctx.outputShape} "
140+ }
141+
142+ ctx.outputShape = Comm .Shape .Stream
143+ }
144+
145+ // //////////////////////////////////////
146+
82147data object UnaryCommShapeKeyword
83148
84149@Marker0
0 commit comments