Commit Graph

192725 Commits

Author SHA1 Message Date
Philip Herron 7a3c935c0f Check if this constant item might already be compiled 2022-03-07 12:06:20 +00:00
bors[bot] 366c53371a
Merge #991
991: Match and expand macro separators properly r=CohenArthur a=CohenArthur

More nice recursive macros:
```rust
macro_rules! add {
    ($e:expr | $($es:expr) | *) => {
        $e + add!($($es) | *)
    };
    ($e:expr) => {
        $e
    };
}

add!(1 | 2 | 3 | 4 | 5 | 6);
```
Closes #968

This PR needs #986 to be merged first, as it depends on it for the test cases. You can skip reviewing the first two commits which are just from #986 

Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-03-07 08:47:19 +00:00
bors[bot] b82408fd6a
Merge #986
986: Fix ICE on recursive macro invocation r=CohenArthur a=CohenArthur

Closes #982 

We can now do fancy lispy things!
```rust
macro_rules! add {
    ($e:literal) => {
        0 + $e
    };
    ($e:literal $($es:literal)*) => {
        $e + add!($($es)*)
    };
}
```

I've switched the order of the commits around so that the buildbot is happy

Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-03-06 21:24:24 +00:00
bors[bot] e2bccf43ed
Merge #985
985: Parse macro!(); as MacroInvocation with semicolon r=CohenArthur a=CohenArthur

When parsing a macro invocation as a statement, the parser would parse
an expression and then try parsing a semicolon. Since no actual
lookahead was done (which is a good thing), we couldn't convert a
`MacroInvocation` to a `MacroInvocationSemi` after the fact.

Since, unlike function calls, macro invocations can act differently
based on whether or not they are followed by a semicolon, we actually
need to differentiate between the two up until expansion.

This commits adds a new virtual method for ExprWithoutBlock when
converting to ExprStmtWithoutBlock so that classes inheriting
ExprWithoutBlock can specify a new behavior. In the case of our
MacroInvocation class, it simply means toggling a boolean: If we're
converting a macro from an expression to a statement, it must mean that
it should contain a semicolon.

Closes #941 

Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-03-06 20:50:55 +00:00
bors[bot] d89c8ccf32
Merge #990
990: Add must use attribute support r=philberty a=philberty

This is a port of the CPP front-end nodiscard attribute to be used for
must_use. It contains a patch to clean up how we handle expressions vs
statements and removes more of the GCC abstraction. Its my hope that we
can leverage more and more existing code to get the static analysis where
we want it.

Fixes #856 

Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2022-03-04 11:58:45 +00:00
bors[bot] b4bd389c66
Merge #984
984: Implimented Soluion 1 and solution 2 for issue_734 r=philberty a=mvvsmk

Fixes #734 
Done :
- [x]  Remove iterate_params function
- [x] Create new get_params function

Solution 1
1) Created a new get_params function which returns the parameters.
2) Changed the references of the iterate_params to use get_params.

Solution 2
1) Added get_params2 which returns `std::vector<TyTy::BaseType*>`
2) Changed the references of the iterate_params to use get_params.

Status :  
Currently I have implemented the first solution. 

Signed-off-by : M V V S Manoj Kumar <mvvsmanojkumar@gmail.com>


Co-authored-by: M V V S Manoj Kumar <mvvsmanojkumar@gmail.com>
2022-03-04 11:30:52 +00:00
M V V S Manoj Kumar 3f2d5a720b Got rid of lambda in TyTy::FnPtr iterate_params
Fixes issue #734
1)Removed iterate_params function
2)Created a get_params function which returns std::vector& params

