Skip to content

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

Merged
merged 39 commits into from
Mar 9, 2021
Merged

Use unit and element symbol attributes #2365

merged 39 commits into from
Mar 9, 2021

Conversation

MirceaS
Copy link
Contributor

@MirceaS MirceaS commented Jan 25, 2021

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 full Symbol 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.

  • Summary. Write a summary of the changes. Explain what you did to fix the issue, and why you did it. Present the changes in a logical order. Instead of writing a summary in the pull request, you may push a clean Git history.
  • Documentation. Write documentation for new functions. Update documentation for functions that changed, or complete documentation where it is missing.
  • Tests. Write unit tests for every change. Write the unit tests that were missing before the changes. Include any examples from the reported issue as integration tests.
  • Clean up. The changes are already clean. Clean up anything near the changes that you noticed while working. This does not mean only spatially near the changes, but logically near: any code that interacts with the changes!

@ttuegel ttuegel changed the title 2222 Use unit and element symbol attributes Jan 27, 2021
Comment on lines 56 to 60
-- | 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}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Remove these comments

@ttuegel ttuegel requested review from emarzion and ana-pantilie March 2, 2021 15:18
Copy link
Contributor

@ana-pantilie ana-pantilie left a 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?

Comment on lines 41 to 46
| otherwise = error $
"Concat symbol mismatch error! Found both "
++ unparseToString aSymbol
++ " and "
++ unparseToString bSymbol
++ " inside term. This is a bug in the Haskell backend."
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Comment on lines 35 to 42
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."
Copy link
Contributor

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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@MirceaS
Copy link
Contributor Author

MirceaS commented Mar 5, 2021

Could you please add a description to the PR as well?

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{}())))))))
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

@ana-pantilie ana-pantilie left a 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.

@@ -78,44 +89,50 @@ test_internalize =

, internalizes "unitMap"
unitMap
(mkMap [])
(mkMap [] True False False)
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@rv-jenkins rv-jenkins merged commit abf0292 into master Mar 9, 2021
@rv-jenkins rv-jenkins deleted the 2222 branch March 9, 2021 20:49
Copy link
Contributor

@ttuegel ttuegel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MirceaS Please fix the names of the attribute fields and update the glossary (#2457).

Comment on lines +130 to +132
, unitHook :: !(Unit SymbolOrAlias)
, elementHook :: !(Element SymbolOrAlias)
, concatHook :: !(Concat SymbolOrAlias)
Copy link
Contributor

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
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dereference unit and element symbol attributes
5 participants