-
Notifications
You must be signed in to change notification settings - Fork 63
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
Add Trees That Grow-style extension fields to SetupValue
#1914
Labels
tech debt
Issues that document or involve technical debt
type: enhancement
Issues describing an improvement to an existing feature or capability
Comments
RyanGlScott
added
type: enhancement
Issues describing an improvement to an existing feature or capability
tech debt
Issues that document or involve technical debt
labels
Aug 22, 2023
29 tasks
RyanGlScott
added a commit
that referenced
this issue
Aug 24, 2023
This removes all of the `HasSetup* :: Bool` type families in favor of new `X* :: Type` type families. These largely serve the same purpose of distinguishing which constructors of `SetupValue` are permissible in each language backend, but they are permit bundling additional, language-specific information into a `SetupValue`. For instance, the `XSetupStruct` instance for `LLVM` evaluates to `Bool`, representing whether we are dealing with an LLVM packed struct or not, and the `XSetupCast` instance for `LLVM` evaluates to an LLVM `Type` to represent the type to cast to. One consequence of this design, aside from some `SetupValue` fields moving around, is that `ppSetupValue` now must perform case analysis on which language backend is currently in use in order to pretty-print any backend-specific data. This is accomplished with the new `SAWExt` data type and the corresponding `IsExt` class. There is a lot of code that shifts around in this patch, but everything is still functionally equivalent. In a subsequent patch, I will introduce additional data into MIR-specific extension fields. Fixes #1914.
RyanGlScott
added a commit
that referenced
this issue
Sep 1, 2023
This removes all of the `HasSetup* :: Bool` type families in favor of new `X* :: Type` type families. These largely serve the same purpose of distinguishing which constructors of `SetupValue` are permissible in each language backend, but they are permit bundling additional, language-specific information into a `SetupValue`. For instance, the `XSetupStruct` instance for `LLVM` evaluates to `Bool`, representing whether we are dealing with an LLVM packed struct or not, and the `XSetupCast` instance for `LLVM` evaluates to an LLVM `Type` to represent the type to cast to. One consequence of this design, aside from some `SetupValue` fields moving around, is that `ppSetupValue` now must perform case analysis on which language backend is currently in use in order to pretty-print any backend-specific data. This is accomplished with the new `SAWExt` data type and the corresponding `IsExt` class. There is a lot of code that shifts around in this patch, but everything is still functionally equivalent. In a subsequent patch, I will introduce additional data into MIR-specific extension fields. Fixes #1914.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
tech debt
Issues that document or involve technical debt
type: enhancement
Issues describing an improvement to an existing feature or capability
Currently,
SetupValue
is defined like this:saw-script/src/SAWScript/Crucible/Common/MethodSpec.hs
Lines 118 to 124 in 64f41ca
As this comment indicates, the design of
SetupValue
was inspired by the Trees That Grow paper, which allows defining an AST that can be extended with information specific to particular backends. Specifically, theext
type parameter is instantiated with one ofLLVM
,JVM
, orMIR
, and these determine whether fields with types such asB (HasSetupNull ext)
are inhabited. If they are inhabited, these fields evaluate to()
, indicating that that constructor is valid in that particular backend. If they are not inhabited, then these fields evaluate toVoid
, indicating that that constructor is never meant to be used in that particular backend.Unfortunately,
SetupValue
only commits halfway to the Trees That Grow design. The definition forSetupStruct
is:saw-script/src/SAWScript/Crucible/Common/MethodSpec.hs
Lines 125 to 126 in 64f41ca
This
Bool
field is terrible, as the notion of packed structs is only ever used by the LLVM backend. Despite this, other backends will still have to passFalse
when usingSetupStruct
, even though thisBool
is immaterial in these backends. This goes against the entire philosophy of Trees That Grow, which offers a way to have information that is specific to each backend without requiring other backends to care about it.I propose that we refactor the Trees That Grow machinery in
SetupValue
slightly to fix this infelicity. Instead of havingtype family HasSetupStruct ext :: Bool
,type family HasSetupNull ext :: Bool
, etc., we should instead have something liketype family XSetupStruct ext :: Type
. Just as before, we will provide instances ofXSetupStruct
et al. forLLVM
,JVM
, andMIR
, and if a particular construct isn't used in a backend, we will declareXSetupStruct
etc. to evaluate toVoid
. If a construct is used in a particular backend, however, thenXSetupStruct
etc. should evaluate to the type used in that specific backend rather than just()
. To wit, this means that we would have:Now that JVM backend doesn't need to care about packed structs at all.
This refactoring would be especially useful for the in-development MIR backend for SAW (see #1859), as various MIR constructs need additional information not required by other backends:
SetupArray
does not store this type, however.SetupStruct
does not have a place to store this type.The text was updated successfully, but these errors were encountered: