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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use const generics for array impls [part 1] #62435

Merged
merged 1 commit into from Jul 7, 2019

Conversation

@scottmcm
Copy link
Member

commented Jul 6, 2019

Part 1 of #61415, following the plan in #61415 (comment)

Found a way that works 馃檭

@rust-highfive

This comment was marked as resolved.

Copy link
Collaborator

commented Jul 6, 2019

r? @withoutboats

(rust_highfive has picked a reviewer for you, use r? to override)

@@ -264,6 +267,269 @@ macro_rules! array_impls {
}
}

#[cfg(not(bootstrap))]
mod impls_using_const_generics {

This comment has been minimized.

Copy link
@scottmcm

scottmcm Jul 6, 2019

Author Member

These are separate because I don't want to rely on the bootstrap compiler's const generics.

@scottmcm

This comment has been minimized.

Copy link
Member Author

commented Jul 6, 2019

r? @varkor

@rust-highfive rust-highfive assigned varkor and unassigned withoutboats Jul 6, 2019

@scottmcm scottmcm added the S-blocked label Jul 6, 2019

@scottmcm

This comment was marked as outdated.

Copy link
Member Author

commented Jul 6, 2019

Current problem:

thread 'rustc' panicked at 'Box<Any>', src\librustc_errors\lib.rs:649:9
stack backtrace:
   0: backtrace::backtrace::trace_unsynchronized
   1: std::sys_common::backtrace::print
   2: std::panicking::take_hook
   3: std::panicking::take_hook
   4: <rustc::ty::sty::Binder<rustc::ty::ProjectionPredicate> as rustc::ty::ToPredicate>::to_predicate
   5: std::panicking::rust_panic_with_hook
   6: std::io::buffered::BufWriter<W>::flush_buf
   7: rustc_errors::Handler::bug
   8: rustc::util::bug::span_bug_fmt
   9: rustc::ty::context::tls::with_opt::{{closure}}
  10: rustc::ty::context::TyCtxt::encode_metadata
  11: rustc::ty::context::tls::with_context::{{closure}}
  12: rustc::util::bug::span_bug_fmt
  13: rustc::util::bug::bug_fmt
  14: rustc_metadata::decoder::<impl rustc_metadata::cstore::CrateMetadata>::entry
  15: rustc_metadata::decoder::<impl rustc_metadata::cstore::CrateMetadata>::get_type
  16: rustc_metadata::cstore_impl::provide_extern
  17: rustc::ty::query::on_disk_cache::__ty_decoder_impl::<impl serialize::serialize::Decoder for rustc::ty::query::on_disk_cache::CacheDecoder>::read_str
  18: rustc::dep_graph::graph::DepGraph::with_task_impl
  19: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  20: rustc::ty::instance::Instance::resolve
  21: <rustc::traits::project::AssocTypeNormalizer as rustc::ty::fold::TypeFolder>::fold_const
  22: <smallvec::SmallVec<A> as core::iter::traits::collect::FromIterator<<A as smallvec::Array>::Item>>::from_iter
  23: rustc::ty::fold::TypeFoldable::fold_with
  24: rustc::traits::project::normalize_with_depth
  25: rustc::traits::select::SelectionContext::match_impl
  26: rustc::traits::object_safety::<impl rustc::ty::context::TyCtxt>::contains_illegal_self_type_reference
  27: rustc::ty::trait_def::<impl rustc::ty::context::TyCtxt>::for_each_relevant_impl
  28: rustc::traits::select::SelectionContext::match_projection
  29: rustc::traits::select::SelectionContext::candidate_from_obligation_no_cache
  30: rustc::traits::select::SelectionContext::candidate_from_obligation_no_cache
  31: rustc::dep_graph::graph::DepGraph::with_anon_task
  32: rustc::traits::select::SelectionContext::coinductive_predicate
  33: rustc::traits::select::SelectionContext::evaluate_stack
  34: rustc::dep_graph::graph::DepGraph::with_anon_task
  35: rustc::traits::select::SelectionContext::evaluate_predicate_recursively
  36: rustc::traits::select::SelectionContext::evaluate_predicates_recursively
  37: rustc::infer::InferCtxt::probe
  38: <alloc::vec::IntoIter<T> as core::ops::drop::Drop>::drop
  39: rustc::traits::select::SelectionContext::candidate_from_obligation_no_cache
  40: rustc::dep_graph::graph::DepGraph::with_anon_task
  41: rustc::traits::select::SelectionContext::coinductive_predicate
  42: rustc::traits::select::SelectionContext::evaluate_stack
  43: rustc::dep_graph::graph::DepGraph::with_anon_task
  44: rustc::traits::select::SelectionContext::evaluate_predicate_recursively
  45: rustc::traits::select::SelectionContext::evaluate_predicates_recursively
  46: rustc::infer::InferCtxt::probe
  47: <alloc::vec::IntoIter<T> as core::ops::drop::Drop>::drop
  48: rustc::traits::select::SelectionContext::candidate_from_obligation_no_cache
  49: rustc::dep_graph::graph::DepGraph::with_anon_task
  50: rustc::traits::select::SelectionContext::coinductive_predicate
  51: rustc::traits::select::SelectionContext::evaluate_stack
  52: rustc::dep_graph::graph::DepGraph::with_anon_task
  53: rustc::traits::select::SelectionContext::evaluate_predicate_recursively
  54: rustc::infer::InferCtxt::probe
  55: rustc::traits::select::SelectionContext::evaluate_root_obligation
  56: rustc_traits::evaluate_obligation::evaluate_obligation
  57: rustc::ty::query::__query_compute::evaluate_obligation
  58: rustc::ty::query::on_disk_cache::__ty_decoder_impl::<impl serialize::serialize::Decoder for rustc::ty::query::on_disk_cache::CacheDecoder>::read_str
  59: rustc::dep_graph::graph::DepGraph::with_task_impl
  60: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  61: rustc::traits::query::evaluate_obligation::<impl rustc::infer::InferCtxt>::evaluate_obligation
  62: rustc::traits::query::evaluate_obligation::<impl rustc::infer::InferCtxt>::evaluate_obligation_no_overflow
  63: rustc::traits::query::evaluate_obligation::<impl rustc::infer::InferCtxt>::predicate_may_hold
  64: rustc_typeck::check::method::<impl rustc_typeck::check::FnCtxt>::lookup_method_in_trait
  65: rustc_typeck::check::op::<impl rustc_typeck::check::FnCtxt>::check_user_unop
  66: rustc_typeck::check::op::<impl rustc_typeck::check::FnCtxt>::check_binop
  67: rustc_typeck::check::op::<impl rustc_typeck::check::FnCtxt>::check_binop
  68: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  69: rustc_typeck::check::op::<impl rustc_typeck::check::FnCtxt>::check_binop
  70: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  71: rustc_typeck::check::FnCtxt::check_block_no_value
  72: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  73: rustc_typeck::check::_match::<impl rustc_typeck::check::FnCtxt>::check_match
  74: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  75: rustc_typeck::check::FnCtxt::check_block_no_value
  76: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  77: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  78: rustc_typeck::check::check_fn
  79: rustc::infer::InferCtxtBuilder::enter
  80: rustc_typeck::check::typeck_tables_of
  81: rustc::ty::fold::<impl rustc::ty::context::TyCtxt>::anonymize_late_bound_regions
  82: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  83: rustc::ty::<impl rustc::ty::context::TyCtxt>::par_body_owners
  84: rustc_typeck::check::typeck_item_bodies
  85: rustc::ty::fold::<impl rustc::ty::context::TyCtxt>::anonymize_late_bound_regions
  86: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  87: rustc_typeck::check_crate
  88: rustc_interface::passes::analysis
  89: alloc::slice::merge_sort
  90: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  91: env_logger::init_from_env
  92: rustc_interface::passes::lower_to_hir::{{closure}}
  93: rustc_interface::interface::run_compiler_in_existing_thread_pool
  94: std::thread::local::LocalKey<T>::with
  95: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
query stack during panic:
thread 'rustc' panicked at 'Box<Any>', src\librustc_errors\lib.rs:649:9
stack backtrace:
   0:      0x7fed652c909 - backtrace::backtrace::trace_unsynchronized::hc2b4972ce642e7fe
   1:      0x7fed65247a1 - std::sys_common::backtrace::print::hba526b61977e2223
   2:      0x7fed6535d1c - std::panicking::take_hook::h6d0ee51fc94ebbd4
   3:      0x7fed65359bd - std::panicking::take_hook::h6d0ee51fc94ebbd4
   4:      0x7fed3e638de - <rustc::ty::sty::Binder<rustc::ty::ProjectionPredicate> as rustc::ty::ToPredicate>::to_predicate::h5b2689191e79fa73
   5:      0x7fed6536572 - std::panicking::rust_panic_with_hook::h862a758d47ebc191
   6:      0x7feeb36d514 - std::io::buffered::BufWriter<W>::flush_buf::hd1be867c39240e62
   7:      0x7feeb37e03d - rustc_errors::Handler::bug::hdb28144644066777
   8:      0x7fed4424801 - rustc::util::bug::span_bug_fmt::h8aedd1203896ec64
   9:      0x7fed44117e6 - rustc::ty::context::tls::with_opt::{{closure}}::h6d26eb9168b6b9b5
  10:      0x7fed440667e - rustc::ty::context::TyCtxt::encode_metadata::h1ede840ac64af31d
  11:      0x7fed4410ffa - rustc::ty::context::tls::with_context::{{closure}}::h0ace010b40183159
  12:      0x7fed442470f - rustc::util::bug::span_bug_fmt::h8aedd1203896ec64
  13:      0x7fed442466d - rustc::util::bug::bug_fmt::h4a1b1655d756f408
  14:      0x7fed3a1ab4b - rustc_metadata::decoder::<impl rustc_metadata::cstore::CrateMetadata>::entry::h4c420f9ddf3c045a
  15:      0x7fed3a1ad47 - rustc_metadata::decoder::<impl rustc_metadata::cstore::CrateMetadata>::def_kind::hcf2ffc0f2ba0adf3
  16:      0x7fed3a2bb27 - rustc_metadata::cstore_impl::provide_extern::hd96e7e400536b80a
  17:      0x7fed443a0cc - rustc::ty::query::on_disk_cache::__ty_decoder_impl::<impl serialize::serialize::Decoder for rustc::ty::query::on_disk_cache::CacheDecoder>::read_str::had5f64a164851791
  18:      0x7fed3f36092 - rustc::dep_graph::graph::DepGraph::with_task_impl::h286bce8e830096a2
  19:      0x7fed429ea73 - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query::h9dcbed4f958e5e23
  20:      0x7fed4009fe7 - <rustc::ty::print::pretty::FmtPrinter<F> as rustc::ty::print::Printer>::print_const::h7be1190548b3c34a
  21:      0x7fed4011d7e - rustc::ty::print::Printer::default_print_def_path::h079b2044023798a0
  22:      0x7fed400363d - <rustc::ty::print::pretty::FmtPrinter<F> as rustc::ty::print::Printer>::print_def_path::h2909686884571440
  23:      0x7fed400bb89 - <rustc::ty::print::pretty::FmtPrinter<F> as rustc::ty::print::Printer>::print_const::h7be1190548b3c34a
  24:      0x7fed401141a - rustc::ty::print::Printer::default_print_def_path::h079b2044023798a0
  25:      0x7fed400363d - <rustc::ty::print::pretty::FmtPrinter<F> as rustc::ty::print::Printer>::print_def_path::h2909686884571440
  26:      0x7fed4011085 - rustc::ty::print::Printer::default_print_def_path::h079b2044023798a0
  27:      0x7fed400363d - <rustc::ty::print::pretty::FmtPrinter<F> as rustc::ty::print::Printer>::print_def_path::h2909686884571440
  28:      0x7fed41cbcc8 - rustc::ty::print::pretty::<impl rustc::ty::context::TyCtxt>::def_path_str::h67b039cf94e16052
  29:      0x7fed3e9e261 - rustc::ty::query::Query::describe::h59069403c7ef4446
  30:      0x7fed41d0e5a - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::try_print_query_stack::he8d291ed46625428
  31:      0x7fed3e6394e - <rustc::ty::sty::Binder<rustc::ty::ProjectionPredicate> as rustc::ty::ToPredicate>::to_predicate::h5b2689191e79fa73
  32:      0x7fed6536572 - std::panicking::rust_panic_with_hook::h862a758d47ebc191
  33:      0x7feeb36d514 - std::io::buffered::BufWriter<W>::flush_buf::hd1be867c39240e62
  34:      0x7feeb37e03d - rustc_errors::Handler::bug::hdb28144644066777
  35:      0x7fed4424801 - rustc::util::bug::span_bug_fmt::h8aedd1203896ec64
  36:      0x7fed44117e6 - rustc::ty::context::tls::with_opt::{{closure}}::h6d26eb9168b6b9b5
  37:      0x7fed440667e - rustc::ty::context::TyCtxt::encode_metadata::h1ede840ac64af31d
  38:      0x7fed4410ffa - rustc::ty::context::tls::with_context::{{closure}}::h0ace010b40183159
  39:      0x7fed442470f - rustc::util::bug::span_bug_fmt::h8aedd1203896ec64
  40:      0x7fed442466d - rustc::util::bug::bug_fmt::h4a1b1655d756f408
  41:      0x7fed3a1ab4b - rustc_metadata::decoder::<impl rustc_metadata::cstore::CrateMetadata>::entry::h4c420f9ddf3c045a
  42:      0x7fed3a1c22d - rustc_metadata::decoder::<impl rustc_metadata::cstore::CrateMetadata>::get_type::hd28542e6c6f75b76
  43:      0x7fed3a26f8d - rustc_metadata::cstore_impl::provide_extern::hd96e7e400536b80a
  44:      0x7fed443954c - rustc::ty::query::on_disk_cache::__ty_decoder_impl::<impl serialize::serialize::Decoder for rustc::ty::query::on_disk_cache::CacheDecoder>::read_str::had5f64a164851791
  45:      0x7fed3f5f7e6 - rustc::dep_graph::graph::DepGraph::with_task_impl::hd4a18fb0e0ba478e
  46:      0x7fed42b8e63 - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query::hbcd1616f31b94c00
  47:      0x7fed4023cf9 - rustc::ty::instance::Instance::resolve::h7721cb5b61a618e6
  48:      0x7fed3d1dc21 - <rustc::traits::project::AssocTypeNormalizer as rustc::ty::fold::TypeFolder>::fold_const::h70cc1cd1f66dc9ea
  49:      0x7fed3ebfd82 - <smallvec::SmallVec<A> as core::iter::traits::collect::FromIterator<<A as smallvec::Array>::Item>>::from_iter::h76bea04cfbe999cb
  50:      0x7fed41bcd29 - rustc::ty::fold::TypeFoldable::fold_with::h533ed27275e8cf45
  51:      0x7fed3d1d546 - rustc::traits::project::normalize_with_depth::had388a52f84bf0dd
  52:      0x7fed3e3d6e4 - rustc::traits::select::SelectionContext::match_impl::hae01edf6571567a5
  53:      0x7fed41b20c5 - rustc::traits::object_safety::<impl rustc::ty::context::TyCtxt>::contains_illegal_self_type_reference::h52361ba093cc8db4
  54:      0x7fed43f4e7e - rustc::ty::trait_def::<impl rustc::ty::context::TyCtxt>::for_each_relevant_impl::hd737eed25188af89
  55:      0x7fed3e34d88 - rustc::traits::select::SelectionContext::match_projection::h64f2f9e89dfb329b
  56:      0x7fed3e32998 - rustc::traits::select::SelectionContext::candidate_from_obligation_no_cache::h69335986cbdf213c
  57:      0x7fed3e304bc - rustc::traits::select::SelectionContext::candidate_from_obligation_no_cache::h69335986cbdf213c
  58:      0x7fed3f6c48f - rustc::dep_graph::graph::DepGraph::with_anon_task::h145f853e5ea70328
  59:      0x7fed3e2f7a6 - rustc::traits::select::SelectionContext::coinductive_predicate::hb059aacf0b8b2a18
  60:      0x7fed3e2ea28 - rustc::traits::select::SelectionContext::evaluate_stack::h071ccf0858841b50
  61:      0x7fed3f6cf84 - rustc::dep_graph::graph::DepGraph::with_anon_task::ha56e59d9eac32052
  62:      0x7fed3e2d4fc - rustc::traits::select::SelectionContext::evaluate_predicate_recursively::h728009a1728cd097
  63:      0x7fed3e2bda1 - rustc::traits::select::SelectionContext::evaluate_predicates_recursively::h76392a7559cd95fd
  64:      0x7fed416ce0b - rustc::infer::InferCtxt::probe::h0ab8d17b87062b58
  65:      0x7fed3d9f88b - <alloc::vec::IntoIter<T> as core::ops::drop::Drop>::drop::hc2129ff4ef5ee1ef
  66:      0x7fed3e30665 - rustc::traits::select::SelectionContext::candidate_from_obligation_no_cache::h69335986cbdf213c
  67:      0x7fed3f6c48f - rustc::dep_graph::graph::DepGraph::with_anon_task::h145f853e5ea70328
  68:      0x7fed3e2f7a6 - rustc::traits::select::SelectionContext::coinductive_predicate::hb059aacf0b8b2a18
  69:      0x7fed3e2ea28 - rustc::traits::select::SelectionContext::evaluate_stack::h071ccf0858841b50
  70:      0x7fed3f6cf84 - rustc::dep_graph::graph::DepGraph::with_anon_task::ha56e59d9eac32052
  71:      0x7fed3e2d4fc - rustc::traits::select::SelectionContext::evaluate_predicate_recursively::h728009a1728cd097
  72:      0x7fed3e2bda1 - rustc::traits::select::SelectionContext::evaluate_predicates_recursively::h76392a7559cd95fd
  73:      0x7fed416ce0b - rustc::infer::InferCtxt::probe::h0ab8d17b87062b58
  74:      0x7fed3d9f88b - <alloc::vec::IntoIter<T> as core::ops::drop::Drop>::drop::hc2129ff4ef5ee1ef
  75:      0x7fed3e30665 - rustc::traits::select::SelectionContext::candidate_from_obligation_no_cache::h69335986cbdf213c
  76:      0x7fed3f6c48f - rustc::dep_graph::graph::DepGraph::with_anon_task::h145f853e5ea70328
  77:      0x7fed3e2f7a6 - rustc::traits::select::SelectionContext::coinductive_predicate::hb059aacf0b8b2a18
  78:      0x7fed3e2ea28 - rustc::traits::select::SelectionContext::evaluate_stack::h071ccf0858841b50
  79:      0x7fed3f6cf84 - rustc::dep_graph::graph::DepGraph::with_anon_task::ha56e59d9eac32052
  80:      0x7fed3e2d4fc - rustc::traits::select::SelectionContext::evaluate_predicate_recursively::h728009a1728cd097
  81:      0x7fed416db79 - rustc::infer::InferCtxt::probe::he64460955cd4f3b9
  82:      0x7fed3e2bb30 - rustc::traits::select::SelectionContext::evaluate_root_obligation::h84336ed4461425ef
  83:      0x7fed8d4624c - rustc_traits::evaluate_obligation::evaluate_obligation::h1ad57efb84317ead
  84:      0x7fed40438b3 - rustc::ty::query::__query_compute::evaluate_obligation::h120b1a8d1e1547ea
  85:      0x7fed443ad3f - rustc::ty::query::on_disk_cache::__ty_decoder_impl::<impl serialize::serialize::Decoder for rustc::ty::query::on_disk_cache::CacheDecoder>::read_str::had5f64a164851791
  86:      0x7fed3f4b999 - rustc::dep_graph::graph::DepGraph::with_task_impl::h7b794a67a15077b6
  87:      0x7fed42865ef - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query::h8a267b4a8b6a58a1
  88:      0x7fed41b5d8a - rustc::traits::query::evaluate_obligation::<impl rustc::infer::InferCtxt>::evaluate_obligation::h7d2692681e00d9c4
  89:      0x7fed41b5e8a - rustc::traits::query::evaluate_obligation::<impl rustc::infer::InferCtxt>::evaluate_obligation_no_overflow::h9c841e8cf8850972
  90:      0x7fed41b5b49 - rustc::traits::query::evaluate_obligation::<impl rustc::infer::InferCtxt>::predicate_may_hold::he4414490bffaed69
  91:      0x7fed214c9f1 - rustc_typeck::check::method::<impl rustc_typeck::check::FnCtxt>::lookup_method_in_trait::hf26fd0a8beccf618
  92:      0x7fed216d3ad - rustc_typeck::check::op::<impl rustc_typeck::check::FnCtxt>::check_user_unop::h29f9ce648e6b3c31
  93:      0x7fed2169883 - rustc_typeck::check::op::<impl rustc_typeck::check::FnCtxt>::check_binop::h0f20ce481e2b06f0
  94:      0x7fed216950e - rustc_typeck::check::op::<impl rustc_typeck::check::FnCtxt>::check_binop::h0f20ce481e2b06f0
  95:      0x7fed2134825 - rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs::hdb66f052b26f0185
  96:      0x7fed216946b - rustc_typeck::check::op::<impl rustc_typeck::check::FnCtxt>::check_binop::h0f20ce481e2b06f0
  97:      0x7fed2134825 - rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs::hdb66f052b26f0185
  98:      0x7fed218c114 - rustc_typeck::check::FnCtxt::check_block_no_value::h10a5c2115c8b8ce8
  99:      0x7fed21347bc - rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs::hdb66f052b26f0185
  100:      0x7fed2119207 - rustc_typeck::check::_match::<impl rustc_typeck::check::FnCtxt>::check_match::h051fab31983aba00
@scottmcm

This comment has been minimized.

Copy link
Member Author

commented Jul 6, 2019

Shrinks the primitive array docs from 88 pages to 7 pages
image

@scottmcm scottmcm changed the title Use const generics for array impls Use const generics for array impls [part 1] Jul 6, 2019

@scottmcm scottmcm referenced this pull request Jul 6, 2019

Open

Use const generics for array impls #61415

1 of 3 tasks complete
@tanriol

This comment has been minimized.

Copy link

commented Jul 6, 2019

IMHO, AllowedArrayLength is a slightly confusing name for the documentation purposes. How about something like FullySupportedArrayLength?

@@ -4,13 +4,14 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^

error[E0277]: `[T; _]` doesn't implement `std::fmt::Debug`
error[E0277]: arrays only have std trait implementations for lengths 0..=32

This comment has been minimized.

Copy link
@Centril

Centril Jul 6, 2019

Member

Nice 馃憤

Show resolved Hide resolved src/libcore/array.rs Outdated
Show resolved Hide resolved src/libcore/array.rs Outdated
@Centril

This comment has been minimized.

Copy link
Member

commented Jul 6, 2019

IMHO, AllowedArrayLength is a slightly confusing name for the documentation purposes. How about something like FullySupportedArrayLength?

IMO, "Fully Supported" opens up questions whereas "Allowed" closes them, which is helpful.


We'll also want a perf run for this so... @bors try

@bors

This comment has been minimized.

Copy link
Contributor

commented Jul 6, 2019

鈱涳笍 Trying commit 5b2120b with merge a32e974...

bors added a commit that referenced this pull request Jul 6, 2019

Auto merge of #62435 - scottmcm:constrained-array-impls, r=<try>
Use const generics for array impls [part 1]

Part 1 of #61415, following the plan in #61415 (comment)

Found a way that works 馃檭
Show resolved Hide resolved src/libcore/array.rs Outdated
@shepmaster

This comment has been minimized.

Copy link
Member

commented Jul 6, 2019

There鈥檚 no secret tricks we can use to have the docs say the straightforward version, is there?

where
    N <= 32,
@bjorn3

This comment has been minimized.

Copy link
Contributor

commented Jul 6, 2019

where
    N <= 32,

That could make people think that that is real syntax.

Maybe call AllowedArrayLength ArrayLengthAtMost32 instead?

@bors

This comment has been minimized.

Copy link
Contributor

commented Jul 6, 2019

鈽锔 Try build successful - checks-azure, checks-travis
Build commit: a32e974

@Centril

This comment has been minimized.

Copy link
Member

commented Jul 6, 2019

@rust-timer

This comment has been minimized.

Copy link

commented Jul 6, 2019

Success: Queued a32e974 with parent 254f201, comparison URL.

@petrochenkov

This comment has been minimized.

Copy link
Contributor

commented Jul 6, 2019

@scottmcm
Could you compare the size of libcore before and after the change, in addition to the perf run?

@rust-timer

This comment has been minimized.

Copy link

commented Jul 6, 2019

Finished benchmarking try commit a32e974, comparison URL.

@Centril

This comment has been minimized.

Copy link
Member

commented Jul 6, 2019

Perf looks promising; @bors rollup=never

@c410-f3r

This comment has been minimized.

Copy link
Contributor

commented Jul 6, 2019

Since this PR is part 1, does the following PRs include a feature gate to enable implementations > 32 behind a feature gate?

@est31

This comment has been minimized.

Copy link
Contributor

commented Jul 6, 2019

@c410-f3r that wouldn't work I think. In general, impls are insta-stable. That won't prevent anyone from removing the check and building libstd themselves though.

@Centril

This comment has been minimized.

Copy link
Member

commented Jul 7, 2019

Was this what you were looking for, @Centril?

Yep, but please avoid pinging folks in commits because that generates more pings over time =)


