Skip to content
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
28 changes: 23 additions & 5 deletions compiler/noirc_frontend/src/hir/comptime/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub(super) fn display_quoted(
writeln!(f, "quote {{")?;
let indent = indent + 1;
write!(f, "{}", " ".repeat(indent * 4))?;
TokensPrettyPrinter { tokens, interner, indent }.fmt(f)?;
TokensPrettyPrinter { tokens, interner, indent, preserve_unquote_markers: false }.fmt(f)?;
writeln!(f)?;
let indent = indent - 1;
write!(f, "{}", " ".repeat(indent * 4))?;
Expand All @@ -48,11 +48,13 @@ struct TokensPrettyPrinter<'tokens, 'interner> {
tokens: &'tokens [LocatedToken],
interner: &'interner NodeInterner,
indent: usize,
preserve_unquote_markers: bool,
}

impl Display for TokensPrettyPrinter<'_, '_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut token_printer = TokenPrettyPrinter::new(self.interner, self.indent);
let mut token_printer =
TokenPrettyPrinter::new(self.interner, self.indent, self.preserve_unquote_markers);
for token in self.tokens {
token_printer.print(token.token(), f)?;
}
Expand All @@ -65,15 +67,16 @@ impl Display for TokensPrettyPrinter<'_, '_> {
}

pub fn tokens_to_string(tokens: &[LocatedToken], interner: &NodeInterner) -> String {
tokens_to_string_with_indent(tokens, 0, interner)
tokens_to_string_with_indent(tokens, 0, false, interner)
}

pub fn tokens_to_string_with_indent(
tokens: &[LocatedToken],
indent: usize,
preserve_unquote_markers: bool,
interner: &NodeInterner,
) -> String {
TokensPrettyPrinter { tokens, interner, indent }.to_string()
TokensPrettyPrinter { tokens, interner, indent, preserve_unquote_markers }.to_string()
}

/// Tries to print tokens in a way that it'll be easier for the user to understand a
Expand All @@ -95,6 +98,7 @@ pub fn tokens_to_string_with_indent(
struct TokenPrettyPrinter<'interner> {
interner: &'interner NodeInterner,
indent: usize,
preserve_unquote_markers: bool,
/// Determines whether the last outputted byte was alphanumeric.
/// This is used to add a space after the last token and before another token
/// that starts with an alphanumeric byte.
Expand All @@ -105,10 +109,15 @@ struct TokenPrettyPrinter<'interner> {
}

impl<'interner> TokenPrettyPrinter<'interner> {
fn new(interner: &'interner NodeInterner, indent: usize) -> Self {
fn new(
interner: &'interner NodeInterner,
indent: usize,
preserve_unquote_markers: bool,
) -> Self {
Self {
interner,
indent,
preserve_unquote_markers,
last_was_alphanumeric: false,
last_was_right_brace: false,
last_was_semicolon: false,
Expand Down Expand Up @@ -208,6 +217,15 @@ impl<'interner> TokenPrettyPrinter<'interner> {
Token::InternedCrate(_) => write!(f, "$crate"),
Token::UnquoteMarker(id) => {
let value = Value::TypedExpr(TypedExpr::ExprId(*id));
let last_was_alphanumeric = if self.preserve_unquote_markers {
if last_was_alphanumeric {
write!(f, " ")?;
}
write!(f, "$")?;
false
} else {
last_was_alphanumeric
};
self.print_value(&value, last_was_alphanumeric, f)
}
Token::Keyword(..) | Token::Ident(..) | Token::Int(..) | Token::Bool(..) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "comptime_trait_constraint_method"
type = "bin"
authors = [""]

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
mod moo {
pub trait Trait {
fn trait_method(self);
}

impl Trait for Field {
fn trait_method(self) {}
}

pub comptime fn attr(_: FunctionDefinition) -> Quoted {
let trait_constraint = quote { Trait }.as_trait_constraint();
let field = quote { Field }.as_type();
let trait_impl = field.get_trait_impl(trait_constraint).unwrap();
let method = trait_impl.methods()[0].as_typed_expr();
let x = 1;
quote {
pub fn bar() {
let _ = $x;
$method(1);
}
}
}
}

#[moo::attr]
fn main() {
bar();
}
26 changes: 6 additions & 20 deletions tooling/nargo_cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ const TESTS_WITHOUT_STDOUT_CHECK: [&str; 0] = [];
/// These tests are ignored because of existing bugs in `nargo expand`.
/// As the bugs are fixed these tests should be removed from this list.
/// (some are ignored on purpose for the same reason as `IGNORED_NARGO_EXPAND_EXECUTION_TESTS`)
const IGNORED_NARGO_EXPAND_COMPILE_SUCCESS_EMPTY_TESTS: [&str; 13] = [
const IGNORED_NARGO_EXPAND_COMPILE_SUCCESS_EMPTY_TESTS: [&str; 9] = [
// bug
"associated_type_bounds",
// bug
Expand All @@ -202,21 +202,12 @@ const IGNORED_NARGO_EXPAND_COMPILE_SUCCESS_EMPTY_TESTS: [&str; 13] = [
// There's no "src/main.nr" here so it's trickier to make this work
"workspace_reexport_bug",
// bug
"type_trait_method_call_multiple_candidates",
// bug
"alias_trait_method_call_multiple_candidates",
// bug
"trait_call_in_global",
// bug
"comptime_traits",
// bug
"trait_multi_module_test",
];

/// These tests are ignored because of existing bugs in `nargo expand`.
/// As the bugs are fixed these tests should be removed from this list.
const IGNORED_NARGO_EXPAND_COMPILE_SUCCESS_NO_BUG_TESTS: [&str; 18] = [
"noirc_frontend_tests_arithmetic_generics_checked_casts_do_not_prevent_canonicalization",
const IGNORED_NARGO_EXPAND_COMPILE_SUCCESS_NO_BUG_TESTS: [&str; 14] = [
"noirc_frontend_tests_check_trait_as_type_as_fn_parameter",
"noirc_frontend_tests_check_trait_as_type_as_two_fn_parameters",
"noirc_frontend_tests_enums_match_on_empty_enum",
Expand All @@ -232,14 +223,9 @@ const IGNORED_NARGO_EXPAND_COMPILE_SUCCESS_NO_BUG_TESTS: [&str; 18] = [
"noirc_frontend_tests_aliases_identity_numeric_type_alias_works",
"noirc_frontend_tests_aliases_type_alias_to_numeric_as_generic",
"noirc_frontend_tests_aliases_type_alias_to_numeric_generic",
// bug
"noirc_frontend_tests_traits_associated_constant_sum_of_other_constants_3",
"noirc_frontend_tests_traits_trait_where_clause_associated_type_constraint_expected_order",
"noirc_frontend_tests_traits_trait_where_clause_associated_type_constraint_unexpected_order",
];

const IGNORED_NARGO_EXPAND_COMPILE_SUCCESS_WITH_BUG_TESTS: [&str; 1] =
["noirc_frontend_tests_cast_negative_one_to_u8_size_checks"];
const IGNORED_NARGO_EXPAND_COMPILE_SUCCESS_WITH_BUG_TESTS: [&str; 0] = [];

fn read_test_cases(
test_data_dir: &Path,
Expand Down Expand Up @@ -868,16 +854,16 @@ mod nargo_expand_{test_type} {{
.unwrap();

for (test_name, test_dir) in test_cases {
if ignore.contains(&test_name.as_str()) {
continue;
}
let should_panic =
if ignore.contains(&test_name.as_str()) { "#[should_panic]" } else { "" };

let test_dir = test_dir.display();

write!(
test_file,
r#"
#[test]
{should_panic}
fn test_{test_name}() {{
let test_program_dir = PathBuf::from("{test_dir}");
nargo_expand_compile(test_program_dir, "{test_type}");
Expand Down

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

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

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

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

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

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

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

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

Loading
Loading