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

More generic contract generation #1192

Merged
merged 5 commits into from
Mar 23, 2023
Merged

More generic contract generation #1192

merged 5 commits into from
Mar 23, 2023

Conversation

vkleen
Copy link
Member

@vkleen vkleen commented Mar 20, 2023

This PR introduces a type variable environment into labels and makes the tracking type variable polarities for contract generation dynamic. Additionally, it introduces two new primops to manipulate this environment.

This is preparatory work for #1177.

Copy link
Member

@yannham yannham left a comment

Choose a reason for hiding this comment

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

It's not urgent, but looking at code each time we add a new primop, it really feels cumbersome to do (add stuff to the lexer, to the parser, implement boiler plate code for dynamically typing the arguments, extract them, oh should I take ownership with match_shared! or not 🤷‍♂️ ). It's not urgent but there must be a better way of organizing (and splitting, as well) eval::operation.

src/eval/operation.rs Outdated Show resolved Hide resolved
src/eval/operation.rs Outdated Show resolved Hide resolved
src/eval/operation.rs Outdated Show resolved Hide resolved
src/eval/operation.rs Outdated Show resolved Hide resolved
src/eval/operation.rs Show resolved Hide resolved
/// Data about type variables that is needed for polymorphic contracts to decide which actions to take.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TypeVarData {
pub polarity: Polarity,
Copy link
Member

Choose a reason for hiding this comment

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

I guess this field will take on more values once you do the "one-pass" version? Morally, positive, negative, and the composite partial identities (positive, negative) and (negative, positive) ?

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 was expecting to need more data for type variables, indeed. Originally I was also tracking the variable kind, but that ended up being unnecessary for now.

src/label.rs Outdated
}
}

impl HasUnifType for TypeVarData {
Copy link
Member

Choose a reason for hiding this comment

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

I find the name a tad misleading, I would expect a trait named HasUnifType to define a method has_unif_type(&self) -> bool. I don't know of a good name scheme for those kind of * -> * functions from a type to a type. AssociatedUnifType? Looks a bit long. ReifyAsUnifType? ReifyAsNickelType? I like reify, it sounds professional 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

+1 for reify 👑 Another possibility would be AsUnifType. Really, the problem seems to be that TypeVarData::unif_type() should actually be an associated constant; and that the trait can't be named UnifType to conform to the usual naming format.

Copy link
Member

Choose a reason for hiding this comment

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

Right, I would also have called it UnifType naturally.

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've renamed it to ReifyAsUnifType. Yell if that's a bad idea 😅

stdlib/internals.ncl Outdated Show resolved Hide resolved
Co-authored-by: Yann Hamdaoui <yann.hamdaoui@tweag.io>
@github-actions github-actions bot temporarily deployed to pull request March 22, 2023 10:46 Inactive
This avoids a pass through the merging code path. The result is a ~10%
performance improvement on a large tf-ncl AWS example.

Co-authored-by: Yann Hamdaoui <yann.hamdaoui@tweag.io>
@github-actions github-actions bot temporarily deployed to pull request March 22, 2023 12:24 Inactive
@github-actions github-actions bot temporarily deployed to pull request March 23, 2023 12:26 Inactive
@vkleen vkleen merged commit 7284ce5 into master Mar 23, 2023
@vkleen vkleen deleted the generic-contract-generation branch March 23, 2023 16:10
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.

None yet

2 participants