From f46e1df061c3db84769333f936740a64535c76c1 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sun, 17 Mar 2019 19:23:44 -0700 Subject: [PATCH 1/3] Document `type_length_limit`. --- src/attributes.md | 2 ++ src/attributes/limits.md | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/attributes.md b/src/attributes.md index 313320815..7ca9098a9 100644 --- a/src/attributes.md +++ b/src/attributes.md @@ -227,6 +227,7 @@ The following is an index of all built-in attributes. - Limits - [`recursion_limit`] — Sets the maximum recursion limit for certain compile-time operations. + - [`type_length_limit`] — Sets the maximum size of a polymorphic type. - Runtime - [`panic_handler`] — Sets the function to handle panics. - [`global_allocator`] — Sets the global memory allocator. @@ -283,6 +284,7 @@ The following is an index of all built-in attributes. [`repr`]: type-layout.html#representations [`should_panic`]: attributes/testing.html#the-should_panic-attribute [`test`]: attributes/testing.html#the-test-attribute +[`type_length_limit`]: attributes/limits.html#the-type_length_limit-attribute [`used`]: abi.html#the-used-attribute [`warn`]: attributes/diagnostics.html#lint-check-attributes [`windows_subsystem`]: runtime.html#the-windows_subsystem-attribute diff --git a/src/attributes/limits.md b/src/attributes/limits.md index bc11e42d7..b57f6d9ca 100644 --- a/src/attributes/limits.md +++ b/src/attributes/limits.md @@ -7,8 +7,42 @@ The following [attributes] affect compile-time limits. The *`recursion_limit` attribute* may be applied at the crate level to set the maximum depth for potentially infinitely-recursive compile-time operations like auto-dereference or macro expansion. It uses the [_MetaNameValueStr_] -syntax to specify the recursion depth. The default is -`#![recursion_limit="64"]`. +syntax to specify the recursion depth. The default is 64. + +```rust,ignore +#![recursion_limit = "4"] + +macro_rules! a { + () => { a!(1) }; + (1) => { a!(2) }; + (2) => { a!(3) }; + (3) => { a!(4) }; + (4) => { }; +} + +// This fails to expand because it requires a recursion depth greater than 4. +a!{} +``` + +## The `type_length_limit` attribute + +The *`type_length_limit` attribute* limits the maximum size of a type +constructed during monomorphization. It is applied at the crate level, and +uses the [_MetaNameValueStr_] syntax to set the limit based on the number of +type substitutions within the type. The default value is 1048576. + +```rust,ignore +#![type_length_limit = "8"] + +type A = (B, B, B); +type B = (C, C, C); +struct C; + +// This fails to compile because monomorphizing to +// `drop::>` requires more than 8 +// type elements. +drop::>(None); +``` [attributes]: attributes.html [_MetaNameValueStr_]: attributes.html#meta-item-attribute-syntax From 2c210e15efb3c4ceb77ef583697237418fe6d80d Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 18 Mar 2019 11:45:16 -0700 Subject: [PATCH 2/3] Update for review comments. --- src/attributes/limits.md | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/attributes/limits.md b/src/attributes/limits.md index b57f6d9ca..d5574ad01 100644 --- a/src/attributes/limits.md +++ b/src/attributes/limits.md @@ -4,10 +4,12 @@ The following [attributes] affect compile-time limits. ## The `recursion_limit` attribute -The *`recursion_limit` attribute* may be applied at the crate level to set the +The *`recursion_limit` attribute* may be applied at the [crate] level to set the maximum depth for potentially infinitely-recursive compile-time operations like auto-dereference or macro expansion. It uses the [_MetaNameValueStr_] -syntax to specify the recursion depth. The default is 64. +syntax to specify the recursion depth. + +> Note: The default in `rustc` is 64. ```rust,ignore #![recursion_limit = "4"] @@ -26,10 +28,12 @@ a!{} ## The `type_length_limit` attribute -The *`type_length_limit` attribute* limits the maximum size of a type -constructed during monomorphization. It is applied at the crate level, and -uses the [_MetaNameValueStr_] syntax to set the limit based on the number of -type substitutions within the type. The default value is 1048576. +The *`type_length_limit` attribute* limits the maximum number of type +substitutions made when constructing a concrete type during monomorphization. +It is applied at the [crate] level, and uses the [_MetaNameValueStr_] syntax +to set the limit based on the number of type substitutions. + +> Note: The default in `rustc` is 1048576. ```rust,ignore #![type_length_limit = "8"] @@ -44,5 +48,6 @@ struct C; drop::>(None); ``` -[attributes]: attributes.html [_MetaNameValueStr_]: attributes.html#meta-item-attribute-syntax +[attributes]: attributes.html +[crate]: crates-and-source-files.html From 17060fdb3ea0e54cef4910e6de5d0ad70e79f6b6 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 19 Mar 2019 09:36:42 -0700 Subject: [PATCH 3/3] Update for review comments. --- src/attributes/limits.md | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/attributes/limits.md b/src/attributes/limits.md index d5574ad01..1ff5b8883 100644 --- a/src/attributes/limits.md +++ b/src/attributes/limits.md @@ -6,12 +6,12 @@ The following [attributes] affect compile-time limits. The *`recursion_limit` attribute* may be applied at the [crate] level to set the maximum depth for potentially infinitely-recursive compile-time operations -like auto-dereference or macro expansion. It uses the [_MetaNameValueStr_] +like macro expansion or auto-dereference. It uses the [_MetaNameValueStr_] syntax to specify the recursion depth. > Note: The default in `rustc` is 64. -```rust,ignore +```rust,compile_fail #![recursion_limit = "4"] macro_rules! a { @@ -26,6 +26,13 @@ macro_rules! a { a!{} ``` +```rust,compile_fail +#![recursion_limit = "1"] + +// This fails because it requires two recursive steps to auto-derefence. +(|_: &u8| {})(&&1); +``` + ## The `type_length_limit` attribute The *`type_length_limit` attribute* limits the maximum number of type @@ -35,17 +42,15 @@ to set the limit based on the number of type substitutions. > Note: The default in `rustc` is 1048576. -```rust,ignore +```rust,compile_fail #![type_length_limit = "8"] -type A = (B, B, B); -type B = (C, C, C); -struct C; +fn f(x: T) {} // This fails to compile because monomorphizing to -// `drop::>` requires more than 8 -// type elements. -drop::>(None); +// `f::<(i32, i32, i32, i32, i32, i32, i32, i32, i32)>>` requires more +// than 8 type elements. +f(((1, 2, 3, 4, 5, 6, 7, 8, 9)); ``` [_MetaNameValueStr_]: attributes.html#meta-item-attribute-syntax