Commit Graph

192831 Commits

Author SHA1 Message Date
bors[bot] f6e244dc0e
Merge #1134
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>
2022-04-19 17:01:25 +00:00
bors[bot] 4152743451
Merge #1121
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>
2022-04-19 16:33:48 +00:00
Philip Herron c3a3e1053f Support pattern bindings within function signitures
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
2022-04-19 17:00:32 +01:00
Arthur Cohen 038677dd83 ast: lower: Split rust-lower-base in its own source file 2022-04-19 17:53:37 +02:00
Philip Herron 5528001eca Fix ICE during HIR lowering of ExprWithBlock MatchExpr
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
2022-04-19 12:43:21 +01:00
bors[bot] 5b14291b54
Merge #1124
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>
2022-04-19 09:37:52 +00:00
bors[bot] 321be1b3c9
Merge #1096
1096: macros: add include! macro r=CohenArthur a=liushuyu

- add `include!` macro

Co-authored-by: liushuyu <liushuyu011@gmail.com>
2022-04-19 09:08:38 +00:00
liushuyu f876cba554
macros: save included filename into session manager 2022-04-19 01:46:26 -06:00
liushuyu 82c045ecfe
CI: do not push Docker image ...
... when the workflow is ran in a forked repository

Signed-off-by: Zixing Liu <liushuyu011@gmail.com>
2022-04-18 03:41:07 -06:00
liushuyu e753fa4e36
macros: add include! macro 2022-04-17 17:35:57 -06:00
bors[bot] 27ad3813dc
Merge #1122
1122: testsuite/rust: fix test case failure on macOS r=CohenArthur a=liushuyu

- extent `macro_return` xfail targets to three-segment triples

Co-authored-by: liushuyu <liushuyu011@gmail.com>
2022-04-16 10:05:42 +00:00
bors[bot] e76b639955
Merge #1118
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>
2022-04-16 09:37:42 +00:00
liushuyu f5f11bef14
testsuite/rust: extent xfail targets 2022-04-15 21:01:23 -06:00
bors[bot] 042c875024
Merge #1107
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>
2022-04-15 21:08:17 +00:00
Philip Herron ad9e185e15 Fix bad projection substitution
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
2022-04-15 21:23:28 +01:00
bors[bot] d17e0aa769
Merge #1116
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>
2022-04-15 08:54:55 +00:00
antego a9c0649503 Move cfg!() macro to builtins
Fixes #1039
2022-04-15 07:31:32 +10:00
Arthur Cohen c4443ca3b2 privacy: reachability: Visit all variants of an Enum and their fields 2022-04-14 10:50:02 +02:00
Arthur Cohen 126f7aecdc hir: Add `EnumItemKind` enum for EnumItem classes 2022-04-14 10:49:19 +02:00
Arthur Cohen 71f2cd57c6 privacy: reachability: wip: Update all base reach levels 2022-04-14 10:01:41 +02:00
bors[bot] d36a3c5752
Merge #1110
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>
2022-04-14 07:27:52 +00:00
bors[bot] 73e017f7cb
Merge #1113
1113: macros: Add env! macro r=CohenArthur a=omachota

Added the `env!()` macro and relevant test cases

Fixes: #977 

Signed-off-by: Ondřej Machota <ondrejmachota@gmail.com>