Signed-off-by : M V V S Manoj Kumar <mvvsmanojkumar@gmail.com>
2022-03-04 08:27:22 +05:30
Arthur Cohen 0c7e16e125 macros: Add test cases for macro repetition separators 2022-03-03 15:21:09 +01:00
Arthur Cohen 4fde21b37a macros: Substitute separator if necessary when expanding repetitions 2022-03-03 15:21:03 +01:00
Arthur Cohen ab4533dab7 macros: Match repetition separator properly 2022-03-03 15:20:55 +01:00
Arthur Cohen 25a33b0739 macros: Add test cases for recursive macro invocation 2022-03-03 15:11:23 +01:00
Arthur Cohen a498b2c5d6 macro-substitute: Do not substitute non-repetition fragments in sub-maps
When creating a sub-map for repetitions, we need to be weary of not
accessing matched-fragments beyond the vector's size. For example, with
the following *fragments*

{ "e": [1], "es": [2, 3, 10]},

the sub-maps we want to create are the following:

{ "e": [1], "es": [2]},
{ "e": [1], "es": [3]},
{ "e": [1], "es": [10]},

Up until this point however, we were trying to access the second index
for the "e" metavar when creating the second submap, then the third, and
  so on... which is obviously outside of the vector's bounds.

We can simply check if the metavar only has one match and expand that
one in that case. We still need to work on checking that multiple
metavars in the same transcriber repetition pattern have the same amount
of matched fragments (ie the original vectors of matches in the
original map have the same size)
2022-03-03 15:11:23 +01:00
Philip Herron d6e1771291 must use attribute support
This ports over the code from the cpp front-end which implements the cpp
nodiscard attribute which has the same behaviour and is also implemented
in the front-end explicitly.

Fixes #856
2022-03-03 11:08:18 +00:00
Philip Herron 57b5060798 Add missing accessor for attributes on external items 2022-03-03 11:08:17 +00:00
Philip Herron 17d4a75971 Remove gcc abstraction for expression statement
The gcc abstraction contained a method of turning expressions into
statements which used to contain their own types like Bstatement,
Bexpression this produced awkward interfaces which we no longer require.

This is part of a patch series to introduce the CPP front-end
convert_to_void to port over the support for the nodiscard attribute which
maps nicely over to Rust's must_use attribute.
2022-03-03 11:08:17 +00:00
bors[bot] e35da26d8e
Merge #988
988: lexer: Add reference and warning documentation r=tschwinge a=CohenArthur

Fixes the -fself-test invalid memory accesses and adds documentation
regarding a possible future fix.

Co-authored-by: tschwinge <thomas@schwinge.name>
Co-authored-by: philberty <philip.herron@embecosm.com>

Closes #987 

Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-03-02 16:27:51 +00:00
Arthur Cohen 45eac56868 lexer: Add reference and warning documentation
Fixes the -fself-test invalid memory accesses and adds documentation
regarding a possible future fix.

Co-authored-by: tschwinge <thomas@schwinge.name>
Co-authored-by: philberty <philip.herron@embecosm.com>
2022-03-02 15:18:40 +01:00
bors[bot] 6cf9f8c99c
Merge #983
983: Parse proper cfg values r=CohenArthur a=CohenArthur

Closes #936 

Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-03-01 17:26:07 +00:00
Arthur Cohen f7ff6020f8 lexer: Improve safety by taking ownership of the tokenized string
Co-authored-by: philberty <philip.herron@embecosm.com>
2022-03-01 17:20:29 +01:00
Arthur Cohen 82fc107e3d macros: Add test cases for recursive macro invocation 2022-03-01 15:20:31 +01:00
Arthur Cohen c8499831fd macro-substitute: Do not substitute non-repetition fragments in sub-maps
When creating a sub-map for repetitions, we need to be weary of not
accessing matched-fragments beyond the vector's size. For example, with
the following *fragments*

{ "e": [1], "es": [2, 3, 10]},

the sub-maps we want to create are the following:

{ "e": [1], "es": [2]},
{ "e": [1], "es": [3]},
{ "e": [1], "es": [10]},