r? @Centril

The implementation, perf, and the size of libcore all look good.

r=me with or without squashing but please unping me in that one commit =P

@rust-highfive rust-highfive assigned Centril and unassigned varkor Jul 7, 2019

Use const generics for array impls, restricted to 0..=32
- uses a never-stable core::array::LengthAtMost32 to bound the impls
- includes a custom error message to avoid mentioning LengthAtMost32 too often
- doesn't use macros for the slice implementations to avoid #62433

@scottmcm scottmcm force-pushed the scottmcm:constrained-array-impls branch from 752a25e to d6a9793 Jul 7, 2019

@scottmcm

This comment has been minimized.

Copy link
Member Author

commented Jul 7, 2019

Squashed & removed the ping against @鈥媍entril

@bors r=centril

@bors

This comment has been minimized.

Copy link
Contributor

commented Jul 7, 2019

馃搶 Commit d6a9793 has been approved by centril

@bors

This comment has been minimized.

Copy link
Contributor

commented Jul 7, 2019

鈱涳笍 Testing commit d6a9793 with merge 6e310f2...

bors added a commit that referenced this pull request Jul 7, 2019

Auto merge of #62435 - scottmcm:constrained-array-impls, r=centril
Use const generics for array impls [part 1]

Part 1 of #61415, following the plan in #61415 (comment)

