@@ -4180,11 +4180,12 @@ and printArgumentsWithCallbackInFirstPosition ~uncurried ~customLayout args
4180
4180
printPexpFun ~custom Layout ~in Callback:FitsOnOneLine expr cmtTbl;
4181
4181
]
4182
4182
in
4183
- let callback = printComments callback cmtTbl expr.pexp_loc in
4183
+ let callback = lazy ( printComments callback cmtTbl expr.pexp_loc) in
4184
4184
let printedArgs =
4185
- Doc. join
4186
- ~sep: (Doc. concat [Doc. comma; Doc. line])
4187
- (List. map (fun arg -> printArgument ~custom Layout arg cmtTbl) args)
4185
+ lazy
4186
+ (Doc. join
4187
+ ~sep: (Doc. concat [Doc. comma; Doc. line])
4188
+ (List. map (fun arg -> printArgument ~custom Layout arg cmtTbl) args))
4188
4189
in
4189
4190
(callback, printedArgs)
4190
4191
| _ -> assert false
@@ -4200,10 +4201,10 @@ and printArgumentsWithCallbackInFirstPosition ~uncurried ~customLayout args
4200
4201
(Doc. concat
4201
4202
[
4202
4203
(if uncurried then Doc. text " (. " else Doc. lparen);
4203
- callback;
4204
+ Lazy. force callback;
4204
4205
Doc. comma;
4205
4206
Doc. line;
4206
- printedArgs;
4207
+ Lazy. force printedArgs;
4207
4208
Doc. rparen;
4208
4209
])
4209
4210
in
@@ -4234,8 +4235,8 @@ and printArgumentsWithCallbackInFirstPosition ~uncurried ~customLayout args
4234
4235
* In this case, we always want the arguments broken over multiple lines,
4235
4236
* like a normal function call.
4236
4237
*)
4237
- if Doc. willBreak printedArgs then Lazy. force breakAllArgs
4238
- else if customLayout > customLayoutThreshold then Lazy. force fitsOnOneLine
4238
+ if customLayout > customLayoutThreshold then Lazy. force breakAllArgs
4239
+ else if Doc. willBreak ( Lazy. force printedArgs) then Lazy. force breakAllArgs
4239
4240
else Doc. customLayout [Lazy. force fitsOnOneLine; Lazy. force breakAllArgs]
4240
4241
4241
4242
and printArgumentsWithCallbackInLastPosition ~customLayout ~uncurried args
@@ -4248,7 +4249,7 @@ and printArgumentsWithCallbackInLastPosition ~customLayout ~uncurried args
4248
4249
let cmtTblCopy2 = CommentTable. copy cmtTbl in
4249
4250
let rec loop acc args =
4250
4251
match args with
4251
- | [] -> (Doc. nil, Doc. nil, Doc. nil)
4252
+ | [] -> (lazy Doc. nil, lazy Doc. nil, lazy Doc. nil)
4252
4253
| [(lbl, expr)] ->
4253
4254
let lblDoc =
4254
4255
match lbl with
@@ -4259,21 +4260,23 @@ and printArgumentsWithCallbackInLastPosition ~customLayout ~uncurried args
4259
4260
Doc. concat [Doc. tilde; printIdentLike txt; Doc. equal; Doc. question]
4260
4261
in
4261
4262
let callbackFitsOnOneLine =
4262
- let pexpFunDoc =
4263
- printPexpFun ~custom Layout ~in Callback:FitsOnOneLine expr cmtTbl
4264
- in
4265
- let doc = Doc. concat [lblDoc; pexpFunDoc] in
4266
- printComments doc cmtTbl expr.pexp_loc
4263
+ lazy
4264
+ (let pexpFunDoc =
4265
+ printPexpFun ~custom Layout ~in Callback:FitsOnOneLine expr cmtTbl
4266
+ in
4267
+ let doc = Doc. concat [lblDoc; pexpFunDoc] in
4268
+ printComments doc cmtTbl expr.pexp_loc)
4267
4269
in
4268
4270
let callbackArgumentsFitsOnOneLine =
4269
- let pexpFunDoc =
4270
- printPexpFun ~custom Layout ~in Callback:ArgumentsFitOnOneLine expr
4271
- cmtTblCopy
4272
- in
4273
- let doc = Doc. concat [lblDoc; pexpFunDoc] in
4274
- printComments doc cmtTblCopy expr.pexp_loc
4271
+ lazy
4272
+ (let pexpFunDoc =
4273
+ printPexpFun ~custom Layout ~in Callback:ArgumentsFitOnOneLine expr
4274
+ cmtTblCopy
4275
+ in
4276
+ let doc = Doc. concat [lblDoc; pexpFunDoc] in
4277
+ printComments doc cmtTblCopy expr.pexp_loc)
4275
4278
in
4276
- ( Doc. concat (List. rev acc),
4279
+ ( lazy ( Doc. concat (List. rev acc) ),
4277
4280
callbackFitsOnOneLine,
4278
4281
callbackArgumentsFitsOnOneLine )
4279
4282
| arg :: args ->
@@ -4288,8 +4291,8 @@ and printArgumentsWithCallbackInLastPosition ~customLayout ~uncurried args
4288
4291
(Doc. concat
4289
4292
[
4290
4293
(if uncurried then Doc. text " (." else Doc. lparen);
4291
- printedArgs;
4292
- callback;
4294
+ Lazy. force printedArgs;
4295
+ Lazy. force callback;
4293
4296
Doc. rparen;
4294
4297
])
4295
4298
in
@@ -4303,8 +4306,8 @@ and printArgumentsWithCallbackInLastPosition ~customLayout ~uncurried args
4303
4306
(Doc. concat
4304
4307
[
4305
4308
(if uncurried then Doc. text " (." else Doc. lparen);
4306
- printedArgs;
4307
- Doc. breakableGroup ~force Break:true callback2;
4309
+ Lazy. force printedArgs;
4310
+ Doc. breakableGroup ~force Break:true ( Lazy. force callback2) ;
4308
4311
Doc. rparen;
4309
4312
])
4310
4313
in
@@ -4335,8 +4338,8 @@ and printArgumentsWithCallbackInLastPosition ~customLayout ~uncurried args
4335
4338
* In this case, we always want the arguments broken over multiple lines,
4336
4339
* like a normal function call.
4337
4340
*)
4338
- if Doc. willBreak printedArgs then Lazy. force breakAllArgs
4339
- else if customLayout > customLayoutThreshold then Lazy. force fitsOnOneLine
4341
+ if customLayout > customLayoutThreshold then Lazy. force breakAllArgs
4342
+ else if Doc. willBreak ( Lazy. force printedArgs) then Lazy. force breakAllArgs
4340
4343
else
4341
4344
Doc. customLayout
4342
4345
[
0 commit comments