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

Simple constant folding optimization as an example #332

Merged
merged 2 commits into from
Feb 7, 2024

Conversation

oflatt
Copy link
Member

@oflatt oflatt commented Feb 7, 2024

No description provided.

@oflatt oflatt requested a review from ajpal February 7, 2024 17:17
@rtjoa
Copy link
Collaborator

rtjoa commented Feb 7, 2024

Looks good! I like that we're moving away from egglog programs as strings.

egglog_test seems to do two separate things. What if we split it into the following functions? (Separation of concerns; we can still encourage people to test with both styles)

egglog_test_opt(
  build: &str,
  check: &str
)

egglog_test_interp(
  pgrm: TreeProgram,
  input: Value,
  expected: Value
)

Another common test pattern, which desugars to egglog_test_opt, could be

egglog_test_optimized_to(
  pgrm: TreeProgram,
  epxected: TreeProgram
)

@oflatt
Copy link
Member Author

oflatt commented Feb 7, 2024

I considered separating these two, but we should almost always be calling both. This way, you won't forget to.

@rtjoa rtjoa self-requested a review February 7, 2024 18:08
@rtjoa
Copy link
Collaborator

rtjoa commented Feb 7, 2024

I considered separating these two, but we should almost always be calling both. This way, you won't forget to.

I think tests will come out cleaner and be more readable if they are separate. If it's good style to test both, this should happen during review.

Also note that it's odd we expect all test programs to have the same expected value - turning the param from a vector of programs to a single program (or: vector of program-output pairs) will encourage more diverse testing.

@rtjoa
Copy link
Collaborator

rtjoa commented Feb 7, 2024

Here's a "test both" alternative that doesn't do two separate things:

egglog_unit_test_opt(
  pgrm: TreeProgram,
  expected: TreeProgram
  input_output_tests: Vec<Pair<Value, Value>>
)

It can first interpret and check the i/o pairs on both pgrm and expected. If there's a discrepancy, there's an issue in the test or the interpreter!

Then, if pgrm is not rewritten to expected, we catch a bug in the optimizations.

Note that it can be implemented neatly using the functions I suggested in my first comment.

@oflatt
Copy link
Member Author

oflatt commented Feb 7, 2024

We should add that too, but a lot of our tests involve strait up egglog code (f.e. analysis tests)
Having a list of values would also be nice but for now this is good enough

@ajpal
Copy link
Collaborator

ajpal commented Feb 7, 2024

I considered separating these two, but we should almost always be calling both. This way, you won't forget to.

I think tests will come out cleaner and be more readable if they are separate. If it's good style to test both, this should happen during review.

Also note that it's odd we expect all test programs to have the same expected value - turning the param from a vector of programs to a single program (or: vector of program-output pairs) will encourage more diverse testing.

+1

@oflatt
Copy link
Member Author

oflatt commented Feb 7, 2024

Chatted with @ajpal about this
For now lets go with the existing one, we can add @rtjoa's egglog_unit_test_opt as needed

@oflatt oflatt merged commit a083fcd into main Feb 7, 2024
4 checks passed
@oflatt oflatt deleted the oflatt-simple-constant-fold branch February 7, 2024 21:47
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