Found a way that works 馃檭
@bors

This comment has been minimized.

Copy link
Contributor

commented Jul 7, 2019

鈽锔 Test successful - checks-azure, checks-travis, status-appveyor
Approved by: centril
Pushing 6e310f2 to master...

@bors bors added the merged-by-bors label Jul 7, 2019

@bors bors merged commit d6a9793 into rust-lang:master Jul 7, 2019

4 checks passed

homu Test successful
Details
pr Build #20190707.54 succeeded
Details
pr (Linux mingw-check) Linux mingw-check succeeded
Details
pr (Linux x86_64-gnu-llvm-6.0) Linux x86_64-gnu-llvm-6.0 succeeded
Details

@scottmcm scottmcm deleted the scottmcm:constrained-array-impls branch Jul 8, 2019

#[unstable(feature = "const_generic_impls_guard", issue = "0",
reason = "will never be stable, just a temporary step until const generics are stable")]
#[cfg(not(bootstrap))]
pub trait LengthAtMost32 {}

This comment has been minimized.

Copy link
@varkor

varkor Jul 12, 2019

Member

Is it not possible to make this invisible outside std? It'd be better if users couldn't do:

use std::array::LengthAtMost32;

This comment has been minimized.

Copy link
@est31

est31 Jul 12, 2019

