Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert #1661 "58e75f65e56d: Remove HOST_WIDE_INT struct member" #1666

Conversation

tschwinge
Copy link
Member

No description provided.

CohenArthur and others added 30 commits November 17, 2022 12:32
The Rust 'char' type should use the DWARF DW_ATE_UTF encoding.
This copies over code from other front-end testsuites to enable testing
for the rust front-end specifically.

Co-authored-by: Marc Poulhiès <dkm@kataplop.net>
Co-authored-by: Thomas Schwinge <thomas@codesourcery.com>
This testsuite is specifically about testcases which scan the asm debug
info for results.

Co-authored-by: Tom Tromey <tom@tromey.com>
This testsuite is heavily inspired from the lto testsuite which uses a
pattern that each file is compiled to an object file and finally linked
together. Since rust does not have headers/prototypes we rely on the
ordering here so that all files numbered greater than zero get compiled to
object files first leaving the _0 file free to test the 'extern crate' and
use keywords to force testing of the compiler to read metadata from the
other 'crates'.
This suite of tests has two sections compile/*.rs and compile/torture/*.rs.
The first section are all dg-compile tests which contain dg-warning or
dg-error annotations and some with no annotations to ensure they do create
a resulting asm output. The second section is the same but have tests which
are ran with the full torture options, as during development the test case
may have had an issue with a specific optimization level.

Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Co-authored-by: Thomas Schwinge <thomas@codesourcery.com>
Co-authored-by: Mark Wielaard <mark@klomp.org>
Co-authored-by: Marc Poulhiès <dkm@kataplop.net>
This is similar to the compile/torture/*.rs test cases but all of these are
dg-execute testcases so they get compiled, linked and executed by default,
all the while being compiled with the matrix of torture options.

The only caveat here is that currently gccrs does not currently support
the main shim yet so we have a C-style main function here returning zero
which is not supported in Rustc.

Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Co-authored-by: Thomas Schwinge <thomas@codesourcery.com>
Co-authored-by: Mark Wielaard <mark@klomp.org>
Co-authored-by: Marc Poulhiès <dkm@kataplop.net>
This allows us to invoke the rust testsuite.

ChangeLog:
	* Makefile.def: Add Rust language.
	* Makefile.in: Regenerate via autogen.
This is a full C++11 class hierarchy representing the Rust AST. We do not
allow dynamic_cast and so the main mechanism to work with the AST is by
using the visitor interface. Slowly we are adding TREE_CODE style node
types to the AST which will allow for more ways to work with the AST but
for now this is it.

See: https://doc.rust-lang.org/reference/items.html

Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com
This adds the proper definitions of our AST Item nodes.

Co-authored-by: Philip Herron <philip.herron@embecosm.com>
This adds the proper definitions of our AST nodes split across multiple
files for clarity

Co-authored-by: Philip Herron <philip.herron@embecosm.com>
This patch contains the basic framework of our AST visitors, as well as
one aimed at pretty-printing and exporting these AST nodes

Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
The lexer is refered to as a ManagedTokenSource within the parser, this
lexer does not currently support unicode but serves as a starting point
to do so.

Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Co-authored-by: Mark Wielaard <mark@klomp.org>
This is a Pratt style parser for Rust implementing all of the AST. The
rust-parser-impl.h is the implementation of the parser which is a template
so we can give it any ManagedTokenSource and avoid virtual calls. The down
side is it takes time to compile when used.

see: https://en.wikipedia.org/wiki/Operator-precedence_parser#Pratt_parsing

This patch contains the first half of our templated parser, as to not
lose patches in the mailing list archives.

Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com
This patch contains the second half of our templated Rust parser.

Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com
The expansion pass is responsible for two actions on our AST:

1. Expanding macro calls
2. Performing conditional compilation

Calls to macros should be checked and expanded into an AST fragment based on
the context they've been called in. This is similar to token substitution, with
a lot of intricacies and checks being performed. A single invocation can result
in an AST fragment containing multiple statements or multiple expressions,
which need to be handled as well. Furthermore, Rust macros can contain
repetitions relying on Kleine operators, similar to regular expression
patterns, that also need to be expanded properly.

Finally, Rust code can be hidden behind `cfg` directives, which allow the user
to perform conditional compilation. If a `cfg` predicate is not met, the
expression or statement it refers to should be marked for strip and removed
from the AST.

Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Co-authored-by: The Other <simplytheother@gmail.com>
The name resolution is split into two phases, one toplevel pass which scans
the whole "Crate" which iterates all items and nested items in modules to
generate a context class full of CanonicalPath items. It also generates
a hierarchy of parent->child and child->parent relationships using the AST
NodeId for PathResolution in the second phase.

The second phase drills into each item like functions and creates a stack
of canonical paths for variables etc so that we can store information in
a side table of usage variable 'a' resolves to NodeId '123' which refers
to the NodeId of the "let a;" statement.
This patch contains the declarations needed for our second intermediate
representation, which we will refer to as an HIR.

This gives the front-end a chance to desugar alot of the AST such as:
- Remove distinction between functions and methods
- Remove Macros
- Remove IdentifierExpr's
- Remove duplicate attribute structures
This patch implements the classes mentionned in the previous HIR patch,
as well as a set of visitor frameworks used in handling that HIR.
This performs the lowering of the AST to HIR the interesting piece here is
that we desugar alot of the AST like we mentioned in the previous pass, but
crucially we strip out all code that is "marked-for-strip" which failed
cfg-expansion from the expansion pass. So now the HIR includes all code
required to compile for this crate.
This is a wrapper for make_unique we can likely get rid of this as there
are other implementations available or simply keep using the unique_ptr
constructor.
This hash was ported from the go runime as we needed a hash for the legacy
symbol mangling system. Which means all symbols in Rust contain a hash of
some metadata for uniqueness on generic functions.
This is a simple helper over an enum of possible ABI options in Rust.
Used for V0 symbol mangling scheme which.
Add an Optional<T> class to improve error handling
The attribute checker is responsible for checking the validity of various
attributes including built-in ones. It is currently unfinished and will
receive some modifications, as well as become the host of some existing
code in the compiler which needs to be refactored. One of its
responsibilities is to make sure that arguments given to built-in
attributes are correct, or contain the correct type of information. This
visitor also checks that an attribute is allowed to be used in the current
particular context.
These are various helper classes used in the compiler pipeline.
This serves to handle some part of the Rust type-system: Namely the type
resolution, similar to type-checking, and the trait solving algorithms,
which ensures Rust's type contracts are upheld throughout the codebase.
Contains abstractions over Rust's types, used when performing the
HIR's type-resolution.
This patch implements multiple transformation performed on the HIR
during type-resolution such as type coercion, casts, auto-dereferencement.
CohenArthur and others added 18 commits November 18, 2022 13:26
DW_LANG_Rust_old is a non-standard DWARF language code used by old
rustc compilers before DWARF5 (released in 2017). Just always emit
DW_LANG_Rust unless producing strict DWARF for versions before 5.
And in that old strict DWARF case just emit DW_LANG_C instead of a
non-standard language code.
8e52e41: Use build_int_cstu for size expressions
…stexpr-ctx

58e75f6: Remove HOST_WIDE_INT struct member
dwarf2out.c: Don't emit DW_LANG_Rust_old
This reverts commit 4a673ab.

This resolves:

    [...]/source-gcc/gcc/rust/backend/rust-constexpr.cc: In function ‘tree_node* Rust::Compile::constexpr_expression(const constexpr_ctx*, tree)’:
    [...]/source-gcc/gcc/rust/backend/rust-constexpr.cc:99:42: error: comparison of integer expressions of different signedness: ‘long unsigned int’ and ‘long int’ [-Werror=sign-compare]
       99 |   if (++ctx->global->constexpr_ops_count >= constexpr_ops_limit)

See the original C++ code:

    gcc/cp/constexpr.cc:  HOST_WIDE_INT constexpr_ops_count;

    gcc/c-family/c.opt-fconstexpr-ops-limit=
    gcc/c-family/c.opt:C++ ObjC++ Joined RejectNegative Host_Wide_Int Var(constexpr_ops_limit) Init(33554432)
    gcc/c-family/c.opt--fconstexpr-ops-limit=<number>       Specify maximum number of constexpr operations during a single constexpr evaluation.
@CohenArthur CohenArthur force-pushed the gcc-patch-dev branch 8 times, most recently from a8679ac to 8592a8d Compare November 29, 2022 17:50
@CohenArthur
Copy link
Member

Cherry-picked and fixed-up offline since I had already cleaned up the branch. Thank you @tschwinge :)

@tschwinge tschwinge deleted the tschwinge/restore-HOST_WIDE_INT-constexpr_ops_count branch December 1, 2022 07:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants