Restore special handling of the option enum in scalc backends

it's not very satisfying, but we make it pass through renaming for now. A better
approach could be to make this special handling structural, or to have something
more specific than an id to hold onto.
This commit is contained in:
Louis Gesbert 2024-08-07 18:33:22 +02:00
parent 081e07378a
commit f565e84dae
3 changed files with 218 additions and 227 deletions

View File

@ -340,6 +340,18 @@ let program
let pctxmap, enums_map, constrs_map, ctx_enums =
EnumName.Map.fold
(fun name constrs (pctxmap, enums_map, constrs_map, ctx_enums) ->
if EnumName.equal name Expr.option_enum then
(* The option type shouldn't be renamed, it has special handling in
backends. FIXME: could the fact that it's special be detected
differently from id comparison ? Structure maybe, or a more
specific construct ? *)
( pctxmap,
EnumName.Map.add name name enums_map,
EnumConstructor.Map.fold
(fun c _ constrs_map -> EnumConstructor.Map.add c c constrs_map)
Expr.option_enum_config constrs_map,
ctx_enums )
else
let path = EnumName.path name in
let str, pos = EnumName.get_info name in
let pctxmap, ctx =

View File

@ -91,81 +91,75 @@ class BIn:
def some_name(some_name_in:SomeNameIn):
i = some_name_in.i_in
match_arg = handle_exceptions([], [])
if match_arg.code == Eoption_Code.ENone:
_ = match_arg.value
perhaps_none_arg = handle_exceptions([], [])
if perhaps_none_arg is None:
if True:
o3 = Eoption(Eoption_Code.ESome, (i + integer_of_string("1")))
o3 = (i + integer_of_string("1"))
else:
o3 = Eoption(Eoption_Code.ENone, Unit())
elif match_arg.code == Eoption_Code.ESome:
x = match_arg.value
o3 = Eoption(Eoption_Code.ESome, x)
match_arg = handle_exceptions(
o3 = None
else:
x = perhaps_none_arg
o3 = x
perhaps_none_arg = handle_exceptions(
[SourcePosition(
filename="tests/backends/python_name_clash.catala_en",
start_line=10, start_column=23,
end_line=10, end_column=28, law_headings=[])],
[o3]
)
if match_arg.code == Eoption_Code.ENone:
_ = match_arg.value
if perhaps_none_arg is None:
if False:
o2 = Eoption(Eoption_Code.ENone, Unit())
o2 = None
else:
o2 = Eoption(Eoption_Code.ENone, Unit())
elif match_arg.code == Eoption_Code.ESome:
x = match_arg.value
o2 = Eoption(Eoption_Code.ESome, x)
match_arg = o2
if match_arg.code == Eoption_Code.ENone:
_ = match_arg.value
o2 = None
else:
x = perhaps_none_arg
o2 = x
perhaps_none_arg = o2
if perhaps_none_arg is None:
raise NoValue(SourcePosition(
filename="tests/backends/python_name_clash.catala_en",
start_line=7, start_column=10,
end_line=7, end_column=11, law_headings=[]))
elif match_arg.code == Eoption_Code.ESome:
arg = match_arg.value
else:
arg = perhaps_none_arg
o1 = arg
o = o1
return SomeName(o = o)
def b(b_in:BIn):
match_arg = handle_exceptions([], [])
if match_arg.code == Eoption_Code.ENone:
_ = match_arg.value
perhaps_none_arg = handle_exceptions([], [])
if perhaps_none_arg is None:
if True:
result3 = Eoption(Eoption_Code.ESome, integer_of_string("1"))
result3 = integer_of_string("1")
else:
result3 = Eoption(Eoption_Code.ENone, Unit())
elif match_arg.code == Eoption_Code.ESome:
x = match_arg.value
result3 = Eoption(Eoption_Code.ESome, x)
match_arg = handle_exceptions(
result3 = None
else:
x = perhaps_none_arg
result3 = x
perhaps_none_arg = handle_exceptions(
[SourcePosition(
filename="tests/backends/python_name_clash.catala_en",
start_line=16, start_column=33,
end_line=16, end_column=34, law_headings=[])],
[result3]
)
if match_arg.code == Eoption_Code.ENone:
_ = match_arg.value
if perhaps_none_arg is None:
if False:
result2 = Eoption(Eoption_Code.ENone, Unit())
result2 = None
else:
result2 = Eoption(Eoption_Code.ENone, Unit())
elif match_arg.code == Eoption_Code.ESome:
x = match_arg.value
result2 = Eoption(Eoption_Code.ESome, x)
match_arg = result2
if match_arg.code == Eoption_Code.ENone:
_ = match_arg.value
result2 = None
else:
x = perhaps_none_arg
result2 = x
perhaps_none_arg = result2
if perhaps_none_arg is None:
raise NoValue(SourcePosition(
filename="tests/backends/python_name_clash.catala_en",
start_line=16, start_column=14,
end_line=16, end_column=25, law_headings=[]))
elif match_arg.code == Eoption_Code.ESome:
arg = match_arg.value
else:
arg = perhaps_none_arg
result1 = arg
result = some_name(SomeNameIn(i_in = result1))
result1 = SomeName(o = result.o)

View File

@ -446,19 +446,17 @@ glob6 = (
)
def s2(s2_in:S2In):
match_arg = handle_exceptions([], [])
if match_arg.code == Eoption_Code.ENone:
_ = match_arg.value
perhaps_none_arg = handle_exceptions([], [])
if perhaps_none_arg is None:
if True:
a3 = Eoption(Eoption_Code.ESome,
(glob3(money_of_cents_string("4400")) +
decimal_of_string("100.")))
a3 = (glob3(money_of_cents_string("4400")) +
decimal_of_string("100."))
else:
a3 = Eoption(Eoption_Code.ENone, Unit())
elif match_arg.code == Eoption_Code.ESome:
x = match_arg.value
a3 = Eoption(Eoption_Code.ESome, x)
match_arg = handle_exceptions(
a3 = None
else:
x = perhaps_none_arg
a3 = x
perhaps_none_arg = handle_exceptions(
[SourcePosition(
filename="tests/name_resolution/good/toplevel_defs.catala_en",
start_line=53, start_column=24,
@ -466,195 +464,182 @@ def s2(s2_in:S2In):
law_headings=["Test toplevel function defs"])],
[a3]
)
if match_arg.code == Eoption_Code.ENone:
_ = match_arg.value
if perhaps_none_arg is None:
if False:
a2 = Eoption(Eoption_Code.ENone, Unit())
a2 = None
else:
a2 = Eoption(Eoption_Code.ENone, Unit())
elif match_arg.code == Eoption_Code.ESome:
x = match_arg.value
a2 = Eoption(Eoption_Code.ESome, x)
match_arg = a2
if match_arg.code == Eoption_Code.ENone:
_ = match_arg.value
a2 = None
else:
x = perhaps_none_arg
a2 = x
perhaps_none_arg = a2
if perhaps_none_arg is None:
raise NoValue(SourcePosition(
filename="tests/name_resolution/good/toplevel_defs.catala_en",
start_line=50, start_column=10,
end_line=50, end_column=11,
law_headings=["Test toplevel function defs"]))
elif match_arg.code == Eoption_Code.ESome:
arg = match_arg.value
else:
arg = perhaps_none_arg
a1 = arg
a = a1
return S2(a = a)
def s3(s3_in:S3In):
match_arg = handle_exceptions([], [])
if match_arg.code == Eoption_Code.ENone:
_ = match_arg.value
perhaps_none_arg = handle_exceptions([], [])
if perhaps_none_arg is None:
if True:
a3 = Eoption(Eoption_Code.ESome,
(decimal_of_string("50.") +
a3 = (decimal_of_string("50.") +
glob4(money_of_cents_string("4400"),
decimal_of_string("55."))))
decimal_of_string("55.")))
else:
a3 = Eoption(Eoption_Code.ENone, Unit())
elif match_arg.code == Eoption_Code.ESome:
x = match_arg.value
a3 = Eoption(Eoption_Code.ESome, x)
match_arg = handle_exceptions(
a3 = None
else:
x = perhaps_none_arg
a3 = x
perhaps_none_arg = handle_exceptions(
[SourcePosition(
filename="tests/name_resolution/good/toplevel_defs.catala_en",
start_line=74, start_column=24,
end_line=74, end_column=47,
law_headings=["Test function def with two args"])],
law_headings=["Test function def with two args"]
)],
[a3]
)
if match_arg.code == Eoption_Code.ENone:
_ = match_arg.value
if perhaps_none_arg is None:
if False:
a2 = Eoption(Eoption_Code.ENone, Unit())
a2 = None
else:
a2 = Eoption(Eoption_Code.ENone, Unit())
elif match_arg.code == Eoption_Code.ESome:
x = match_arg.value
a2 = Eoption(Eoption_Code.ESome, x)
match_arg = a2
if match_arg.code == Eoption_Code.ENone:
_ = match_arg.value
a2 = None
else:
x = perhaps_none_arg
a2 = x
perhaps_none_arg = a2
if perhaps_none_arg is None:
raise NoValue(SourcePosition(
filename="tests/name_resolution/good/toplevel_defs.catala_en",
start_line=71, start_column=10,
end_line=71, end_column=11,
law_headings=["Test function def with two args"]))
elif match_arg.code == Eoption_Code.ESome:
arg = match_arg.value
else:
arg = perhaps_none_arg
a1 = arg
a = a1
return S3(a = a)
def s4(s4_in:S4In):
match_arg = handle_exceptions([], [])
if match_arg.code == Eoption_Code.ENone:
_ = match_arg.value
perhaps_none_arg = handle_exceptions([], [])
if perhaps_none_arg is None:
if True:
a3 = Eoption(Eoption_Code.ESome,
(glob5 +
decimal_of_string("1.")))
a3 = (glob5 + decimal_of_string("1."))
else:
a3 = Eoption(Eoption_Code.ENone, Unit())
elif match_arg.code == Eoption_Code.ESome:
x = match_arg.value
a3 = Eoption(Eoption_Code.ESome, x)
match_arg = handle_exceptions(
a3 = None
else:
x = perhaps_none_arg
a3 = x
perhaps_none_arg = handle_exceptions(
[SourcePosition(
filename="tests/name_resolution/good/toplevel_defs.catala_en",
start_line=98, start_column=24,
end_line=98, end_column=34,
law_headings=["Test inline defs in toplevel defs"])],
law_headings=["Test inline defs in toplevel defs"]
)],
[a3]
)
if match_arg.code == Eoption_Code.ENone:
_ = match_arg.value
if perhaps_none_arg is None:
if False:
a2 = Eoption(Eoption_Code.ENone, Unit())
a2 = None
else:
a2 = Eoption(Eoption_Code.ENone, Unit())
elif match_arg.code == Eoption_Code.ESome:
x = match_arg.value
a2 = Eoption(Eoption_Code.ESome, x)
match_arg = a2
if match_arg.code == Eoption_Code.ENone:
_ = match_arg.value
a2 = None
else:
x = perhaps_none_arg
a2 = x
perhaps_none_arg = a2
if perhaps_none_arg is None:
raise NoValue(SourcePosition(
filename="tests/name_resolution/good/toplevel_defs.catala_en",
start_line=95, start_column=10,
end_line=95, end_column=11,
law_headings=["Test inline defs in toplevel defs"]))
elif match_arg.code == Eoption_Code.ESome:
arg = match_arg.value
else:
arg = perhaps_none_arg
a1 = arg
a = a1
return S4(a = a)
def s5(s_in:SIn):
match_arg = handle_exceptions([], [])
if match_arg.code == Eoption_Code.ENone:
_ = match_arg.value
perhaps_none_arg = handle_exceptions([], [])
if perhaps_none_arg is None:
if True:
a3 = Eoption(Eoption_Code.ESome, (glob1 * glob1))
a3 = (glob1 * glob1)
else:
a3 = Eoption(Eoption_Code.ENone, Unit())
elif match_arg.code == Eoption_Code.ESome:
x = match_arg.value
a3 = Eoption(Eoption_Code.ESome, x)
match_arg = handle_exceptions(
a3 = None
else:
x = perhaps_none_arg
a3 = x
perhaps_none_arg = handle_exceptions(
[SourcePosition(
filename="tests/name_resolution/good/toplevel_defs.catala_en",
start_line=18, start_column=24,
end_line=18, end_column=37,
law_headings=["Test basic toplevel values defs"])],
law_headings=["Test basic toplevel values defs"]
)],
[a3]
)
if match_arg.code == Eoption_Code.ENone:
_ = match_arg.value
if perhaps_none_arg is None:
if False:
a2 = Eoption(Eoption_Code.ENone, Unit())
a2 = None
else:
a2 = Eoption(Eoption_Code.ENone, Unit())
elif match_arg.code == Eoption_Code.ESome:
x = match_arg.value
a2 = Eoption(Eoption_Code.ESome, x)
match_arg = a2
if match_arg.code == Eoption_Code.ENone:
_ = match_arg.value
a2 = None
else:
x = perhaps_none_arg
a2 = x
perhaps_none_arg = a2
if perhaps_none_arg is None:
raise NoValue(SourcePosition(
filename="tests/name_resolution/good/toplevel_defs.catala_en",
start_line=7, start_column=10,
end_line=7, end_column=11,
law_headings=["Test basic toplevel values defs"]))
elif match_arg.code == Eoption_Code.ESome:
arg = match_arg.value
else:
arg = perhaps_none_arg
a1 = arg
a = a1
match_arg = handle_exceptions([], [])
if match_arg.code == Eoption_Code.ENone:
_ = match_arg.value
perhaps_none_arg = handle_exceptions([], [])
if perhaps_none_arg is None:
if True:
b3 = Eoption(Eoption_Code.ESome, glob6)
b3 = glob6
else:
b3 = Eoption(Eoption_Code.ENone, Unit())
elif match_arg.code == Eoption_Code.ESome:
x = match_arg.value
b3 = Eoption(Eoption_Code.ESome, x)
match_arg = handle_exceptions(
b3 = None
else:
x = perhaps_none_arg
b3 = x
perhaps_none_arg = handle_exceptions(
[SourcePosition(
filename="tests/name_resolution/good/toplevel_defs.catala_en",
start_line=19, start_column=24,
end_line=19, end_column=29,
law_headings=["Test basic toplevel values defs"])],
law_headings=["Test basic toplevel values defs"]
)],
[b3]
)
if match_arg.code == Eoption_Code.ENone:
_ = match_arg.value
if perhaps_none_arg is None:
if False:
b2 = Eoption(Eoption_Code.ENone, Unit())
b2 = None
else:
b2 = Eoption(Eoption_Code.ENone, Unit())
elif match_arg.code == Eoption_Code.ESome:
x = match_arg.value
b2 = Eoption(Eoption_Code.ESome, x)
match_arg = b2
if match_arg.code == Eoption_Code.ENone:
_ = match_arg.value
b2 = None
else:
x = perhaps_none_arg
b2 = x
perhaps_none_arg = b2
if perhaps_none_arg is None:
raise NoValue(SourcePosition(
filename="tests/name_resolution/good/toplevel_defs.catala_en",
start_line=8, start_column=10,
end_line=8, end_column=11,
law_headings=["Test basic toplevel values defs"]))
elif match_arg.code == Eoption_Code.ESome:
arg = match_arg.value
else:
arg = perhaps_none_arg
b1 = arg
b = b1
return S(a = a, b = b)