Skip to content
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

Merged
merged 19 commits into from
Oct 3, 2022

Conversation

mdurero
Copy link
Collaborator

@mdurero mdurero commented Sep 12, 2022

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 : 

  • Bir module public interface should provide access to all three of bare main_function, main_function with context from a m_spec (context_function) and context_function providing a reset of the input table (needed for the Mlang built-in interpreter)
  • Bir.program function map should stay untouched by Bir_interface, reflecting the computation as described in M and MPP, that's why statements for context_function and Co. should be stored in specific fields of the program record.

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
@@ -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;
Copy link
Collaborator

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.

Copy link
Collaborator Author

@mdurero mdurero Sep 13, 2022

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.

Copy link
Collaborator

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...)

Copy link
Collaborator Author

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.

Copy link
Collaborator

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.

Copy link
Collaborator Author

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).

Copy link
Collaborator

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.

Copy link
Collaborator Author

@mdurero mdurero Sep 16, 2022

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.

Copy link
Collaborator Author

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.

…nctions map is now always agnostic, context being stored outside it.
…tial Bir.program to the Oir output without change"

This reverts commit c79a4ce.
@mdurero mdurero marked this pull request as ready for review September 16, 2022 14:03
@mdurero mdurero marked this pull request as draft September 19, 2022 14:55
@mdurero mdurero marked this pull request as ready for review September 20, 2022 16:20
@mdurero mdurero mentioned this pull request Sep 21, 2022
mdurero added a commit that referenced this pull request Sep 21, 2022
Copy link
Contributor

@denismerigoux denismerigoux left a 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

src/mlang/test_framework/test_interpreter.ml Show resolved Hide resolved
@@ -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 = {
Copy link
Contributor

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).

Copy link
Collaborator Author

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)
Copy link
Contributor

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

…_tgv_init and add comment explaining why BIR interpreter needs the addition of these initialisation statements
@denismerigoux denismerigoux merged commit 934aac9 into master Oct 3, 2022
mdurero added a commit that referenced this pull request Mar 30, 2023
mdurero added a commit that referenced this pull request Jun 30, 2023
mdurero added a commit that referenced this pull request Jul 6, 2023
@denismerigoux denismerigoux deleted the main-function-selection-in-bir branch April 2, 2024 09:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants