Commit Graph

192641 Commits

Author SHA1 Message Date
Thomas Schwinge 10ff5d5507 Merge 'Build logs' into 'Build' in '.github/workflows/ccpp.yml:jobs.build-and-check'
This avoids the supposed issue that in case that 'make' fails, the whole
'jobs.build-and-check' stops, and 'Build logs' isn't executed, and thus there's
no indication in the GitHub UI why 'make' failed.

Using a shell pipeline is OK; the exit code of 'make' isn't lost, as per
<https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsshell>,
'bash' is being run with '-o pipefail'.
2022-03-22 12:17:23 +01:00
Thomas Schwinge 246fb48cbb Force 'LC_ALL=C.UTF-8' for all steps of '.github/workflows/ccpp.yml:jobs.build-and-check'
That's what I use in my local development enviroment, and I suppose I'll
be the main one touching this file semi-regularly in context of
<https://github.com/Rust-GCC/gccrs/issues/247> "Rebasing against GCC".
2022-03-22 12:17:23 +01:00
Thomas Schwinge 202e61bc2d Force 'LC_ALL=C' for all steps of '.github/workflows/ccpp.yml:jobs.build-and-check' 2022-03-22 09:55:43 +01:00
CastilloDel 60d1fd533c Add a check for new warnings to the CI
This should prevent new warnings from appearing silently

Signed-off-by: Daniel del Castillo delcastillodelarosadaniel@gmail.com
2022-03-20 09:42:41 +00:00
bors[bot] 1bb9a29688
Merge #1029
1029: Macro in trait impl r=CohenArthur a=CohenArthur

Needs #1028 

You can just review the last commit to avoid reviewing twice. Sorry about that!

Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-03-17 16:04:23 +00:00
Arthur Cohen a7ef6f98be macros: Allow macro calls in trait implementations
Just like inherent implementation blocks, trait implementation blocks
(`impl Trait for Type`) can also contain macro invocations.
2022-03-17 15:56:18 +01:00
Arthur Cohen 935b561e7f macros: Add test cases for remaining expansion contexts 2022-03-17 15:51:09 +01:00
Arthur Cohen 1a2ef9cae9 macros: Add remaining context and improve parsing macro dispatch
This allows us to expand macor invocations in more places, as macro
calls are not limited to statements or expressions. It is quite common
to use macros to abstract writing repetitive boilerplate for type
implementations, for example.
2022-03-17 15:51:06 +01:00
bors[bot] 1a14348afe
Merge #1035
1035: Handle -fsyntax-only r=CohenArthur a=CohenArthur

Handle the -fsyntax-only properly from the rust frontend. This flag
allows checking for syntax and stopping after that, skipping further
passes of the pipeline.
The flag was accepted by the frontend, but was not used anywhere.

Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-03-17 13:15:45 +00:00
bors[bot] b7baee8795
Merge #1037
1037: Support placeholders becoming slices r=philberty a=philberty

When we setup trait-impls the type-alias are allowed to become any type
this interface was missing a visitor. We also need to support constraining
type-parameters behind slices.

The get_root interface is currently unsafe, it needs a flag for allowing
unsized and for keeping a map of adjustments along the way. This will
be added down the line when we support unsized method resolution.

Fixes #1034
Addresses #849 

Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2022-03-17 12:47:18 +00:00
Arthur Cohen e30d07de5c parser: Handle -fsyntax-only properly
Handle the -fsyntax-only properly from the rust frontend. This flag
allows checking for syntax and stopping after that, skipping further
passes of the pipeline.
The flag was accepted by the frontend, but was not used anywhere.

Co-authored-by: philberty <philip.herron@embecosm.com>
2022-03-17 13:29:38 +01:00
bors[bot] e48bce446c
Merge #1027 #1032
1027: parser: Allow parsing stmts without closing semicolon r=CohenArthur a=CohenArthur

In certain cases such as macro matching or macro expansion, it is
important to allow the parser to return a valid statement even if no
closing semicolon is given. This commit adds an optional parameter to
the concerned functions to allow a lack of semicolon those special cases

Closes #1011 
Closes #1010 

1032: Add AST kind information r=CohenArthur a=CohenArthur

Closes #1001 

This PR adds a base for adding node information to our AST types. It can be used when requiring to differentiate between multiple kinds of nodes, while not necessarily wanting to do a full static cast. This will open up a lot of cleanup issues and good first issues for Project Pineapple

Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-03-17 11:25:48 +00:00
Philip Herron f6c86fc8cd Support placeholders becoming slices
When we setup trait-impls the type-alias are allowed to become any type
this interface was missing a visitor. We also need to support constraining
type-parameters behind slices.

The get_root interface is currently unsafe, it needs a flag for allowing
unsized and for keeping a map of adjustments along the way.

Fixes #1034
2022-03-17 11:02:58 +00:00
bors[bot] 3ada3d8365
Merge #1022 #1033
1022: attribute expansion: Fix spurious stripping of tail expression r=CohenArthur a=CohenArthur

This commit fixes the issue reported in #391, but highlights another
one, which will be reported.

Closes #391 

1033: Fix bad copy-paste in can equal interface for pointer types r=philberty a=philberty

When we perform method resolution we check if the self arguments can be
matched. Here the bug was that pointer types had a bad vistitor and only
could ever match reference types which is wrong and was a copy paste error.

Fixes #1031
Addresses #849 


Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2022-03-17 10:53:07 +00:00
bors[bot] fe13ad49b1
Merge #1030
1030: Rewrite our unconstrained type-param error checking r=philberty a=philberty

This is a series of patches that were all required to fix this issue. We
now take advantage of our substitutions abstractions and traits
so that our TypeBoundPredicate's which form the basis of our HRTB code
I think this class is almost akin to rustc existential-trait-references. This now
reuses the same code path to give us the same error checking for generics
as we get with ADT's, functions etc.

With this refactoring in place we can then reuse the abstractions to map the
ID's from the used arguments in the type-bound-predicate, the impl block type
substation mappings and the self type itself.

There are quite a few cases to handle and our testsuite picked up all the regressions
so no behaviour of our existing test-cases have changed now. See each commit for
more detailed information.

Fixes #1019 
Addresses #849

Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2022-03-17 10:23:04 +00:00
Philip Herron 6e385d2f25 Fix bad copy-paste in can equal interface for pointer types
When we perform method resolution we check if the self arguments can be
matched. Here the bug was that pointer types had a bad vistitor and only
could ever match reference types which is wrong and was a copy paste error.

Fixes #1031
2022-03-17 09:51:39 +00:00
Arthur Cohen 1e873922f0 ast: Add Kind::MACRO_INVOCATION and cleanup fatal errors in lowering
macro invocations
2022-03-17 10:38:07 +01:00
Arthur Cohen b776c4953c macros: Do not lower macro definitions to HIR
Avoid lowering block statements that should not be lowered, such as
macro-rules definitions
2022-03-17 10:22:44 +01:00
Arthur Cohen 14b99bed08 ast: Add base Node class with get_ast_kind() function
This adds a new base class common to all abstract base classes of the
AST: We can use it to store information shared by all nodes, such as the
newly introduced `AST::Kind` which helps in differentiating nodes.
We could also consider using it to store location info, since all AST
nodes probably need it.
2022-03-17 10:21:32 +01:00
bors[bot] bb234b080a
Merge #1021
1021: macros: Do not try and re-expand if depth has exceeded recursion limit r=CohenArthur a=CohenArthur

We need to limit the amount of times that macro get expanded recursively
during macro-expansion. This limits the amount of times an ASTFragment
can be visited by simply incrementing the depth when setting a fragment,
and decreasing it when taking one. This way, recursive expansion which
happens at the expansion level (instead of the matching level) will
still get caught

