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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start supporting ?Sized and Sized properly #2483

Merged
merged 3 commits into from
Jul 30, 2023
Merged

Conversation

philberty
Copy link
Member

Fixes: #2375
Addresses: #2443

@philberty philberty self-assigned this Jul 29, 2023
@philberty philberty enabled auto-merge July 29, 2023 16:06
@philberty philberty force-pushed the phil/sized-trait-dev branch from 0c92b2f to 62db4bf Compare July 29, 2023 16:44
@philberty philberty added this pull request to the merge queue Jul 29, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 29, 2023
Trait bounds can have three forms in Rust the regular trait bound, '!' the
negative trait bound to enforice that this trait must not be implmented and
'?' the anti trait bound to remove this bound. This patch extends our
Polarity enum to include the Anti trait bound and updates the HIR lowering
code to track this properly.

Addresses #2443

gcc/rust/ChangeLog:

	* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): use new BoundPolarity enum
	* hir/rust-ast-lower-type.cc (ASTLoweringTypeBounds::visit): likewise
	* hir/rust-hir-dump.cc (BoundPolarityString): new helper
	(Dump::visit): update hir dump
	* hir/tree/rust-hir-item.h (class ImplBlock): likewise
	* hir/tree/rust-hir-type.h (class TraitBound): likewise
	* hir/tree/rust-hir.cc (TraitBound::as_string): fix as string
	* util/rust-common.h (enum Polarity): add new anti bound
	(enum BoundPolarity): likewise
	* util/rust-hir-map.cc (Mappings::Mappings): update naming

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Addresses #2443

gcc/rust/ChangeLog:

	* typecheck/rust-hir-path-probe.cc: track regular polarity
	* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait): likewise
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): likewise
	* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): likewise
	* typecheck/rust-tyty-bounds.cc (TypeCheckBase::get_predicate_from_bound): likewise
	(TypeBoundPredicate::TypeBoundPredicate): update ctor
	(TypeBoundPredicate::operator=): update copy assignment ctor
	(TypeBoundPredicate::error): update error node
	* typecheck/rust-tyty.h: add polarity field to predicate

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
…ized

Sized is implicitly applied to every generic type parameter apart from the
implicit Self type parameter on traits, as that would cause a recursive
bound and would make Traits unable to be appied to unsized types.

In order to keep everything happy this means we also need to support the
anti trait bound '?' so that Sized can be removed properly. The full Sized
rules are not completely implemented here. Slice's and Str's are currently
marked as Sized but there is a small regression here that looks like a more
general bug which should be fixed on its own as part of #2443. There is
a big testsuite update here to pull in the Sized lang item.

Note this lays the bound's ground work so we can start supporting Drop
trait properly which needs tackled very soon.

Fixes: #2375
Addresses: #2443

gcc/rust/ChangeLog:

	* expand/rust-proc-macro.cc (literal_from_string): update Lexer constructor
	(tokenstream_from_string): likewise
	* lex/rust-lex.cc (Lexer::Lexer): likewise
	* lex/rust-lex.h: pass through Linemap
	* parse/rust-cfg-parser.cc (parse_cfg_option): likewise
	* rust-session-manager.cc (Session::load_extern_crate): likewise
	* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait):
	dont apply Sized on self
	* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::get_marker_predicate): new
	* typecheck/rust-hir-type-check-base.h: add prototype
	* typecheck/rust-hir-type-check-type.cc (TypeResolveGenericParam::Resolve): apply Sized
	(TypeResolveGenericParam::visit): likewise
	* typecheck/rust-hir-type-check-type.h: update prototypes
	* typecheck/rust-typecheck-context.cc: remove bad assertions
	* typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::assemble_sized_builtin): cleanup
	(TypeCheckBase::get_predicate_from_bound): apply sized rules properly
	* util/rust-hir-map.cc (Mappings::lookup_trait_item_lang_item): helpers
	(Mappings::get_lang_item): likewise
	* util/rust-hir-map.h: likewise
	* util/rust-token-converter.cc (from_ident): update lexer ctor
	(from_punct): likewise

