From 3473822c010ebaeeeb954e36edb01c769e972f5d Mon Sep 17 00:00:00 2001 From: Leonardo de Moura Date: Sun, 23 Sep 2018 11:29:46 -0700 Subject: [PATCH] feat(library/compiler/inliner): add `[macro_inline]` attribute For the old compiler stack, it behaves like `[inline]`. For the new compiler stack, it instructs the compiler to inline definitions before LCNF/ANF conversion. --- src/library/compiler/inliner.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/library/compiler/inliner.cpp b/src/library/compiler/inliner.cpp index ad417c10f9..54f1c138fe 100644 --- a/src/library/compiler/inliner.cpp +++ b/src/library/compiler/inliner.cpp @@ -19,6 +19,9 @@ bool is_inline(environment const & env, name const & n) { if (has_attribute(env, "inline", n)) { return true; } + if (has_attribute(env, "macro_inline", n)) { + return true; + } // decl._main is an auxiliary declaration, check decl instead if (n.is_string() && n.get_string().data()[0] == '_') { return is_inline(env, n.get_prefix()); @@ -34,6 +37,14 @@ void initialize_inliner() { if (!decl.is_definition()) throw exception("invalid 'inline' use, only definitions can be marked as inline"); })); + + register_system_attribute(basic_attribute::with_check( + "macro_inline", "mark definition to always be inlined before ANF conversion", + [](environment const & env, name const & d, bool) -> void { + auto decl = env.get(d); + if (!decl.is_definition()) + throw exception("invalid 'macro_inline' use, only definitions can be marked as inline"); + })); } void finalize_inliner() {