In the following:
argument match {
case A => **executed code**
...
is the executed code directly link at compile time with respect to the pattern of the matched argument
, or is it "simply" some kind of powerful switch-case solved at runtime?
(I'm speaking about off line compilation, not JIT)
Edit: answer
The question was close as duplicate. I think this answer would have been wiser:
The question How is pattern matching in Scala implemented at the bytecode level? explain that pattern matching is converted to a set of if and else, chosen depending on the patterns.
Thus it is not solved at compile time, in the sense that:
- the compiler does not link directly to the
**executed code**
, w.rt the argument type - thus, the matching (i.e. the if-else) is computed at runtime
(I hoped it did because I'm pretty sure it could in at least some situation)
Also, looking at the question is it possible to remove jumps with final boolean on java jit?, it is possible that the JIT will actually do it. Not sure how well it works in practice (I would expect it depends on the situation), but if it does, then processing pattern matching at compile time is not really necessary.