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

fix EHeapElems bug by combining length member with heap array #71

Merged
merged 1 commit into from
Nov 1, 2018

Conversation

izgzhen
Copy link
Collaborator

@izgzhen izgzhen commented Oct 23, 2018

fix #60

@izgzhen izgzhen requested review from Calvin-L and mernst October 23, 2018 22:08
cozy/codegen/cxx.py Outdated Show resolved Hide resolved
@izgzhen izgzhen force-pushed the heap branch 5 times, most recently from 5df332d to 9612767 Compare October 26, 2018 05:01
@izgzhen
Copy link
Collaborator Author

izgzhen commented Oct 26, 2018

@Calvin-L I think I've done working on this -- do you have any feedback?

Copy link
Collaborator

@Calvin-L Calvin-L left a comment

Choose a reason for hiding this comment

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

The changes here look good to me.

Travis is complaining about two stray semicolons (noted below).

Additionally, there is one failing test because of an unimplemented case in visit_EArrayIndexOf in cxx.py.

cozy/codegen/cxx.py Outdated Show resolved Hide resolved
cozy/codegen/java.py Outdated Show resolved Hide resolved
@izgzhen
Copy link
Collaborator Author

izgzhen commented Oct 26, 2018

Additionally, there is one failing test because of an unimplemented case in visit_EArrayIndexOf in cxx.py.

assert isinstance(e.a, EVar) # TODO: make this fast when this is false

It seems like I will need to comment this assertion out -- and even if this is done, generated code will complain about hash function: there is no hash function for std::vector<int>

@izgzhen
Copy link
Collaborator Author

izgzhen commented Oct 26, 2018

The curious fact is that, hashCode can be applied to an integer array in Java, but std::hash can't be applied to an integer vector in C++.

@izgzhen
Copy link
Collaborator Author

izgzhen commented Oct 26, 2018

I found that I can just delete the un-compilable gash function definition in C++. it seems not needed.

I think I will first propose to only generate hash function for struct that actually needs it.

@izgzhen
Copy link
Collaborator Author

izgzhen commented Oct 26, 2018

revised C++ hash struct logic a bit -- only generating Hash function if all subfields are scalar types

@izgzhen
Copy link
Collaborator Author

izgzhen commented Oct 26, 2018

@Calvin-L regarding the ArrayIndexOf, it seems that what you need is to cache evaluated e.a inside some variable?

@Calvin-L
Copy link
Collaborator

That's right. I put that assert in place to make sure that someday we store the result of e.a in a variable to avoid recomputing it over and over.

@izgzhen
Copy link
Collaborator Author

izgzhen commented Oct 26, 2018

That's right. I put that assert in place to make sure that someday we store the result of e.a in a variable to avoid recomputing it over and over.

I figured that caching inside a variable is a bit overkill in this case - I found that in C++ assignment might copy the vector. In my case, the e.a is just a ETupleGet(EVar(...), 1). If we assign this expression to a new variable, I am afraid that there will be extra copying. So I just add my case as another special case which doesn't incur repeated computation, and also avoiding overhead of copying.

cozy/codegen/cxx.py Outdated Show resolved Hide resolved
cozy/codegen/cxx.py Outdated Show resolved Hide resolved
cozy/structures/arrays.py Show resolved Hide resolved
@izgzhen
Copy link
Collaborator Author

izgzhen commented Oct 29, 2018

I added implementation for hashing the TArray

@izgzhen
Copy link
Collaborator Author

izgzhen commented Oct 30, 2018

a lot of tests are broken by my hash implementation -- @Calvin-L maybe we can do this in a separate commit later?

@izgzhen
Copy link
Collaborator Author

izgzhen commented Oct 31, 2018

@Calvin-L ping

@izgzhen
Copy link
Collaborator Author

izgzhen commented Nov 1, 2018

@Calvin-L I intend to revert my attempt to implement hash function for array, and leave it as a future work since it breaks too many regression test -- what do you think?

@Calvin-L
Copy link
Collaborator

Calvin-L commented Nov 1, 2018

I would much prefer not to push code that breaks tests. If you have a follow-up in mind that fixes them, just add it to this PR.

Also, a quick note:

Many of the tests are failing on this PR with messages like At (x == 0): cannot unify types Int and std::size_t (due to comparison). I suspect this is because Cozy is somehow changing the type of a global constant somewhere. Off the cuff, I'd say it isn't anything you committed, but rather this line in cxx.py. Seems that past-me did not follow his own advice about creating shallow copies when adjusting the type of an expression that might alias with others. 🤣 Would you mind adjusting that line to self.declare(shallow_copy(s.var).with_type(t), s.val) and see if more tests pass?

@Calvin-L
Copy link
Collaborator

Calvin-L commented Nov 1, 2018

(FWIW: I am eager to get this merged, I'd just like to do it with a passing test suite. There is good stuff in this PR, and the changes I am putting together for #49 depend on some of the changes here.)

@mernst
Copy link
Member

mernst commented Nov 1, 2018

I agree that we should never push code to master that breaks tests.

@izgzhen
Copy link
Collaborator Author

izgzhen commented Nov 1, 2018

Would you mind adjusting that line to self.declare(shallow_copy(s.var).with_type(t), s.val) and see if more tests pass?

Pushed update and it seems fixing it (also, with just the fix you suggested, solver.py can't deal with TNative(std::size_t), so I rewrite some types in hashing function from TNative(std::size_t) to INT. It indeed helps.

Thanks a lot!

@izgzhen
Copy link
Collaborator Author

izgzhen commented Nov 1, 2018

@Calvin-L tests are passed!

@izgzhen izgzhen merged commit 8f688b4 into CozySynthesizer:master Nov 1, 2018
@izgzhen izgzhen deleted the heap branch October 21, 2019 19:25
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.

EHeapElems is buggy
3 participants