-
Notifications
You must be signed in to change notification settings - Fork 3
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
feat: elide attribute type with new StaticallyTypedAttrInterface
#59
Merged
ingomueller-net
merged 2 commits into
substrait-io:main
from
ingomueller-net:statically-typed-attr
Jan 30, 2025
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,9 +15,24 @@ include "mlir/IR/AttrTypeBase.td" | |
include "mlir/IR/BuiltinAttributeInterfaces.td" | ||
|
||
// Base class for Substrait dialect attribute types. | ||
class Substrait_Attr<string name, string typeMnemonic, list<Trait> traits = []> | ||
class Substrait_Attr<string name, string attrMnemonic, list<Trait> traits = []> | ||
: AttrDef<Substrait_Dialect, name, traits> { | ||
let mnemonic = typeMnemonic; | ||
let mnemonic = attrMnemonic; | ||
} | ||
|
||
// Base class for Substrait dialect attribute types that have a statically known | ||
// value type. | ||
class Substrait_StaticallyTypedAttr< | ||
string name, string attrMnemonic, string typeName, list<Trait> traits = []> | ||
: Substrait_Attr<name, attrMnemonic, traits # [ | ||
DeclareAttrInterfaceMethods<TypeInferableAttrInterface> | ||
]> { | ||
let extraClassDeclaration = [{ | ||
/// Implement TypeInferableAttrInterface. | ||
::mlir::Type getType() { | ||
return ::mlir::substrait::}] # typeName # [{::get(getContext()); | ||
} | ||
}]; | ||
} | ||
|
||
def Substrait_AdvancedExtensionAttr | ||
|
@@ -34,64 +49,44 @@ def Substrait_AdvancedExtensionAttr | |
let genVerifyDecl = 1; | ||
} | ||
|
||
def Substrait_DateAttr : Substrait_Attr<"Date", "date", | ||
[TypedAttrInterface]> { | ||
def Substrait_DateAttr | ||
: Substrait_StaticallyTypedAttr<"Date", "date", "DateType"> { | ||
let summary = "Substrait date type"; | ||
let description = [{ | ||
This type represents a substrait date attribute type. | ||
}]; | ||
let parameters = (ins "int32_t":$value); | ||
let assemblyFormat = [{ `<` $value `>` }]; | ||
let extraClassDeclaration = [{ | ||
::mlir::Type getType() const { | ||
return DateType::get(getContext()); | ||
} | ||
}]; | ||
} | ||
|
||
def Substrait_TimeAttr : Substrait_Attr<"Time", "time", | ||
[TypedAttrInterface]> { | ||
def Substrait_TimeAttr : | ||
Substrait_StaticallyTypedAttr<"Time", "time", "TimeType"> { | ||
let summary = "Substrait time type"; | ||
let description = [{ | ||
This type represents a substrait time attribute type. | ||
}]; | ||
let parameters = (ins "int64_t":$value); | ||
let assemblyFormat = [{ `<` $value `` `us` `>` }]; | ||
let extraClassDeclaration = [{ | ||
::mlir::Type getType() const { | ||
return TimeType::get(getContext()); | ||
} | ||
}]; | ||
} | ||
|
||
def Substrait_TimestampAttr : Substrait_Attr<"Timestamp", "timestamp", | ||
[TypedAttrInterface]> { | ||
def Substrait_TimestampAttr | ||
ingomueller-net marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: colon on this line to match the others. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
: Substrait_StaticallyTypedAttr<"Timestamp", "timestamp", "TimestampType"> { | ||
let summary = "Substrait timezone-unaware timestamp type"; | ||
let description = [{ | ||
This type represents a substrait timezone-unaware timestamp attribute type. | ||
}]; | ||
let parameters = (ins "int64_t":$value); | ||
let assemblyFormat = [{ `<` $value `` `us` `>` }]; | ||
let extraClassDeclaration = [{ | ||
::mlir::Type getType() const { | ||
return TimestampType::get(getContext()); | ||
} | ||
}]; | ||
} | ||
|
||
def Substrait_TimestampTzAttr : Substrait_Attr<"TimestampTz", "timestamp_tz", | ||
[TypedAttrInterface]> { | ||
def Substrait_TimestampTzAttr : Substrait_StaticallyTypedAttr< | ||
"TimestampTz", "timestamp_tz", "TimestampTzType"> { | ||
let summary = "Substrait timezone-aware timestamp type"; | ||
let description = [{ | ||
This type represents a substrait timezone-aware timestamp attribute type. | ||
}]; | ||
let parameters = (ins "int64_t":$value); | ||
let assemblyFormat = [{ `<` $value `` `us` `>` }]; | ||
let extraClassDeclaration = [{ | ||
::mlir::Type getType() const { | ||
return TimestampTzType::get(getContext()); | ||
} | ||
}]; | ||
} | ||
|
||
/// Attributes of currently supported atomic types, listed in order of substrait | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Micro nit: add additional spaces here to differentiate from body below (I normally just add 2 extra, else this and body looks at same scope ... I should really try out the new formatter)
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.
Fixed. I tried
clang-format
, which seems to work on.td
files as well, and it works. I have formatted the lines of this commit using it. However, I am unsure as to whether and how to apply or enforce it on the existing files. The diff is quite big and a big commit just for reformatting has disadvantages...