Skip to content

In scope-passing style: use a Movable b instead of Ur b#473

Merged
aspiwack merged 1 commit intomasterfrom
scope-with-movable
Jan 26, 2024
Merged

In scope-passing style: use a Movable b instead of Ur b#473
aspiwack merged 1 commit intomasterfrom
scope-with-movable

Conversation

@aspiwack
Copy link
Copy Markdown
Member

Functions of the form

f :: (A %1 -> Ur b) %1 -> Ur b

are now of the form

f :: Movable b => (A %1 -> b) %1 -> b

The new type is strictly more general. Technically this seems to involve some extra allocations here and there. I expect it to be negligible (we don't want to call too many scoped functions anyway).

The extra allocation is interesting, in that it's not always strictly necessary: when returning an Int, I don't need to produce an Ur Int to make sure that I've actually forced everything, just returning the forced Int would do the trick. Yet we use an Ur Int to communicate that we've indeed done the job (in some cases the optimiser can actually remove the extra allocation, but not in every case as far as I can tell). Maybe there are cheaper way to tell the compiler that we've, in fact, moved the value. But that's a question for the future.

See #468 for the initial discussion.

@aspiwack
Copy link
Copy Markdown
Member Author

I think I've got all the places where I could do this. @Qqwy did you have other places is mind that I might have missed?

Functions of the form

```haskell
f :: (A %1 -> Ur b) %1 -> Ur b
```

are now of the form

```haskell
f :: Movable b => (A %1 -> b) %1 -> b
```

The new type is strictly more general. Technically this seems to
involve some extra allocations here and there. I expect it to be
negligible (we don't want to call too many scoped functions anyway).

The extra allocation is interesting, in that it's not always strictly
necessary: when returning an `Int`, I don't need to produce an `Ur
Int` to make sure that I've actually forced everything, just returning
the forced `Int` would do the trick. Yet we use an `Ur Int` to
communicate that we've indeed done the job (in some cases the
optimiser can actually remove the extra allocation, but not in every
case as far as I can tell). Maybe there are cheaper way to tell the
compiler that we've, in fact, moved the value. But that's a question
for the future.

See #468 for the
initial discussion.
@Qqwy
Copy link
Copy Markdown
Contributor

Qqwy commented Jan 16, 2024

@aspiwack Thanks for tagging me! I think you've caught them all. 🚀

@aspiwack
Copy link
Copy Markdown
Member Author

Let me merge then.

@aspiwack aspiwack merged commit 4398151 into master Jan 26, 2024
@aspiwack aspiwack deleted the scope-with-movable branch January 26, 2024 15:51
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.

2 participants