daml icon indicating copy to clipboard operation
daml copied to clipboard

Optimise `fromListWith` in `Map` and `TextMap` for list-like structures.

Open yangzai opened this issue 1 year ago • 5 comments

Optimise fromListWith to prepend the singleton list to the accumulated list instead of appending to it. It also does not make sense that fromListWith appends the new values and insertWith prepends.

yangzai avatar Jan 23 '24 07:01 yangzai

Hi @yangzai, thanks for your PR. Before merging it we need to discuss internally about the implications for existing uses of these functions, but for now I'll kick off the CI tests

akrmn avatar Jan 23 '24 13:01 akrmn

/azp run

akrmn avatar Jan 23 '24 13:01 akrmn

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Jan 23 '24 13:01 azure-pipelines[bot]

Hi @yangzai, thanks for your PR. Before merging it we need to discuss internally about the implications for existing uses of these functions, but for now I'll kick off the CI tests

We could suggest users to flip their combining function during migration if they want to keep to the old behaviour.

yangzai avatar Jan 23 '24 17:01 yangzai

rebased

yangzai avatar Jan 23 '24 21:01 yangzai

@yangzai Sorry for the lack of update here. We can't really make a semantic change while keeping the function name the same, as this would change existing code's behaviour.

We're currently looking into providing fromListWithL and fromListWithR as a future release, but this is still being discussed.

basvangijzel-DA avatar Mar 06 '24 14:03 basvangijzel-DA

@yangzai Sorry for the lack of update here. We can't really make a semantic change while keeping the function name the same, as this would change existing code's behaviour.

We're currently looking into providing fromListWithL and fromListWithR as a future release, but this is still being discussed.

@basvangijzel-DA noted. I can work on the necessary refactoring while the decision is being made.

yangzai avatar Mar 06 '24 14:03 yangzai

@yangzai Okay, great if you're happy to do the refactoring. The following would we be good to have:

  • define fromListWithL and fromListWithR as new functions (you can copy paste fromWithList as a base)
  • change the definition of fromListWith to point to fromListWithL (please doublecheck that I picked the right one)

Just FYI: In a later major release (not for this PR) we would delete fromListWith, but provide a rewrite rule in the compiler/IDE to help with a fix.

basvangijzel-DA avatar Mar 06 '24 14:03 basvangijzel-DA

@yangzai Okay, great if you're happy to do the refactoring. The following would we be good to have:

  • define fromListWithL and fromListWithR as new functions (you can copy paste fromWithList as a base)
  • change the definition of fromListWith to point to fromListWithL (please doublecheck that I picked the right one)

Just FYI: In a later major release (not for this PR) we would delete fromListWith, but provide a rewrite rule in the compiler/IDE to help with a fix.

@basvangijzel-DA I have pointed fromListWith to fromListWithR instead. As a sanity check testfromListWithR should match with the old testfromListWith.

yangzai avatar Mar 12 '24 19:03 yangzai

/azp run

basvangijzel-DA avatar Mar 14 '24 14:03 basvangijzel-DA

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Mar 14 '24 14:03 azure-pipelines[bot]

@yangzai, there's a failing test, //compiler/damlc/tests:platform-independence-dar-hash-file-matches. The reason is that your change affects the package id of daml-stdlib, which means that the golden file needs to be updated. Since I can't push to your branch and I'm not sure you'll be able to run the bazel rule to update the golden file, I've cherry-picked your commits and updated the golden file in PR https://github.com/digital-asset/daml/pull/18753

moisesackerman-da avatar Mar 14 '24 16:03 moisesackerman-da