Skip to content
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

Implement type-safe attributes #983

Merged
merged 13 commits into from
Feb 16, 2024
Merged

Implement type-safe attributes #983

merged 13 commits into from
Feb 16, 2024

Conversation

Baltoli
Copy link
Contributor

@Baltoli Baltoli commented Feb 15, 2024

This PR implements a more limited version of the type-safe attribute infrastructure that we use in the K frontend; by doing so we can construct a canonical list of the attributes that we actually use in the backend, and avoid working with string data when we don't need to be.

The core of the change is a new attribute_set structure that accepts attributes permissively from the parser, but only allows key-value lookup via a limited set of whitelisted attribute keys. There are a couple of places in the code that need to access the full set of attributes, ignoring the whitelist:

  • When pretty-printing via iteration over the set of stored attributes
  • When returning the set of attributes to Pyk via the Python bindings

Both of these code paths have comments to make sure they are used cautiously.

The bulk of the changes are 1:1 and can be reviewed pretty easily in the split diff; there's only a small API change in code that consumes attributes in the backend.

There is a small papercut in that the syntax to reference an attribute key is quite verbose (attribute_set::key::name); when we upgrade to C++20 in the near future we get access to using enum attribute_set::key; which solves this problem and makes the code nicer to read.

I've tested the change upstream against the K integration test suite.

@Baltoli Baltoli changed the title Rethink attribute infrastructure Implement type-safe attributes Feb 15, 2024
@Baltoli Baltoli marked this pull request as ready for review February 15, 2024 15:57
Copy link
Contributor

@Scott-Guest Scott-Guest left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@theo25 theo25 left a comment

Choose a reason for hiding this comment

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

This looks good to me. I left a few minor comments but I will approve and leave to you to decide if you want to address them.

include/kllvm/ast/attribute_set.h Outdated Show resolved Hide resolved
lib/ast/attribute_set.cpp Show resolved Hide resolved
lib/ast/attribute_set.cpp Show resolved Hide resolved
lib/ast/attribute_set.cpp Show resolved Hide resolved
@rv-jenkins rv-jenkins merged commit 8918d3e into master Feb 16, 2024
7 checks passed
@rv-jenkins rv-jenkins deleted the attribute-rethink branch February 16, 2024 01:00
rv-jenkins pushed a commit that referenced this pull request Feb 16, 2024
Following runtimeverification/k#3989, the KORE
attribute that encodes "this axiom declares an overload equality over
two symbols `X` and `Y`" is being gradually renamed from `overload(_,_)`
to `symbol-overload(_,_)`.

This PR moves the LLVM backend over to accepting the new attribute
rather than the old one; doing so is a simple renaming process on the
attribute following #983. The checked-in KORE test files are updated by
a simple renaming of the attribute.[^1]

~~Blocked on: #983~~

[^1]: See #987; it's a pain to regenerate all the KORE at the moment so
I've edited the files manually using `sed` rather than the actual K
frontend. This is fine for this case in the frontend, but in the future
if we make more complex changes to the structure of compiled KORE
definitions we should implement a more robust way of rebuilding the test
suite to pin against a particular frontend version.
@gtrepta gtrepta mentioned this pull request Feb 16, 2024
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.

4 participants