gcc/testsuite/ChangeLog:

	* rust/compile/bounds1.rs: Apply sized trait
	* rust/compile/canonical_paths1.rs: likewise
	* rust/compile/cast_generics.rs: likewise
	* rust/compile/closure_no_type_anno.rs: likewise
	* rust/compile/complex_qualified_path_in_expr.rs: likewise
	* rust/compile/const-issue1440.rs: likewise
	* rust/compile/const_generics_1.rs: likewise
	* rust/compile/const_generics_8.rs: likewise
	* rust/compile/derive_macro1.rs: likewise
	* rust/compile/derive_macro3.rs: likewise
	* rust/compile/derive_macro4.rs: likewise
	* rust/compile/derive_macro6.rs: likewise
	* rust/compile/expected_type_args2.rs: likewise
	* rust/compile/expected_type_args3.rs: likewise
	* rust/compile/generics1.rs: likewise
	* rust/compile/generics11.rs: likewise
	* rust/compile/generics12.rs: likewise
	* rust/compile/generics2.rs: likewise
	* rust/compile/generics3.rs: likewise
	* rust/compile/generics4.rs: likewise
	* rust/compile/generics6.rs: likewise
	* rust/compile/generics7.rs: likewise
	* rust/compile/generics8.rs: likewise
	* rust/compile/if_let_expr.rs: likewise
	* rust/compile/issue-1005.rs: likewise
	* rust/compile/issue-1019.rs: likewise
	* rust/compile/issue-1031.rs: likewise
	* rust/compile/issue-1034.rs: likewise
	* rust/compile/issue-1128.rs: likewise
	* rust/compile/issue-1129-2.rs: likewise
	* rust/compile/issue-1130.rs: likewise
	* rust/compile/issue-1131.rs: likewise
	* rust/compile/issue-1165.rs: likewise
	* rust/compile/issue-1173.rs: likewise
	* rust/compile/issue-1235.rs: likewise
	* rust/compile/issue-1237.rs: likewise
	* rust/compile/issue-1289.rs: likewise
	* rust/compile/issue-1383.rs: likewise
	* rust/compile/issue-1447.rs: likewise
	* rust/compile/issue-1589.rs: likewise
	* rust/compile/issue-1725-1.rs: likewise
	* rust/compile/issue-1725-2.rs: likewise
	* rust/compile/issue-1773.rs: likewise
	* rust/compile/issue-1786.rs: likewise
	* rust/compile/issue-1893.rs: likewise
	* rust/compile/issue-1901.rs: likewise
	* rust/compile/issue-1930.rs: likewise
	* rust/compile/issue-1981.rs: likewise
	* rust/compile/issue-2019-1.rs: likewise
	* rust/compile/issue-2019-2.rs: likewise
	* rust/compile/issue-2019-3.rs: likewise
	* rust/compile/issue-2036.rs: likewise
	* rust/compile/issue-2037.rs: likewise
	* rust/compile/issue-2070.rs: likewise
	* rust/compile/issue-2105.rs: likewise
	* rust/compile/issue-2106.rs: likewise
	* rust/compile/issue-2135.rs: likewise
	* rust/compile/issue-2136-1.rs: likewise
	* rust/compile/issue-2136-2.rs: likewise
	* rust/compile/issue-2139.rs: likewise
	* rust/compile/issue-2142.rs: likewise
	* rust/compile/issue-2165.rs: likewise
	* rust/compile/issue-2166.rs: likewise
	* rust/compile/issue-2190-1.rs: likewise
	* rust/compile/issue-2190-2.rs: likewise
	* rust/compile/issue-2195.rs: likewise
	* rust/compile/issue-2238.rs: likewise
	* rust/compile/issue-2304.rs: likewise
	* rust/compile/issue-850.rs: likewise
	* rust/compile/issue-855.rs: likewise
	* rust/compile/issue-925.rs: likewise
	* rust/compile/macro-issue1400.rs: likewise
	* rust/compile/macro20.rs: likewise
	* rust/compile/macro23.rs: likewise
	* rust/compile/macro40.rs: likewise
	* rust/compile/macro54.rs: likewise
	* rust/compile/name_resolution2.rs: likewise
	* rust/compile/name_resolution4.rs: likewise
	* rust/compile/nested_generic.rs: likewise
	* rust/compile/parse_associated_type_as_generic_arg.rs: likewise
	* rust/compile/parse_associated_type_as_generic_arg2.rs: likewise
	* rust/compile/parse_associated_type_as_generic_arg3.rs: likewise
	* rust/compile/parse_complex_generic_application.rs: likewise
	* rust/compile/parse_complex_generic_application2.rs: likewise
	* rust/compile/path_as_generic_arg.rs: likewise
	* rust/compile/privacy4.rs: likewise
	* rust/compile/privacy6.rs: likewise
	* rust/compile/sizeof-stray-infer-var-bug.rs: likewise
	* rust/compile/stmt_with_block_dot.rs: likewise
	* rust/compile/torture/associated_types1.rs: likewise
	* rust/compile/torture/forward_decl_5.rs: likewise
	* rust/compile/torture/generics1.rs: likewise
	* rust/compile/torture/generics10.rs: likewise
	* rust/compile/torture/generics11.rs: likewise
	* rust/compile/torture/generics12.rs: likewise
	* rust/compile/torture/generics13.rs: likewise
	* rust/compile/torture/generics14.rs: likewise
	* rust/compile/torture/generics15.rs: likewise
	* rust/compile/torture/generics16.rs: likewise
	* rust/compile/torture/generics17.rs: likewise
	* rust/compile/torture/generics18.rs: likewise
	* rust/compile/torture/generics19.rs: likewise
	* rust/compile/torture/generics2.rs: likewise
	* rust/compile/torture/generics20.rs: likewise
	* rust/compile/torture/generics21.rs: likewise
	* rust/compile/torture/generics22.rs: likewise
	* rust/compile/torture/generics23.rs: likewise
	* rust/compile/torture/generics24.rs: likewise
	* rust/compile/torture/generics25.rs: likewise
	* rust/compile/torture/generics26.rs: likewise
	* rust/compile/torture/generics27.rs: likewise
	* rust/compile/torture/generics28.rs: likewise
	* rust/compile/torture/generics29.rs: likewise
	* rust/compile/torture/generics3.rs: likewise
	* rust/compile/torture/generics30.rs: likewise
	* rust/compile/torture/generics31.rs: likewise
	* rust/compile/torture/generics32.rs: likewise
	* rust/compile/torture/generics4.rs: likewise
	* rust/compile/torture/generics5.rs: likewise
	* rust/compile/torture/generics6.rs: likewise
	* rust/compile/torture/generics7.rs: likewise
	* rust/compile/torture/generics8.rs: likewise
	* rust/compile/torture/generics9.rs: likewise
	* rust/compile/torture/intrinsics-2.rs: likewise
	* rust/compile/torture/intrinsics-6.rs: likewise
	* rust/compile/torture/intrinsics-7.rs: likewise
	* rust/compile/torture/intrinsics-8.rs: likewise
	* rust/compile/torture/issue-1024.rs: likewise
	* rust/compile/torture/issue-1075.rs: likewise
	* rust/compile/torture/issue-1432.rs: likewise
	* rust/compile/torture/issue-1555.rs: likewise
	* rust/compile/torture/issue-368.rs: likewise
	* rust/compile/torture/issue-808.rs: likewise
	* rust/compile/torture/issue-862.rs: likewise
	* rust/compile/torture/issue-893-2.rs: likewise
	* rust/compile/torture/issue-893.rs: likewise
	* rust/compile/torture/must_use2.rs: likewise
	* rust/compile/torture/nested_fn2.rs: likewise
	* rust/compile/torture/phantom_data.rs: likewise
	* rust/compile/torture/range-lang-item1.rs: likewise
	* rust/compile/torture/traits1.rs: likewise
	* rust/compile/torture/traits11.rs: likewise
	* rust/compile/torture/traits12.rs: likewise
	* rust/compile/torture/traits13.rs: likewise
	* rust/compile/torture/traits14.rs: likewise
	* rust/compile/torture/traits15.rs: likewise
	* rust/compile/torture/traits16.rs: likewise
	* rust/compile/torture/traits17.rs: likewise
	* rust/compile/torture/traits18.rs: likewise
	* rust/compile/torture/traits19.rs: likewise
	* rust/compile/torture/traits2.rs: likewise
	* rust/compile/torture/traits3.rs: likewise
	* rust/compile/torture/traits4.rs: likewise
	* rust/compile/torture/traits5.rs: likewise
	* rust/compile/torture/traits6.rs: likewise
	* rust/compile/torture/traits7.rs: likewise
	* rust/compile/torture/traits8.rs: likewise
	* rust/compile/torture/traits9.rs: likewise
	* rust/compile/torture/transmute-size-check-1.rs: likewise
	* rust/compile/torture/transmute1.rs: likewise
	* rust/compile/torture/uninit-intrinsic-1.rs: likewise
	* rust/compile/torture/utf8_identifiers.rs: likewise
	* rust/compile/traits1.rs: likewise
	* rust/compile/traits10.rs: likewise
	* rust/compile/traits11.rs: likewise
	* rust/compile/traits12.rs: likewise
	* rust/compile/traits2.rs: likewise
	* rust/compile/traits3.rs: likewise
	* rust/compile/traits4.rs: likewise
	* rust/compile/traits5.rs: likewise
	* rust/compile/traits6.rs: likewise
	* rust/compile/traits7.rs: likewise
	* rust/compile/traits8.rs: likewise
	* rust/compile/traits9.rs: likewise
	* rust/compile/type-bindings1.rs: likewise
	* rust/compile/unconstrained_type_param.rs: likewise
	* rust/compile/unsafe10.rs: likewise
	* rust/execute/torture/closure1.rs: likewise
	* rust/execute/torture/closure2.rs: likewise
	* rust/execute/torture/closure3.rs: likewise
	* rust/execute/torture/closure4.rs: likewise
	* rust/execute/torture/coercion1.rs: likewise
	* rust/execute/torture/coercion2.rs: likewise
	* rust/execute/torture/coercion3.rs: likewise
	* rust/execute/torture/copy_nonoverlapping1.rs: likewise
	* rust/execute/torture/derive_macro1.rs: likewise
	* rust/execute/torture/derive_macro3.rs: likewise
	* rust/execute/torture/derive_macro4.rs: likewise
	* rust/execute/torture/index1.rs: likewise
	* rust/execute/torture/issue-1120.rs: likewise
	* rust/execute/torture/issue-1133.rs: likewise
	* rust/execute/torture/issue-1198.rs: likewise
	* rust/execute/torture/issue-1232.rs: likewise
	* rust/execute/torture/issue-1249.rs: likewise
	* rust/execute/torture/issue-1436.rs: likewise
	* rust/execute/torture/issue-1496.rs: likewise
	* rust/execute/torture/issue-1720-2.rs: likewise
	* rust/execute/torture/issue-1720.rs: likewise
	* rust/execute/torture/issue-2052.rs: likewise
	* rust/execute/torture/issue-2179.rs: likewise
	* rust/execute/torture/issue-2180.rs: likewise
	* rust/execute/torture/issue-2236.rs: likewise
	* rust/execute/torture/issue-647.rs: likewise
	* rust/execute/torture/issue-845.rs: likewise
	* rust/execute/torture/issue-851.rs: likewise
	* rust/execute/torture/issue-858.rs: likewise
	* rust/execute/torture/macros23.rs: likewise
	* rust/execute/torture/macros28.rs: likewise
	* rust/execute/torture/method2.rs: likewise
	* rust/execute/torture/method3.rs: likewise
	* rust/execute/torture/method4.rs: likewise
	* rust/execute/torture/operator_overload_1.rs: likewise
	* rust/execute/torture/operator_overload_10.rs: likewise
	* rust/execute/torture/operator_overload_11.rs: likewise
	* rust/execute/torture/operator_overload_12.rs: likewise
	* rust/execute/torture/operator_overload_2.rs: likewise
	* rust/execute/torture/operator_overload_3.rs: likewise
	* rust/execute/torture/operator_overload_4.rs: likewise
	* rust/execute/torture/operator_overload_5.rs: likewise
	* rust/execute/torture/operator_overload_6.rs: likewise
	* rust/execute/torture/operator_overload_7.rs: likewise
	* rust/execute/torture/operator_overload_8.rs: likewise
	* rust/execute/torture/operator_overload_9.rs: likewise
	* rust/execute/torture/prefetch_data.rs: likewise
	* rust/execute/torture/ref-pattern2.rs: likewise
	* rust/execute/torture/slice-magic.rs: likewise
	* rust/execute/torture/slice-magic2.rs: likewise
	* rust/execute/torture/slice1.rs: likewise
	* rust/execute/torture/str-layout1.rs: likewise
	* rust/execute/torture/trait1.rs: likewise
	* rust/execute/torture/trait10.rs: likewise
	* rust/execute/torture/trait11.rs: likewise
	* rust/execute/torture/trait12.rs: likewise
	* rust/execute/torture/trait13.rs: likewise
	* rust/execute/torture/trait2.rs: likewise
	* rust/execute/torture/trait3.rs: likewise
	* rust/execute/torture/trait4.rs: likewise
	* rust/execute/torture/trait5.rs: likewise
	* rust/execute/torture/trait6.rs: likewise
	* rust/execute/torture/trait7.rs: likewise
	* rust/execute/torture/trait8.rs: likewise
	* rust/execute/torture/trait9.rs: likewise
	* rust/execute/torture/transmute1.rs: likewise
	* rust/execute/torture/wrapping_op1.rs: likewise
	* rust/execute/torture/wrapping_op2.rs: likewise
	* rust/link/generic_function_0.rs: likewise
	* rust/link/generic_function_1.rs: likewise
	* rust/compile/issue-2375.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
@philberty philberty force-pushed the phil/sized-trait-dev branch from 62db4bf to f806230 Compare July 29, 2023 22:57
@philberty philberty enabled auto-merge July 29, 2023 22:57
@philberty philberty added this pull request to the merge queue Jul 29, 2023
Merged via the queue into master with commit 5785d32 Jul 30, 2023
@philberty philberty deleted the phil/sized-trait-dev branch July 31, 2023 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Resolve type path error
1 participant