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

Added support for identities to Impls #968

Open
wants to merge 45 commits into
base: main
Choose a base branch
from
Open

Conversation

varun10p
Copy link
Contributor

@varun10p varun10p commented Aug 20, 2024

Added new clause to impl syntax which is currently defined by #:identities ( ...) where

<ident-expr> ::= [<name> <lhs-expr> <rhs-expr>]
               | #:exact <expr>
               | #:commutes

and the keyword translation

#:exact <expr> ==> [<generated-name> <expr> (prog->spec <expr>)]
#:commutes ==> [<impl>-commutes (<impl> a b) (<impl> b a)]

The new identities are added to the operator-impl stuct as a hash map.

@pavpanchekha
Copy link
Contributor

Use triple-backticks for multiline code blocks

Copy link
Contributor

@pavpanchekha pavpanchekha left a comment

Choose a reason for hiding this comment

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

The code is mostly good, but why the specific choice of #:commutes and #:exact? Did you look at the existing FP-safe rules and find that this was enough? Or something else?

Also I see there's no code actually using these rules, I assume that's intended?

src/syntax/syntax.rkt Outdated Show resolved Hide resolved
src/syntax/syntax.rkt Outdated Show resolved Hide resolved
src/syntax/syntax.rkt Outdated Show resolved Hide resolved
src/syntax/syntax.rkt Outdated Show resolved Hide resolved
@varun10p
Copy link
Contributor Author

The code is mostly good, but why the specific choice of #:commutes and #:exact? Did you look at the existing FP-safe rules and find that this was enough? Or something else?

Also I see there's no code actually using these rules, I assume that's intended?

Those key words seemed like good shortcuts for now. Yes the code using these rules is coming in the future.

@bksaiki
Copy link
Contributor

bksaiki commented Aug 21, 2024

I think this PR was actually not ready for review (but feedback appreciated from @pavpanchekha). I was hoping to discuss our approach with fp-safe rules at our next meeting to make sure we're on the same page.

src/platforms/bool.rkt Outdated Show resolved Hide resolved
src/syntax/platform.rkt Outdated Show resolved Hide resolved
Copy link
Contributor

@bksaiki bksaiki left a comment

Choose a reason for hiding this comment

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

Looks mostly good. Just a few changes requested here, as well as outside GitHub.

src/syntax/syntax.rkt Show resolved Hide resolved
src/syntax/syntax.rkt Show resolved Hide resolved
src/syntax/syntax.rkt Outdated Show resolved Hide resolved
src/syntax/syntax.rkt Outdated Show resolved Hide resolved
src/syntax/syntax.rkt Outdated Show resolved Hide resolved
src/syntax/syntax.rkt Outdated Show resolved Hide resolved
Comment on lines -524 to -486
(unless (type-name? itype)
(error 'rule->egg-rules "expansive rules over impls is unsound ~a" input))
Copy link
Contributor

Choose a reason for hiding this comment

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

This is still strange. What is the story here?

#:spec (* x y)
#:fpcore (! :precision binary32 (* x y))
#:fl fl32*
#:identities (#:commutes [distribute-lft-neg-out (*.f32 (neg.f32 x) y) (neg.f32 (*.f32 x y))]
Copy link
Contributor

Choose a reason for hiding this comment

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

Should #:commutes be at the define-operator-impl level? Just a thought

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should be

@@ -92,12 +191,9 @@
atanh
cbrt
ceil
cos
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm a bit ugly, but mergeable

Comment on lines -43 to -57
[not-true (not (TRUE)) (FALSE)]
[not-false (not (FALSE)) (TRUE)]
[not-not (not (not a)) a]
[not-and (not (and a b)) (or (not a) (not b))]
[not-or (not (or a b)) (and (not a) (not b))]
[and-true-l (and (TRUE) a) a]
[and-true-r (and a (TRUE)) a]
[and-false-l (and (FALSE) a) (FALSE)]
[and-false-r (and a (FALSE)) (FALSE)]
[and-same (and a a) a]
[or-true-l (or (TRUE) a) (TRUE)]
[or-true-r (or a (TRUE)) (TRUE)]
[or-false-l (or (FALSE) a) a]
[or-false-r (or a (FALSE)) a]
[or-same (or a a) a])
Copy link
Contributor

Choose a reason for hiding this comment

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

Have we tested if expressions of these forms simplify?

Copy link
Contributor

@bksaiki bksaiki left a comment

Choose a reason for hiding this comment

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

Just a few questions/changes

@pavpanchekha
Copy link
Contributor

@varun10p I'm going to assume Brett is handling this so I won't review unless you tell me you want one from me too.

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.

3 participants