1164: Add `NodeId`s to `SimplePath{Segment}`s r=CohenArthur a=CohenArthur
This is a necessary first step which addresses #1158
I am working on the visibility resolver and simple-path name resolver in parallel and will need those changes.
I'm not sure if the `has_path` method is necessary since we will have `HIR::Visibilities` in the visibility resolver, which will be desugared. Maybe I am doing this wrong and we should be working on `AST::Visibilities` instead?
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
1161: Implement macro expansion for ComparisonExpr, LazyBooleanExpr, AssignmentExpr r=CohenArthur a=antego
Following up on https://github.com/Rust-GCC/gccrs/issues/1141
Currently the macro expansion doesn't work for ComparisonExpr, LazyBooleanExpr, AssignmentExpr. To fix this, I just copied the code from the `ArithmeticOrLogicalExpr` and it seemed to work. I don't like the code duplication, happy to try refactoring it into a separate function.
Will work on the macro expansion in the `if` expressions next.
Co-authored-by: antego <antego@users.noreply.github.com>
1160: Refactor name resolver r=CohenArthur a=CohenArthur
This PR splits up the `rust-name-resolver.h` file into source and header. It also removes a bunch of `iterate_*` functions: Some were not used anymore, and some were refactored.
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
1156: tests/attr_cold: fix a typo r=philberty a=liushuyu
- fix a typo in the `rust/compile/attr_cold.rs` file
Co-authored-by: liushuyu <liushuyu011@gmail.com>
1157: Resolve remaining simple visibilites r=CohenArthur a=CohenArthur
Based on #1155, so you can review just the last commit.
This adds the remaining simple visitors for visibility resolving, as well as a helper method for doing so.
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
1155: Add base for visibility resolving r=CohenArthur a=CohenArthur
This adds a new visitor whose aim is to resolve the visibility of each VisItem in a crate. The crux of the implementation will be resolving `pub restricted` items, whose module needs to be resolved using name resolution/path resolution. On top of that, we will need to add a new visitor building a "tree" of modules, with a `accessible_from` or `is_child_of` method: All children of a module get to access its items whose visibility is inherited.
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
1154: Add support for isize and usize type-hints r=philberty a=philberty
This bug turned out to be that we expected a usize for the array capacity
but the specified capacity turned out to be an integer inference variable
which will default to a signed integer. The type resolution was missing
handling the type-hints of isize and usize
Fixes#1152
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
1147: Add missing coercion rule from array to slice r=philberty a=philberty
Arrays are coercible into slices, this adds the missing type-resolution
the rule which works for now. The other part of this fix is described in #1146
for coercion_site to be recursive and reuse the adjustment classes so that
we reuse as much code as possible and handle complex coercion sites.
Fixes#1129
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
1145: Fix generic param redefined bug r=philberty a=philberty
When we name-resolve generic parameters their declaration gets inserted in
to the upper-most rib on the stack. Then when this is referenced we lookup
the relevant binding starting from the uppermost rib this lead to the 2nd
extern item adding the same binding into the same rib which caused this
clash. To fix this we need to have a seperate rib for each declaration
so as reusing the same names don't clash with each other.
Fixes#1131
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
This bug turned out to be that we expected a usize for the array capacity
but the specified capacity turned out to be an integer inference variable
which will default to a signed integer. The type resolution was missing
handling the type-hints of isize and usize
Fixes#1152
Arrays are coercible into slices, this adds the missing type-resolution
the rule which works for now. The other part of this fix is described in
so that we reuse as much code as possible and handle complex coercion
sites.
Fixes#1129
When we name-resolve generic parameters their declaration gets inserted in
to the upper-most rib on the stack. Then when this is referenced we lookup
the relevant binding starting from the uppermost rib this lead to the 2nd
extern item adding the same binding into the same rib which caused this
clash. To fix this we need to have a seperate rib for each declaration
so as reusing the same names don't clash with each other.
Fixes#1131
1144: Add name and type resolution support TuplePatterns in MatchArms r=philberty a=philberty
This adds support for the name and type resolution of match expressions. The code generation
and checks for all cases possible cases needs more thought so this will be done as part of a
separate PR.
Addresses #1081
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
This adds the relevant pattern resolution steps to match up the
TuplePattern. This patch leaves out type resolution on TupleRange Patterns
for now. Some thought is needed to figure out how do have a canonical
algorithm for code-generation here so splitting this up makes sense for
now.
This patch extracts the type-resolution handling for HIR::LiteralExpr
to have a generic function to resolve the HIR::Literal which is used within
HIR::LiteralExpr and HIR::LiteralPattern.
Addresses #1081
When parsing a match expression such as:
```
match (f, g) {
(Foo::A, 1) => {}
(Foo::B, 2) => {}
_ => {}
}
```
The first match arm here has an empty block expression of {}. This was
being parsed into a CallExpr of {}(Foo::B, 2) which is wrong. The parsing
of match arms are expression statements so they can be a block but must not
consume the semi-colon as it is valid to have a comma to delimit the match
arm or it can be ignored if this is a ExprWithBlock.
Addresses #1081
1119: Add a test for the cfg!() macro r=CohenArthur a=antego
See #1116 and #1039
Adding a test for the cfg!() macro. The compilation of the test fails with the message:
```
fatal error: Failed to lower expr: [MacroInvocation:
outer attributes: none
cfg!((A))
has semicolon: false]
compilation terminated.
```
Co-authored-by: antego <antego@users.noreply.github.com>
1138: Support pattern bindings within function signitures r=philberty a=philberty
This reuses our code to handle match-arms 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
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
1137: ast: lower: Split rust-lower-base in its own source file r=CohenArthur a=CohenArthur
The implementation of all functions declared in `rust-ast-lower-base.h` was a big offender of our "definitions in headers" problem, spanning over 900 lines of code. We can do the same for basically all headers in `gcc/rust/hir` which all contain some definitions that have accumulated over time
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>