Fixes #1012 

Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-03-17 08:27:03 +00:00
Philip Herron 8086790254 Fix unconstrained type parameter checks
This patch removes our old method of checking for unconstrained type
parameters which only worked for the basic cases such as:

  impl<T> Foo { }

But checking for unconstrained types is more complex, we need to handle
covariant types such as:

  impl<T> *T { }

Or

  struct foo<X,Y>(X,Y);
  impl<T> foo<&T,*T> {}

This rewrites the algorithm to take advantage of our substition
abstractions and HirIds so we can map the ids of the type-params to be
constrained and look at the trait-references used-arguments when the
generics are applied (or they may be empty) and then do the same for any
used arguments on an algebraic data type.

Fixes #1019
2022-03-16 22:12:35 +00:00
Philip Herron 21cf0e67a6 Add missing location info on GenericArgs 2022-03-16 15:49:26 +00:00
Philip Herron 7ac9a76c89 Make TypeBoundPredicate a subclass of the SubstitutionRef
This will allow us to reuse our generic substitions code to manage generic
traits and their substitions better. It will unify the handling in one
path so we get the same error handling.
2022-03-16 15:22:52 +00:00
Philip Herron 56a1571614 Keep track of substitution mappings as part of the TraitReference
The TraitReference wrapper is a class that allows us to work with traits
in a query manar. This patch allows us to keep track of the substitution
mappings that are defined on the trait. This will always be non-empty
since traits always contain an implicit Self type parameter so there
is special handling in how we perform monomorphization.
2022-03-16 14:34:26 +00:00
Philip Herron 9411c061aa Refactor TypeBoundPredicate to be below the definition for SubstitutionRef
This means TypeBoundPredicate will now be able to inherit all behaviours
of normal generics so we do not duplicate the work in handling generics
it will also allow us to more easily check for unconstrained type
parameters on traits.
2022-03-16 14:24:41 +00:00
Arthur Cohen b6b567171c attribute expansion: Fix spurious stripping of tail expression
This commit fixes the issue reported in #391, but highlights another
one, which will be reported.
2022-03-16 09:38:09 +01:00
Arthur Cohen 313e9890d8 parser: Allow parsing stmts without closing semicolon
In certain cases such as macro matching or macro expansion, it is
important to allow the parser to return a valid statement even if no
closing semicolon is given. This commit adds an optional parameter to
the concerned functions to allow a lack of semicolon those special cases
2022-03-14 16:34:50 +01:00
bors[bot] 2dfc196477
Merge #1025
1025: Fix memory corruption in generation of builtin functions r=philberty a=philberty

This patch removes the pop_fn calls since no fncontext stack is required here for these intrinsic.
More context on the issues is in the commit message.

Fixes #1024

Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2022-03-14 15:03:08 +00:00
Philip Herron 7d7bc2ce38 Fix memory corruption in generation of builtin functions
When we compile normal language functions we maintain a stack of the
current function declaration and associated return addresses. This is used
while building up the GCC tree graph. When we generate builtin intrinsic
functions such as offset or size_of were missing their associated push_fn
but still performed a pop_fn on completion this resulted in a corrupt
stack which valgrind shown as bad read/writes.

This patch removes the pop_fn calls since no fncontext stack is required here for these intrinsics.

Fixes #1024
2022-03-14 12:57:01 +00:00
Arthur Cohen 02887c88f5 macros: Do not try and re-expand if depth has exceeded recursion limit
We need to limit the amount of times that macro get expanded recursively
during macro-expansion. This limits the amount of times an ASTFragment
can be visited by simply incrementing the depth when setting a fragment,
and decreasing it when taking one. This way, recursive expansion which
happens at the expansion level (instead of the matching level) will
still get caught
2022-03-14 11:21:20 +01:00
bors[bot] 41f402f0b1
Merge #1004
1004: Added column!() macro r=CohenArthur a=mvvsmk

