@@ -657,7 +657,7 @@ private RustFile operationOuterModule(final OperationShape operationShape) {
657
657
StructureShape outputShape = operationIndex
658
658
.getOutputShape (operationShape )
659
659
.get ();
660
- if (inputShape .hasTrait (PositionalTrait .class )) {
660
+ if (outputShape .hasTrait (PositionalTrait .class )) {
661
661
variables .put (
662
662
"outputFromDafny" ,
663
663
fromDafny (outputShape , "inner_result.value()" , false , false )
@@ -1175,7 +1175,7 @@ protected Set<RustFile> operationConversionModules(
1175
1175
operationName (operationShape )
1176
1176
);
1177
1177
1178
- Optional <StructureShape > inputStructure = operationIndex .getOutputShape (
1178
+ Optional <StructureShape > inputStructure = operationIndex .getInputShape (
1179
1179
operationShape
1180
1180
);
1181
1181
final boolean hasInputStructure =
@@ -1307,7 +1307,6 @@ private TokenTree operationStructureFromDafnyFunction(
1307
1307
structureId ,
1308
1308
StructureShape .class
1309
1309
);
1310
- final boolean isPositional = structureShape .hasTrait (PositionalTrait .class );
1311
1310
final Map <String , String > variables = MapUtils .merge (
1312
1311
serviceVariables (),
1313
1312
operationVariables (operationShape ),
@@ -1318,46 +1317,24 @@ private TokenTree operationStructureFromDafnyFunction(
1318
1317
fluentMemberSettersForStructure (structureShape ).toString ()
1319
1318
);
1320
1319
1321
- if (isPositional ) {
1322
- return TokenTree .of (
1323
- evalTemplate (
1324
- """
1325
- #[allow(dead_code)]
1326
- pub fn from_dafny(
1327
- dafny_value: ::std::rc::Rc<
1328
- crate::r#$dafnyTypesModuleName:L::$structureName:L,
1329
- >,
1330
- ) -> crate::operation::$snakeCaseOperationName:L::$rustStructureName:L {
1331
- crate::operation::$snakeCaseOperationName:L::$rustStructureName:L::builder()
1332
- $fluentMemberSetters:L
1333
- .build()
1334
- .unwrap()
1335
- }
1336
- """ ,
1337
- variables
1338
- )
1339
- );
1340
- } else {
1341
- // unwrap() is safe as long as the builder is infallible
1342
- return TokenTree .of (
1343
- evalTemplate (
1344
- """
1345
- #[allow(dead_code)]
1346
- pub fn from_dafny(
1347
- dafny_value: ::std::rc::Rc<
1348
- crate::r#$dafnyTypesModuleName:L::$structureName:L,
1349
- >,
1350
- ) -> crate::operation::$snakeCaseOperationName:L::$rustStructureName:L {
1351
- crate::operation::$snakeCaseOperationName:L::$rustStructureName:L::builder()
1352
- $fluentMemberSetters:L
1353
- .build()
1354
- .unwrap()
1355
- }
1356
- """ ,
1357
- variables
1358
- )
1359
- );
1360
- }
1320
+ return TokenTree .of (
1321
+ evalTemplate (
1322
+ """
1323
+ #[allow(dead_code)]
1324
+ pub fn from_dafny(
1325
+ dafny_value: ::std::rc::Rc<
1326
+ crate::r#$dafnyTypesModuleName:L::$structureName:L,
1327
+ >,
1328
+ ) -> crate::operation::$snakeCaseOperationName:L::$rustStructureName:L {
1329
+ crate::operation::$snakeCaseOperationName:L::$rustStructureName:L::builder()
1330
+ $fluentMemberSetters:L
1331
+ .build()
1332
+ .unwrap()
1333
+ }
1334
+ """ ,
1335
+ variables
1336
+ )
1337
+ );
1361
1338
}
1362
1339
1363
1340
private RustFile wrappedModule () {
@@ -1434,7 +1411,7 @@ private String wrappedClientOperationImpl(
1434
1411
StructureShape outputShape = operationIndex
1435
1412
.getOutputShape (operationShape )
1436
1413
.get ();
1437
- if (inputShape .hasTrait (PositionalTrait .class )) {
1414
+ if (outputShape .hasTrait (PositionalTrait .class )) {
1438
1415
variables .put (
1439
1416
"outputToDafny" ,
1440
1417
toDafny (outputShape , "inner_result" , false , false ).toString ()
@@ -1641,14 +1618,26 @@ protected TokenTree toDafny(
1641
1618
}
1642
1619
}
1643
1620
case BOOLEAN -> {
1644
- if (isRustOption ) {
1645
- yield TokenTree .of (
1646
- "crate::standard_library_conversions::obool_to_dafny(&%s)" .formatted (
1647
- rustValue
1648
- )
1649
- );
1621
+ if (isDafnyOption ) {
1622
+ if (isRustOption ) {
1623
+ yield TokenTree .of (
1624
+ "crate::standard_library_conversions::obool_to_dafny(&%s)" .formatted (
1625
+ rustValue
1626
+ )
1627
+ );
1628
+ } else {
1629
+ yield TokenTree .of (
1630
+ "crate::standard_library_conversions::obool_to_dafny(Some(%s))" .formatted (
1631
+ rustValue
1632
+ )
1633
+ );
1634
+ }
1650
1635
} else {
1651
- yield TokenTree .of ("%s.clone()" .formatted (rustValue ));
1636
+ if (isRustOption ) {
1637
+ yield TokenTree .of ("%s.clone().unwrap()" .formatted (rustValue ));
1638
+ } else {
1639
+ yield TokenTree .of ("%s.clone()" .formatted (rustValue ));
1640
+ }
1652
1641
}
1653
1642
}
1654
1643
case INTEGER -> {
@@ -1667,7 +1656,11 @@ protected TokenTree toDafny(
1667
1656
);
1668
1657
}
1669
1658
} else {
1670
- yield TokenTree .of ("%s.clone()" .formatted (rustValue ));
1659
+ if (isRustOption ) {
1660
+ yield TokenTree .of ("%s.clone().unwrap()" .formatted (rustValue ));
1661
+ } else {
1662
+ yield TokenTree .of ("%s.clone()" .formatted (rustValue ));
1663
+ }
1671
1664
}
1672
1665
}
1673
1666
case LONG -> {
@@ -1830,7 +1823,7 @@ protected TokenTree toDafny(
1830
1823
if (isRustOption ) {
1831
1824
yield TokenTree .of (
1832
1825
"""
1833
- %s::conversions::%s::to_dafny(& %s.clone().unwrap())
1826
+ %s::conversions::%s::to_dafny(%s.clone().unwrap())
1834
1827
""" .formatted (prefix , structureShapeName , rustValue )
1835
1828
);
1836
1829
} else {
0 commit comments