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

Proof of Concept: add #[defines] attribute and require it for all type-alias-impl-trait sites that register a hidden type #128440

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Jul 31, 2024

This PR is not meant to be merged (I will not be pushing changes in the next 4 months), but serves as a starting point for anyone wanting to make progress on this. It should hopefully be simple to rebase and not require you to edit 200+ tests, as these edits are done here and you can just cherry pick them out (no need for attribution, just squash as you want)

I left TODOs for everything that I think needs to be done.

  • differentiate between no attribute and an empty attribute (#[defines()]), the latter opting out of impl-trait-in-assoc types automatic opaque collection in the signature (or in general, any #[defines(SomeOhterTait)] attribute behaving as an override for the default collection, too).

An interesting follow-up could also be to automatically fill in RPITs into that list in ast lowering, so that opaque_types_defined_by doesn't need to walk for RPITs anymore.

@petrochenkov can you have a look at the resolver changes so that anyone picking this up will know what to change?

Comment on lines 250 to 224
self.tcx.dcx().emit_err(TaitForwardCompat2 {
let guar = self.tcx.dcx().emit_err(TaitForwardCompat2 {
span: self
.tcx
.def_ident_span(item_def_id)
.unwrap_or_else(|| self.tcx.def_span(item_def_id)),
opaque_type_span: self.tcx.def_span(self.def_id),
opaque_type: self.tcx.def_path_str(self.def_id),
});
// TODO: land this change as a separate PR on master, it works on its own.
// Avoid "opaque type not constrained" errors on the opaque itself.
self.found = Some(ty::OpaqueHiddenType {
span: DUMMY_SP,
ty: Ty::new_error(self.tcx, guar),
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change should be a fairly trivial PR on its own (just removes some redundant errors)

@oli-obk oli-obk added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 31, 2024
@rust-log-analyzer

This comment has been minimized.

@petrochenkov petrochenkov self-assigned this Jul 31, 2024
@petrochenkov petrochenkov added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 31, 2024
@bors
Copy link
Contributor

bors commented Aug 1, 2024

☔ The latest upstream changes (presumably #128481) made this pull request unmergeable. Please resolve the merge conflicts.

}
MetaItemKind::NameValue(_) => vec![],
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this function ever used?
The ids used to identify defines paths are created with next_node_id in resolver, so they do not match ids kept in meta-item paths (if such ids are filled to non-dummy values at all).

// TODO: error reporting and tests that go through these code paths
PathResult::Module(_) => todo!(),
PathResult::NonModule(partial_res) => {
let id = self.r.next_node_id();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these ids necessary?
Probably simpler to push the resolutions straight to self.r.defines.entry(attr.id), without doing record_partial_res.

match self.resolve_path(
&Segment::from_path(&item.path),
Some(Namespace::TypeNS),
None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a speculative resolution, so there should be Some here, but the real fix would be using smart_resolve_path instead of resolve_path above.

fn check_defines(&self, attr: &Attribute, span: Span, target: Target) -> bool {
match target {
Target::Fn
| Target::Closure
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The closure case is not processed in resolve.

@petrochenkov
Copy link
Contributor

Simple paths in attributes are not as bad as rust-lang/rfcs#3659, but still sort of meh, but probably acceptable.

We don't currently have any resolved paths (staying after macro expansion) in attributes in the proper language.
We have links in doc comments though, which are also simple paths processed during late resolution, and they also have to be kept in a separate special side table.

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 14, 2024
@petrochenkov petrochenkov removed their assignment Aug 14, 2024
@petrochenkov
Copy link
Contributor

Also, defines is probably a popular enough name, so the chance of regressions like #128888 may be high, if it becomes a built-in attribute.

@traviscross traviscross added the F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` label Aug 23, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 4, 2024
…ler-errors

Avoid `opaque type not constrained` errors in the presence of other errors

pulled out of rust-lang#128440

These errors carry no new information if the opaque type was actually used in a constraining (but erroneous) way somewhere.
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Dec 4, 2024
Rollup merge of rust-lang#133850 - oli-obk:push-xryukktpyooq, r=compiler-errors

Avoid `opaque type not constrained` errors in the presence of other errors

pulled out of rust-lang#128440

These errors carry no new information if the opaque type was actually used in a constraining (but erroneous) way somewhere.
@rustbot rustbot added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Dec 10, 2024
…ng from the signature to the list of opaques that are being defined
@rust-log-analyzer
Copy link
Collaborator

The job mingw-check-tidy failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

COPY host-x86_64/mingw-check/validate-toolstate.sh /scripts/
COPY host-x86_64/mingw-check/validate-error-codes.sh /scripts/

# NOTE: intentionally uses python2 for x.py so we can test it still works.
# validate-toolstate only runs in our CI, so it's ok for it to only support python3.
ENV SCRIPT TIDY_PRINT_DIFF=1 python2.7 ../x.py test \
           --stage 0 src/tools/tidy tidyselftest --extra-checks=py:lint,cpp:fmt
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
#    pip-compile --allow-unsafe --generate-hashes reuse-requirements.in
---
#13 2.880 Building wheels for collected packages: reuse
#13 2.881   Building wheel for reuse (pyproject.toml): started
#13 3.130   Building wheel for reuse (pyproject.toml): finished with status 'done'
#13 3.130   Created wheel for reuse: filename=reuse-4.0.3-cp310-cp310-manylinux_2_35_x86_64.whl size=132720 sha256=026f3bb0f1aa8090b861fd0a0939cb1a782396d84c8aab7875096557d637a0f6
#13 3.131   Stored in directory: /tmp/pip-ephem-wheel-cache-z81vlf3j/wheels/3d/8d/0a/e0fc6aba4494b28a967ab5eaf951c121d9c677958714e34532
#13 3.134 Installing collected packages: boolean-py, binaryornot, tomlkit, reuse, python-debian, markupsafe, license-expression, jinja2, chardet, attrs
#13 3.522 Successfully installed attrs-23.2.0 binaryornot-0.4.4 boolean-py-4.0 chardet-5.2.0 jinja2-3.1.4 license-expression-30.3.0 markupsafe-2.1.5 python-debian-0.1.49 reuse-4.0.3 tomlkit-0.13.0
#13 3.523 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
#13 4.055 Collecting virtualenv
#13 4.055 Collecting virtualenv
#13 4.109   Downloading virtualenv-20.28.0-py3-none-any.whl (4.3 MB)
#13 4.413      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.3/4.3 MB 14.1 MB/s eta 0:00:00
#13 4.473 Collecting platformdirs<5,>=3.9.1
#13 4.480   Downloading platformdirs-4.3.6-py3-none-any.whl (18 kB)
#13 4.519 Collecting filelock<4,>=3.12.2
#13 4.547 Collecting distlib<1,>=0.3.7
#13 4.554   Downloading distlib-0.3.9-py2.py3-none-any.whl (468 kB)
#13 4.567      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 469.0/469.0 KB 41.3 MB/s eta 0:00:00
#13 4.567      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 469.0/469.0 KB 41.3 MB/s eta 0:00:00
#13 4.648 Installing collected packages: distlib, platformdirs, filelock, virtualenv
#13 4.830 Successfully installed distlib-0.3.9 filelock-3.16.1 platformdirs-4.3.6 virtualenv-20.28.0
#13 DONE 4.9s

#14 [7/8] COPY host-x86_64/mingw-check/validate-toolstate.sh /scripts/
#14 DONE 0.0s
---
DirectMap4k:      120768 kB
DirectMap2M:     8267776 kB
DirectMap1G:    10485760 kB
##[endgroup]
Executing TIDY_PRINT_DIFF=1 python2.7 ../x.py test            --stage 0 src/tools/tidy tidyselftest --extra-checks=py:lint,cpp:fmt
+ TIDY_PRINT_DIFF=1 python2.7 ../x.py test --stage 0 src/tools/tidy tidyselftest --extra-checks=py:lint,cpp:fmt
    Finished `dev` profile [unoptimized] target(s) in 0.04s
##[endgroup]
WARN: currently no CI rustc builds have rustc debug assertions enabled. Please either set `rust.debug-assertions` to `false` if you want to use download CI rustc or set `rust.download-rustc` to `false`.
downloading https://static.rust-lang.org/dist/2024-11-27/rustfmt-nightly-x86_64-unknown-linux-gnu.tar.xz
---
   Compiling tidy v0.1.0 (/checkout/src/tools/tidy)
    Finished `release` profile [optimized] target(s) in 31.19s
##[endgroup]
fmt check
Diff in /checkout/compiler/rustc_ast/src/attr/mod.rs:9:
 use smallvec::{SmallVec, smallvec};
 use thin_vec::{ThinVec, thin_vec};
+use crate::NodeId;
 use crate::ast::{
 use crate::ast::{
     AttrArgs, AttrId, AttrItem, AttrKind, AttrStyle, AttrVec, Attribute, DUMMY_NODE_ID, DelimArgs,
     Expr, ExprKind, LitKind, MetaItem, MetaItemInner, MetaItemKind, MetaItemLit, NormalAttr, Path,
Diff in /checkout/compiler/rustc_ast/src/attr/mod.rs:19:
 use crate::tokenstream::{DelimSpan, LazyAttrTokenStream, Spacing, TokenStream, TokenTree};
 use crate::util::comments;
-use crate::NodeId;
 
 
 pub struct MarkedAttrs(GrowableBitSet<AttrId>);
 
fmt error: Running `"/checkout/obj/build/x86_64-unknown-linux-gnu/rustfmt/bin/rustfmt" "--config-path" "/checkout" "--edition" "2021" "--unstable-features" "--skip-children" "--check" "/checkout/compiler/rustc_hir_analysis/src/constrained_generic_params.rs" "/checkout/compiler/rustc_hir_analysis/src/check_unused.rs" "/checkout/compiler/rustc_hir_analysis/src/check/dropck.rs" "/checkout/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs" "/checkout/compiler/rustc_hir_analysis/src/check/intrinsic.rs" "/checkout/compiler/rustc_hir_analysis/src/check/region.rs" "/checkout/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs" "/checkout/compiler/rustc_hir_analysis/src/check/entry.rs" "/checkout/compiler/rustc_hir_analysis/src/check/wfcheck.rs" "/checkout/compiler/rustc_hir_analysis/src/check/check.rs" "/checkout/compiler/rustc_hir_analysis/src/check/mod.rs" "/checkout/compiler/rustc_hir_analysis/src/check/intrinsicck.rs" "/checkout/compiler/rustc_hir_analysis/src/impl_wf_check.rs" "/checkout/compiler/rustc_hir_analysis/src/lib.rs" "/checkout/compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs" "/checkout/compiler/rustc_hir_analysis/src/hir_wf_check.rs" "/checkout/compiler/rustc_hir_analysis/src/variance/solve.rs" "/checkout/compiler/rustc_hir_analysis/src/variance/terms.rs" "/checkout/compiler/rustc_hir_analysis/src/variance/constraints.rs" "/checkout/compiler/rustc_hir_analysis/src/variance/mod.rs" "/checkout/compiler/rustc_hir_analysis/src/variance/dump.rs" "/checkout/compiler/rustc_hir_analysis/src/variance/xform.rs" "/checkout/compiler/rustc_hir_analysis/src/errors.rs" "/checkout/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs" "/checkout/compiler/rustc_hir_analysis/src/hir_ty_lowering/cmse.rs" "/checkout/compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs" "/checkout/compiler/rustc_hir_analysis/src/hir_ty_lowering/lint.rs" "/checkout/compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs" "/checkout/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs" "/checkout/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs" "/checkout/compiler/rustc_hir_analysis/src/delegation.rs" "/checkout/compiler/rustc_hir_analysis/src/collect/type_of.rs" "/checkout/compiler/rustc_hir_analysis/src/collect/item_bounds.rs" "/checkout/compiler/rustc_hir_analysis/src/collect/predicates_of.rs" "/checkout/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs" "/checkout/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs" "/checkout/compiler/rustc_hir_analysis/src/collect/dump.rs" "/checkout/compiler/rustc_hir_analysis/src/collect/generics_of.rs" "/checkout/compiler/rustc_ast/src/attr/mod.rs" "/checkout/compiler/rustc_ast/src/tokenstream.rs" "/checkout/compiler/rustc_ast/src/ast_traits.rs" "/checkout/compiler/rustc_ast/src/visit.rs" "/checkout/compiler/rustc_ast/src/node_id.rs" "/checkout/compiler/rustc_ast/src/util/case.rs" "/checkout/compiler/rustc_ast/src/util/literal.rs" "/checkout/compiler/rustc_ast/src/util/comments.rs" "/checkout/compiler/rustc_ast/src/util/classify.rs" "/checkout/compiler/rustc_ast/src/util/comments/tests.rs" "/checkout/compiler/rustc_ast/src/util/unicode.rs" "/checkout/compiler/rustc_ast/src/util/parser.rs" "/checkout/compiler/rustc_ast/src/expand/autodiff_attrs.rs" "/checkout/compiler/rustc_ast/src/expand/typetree.rs" "/checkout/compiler/rustc_ast/src/expand/allocator.rs" "/checkout/compiler/rustc_ast/src/expand/mod.rs" "/checkout/compiler/rustc_ast/src/ast.rs" "/checkout/compiler/rustc_ast/src/ptr.rs" "/checkout/compiler/rustc_ast/src/token.rs" "/checkout/compiler/rustc_ast/src/lib.rs" "/checkout/compiler/rustc_ast/src/entry.rs" "/checkout/compiler/rustc_ast/src/mut_visit.rs" "/checkout/compiler/rustc_ast/src/format.rs" "/checkout/compiler/rustc_expand/src/proc_macro.rs" "/checkout/compiler/rustc_expand/src/placeholders.rs" "/checkout/compiler/rustc_hir_analysis/src/autoderef.rs"` failed.
If you're running `tidy`, try again with `--bless`. Or, if you just want to format code, run `./x.py fmt` instead.
  local time: Wed Dec 18 10:21:30 UTC 2024
  network time: Wed, 18 Dec 2024 10:21:30 GMT
##[error]Process completed with exit code 1.
Post job cleanup.

@bors
Copy link
Contributor

bors commented Dec 19, 2024

☔ The latest upstream changes (presumably #134492) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)
Development

Successfully merging this pull request may close these issues.

7 participants