Contributor

The trait is unstable. Users can't do it unless they opt into instability.

This comment has been minimized.

Copy link
@varkor

varkor Jul 12, 2019

Member

It's surprising that it's user-facing at all, even unstably. It's not a big problem though.

This comment has been minimized.

Copy link
@scottmcm

scottmcm Jul 12, 2019

Author Member

I think it's good that it shows up in the impls, so that they don't look like they work for all N. And if it's going to be visible in the rustdoc there, I think it's better that the bound be clickable so people can see what it is.

@RalfJung

This comment has been minimized.

Copy link
Member

commented Jul 13, 2019

This PR broke Miri executing array code. I think I will need some help for this. We are getting an error somewhere in this function, likely in this line:

ConstValue::Param(_) => return err!(TooGeneric), // FIXME(oli-obk): try to monomorphize

@gnzlbg

This comment has been minimized.

Copy link
Contributor

commented Jul 23, 2019

[T; N]: LengthAtMost32,

Heh, this is the same "trick" packed_simd uses to constrain the array argument of the Simd<T> type, where T can only be an [E; N] type of particular Es and Ns.

@Centril Centril referenced this pull request Jul 24, 2019

Open

Add by-value iterator for arrays (WIP!) #62959

2 of 4 tasks complete

LukasKalbertodt added a commit to LukasKalbertodt/rust that referenced this pull request Jul 25, 2019

