mirror of
https://github.com/CatalaLang/catala.git
synced 2024-09-19 00:15:39 +03:00
The typer doesn't handle monomorphised code yet
so don't retype after monomorphisation, which is now possible as the pass itself correctly preserves types. In time the typer will need a special case to get knowledge of the new types and modified operator types.
This commit is contained in:
parent
df70c5dd57
commit
ea512bfd5b
@ -238,15 +238,13 @@ module Passes = struct
|
||||
Message.raise_error
|
||||
"Option --avoid-exceptions is not compatible with option --trace"
|
||||
| true, _, Untyped _ ->
|
||||
Lcalc.From_dcalc.translate_program_without_exceptions
|
||||
(Shared_ast.Typing.program ~leave_unresolved:ErrorOnAny prg)
|
||||
Lcalc.From_dcalc.translate_program_without_exceptions prg
|
||||
| true, _, Typed _ ->
|
||||
Lcalc.From_dcalc.translate_program_without_exceptions prg
|
||||
| false, _, Typed _ ->
|
||||
Lcalc.From_dcalc.translate_program_with_exceptions prg
|
||||
| false, _, Untyped _ ->
|
||||
Lcalc.From_dcalc.translate_program_with_exceptions
|
||||
(Shared_ast.Typing.program ~leave_unresolved:ErrorOnAny prg)
|
||||
Lcalc.From_dcalc.translate_program_with_exceptions prg
|
||||
| _, _, Custom _ -> invalid_arg "Driver.Passes.lcalc"
|
||||
in
|
||||
let prg =
|
||||
@ -275,10 +273,11 @@ module Passes = struct
|
||||
let prg, type_ordering =
|
||||
if monomorphize_types then (
|
||||
Message.emit_debug "Monomorphizing types...";
|
||||
let prg, type_ordering = Lcalc.Monomorphize.program prg in
|
||||
Message.emit_debug "Retyping lambda calculus...";
|
||||
let prg = Typing.program ~leave_unresolved:ErrorOnAny prg in
|
||||
prg, type_ordering)
|
||||
Lcalc.Monomorphize.program prg
|
||||
(* (* FIXME: typing no longer works after monomorphisation, it would
|
||||
* need special operator handling for arrays and options *)
|
||||
* Message.emit_debug "Retyping lambda calculus...";
|
||||
* let prg = Typing.program ~leave_unresolved:LeaveAny prg in *))
|
||||
else prg, type_ordering
|
||||
in
|
||||
prg, type_ordering
|
||||
|
@ -243,9 +243,7 @@ let rec monomorphize_expr
|
||||
let tup_ty =
|
||||
match e0 with ETupleAccess { e; _ }, _ -> Expr.ty e | _ -> assert false
|
||||
in
|
||||
let tuple_instance =
|
||||
Type.Map.find tup_ty monomorphized_instances.tuples
|
||||
in
|
||||
let tuple_instance = Type.Map.find tup_ty monomorphized_instances.tuples in
|
||||
EStructAccess
|
||||
{
|
||||
name = tuple_instance.name;
|
||||
|
@ -297,6 +297,7 @@ let polymorphic_op_type (op : Operator.polymorphic A.operator Mark.pos) :
|
||||
let it = lazy (UnionFind.make (TLit TInt, pos)) in
|
||||
let cet = lazy (UnionFind.make (TClosureEnv, pos)) in
|
||||
let array a = lazy (UnionFind.make (TArray (Lazy.force a), pos)) in
|
||||
let option a = lazy (UnionFind.make (TOption (Lazy.force a), pos)) in
|
||||
let ( @-> ) x y =
|
||||
lazy (UnionFind.make (TArrow (List.map Lazy.force x, Lazy.force y), pos))
|
||||
in
|
||||
@ -312,13 +313,9 @@ let polymorphic_op_type (op : Operator.polymorphic A.operator Mark.pos) :
|
||||
| Log (PosRecordIfTrueBool, _) -> [bt] @-> bt
|
||||
| Log _ -> [any] @-> any
|
||||
| Length -> [array any] @-> it
|
||||
(* The [HandleDefault] and [HandleDefaultOpt] need to be typed before and
|
||||
after the Lcalc monomorphization which affects arrays and option types.
|
||||
Because of that, we give the operators very lax typing rules with [any]
|
||||
but it doesn't matter for unification because the concrete types on which
|
||||
they will be instantiated are stored in the [EAppOp] node. *)
|
||||
| HandleDefault -> [any2; [ut] @-> bt; [ut] @-> any] @-> any
|
||||
| HandleDefaultOpt -> [any2; [ut] @-> bt; [ut] @-> any] @-> any
|
||||
| HandleDefault -> [array ([ut] @-> any); [ut] @-> bt; [ut] @-> any] @-> any
|
||||
| HandleDefaultOpt ->
|
||||
[array (option any); [ut] @-> bt; [ut] @-> option any] @-> option any
|
||||
| ToClosureEnv -> [any] @-> cet
|
||||
| FromClosureEnv -> [cet] @-> any
|
||||
in
|
||||
|
Loading…
Reference in New Issue
Block a user