aboutsummaryrefslogtreecommitdiff
path: root/gcc
AgeCommit message (Collapse)AuthorFilesLines
2021-06-23Add support for struct definitions to be within a blockPhilip Herron8-14/+347
We still have bugs handling unit-structs but this allows for Tuple Structs and normal named field structs to be declared within a block and referenced lexically. This allows rust statements to follow the correct grammar. Fixes #519
2021-06-23Merge #518bors[bot]2-34/+37
518: Token strings r=philberty a=tromey This series implements a couple of small changes to improve the handling of strings attached to Token. Co-authored-by: Tom Tromey <tom@tromey.com>
2021-06-22Fix RAIIFile bugletTom Tromey1-5/+8
RAIIFile's implementation of operator= can leak a file, because it doesn't handle the case where the assignee holds an open file handle.
2021-06-22Require moves in Token constructorsTom Tromey2-31/+34
This avoids some string copies by changing the Token constructors to require any std::string argument to be transferred via std::move.
2021-06-21Use unique_ptr in TokenTom Tromey1-3/+3
Token currently uses a "std::string *". There's a comment proposing that perhaps this should be changed; but meanwhile, it's slightly cleaner to use unique_ptr rather than have Token manage the string's lifetime manually.
2021-06-21Merge #514bors[bot]2-2/+17
514: Rename tuple field names r=philberty a=tromey Tuples currently use plain integer field names in the DWARF. However, rustc prefixes these with "__", and GDB understands this convention. This patch changes gccrs to match, and adds an explanatory comment. Co-authored-by: Tom Tromey <tom@tromey.com>
2021-06-21Rename tuple field namesTom Tromey2-2/+17
Tuples currently use plain integer field names in the DWARF. However, rustc prefixes these with "__", and GDB understands this convention. This patch changes gccrs to match, and adds an explanatory comment.
2021-06-21Fix various Wformat-diag diagnosticsMarc Poulhiès20-42/+48
Fix warnings mainly coming from ` being used instead of %< and %>. Also fixing occurences of : ../../gcc/rust/lex/rust-token.cc:126:40: warning: unquoted sequence of 2 consecutive punctuation characters ‘',’ in format [-Wformat-diag] 126 | "attempted to get string for '%s', which has no string. " | ^~ ../../gcc/rust/lex/rust-token.cc:127:39: warning: spurious trailing punctuation sequence ‘.’ in format [-Wformat-diag] 127 | "returning empty string instead.", | ^ ../../gcc/rust/lex/rust-token.cc:126:37: warning: unterminated quote character ‘'’ in format [-Wformat-diag] 126 | "attempted to get string for '%s', which has no string. " | ^ and various occurences of : ../../gcc/rust/lex/rust-lex.cc:1326:11: warning: unquoted keyword ‘char’ in format [-Wformat-diag] 1326 | "byte char %<%c%> out of range", byte_char); | ^~~~ Also using full word for arguments, integer, character, declaration, variable, floting-point instead of args, int, char, decl, var, float when applicable.
2021-06-20Fix up test suite bugletsTom Tromey4-5/+5
Mark Wielaard pointed out that the i8u8.rs test that I recently introduced has a bug: it checks the DW_AT_language attribute, not DW_AT_encoding. Sorry about this. This patch fixes this problem. I've verified that this notices the failure after temporarily backing out the corresponding GCC change. This patch also fixes another problem that he found, namely that it's possible for these tests to find the wrong answer, because the hex value that is checked for might be a prefix of some longer value. This patch also adds a whitespace check to avoid this potential problem.
2021-06-19Merge #506 #507 #508bors[bot]4-12/+17
506: Fix: do not use object after it has been moved r=philberty a=dkm After std::move(mapping), mapping is unspecified <!-- THIS COMMENT IS INVISIBLE IN THE FINAL PR, BUT FEEL FREE TO REMOVE IT Thank you for making Rust GCC better! If your PR fixes an issue, you can add "Fixes #issue_number" into this PR description and the git commit message. This way the issue will be automatically closed when your PR is merged. If your change addresses an issue but does not fully fix it please mark it as "Addresses #issue_number" in the git commit message. Here is a checklist to help you with your PR. - \[ ] GCC code require copyright assignment: https://gcc.gnu.org/contribute.html - \[ ] Read contributing guidlines - \[ ] `make check-rust` passes locally - \[ ] Run `clang-format` - \[ ] Added any relevant test cases to `gcc/testsuite/rust/` Note that you can skip the above if you are just opening a WIP PR in order to get feedback. --- --> 507: Add more info in HIR dump for struct r=philberty a=dkm Make struct fields more visible in dumps and add the mapping in the dump string. <!-- THIS COMMENT IS INVISIBLE IN THE FINAL PR, BUT FEEL FREE TO REMOVE IT Thank you for making Rust GCC better! If your PR fixes an issue, you can add "Fixes #issue_number" into this PR description and the git commit message. This way the issue will be automatically closed when your PR is merged. If your change addresses an issue but does not fully fix it please mark it as "Addresses #issue_number" in the git commit message. Here is a checklist to help you with your PR. - \[ ] GCC code require copyright assignment: https://gcc.gnu.org/contribute.html - \[ ] Read contributing guidlines - \[ ] `make check-rust` passes locally - \[ ] Run `clang-format` - \[ ] Added any relevant test cases to `gcc/testsuite/rust/` Note that you can skip the above if you are just opening a WIP PR in order to get feedback. --- --> 508: Make 3 error messages slightly more informational r=philberty a=dkm Add more context to some internal error messages (ie. not intended for user) <!-- THIS COMMENT IS INVISIBLE IN THE FINAL PR, BUT FEEL FREE TO REMOVE IT Thank you for making Rust GCC better! If your PR fixes an issue, you can add "Fixes #issue_number" into this PR description and the git commit message. This way the issue will be automatically closed when your PR is merged. If your change addresses an issue but does not fully fix it please mark it as "Addresses #issue_number" in the git commit message. Here is a checklist to help you with your PR. - \[ ] GCC code require copyright assignment: https://gcc.gnu.org/contribute.html - \[ ] Read contributing guidlines - \[ ] `make check-rust` passes locally - \[ ] Run `clang-format` - \[ ] Added any relevant test cases to `gcc/testsuite/rust/` Note that you can skip the above if you are just opening a WIP PR in order to get feedback. --- --> Co-authored-by: Marc Poulhiès <dkm@kataplop.net>
2021-06-19Add more info in HIR dump for structMarc Poulhiès1-2/+3
Make struct fields more visible in dumps and add the mapping in the dump string.
2021-06-19Make 3 error messages slightly more informationalMarc Poulhiès2-6/+10
Add more context to some internal error messages (ie. not intended for user)
2021-06-19Fix: do not use object after it has been movedMarc Poulhiès1-4/+4
After std::move(mapping), mapping is unspecified
2021-06-18Use DW_ATE_UTF for the Rust 'char' typeTom Tromey3-5/+27
The Rust 'char' type should use the DWARF DW_ATE_UTF encoding.
2021-06-18Use correct DWARF encoding for i8 and u8 typesTom Tromey2-5/+13
Currently, the i8 and u8 types use the DWARF character encoding, like: <1><113>: Abbrev Number: 3 (DW_TAG_base_type) <114> DW_AT_byte_size : 1 <115> DW_AT_encoding : 8 (unsigned char) <116> DW_AT_name : u8 This happens because gccrs uses signed_char_type_node and unsigned_char_type_node for i8 and u8, respectively. This patch fixes this problem by arranging to use a custom integer type instead. Another option is to clear TYPE_STRING_FLAG on these types, but it was unclear to me whether this would impact other parts of GCC.
2021-06-18Use DW_LANG_Rust in DWARFTom Tromey4-0/+52
This changes the GCC DWARF emitterto use DW_LANG_Rust or DW_LANG_Rust_old as appropriate.
2021-06-17Ensure rust_debug has printf specifier checksPhilip Herron2-9/+5
This adds a macro wrapper over rust_debug_loc to inject a default location so calls can maintain printf specifier checks.
2021-06-17Mark function as override to squash warningPhilip Herron1-1/+1
2021-06-17Merge #498bors[bot]13-358/+108
498: Remove HIR::TraitItemMethod, this can be represented by TraitItemFunction r=philberty a=philberty Canonicalizing the paths of the compiler to treat functions and methods the same way will ensure we avoid duplication. Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2021-06-17Remove HIR::TraitItemMethod this can be represented by TraitItemFunctionPhilip Herron13-358/+108
Methods are simply functions with a self param, this simplifies the paths in HIR to avoid duplication as much as possible.
2021-06-17Merge #497bors[bot]4-13/+12
497: Avoid abort macro override the abort of std r=philberty a=thomasyonug Fixing the build issue in macos by avoiding abort macro override the abort call of std. Co-authored-by: Thomas Young <wenzhang5800@gmail.com>
2021-06-17avoid abort macro override the abort of stdThomas Young4-13/+12
2021-06-16Merge #496bors[bot]3-2/+29
496: TraitImpl blocks have a different CanonicalPath to normal impl blocks r=philberty a=philberty TraitImpls have a canonical path which is a trait projection such as ```rust pub trait Trait { // ::a::Trait fn f(&self); // ::a::Trait::f } impl Trait for Struct { fn f(&self) {} // <::a::Struct as ::a::Trait>::f } ``` Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2021-06-16TraitImpl blocks have a different CanonicalPath to normal impl blocksPhilip Herron3-2/+29
TraitImpls have a canonical path which is a trait projection such as ```rust pub trait Trait { // ::a::Trait fn f(&self); // ::a::Trait::f } impl Trait for Struct { fn f(&self) {} // <::a::Struct as ::a::Trait>::f } ```
2021-06-16Impl blocks can have a trait referencePhilip Herron4-78/+113
This refactors Type HIR lowering to extract TypePath AST -> HIR lowering function, as Trait References are simply TypePaths.
2021-06-16Refactor HIR::InherentImpl to become HIR::ImplBlockPhilip Herron26-226/+157
This folds the abstract Impl class directly into HIR::ImplBlock since the TraitImplBlock is removed. It also refactors InherentImplItem to become simply ImplItem.
2021-06-16Cleanup HIR to canonicalize TraitImpl to be treated as an impl blockPhilip Herron17-431/+32
HIR should desugar the AST as best it can. Trait impl blocks are just impl blocks. The HIR impl block can just have an optional<TraitRef> in order to represent a trait impl block.
2021-06-15replace analysis dir with lint dir and rename liveness to markliveThomas Young6-33/+32
2021-06-14Merge #492 #493bors[bot]12-1038/+187
492: HIR should not contain any macros r=philberty a=philberty This removes the macros tree's from HIR. HIR should be an expanded and simplifed representation of the compilation unit. Fixes #70 493: Path resolution fixes r=philberty a=philberty In order to support Modules, we need to do path resolution properly. The old code assumed a basic A::B but this is not generic enough in order to support modules. Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2021-06-14Add comment about modules and pathsPhilip Herron1-1/+22
In order to support modules the path expression will fail here since a module is not a value and does not have a TyTy type, so this is ok to continue the rest of resolution so long as there are more segments. Addresses: #432
2021-06-14Fix PathExpression type resolutionPhilip Herron1-56/+103
There are cases where the name resolver can fully resolve a path such as: ```rust struct Foo(i32); impl Foo{ fn new() { ... } } fn main() { let a; a = Foo::new(); } ``` This case does not require a PathProbe. This enhances the Path resolution to iterate each segment untill we are unable to resolve the root segment at that point we can fall back to a PathProbe and lookup any impl item that might satisfy the path instead. Addresses #432
2021-06-14Name resolver should try to resolve each segment in turnPhilip Herron1-54/+58
Name resolution tried to greedily resolve the entire CanonicalPath in one lookup which was ok for simple paths like A::B. This changes the name resolver to resolve each segment which allows the type resolution to determine the root path to be up until the segment is unresolved which will then require a PathProbe or its a failure. This will be required to support modules which extend the resolution to be much more generic than is assumed here. Addresses: #432
2021-06-11HIR should not contain any macrosPhilip Herron10-928/+5
This removes the macros tree's from HIR. HIR should be an expanded and simplifed representation of the compilation unit. Fixes #70
2021-06-07arm: rust: Remove unsupported baselines arm_arch8_5 and arm_arch8_6John Paul Adrian Glaubitz1-4/+0
2021-06-07arm: rust: Fix typo: hasBaseLine8MPreReqs => hasBaseline8MPreReqsJohn Paul Adrian Glaubitz1-1/+1
2021-06-05Merge #484 #485 #486bors[bot]22-84/+916
484: Trait impls and initial start of traits work r=philberty a=philberty This does not start enforcing anything to do with traits. in order to implement the traits milestone we need to be able to implement a trait first. This makes the Trait impls follow a normal impl block. As the starting point. Fixes #395 #472 485: All toplevel items must respect the prefix for their path r=philberty a=philberty The commit message has a more detailed explanation as to why. But some toplevel items were not respecting their prefix which is important for module support. 486: Use PRIx64 to print 64bit hex values in legacy_hash r=philberty a=philberty * gcc/rust/backend/rust-compile.cc (legacy_hash): lo and hi are uint64_t use PRIx64 to print them as hex values instead of %lx which is target specific. Co-authored-by: Philip Herron <philip.herron@embecosm.com> Co-authored-by: Mark Wielaard <mark@klomp.org>
2021-06-05Use PRIx64 to print 64bit hex values in legacy_hashMark Wielaard1-1/+1
* gcc/rust/backend/rust-compile.cc (legacy_hash): lo and hi are uint64_t use PRIx64 to print them as hex values instead of %lx which is target specific.
2021-06-05All toplevel items must respect the prefix for their pathPhilip Herron1-8/+8
Name resolution is split into two parts, one for the toplevel canonical paths and then a second to actually drill down into new scopes for blocks for example. Consider a rust program: ```rust fn foo() -> bar { ... } struct bar(..); ``` In that example the function foo references bar which is declared later on. The compiler is partly query based in that we use ids to get away from looking up things via strings as quickly as possible. The toplevel scan follows the rust documentation over on: This assigns canonical names for all toplevel items but ignore the details like return types, or body. So the name resolver ends up with: ::foo ::bar Then we can drill down into foo and check the return type and see that ::bar is already defined. The prefix is important for the case of modules for example. This should be a toplevel scan within the same scope. Addresses: #432
2021-06-05This is the initial building blocks for TraitsPhilip Herron7-0/+128
We can compile TraitImpls, since before we can actually start checking trait obligations we need to be able to implement the trait first. More desugaring is needed in HIR to make TraitImpls contain normal impl items to avoid seperation in how impl blocks are handled. Fixes #395 #472
2021-06-05Add AST to HIR lowering for traits and trait impls.Philip Herron8-37/+416
This will change to desugar trait-impls to be just like a normal impl block later on. This will simplify things for method resolution. This is the initial building block so we can move forward and refactor as the trait resolution evolves. Addresses #395 #472
2021-06-05Add initial name resolution for traits and trait implsPhilip Herron6-0/+292
We need to add name resolution for traits and trait impls. We cannot start working with trait obligations untill we can actually implment a basic trait first. Addresses: #395
2021-06-05Add NodeMappings to HIR::Trait ItemsPhilip Herron2-34/+38
NodeMappings are used to map HIR items into the type system and back to NodeIds as part of name Resolution. LocalDefId signify local crate defintions and DefId are cratenum + localdefids for cross crate definitions. Addresses: #395
2021-06-05Add AST node_id to AST Trait ItemsPhilip Herron2-7/+36
NodeIds are ids to map back to the AST from HIR. This is the building block to begin name resolution for traits. Addresses #395
2021-06-04Merge #482bors[bot]1-3/+2
482: arm: Override TARGET_RUST_OS_INFO in bpabi.h r=tschwinge a=glaubitz Similar to PowerPC, 32-bit ARM has the issue that TARGET_RUST_OS_INFO is defined in two separate headers, namely config/arm/bpabi.h and config/arm/linux-elf.h. We can apply the same fix that was already used for PowerPC. gcc/ChangeLog: 2021-06-04 John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de> * config/arm/bpabi.h: Undefine TARGET_RUST_OS_INFO before defining it. Co-authored-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
2021-06-04arm: Override TARGET_RUST_OS_INFO in bpabi.hJohn Paul Adrian Glaubitz1-3/+2
Similar to PowerPC, 32-bit ARM has the issue that TARGET_RUST_OS_INFO is defined in two separate headers, namely config/arm/bpabi.h and config/arm/linux-elf.h. We can apply the same fix that was already used for PowerPC. gcc/ChangeLog: 2021-06-04 John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de> * config/arm/bpabi.h: Undefine TARGET_RUST_OS_INFO before defining it.
2021-06-04Use '-frust-debug' to control dumping of various Rust front end internalsThomas Schwinge7-1/+32
... as discussed in #479, and elsewhere.
2021-06-03Remove diagnostics pruning from 'rust_target_compile' [#301, #466]Thomas Schwinge14-19/+43
This is no longer necessary after #466 "Expose rust debug and use it", where commit 665df329a2ad60580ab593f6cbd646aa55927a37 "rust_debug: Replace fprintf (stderr) with rust_debug" turned all 'fprintf' to 'stderr' into standard GCC 'inform' ('note: [...]') diagnostics -- which do get pruned by default. Adjust the testsuite: instead of 'dg-excess-errors', spell out the additional diagnostics now seen.
2021-06-03Merge #466bors[bot]12-338/+269
466: Expose rust debug and use it r=tschwinge a=CohenArthur Fixes #464 @philberty I've checked and rust_debug does output on stderr correctly :) This PR exposes the rust_debug prototype and replaces debug printfs (`fprintf (stderr, ...)`) with calls to rust_debug. This also removes the extra newlines that were added at the end of the fprintf format strings, since calling rust_debug already adds one. Without this, the tests fail due to blank lines in the output. I have used a template to overload the rust_debug function and pass variadic arguments to the complete version. While the code looks cleaner than using `va_args`, it's also heavier C++. I'm open to changing it and definitely not attached to this implementation. Most of the PR was made using sed and then clang-format Co-authored-by: CohenArthur <arthur.cohen@epita.fr>
2021-06-03rust_debug: Replace fprintf (stderr) with rust_debugCohenArthur10-333/+258
Co-authored-by: tschwinge <thomas@schwinge.name>
2021-06-03rust_debug: Expose function in header and add inline overloaded alternativeCohenArthur2-5/+11
Co-authored-by: tschwinge <thomas@schwinge.name>