Up until this point however, we were trying to access the second index
for the "e" metavar when creating the second submap, then the third, and
  so on... which is obviously outside of the vector's bounds.

We can simply check if the metavar only has one match and expand that
one in that case. We still need to work on checking that multiple
metavars in the same transcriber repetition pattern have the same amount
of matched fragments (ie the original vectors of matches in the
original map have the same size)
2022-03-01 15:20:31 +01:00
bors[bot] e82b59dfc9
Merge #981
981: macro-expand: Add SubstitutionCtx class in its own file r=CohenArthur a=CohenArthur

The `MacroExpander` class had multiple static functions which were constantly passing the same parameters around for expansion. This refactor adds a new `SubstituteCtx` class which keeps track of the three common arguments given to the substitute functions, and offers these implementations in a new source file to keep the original expander light.

Closes #957 

Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-03-01 11:36:13 +00:00
Arthur Cohen 58d1721529 macroinvocation: Only allow *stmt* visitors when semicoloned 2022-03-01 11:19:11 +01:00
Arthur Cohen 12d156566a parser: Allow parsing macro invocations as statements
When parsing a macro invocation as a statement, the parser would parse
an expression and then try parsing a semicolon. Since no actual
lookahead was done (which is a good thing), we couldn't convert a
`MacroInvocation` to a `MacroInvocationSemi` after the fact.

Since, unlike function calls, macro invocations can act differently
based on whether or not they are followed by a semicolon, we actually
need to differentiate between the two up until expansion.

This commits adds a new virtual method for ExprWithoutBlock when
converting to ExprStmtWithoutBlock so that classes inheriting
ExprWithoutBlock can specify a new behavior. In the case of our
MacroInvocation class, it simply means toggling a boolean: If we're
converting a macro from an expression to a statement, it must mean that
it should contain a semicolon.
2022-03-01 11:19:11 +01:00
Arthur Cohen 49dcecd3b6 frust-cfg: Use proper parser to parse key-value pairs
In order to conform to the rust reference, we must make sure that when
parsing -frust-cfg key-value pairs, we actually parse a valid key and
value. The key must be a valid identifier, while the value must be a
valid identifier surrounded by double quotes
2022-02-26 13:23:12 +01:00
Arthur Cohen ede68b7ba6 lexer: Add ability to lex strings directly
By allowing us to parse strings directly instead of necessarily a
filename, we are now able to reuse the parser and lexer in various
places of the compiler. This is useful for -frust-cfg, but may also come
in handy for
other compiler mechanics such as the include!() builtin macro, where we
do not actually want location info but just a stream of tokens.
2022-02-26 13:21:46 +01:00
Arthur Cohen 27be628911 macro-expand: Add SubstitutionCtx class in its own file 2022-02-26 11:35:01 +01:00
bors[bot] ed1a4dc33f
Merge #954
954: HIR Visitor refactoring r=philberty a=dkm

This change split the single HIR visitor in smaller abstract ones:
- Stmt
- VisItem
- Pattern
- ExternalItem
- Impl
- Type
- Expression

Instead of providing a Base class with empty visit() methods, they are kept
abstract to avoid the case where a missing visit() is silently ignored:
implementors must explicitely override all visit.

There is also a FullVisitor that covers all HIR nodes and also provides a Base
class with empty behavior.

fixes #825

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>

Co-authored-by: Marc Poulhiès <dkm@kataplop.net>
2022-02-25 21:43:04 +00:00
Marc Poulhiès dffb1adabd HIR Visitor refactoring
This change split the single HIR visitor in smaller abstract ones:
- Stmt
- VisItem
- Pattern
- ExternalItem
- Impl
- Type
- Expression

Instead of providing a Base class with empty visit() methods, they are kept
abstract to avoid the case where a missing visit() is silently ignored:
implementors must explicitely override all visit.

There is also a FullVisitor that covers all HIR nodes and also provides a Base
class with empty behavior.