Co-authored-by: Ondřej Machota <ondrejmachota@gmail.com>
2022-04-14 06:56:37 +00:00
Ondřej Machota 1e6e427696 macros: Add env! macro
Signed-off-by: Ondřej Machota <ondrejmachota@gmail.com>
2022-04-13 23:24:53 +02:00
bors[bot] 60324125c3
Merge #1088
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>
2022-04-13 14:17:42 +00:00
Arthur Cohen ed904fefdd privacy: reachability: Add base visitor for items with generic params
Co-authored-by: philberty <philip.herron@embecosm.com>
2022-04-13 13:15:30 +02:00
Arthur Cohen cdfb5b34ac privacy: reachability: Cleanup Struct definition visitor 2022-04-13 13:15:10 +02:00
bors[bot] 497ee70b77
Merge #1111
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>
2022-04-13 10:41:12 +00:00
bors[bot] c1639be8bb
Merge #1114
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>
2022-04-13 10:10:21 +00:00
liushuyu a125901c55
rust-session-manager: address more comments
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Signed-off-by: Zixing Liu <liushuyu011@gmail.com>
2022-04-13 02:30:46 -06:00
Arthur Cohen 03cb435c19 visibility: Add create_private() static function
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.
2022-04-13 09:04:26 +02:00
bors[bot] a196568774
Merge #1112
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>
2022-04-13 06:43:54 +00:00
Simon Cook addf65ddfa rust: Use -Otarget when building and logging warnings
This will provide some synchronization for output lines, and so will
make comparisons with known warnings as part of CI more reliable.
2022-04-13 08:34:30 +02:00
liushuyu 1a7391d97f rust-session-manager: address comments ...
... also more closely match rustc's behavior

Signed-off-by: Zixing Liu <liushuyu011@gmail.com>
2022-04-12 18:37:09 -06:00
liushuyu 28769ea0ab testsuite/rust: adapt/fix the testcases ...
... so that the tests will still pass after the crate name logic change

Signed-off-by: Zixing Liu <liushuyu011@gmail.com>
2022-04-12 18:34:54 -06:00
liushuyu f50e9a27b2 rust-session-manager: set and validate crate name properly ...
... should fix #789

Signed-off-by: Zixing Liu <liushuyu011@gmail.com>
2022-04-12 18:34:54 -06:00
Simon Cook 649f6640c6 rust: Clang/macOS Testing
This adds a version of the build-and-check job that runs with clang on
macOS.
2022-04-12 18:03:58 +02:00
bors[bot] e9ab95c088
Merge #1109
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>
2022-04-12 15:04:30 +00:00
Simon Cook 1a3f38a2b0 rust: Allow gccrs to build on x86_64-apple-darwin with clang/libc++
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.
2022-04-12 16:45:56 +02:00
bors[bot] 7430791e0f
Merge #1082
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>
2022-04-12 14:32:53 +00:00
bors[bot] 2076e69bf9
Merge #1108
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>
2022-04-12 14:03:11 +00:00
bors[bot] c494f30766
Merge #1106
1106: macros: fix an infinite loop in `concat!` macro parser r=CohenArthur a=liushuyu

- Fix concat macro parser issue which caused an infinite loop when invalid token is encountered


Co-authored-by: liushuyu <liushuyu011@gmail.com>
2022-04-12 13:28:28 +00:00
Arthur Cohen 1e5126022d privacy: reachability: Visit all types of a struct's public fields 2022-04-12 15:26:11 +02:00
Arthur Cohen 3058b55328 privacy: reachability: Visit all struct generic predicates 2022-04-12 15:26:11 +02:00
Arthur Cohen 415586f0e2 typectx: Mark lookup_type() method as const 2022-04-12 15:26:11 +02:00
Arthur Cohen ece3809c50 privacy: Keep DefIds in reachability map instead
This commit also specialized `std::hash<DefId>` to be able to use it as
key in {unordered_}maps
2022-04-12 15:26:11 +02:00
Arthur Cohen a376e1939e hir: Keep BaseKind enum inside the Node class
Co-authored-by: philberty <philip.herron@embecosm.com>
2022-04-12 15:26:11 +02:00
Arthur Cohen be8f2ead95 privacy: reachability: Add base for visiting struct definitions 2022-04-12 15:26:11 +02:00
Arthur Cohen d103151143 hir: StructField: Add `get_visibility()` method 2022-04-12 15:26:11 +02:00
Arthur Cohen 6db5c9fb19 privacy: reachability: Add better implementation for StructStruct 2022-04-12 15:26:08 +02:00
Arthur Cohen 3bb4d746a0 privacy: reachability: Add `maybe_get_vis_item` helper static function 2022-04-12 15:25:37 +02:00