You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Tofino code replaces/moves nodes in several places, such as during V1 -> TNA translation. During this translation, the compiler moves code from the VerifyChecksum block into the Parser block, translating verify_checksum into Checksum.add calls.
ResolutionContext::lookup compares the location of the name being looked up with the potential declaration to determine whether the declaration is a valid match. It will only match if the declaration is before the name, and it uses the SourceInfo to perform that comparison:
The issue is that after moving/replacing IR nodes, the source info may no longer reflect the IR order and so the comparison will produce the wrong result.
When performing the V1 -> TNA translation, the verifyChecksum code from ComputeChecksum is moved and translated into IngressParser.
The challenge is what to use for the SourceInfo for the Checksum.add() calls inserted in IngressParser, such as checksum_0.add(hdr.ipv4.version)? A reasonable choice would be to use L5 as the SourceInfo for hdr.ipv4.version Member node in the add call. However during name lookup, the name SourceInfo would be L5, and the declaration SourceInfo would be L13, and so the before check would fail. The other choice then is to use a SourceInfo of the parser instance or beyond, but then error reports will not accurately reflect the location of hdr.ipv4.version in the input file.
This because an issue for the Tofino project when TypeInference switched from using a ReferenceMap object and instead relying on ResolutionContext.
The text was updated successfully, but these errors were encountered:
My current thinking is that instead of using the SourceInfo to check the ordering of the name vs declaration, the compiler should be looking at their relative locations within the IR tree.
@grg I was already bitten by this couple of times as well. I tend to agree that source info should not be used here. Checking declared-before seems to be pretty straightforward for tree-like IR. We need to be more careful with DAGs though.
PS: Actually, the entire ResolutionContext / ReferenceMap should not be used anywhere, but this is a separate issue :)
The Tofino code replaces/moves nodes in several places, such as during V1 -> TNA translation. During this translation, the compiler moves code from the VerifyChecksum block into the Parser block, translating
verify_checksum
intoChecksum.add
calls.ResolutionContext::lookup
compares the location of the name being looked up with the potential declaration to determine whether the declaration is a valid match. It will only match if the declaration is before the name, and it uses the SourceInfo to perform that comparison:(See here and here.)
The issue is that after moving/replacing IR nodes, the source info may no longer reflect the IR order and so the comparison will produce the wrong result.
Consider a program as follows:
When performing the V1 -> TNA translation, the
verifyChecksum
code fromComputeChecksum
is moved and translated intoIngressParser
.The challenge is what to use for the SourceInfo for the
Checksum.add()
calls inserted inIngressParser
, such aschecksum_0.add(hdr.ipv4.version)
? A reasonable choice would be to use L5 as the SourceInfo forhdr.ipv4.version
Member node in the add call. However during name lookup, the name SourceInfo would be L5, and the declaration SourceInfo would be L13, and so the before check would fail. The other choice then is to use a SourceInfo of the parser instance or beyond, but then error reports will not accurately reflect the location ofhdr.ipv4.version
in the input file.This because an issue for the Tofino project when
TypeInference
switched from using aReferenceMap
object and instead relying onResolutionContext
.The text was updated successfully, but these errors were encountered: