Skip to content

Conversation

chambart
Copy link
Contributor

Accessing record information in the typedtree is not very practical, and the information about the type of kept fields (when using the { record with label = exp } construct) is available.

I propose to replace it by:

  | Texp_record of
      record_label_definition array *
      Types.label_description array *
      Types.record_representation *
       expression option

and record_label_definition =
  | Kept of Types.type_expr
  | Overridden of Longident.t loc * expression

This allows to easily access a particular field information (instead of searching for a field with the right field position).

The main motivation for this change is to provide the type information to translcore to propagate it to the lambda. In particular, the PR #336 would make use of it. I had a previous version that needed to do some unification after the type checking, but this version is a lot cleaner.

Notice that even if we lost the order of the fields in the parsetree, this does not affect the evaluation order. I added a test to verify that.

Notice that the evaluation order for record update depend on the number of fields updated:

  • if there are less than (size - 3) / 2 updated fields then the evaluation order is from the last index to the first
  • otherwise it is the opposite

Would anyone object if I changed the order to avoid this strangeness ?

@damiendoligez damiendoligez added this to the 4.04 milestone Mar 31, 2016
@chambart
Copy link
Contributor Author

Merged recent trunk and fix propagation of record update type informations

@chambart chambart force-pushed the improve_texp_record_representation branch from 5914078 to 455a4b5 Compare July 7, 2016 14:28
@chambart
Copy link
Contributor Author

chambart commented Jul 7, 2016

Re-rebased to the current trunk.

Also use the type information to populate makeblock kinds in case of record update and add some test to check that this effectively allow unboxing in case of record update.

This test was failing first due to a bug introduced by #538 . This contain the fix for it.

@chambart
Copy link
Contributor Author

chambart commented Jul 7, 2016

Note also #538 changed the evaluation order of records.
The failure comes from the new evaluation order failing due to this change. If this is considered as irrelevant, I will make every record use the same evaluation order.

@chambart
Copy link
Contributor Author

chambart commented Jul 7, 2016

@garrigue @lpw25 or @alainfrisch would you object to this change ?

@alainfrisch
Copy link
Contributor

I think it's a good change, but I did not review the patch itself.

record_label_definition array * Types.label_description array *

Why not (Types.label_description * record_label_definition) array? This makes an invariant explicit (the two arrays have the same length) and simplify the code that work on them.

Moreover, the comment in Typedtree is confusing since it leads to believe that only overridden fields are listed. Perhaps just adding a sentence about the fact that all fields of the record type are listed in the arrays would help.

@bluddy
Copy link
Contributor

bluddy commented Jul 7, 2016

I would also recommend switching to inline records where there are more than a pair of parameters, for clarity.

@chambart
Copy link
Contributor Author

chambart commented Jul 7, 2016

@alainfrisch, no real reason, it made some change a bit smaller, but this is marginal.

Thanks for the suggestions, I will try this.

@chambart chambart force-pushed the improve_texp_record_representation branch from 38948fe to 60a8e1d Compare July 7, 2016 16:11
@chambart
Copy link
Contributor Author

chambart commented Jul 7, 2016

Rererebased...

And applied @alainfrisch suggestions

@chambart
Copy link
Contributor Author

chambart commented Jul 7, 2016

@bluddy in that case the name of the type of each field is probably sufficient to describe what is its concern, but that should probably go in another pr soon

@alainfrisch
Copy link
Contributor

The order I suggested (Types.label_description * record_label_definition) seems more natural (it follows the OCaml syntax).

Regarding (inline or not) record for the arguments: if you think this is a good idea, why not doing it in this PR? Typedtree is processed by external tools (reading .cmt files) so we should indeed aim at user-friendliness and stability (i.e. not change again the definition post 4.04).

@@ -181,6 +181,26 @@ module Stdlib = struct
| None -> default
| Some a -> f a
end

module Array = struct
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This helper module is now useless, I think.

@chambart chambart force-pushed the improve_texp_record_representation branch from 7c28f45 to 32cbe38 Compare July 11, 2016 14:55
If the type is { l1: t1; l2: t2 }, the expression
{ E0 with t2=P2 } is represented as
Texp_record
([| l1, Kept t1; l2 Override P2 |], representation,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be updated.

@alainfrisch
Copy link
Contributor

Good to merge in my opinion (after fixing the doc).

@chambart
Copy link
Contributor Author

@alainfrisch thanks for the review.

@chambart chambart merged commit 1ae28b9 into ocaml:trunk Jul 12, 2016
camlspotter pushed a commit to camlspotter/ocaml that referenced this pull request Oct 17, 2017
…entation

Improve Texp_record constructor representation
EduardoRFS pushed a commit to esy-ocaml/ocaml that referenced this pull request May 17, 2021
mshinwell added a commit to mshinwell/ocaml that referenced this pull request Jun 30, 2021
stedolan pushed a commit to stedolan/ocaml that referenced this pull request May 24, 2022
EmileTrotignon pushed a commit to EmileTrotignon/ocaml that referenced this pull request Jan 12, 2024
* Generalize Table.Regular

* Generalize Stats component

* Generalize Testimonials

* Generalize UserLevelIntroduction

* Generalize MediaCarousel

* Extract Timeline

* Factor out Blog

* Add components to storybook

* Add Page elements to storybook.

* Add a few more examples of Page.Basic

* Add examples of PageTitles

* Add Page Containers

* Implement ContentGrid component.

* Extract VerticalHighlightCard

* Add examples of ContentGrid.

* Add example of VerticalHighlightCard
EmileTrotignon pushed a commit to EmileTrotignon/ocaml that referenced this pull request Jan 12, 2024
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.

5 participants