Commit Graph

192831 Commits

Author SHA1 Message Date
liushuyu 461bf1369f
CI: catch malformed test cases
Signed-off-by: Zixing Liu <liushuyu011@gmail.com>
2022-04-25 16:08:24 -06:00
bors[bot] b74044fb62
Merge #1164
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>
2022-04-25 19:14:00 +00:00
Arthur Cohen d0c75495dd ast: Visibility: Add `has_path` method 2022-04-25 16:56:31 +02:00
Arthur Cohen 5536d36307 ast: SimplePath{Segment}: Add NodeId fields 2022-04-25 16:56:24 +02:00
bors[bot] 2b1cb4ba86
Merge #1161
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>
2022-04-25 11:10:22 +00:00
bors[bot] d54ca71685
Merge #1160
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>
2022-04-25 10:36:08 +00:00
Arthur Cohen 23db789ecb resolver: Move Scope methods into source file 2022-04-25 12:34:13 +02:00
bors[bot] bbbd15a4a1
Merge #1156
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>
2022-04-25 10:01:03 +00:00
bors[bot] f562d738ef
Merge #1149
1149: backend: handle no_mangle attribute r=philberty a=liushuyu

- handle the `no_mangle` attribute

Co-authored-by: liushuyu <liushuyu011@gmail.com>
2022-04-25 08:51:51 +00:00
antego e26b95f64a Following up on #1141. Implementing macro expansion or ComparisonExpr, LazyBooleanExpr, AssignmentExpr. 2022-04-23 10:59:44 +10:00
liushuyu 49c0eeb670
tests/attr_cold: fix a typo 2022-04-22 16:29:26 -06:00
liushuyu a969ab61ad backend: address comments about no_mangle 2022-04-22 16:17:40 -06:00
liushuyu af7622f219 backend: handle no_mangle attribute 2022-04-22 16:16:37 -06:00
Arthur Cohen 8466c9b162 resolver: Move Resolver methods into own source file 2022-04-22 16:34:55 +02:00
Arthur Cohen 3001bb64cc resolver: Refactor Rib class in a source file 2022-04-22 16:28:26 +02:00
bors[bot] 1286acc34e
Merge #1157
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>
2022-04-22 14:00:50 +00:00
Arthur Cohen 159ffebb20 privacy: visibility: Add remaining visitors for simple items 2022-04-22 15:36:44 +02:00
bors[bot] a936265bb0
Merge #1150
1150: backend: handle link_section attribute r=philberty a=liushuyu

- handle the `link_section` attribute

Co-authored-by: liushuyu <liushuyu011@gmail.com>
2022-04-22 13:32:20 +00:00
bors[bot] 4337aea3be
Merge #1155
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>
2022-04-22 12:15:22 +00:00
Arthur Cohen bdd1b86ccb privacy: ModuleVis: Constify accessor functions
Co-authored-by: philberty <philip.herron@embecosm.com>
2022-04-22 13:46:46 +02:00
bors[bot] b392376cc5
Merge #1154
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>
2022-04-22 11:45:59 +00:00
Arthur Cohen c3a81139f7 privacy: visibility: Assert on module stack instead
Co-authored-by: philberty <philip.herron@embecosm.com>
2022-04-22 13:18:30 +02:00
liushuyu f6194707a6
backend: handle link_section attribute 2022-04-22 05:17:09 -06:00
bors[bot] d541ded485
Merge #1148
1148: backend: handle cold attribute r=philberty a=liushuyu

- handle the `cold` attribute

Co-authored-by: liushuyu <liushuyu011@gmail.com>
2022-04-22 10:34:59 +00:00
Arthur Cohen 3e3c0660cb privacy: visibility: Insert enum/traits and their subitems properly 2022-04-22 12:31:58 +02:00
Arthur Cohen cae1e87339 privacy: visibility: Handle modules properly 2022-04-22 12:31:58 +02:00
Arthur Cohen 7be856f7b6 privacy: visibility: Add resolving for "private" items 2022-04-22 12:31:58 +02:00
Arthur Cohen 77afec780a privacy: visibility: Add base for ModuleVisibility resolver 2022-04-22 12:23:21 +02:00
Arthur Cohen ca59275cc9 privacy: Add base for visibility map of DefIds 2022-04-22 12:23:21 +02:00
Arthur Cohen e70aa7f262 hir: Fix documentation on previously changed Visibility struct 2022-04-22 12:23:21 +02:00
Arthur Cohen bfe8ffef86 privacy: Add ModuleVisibility class 2022-04-22 12:23:21 +02:00
bors[bot] 75ac2f6fc0
Merge #1147
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>
2022-04-22 10:04:28 +00:00
bors[bot] f0b6dca3fc
Merge #1145
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>
2022-04-22 09:31:08 +00:00
Philip Herron 7915329a0c Add support for isize and usize type-hints
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
2022-04-22 10:24:46 +01:00
liushuyu 16730054de
backend: handle cold attribute 2022-04-21 17:30:52 -06:00
bors[bot] 243ef0dfe7
Merge #1139
1139: hir: improve doc attribute handling r=philberty a=liushuyu

- hir: improve doc attribute handling

Addresses #1140

Co-authored-by: liushuyu <liushuyu011@gmail.com>
2022-04-21 19:25:01 +00:00
Philip Herron 639b3d61ab Add missing coercion rule from array to slice
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
2022-04-21 20:20:24 +01:00
Philip Herron 0d4fc557c7 Fix generic param redefined bug
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
2022-04-21 18:57:24 +01:00
bors[bot] cb42c3674a
Merge #1144
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>
2022-04-21 17:24:27 +00:00
Philip Herron dd9e4c1e0c Add name and type resolution for TuplePatterns
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
2022-04-21 16:06:18 +01:00
Philip Herron fe10ca37ab Handle parsing match arms with no comma
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
2022-04-21 12:13:33 +01:00
bors[bot] fc22f12c9c
Merge #1119
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>
2022-04-21 08:13:19 +00:00
antego 9a56a0d10d Add a test for the cfg!() macro
See #1116 and #1039
2022-04-21 09:02:52 +10:00
Philip Herron c18257c726 Add HIR Lowering for TuplePattern 2022-04-20 18:04:42 +01:00
Philip Herron 53ce1d5ac9 Add ExprStmt::ExprStmtType WITH_BLOCK and WITHOUT_BLOCK to allow switching 2022-04-20 18:03:41 +01:00
Philip Herron 4eaec85303 Add AST::TuplePatternItems::TuplePatternItemType to differentiate between them 2022-04-20 18:03:15 +01:00
Philip Herron 03ec66cf11 Remove bad has-minus flag which should be contained within AST::Literal 2022-04-20 18:02:22 +01:00
liushuyu a1c34b478f
hir: improve doc attribute handling ...
... should fix #1125

Signed-off-by: Zixing Liu <liushuyu011@gmail.com>
2022-04-20 02:56:36 -06:00
bors[bot] 14dbac9a8b
Merge #1138
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>
2022-04-20 08:33:46 +00:00
bors[bot] dc57f4ced0
Merge #1137
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>
2022-04-20 06:51:19 +00:00