Skip to content

Commit 6ef99bf

Browse files
committed
fix how to lift mono types to poly types as to MustBeBoundRow
1 parent 8913a12 commit 6ef99bf

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

src/frontend/typeConv.ml

+25-12
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ let instantiate_macro_type (lev : level) (qtfbl : quantifiability) (pmacty : pol
216216
| BlockMacroType(pmacparamtys) -> BlockMacroType(pmacparamtys |> List.map aux)
217217

218218

219-
let lift_poly_general (intern_ty : FreeID.t -> BoundID.t option) (intern_row : FreeRowID.t -> LabelSet.t -> BoundRowID.t option) (must_be_bound : MustBeBoundID.t -> bool) (ty : mono_type) : poly_type_body =
219+
let lift_poly_general (intern_ty : FreeID.t -> BoundID.t option) (intern_row : FreeRowID.t -> LabelSet.t -> BoundRowID.t option) (must_be_bound : MustBeBoundID.t -> bool) (must_be_bound_row : MustBeBoundRowID.t -> bool) (ty : mono_type) : poly_type_body =
220220
let rec iter ((rng, tymain) : mono_type) =
221221
match tymain with
222222
| TypeVariable(tv) ->
@@ -248,9 +248,9 @@ let lift_poly_general (intern_ty : FreeID.t -> BoundID.t option) (intern_row : F
248248
(rng, TypeVariable(ptvi))
249249
end
250250

251-
| FuncType(optrow, tydom, tycod) -> (rng, FuncType(generalize_row LabelSet.empty optrow, iter tydom, iter tycod))
251+
| FuncType(optrow, tydom, tycod) -> (rng, FuncType(iter_row LabelSet.empty optrow, iter tydom, iter tycod))
252252
| ProductType(tys) -> (rng, ProductType(TupleList.map iter tys))
253-
| RecordType(row) -> (rng, RecordType(generalize_row LabelSet.empty row))
253+
| RecordType(row) -> (rng, RecordType(iter_row LabelSet.empty row))
254254
| DataType(tyargs, tyid) -> (rng, DataType(List.map iter tyargs, tyid))
255255
| ListType(tysub) -> (rng, ListType(iter tysub))
256256
| RefType(tysub) -> (rng, RefType(iter tysub))
@@ -260,13 +260,13 @@ let lift_poly_general (intern_ty : FreeID.t -> BoundID.t option) (intern_row : F
260260
| MathCommandType(tys) -> (rng, MathCommandType(List.map (lift_argument_type iter) tys))
261261
| CodeType(tysub) -> (rng, CodeType(iter tysub))
262262

263-
and generalize_row (labset : LabelSet.t) = function
263+
and iter_row (labset : LabelSet.t) = function
264264
| RowEmpty ->
265265
RowEmpty
266266

267267
| RowCons(rlabel, ty, tail) ->
268268
let (_, label) = rlabel in
269-
RowCons(rlabel, iter ty, generalize_row (labset |> LabelSet.add label) tail)
269+
RowCons(rlabel, iter ty, iter_row (labset |> LabelSet.add label) tail)
270270

271271
| RowVar(UpdatableRow(orviref) as rv0) ->
272272
begin
@@ -282,12 +282,19 @@ let lift_poly_general (intern_ty : FreeID.t -> BoundID.t option) (intern_row : F
282282
end
283283

284284
| MonoRowLink(row) ->
285-
generalize_row labset row
285+
iter_row labset row
286286
end
287287

288-
| RowVar(MustBeBoundRow(mbbrid)) ->
289-
let brid = MustBeBoundRowID.to_bound_id mbbrid in
290-
RowVar(PolyRowBound(brid))
288+
| RowVar(MustBeBoundRow(mbbrid) as rv0) ->
289+
let prvi =
290+
if must_be_bound_row mbbrid then
291+
let brid = MustBeBoundRowID.to_bound_id mbbrid in
292+
PolyRowBound(brid)
293+
else
294+
PolyRowFree(rv0)
295+
in
296+
RowVar(prvi)
297+
291298
in
292299
iter ty
293300

@@ -332,14 +339,16 @@ let generalize (lev : level) (ty : mono_type) : poly_type =
332339
let intern_ty = make_type_generalization_intern lev tvid_ht in
333340
let intern_row = make_row_generalization_intern lev rvid_ht in
334341
let must_be_bound (mbbid : MustBeBoundID.t) = Level.less_than lev (MustBeBoundID.get_level mbbid) in
335-
Poly(lift_poly_general intern_ty intern_row must_be_bound ty)
342+
let must_be_bound_row (mbbrid : MustBeBoundRowID.t) = Level.less_than lev (MustBeBoundRowID.get_level mbbrid) in
343+
Poly(lift_poly_general intern_ty intern_row must_be_bound must_be_bound_row ty)
336344

337345

338346
let lift_poly_body =
339347
lift_poly_general
340348
(fun _ -> None)
341349
(fun _ _ -> None)
342350
(fun _ -> false)
351+
(fun _ -> false)
343352

344353

345354
let lift_poly (ty : mono_type) : poly_type =
@@ -352,9 +361,13 @@ let generalize_macro_type (macty : mono_macro_type) : poly_macro_type =
352361
let intern_ty = make_type_generalization_intern Level.bottom tvid_ht in
353362
let intern_row = make_row_generalization_intern Level.bottom rvid_ht in
354363
let must_be_bound (mbbid : MustBeBoundID.t) = Level.less_than Level.bottom (MustBeBoundID.get_level mbbid) in
364+
let must_be_bound_row (mbbrid : MustBeBoundRowID.t) = Level.less_than Level.bottom (MustBeBoundRowID.get_level mbbrid) in
355365
let aux = function
356-
| LateMacroParameter(ty) -> LateMacroParameter(lift_poly_general intern_ty intern_row must_be_bound ty)
357-
| EarlyMacroParameter(ty) -> EarlyMacroParameter(lift_poly_general intern_ty intern_row must_be_bound ty)
366+
| LateMacroParameter(ty) ->
367+
LateMacroParameter(lift_poly_general intern_ty intern_row must_be_bound must_be_bound_row ty)
368+
369+
| EarlyMacroParameter(ty) ->
370+
EarlyMacroParameter(lift_poly_general intern_ty intern_row must_be_bound must_be_bound_row ty)
358371
in
359372
match macty with
360373
| InlineMacroType(macparamtys) -> InlineMacroType(macparamtys |> List.map aux)

0 commit comments

Comments
 (0)