-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow for selection of diversly contextualized main functions in Bir #184
Conversation
…n and context_function
The context_function now don't reset input table. Most parts of inner Mlang making use of context_function or Bir.main_statements are now using context_function_with_reset or Bir.main_statements_with_reset as they are linked to the interpreter.
…and store them as their own mpp_function field
src/mlang/backend_ir/bir.mli
Outdated
@@ -61,6 +61,8 @@ type program = { | |||
mpp_functions : mpp_function FunctionMap.t; | |||
rules_and_verifs : rule_or_verif ROVMap.t; | |||
main_function : function_name; | |||
context_function : mpp_function; | |||
context_with_reset_function : mpp_function; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather have those out of the function map, since it corresponds to nothing in the mpp. Maybe a option would be to put the statements lists out in the record (or a context subrecord) with names such as e.g. undefined_inputs_init
constant_inputs_init
and adhoc_spec_tests
. Then make sure the proper statements list are build by function below and that the rest of the code refer to those functions instead of tapping into the program record.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now they are out of the function map, encapsulated in a type mpp_fuction, but outside.
They could be directly put as statements lists corresponding to the same function (that's to say a function built from the context you describe and the main function).
Or as you suggest, we can store the components in a record and build them on the fly. Better for modularity, a bit scary for the OIR as the further away I get from the initial state, the more it will require a rework.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't worry for OIR as long as you input the same date as before (and even then...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The point with OIR is: it transforms Bir.program to Oir.program and back, this could be solved easily by adding relevant information to Oir.program.
But I don't know yet if the context part of the statements were included in the optimisation. I think so, because it was added to the function map and indistinguishable from the original statements of the program. If so, my work will have changed the optimisation behaviour.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optimisations already lose information by burying it in its output code. If you give the same input (with context IIRC), then you'd have the same output, losing context information in the process, sure, but its output should not change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I keep this behaviour, the OIR will effectively bury the potential context in the mpp_functions map of the Bir.program. I feel like this would be an unwanted behaviour as part of the point of having the context isolated in its own field is to keep the ability to choose in the backends if we want to use a contextualized main function or not.
So my position would be that OIR should keep either keep intact the context statements (but then they won't be optimized), or the choice to have them should be made before OIR call, as far as I can tell it's not trivial with the current Driver.
I'm inclined to modify OIR.program to pass context information transparently as the context is not the most useful in the cases we want to optimise the generated code (like C for batch processing).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let it drown, without the context some passes might have the wrong behaviour, and you don't want to put your nose in there for this PR.
I agree this is unsatisfactory but it's not worth spending much time on this for now. We'll discuss this in more details later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, we must ignore my last commit c79a4ce then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let it drown,
Well, now we can't, because optimisation made it back to master and so this PR breaks it as is, so I'm trying to resolve it while staying close of the old behaviour.
…tion are already added by Bir_interface.adapt_program_to_function
…nctions map is now always agnostic, context being stored outside it.
….program to the Oir output without change
…tial Bir.program to the Oir output without change" This reverts commit c79a4ce.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Congrats @MdrditArthur ! The code is fine but lacks some comments. You can put comments with the (* .. *)
syntax, or (** .. *)
for top-level comments that will be collected by ocamldoc
to generate https://mlanguage.github.io/mlang/mlang/index.html
@@ -57,10 +57,17 @@ type mpp_function = { mppf_stmts : stmt list; mppf_is_verif : bool } | |||
|
|||
module FunctionMap : Map.S with type key = function_name | |||
|
|||
type program_context = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok with the change but you should put the rationale about why we need this context as a documentation comment here (you can start from your PR description which is quite informative).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation comment proposed in commit b8e0f56.
@@ -752,7 +752,9 @@ module Make (N : Bir_number.NumberInterface) = struct | |||
(code_loc_start_value : int) : ctx = | |||
try | |||
let ctx = | |||
evaluate_stmts p ctx (Bir.main_statements p) [] code_loc_start_value | |||
evaluate_stmts p ctx | |||
(Bir.main_statements_with_reset p) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here a little comment about why we reset would be good
…-function-selection-in-bir
…_tgv_init and add comment explaining why BIR interpreter needs the addition of these initialisation statements
Bir_interface currently overwrites silently MPP-declared main function by a "context_function", adding reset of input variables and valuation of constants and conditional statements to verify according to m_spec file used. If no m_spec is used, a reset of the whole input table is added.
This results in unwanted behaviour for some backends and obfuscates which part of the statements originates from MPP files or M_spec files.
Target for this PR as for now is :