Fixes issue #979 
1) Added the column!() macro using the LOCATION_COLUMN() from gcc_linemap
2) To-Do: add relevant test cases.

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

The test case I added always fails, I can't figure out whether there is a problem in my test case or there is something wrong with my implementation of the column!() macro. Do let me know where I am going wrong and also if I missed something . :)


Co-authored-by: M V V S Manoj Kumar <mvvsmanojkumar@gmail.com>
2022-03-13 11:45:43 +00:00
M V V S Manoj Kumar d9a5bddb4c Added column!() macro
Addresses issue #979
1) Added the column!() macro using the LOCATION_COLUMN() from gcc_linemap
2) Added relevent test cases

Signed-off-by : M V V S Manoj Kumar <mvvsmanojkumar@gmail.com>
2022-03-13 11:42:22 +05:30
bors[bot] 8c88e8e0c9
Merge #1015 #1018
1015: Add code generation for the slice type r=philberty a=philberty

This type must respect the layout of the FatPtr type in libcore. Rust
implements slices using Rustc types in libcore and uses a neat trick.

Addresses #849

1018: builtin-macros: Add more documentation for defining builtins r=CohenArthur a=CohenArthur

`@mvvsmk` you might find this a little more clear. Sorry about the confusion!

Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-03-11 14:40:22 +00:00
bors[bot] a50fcbc2eb
Merge #1017
1017: attr-visitor: Split in its own source and header r=CohenArthur a=CohenArthur

Split up the 4000 lines rust-macro-expand.cc file containing the
AttrVisitor class and the macro expander implementation


Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-03-11 14:09:01 +00:00
Philip Herron 040b2ec9a6 Add code generation for the slice type
This type must respect the layout of the FatPtr type in libcore. Rust
implements slices using Rustc types in libcore and uses a neat trick.

The slice is generated into the FatPtr which contains the pointer and
length of the slice. This is then placed into a union called Repr which
has 3 variants a mutable and immutable pointer to the FatPtr and a final
variant which is the raw FatPtr. This means we can use unsafe access to
the union to gain a pointer to the FatPtr.

Addresses #849
2022-03-11 13:54:21 +00:00
Arthur Cohen c62e9eb5ee builtin-macros: Add more documentation for defining builtins 2022-03-11 14:19:56 +01:00
Arthur Cohen 63a214618a attr-visitor: Split in its own source and header
Split up the 4000 lines rust-macro-expand.cc file containing the
AttrVisitor class and the macro expander implementation
2022-03-11 13:33:59 +01:00
bors[bot] e076823eda
Merge #1016
1016: Add missing HIR lowering for SliceTypes r=philberty a=philberty

Addresses #849


Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2022-03-11 12:08:30 +00:00
Philip Herron 47ae663a3e Add missing HIR lowering for SliceTypes
Addresses #849
2022-03-11 11:44:00 +00:00
bors[bot] 6e64e6636e
Merge #1008 #1009
1008: Add const_ptr lang item mappings r=philberty a=philberty

In order to support slices, we need to be able to parse and contain
mappings for the const_ptr lang item. We do not need to do any
special handling of this lang item yet but this adds the mappings
so when we hit it we do not output an unknown lang item error.

Addresses #849 

1009: Add missing type resolution to slices and arrays r=philberty a=philberty

This adds in the missing type resolution for slices and generic slices
and arrays. Since Arrays and Slices are both covariant types just like
references and pointers for example they need to handle recursive
substitutions where their element type might be a generic type
that can bind substitution parameters such as functions and ADT's.

Addresses #849 

Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2022-03-11 10:39:24 +00:00
bors[bot] dbe59a3198
Merge #1007
1007: Add missing canonicalization of slices and raw pointer types r=philberty a=philberty

This is part of my patch series for slices. This adds the missing visitors
for name canonicalization. More information in the patch, once we get
slice support in we need to start taking advantage of `@dkm's` HIR
visitor refactoring to avoid these issues with missing visitors making
simple bugs hard to track down.

