diff --git a/hilti/toolchain/include/ast/node-range.h b/hilti/toolchain/include/ast/node-range.h index 2f21731a98..22b4d042ee 100644 --- a/hilti/toolchain/include/ast/node-range.h +++ b/hilti/toolchain/include/ast/node-range.h @@ -110,7 +110,7 @@ class Range { auto begin() const { return const_iterator(_begin); } auto end() const { return const_iterator(_end); } size_t size() const { return static_cast(_end - _begin); } - const T& front() const { return *_begin; } + T* front() const { return *_begin; } bool empty() const { return _begin == _end; } operator NodeVector() const { diff --git a/hilti/toolchain/src/compiler/optimizer.cc b/hilti/toolchain/src/compiler/optimizer.cc index d9c32e6e74..9d7bace865 100644 --- a/hilti/toolchain/src/compiler/optimizer.cc +++ b/hilti/toolchain/src/compiler/optimizer.cc @@ -1000,6 +1000,22 @@ struct PeepholeOptimizer : visitor::MutatingPostOrder { } } } + + void operator()(statement::Try* n) final { + // If a there's only a single catch block that just rethrows, replace + // the whole try/catch with the block inside. + if ( auto catches = n->catches(); catches.size() == 1 ) { + const auto& catch_ = catches.front(); + if ( auto catch_body = catch_->body()->as(); catch_body->statements().size() == 1 ) { + if ( auto throw_ = catch_body->statements().front()->tryAs(); + throw_ && ! throw_->expression() ) { + recordChange(n, "replacing rethrowing try/catch with just the block"); + replaceNode(n, n->body()); + return; + } + } + } + } }; // This visitor collects requirement attributes in the AST and toggles unused features. diff --git a/tests/Baseline/hilti.optimization.peephole-try-catch/opt.hlt b/tests/Baseline/hilti.optimization.peephole-try-catch/opt.hlt new file mode 100644 index 0000000000..3d9e3fedc7 --- /dev/null +++ b/tests/Baseline/hilti.optimization.peephole-try-catch/opt.hlt @@ -0,0 +1,11 @@ +### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. +module Test { + + +public function void foo() { + + assert True; + +} + +} diff --git a/tests/Baseline/spicy.optimization.default-parser-functions/log b/tests/Baseline/spicy.optimization.default-parser-functions/log index 0d0e69d683..aa9cee0541 100644 --- a/tests/Baseline/spicy.optimization.default-parser-functions/log +++ b/tests/Baseline/spicy.optimization.default-parser-functions/log @@ -273,6 +273,8 @@ [debug/optimizer] [] statement::If "if ( False ) { }" -> null [debug/optimizer] [] statement::If "if ( False ) { }" -> null [debug/optimizer] [] statement::If "if ( False ) { }" -> null +[debug/optimizer] [] statement::Try "try { hilti::debugIndent("spicy"); local iterator __begin = begin(__cur); local strong_ref filtered = Null; if ( ! filtered ) __result = (*self).__parse_foo__P1_stage2(__data, __begin, __cur, __trim, __lah, __lahe, __error); } catch ( hilti::SystemException __except ) { throw; }" -> replacing rethrowing try/catch with just the block +[debug/optimizer] [] statement::Try "try { hilti::debugIndent("spicy"); local iterator __begin = begin(__cur); local strong_ref filtered = Null; if ( ! filtered ) __result = (*self).__parse_foo__P1_stage2(__data, __begin, __cur, __trim, __lah, __lahe, __error); } catch ( hilti::SystemException __except ) { throw; }" -> statement::Block "{ hilti::debugIndent("spicy"); local iterator __begin = begin(__cur); local strong_ref filtered = Null; if ( ! filtered ) __result = (*self).__parse_foo__P1_stage2(__data, __begin, __cur, __trim, __lah, __lahe, __error); }" [debug/optimizer] [default-parser-functions.spicy:10:1-21:2] declaration::Constant "const bool __feat%foo@@P0%supports_filters = False;" -> disabled feature 'supports_filters' of type 'foo::P0' since it is not used [debug/optimizer] [default-parser-functions.spicy:10:1-21:2] declaration::Constant "const bool __feat%foo@@P0%supports_sinks = False;" -> disabled feature 'supports_sinks' of type 'foo::P0' since it is not used [debug/optimizer] [default-parser-functions.spicy:10:1-21:2] declaration::Constant "const bool __feat%foo@@P0%synchronization = False;" -> disabled feature 'synchronization' of type 'foo::P0' since it is not used diff --git a/tests/Baseline/spicy.optimization.default-parser-functions/opt.hlt b/tests/Baseline/spicy.optimization.default-parser-functions/opt.hlt index 797aae34aa..980664ae73 100644 --- a/tests/Baseline/spicy.optimization.default-parser-functions/opt.hlt +++ b/tests/Baseline/spicy.optimization.default-parser-functions/opt.hlt @@ -58,7 +58,7 @@ init function void __register_foo_P0() { method method tuple, int<64>, const iterator, optional> foo::P1::__parse_stage1(inout value_ref __data, iterator __begin, copy view __cur, copy bool __trim, copy int<64> __lah, copy iterator __lahe, copy optional __error) { # "<...>/default-parser-functions.spicy:14:18-14:24" local tuple, int<64>, const iterator, optional> __result; - try { + { hilti::debugIndent("spicy"); local iterator __begin = begin(__cur); local strong_ref filtered = Null; @@ -67,8 +67,6 @@ method method tuple, int<64>, const iterator, optiona __result = (*self).__parse_foo__P1_stage2(__data, __begin, __cur, __trim, __lah, __lahe, __error); } - catch ( hilti::SystemException __except ) - throw; return __result; } diff --git a/tests/Baseline/spicy.optimization.unused-functions/log b/tests/Baseline/spicy.optimization.unused-functions/log index 937893397b..2c95f8226e 100644 --- a/tests/Baseline/spicy.optimization.unused-functions/log +++ b/tests/Baseline/spicy.optimization.unused-functions/log @@ -426,6 +426,12 @@ [debug/optimizer] [] statement::If "if ( False ) { }" -> null [debug/optimizer] [] statement::If "if ( False ) { }" -> null [debug/optimizer] [] statement::If "if ( False ) { }" -> null +[debug/optimizer] [] statement::Try "try { hilti::debugIndent("spicy"); local iterator __begin = begin(__cur); local strong_ref filtered = Null; if ( ! filtered ) __result = (*self).__parse_foo__B_stage2(__data, __begin, __cur, __trim, __lah, __lahe, __error); } catch ( hilti::SystemException __except ) { throw; }" -> replacing rethrowing try/catch with just the block +[debug/optimizer] [] statement::Try "try { hilti::debugIndent("spicy"); local iterator __begin = begin(__cur); local strong_ref filtered = Null; if ( ! filtered ) __result = (*self).__parse_foo__B_stage2(__data, __begin, __cur, __trim, __lah, __lahe, __error); } catch ( hilti::SystemException __except ) { throw; }" -> statement::Block "{ hilti::debugIndent("spicy"); local iterator __begin = begin(__cur); local strong_ref filtered = Null; if ( ! filtered ) __result = (*self).__parse_foo__B_stage2(__data, __begin, __cur, __trim, __lah, __lahe, __error); }" +[debug/optimizer] [] statement::Try "try { hilti::debugIndent("spicy"); local iterator __begin = begin(__cur); local strong_ref filtered = Null; if ( ! filtered ) __result = (*self).__parse_foo__C_stage2(__data, __begin, __cur, __trim, __lah, __lahe, __error); } catch ( hilti::SystemException __except ) { throw; }" -> replacing rethrowing try/catch with just the block +[debug/optimizer] [] statement::Try "try { hilti::debugIndent("spicy"); local iterator __begin = begin(__cur); local strong_ref filtered = Null; if ( ! filtered ) __result = (*self).__parse_foo__C_stage2(__data, __begin, __cur, __trim, __lah, __lahe, __error); } catch ( hilti::SystemException __except ) { throw; }" -> statement::Block "{ hilti::debugIndent("spicy"); local iterator __begin = begin(__cur); local strong_ref filtered = Null; if ( ! filtered ) __result = (*self).__parse_foo__C_stage2(__data, __begin, __cur, __trim, __lah, __lahe, __error); }" +[debug/optimizer] [] statement::Try "try { hilti::debugIndent("spicy"); local iterator __begin = begin(__cur); local strong_ref filtered = Null; if ( ! filtered ) __result = (*self).__parse_foo__D_stage2(__data, __begin, __cur, __trim, __lah, __lahe, __error); } catch ( hilti::SystemException __except ) { throw; }" -> replacing rethrowing try/catch with just the block +[debug/optimizer] [] statement::Try "try { hilti::debugIndent("spicy"); local iterator __begin = begin(__cur); local strong_ref filtered = Null; if ( ! filtered ) __result = (*self).__parse_foo__D_stage2(__data, __begin, __cur, __trim, __lah, __lahe, __error); } catch ( hilti::SystemException __except ) { throw; }" -> statement::Block "{ hilti::debugIndent("spicy"); local iterator __begin = begin(__cur); local strong_ref filtered = Null; if ( ! filtered ) __result = (*self).__parse_foo__D_stage2(__data, __begin, __cur, __trim, __lah, __lahe, __error); }" [debug/optimizer] [spicy_rt.hlt:28:5-28:76] declaration::Field "method void connect_mime_type(string mime_type, string scope) &internal;" -> null (removing unused member) [debug/optimizer] [spicy_rt.hlt:29:5-29:75] declaration::Field "method void connect_mime_type(bytes mime_type, string scope) &internal;" -> null (removing unused member) [debug/optimizer] [unused-functions.spicy:10:1-32:2] declaration::Constant "const bool __feat%foo@@A%supports_filters = False;" -> disabled feature 'supports_filters' of type 'foo::A' since it is not used diff --git a/tests/Baseline/spicy.optimization.unused-functions/opt.hlt b/tests/Baseline/spicy.optimization.unused-functions/opt.hlt index 637066b030..bd57a8c21f 100644 --- a/tests/Baseline/spicy.optimization.unused-functions/opt.hlt +++ b/tests/Baseline/spicy.optimization.unused-functions/opt.hlt @@ -79,7 +79,7 @@ init function void __register_foo_A() { method method tuple, int<64>, const iterator, optional> foo::B::__parse_stage1(inout value_ref __data, iterator __begin, copy view __cur, copy bool __trim, copy int<64> __lah, copy iterator __lahe, copy optional __error) { # "<...>/unused-functions.spicy:21:17-21:23" local tuple, int<64>, const iterator, optional> __result; - try { + { hilti::debugIndent("spicy"); local iterator __begin = begin(__cur); local strong_ref filtered = Null; @@ -88,8 +88,6 @@ method method tuple, int<64>, const iterator, optiona __result = (*self).__parse_foo__B_stage2(__data, __begin, __cur, __trim, __lah, __lahe, __error); } - catch ( hilti::SystemException __except ) - throw; return __result; } @@ -167,7 +165,7 @@ init function void __register_foo_B() { method method tuple, int<64>, const iterator, optional> foo::C::__parse_stage1(inout value_ref __data, iterator __begin, copy view __cur, copy bool __trim, copy int<64> __lah, copy iterator __lahe, copy optional __error) { # "<...>/unused-functions.spicy:24:10-24:16" local tuple, int<64>, const iterator, optional> __result; - try { + { hilti::debugIndent("spicy"); local iterator __begin = begin(__cur); local strong_ref filtered = Null; @@ -176,8 +174,6 @@ method method tuple, int<64>, const iterator, optiona __result = (*self).__parse_foo__C_stage2(__data, __begin, __cur, __trim, __lah, __lahe, __error); } - catch ( hilti::SystemException __except ) - throw; return __result; } @@ -196,7 +192,7 @@ init function void __register_foo_C() { method method tuple, int<64>, const iterator, optional> foo::D::__parse_stage1(inout value_ref __data, iterator __begin, copy view __cur, copy bool __trim, copy int<64> __lah, copy iterator __lahe, copy optional __error) { # "<...>/unused-functions.spicy:25:17-27:1" local tuple, int<64>, const iterator, optional> __result; - try { + { hilti::debugIndent("spicy"); local iterator __begin = begin(__cur); local strong_ref filtered = Null; @@ -205,8 +201,6 @@ method method tuple, int<64>, const iterator, optiona __result = (*self).__parse_foo__D_stage2(__data, __begin, __cur, __trim, __lah, __lahe, __error); } - catch ( hilti::SystemException __except ) - throw; return __result; } diff --git a/tests/Baseline/spicy.optimization.unused-types/log b/tests/Baseline/spicy.optimization.unused-types/log index b4e3f2062a..1e58b9a6b8 100644 --- a/tests/Baseline/spicy.optimization.unused-types/log +++ b/tests/Baseline/spicy.optimization.unused-types/log @@ -788,6 +788,16 @@ [debug/optimizer] [] statement::If "if ( False ) { }" -> null [debug/optimizer] [] statement::If "if ( False ) { }" -> null [debug/optimizer] [] statement::If "if ( False ) { }" -> null +[debug/optimizer] [] statement::Try "try { hilti::debugIndent("spicy"); local iterator __begin = begin(__cur); local strong_ref filtered = Null; if ( ! filtered ) __result = (*self).__parse_foo__Priv10_stage2(__data, __begin, __cur, __trim, __lah, __lahe, __error); } catch ( hilti::SystemException __except ) { throw; }" -> replacing rethrowing try/catch with just the block +[debug/optimizer] [] statement::Try "try { hilti::debugIndent("spicy"); local iterator __begin = begin(__cur); local strong_ref filtered = Null; if ( ! filtered ) __result = (*self).__parse_foo__Priv10_stage2(__data, __begin, __cur, __trim, __lah, __lahe, __error); } catch ( hilti::SystemException __except ) { throw; }" -> statement::Block "{ hilti::debugIndent("spicy"); local iterator __begin = begin(__cur); local strong_ref filtered = Null; if ( ! filtered ) __result = (*self).__parse_foo__Priv10_stage2(__data, __begin, __cur, __trim, __lah, __lahe, __error); }" +[debug/optimizer] [] statement::Try "try { hilti::debugIndent("spicy"); local iterator __begin = begin(__cur); local strong_ref filtered = Null; if ( ! filtered ) __result = (*self).__parse_foo__Priv5_stage2(__data, __begin, __cur, __trim, __lah, __lahe, __error); } catch ( hilti::SystemException __except ) { throw; }" -> replacing rethrowing try/catch with just the block +[debug/optimizer] [] statement::Try "try { hilti::debugIndent("spicy"); local iterator __begin = begin(__cur); local strong_ref filtered = Null; if ( ! filtered ) __result = (*self).__parse_foo__Priv5_stage2(__data, __begin, __cur, __trim, __lah, __lahe, __error); } catch ( hilti::SystemException __except ) { throw; }" -> statement::Block "{ hilti::debugIndent("spicy"); local iterator __begin = begin(__cur); local strong_ref filtered = Null; if ( ! filtered ) __result = (*self).__parse_foo__Priv5_stage2(__data, __begin, __cur, __trim, __lah, __lahe, __error); }" +[debug/optimizer] [] statement::Try "try { hilti::debugIndent("spicy"); local iterator __begin = begin(__cur); local strong_ref filtered = Null; if ( ! filtered ) __result = (*self).__parse_foo__Priv6_stage2(__data, __begin, __cur, __trim, __lah, __lahe, __error); } catch ( hilti::SystemException __except ) { throw; }" -> replacing rethrowing try/catch with just the block +[debug/optimizer] [] statement::Try "try { hilti::debugIndent("spicy"); local iterator __begin = begin(__cur); local strong_ref filtered = Null; if ( ! filtered ) __result = (*self).__parse_foo__Priv6_stage2(__data, __begin, __cur, __trim, __lah, __lahe, __error); } catch ( hilti::SystemException __except ) { throw; }" -> statement::Block "{ hilti::debugIndent("spicy"); local iterator __begin = begin(__cur); local strong_ref filtered = Null; if ( ! filtered ) __result = (*self).__parse_foo__Priv6_stage2(__data, __begin, __cur, __trim, __lah, __lahe, __error); }" +[debug/optimizer] [] statement::Try "try { hilti::debugIndent("spicy"); local iterator __begin = begin(__cur); local strong_ref filtered = Null; if ( ! filtered ) __result = (*self).__parse_foo__Pub2_stage2(__data, __begin, __cur, __trim, __lah, __lahe, __error); } catch ( hilti::SystemException __except ) { throw; }" -> replacing rethrowing try/catch with just the block +[debug/optimizer] [] statement::Try "try { hilti::debugIndent("spicy"); local iterator __begin = begin(__cur); local strong_ref filtered = Null; if ( ! filtered ) __result = (*self).__parse_foo__Pub2_stage2(__data, __begin, __cur, __trim, __lah, __lahe, __error); } catch ( hilti::SystemException __except ) { throw; }" -> statement::Block "{ hilti::debugIndent("spicy"); local iterator __begin = begin(__cur); local strong_ref filtered = Null; if ( ! filtered ) __result = (*self).__parse_foo__Pub2_stage2(__data, __begin, __cur, __trim, __lah, __lahe, __error); }" +[debug/optimizer] [] statement::Try "try { hilti::debugIndent("spicy"); local iterator __begin = begin(__cur); local strong_ref filtered = Null; if ( ! filtered ) __result = (*self).__parse_foo__Pub3_stage2(__data, __begin, __cur, __trim, __lah, __lahe, __error); } catch ( hilti::SystemException __except ) { throw; }" -> replacing rethrowing try/catch with just the block +[debug/optimizer] [] statement::Try "try { hilti::debugIndent("spicy"); local iterator __begin = begin(__cur); local strong_ref filtered = Null; if ( ! filtered ) __result = (*self).__parse_foo__Pub3_stage2(__data, __begin, __cur, __trim, __lah, __lahe, __error); } catch ( hilti::SystemException __except ) { throw; }" -> statement::Block "{ hilti::debugIndent("spicy"); local iterator __begin = begin(__cur); local strong_ref filtered = Null; if ( ! filtered ) __result = (*self).__parse_foo__Pub3_stage2(__data, __begin, __cur, __trim, __lah, __lahe, __error); }" [debug/optimizer] [spicy_rt.hlt:28:5-28:76] declaration::Field "method void connect_mime_type(string mime_type, string scope) &internal;" -> null (removing unused member) [debug/optimizer] [spicy_rt.hlt:29:5-29:75] declaration::Field "method void connect_mime_type(bytes mime_type, string scope) &internal;" -> null (removing unused member) [debug/optimizer] [unused-types.spicy:10:1-53:30] declaration::Constant "const bool __feat%foo@@Priv1%supports_filters = False;" -> disabled feature 'supports_filters' of type 'foo::Priv1' since it is not used diff --git a/tests/Baseline/spicy.optimization.unused-types/opt.hlt b/tests/Baseline/spicy.optimization.unused-types/opt.hlt index a95b0314ac..5a2db4ba30 100644 --- a/tests/Baseline/spicy.optimization.unused-types/opt.hlt +++ b/tests/Baseline/spicy.optimization.unused-types/opt.hlt @@ -133,7 +133,7 @@ init function void __register_foo_Priv1() { method method tuple, int<64>, const iterator, optional> foo::Pub2::__parse_stage1(inout value_ref __data, iterator __begin, copy view __cur, copy bool __trim, copy int<64> __lah, copy iterator __lahe, copy optional __error) { # "<...>/unused-types.spicy:16:20-16:26" local tuple, int<64>, const iterator, optional> __result; - try { + { hilti::debugIndent("spicy"); local iterator __begin = begin(__cur); local strong_ref filtered = Null; @@ -142,8 +142,6 @@ method method tuple, int<64>, const iterator, optiona __result = (*self).__parse_foo__Pub2_stage2(__data, __begin, __cur, __trim, __lah, __lahe, __error); } - catch ( hilti::SystemException __except ) - throw; return __result; } @@ -230,7 +228,7 @@ init function void __register_foo_Priv4() { method method tuple, int<64>, const iterator, optional> foo::Priv5::__parse_stage1(inout value_ref __data, iterator __begin, copy view __cur, copy bool __trim, copy int<64> __lah, copy iterator __lahe, copy optional __error) { # "<...>/unused-types.spicy:27:14-27:20" local tuple, int<64>, const iterator, optional> __result; - try { + { hilti::debugIndent("spicy"); local iterator __begin = begin(__cur); local strong_ref filtered = Null; @@ -239,8 +237,6 @@ method method tuple, int<64>, const iterator, optiona __result = (*self).__parse_foo__Priv5_stage2(__data, __begin, __cur, __trim, __lah, __lahe, __error); } - catch ( hilti::SystemException __except ) - throw; return __result; } @@ -259,7 +255,7 @@ init function void __register_foo_Priv5() { method method tuple, int<64>, const iterator, optional> foo::Priv6::__parse_stage1(inout value_ref __data, iterator __begin, copy view __cur, copy bool __trim, copy int<64> __lah, copy iterator __lahe, copy optional __error) { # "<...>/unused-types.spicy:28:14-28:20" local tuple, int<64>, const iterator, optional> __result; - try { + { hilti::debugIndent("spicy"); local iterator __begin = begin(__cur); local strong_ref filtered = Null; @@ -268,8 +264,6 @@ method method tuple, int<64>, const iterator, optiona __result = (*self).__parse_foo__Priv6_stage2(__data, __begin, __cur, __trim, __lah, __lahe, __error); } - catch ( hilti::SystemException __except ) - throw; return __result; } @@ -288,7 +282,7 @@ init function void __register_foo_Priv6() { method method tuple, int<64>, const iterator, optional> foo::Pub3::__parse_stage1(inout value_ref __data, iterator __begin, copy view __cur, copy bool __trim, copy int<64> __lah, copy iterator __lahe, copy optional __error) { # "<...>/unused-types.spicy:29:20-32:1" local tuple, int<64>, const iterator, optional> __result; - try { + { hilti::debugIndent("spicy"); local iterator __begin = begin(__cur); local strong_ref filtered = Null; @@ -297,8 +291,6 @@ method method tuple, int<64>, const iterator, optiona __result = (*self).__parse_foo__Pub3_stage2(__data, __begin, __cur, __trim, __lah, __lahe, __error); } - catch ( hilti::SystemException __except ) - throw; return __result; } @@ -391,7 +383,7 @@ init function void __register_foo_Pub3() { method method tuple, int<64>, const iterator, optional> foo::Priv10::__parse_stage1(inout value_ref __data, iterator __begin, copy view __cur, copy bool __trim, copy int<64> __lah, copy iterator __lahe, copy optional __error) { # "<...>/unused-types.spicy:43:22-46:1" local tuple, int<64>, const iterator, optional> __result; - try { + { hilti::debugIndent("spicy"); local iterator __begin = begin(__cur); local strong_ref filtered = Null; @@ -400,8 +392,6 @@ method method tuple, int<64>, const iterator, optiona __result = (*self).__parse_foo__Priv10_stage2(__data, __begin, __cur, __trim, __lah, __lahe, __error); } - catch ( hilti::SystemException __except ) - throw; return __result; } diff --git a/tests/Baseline/spicy.rt.debug-trace/.stderr b/tests/Baseline/spicy.rt.debug-trace/.stderr index 931d64939c..c0d0c62899 100644 --- a/tests/Baseline/spicy.rt.debug-trace/.stderr +++ b/tests/Baseline/spicy.rt.debug-trace/.stderr @@ -16,7 +16,6 @@ [hilti-trace] : (__ncur, __lahead, __lahead_end, __error) = (*__unit).__parse_stage1(__data, begin(__ncur), __ncur, True, __lahead, __lahead_end, __error); [hilti-trace] : # "<...>/debug-trace.spicy:8:20-13:1" [hilti-trace] : local tuple, int<64>, const iterator, optional> __result; -[hilti-trace] : try { hilti::debug("spicy", "Mini::Test"); hilti::debugIndent("spicy"); local iterator __begin = begin(__cur); (*self).__error = __error; (*self).__on_0x25_init(); __error = (*self).__error; local strong_ref filtered = Null; if ( ! filtered ) __result = (*self).__parse_Mini__Test_stage2(__data, __begin, __cur, __trim, __lah, __lahe, __error); } catch ( hilti::SystemException __except ) { throw; } [hilti-trace] : hilti::debug("spicy", "Mini::Test"); [hilti-trace] : hilti::debugIndent("spicy"); [hilti-trace] : local iterator __begin = begin(__cur); diff --git a/tests/Baseline/spicy.types.unit.canonical-ids-with-import/output b/tests/Baseline/spicy.types.unit.canonical-ids-with-import/output index 00234494af..b51599e8b6 100644 --- a/tests/Baseline/spicy.types.unit.canonical-ids-with-import/output +++ b/tests/Baseline/spicy.types.unit.canonical-ids-with-import/output @@ -929,11 +929,11 @@ [debug/ast-declarations] - ImportedModule "hilti" (spicy::hilti) [debug/ast-declarations] - ImportedModule "spicy_rt" (spicy::spicy_rt) [debug/ast-declarations] Declaration dependencies: -[debug/ast-declarations] - [module] a -> a::X, a::__feat%a@@X%is_filter, a::__feat%a@@X%supports_filters, a::__feat%a@@X%supports_sinks, a::__feat%a@@X%synchronization, a::__feat%a@@X%uses_offset, a::__feat%a@@X%uses_random_access, a::__feat%a@@X%uses_stream, a::__feat%a@@X%uses_sync_advance, a::__register_a_X, a::a::X::__parse_a__X_stage2, a::a::X::__parse_stage1, a::a::X::parse1, a::a::X::parse2, a::a::X::parse3, hilti::ByteOrder, hilti::Exception, hilti::RecoverableFailure, hilti::SystemException, hilti::debugDedent, hilti::debugIndent, hilti::exception_what_2, hilti::exception_where_2, spicy_rt::Filters, spicy_rt::MIMEType, spicy_rt::ParseError, spicy_rt::ParsedUnit, spicy_rt::Parser, spicy_rt::ParserPort, spicy_rt::TypeInfo, spicy_rt::UnitContext, spicy_rt::initializeParsedUnit, spicy_rt::registerParser, spicy_rt::waitForInput_2 +[debug/ast-declarations] - [module] a -> a::X, a::__feat%a@@X%is_filter, a::__feat%a@@X%supports_filters, a::__feat%a@@X%supports_sinks, a::__feat%a@@X%synchronization, a::__feat%a@@X%uses_offset, a::__feat%a@@X%uses_random_access, a::__feat%a@@X%uses_stream, a::__feat%a@@X%uses_sync_advance, a::__register_a_X, a::a::X::__parse_a__X_stage2, a::a::X::__parse_stage1, a::a::X::parse1, a::a::X::parse2, a::a::X::parse3, hilti::ByteOrder, hilti::Exception, hilti::RecoverableFailure, hilti::debugDedent, hilti::debugIndent, hilti::exception_what_2, hilti::exception_where_2, spicy_rt::Filters, spicy_rt::MIMEType, spicy_rt::ParseError, spicy_rt::ParsedUnit, spicy_rt::Parser, spicy_rt::ParserPort, spicy_rt::TypeInfo, spicy_rt::UnitContext, spicy_rt::initializeParsedUnit, spicy_rt::registerParser, spicy_rt::waitForInput_2 [debug/ast-declarations] - [type] a::X -> a::X, hilti::Exception, hilti::RecoverableFailure, spicy_rt::MIMEType, spicy_rt::ParsedUnit, spicy_rt::Parser, spicy_rt::ParserPort, spicy_rt::TypeInfo, spicy_rt::UnitContext [debug/ast-declarations] - [function] a::__register_a_X -> a::X, hilti::Exception, hilti::RecoverableFailure, spicy_rt::MIMEType, spicy_rt::ParsedUnit, spicy_rt::Parser, spicy_rt::ParserPort, spicy_rt::TypeInfo, spicy_rt::UnitContext, spicy_rt::registerParser [debug/ast-declarations] - [function] a::a::X::__parse_a__X_stage2 -> a::X, hilti::ByteOrder, hilti::Exception, hilti::RecoverableFailure, hilti::debugDedent, spicy_rt::Filters, spicy_rt::MIMEType, spicy_rt::ParsedUnit, spicy_rt::Parser, spicy_rt::ParserPort, spicy_rt::TypeInfo, spicy_rt::UnitContext, spicy_rt::waitForInput_2 -[debug/ast-declarations] - [function] a::a::X::__parse_stage1 -> a::X, hilti::Exception, hilti::RecoverableFailure, hilti::SystemException, hilti::debugIndent, spicy_rt::MIMEType, spicy_rt::ParsedUnit, spicy_rt::Parser, spicy_rt::ParserPort, spicy_rt::TypeInfo, spicy_rt::UnitContext +[debug/ast-declarations] - [function] a::a::X::__parse_stage1 -> a::X, hilti::Exception, hilti::RecoverableFailure, hilti::debugIndent, spicy_rt::MIMEType, spicy_rt::ParsedUnit, spicy_rt::Parser, spicy_rt::ParserPort, spicy_rt::TypeInfo, spicy_rt::UnitContext [debug/ast-declarations] - [function] a::a::X::parse1 -> a::X, hilti::Exception, hilti::RecoverableFailure, hilti::exception_what_2, hilti::exception_where_2, spicy_rt::MIMEType, spicy_rt::ParseError, spicy_rt::ParsedUnit, spicy_rt::Parser, spicy_rt::ParserPort, spicy_rt::TypeInfo, spicy_rt::UnitContext [debug/ast-declarations] - [function] a::a::X::parse2 -> a::X, hilti::Exception, hilti::RecoverableFailure, hilti::exception_what_2, hilti::exception_where_2, spicy_rt::MIMEType, spicy_rt::ParseError, spicy_rt::ParsedUnit, spicy_rt::Parser, spicy_rt::ParserPort, spicy_rt::TypeInfo, spicy_rt::UnitContext [debug/ast-declarations] - [function] a::a::X::parse3 -> a::X, hilti::Exception, hilti::RecoverableFailure, hilti::exception_what_2, hilti::exception_where_2, spicy_rt::MIMEType, spicy_rt::ParseError, spicy_rt::ParsedUnit, spicy_rt::Parser, spicy_rt::ParserPort, spicy_rt::TypeInfo, spicy_rt::UnitContext, spicy_rt::initializeParsedUnit diff --git a/tests/Baseline/spicy.types.unit.canonical-ids/output b/tests/Baseline/spicy.types.unit.canonical-ids/output index 07adc814bc..40209046f5 100644 --- a/tests/Baseline/spicy.types.unit.canonical-ids/output +++ b/tests/Baseline/spicy.types.unit.canonical-ids/output @@ -1073,11 +1073,11 @@ [debug/ast-declarations] - ImportedModule "hilti" (spicy::hilti) [debug/ast-declarations] - ImportedModule "spicy_rt" (spicy::spicy_rt) [debug/ast-declarations] Declaration dependencies: -[debug/ast-declarations] - [module] DNS -> DNS::DNS::Label::__parse_DNS__Label_stage2, DNS::DNS::Label::__parse_stage1, DNS::DNS::Pointer::__parse_DNS__Pointer_2_stage2, DNS::DNS::Pointer::__parse_stage1, DNS::Label, DNS::Pointer, DNS::__feat%DNS@@Label%is_filter, DNS::__feat%DNS@@Label%supports_filters, DNS::__feat%DNS@@Label%supports_sinks, DNS::__feat%DNS@@Label%synchronization, DNS::__feat%DNS@@Label%uses_offset, DNS::__feat%DNS@@Label%uses_random_access, DNS::__feat%DNS@@Label%uses_stream, DNS::__feat%DNS@@Label%uses_sync_advance, DNS::__feat%DNS@@Pointer%is_filter, DNS::__feat%DNS@@Pointer%supports_filters, DNS::__feat%DNS@@Pointer%supports_sinks, DNS::__feat%DNS@@Pointer%synchronization, DNS::__feat%DNS@@Pointer%uses_offset, DNS::__feat%DNS@@Pointer%uses_random_access, DNS::__feat%DNS@@Pointer%uses_stream, DNS::__feat%DNS@@Pointer%uses_sync_advance, DNS::__register_DNS_Label, DNS::__register_DNS_Pointer, hilti::Exception, hilti::RecoverableFailure, hilti::SystemException, hilti::debugDedent, hilti::debugIndent +[debug/ast-declarations] - [module] DNS -> DNS::DNS::Label::__parse_DNS__Label_stage2, DNS::DNS::Label::__parse_stage1, DNS::DNS::Pointer::__parse_DNS__Pointer_2_stage2, DNS::DNS::Pointer::__parse_stage1, DNS::Label, DNS::Pointer, DNS::__feat%DNS@@Label%is_filter, DNS::__feat%DNS@@Label%supports_filters, DNS::__feat%DNS@@Label%supports_sinks, DNS::__feat%DNS@@Label%synchronization, DNS::__feat%DNS@@Label%uses_offset, DNS::__feat%DNS@@Label%uses_random_access, DNS::__feat%DNS@@Label%uses_stream, DNS::__feat%DNS@@Label%uses_sync_advance, DNS::__feat%DNS@@Pointer%is_filter, DNS::__feat%DNS@@Pointer%supports_filters, DNS::__feat%DNS@@Pointer%supports_sinks, DNS::__feat%DNS@@Pointer%synchronization, DNS::__feat%DNS@@Pointer%uses_offset, DNS::__feat%DNS@@Pointer%uses_random_access, DNS::__feat%DNS@@Pointer%uses_stream, DNS::__feat%DNS@@Pointer%uses_sync_advance, DNS::__register_DNS_Label, DNS::__register_DNS_Pointer, hilti::Exception, hilti::RecoverableFailure, hilti::debugDedent, hilti::debugIndent [debug/ast-declarations] - [function] DNS::DNS::Label::__parse_DNS__Label_stage2 -> DNS::Label, DNS::Pointer, hilti::Exception, hilti::RecoverableFailure, hilti::debugDedent -[debug/ast-declarations] - [function] DNS::DNS::Label::__parse_stage1 -> DNS::Label, DNS::Pointer, hilti::Exception, hilti::RecoverableFailure, hilti::SystemException, hilti::debugIndent +[debug/ast-declarations] - [function] DNS::DNS::Label::__parse_stage1 -> DNS::Label, DNS::Pointer, hilti::Exception, hilti::RecoverableFailure, hilti::debugIndent [debug/ast-declarations] - [function] DNS::DNS::Pointer::__parse_DNS__Pointer_2_stage2 -> DNS::Label, DNS::Pointer, hilti::Exception, hilti::RecoverableFailure, hilti::debugDedent -[debug/ast-declarations] - [function] DNS::DNS::Pointer::__parse_stage1 -> DNS::Label, DNS::Pointer, hilti::Exception, hilti::RecoverableFailure, hilti::SystemException, hilti::debugIndent +[debug/ast-declarations] - [function] DNS::DNS::Pointer::__parse_stage1 -> DNS::Label, DNS::Pointer, hilti::Exception, hilti::RecoverableFailure, hilti::debugIndent [debug/ast-declarations] - [type] DNS::Label -> DNS::Label, DNS::Pointer, hilti::Exception, hilti::RecoverableFailure [debug/ast-declarations] - [type] DNS::Pointer -> DNS::Label, DNS::Pointer, hilti::Exception, hilti::RecoverableFailure [debug/ast-declarations] - [module] hilti -> hilti::AddressFamily, hilti::BitOrder, hilti::ByteOrder, hilti::Captures, hilti::Charset, hilti::DecodeErrorStrategy, hilti::Exception, hilti::MatchState, hilti::MissingData, hilti::Profiler, hilti::Protocol, hilti::RealType, hilti::RecoverableFailure, hilti::RuntimeError, hilti::Side, hilti::StreamStatistics, hilti::SystemException, hilti::abort, hilti::current_time, hilti::debug, hilti::debugDedent, hilti::debugIndent, hilti::exception_what, hilti::exception_what_2, hilti::exception_where, hilti::exception_where_2, hilti::mktime, hilti::print, hilti::printValues, hilti::profiler_start, hilti::profiler_stop diff --git a/tests/hilti/optimization/peephole-try-catch.hlt b/tests/hilti/optimization/peephole-try-catch.hlt new file mode 100644 index 0000000000..572977d9e8 --- /dev/null +++ b/tests/hilti/optimization/peephole-try-catch.hlt @@ -0,0 +1,16 @@ +# @TEST-EXEC: hiltic -p %INPUT >opt.hlt +# @TEST-EXEC: btest-diff opt.hlt +# +# @TEST-DOC: Test that catch-blocks that just rethrow get removed. + +module Test { + +public function void foo() { + try { + assert True; + } catch { + throw; + } +} + +}