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

Add PlutusTx.Data.List.destructList #6945

Merged
merged 4 commits into from
Mar 26, 2025
Merged

Add PlutusTx.Data.List.destructList #6945

merged 4 commits into from
Mar 26, 2025

Conversation

zliu41
Copy link
Member

@zliu41 zliu41 commented Mar 12, 2025

This seems not only useful for @adamsmo's scripts, but also useful in general. See Haddock for more details.

Closes #6936

@zliu41 zliu41 requested a review from a team March 12, 2025 14:53
@zliu41 zliu41 changed the title Add PlutusTx.Utils.TH.destructBuiltinList Add PlutusTx.Data.List.destructList Mar 19, 2025
@zliu41 zliu41 requested a review from Unisay March 19, 2025 03:50
((\tail -> tail (tail (force tailList nt)))
(\eta -> force tailList eta)))
(unIData (force headList nt)))
(force tailList (unListData d))))
Copy link
Contributor

Choose a reason for hiding this comment

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

That's a lot of forcing, why not bind force tailList and force headList to a variable? Or do you expect CSE to clean it up? Particularly when you already seem to do that in (\eta -> force tailList eta). Why the eta-expansion btw?

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't CSE work-free terms such as force tailList. As mentioned in the CSE Note, doing so may reduce size but always increases cost, and CSE currently favors smaller cost. I don't think there is a way to manually bind force tailList to a variable, is there?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's not really work-free, since both Force and Builtin have a cost. Var has a cost too, but it's 1 against 2, so binding it to a variable should be an overall cost reduction.

I don't think there is a way to manually bind force tailList to a variable, is there?

I don't know.

Copy link
Member Author

@zliu41 zliu41 Mar 20, 2025

Choose a reason for hiding this comment

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

There's also LamAbs and App, though perhaps if a builtin is forced many times, it may be worth hoisting it.

Copy link
Contributor

Choose a reason for hiding this comment

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

The file is named ...unsafeFixIO_th_utils... for a reason that I don't understand, but that doesn't matter much, I guess.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's because my git email is unsafeFixIO@gmail.com.

Comment on lines +143 to +155
-- | Prints uniques. This should be used sparingly: a simple change to a script or a
-- compiler pass may change all uniques, making it difficult to see the actual
-- change if all uniques are printed. It is nonetheless useful sometimes.
goldenPirReadableU ::
(PrettyUni uni, Pretty fun, uni `PLC.Everywhere` Flat, Flat fun) =>
String ->
CompiledCodeIn uni fun a ->
TestNested
goldenPirReadableU name value =
nestedGoldenVsDoc name ".pir"
. maybe "PIR not found in CompiledCode" (prettyReadable . view progTerm)
$ getPirNoAnn value

Copy link
Contributor

@Unisay Unisay Mar 25, 2025

Choose a reason for hiding this comment

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

Please apply fourmolu to this new code (and other new code too) if you haven't done it yet.

Copy link
Member Author

Choose a reason for hiding this comment

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

There's no way to only fourmolu a single function, is it? I don't want to fourmolu the whole module, since I only added this one function. We can format it in a separate PR.

Copy link
Contributor

@Unisay Unisay left a comment

Choose a reason for hiding this comment

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

Other than rebase and fourmolu - LGTM!

@zliu41 zliu41 enabled auto-merge (squash) March 26, 2025 14:28
@zliu41 zliu41 disabled auto-merge March 26, 2025 14:28
@zliu41 zliu41 merged commit e535cb0 into master Mar 26, 2025
8 checks passed
@zliu41 zliu41 deleted the zliu41/th-utils branch March 26, 2025 14:30
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.

Plinth Metaprogramming: bind each List element to an indexed name.
3 participants