fixes #825

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
2022-02-25 20:37:37 +01:00
bors[bot] b695eb8f0b
Merge #970
970: Add file!() builtin r=CohenArthur a=CohenArthur



Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-02-25 12:09:43 +00:00
bors[bot] d3a4cf93b7
Merge #974
974: Add support for  ranges and index lang items  along with the TyTy::SliceType r=philberty a=philberty

This PR contains more code to begin supporting Slices which requires support
for more intrinsic, range and index lang items. More work is needed to support
slices such as the const_ptr lang item and the offset intrinsic but this is a big
PR already and adds support for more lang items along the way.

Fixes #975
Addresses #849 

Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2022-02-25 11:14:37 +00:00
Philip Herron 22c6bca60a Add support for index lang item overloads
This reuses our code to resolve operator overloads to call into the index
lang item for the array-index-expression this serves as a basis for
supporting slices.

Fixes #975
2022-02-24 16:59:56 +00:00
Philip Herron d8351d9168 Decouple the HIR::OperatorExpr from resolving operator overloads
This means we can reuse the same code for operations that are not
HIR::OperatorExpr's such as ArrayIndexExpr which can resolve to
core::ops::index lang items.
2022-02-24 16:39:12 +00:00
Philip Herron 5d5396d522 Refactor operator overloading code into cc file 2022-02-24 16:02:50 +00:00
Philip Herron 3b3079eba5 Cleanup error handling on array index expression type resolution 2022-02-24 15:55:35 +00:00
Philip Herron 7d6579c2fa Fix ICE as infered is nullptr at this point 2022-02-24 15:43:00 +00:00
Philip Herron 2975f11436 Add index and index_mut lang item mappings 2022-02-24 14:54:34 +00:00
Philip Herron 0033df1a52 Refactor ArrayIndexExpr typechecking into cc impl file 2022-02-24 14:30:15 +00:00
Philip Herron 833c439a50 Add boilerplate for the new SliceType 2022-02-24 12:47:57 +00:00
Philip Herron a6dd242845 Refactor ArrayIndexExpr code into implementation cc file 2022-02-24 11:59:19 +00:00
Philip Herron 7d4845bc95 Add code generation for range expressions 2022-02-24 11:49:51 +00:00
Philip Herron fa21267280 Fix TyTy::ADTType is_equals to always check the variants for equality 2022-02-24 11:20:19 +00:00
Philip Herron a64983f86c Add typechecking for range expressions
This looks up the relevant lang items and constructs their algebraic data
types with the specified range types for the substitution argument.
2022-02-24 11:19:23 +00:00
Philip Herron 1c3af63eae Add missing range mapping lang item 2022-02-24 11:19:23 +00:00
Philip Herron ac17ed5f5e Add HIR lowering for range expressions 2022-02-24 11:19:23 +00:00
Arthur Cohen 8cc50f2d23 builtin_macros: Add test for file!() 2022-02-23 15:53:15 +01:00
Arthur Cohen 62ab4d6bf1 builtin_macros: Add make_string helper 2022-02-23 15:53:15 +01:00
Arthur Cohen 986b8c3c60 builtins: Add file!() macro 2022-02-23 15:44:21 +01:00
bors[bot] bf92a10122
Merge #969
969: Add builtin macros framework r=CohenArthur a=CohenArthur

This PR adds bases to define new builtin macro functions.

Since we operate at the `insert_macro_def` level, this requires builtin macros to be defined, as is the case in the rust standard library:

```rust
    macro_rules! assert {
        ($cond:expr $(,)?) => {{ /* compiler built-in */ }};
        ($cond:expr, $($arg:tt)+) => {{ /* compiler built-in */ }};
    }
```

Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-02-23 13:37:07 +00:00
Arthur Cohen 48b3fe622e macros: Add optional builtin transcribers to MacroRulesDefinition 2022-02-23 14:36:11 +01:00