Remove `cfg(bootstrap)` code for array implementations
In PR rust-lang#62435 ("Use const generics for array impls [part 1]") the old
macro-based implementations were not removed but still used with
`cfg(bootstrap)` since the bootstrap compiler had some problems with
const generics at the time. This does not seem to be the case anymore,
so there is no reason to keep the old code.

Centril added a commit to Centril/rust that referenced this pull request Jul 25, 2019

Rollup merge of rust-lang#62978 - LukasKalbertodt:remove-array-impl-b鈥
鈥otstrap-cfg, r=Mark-Simulacrum

Remove `cfg(bootstrap)` code for array implementations

In rust-lang#62435 ("Use const generics for array impls [part 1]") the old macro-based implementations were not removed but still used with `cfg(bootstrap)` since the bootstrap compiler had some problems with const generics at the time. This does not seem to be the case anymore, so there is no reason to keep the old code.

Unfortunately, the diff is pretty ugly because much of the code was indented by one level before. The change is pretty trivial, though.

PS: I did not run the full test suite locally. There are 40掳C outside and 31掳C inside my room. I don't want my notebook to melt. I hope that CI is green.

r? @scottmcm

bors added a commit that referenced this pull request Jul 28, 2019

Auto merge of #63061 - Centril:constantly-improving, r=<try>
In which we constantly improve the Vec(Deque) array PartialEq impls

Use the same approach as in #62435 as sanctioned by #61415 (comment).

r? @scottmcm

Centril added a commit to Centril/rust that referenced this pull request Jul 28, 2019

Rollup merge of rust-lang#63061 - Centril:constantly-improving, r=sco鈥
鈥tmcm

In which we constantly improve the Vec(Deque) array PartialEq impls

Use the same approach as in rust-lang#62435 as sanctioned by rust-lang#61415 (comment).

r? @scottmcm

Centril added a commit to Centril/rust that referenced this pull request Jul 28, 2019

Rollup merge of rust-lang#63061 - Centril:constantly-improving, r=sco鈥
鈥tmcm

In which we constantly improve the Vec(Deque) array PartialEq impls

Use the same approach as in rust-lang#62435 as sanctioned by rust-lang#61415 (comment).

r? @scottmcm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can鈥檛 perform that action at this time.