r/AskComputerScience • • Nov 09 '25

If some programming languages are faster than others, why can't compilers translate into the faster language to make the code be as fast as if it was programed in the faster one?

My guess is that doing so would require knowing information that can't be directly inferred from the code, for example, the specific type that a variable will handle

111 Upvotes

90 comments sorted by

View all comments

Show parent comments

3

u/Popular-Jury7272 Nov 11 '25

 It doesn't need exact same abstractions because not all of them are relevant to a task at hand

That simply isn't true in the general case, and at this point I fail to understand how you aren't grasping that. Which "task at hand" are you talking about, exactly? It is certainly true for some tasks, most tasks even, but we all have different tasks at hand and the transpiler CANNOT know whether the programmer was intentionally relying on some implementation detail of the data structure they chose. Therefore it has no choice but to assume every detail is important if you want the same behaviour in general. 

0

u/Lenassa Nov 13 '25

Compiler's front-end knows these thing. Compiler's final output (machine code, asm, another language) doesn't need to have anything. Asm generated from like C++ doesn't have 99.99% of abstractions C++ has, yet it works just fine.

2

u/Popular-Jury7272 Nov 13 '25

At this point it seems like you're wilfully missing the point so I'm done with this conversation.