lingua-franca icon indicating copy to clipboard operation
lingua-franca copied to clipboard

`{=0=}` should not be a valid time literal

Open cmnrd opened this issue 2 years ago • 4 comments

While working on the handling of time values within our compiler, I found many inconsistencies, redundant code and weird constructs. The code regarding handling of time values (ASTUtils) and their validation (LFValidator) should be revised. One particular change that is needed is the handling of {=0=}. Currently, we interpret this as the time 0. However, we should refrain from evaluating values escaped with {=...=}.

cmnrd avatar Dec 20 '21 14:12 cmnrd

Why? The brackets are there predominantly for situations where we can't parse what's inside, but if it turns out we can, why shouldn't we? I never interpreted the funny brackets to denote "don't look inside of this" but rather "what you find in here is target-specific."

lhstrh avatar Dec 21 '21 02:12 lhstrh

Exactly, the brackets denote target code. Interpreting the 0 only works if time is represented as an integer in the target language. This is not the case in C++ and 0 is not a valid time literal in C++ code. So {=0=} should also not be a valid time in LF. We say that we treat everything inside {=...=} as a black box and I think we should stick to this rule. Otherwise, we will get all sorts of weird behavior. For instance, why can I write timer t({=0=}) but not timer t({=foo()=})? Why can I write timer t({=0=}) which is illegal in C++, but cannot write timer t({=0s=} which would be proper C++ code?

cmnrd avatar Dec 21 '21 08:12 cmnrd

Related to #657

oowekyala avatar Dec 21 '21 08:12 oowekyala

Right, I remembered this issue but did not find it anymore. Thanks!

cmnrd avatar Dec 21 '21 10:12 cmnrd

I am closing this as a duplicate because #657 has more references than this one (eg in todos in the code, and in Github issues)

oowekyala avatar Nov 17 '22 17:11 oowekyala