gccrs: avoid ICE on generic const expressions in path resolution#4341
gccrs: avoid ICE on generic const expressions in path resolution#4341Pasta-coder wants to merge 1 commit intoRust-GCC:masterfrom
Conversation
896d6ad to
1b1c341
Compare
CohenArthur
left a comment
There was a problem hiding this comment.
The change looks great, only a few issues but nothing bad. Once this is fixed I'm happy to merge your PR. Thanks for your contribution!
e9afc67 to
3d52076
Compare
|
All checks are now passing and the PR is ready for merge. @CohenArthur Thanks a lot for the review and helpful feedback — it clarified the expected coding style and workflow. I’ll keep future PRs focused with a clean commit history. Please let me know if there’s anything else I should adjust. |
546caf5 to
56a7611
Compare
|
@P-E-P please review . thankyou |
philberty
left a comment
There was a problem hiding this comment.
Hmmm... i am not 100% sure this is the correct place to handle this because at this case is where it should be lazy evaluated and monomophized so i think this will cause false positives for other cases.
This should be handled in the typecheck pass when we resolve generic arguments instead where case cannot do N + 1 because N is not defined at this case.
|
okay , i will look into that . thanks for pointing this out . |
c363e86 to
ce25686
Compare
f55981c to
87e8a7f
Compare
Generic const expressions such as `{ N + 1 }` are symbolic and cannot be
evaluated to a concrete value immediately during type checking. Previously,
the compiler lacked a representation for these symbolic expressions in the
type system, causing it to treat them as concrete values. This led to
assertion failures and Internal Compiler Errors (ICE) in the backend and
path resolution logic when the compiler attempted to access the raw value.
This patch introduces `TyTy::ConstExprType`, a new type variant designed
to hold symbolic expressions that have not yet been evaluated. It updates
the core type system, substitution mapper, unification rules, call checkers,
and backend compilation visitors to handle this new type gracefully.
Key changes include:
1. Validating const generic arguments in path resolution to detect dependency.
2. Bridging the substitution mapper to clone symbolic expressions.
3. Relaxing backend assertions to return `error_mark_node` for symbolic types.
4. Implementing identity-based unification for symbolic expressions.
Fixes Rust-GCC#4341
gcc/rust/ChangeLog:
* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve_with_node_id):
Relax assertion to return error_mark_node for non-value constants.
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Add handler for
ConstExprType to prevent ICE.
* backend/rust-compile-type.h: Declare visit method.
* typecheck/rust-hir-type-check-path.cc (is_const_dependent): New helper.
(TypeCheckExpr::resolve_root_path): Skip immediate resolution for
dependent const arguments.
(TypeCheckExpr::resolve_segments): Likewise.
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
Handle ConstKind::Expr in switch to prevent fallthrough.
* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit):
Implement cloning for ConstExprType.
* typecheck/rust-substitution-mapper.h: Add visit declarations.
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Implement stub
for ConstExprType.
* typecheck/rust-tyty-call.h: Declare visit method.
* typecheck/rust-tyty-variance-analysis-private.h (VisitorBase::visit):
Add stub implementation.
* typecheck/rust-tyty-visitor.h: Add virtual visit methods.
* typecheck/rust-tyty.cc (ConstExprType::const_kind): Implement.
(ConstExprType::accept_vis): Implement.
(ConstExprType::as_string): Implement.
(ConstExprType::clone): Implement.
(ConstExprType::is_equal): Implement.
(ConstExprType::get_expr): Implement.
* typecheck/rust-tyty.h (enum ConstKind): Add Expr variant.
(class ConstExprType): New class definition.
* typecheck/rust-unify.cc (UnifyRules::expect_const): Add unification
logic for ConstExprType.
gcc/testsuite/ChangeLog:
* rust/compile/issue-4302.rs: New test.
Signed-off-by: Jayant Chauhan <0001jayant@gmail.com>
87e8a7f to
e029ed9
Compare
Generic const expressions such as `{ N + 1 }` are symbolic and cannot be
evaluated to a concrete value immediately during type checking. Previously,
the compiler lacked a representation for these symbolic expressions in the
type system, causing it to treat them as concrete values. This led to
assertion failures and Internal Compiler Errors (ICE) in the backend and
path resolution logic when the compiler attempted to access the raw value.
This patch introduces `TyTy::ConstExprType`, a new type variant designed
to hold symbolic expressions that have not yet been evaluated. It updates
the core type system, substitution mapper, unification rules, call checkers,
and backend compilation visitors to handle this new type gracefully.
Key changes include:
1. Validating const generic arguments in path resolution to detect dependency.
2. Bridging the substitution mapper to clone symbolic expressions.
3. Relaxing backend assertions to return `error_mark_node` for symbolic types.
4. Implementing identity-based unification for symbolic expressions.
Fixes Rust-GCC#4341
gcc/rust/ChangeLog:
* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve_with_node_id):
Relax assertion to return error_mark_node for non-value constants.
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Add handler for
ConstExprType to prevent ICE.
* backend/rust-compile-type.h: Declare visit method.
* typecheck/rust-hir-type-check-path.cc (is_const_dependent): New helper.
(TypeCheckExpr::resolve_root_path): Skip immediate resolution for
dependent const arguments.
(TypeCheckExpr::resolve_segments): Likewise.
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
Handle ConstKind::Expr in switch to prevent fallthrough.
* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit):
Implement cloning for ConstExprType.
* typecheck/rust-substitution-mapper.h: Add visit declarations.
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Implement stub
for ConstExprType.
* typecheck/rust-tyty-call.h: Declare visit method.
* typecheck/rust-tyty-variance-analysis-private.h (VisitorBase::visit):
Add stub implementation.
* typecheck/rust-tyty-visitor.h: Add virtual visit methods.
* typecheck/rust-tyty.cc (ConstExprType::const_kind): Implement.
(ConstExprType::accept_vis): Implement.
(ConstExprType::as_string): Implement.
(ConstExprType::clone): Implement.
(ConstExprType::is_equal): Implement.
(ConstExprType::get_expr): Implement.
* typecheck/rust-tyty.h (enum ConstKind): Add Expr variant.
(class ConstExprType): New class definition.
* typecheck/rust-unify.cc (UnifyRules::expect_const): Add unification
logic for ConstExprType.
gcc/testsuite/ChangeLog:
* rust/compile/issue-4302.rs: New test.
Signed-off-by: Jayant Chauhan <0001jayant@gmail.com>
e029ed9 to
7b5672f
Compare
Generic const expressions such as `{ N + 1 }` are symbolic and cannot be
evaluated to a concrete value immediately during type checking. Previously,
the compiler lacked a representation for these symbolic expressions in the
type system, causing it to treat them as concrete values. This led to
assertion failures and Internal Compiler Errors (ICE) in the backend and
path resolution logic when the compiler attempted to access the raw value.
This patch introduces `TyTy::ConstExprType`, a new type variant designed
to hold symbolic expressions that have not yet been evaluated. It updates
the core type system, substitution mapper, unification rules, call checkers,
and backend compilation visitors to handle this new type gracefully.
Key changes include:
1. Validating const generic arguments in path resolution to detect dependency.
2. Bridging the substitution mapper to clone symbolic expressions.
3. Relaxing backend assertions to return `error_mark_node` for symbolic types.
4. Implementing identity-based unification for symbolic expressions.
Fixes Rust-GCC#4341
gcc/rust/ChangeLog:
* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve_with_node_id):
Relax assertion to return error_mark_node for non-value constants.
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Add handler for
ConstExprType to prevent ICE.
* backend/rust-compile-type.h: Declare visit method.
* typecheck/rust-hir-type-check-path.cc (is_const_dependent): New helper.
(TypeCheckExpr::resolve_root_path): Skip immediate resolution for
dependent const arguments.
(TypeCheckExpr::resolve_segments): Likewise.
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
Handle ConstKind::Expr in switch to prevent fallthrough.
* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit):
Implement cloning for ConstExprType.
* typecheck/rust-substitution-mapper.h: Add visit declarations.
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Implement stub
for ConstExprType.
* typecheck/rust-tyty-call.h: Declare visit method.
* typecheck/rust-tyty-variance-analysis-private.h (VisitorBase::visit):
Add stub implementation.
* typecheck/rust-tyty-visitor.h: Add virtual visit methods.
* typecheck/rust-tyty.cc (ConstExprType::const_kind): Implement.
(ConstExprType::accept_vis): Implement.
(ConstExprType::as_string): Implement.
(ConstExprType::clone): Implement.
(ConstExprType::is_equal): Implement.
(ConstExprType::get_expr): Implement.
* typecheck/rust-tyty.h (enum ConstKind): Add Expr variant.
(class ConstExprType): New class definition.
* typecheck/rust-unify.cc (UnifyRules::expect_const): Add unification
logic for ConstExprType.
gcc/testsuite/ChangeLog:
* rust/compile/issue-4302.rs: New test.
Signed-off-by: Jayant Chauhan <0001jayant@gmail.com>
7b5672f to
385f43b
Compare
Generic const expressions such as `{ N + 1 }` are symbolic and cannot be
evaluated to a concrete value immediately during type checking. Previously,
the compiler lacked a representation for these symbolic expressions in the
type system, causing it to treat them as concrete values. This led to
assertion failures and Internal Compiler Errors (ICE) in the backend and
path resolution logic when the compiler attempted to access the raw value.
This patch introduces `TyTy::ConstExprType`, a new type variant designed
to hold symbolic expressions that have not yet been evaluated. It updates
the core type system, substitution mapper, unification rules, call checkers,
and backend compilation visitors to handle this new type gracefully.
Key changes include:
1. Validating const generic arguments in path resolution to detect dependency
using the name resolver.
2. Bridging the substitution mapper to clone symbolic expressions.
3. Relaxing backend assertions to return `error_mark_node` for symbolic types.
4. Implementing identity-based unification for symbolic expressions.
Fixes Rust-GCC#4341
gcc/rust/ChangeLog:
* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve_with_node_id):
Relax assertion to return error_mark_node for non-value constants.
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Add handler for
ConstExprType to prevent ICE.
* backend/rust-compile-type.h: Declare visit method.
* typecheck/rust-hir-type-check-path.cc (is_const_dependent): New helper.
(TypeCheckExpr::resolve_root_path): Skip immediate resolution for
dependent const arguments.
(TypeCheckExpr::resolve_segments): Likewise.
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
Handle ConstKind::Expr in switch to prevent fallthrough.
* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit):
Implement cloning for ConstExprType.
* typecheck/rust-substitution-mapper.h: Add visit declarations.
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Implement stub
for ConstExprType.
* typecheck/rust-tyty-call.h: Declare visit method.
* typecheck/rust-tyty-variance-analysis-private.h (VisitorBase::visit):
Add stub implementation.
* typecheck/rust-tyty-visitor.h: Add virtual visit methods.
* typecheck/rust-tyty.cc (ConstExprType::const_kind): Implement.
(ConstExprType::accept_vis): Implement.
(ConstExprType::as_string): Implement.
(ConstExprType::clone): Implement.
(ConstExprType::is_equal): Implement.
(ConstExprType::get_expr): Implement.
* typecheck/rust-tyty.h (enum ConstKind): Add Expr variant.
(class ConstExprType): New class definition.
* typecheck/rust-unify.cc (UnifyRules::expect_const): Add unification
logic for ConstExprType.
gcc/testsuite/ChangeLog:
* rust/compile/issue-4302.rs: New test.
Signed-off-by: Jayant Chauhan <0001jayant@gmail.com>
385f43b to
94e986d
Compare
Generic const expressions such as `{ N + 1 }` are symbolic and cannot be
evaluated to a concrete value immediately during type checking. Previously,
the compiler lacked a representation for these symbolic expressions in the
type system, causing it to treat them as concrete values. This led to
assertion failures and Internal Compiler Errors (ICE) in the backend and
path resolution logic when the compiler attempted to access the raw value.
This patch introduces `TyTy::ConstExprType`, a new type variant designed
to hold symbolic expressions that have not yet been evaluated. It updates
the core type system, substitution mapper, unification rules, call checkers,
and backend compilation visitors to handle this new type gracefully.
Key changes include:
1. Validating const generic arguments in path resolution to detect dependency
using the name resolver.
2. Bridging the substitution mapper to clone symbolic expressions.
3. Relaxing backend assertions to return `error_mark_node` for symbolic types.
4. Implementing identity-based unification for symbolic expressions.
Fixes Rust-GCC#4341
gcc/rust/ChangeLog:
* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve_with_node_id):
Relax assertion to return error_mark_node for non-value constants.
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Add handler for
ConstExprType to prevent ICE.
* backend/rust-compile-type.h: Declare visit method.
* typecheck/rust-hir-type-check-path.cc (is_const_dependent): New helper.
(TypeCheckExpr::resolve_root_path): Skip immediate resolution for
dependent const arguments.
(TypeCheckExpr::resolve_segments): Likewise.
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
Handle ConstKind::Expr in switch to prevent fallthrough.
* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit):
Implement cloning for ConstExprType.
* typecheck/rust-substitution-mapper.h: Add visit declarations.
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Implement stub
for ConstExprType.
* typecheck/rust-tyty-call.h: Declare visit method.
* typecheck/rust-tyty-variance-analysis-private.h (VisitorBase::visit):
Add stub implementation.
* typecheck/rust-tyty-visitor.h: Add virtual visit methods.
* typecheck/rust-tyty.cc (ConstExprType::const_kind): Implement.
(ConstExprType::accept_vis): Implement.
(ConstExprType::as_string): Implement.
(ConstExprType::clone): Implement.
(ConstExprType::is_equal): Implement.
(ConstExprType::get_expr): Implement.
* typecheck/rust-tyty.h (enum ConstKind): Add Expr variant.
(class ConstExprType): New class definition.
* typecheck/rust-unify.cc (UnifyRules::expect_const): Add unification
logic for ConstExprType.
gcc/testsuite/ChangeLog:
* rust/compile/issue-4302.rs: New test.
Signed-off-by: Jayant Chauhan <0001jayant@gmail.com>
94e986d to
dd8b3ad
Compare
Generic const expressions such as `{ N + 1 }` are symbolic and cannot be
evaluated to a concrete value immediately during type checking. Previously,
the compiler lacked a representation for these symbolic expressions in the
type system, causing it to treat them as concrete values. This led to
assertion failures and Internal Compiler Errors (ICE) in the backend and
path resolution logic when the compiler attempted to access the raw value.
This patch introduces `TyTy::ConstExprType`, a new type variant designed
to hold symbolic expressions that have not yet been evaluated. It updates
the core type system, substitution mapper, unification rules, call checkers,
and backend compilation visitors to handle this new type gracefully.
Key changes include:
1. Validating const generic arguments in path resolution to detect dependency
using the name resolver.
2. Bridging the substitution mapper to clone symbolic expressions.
3. Relaxing backend assertions to return `error_mark_node` for symbolic types.
4. Implementing identity-based unification for symbolic expressions.
Fixes Rust-GCC#4341
gcc/rust/ChangeLog:
* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve_with_node_id):
Relax assertion to return error_mark_node for non-value constants.
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Add handler for
ConstExprType to prevent ICE.
* backend/rust-compile-type.h: Declare visit method.
* typecheck/rust-hir-type-check-path.cc (is_const_dependent): New helper.
(TypeCheckExpr::resolve_root_path): Skip immediate resolution for
dependent const arguments.
(TypeCheckExpr::resolve_segments): Likewise.
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
Handle ConstKind::Expr in switch to prevent fallthrough.
* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit):
Implement cloning for ConstExprType.
* typecheck/rust-substitution-mapper.h: Add visit declarations.
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Implement stub
for ConstExprType.
* typecheck/rust-tyty-call.h: Declare visit method.
* typecheck/rust-tyty-variance-analysis-private.h (VisitorBase::visit):
Add stub implementation.
* typecheck/rust-tyty-visitor.h: Add virtual visit methods.
* typecheck/rust-tyty.cc (ConstExprType::const_kind): Implement.
(ConstExprType::accept_vis): Implement.
(ConstExprType::as_string): Implement.
(ConstExprType::clone): Implement.
(ConstExprType::is_equal): Implement.
(ConstExprType::get_expr): Implement.
* typecheck/rust-tyty.h (enum ConstKind): Add Expr variant.
(class ConstExprType): New class definition.
* typecheck/rust-unify.cc (UnifyRules::expect_const): Add unification
logic for ConstExprType.
gcc/testsuite/ChangeLog:
* rust/compile/issue-4302.rs: New test.
Signed-off-by: Jayant Chauhan <0001jayant@gmail.com>
dd8b3ad to
1c72456
Compare
Generic const expressions such as `{ N + 1 }` are symbolic and cannot be
evaluated to a concrete value immediately during type checking. Previously,
the compiler lacked a representation for these symbolic expressions in the
type system, causing it to treat them as concrete values. This led to
assertion failures and Internal Compiler Errors (ICE) in the backend and
path resolution logic when the compiler attempted to access the raw value.
This patch introduces `TyTy::ConstExprType`, a new type variant designed
to hold symbolic expressions that have not yet been evaluated. It updates
the core type system, substitution mapper, unification rules, call checkers,
and backend compilation visitors to handle this new type gracefully.
Key changes include:
1. Validating const generic arguments in path resolution to detect dependency
using the name resolver.
2. Bridging the substitution mapper to clone symbolic expressions.
3. Relaxing backend assertions to return `error_mark_node` for symbolic types.
4. Implementing identity-based unification for symbolic expressions.
Fixes Rust-GCC#4341
gcc/rust/ChangeLog:
* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve_with_node_id):
Relax assertion to return error_mark_node for non-value constants.
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Add handler for
ConstExprType to prevent ICE.
* backend/rust-compile-type.h: Declare visit method.
* typecheck/rust-hir-type-check-path.cc (is_const_dependent): New helper.
(TypeCheckExpr::resolve_root_path): Skip immediate resolution for
dependent const arguments.
(TypeCheckExpr::resolve_segments): Likewise.
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
Handle ConstKind::Expr in switch to prevent fallthrough.
* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit):
Implement cloning for ConstExprType.
* typecheck/rust-substitution-mapper.h: Add visit declarations.
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Implement stub
for ConstExprType.
* typecheck/rust-tyty-call.h: Declare visit method.
* typecheck/rust-tyty-variance-analysis-private.h (VisitorBase::visit):
Add stub implementation.
* typecheck/rust-tyty-visitor.h: Add virtual visit methods.
* typecheck/rust-tyty.cc (ConstExprType::const_kind): Implement.
(ConstExprType::accept_vis): Implement.
(ConstExprType::as_string): Implement.
(ConstExprType::clone): Implement.
(ConstExprType::is_equal): Implement.
(ConstExprType::get_expr): Implement.
* typecheck/rust-tyty.h (enum ConstKind): Add Expr variant.
(class ConstExprType): New class definition.
* typecheck/rust-unify.cc (UnifyRules::expect_const): Add unification
logic for ConstExprType.
gcc/testsuite/ChangeLog:
* rust/compile/issue-4302.rs: New test.
Signed-off-by: Jayant Chauhan <0001jayant@gmail.com>
1c72456 to
0ddabcf
Compare
Generic const expressions such as `{ N + 1 }` are symbolic and cannot be
evaluated to a concrete value immediately during type checking. Previously,
the compiler lacked a representation for these symbolic expressions in the
type system, causing it to treat them as concrete values. This led to
assertion failures and Internal Compiler Errors (ICE) in the backend and
path resolution logic when the compiler attempted to access the raw value.
This patch introduces `TyTy::ConstExprType`, a new type variant designed
to hold symbolic expressions that have not yet been evaluated. It updates
the core type system, substitution mapper, unification rules, call checkers,
and backend compilation visitors to handle this new type gracefully.
Key changes include:
1. Validating const generic arguments in path resolution to detect dependency
using the name resolver.
2. Bridging the substitution mapper to clone symbolic expressions.
3. Relaxing backend assertions to return `error_mark_node` for symbolic types.
4. Implementing identity-based unification for symbolic expressions.
Fixes Rust-GCC#4341
gcc/rust/ChangeLog:
* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve_with_node_id):
Relax assertion to return error_mark_node for non-value constants.
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Add handler for
ConstExprType to prevent ICE.
* backend/rust-compile-type.h: Declare visit method.
* typecheck/rust-hir-type-check-path.cc (is_const_dependent): New helper.
(TypeCheckExpr::resolve_root_path): Skip immediate resolution for
dependent const arguments.
(TypeCheckExpr::resolve_segments): Likewise.
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
Handle ConstKind::Expr in switch to prevent fallthrough.
* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit):
Implement cloning for ConstExprType.
* typecheck/rust-substitution-mapper.h: Add visit declarations.
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Implement stub
for ConstExprType.
* typecheck/rust-tyty-call.h: Declare visit method.
* typecheck/rust-tyty-variance-analysis-private.h (VisitorBase::visit):
Add stub implementation.
* typecheck/rust-tyty-visitor.h: Add virtual visit methods.
* typecheck/rust-tyty.cc (ConstExprType::const_kind): Implement.
(ConstExprType::accept_vis): Implement.
(ConstExprType::as_string): Implement.
(ConstExprType::clone): Implement.
(ConstExprType::is_equal): Implement.
(ConstExprType::get_expr): Implement.
* typecheck/rust-tyty.h (enum ConstKind): Add Expr variant.
(class ConstExprType): New class definition.
* typecheck/rust-unify.cc (UnifyRules::expect_const): Add unification
logic for ConstExprType.
gcc/testsuite/ChangeLog:
* rust/compile/issue-4302.rs: New test.
Signed-off-by: Jayant Chauhan <0001jayant@gmail.com>
0ddabcf to
c30c9a3
Compare
Generic const expressions such as `{ N + 1 }` are symbolic and cannot be
evaluated to a concrete value immediately during type checking. Previously,
the compiler lacked a representation for these symbolic expressions in the
type system, causing it to treat them as concrete values. This led to
assertion failures and Internal Compiler Errors (ICE) in the backend and
path resolution logic when the compiler attempted to access the raw value.
This patch introduces `TyTy::ConstExprType`, a new type variant designed
to hold symbolic expressions that have not yet been evaluated. It updates
the core type system, substitution mapper, unification rules, call checkers,
and backend compilation visitors to handle this new type gracefully.
Key changes include:
1. Validating const generic arguments in path resolution to detect dependency
using the name resolver.
2. Bridging the substitution mapper to clone symbolic expressions.
3. Relaxing backend assertions to return `error_mark_node` for symbolic types.
4. Implementing identity-based unification for symbolic expressions.
Fixes Rust-GCC#4341
gcc/rust/ChangeLog:
* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve_with_node_id):
Relax assertion to return error_mark_node for non-value constants.
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Add handler for
ConstExprType to prevent ICE.
* backend/rust-compile-type.h: Declare visit method.
* typecheck/rust-hir-type-check-path.cc (is_const_dependent): New helper.
(TypeCheckExpr::resolve_root_path): Skip immediate resolution for
dependent const arguments.
(TypeCheckExpr::resolve_segments): Likewise.
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
Handle ConstKind::Expr in switch to prevent fallthrough.
* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit):
Implement cloning for ConstExprType.
* typecheck/rust-substitution-mapper.h: Add visit declarations.
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Implement stub
for ConstExprType.
* typecheck/rust-tyty-call.h: Declare visit method.
* typecheck/rust-tyty-variance-analysis-private.h (VisitorBase::visit):
Add stub implementation.
* typecheck/rust-tyty-visitor.h: Add virtual visit methods.
* typecheck/rust-tyty.cc (ConstExprType::const_kind): Implement.
(ConstExprType::accept_vis): Implement.
(ConstExprType::as_string): Implement.
(ConstExprType::clone): Implement.
(ConstExprType::is_equal): Implement.
(ConstExprType::get_expr): Implement.
* typecheck/rust-tyty.h (enum ConstKind): Add Expr variant.
(class ConstExprType): New class definition.
* typecheck/rust-unify.cc (UnifyRules::expect_const): Add unification
logic for ConstExprType.
gcc/testsuite/ChangeLog:
* rust/compile/issue-4302.rs: New test.
Signed-off-by: Jayant Chauhan <0001jayant@gmail.com>
c30c9a3 to
78e425c
Compare
Generic const expressions such as `{ N + 1 }` are symbolic and cannot be
evaluated to a concrete value immediately during type checking. Previously,
the compiler lacked a representation for these symbolic expressions in the
type system, causing it to treat them as concrete values. This led to
assertion failures and Internal Compiler Errors (ICE) in the backend and
path resolution logic when the compiler attempted to access the raw value.
This patch introduces `TyTy::ConstExprType`, a new type variant designed
to hold symbolic expressions that have not yet been evaluated. It updates
the core type system, substitution mapper, unification rules, call checkers,
and backend compilation visitors to handle this new type gracefully.
Key changes include:
1. Validating const generic arguments in path resolution to detect dependency
using the name resolver.
2. Bridging the substitution mapper to clone symbolic expressions.
3. Relaxing backend assertions to return `error_mark_node` for symbolic types.
4. Implementing identity-based unification for symbolic expressions.
Fixes Rust-GCC#4341
gcc/rust/ChangeLog:
* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve_with_node_id):
Relax assertion to return error_mark_node for non-value constants.
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Add handler for
ConstExprType to prevent ICE.
* backend/rust-compile-type.h: Declare visit method.
* typecheck/rust-hir-type-check-path.cc (is_const_dependent): New helper.
(TypeCheckExpr::resolve_root_path): Skip immediate resolution for
dependent const arguments.
(TypeCheckExpr::resolve_segments): Likewise.
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
Handle ConstKind::Expr in switch to prevent fallthrough.
* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit):
Implement cloning for ConstExprType.
* typecheck/rust-substitution-mapper.h: Add visit declarations.
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Implement stub
for ConstExprType.
* typecheck/rust-tyty-call.h: Declare visit method.
* typecheck/rust-tyty-variance-analysis-private.h (VisitorBase::visit):
Add stub implementation.
* typecheck/rust-tyty-visitor.h: Add virtual visit methods.
* typecheck/rust-tyty.cc (ConstExprType::const_kind): Implement.
(ConstExprType::accept_vis): Implement.
(ConstExprType::as_string): Implement.
(ConstExprType::clone): Implement.
(ConstExprType::is_equal): Implement.
(ConstExprType::get_expr): Implement.
* typecheck/rust-tyty.h (enum ConstKind): Add Expr variant.
(class ConstExprType): New class definition.
* typecheck/rust-unify.cc (UnifyRules::expect_const): Add unification
logic for ConstExprType.
gcc/testsuite/ChangeLog:
* rust/compile/issue-4302.rs: New test.
Signed-off-by: Jayant Chauhan <0001jayant@gmail.com>
78e425c to
08efa26
Compare
Generic const expressions such as `{ N + 1 }` are symbolic and cannot be
evaluated to a concrete value immediately during type checking. Previously,
the compiler lacked a representation for these symbolic expressions in the
type system, causing it to treat them as concrete values. This led to
assertion failures and Internal Compiler Errors (ICE) in the backend and
path resolution logic when the compiler attempted to access the raw value.
This patch introduces `TyTy::ConstExprType`, a new type variant designed
to hold symbolic expressions that have not yet been evaluated. It updates
the core type system, substitution mapper, unification rules, call checkers,
and backend compilation visitors to handle this new type gracefully.
Key changes include:
1. Validating const generic arguments in path resolution to detect dependency
using the name resolver.
2. Bridging the substitution mapper to clone symbolic expressions.
3. Relaxing backend assertions to return `error_mark_node` for symbolic types.
4. Implementing identity-based unification for symbolic expressions.
Fixes Rust-GCC#4341
gcc/rust/ChangeLog:
* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve_with_node_id):
Relax assertion to return error_mark_node for non-value constants.
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Add handler for
ConstExprType to prevent ICE.
* backend/rust-compile-type.h: Declare visit method.
* typecheck/rust-hir-type-check-path.cc (is_const_dependent): New helper.
(TypeCheckExpr::resolve_root_path): Skip immediate resolution for
dependent const arguments.
(TypeCheckExpr::resolve_segments): Likewise.
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
Handle ConstKind::Expr in switch to prevent fallthrough.
* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit):
Implement cloning for ConstExprType.
* typecheck/rust-substitution-mapper.h: Add visit declarations.
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Implement stub
for ConstExprType.
* typecheck/rust-tyty-call.h: Declare visit method.
* typecheck/rust-tyty-variance-analysis-private.h (VisitorBase::visit):
Add stub implementation.
* typecheck/rust-tyty-visitor.h: Add virtual visit methods.
* typecheck/rust-tyty.cc (ConstExprType::const_kind): Implement.
(ConstExprType::accept_vis): Implement.
(ConstExprType::as_string): Implement.
(ConstExprType::clone): Implement.
(ConstExprType::is_equal): Implement.
(ConstExprType::get_expr): Implement.
* typecheck/rust-tyty.h (enum ConstKind): Add Expr variant.
(class ConstExprType): New class definition.
* typecheck/rust-unify.cc (UnifyRules::expect_const): Add unification
logic for ConstExprType.
gcc/testsuite/ChangeLog:
* rust/compile/issue-4302.rs: New test.
Signed-off-by: Jayant Chauhan <0001jayant@gmail.com>
08efa26 to
d4ba309
Compare
Generic const expressions such as `{ N + 1 }` are symbolic and cannot be
evaluated to a concrete value immediately during type checking. Previously,
the compiler lacked a representation for these symbolic expressions in the
type system, causing it to treat them as concrete values. This led to
assertion failures and Internal Compiler Errors (ICE) in the backend and
path resolution logic when the compiler attempted to access the raw value.
This patch introduces `TyTy::ConstExprType`, a new type variant designed
to hold symbolic expressions that have not yet been evaluated. It updates
the core type system, substitution mapper, unification rules, call checkers,
and backend compilation visitors to handle this new type gracefully.
Key changes include:
1. Validating const generic arguments in path resolution to detect dependency
using the name resolver.
2. Bridging the substitution mapper to clone symbolic expressions.
3. Relaxing backend assertions to return `error_mark_node` for symbolic types.
4. Implementing identity-based unification for symbolic expressions.
Fixes Rust-GCC#4341
gcc/rust/ChangeLog:
* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve_with_node_id):
Relax assertion to return error_mark_node for non-value constants.
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Add handler for
ConstExprType to prevent ICE.
* backend/rust-compile-type.h: Declare visit method.
* typecheck/rust-hir-type-check-path.cc (is_const_dependent): New helper.
(TypeCheckExpr::resolve_root_path): Skip immediate resolution for
dependent const arguments.
(TypeCheckExpr::resolve_segments): Likewise.
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
Handle ConstKind::Expr in switch to prevent fallthrough.
* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit):
Implement cloning for ConstExprType.
* typecheck/rust-substitution-mapper.h: Add visit declarations.
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Implement stub
for ConstExprType.
* typecheck/rust-tyty-call.h: Declare visit method.
* typecheck/rust-tyty-variance-analysis-private.h (VisitorBase::visit):
Add stub implementation.
* typecheck/rust-tyty-visitor.h: Add virtual visit methods.
* typecheck/rust-tyty.cc (ConstExprType::const_kind): Implement.
(ConstExprType::accept_vis): Implement.
(ConstExprType::as_string): Implement.
(ConstExprType::clone): Implement.
(ConstExprType::is_equal): Implement.
(ConstExprType::get_expr): Implement.
* typecheck/rust-tyty.h (enum ConstKind): Add Expr variant.
(class ConstExprType): New class definition.
* typecheck/rust-unify.cc (UnifyRules::expect_const): Add unification
logic for ConstExprType.
gcc/testsuite/ChangeLog:
* rust/compile/issue-4302.rs: New test.
Signed-off-by: Jayant Chauhan <0001jayant@gmail.com>
d4ba309 to
f816f7c
Compare
Generic const expressions such as `{ N + 1 }` are symbolic and cannot be
evaluated to a concrete value immediately during type checking. Previously,
the compiler lacked a representation for these symbolic expressions in the
type system, causing it to treat them as concrete values. This led to
assertion failures and Internal Compiler Errors (ICE) in the backend and
path resolution logic when the compiler attempted to access the raw value.
This patch introduces `TyTy::ConstExprType`, a new type variant designed
to hold symbolic expressions that have not yet been evaluated. It updates
the core type system, substitution mapper, unification rules, call checkers,
and backend compilation visitors to handle this new type gracefully.
Key changes include:
1. Validating const generic arguments in path resolution to detect dependency
using the name resolver.
2. Bridging the substitution mapper to clone symbolic expressions.
3. Relaxing backend assertions to return `error_mark_node` for symbolic types.
4. Implementing identity-based unification for symbolic expressions.
Fixes Rust-GCC#4341
gcc/rust/ChangeLog:
* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve_with_node_id):
Relax assertion to return error_mark_node for non-value constants.
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Add handler for
ConstExprType to prevent ICE.
* backend/rust-compile-type.h: Declare visit method.
* typecheck/rust-hir-type-check-path.cc (is_const_dependent): New helper.
(TypeCheckExpr::resolve_root_path): Skip immediate resolution for
dependent const arguments.
(TypeCheckExpr::resolve_segments): Likewise.
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
Handle ConstKind::Expr in switch to prevent fallthrough.
* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit):
Implement cloning for ConstExprType.
* typecheck/rust-substitution-mapper.h: Add visit declarations.
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Implement stub
for ConstExprType.
* typecheck/rust-tyty-call.h: Declare visit method.
* typecheck/rust-tyty-variance-analysis-private.h (VisitorBase::visit):
Add stub implementation.
* typecheck/rust-tyty-visitor.h: Add virtual visit methods.
* typecheck/rust-tyty.cc (ConstExprType::const_kind): Implement.
(ConstExprType::accept_vis): Implement.
(ConstExprType::as_string): Implement.
(ConstExprType::clone): Implement.
(ConstExprType::is_equal): Implement.
(ConstExprType::get_expr): Implement.
* typecheck/rust-tyty.h (enum ConstKind): Add Expr variant.
(class ConstExprType): New class definition.
* typecheck/rust-unify.cc (UnifyRules::expect_const): Add unification
logic for ConstExprType.
gcc/testsuite/ChangeLog:
* rust/compile/issue-4302.rs: New test.
Signed-off-by: Jayant Chauhan <0001jayant@gmail.com>
f816f7c to
89056db
Compare
Generic const expressions such as `{ N + 1 }` are symbolic and cannot be
evaluated to a concrete value immediately during type checking. Previously,
the compiler lacked a representation for these symbolic expressions in the
type system, causing it to treat them as concrete values. This led to
assertion failures and Internal Compiler Errors (ICE) in the backend and
path resolution logic when the compiler attempted to access the raw value.
This patch introduces `TyTy::ConstExprType`, a new type variant designed
to hold symbolic expressions that have not yet been evaluated. It updates
the core type system, substitution mapper, unification rules, call checkers,
and backend compilation visitors to handle this new type gracefully.
Key changes include:
1. Validating const generic arguments in path resolution to detect dependency
using the name resolver.
2. Bridging the substitution mapper to clone symbolic expressions.
3. Relaxing backend assertions to return `error_mark_node` for symbolic types.
4. Implementing identity-based unification for symbolic expressions.
Fixes Rust-GCC#4341
gcc/rust/ChangeLog:
* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve_with_node_id):
Relax assertion to return error_mark_node for non-value constants.
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Add handler for
ConstExprType to prevent ICE.
* backend/rust-compile-type.h: Declare visit method.
* typecheck/rust-hir-type-check-path.cc (is_const_dependent): New helper.
(TypeCheckExpr::resolve_root_path): Skip immediate resolution for
dependent const arguments.
(TypeCheckExpr::resolve_segments): Likewise.
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
Handle ConstKind::Expr in switch to prevent fallthrough.
* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit):
Implement cloning for ConstExprType.
* typecheck/rust-substitution-mapper.h: Add visit declarations.
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Implement stub
for ConstExprType.
* typecheck/rust-tyty-call.h: Declare visit method.
* typecheck/rust-tyty-variance-analysis-private.h (VisitorBase::visit):
Add stub implementation.
* typecheck/rust-tyty-visitor.h: Add virtual visit methods.
* typecheck/rust-tyty.cc (ConstExprType::const_kind): Implement.
(ConstExprType::accept_vis): Implement.
(ConstExprType::as_string): Implement.
(ConstExprType::clone): Implement.
(ConstExprType::is_equal): Implement.
(ConstExprType::get_expr): Implement.
* typecheck/rust-tyty.h (enum ConstKind): Add Expr variant.
(class ConstExprType): New class definition.
* typecheck/rust-unify.cc (UnifyRules::expect_const): Add unification
logic for ConstExprType.
gcc/testsuite/ChangeLog:
* rust/compile/issue-4302.rs: New test.
Signed-off-by: Jayant Chauhan <0001jayant@gmail.com>
89056db to
cbc657a
Compare
Generic const expressions such as `{ N + 1 }` are symbolic and cannot be
evaluated to a concrete value immediately during type checking. Previously,
the compiler lacked a representation for these symbolic expressions in the
type system, causing it to treat them as concrete values. This led to
assertion failures and Internal Compiler Errors (ICE) in the backend and
path resolution logic when the compiler attempted to access the raw value.
This patch introduces `TyTy::ConstExprType`, a new type variant designed
to hold symbolic expressions that have not yet been evaluated. It updates
the core type system, substitution mapper, unification rules, call checkers,
and backend compilation visitors to handle this new type gracefully.
Key changes include:
1. Validating const generic arguments in path resolution to detect dependency
using the name resolver.
2. Bridging the substitution mapper to clone symbolic expressions.
3. Updating backend type compilation (`TyTyResolveCompile`) to compile the
underlying expression tree for symbolic types instead of crashing.
4. Handling non-value constants in path resolution by emitting a specific
diagnostic ("cannot evaluate constant expression") before returning failure.
5. Updating existing tests to match the new `<const_expr>` string representation.
Fixes Rust-GCC#4341
gcc/rust/ChangeLog:
* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve_with_node_id):
Emit diagnostic and return error_mark_node for non-value constants.
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Compile the
underlying expression for ConstExprType.
* backend/rust-compile-type.h: Declare visit method.
* typecheck/rust-hir-type-check-path.cc (is_const_dependent): New helper.
(TypeCheckExpr::resolve_root_path): Skip immediate resolution for
dependent const arguments.
(TypeCheckExpr::resolve_segments): Likewise.
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
Handle ConstKind::Expr in switch to prevent fallthrough.
* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit):
Implement cloning for ConstExprType.
* typecheck/rust-substitution-mapper.h: Add visit declarations.
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Implement stub
for ConstExprType.
* typecheck/rust-tyty-call.h: Declare visit method.
* typecheck/rust-tyty-variance-analysis-private.h (VisitorBase::visit):
Add stub implementation.
* typecheck/rust-tyty-visitor.h: Add virtual visit methods.
* typecheck/rust-tyty.cc (ConstExprType::const_kind): Implement.
(ConstExprType::accept_vis): Implement.
(ConstExprType::as_string): Implement.
(ConstExprType::clone): Implement.
(ConstExprType::is_equal): Implement.
(ConstExprType::get_expr): Implement.
* typecheck/rust-tyty.h (enum ConstKind): Add Expr variant.
(class ConstExprType): New class definition.
* typecheck/rust-unify.cc (UnifyRules::expect_const): Add unification
logic for ConstExprType.
gcc/testsuite/ChangeLog:
* rust/compile/const_generics_10.rs: Update expected error messages to
match <const_expr> representation.
* rust/compile/issue-4302.rs: New test.
* rust/compile/const_generics_12.rs: Update expected error messages to
match <const_expr> representation.
Signed-off-by: Jayant Chauhan <0001jayant@gmail.com>
Fixes #4302
ResolvePathRef::resolve_with_node_id assumed CONST types were always concrete values and asserted otherwise. Generic const expressions such as
{ N + 1 }are symbolic and cannot be evaluated prior to monomorphization, leading to an internal compiler error.Reject non-value const kinds gracefully and emit a diagnostic instead of aborting.
gcc/testsuite:
* rust/compile/const-generic-ice-4302.rs: New test.
Thank you for making Rust GCC better!
If your PR fixes an issue, you can add "Fixes #issue_number" into this
PR description and the git commit message. This way the issue will be
automatically closed when your PR is merged. If your change addresses
an issue but does not fully fix it please mark it as "Addresses #issue_number"
in the git commit message.
Here is a checklist to help you with your PR.
make check-rustpasses locallyclang-formatgcc/testsuite/rust/Note that you can skip the above if you are just opening a WIP PR in
order to get feedback.
*Please write a comment explaining your change. This is the message
that will be part of the merge commit.