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

What exactly guarantees that all of the produced codes have exactly the same behavior? #157

Closed
mavavilj opened this issue Apr 5, 2024 · 7 comments
Labels
question Further information is requested

Comments

@mavavilj
Copy link

mavavilj commented Apr 5, 2024

What exactly guarantees that all of the produced codes have exactly the same behavior?

I want to trust that the resulting codes are functionally the same, but since there can be a lot of it, verifying it manually sounds unideal.

@pfusik
Copy link
Collaborator

pfusik commented Apr 5, 2024

There is no guarantee of exactly same behavior for all target languages in all possible scenarios. For instance, negative-indexing an array:

  • is undefined behavior in C and C++
  • throws an exception in C#, D, Java
  • yields undefined in JavaScript
  • accesses elements from the end of a Python array

It's best to have automated tests for your code.

@mavavilj
Copy link
Author

mavavilj commented Apr 5, 2024

What about if we assume that the programmer does not do anything stupid, is the code on targets then the equivalent program?

@mavavilj
Copy link
Author

mavavilj commented Apr 5, 2024

Also, since tests (to me) are not always trivial, then is some input and output test sufficient to verify that the programs are correct?

@pfusik
Copy link
Collaborator

pfusik commented Apr 5, 2024

What about if we assume that the programmer does not do anything stupid, is the code on targets then the equivalent program?

Yes, that's the essence of Fusion.

Also, since tests (to me) are not always trivial, then is some input and output test sufficient to verify that the programs are correct?

There is no such thing as "universal tests". Tests are always specific to the code you write.

For example, a Fusion project called RECOIL contains a test suite of 1000+ input files and one can check if a code change doesn't break any of them by comparing the outputs with reference PNG files. In a fully automated way, of course.

fut itself contains hundreds of Fusion test sources, transpiles them to different languages, compiles and runs.

@mavavilj
Copy link
Author

mavavilj commented Apr 5, 2024

For example, a Fusion project called RECOIL contains a test suite of 1000+ input files and one can check if a code change doesn't break any of them by comparing the outputs with reference PNG files. In a fully automated way, of course.

Okay now I understand what you mean by testing.

@mavavilj
Copy link
Author

mavavilj commented Apr 5, 2024

There is no such thing as "universal tests". Tests are always specific to the code you write.

Yes, but I think checking Fusion code manually is certainly more complex than if one just wrote the program in one language by hand.

Therefore I think that a Fusion user just needs to trust Fusion as a black box to do what's expected. However, from a compiler perspective I was a bit skeptical as to whether all targets can actually work and not have some corner cases etc.

@pfusik pfusik added the question Further information is requested label Apr 5, 2024
@pfusik
Copy link
Collaborator

pfusik commented Apr 5, 2024

Yes, but I think checking Fusion code manually is certainly more complex than if one just wrote the program in one language by hand.

That might sound scary at first, but:

fut transpiles itself to C++, C#, Java and JavaScript. So we have four programs in different languages and vastly different runtimes, and thousands tests to run on each. But the only thing that adds testing complexity is a different syntax of running the programs. Every program produces an output, which is then tested same way, regardless of how it was produced.

@pfusik pfusik closed this as completed Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants