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

Fix CI for tablegen dialects #276

Merged
merged 16 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
"spirv",
"stdc",
"strided",
"tablegen",
"tblgen",
"tosa",
"unranked",
"vulkan"
Expand Down
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ proc-macro = true

[dependencies]
convert_case = "0.6.0"
lazy_static = "1.4.0"
once_cell = "1.18.0"
proc-macro2 = "1"
quote = "1"
Expand Down
23 changes: 12 additions & 11 deletions macro/src/dialect/mod.rs → macro/src/dialect.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
extern crate proc_macro;

mod error;
mod operation;
mod types;

use std::io::Write;
use std::{env, error::Error, fs::OpenOptions, path::Path, process::Command};

use crate::utility::sanitize_name_snake;
use operation::Operation;
use proc_macro::TokenStream;
use proc_macro2::{Ident, Span};
use quote::{format_ident, quote};
use std::{env, error::Error, fs::OpenOptions, io::Write, path::Path, process::Command, str};
use syn::{bracketed, parse::Parse, punctuated::Punctuated, LitStr, Token};
use tblgen::{record::Record, record_keeper::RecordKeeper, TableGenParser};

Expand All @@ -24,9 +23,9 @@ fn dialect_module<'a>(
let operations = record_keeper
.all_derived_definitions("Op")
.map(Operation::from_def)
.filter_map(|o: Result<Operation, _>| match o {
Ok(o) => (o.dialect.name() == dialect.name()).then_some(Ok(o)),
Err(e) => Some(Err(e)),
.filter_map(|operation: Result<Operation, _>| match operation {
Ok(operation) => (operation.dialect.name() == dialect.name()).then_some(Ok(operation)),
Err(error) => Some(Err(error)),
})
.collect::<Result<Vec<_>, _>>()?;

Expand Down Expand Up @@ -110,10 +109,10 @@ impl Parse for DialectMacroInput {
}
}

// Writes `tablegen_compile_commands.yaml` for any TableGen file that is being parsed.
// See: https://mlir.llvm.org/docs/Tools/MLIRLSP/#tablegen-lsp-language-server--tblgen-lsp-server
// Writes `tablegen_compile_commands.yaml` for any TableGen file that is being
// parsed. See: https://mlir.llvm.org/docs/Tools/MLIRLSP/#tablegen-lsp-language-server--tblgen-lsp-server
fn emit_tablegen_compile_commands(td_file: &str, includes: &[String]) {
let pwd = std::env::current_dir();
let pwd = env::current_dir();
if let Ok(pwd) = pwd {
let path = pwd.join(td_file);
let file = OpenOptions::new()
Expand All @@ -138,6 +137,7 @@ fn emit_tablegen_compile_commands(td_file: &str, includes: &[String]) {
}

pub fn generate_dialect(mut input: DialectMacroInput) -> Result<TokenStream, Box<dyn Error>> {
// spell-checker: disable-next-line
input.includes.push(llvm_config("--includedir").unwrap());

let mut td_parser = TableGenParser::new();
Expand All @@ -156,7 +156,8 @@ pub fn generate_dialect(mut input: DialectMacroInput) -> Result<TokenStream, Box
td_parser = td_parser.add_include_path(include.as_str());
}

if std::env::var("DIALECTGEN_TABLEGEN_COMPILE_COMMANDS").is_ok() {
// spell-checker: disable-next-line
if env::var("DIALECTGEN_TABLEGEN_COMPILE_COMMANDS").is_ok() {
if let Some(td_file) = input.td_file.as_ref() {
emit_tablegen_compile_commands(td_file, &input.includes);
}
Expand Down Expand Up @@ -191,7 +192,7 @@ fn llvm_config(argument: &str) -> Result<String, Box<dyn Error>> {
argument
);

Ok(std::str::from_utf8(
Ok(str::from_utf8(
&if cfg!(target_os = "windows") {
Command::new("cmd").args(["/C", &call]).output()?
} else {
Expand Down
3 changes: 2 additions & 1 deletion macro/src/dialect/operation/accessors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ impl<'a> OperationField<'a> {
if t.is_variable_length() {
if t.is_optional() {
// Optional element, and some singular elements.
// Only present if the amount of groups is at least the number of elements.
// Only present if the amount of groups is at least the number of
// elements.
quote! {
if self.operation.#count() < #len {
None
Expand Down
3 changes: 2 additions & 1 deletion macro/src/dialect/operation/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ impl<'o, 'c> OperationBuilder<'o, 'c> {
};

// Argument types can be singular and variadic, but add functions in melior
// are always variadic, so we need to create a slice or vec for singular arguments
// are always variadic, so we need to create a slice or vec for singular
// arguments
match &f.kind {
FieldKind::Operand(tc) | FieldKind::Result(tc) => {
if tc.is_variable_length() && !tc.is_optional() {
Expand Down
18 changes: 11 additions & 7 deletions macro/src/dialect/operation/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
mod accessors;
mod builder;

use crate::dialect::{
error::{Error, ExpectedSuperClassError},
types::{AttributeConstraint, RegionConstraint, SuccessorConstraint, Trait, TypeConstraint},
use crate::{
dialect::{
error::{Error, ExpectedSuperClassError},
types::{
AttributeConstraint, RegionConstraint, SuccessorConstraint, Trait, TypeConstraint,
},
},
utility::sanitize_name_snake,
};
use crate::utility::sanitize_name_snake;
use proc_macro2::{Ident, TokenStream};
use quote::{format_ident, quote, ToTokens, TokenStreamExt};
use tblgen::error::WithLocation;
use tblgen::record::Record;
use tblgen::{error::WithLocation, record::Record};

use self::builder::OperationBuilder;

Expand Down Expand Up @@ -284,7 +287,8 @@ impl<'a> Operation<'a> {
))
});

// Creates an initial `VariadicKind` instance based on SameSize and AttrSized traits.
// Creates an initial `VariadicKind` instance based on SameSize and AttrSized
// traits.
let initial_variadic_kind = |num_variable_length: usize, kind_name_upper: &str| {
let same_size_trait = format!("::mlir::OpTrait::SameVariadic{}Size", kind_name_upper);
let attr_sized = format!("::mlir::OpTrait::AttrSized{}Segments", kind_name_upper);
Expand Down
Loading