Fixes #1005


Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2022-03-11 10:10:58 +00:00
bors[bot] ddd087b0ef
Merge #1003
1003: Add more intrinsics and refactor how we implement them r=philberty a=philberty

This patch series implements:

1. offset
2. size_of
3. unreachable
4. abort

It removes the GCC wrapper mappings to make them much easier to implement. It also demonstrates in single commits
the implementation of each of these intrinsic to make it easy to follow in how we implement them.

Addresses #658 #849 

Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2022-03-11 09:41:37 +00:00
bors[bot] 1f4e2deb31
Merge #1002
1002: macros: Add abstraction around multiple matches r=CohenArthur a=CohenArthur

Adds an extra layer of abstraction around keeping multiple matches for
the same fragment. This avoids ugly code fetching the first match in
order to get the amounf of matches given by the user, while still
allowing zero-matches to exist.

Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-03-11 08:51:43 +00:00
bors[bot] 51c7cf4b97
Merge #998
998: Parse macro expansion properly r=CohenArthur a=CohenArthur

This PR adds a base for trying to parse statements or items in macro invocations. We are now able to parse multiple items / expressions / statements properly, but do not lower them properly, which is the last remaining task in #943 

New macro parsing logic:
```mermaid
flowchart TD;
    has_semi -- Yes --> stmt;
    has_semi -- No --> invocation;
    invocation -- Is Parens --> expr;
    invocation -- Is Square --> expr;
    invocation -- Is Curly --> stmt;
```

Closes #943 
Closes #959 
Closes #952 

Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-03-11 08:24:43 +00:00
Arthur Cohen f02392c8b3 macros: Replace macro invocations with expanded nodes
Different parsing functions need to be called based on the context
surrounding the macro invocation. This commit adds a flowchart trying to
explain the base resolving rules

Macro expansion happens at the same level as stripping, where nodes
might get removed if they are gated behind an unmet predicate. We also
perform macro expansion during this visitor's pass.

What we can do is thus to replace macro invocations with new items that
might have resulted from macro expansion: Since we're already mutating
numerous elements by removing them if they should be stripped, we can
also add elements if they should be expanded.

This commit also "fixes" macro test cases so that they are now accepted
by the new parser, which is more strict than it should for now.

Co-authored-by: SimplyTheOther <simplytheother@gmail.com>
Co-authored-by: philberty <philip.herron@embecosm.com>
2022-03-11 09:21:29 +01:00
Arthur Cohen 9f73e827ab macros: Add abstraction around multiple matches
Adds an extra layer of abstraction around keeping multiple matches for
the same fragment. This avoids ugly code fetching the first match in
order to get the amounf of matches given by the user, while still
allowing zero-matches to exist.

Co-authored-by: philberty <philip.herron@embecosm.com>
2022-03-10 21:45:34 +01:00
Philip Herron 894e9d29ad Handle generic Slices and Arrays
Slices and Arrays are covariant types which means they can contain elements
which bind generics such as ADT or FnTypes. This means substitutions can be
recursive and this gives the typechecker a chance to handle this recursion
on these types.
2022-03-10 16:51:03 +00:00
Philip Herron a620a228c1 Add missing type-checking for slice types 2022-03-10 16:50:56 +00:00
Philip Herron a1b065050b Add const_ptr lang item mappings
const_ptr is a lang item used as part of the slice implemenation this
adds it to our mappings so we do not error with an unknown lang item.
2022-03-10 16:45:49 +00:00
Philip Herron 31413ebacf Add missing canonicalization of slices and raw pointer types
When we intercept impl blocks for slices or raw pointers we must generate
the canonical path for this for name resolution this adds in the missing
visitors which will generate the path. Previously this was defaulting to
empty path segments and then hitting an assertion when we append the
empty segment.

Fixes #1005
2022-03-10 16:42:36 +00:00