fusionlanguage / fut

Fusion programming language. Transpiling to C, C++, C#, D, Java, JavaScript, Python, Swift, TypeScript and OpenCL C.
https://fusion-lang.org
GNU General Public License v3.0
1.76k stars 55 forks source link

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

Closed mavavilj closed 7 months ago

mavavilj commented 7 months ago

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 commented 7 months ago

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

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

mavavilj commented 7 months ago

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

mavavilj commented 7 months ago

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 commented 7 months ago

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 commented 7 months ago

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 commented 7 months ago

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 commented 7 months ago

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.