1134: Fix ICE during HIR lowering of ExprWithBlock MatchExpr r=philberty a=philberty
When we are lowering blocks using the visitor pattern we must use the
BaseClass of ExprWithBlock to abstract away the notion that this expr
has a block such that we can handle cases like a block expr vs expressions
with a block. This makes the usage of hir lowering of match expressions to
be recursive, if we had more fine grained visitors in the AST we could fix
these types of problems with compile time enforced interfaces.
Fixes#858
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
1121: Fix bad projection substitution r=philberty a=philberty
When we have a Trait such as:
```
pub unsafe trait SliceIndex<T> {
type Output;
fn index(self, slice: &T) -> &Self::Output;
}
unsafe impl<T> SliceIndex<[T]> for Range<usize> {
type Output = [T];
fn index(self, slice: &[T]) -> &[T] {
unsafe { &*self.get_unchecked(slice) }
}
}
```
When we need to verify that the impl index is compatible fir SliceIndex we
get the Type info for the trait-item which is:
fn<Self, T> index(self: Self, slice: &T)
-> &<placeholder=projection<T>=[T]>
This projection gets setup and the types are substituted with
Self=Range<usize> and T=[T] which ended up substituting the projection
twice resulting in a recursive slice [T=[T]]. In this case the associated
type is already setup for the placeholder and does not require generic
substitution. This means we added a flag to the substitution generic
arguments mappings to handle this case.
This patch also addressed memory corruption with the TypeBoundPredicate
as part of the debugging of this issue which resulted in a segv when
trying to debug the mappings. The issue was the copy constructors needed
to update the used argument mappings each time since the substitution param
mappings are copied and the addresses no longer exist, valgrind was great
here to find this issue.
Fixes#1120
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
This reuses our code to handle match-arams within MatchExpressions, we
resolve the pattern's type's and implicitly create types for that binding.
For code-generation we create a tmp var name for the name of the parameter
which is the base type and for the destructuring we reuse the same match
arm code to generate the implicit bindings to the parts of the structure
```c
__attribute__((cdecl))
i32 test::pattern_as_arg (const struct test::Pattern RSTPRM.0)
{
i32 RUSTTMP.1;
return RSTPRM.0.0;
}
```
Fixes#995
When we are lowering blocks using the visitor pattern we must use the
BaseClass of ExprWithBlock to abstract away the notion that this expr
has a block such that we can handle cases like a block expr vs expressions
with a block. This makes the usage of hir lowering of match expressions to
be recursive, if we had more fine grained visitors in the AST we could fix
these types of problems with compile time enforced interfaces.
Fixes#858
1124: CI: do not push Docker image in a fork r=philberty a=liushuyu
- ci: skip docker image push when in a fork
Co-authored-by: liushuyu <liushuyu011@gmail.com>
1118: Add reachability visitor to Enum variants r=CohenArthur a=CohenArthur
This visits all of an enum's variants and their fields if present. To do that properly, this adds a new `EnumItemKind` enum which allows static casting when visiting each variant of the enum (kept as an `EnumItem` class which is derived three times)
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
1107: tests: Improve timeout handling r=philberty a=liushuyu
- add a 10-second timeout for individual compile test
- add a xfail test case to ensure the timeout mechanism is working
Co-authored-by: liushuyu <liushuyu011@gmail.com>
When we have a Trait such as:
```
pub unsafe trait SliceIndex<T> {
type Output;
fn index(self, slice: &T) -> &Self::Output;
}
unsafe impl<T> SliceIndex<[T]> for Range<usize> {
type Output = [T];
fn index(self, slice: &[T]) -> &[T] {
unsafe { &*self.get_unchecked(slice) }
}
}
```
When we need to verify that the impl index is compatible fir SliceIndex we
get the Type info for the trait-item which is:
fn<Self, T> index(self: Self, slice: &T)
-> &<placeholder=projection<T>=[T]>
This projection gets setup and the types are substituted with
Self=Range<usize> and T=[T] which ended up substituting the projection
twice resulting in a recursive slice [T=[T]]. In this case the associated
type is already setup for the placeholder and does not require generic
substitution. This means we added a flag to the substitution generic
arguments mappings to handle this case.
This patch also addressed memory corruption with the TypeBoundPredicate
as part of the debugging of this issue which resulted in a segv when
trying to debug the mappings. The issue was the copy constructors needed
to update the used argument mappings each time since the substitution param
mappings are copied and the addresses no longer exist, valgrind was great
here to find this issue.
Fixes#1120
1116: Move `cfg!()` macro to builtins. Fixes#1039 r=CohenArthur a=antego
Fixes#1039
Hey team, I need help understanding why the test fails.
Compilation succeeds, all the existing tests pass. However the test that I've added fails with the error:
```
FAIL: rust/compile/cfg_macro.rs (test for excess errors)
Excess errors:
/Users/anton/Documents/projects/gcc2/gccrs/gcc/testsuite/rust/compile/cfg_macro.rs:17:8: fatal error: Failed to lower expr: [MacroInvocation:
outer attributes: none
cfg!((A))
has semicolon: false]
compilation terminated.
```
I tried to understand what's happening using a debugger. The only thing that I understood is that the `MacroBuiltin::cfg` function runs.
Appreciate any feedback.
Thank you.
Co-authored-by: antego <antego@users.noreply.github.com>
1110: Add Reachability visitors for items with generics r=CohenArthur a=CohenArthur
This factors generics' predicates visiting in the `ReachabilityVisitor` and calls the function in other items with generic parameters
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
1088: rust-session-manager: better crate name handling logic r=philberty a=liushuyu
- rust-session-manager: set and validate crate name properly
- testsuite/rust: fix the testcases and add more testcases for testing crate name handling
Co-authored-by: liushuyu <liushuyu011@gmail.com>
1111: Add AST Private Visibilities r=CohenArthur a=CohenArthur
When parsing a visibility in `parse_visibility`, it is not an error to
not have a pub token: It simply means we want to create a private
visibility. If we had C++14 or another language, we could instead
represent all visibilities as an optional<AST::Visibility> where the
Visibility class would not need to change. But I think the best course
of action for our case is to instead keep visibilities even when they
are private and have a special case in the `VisKind` enumeration.
This also enables HIR lowering of visibilities to be performed properly for private items
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
1114: rust: Use -Otarget when building and logging warnings r=philberty a=simonpcook
This will provide some synchronization for output lines, and so will
make comparisons with known warnings as part of CI more reliable.
Co-authored-by: Simon Cook <simon.cook@embecosm.com>
When parsing a visibility in `parse_visibility`, it is not an error to
not have a pub token: It simply means we want to create a private
visibility. If we had C++14 or another language, we could instead
represent all visibilities as an optional<AST::Visibility> where the
Visibility class would not need to change. But I think the best course
of action for our case is to instead keep visibilities even when they
are private and have a special case in the `VisKind` enumeration.
1112: rust: Clang/macOS Testing r=philberty a=simonpcook
This adds a version of the build-and-check job that runs with clang on
macOS.
Co-authored-by: Simon Cook <simon.cook@embecosm.com>
1109: rust: Allow gccrs to build on x86_64-apple-darwin with clang/libc++ r=CohenArthur a=simonpcook
This makes changes to the includes such that gccrs can be built with
clang/libc++, and for x86_64-apple-darwin. Similarly, a couple of
changes have been made to creating MacroInvocations and wrapping into
ExprOrStmts for libc++ compatibility.
Co-authored-by: Simon Cook <simon.cook@embecosm.com>
This makes changes to the includes such that gccrs can be built with
clang/libc++, and for x86_64-apple-darwin. Similarly, a couple of
changes have been made to creating MacroInvocations and wrapping into
ExprOrStmts for libc++ compatibility.
1082: Add base for privacy visitor r=CohenArthur a=CohenArthur
This PR is extremely early and implements some building blocks for privacy visitors. I'd like to get some feedback on the architecture and, if satisfactory, merge this first "visitor" which only takes care of visiting HIR struct definitions, to make reviewing easier. We could also merge it to a different branch for now, in order to not add an incomplete pass to the compiler.
Thanks!
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
1108: Add missing unify rules for inference variables r=philberty a=philberty
Inference variables can unify with anything so this includes these
covariant types like references/slices etc. This patch is needed for more
complex type-checking in libcore and generics.
Co-authored-by: Philip Herron <philip.herron@embecosm.com>