Lower paths to functions in const args as ConstKind::Error#157962
Lower paths to functions in const args as ConstKind::Error#157962Shourya742 wants to merge 3 commits into
Conversation
|
HIR ty lowering was modified cc @fmease |
|
|
This comment has been minimized.
This comment has been minimized.
|
This PR changes a file inside |
|
in theory it should be possible to properly lower the path in a way that doesnt ICE and use that for recovering. I would prefer to do that if possible since eventually we do actually want to support function item types in const generics can you try and figure out the right way to paths to lower associated functions? thx :3 |
|
@rustbot author |
f227e79 to
e7edc35
Compare
|
changes to the core type system cc @lcnr |
| path.segments.last().unwrap(), | ||
| parent_args, | ||
| ); | ||
| Const::zero_sized(tcx, Ty::new_fn_def(tcx, def_id, args)) |
There was a problem hiding this comment.
I am lowering this via lower_generic_args_of_assoc_item. There are a couple of caveats here. First, it doesn't support explicit generics on paths. Also, when I initially used it, I got a segfault because of the recursive nature of this case:
trait Bar {
fn x(&self) -> [i32; Bar::x];
//~^ ERROR the constant `<Self as Bar>::x` is not of type `usize`
}With my caveman debugging skills, I found that WF checking for a recovered FnDef could recursively walk the same function signature. The function output contained the same const argument, which lowered back to the same function item.
I added a guard to avoid re-walking the FnDef output when its def_id is the same as the current body_def_id, since that signature is already being checked. You can see this in the changes to the wf method.
@BoxyUwU, let me know what you think about this and whether this is even the correct way to approach it. I didn't try to make lower_generic_args_of_assoc_item smarter, considering the scope of this PR, but that can be done if needed.
There was a problem hiding this comment.
Oh my god that segfault is incredibly funny I hadn't considered that 🤔 definitely think that wf requiring wf(sig(fndef)) to hold for wf(fndef) to hold is wrong/should be changed long term but that's not something we can do right now or as part of this PR... lol
I'm not sure that the check for body_def_id is correct, in theory you could have a usage of Bar::x from within a different body, e.g. just doing fn main() { let _: [(); Bar::x] } probably circumvents that? I think body_def_id is also really supposed to be a diagnostics thing not something that affects the semantics of the type system (which changing wf requirements does :>)
I think this honestly just kinda kills the possibility of properly lowering this. I think this is also a problem for just DefKind::Fn below since this segfaults on current nightly before your PR:
#![feature(min_generic_const_args, macroless_generic_const_args)]
fn foo() -> [(); foo] { todo!() }I think unfortunately we should probably just be handling DefKind::Fn and DefKind::AssocFn by returning ConstKind::Error and forgetting about trying to recover this properly. We should add a FIXME explaining the segfault you ran into and track this work somewhere in the project-const-generics repo.
If we were to actually lower this correctly I think in theory you want to call lower_resolved_const_path instead of lower_generic_args_of_assoc_item (which will handle calling the latter for you). The AssocConst arm above is probably a good thing to base this off.
But, no point in lowering this correctly because of the segfault 😓 Thank u for discovering this and explaining it to me :3
There was a problem hiding this comment.
If I understand correctly, we now want to stop trying to recover function items in const paths for both DefKind::Fn and DefKind::AssocFn, and instead lower them to ConstKind::Error to avoid the overflow/segfault cases.
I have made that change in this commit: ff7f240. I also added a FIXME explaining the issue.
If I misunderstood and we only want to change the associated function case, I can adjust it. Otherwise, if the FIXME looks okay to you, I can open an issue in the project-const-generics repo to track the proper lowering work.
|
@rustbot ready |
This comment has been minimized.
This comment has been minimized.
|
@rustbot author |
|
sorry for taking so long to get to this :> |
…ef const after scheduling. That works only when a later phase emits a real diagnostics. For function item (associated fn), the lowering needs parent trait and self args
e7edc35 to
421d5f5
Compare
…annot-be-used-as-const, r=BoxyUwU Function item should not be used as const arg closes: rust-lang#138088 r? @BoxyUwU
Rollup of 17 pull requests Successful merges: - #158168 (Added implementation on `set_permissions_nofollow` for all primary platforms) - #138618 (Support using const pointers in asm `const` operand) - #157962 (Function item should not be used as const arg) - #158404 (trait_solver: normalize next-gen region constraints) - #158709 (rustdoc: warn on improperly interleaved HTML/MD) - #159720 (document #[global_allocator] constraints) - #159732 (optimization: don't look for diagnostic/canonical items without rustc_attrs enabled) - #159740 (reuse regular exported_non_generic_symbols logic in Miri) - #159780 (check `extern "custom"` function pointers) - #159786 (rustdoc-js: ignore editor temp files in test folder discovery) - #159819 (std::sync::poison: disable auto_cfg on PoisonError::new) - #155388 (stepping into where-clauses during normalization may be productive) - #155914 (when bailing on ambiguity, don't force other results to ambig) - #159411 ([rustdoc] Correctly handle output options with --show-coverage) - #159439 (Fix(lib/fs/win): Fall back on Win32 delete for `Dir::remove_file`) - #159809 (Avoid `#[target_features]`) - #159826 (Remove redundant `#[rustc_paren_sugar]` feature gate)
…annot-be-used-as-const, r=BoxyUwU Function item should not be used as const arg closes: rust-lang#138088 r? @BoxyUwU
Rollup of 16 pull requests Successful merges: - #138618 (Support using const pointers in asm `const` operand) - #157962 (Function item should not be used as const arg) - #158404 (trait_solver: normalize next-gen region constraints) - #158709 (rustdoc: warn on improperly interleaved HTML/MD) - #159720 (document #[global_allocator] constraints) - #159732 (optimization: don't look for diagnostic/canonical items without rustc_attrs enabled) - #159740 (reuse regular exported_non_generic_symbols logic in Miri) - #159780 (check `extern "custom"` function pointers) - #159786 (rustdoc-js: ignore editor temp files in test folder discovery) - #159819 (std::sync::poison: disable auto_cfg on PoisonError::new) - #155388 (stepping into where-clauses during normalization may be productive) - #155914 (when bailing on ambiguity, don't force other results to ambig) - #159411 ([rustdoc] Correctly handle output options with --show-coverage) - #159439 (Fix(lib/fs/win): Fall back on Win32 delete for `Dir::remove_file`) - #159809 (Avoid `#[target_features]`) - #159826 (Remove redundant `#[rustc_paren_sugar]` feature gate)
…annot-be-used-as-const, r=BoxyUwU Function item should not be used as const arg closes: rust-lang#138088 r? @BoxyUwU
…annot-be-used-as-const, r=BoxyUwU Lower paths to functions in const args as ConstKind::Error closes: rust-lang#138088 Lowering these to recovered `FnDef` consts currently interacts poorly with WF checking: WF of a `FnDef` walks the function signature, so a signature that mentions the same function item as a const arg can recurse until it overflows/segfaults. So, for now we are emitting ConstKind::Error r? @BoxyUwU
Rollup of 20 pull requests Successful merges: - #138618 (Support using const pointers in asm `const` operand) - #157962 (Lower paths to functions in const args as ConstKind::Error) - #158404 (trait_solver: normalize next-gen region constraints) - #158709 (rustdoc: warn on improperly interleaved HTML/MD) - #159720 (document #[global_allocator] constraints) - #159732 (optimization: don't look for diagnostic/canonical items without rustc_attrs enabled) - #159738 (implement `CovariantUnsafeCell`) - #159740 (reuse regular exported_non_generic_symbols logic in Miri) - #159780 (check `extern "custom"` function pointers) - #159786 (rustdoc-js: ignore editor temp files in test folder discovery) - #159819 (std::sync::poison: disable auto_cfg on PoisonError::new) - #155388 (stepping into where-clauses during normalization may be productive) - #155914 (when bailing on ambiguity, don't force other results to ambig) - #159439 (Fix(lib/fs/win): Fall back on Win32 delete for `Dir::remove_file`) - #159676 (Update wasm-component-ld to 0.5.27) - #159730 (allow accessing the contents of UnsafeCell without going through get) - #159809 (Avoid `#[target_features]`) - #159826 (Remove redundant `#[rustc_paren_sugar]` feature gate) - #159853 (Updated expect messages for `CString` struct and method documentation) - #159877 (Revert "Export `derive` at `core::derive` and `std::derive`")
This comment has been minimized.
This comment has been minimized.
…ed-as-const, r=BoxyUwU Lower paths to functions in const args as ConstKind::Error closes: #138088 Lowering these to recovered `FnDef` consts currently interacts poorly with WF checking: WF of a `FnDef` walks the function signature, so a signature that mentions the same function item as a const arg can recurse until it overflows/segfaults. So, for now we are emitting ConstKind::Error r? @BoxyUwU
Rollup of 20 pull requests Successful merges: - #138618 (Support using const pointers in asm `const` operand) - #157962 (Lower paths to functions in const args as ConstKind::Error) - #158404 (trait_solver: normalize next-gen region constraints) - #158709 (rustdoc: warn on improperly interleaved HTML/MD) - #159720 (document #[global_allocator] constraints) - #159732 (optimization: don't look for diagnostic/canonical items without rustc_attrs enabled) - #159738 (implement `CovariantUnsafeCell`) - #159740 (reuse regular exported_non_generic_symbols logic in Miri) - #159780 (check `extern "custom"` function pointers) - #159786 (rustdoc-js: ignore editor temp files in test folder discovery) - #159819 (std::sync::poison: disable auto_cfg on PoisonError::new) - #155388 (stepping into where-clauses during normalization may be productive) - #155914 (when bailing on ambiguity, don't force other results to ambig) - #159439 (Fix(lib/fs/win): Fall back on Win32 delete for `Dir::remove_file`) - #159676 (Update wasm-component-ld to 0.5.27) - #159730 (allow accessing the contents of UnsafeCell without going through get) - #159809 (Avoid `#[target_features]`) - #159826 (Remove redundant `#[rustc_paren_sugar]` feature gate) - #159853 (Updated expect messages for `CString` struct and method documentation) - #159877 (Revert "Export `derive` at `core::derive` and `std::derive`")
|
@bors retry |
…annot-be-used-as-const, r=BoxyUwU Lower paths to functions in const args as ConstKind::Error closes: rust-lang#138088 Lowering these to recovered `FnDef` consts currently interacts poorly with WF checking: WF of a `FnDef` walks the function signature, so a signature that mentions the same function item as a const arg can recurse until it overflows/segfaults. So, for now we are emitting ConstKind::Error r? @BoxyUwU
…uwer Rollup of 25 pull requests Successful merges: - #138618 (Support using const pointers in asm `const` operand) - #157962 (Lower paths to functions in const args as ConstKind::Error) - #158404 (trait_solver: normalize next-gen region constraints) - #158709 (rustdoc: warn on improperly interleaved HTML/MD) - #159174 (Fix implicit_provenance_casts warnings on Xous) - #159179 (enable `unreachable_cfg_select_predicates` lint as part of `unused` lint group) - #159518 (iter: extend step_by specialization to cover StepBy<RangeIter<{integer}>>) - #159673 (bootstrap: forward -fdebug-prefix-map when using cc) - #159700 (Split non-local `semicolon_in_expressions_from_macros` into a separate lint) - #159720 (document #[global_allocator] constraints) - #159732 (optimization: don't look for diagnostic/canonical items without rustc_attrs enabled) - #159738 (implement `CovariantUnsafeCell`) - #159740 (reuse regular exported_non_generic_symbols logic in Miri) - #159780 (check `extern "custom"` function pointers) - #159785 (Share _Unwind_Exception definition between native and wasm) - #159786 (rustdoc-js: ignore editor temp files in test folder discovery) - #159819 (std::sync::poison: disable auto_cfg on PoisonError::new) - #155388 (stepping into where-clauses during normalization may be productive) - #155914 (when bailing on ambiguity, don't force other results to ambig) - #159204 (Add support to caller_location to rustc_public) - #159439 (Fix(lib/fs/win): Fall back on Win32 delete for `Dir::remove_file`) - #159676 (Update wasm-component-ld to 0.5.27) - #159695 (proc_macro: Fix cfg_attr inner attrs in file modules) - #159730 (allow accessing the contents of UnsafeCell without going through get) - #159809 (Avoid `#[target_features]`)
…uwer Rollup of 25 pull requests Successful merges: - #138618 (Support using const pointers in asm `const` operand) - #157962 (Lower paths to functions in const args as ConstKind::Error) - #158404 (trait_solver: normalize next-gen region constraints) - #158709 (rustdoc: warn on improperly interleaved HTML/MD) - #159174 (Fix implicit_provenance_casts warnings on Xous) - #159179 (enable `unreachable_cfg_select_predicates` lint as part of `unused` lint group) - #159518 (iter: extend step_by specialization to cover StepBy<RangeIter<{integer}>>) - #159673 (bootstrap: forward -fdebug-prefix-map when using cc) - #159700 (Split non-local `semicolon_in_expressions_from_macros` into a separate lint) - #159720 (document #[global_allocator] constraints) - #159732 (optimization: don't look for diagnostic/canonical items without rustc_attrs enabled) - #159738 (implement `CovariantUnsafeCell`) - #159740 (reuse regular exported_non_generic_symbols logic in Miri) - #159780 (check `extern "custom"` function pointers) - #159785 (Share _Unwind_Exception definition between native and wasm) - #159786 (rustdoc-js: ignore editor temp files in test folder discovery) - #159819 (std::sync::poison: disable auto_cfg on PoisonError::new) - #155388 (stepping into where-clauses during normalization may be productive) - #155914 (when bailing on ambiguity, don't force other results to ambig) - #159204 (Add support to caller_location to rustc_public) - #159439 (Fix(lib/fs/win): Fall back on Win32 delete for `Dir::remove_file`) - #159676 (Update wasm-component-ld to 0.5.27) - #159695 (proc_macro: Fix cfg_attr inner attrs in file modules) - #159730 (allow accessing the contents of UnsafeCell without going through get) - #159809 (Avoid `#[target_features]`)
…uwer Rollup of 25 pull requests Successful merges: - #138618 (Support using const pointers in asm `const` operand) - #157962 (Lower paths to functions in const args as ConstKind::Error) - #158404 (trait_solver: normalize next-gen region constraints) - #158709 (rustdoc: warn on improperly interleaved HTML/MD) - #159174 (Fix implicit_provenance_casts warnings on Xous) - #159179 (enable `unreachable_cfg_select_predicates` lint as part of `unused` lint group) - #159518 (iter: extend step_by specialization to cover StepBy<RangeIter<{integer}>>) - #159673 (bootstrap: forward -fdebug-prefix-map when using cc) - #159700 (Split non-local `semicolon_in_expressions_from_macros` into a separate lint) - #159720 (document #[global_allocator] constraints) - #159732 (optimization: don't look for diagnostic/canonical items without rustc_attrs enabled) - #159738 (implement `CovariantUnsafeCell`) - #159740 (reuse regular exported_non_generic_symbols logic in Miri) - #159780 (check `extern "custom"` function pointers) - #159785 (Share _Unwind_Exception definition between native and wasm) - #159786 (rustdoc-js: ignore editor temp files in test folder discovery) - #159819 (std::sync::poison: disable auto_cfg on PoisonError::new) - #155388 (stepping into where-clauses during normalization may be productive) - #155914 (when bailing on ambiguity, don't force other results to ambig) - #159204 (Add support to caller_location to rustc_public) - #159439 (Fix(lib/fs/win): Fall back on Win32 delete for `Dir::remove_file`) - #159676 (Update wasm-component-ld to 0.5.27) - #159695 (proc_macro: Fix cfg_attr inner attrs in file modules) - #159730 (allow accessing the contents of UnsafeCell without going through get) - #159809 (Avoid `#[target_features]`)
…annot-be-used-as-const, r=BoxyUwU Lower paths to functions in const args as ConstKind::Error closes: rust-lang#138088 Lowering these to recovered `FnDef` consts currently interacts poorly with WF checking: WF of a `FnDef` walks the function signature, so a signature that mentions the same function item as a const arg can recurse until it overflows/segfaults. So, for now we are emitting ConstKind::Error r? @BoxyUwU
…uwer Rollup of 25 pull requests Successful merges: - #159825 (codegen: handle OperandValue::Uninit in codegen_return_terminator) - #138618 (Support using const pointers in asm `const` operand) - #157962 (Lower paths to functions in const args as ConstKind::Error) - #158404 (trait_solver: normalize next-gen region constraints) - #158709 (rustdoc: warn on improperly interleaved HTML/MD) - #159174 (Fix implicit_provenance_casts warnings on Xous) - #159179 (enable `unreachable_cfg_select_predicates` lint as part of `unused` lint group) - #159518 (iter: extend step_by specialization to cover StepBy<RangeIter<{integer}>>) - #159673 (bootstrap: forward -fdebug-prefix-map when using cc) - #159700 (Split non-local `semicolon_in_expressions_from_macros` into a separate lint) - #159720 (document #[global_allocator] constraints) - #159732 (optimization: don't look for diagnostic/canonical items without rustc_attrs enabled) - #159738 (implement `CovariantUnsafeCell`) - #159740 (reuse regular exported_non_generic_symbols logic in Miri) - #159780 (check `extern "custom"` function pointers) - #159786 (rustdoc-js: ignore editor temp files in test folder discovery) - #159819 (std::sync::poison: disable auto_cfg on PoisonError::new) - #155388 (stepping into where-clauses during normalization may be productive) - #155914 (when bailing on ambiguity, don't force other results to ambig) - #159204 (Add support to caller_location to rustc_public) - #159439 (Fix(lib/fs/win): Fall back on Win32 delete for `Dir::remove_file`) - #159676 (Update wasm-component-ld to 0.5.27) - #159695 (proc_macro: Fix cfg_attr inner attrs in file modules) - #159730 (allow accessing the contents of UnsafeCell without going through get) - #159809 (Avoid `#[target_features]`)
…uwer Rollup of 25 pull requests Successful merges: - #159825 (codegen: handle OperandValue::Uninit in codegen_return_terminator) - #138618 (Support using const pointers in asm `const` operand) - #157962 (Lower paths to functions in const args as ConstKind::Error) - #158404 (trait_solver: normalize next-gen region constraints) - #158709 (rustdoc: warn on improperly interleaved HTML/MD) - #159174 (Fix implicit_provenance_casts warnings on Xous) - #159179 (enable `unreachable_cfg_select_predicates` lint as part of `unused` lint group) - #159518 (iter: extend step_by specialization to cover StepBy<RangeIter<{integer}>>) - #159673 (bootstrap: forward -fdebug-prefix-map when using cc) - #159700 (Split non-local `semicolon_in_expressions_from_macros` into a separate lint) - #159720 (document #[global_allocator] constraints) - #159732 (optimization: don't look for diagnostic/canonical items without rustc_attrs enabled) - #159738 (implement `CovariantUnsafeCell`) - #159740 (reuse regular exported_non_generic_symbols logic in Miri) - #159780 (check `extern "custom"` function pointers) - #159786 (rustdoc-js: ignore editor temp files in test folder discovery) - #159819 (std::sync::poison: disable auto_cfg on PoisonError::new) - #155388 (stepping into where-clauses during normalization may be productive) - #155914 (when bailing on ambiguity, don't force other results to ambig) - #159204 (Add support to caller_location to rustc_public) - #159439 (Fix(lib/fs/win): Fall back on Win32 delete for `Dir::remove_file`) - #159676 (Update wasm-component-ld to 0.5.27) - #159695 (proc_macro: Fix cfg_attr inner attrs in file modules) - #159730 (allow accessing the contents of UnsafeCell without going through get) - #159809 (Avoid `#[target_features]`)
View all comments
closes: #138088
Lowering these to recovered
FnDefconsts currently interacts poorly with WF checking: WF of aFnDefwalks the function signature, so a signature that mentions the same function item as a const arg can recurse until it overflows/segfaults. So, for now we are emitting ConstKind::Errorr? @BoxyUwU