-
Notifications
You must be signed in to change notification settings - Fork 44
Use unit and element symbol attributes #2365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
-- | Wrapper for giving names to arguments. | ||
newtype UnitSymbol = UnitSymbol {getUnitSymbol :: Symbol} | ||
-- newtype UnitSymbol = UnitSymbol {getUnitSymbol :: Symbol} | ||
|
||
-- | Wrapper for giving names to arguments. | ||
newtype ConcatSymbol = ConcatSymbol {getConcatSymbol :: Symbol} | ||
-- newtype ConcatSymbol = ConcatSymbol {getConcatSymbol :: Symbol} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: Remove these comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add a description to the PR as well?
kore/src/Kore/Attribute/Concat.hs
Outdated
| otherwise = error $ | ||
"Concat symbol mismatch error! Found both " | ||
++ unparseToString aSymbol | ||
++ " and " | ||
++ unparseToString bSymbol | ||
++ " inside term. This is a bug in the Haskell backend." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better to add an error log entry type for this? Also, we should probably format the message with Pretty
.
I have an additional question. If this throws an error, are we 100% certain that this is a bug in the backend or is it possible that the frontend generated the attributes wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To quickly answer your second question, it could be indeed that the frontend generated some bad attributes. I should probably change that message to just say "This is a bug." as it could be in either the frontend or backend.
kore/src/Kore/Attribute/Element.hs
Outdated
mergeElement a@(Element (Just aSymbol)) (Element (Just bSymbol)) | ||
| aSymbol == bSymbol = a | ||
| otherwise = error $ | ||
"Element symbol mismatch error! Found both " | ||
++ unparseToString aSymbol | ||
++ " and " | ||
++ unparseToString bSymbol | ||
++ " inside term. This is a bug in the Haskell backend." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to my comment on mergeConcat
.
@@ -260,6 +272,90 @@ instance TermWrapper NormalizedMap where | |||
|
|||
simplifiedAttributeValue = TermLike.simplifiedAttribute . getMapValue | |||
|
|||
|
|||
toNormalizedInternalMap |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please document this and the rest of the functions you added to this file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just did, let me know if you're happy with it.
How's this? |
@@ -0,0 +1 @@ | |||
LblinitGeneratedTopCell{}(Lbl'Unds'Map'Unds'{}(Lbl'Unds'Map'Unds'{}(Lbl'Unds'Map'Unds'{}(Lbl'Unds'Map'Unds'{}(Lbl'Stop'Map{}(),Lbl'UndsPipe'-'-GT-Unds'{}(inj{SortKConfigVar{}, SortKItem{}}(\dv{SortKConfigVar{}}("$SCHEDULE")),inj{SortSchedule{}, SortKItem{}}(LblDEFAULT'Unds'EVM{}()))),Lbl'UndsPipe'-'-GT-Unds'{}(inj{SortKConfigVar{}, SortKItem{}}(\dv{SortKConfigVar{}}("$MODE")),inj{SortMode{}, SortKItem{}}(LblVMTESTS{}()))),Lbl'UndsPipe'-'-GT-Unds'{}(inj{SortKConfigVar{}, SortKItem{}}(\dv{SortKConfigVar{}}("$CHAINID")),inj{SortInt{}, SortKItem{}}(\dv{SortInt{}}("1")))),Lbl'UndsPipe'-'-GT-Unds'{}(inj{SortKConfigVar{}, SortKItem{}}(\dv{SortKConfigVar{}}("$PGM")),inj{SortEthereumSimulation{}, SortKItem{}}(inj{SortJSON{}, SortEthereumSimulation{}}(LblJSONObject{}(LblJSONs{}(LblJSONEntry{}(inj{SortString{}, SortJSONKey{}}(\dv{SortString{}}("add0")),LblJSONObject{}(LblJSONs{}(LblJSONEntry{}(inj{SortString{}, SortJSONKey{}}(\dv{SortString{}}("_info")),LblJSONObject{}(LblJSONs{}(LblJSONEntry{}(inj{SortString{}, SortJSONKey{}}(\dv{SortString{}}("comment")),inj{SortString{}, SortJSON{}}(\dv{SortString{}}(""))),LblJSONs{}(LblJSONEntry{}(inj{SortString{}, SortJSONKey{}}(\dv{SortString{}}("filledwith")),inj{SortString{}, SortJSON{}}(\dv{SortString{}}("testeth 1.5.0.dev2-52+commit.d419e0a2"))),LblJSONs{}(LblJSONEntry{}(inj{SortString{}, SortJSONKey{}}(\dv{SortString{}}("lllcversion")),inj{SortString{}, SortJSON{}}(\dv{SortString{}}("Version: 0.4.26-develop.2018.9.19+commit.785cbf40.Linux.g++"))),LblJSONs{}(LblJSONEntry{}(inj{SortString{}, SortJSONKey{}}(\dv{SortString{}}("source")),inj{SortString{}, SortJSON{}}(\dv{SortString{}}("src/VMTestsFiller/vmArithmeticTest/add0Filler.json"))),LblJSONs{}(LblJSONEntry{}(inj{SortString{}, SortJSONKey{}}(\dv{SortString{}}("sourceHash")),inj{SortString{}, SortJSON{}}(\dv{SortString{}}("2d47e8f287f580e1e0ec6b926375f8fee1142475cbf3bdcdf9305e618b66cb40"))),Lbl'Stop'List'LBraQuot'JSONs'QuotRBraUnds'JSONs{}()))))))),LblJSONs{}(LblJSONEntry{}(inj{SortString{}, SortJSONKey{}}(\dv{SortString{}}("callcreates")),LblJSONList{}(Lbl'Stop'List'LBraQuot'JSONs'QuotRBraUnds'JSONs{}())),LblJSONs{}(LblJSONEntry{}(inj{SortString{}, SortJSONKey{}}(\dv{SortString{}}("env")),LblJSONObject{}(LblJSONs{}(LblJSONEntry{}(inj{SortString{}, SortJSONKey{}}(\dv{SortString{}}("currentCoinbase")),inj{SortString{}, SortJSON{}}(\dv{SortString{}}("0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"))),LblJSONs{}(LblJSONEntry{}(inj{SortString{}, SortJSONKey{}}(\dv{SortString{}}("currentDifficulty")),inj{SortString{}, SortJSON{}}(\dv{SortString{}}("0x0100"))),LblJSONs{}(LblJSONEntry{}(inj{SortString{}, SortJSONKey{}}(\dv{SortString{}}("currentGasLimit")),inj{SortString{}, SortJSON{}}(\dv{SortString{}}("0x0f4240"))),LblJSONs{}(LblJSONEntry{}(inj{SortString{}, SortJSONKey{}}(\dv{SortString{}}("currentNumber")),inj{SortString{}, SortJSON{}}(\dv{SortString{}}("0x00"))),LblJSONs{}(LblJSONEntry{}(inj{SortString{}, SortJSONKey{}}(\dv{SortString{}}("currentTimestamp")),inj{SortString{}, SortJSON{}}(\dv{SortString{}}("0x01"))),Lbl'Stop'List'LBraQuot'JSONs'QuotRBraUnds'JSONs{}()))))))),LblJSONs{}(LblJSONEntry{}(inj{SortString{}, SortJSONKey{}}(\dv{SortString{}}("exec")),LblJSONObject{}(LblJSONs{}(LblJSONEntry{}(inj{SortString{}, SortJSONKey{}}(\dv{SortString{}}("address")),inj{SortString{}, SortJSON{}}(\dv{SortString{}}("0x0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6"))),LblJSONs{}(LblJSONEntry{}(inj{SortString{}, SortJSONKey{}}(\dv{SortString{}}("caller")),inj{SortString{}, SortJSON{}}(\dv{SortString{}}("0xcd1722f2947def4cf144679da39c4c32bdc35681"))),LblJSONs{}(LblJSONEntry{}(inj{SortString{}, SortJSONKey{}}(\dv{SortString{}}("code")),inj{SortString{}, SortJSON{}}(\dv{SortString{}}("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01600055"))),LblJSONs{}(LblJSONEntry{}(inj{SortString{}, SortJSONKey{}}(\dv{SortString{}}("data")),inj{SortString{}, SortJSON{}}(\dv{SortString{}}("0x"))),LblJSONs{}(LblJSONEntry{}(inj{SortString{}, SortJSONKey{}}(\dv{SortString{}}("gas")),inj{SortString{}, SortJSON{}}(\dv{SortString{}}("0x0186a0"))),LblJSONs{}(LblJSONEntry{}(inj{SortString{}, SortJSONKey{}}(\dv{SortString{}}("gasPrice")),inj{SortString{}, SortJSON{}}(\dv{SortString{}}("0x5af3107a4000"))),LblJSONs{}(LblJSONEntry{}(inj{SortString{}, SortJSONKey{}}(\dv{SortString{}}("origin")),inj{SortString{}, SortJSON{}}(\dv{SortString{}}("0xcd1722f2947def4cf144679da39c4c32bdc35681"))),LblJSONs{}(LblJSONEntry{}(inj{SortString{}, SortJSONKey{}}(\dv{SortString{}}("value")),inj{SortString{}, SortJSON{}}(\dv{SortString{}}("0x0de0b6b3a7640000"))),Lbl'Stop'List'LBraQuot'JSONs'QuotRBraUnds'JSONs{}())))))))))),LblJSONs{}(LblJSONEntry{}(inj{SortString{}, SortJSONKey{}}(\dv{SortString{}}("gas")),inj{SortString{}, SortJSON{}}(\dv{SortString{}}("0x013874"))),LblJSONs{}(LblJSONEntry{}(inj{SortString{}, SortJSONKey{}}(\dv{SortString{}}("logs")),inj{SortString{}, SortJSON{}}(\dv{SortString{}}("0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"))),LblJSONs{}(LblJSONEntry{}(inj{SortString{}, SortJSONKey{}}(\dv{SortString{}}("out")),inj{SortString{}, SortJSON{}}(\dv{SortString{}}("0x"))),LblJSONs{}(LblJSONEntry{}(inj{SortString{}, SortJSONKey{}}(\dv{SortString{}}("post")),LblJSONObject{}(LblJSONs{}(LblJSONEntry{}(inj{SortString{}, SortJSONKey{}}(\dv{SortString{}}("0x0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6")),LblJSONObject{}(LblJSONs{}(LblJSONEntry{}(inj{SortString{}, SortJSONKey{}}(\dv{SortString{}}("balance")),inj{SortString{}, SortJSON{}}(\dv{SortString{}}("0x0de0b6b3a7640000"))),LblJSONs{}(LblJSONEntry{}(inj{SortString{}, SortJSONKey{}}(\dv{SortString{}}("code")),inj{SortString{}, SortJSON{}}(\dv{SortString{}}("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01600055"))),LblJSONs{}(LblJSONEntry{}(inj{SortString{}, SortJSONKey{}}(\dv{SortString{}}("nonce")),inj{SortString{}, SortJSON{}}(\dv{SortString{}}("0x00"))),LblJSONs{}(LblJSONEntry{}(inj{SortString{}, SortJSONKey{}}(\dv{SortString{}}("storage")),LblJSONObject{}(LblJSONs{}(LblJSONEntry{}(inj{SortString{}, SortJSONKey{}}(\dv{SortString{}}("0x00")),inj{SortString{}, SortJSON{}}(\dv{SortString{}}("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe"))),Lbl'Stop'List'LBraQuot'JSONs'QuotRBraUnds'JSONs{}()))),Lbl'Stop'List'LBraQuot'JSONs'QuotRBraUnds'JSONs{}())))))),Lbl'Stop'List'LBraQuot'JSONs'QuotRBraUnds'JSONs{}()))),LblJSONs{}(LblJSONEntry{}(inj{SortString{}, SortJSONKey{}}(\dv{SortString{}}("pre")),LblJSONObject{}(LblJSONs{}(LblJSONEntry{}(inj{SortString{}, SortJSONKey{}}(\dv{SortString{}}("0x0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6")),LblJSONObject{}(LblJSONs{}(LblJSONEntry{}(inj{SortString{}, SortJSONKey{}}(\dv{SortString{}}("balance")),inj{SortString{}, SortJSON{}}(\dv{SortString{}}("0x0de0b6b3a7640000"))),LblJSONs{}(LblJSONEntry{}(inj{SortString{}, SortJSONKey{}}(\dv{SortString{}}("code")),inj{SortString{}, SortJSON{}}(\dv{SortString{}}("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01600055"))),LblJSONs{}(LblJSONEntry{}(inj{SortString{}, SortJSONKey{}}(\dv{SortString{}}("nonce")),inj{SortString{}, SortJSON{}}(\dv{SortString{}}("0x00"))),LblJSONs{}(LblJSONEntry{}(inj{SortString{}, SortJSONKey{}}(\dv{SortString{}}("storage")),LblJSONObject{}(Lbl'Stop'List'LBraQuot'JSONs'QuotRBraUnds'JSONs{}())),Lbl'Stop'List'LBraQuot'JSONs'QuotRBraUnds'JSONs{}())))))),Lbl'Stop'List'LBraQuot'JSONs'QuotRBraUnds'JSONs{}()))),Lbl'Stop'List'LBraQuot'JSONs'QuotRBraUnds'JSONs{}()))))))))))),Lbl'Stop'List'LBraQuot'JSONs'QuotRBraUnds'JSONs{}()))))))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there an explanation for why some of these have file extensions other than .kore
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is due to the frontend changing the naming of the files in the temporary run directory. There's a discussion about it in our #k channel if you're interested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition to my comments from the meeting, I added a few more suggestions.
kore/test/Test/Kore/Builtin.hs
Outdated
@@ -78,44 +89,50 @@ test_internalize = | |||
|
|||
, internalizes "unitMap" | |||
unitMap | |||
(mkMap []) | |||
(mkMap [] True False False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these tests would be easier to read if instead of using Bool
values we'd create some datatypes with more suggestive names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I experimented with different data types but I think that my latest changes strike the best balance between readability and complexity/overhead. What I ended up doing was just to define some constants to be True
and False
and I'm using those constants in the tests instead of the naked bools. I hope this addresses your point.
Co-authored-by: ana-pantilie <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
, unitHook :: !(Unit SymbolOrAlias) | ||
, elementHook :: !(Element SymbolOrAlias) | ||
, concatHook :: !(Concat SymbolOrAlias) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These fields refer to symbols, not hooks. Furthermore, all of the other fields in this record are named for the type of the field, so these should be named unit
, element
, and concat
.
, unitHook :: !(Unit SymbolOrAlias) | ||
, elementHook :: !(Element SymbolOrAlias) | ||
, concatHook :: !(Concat SymbolOrAlias) | ||
-- ^ The above three are only populated if the symbol is a concat |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the third field populated if the symbol is a concat symbol? Wouldn't it always refer to the symbol itself?
Fixes #2222
This PR aims to get rid of the need to use MetadataTools in the process of internalization of builtin terms. The way this works is that symbols now have three additional attributes, each of which is optional. These attributes are, at the moment, only populated for symbols that are hooked to builtin symbols (such as set concatenation, map element etc.) and they point to that builtin's unit, element or concat symbols. The values for these attributes come from the attributes explicitly written in the definition kore files or from other trivial deductions (e.g. the map unit will set it's unit attribute to itself).
Before, we would only use the MetadataTools to get these symbols at internalization time from the Sort attributes in order to populate the resulting
InternalAc
, but with these changes, we no longer have to look at the Sort's attributes, being able to instead only look at attributes of the symbols that make up our builtin directly.Additionally, since the three symbol fields of an
InternalAc
are mainly just used for unparsing, we can sometimes get away with only recording the id of a symbol, rather than the a fullSymbol
that also has attributes.Review checklist
The author performs the actions on the checklist. The reviewer evaluates the work and checks the boxes as they are completed.