aboutsummaryrefslogtreecommitdiff
path: root/gcc
AgeCommit message (Collapse)AuthorFilesLines
2021-08-06More rustspec.cc cleanupsMark Wielaard3-120/+32
rustspec.cc was based on the Go frontend gospec.cc. Remove special handling of math and pthread libraries and profiling option. Handle .rs files instead of .go files. Keep support for linking with (static) librust which is currently commented out. Add generic static-librust option to common.opt.
2021-08-05Support TypeBounds on Generic functionsPhilip Herron20-128/+845
TypeBounds are what make generics useful in Rust. They act in some ways similar to interfaces in modern Java. Fixes #583
2021-08-05Add missing mappings required for type resolutionPhilip Herron5-5/+100
Add Trait item mappings for trait resolving purposes. This allows us to lookup the trait with a trait item belongs to and vice versa.
2021-08-05Mark clone with constPhilip Herron2-49/+49
TyTy::Clone should be const to enforce compiler checks that we do not change the object.
2021-08-05Add type bound name resolutionPhilip Herron1-0/+44
Resolve the type-bound to the trait.
2021-08-05Fix clone on TypeBoundsPhilip Herron2-10/+31
Covariance was causing issues for the default clone on these classes. Such that the NodeId became messed up. This causes name resolution issues.
2021-08-05Add lowering for TypeBounds on Generic ParametersPhilip Herron9-75/+134
Preserve type-bounds into HIR for type resolution and code generation. This follows the same style of classes in the AST and might need some tweaks for where constraints.
2021-08-05parser: Implement parse_items() as separate public functionCohenArthur2-39/+23
2021-08-04Merge #605bors[bot]8-238/+200
605: Merge both module classes in one r=philberty a=CohenArthur This PR merges both kinds of Modules (formerly `ModuleBodied` and `ModuleNoBody`) as one class with an enum. This is the [behavior used by rustc](https://github.com/rust-lang/rust/blob/2939249f294dd54a9ce78a8ee1f2922a44e7fb7c/compiler/rustc_ast/src/ast.rs#L2274), where both variants are kept in an enum with one holding a vector of items. This change is important for multiple file parsing: An external mod (`mod foo; // defined in foo.rs or foo/mod.rs`) will see its items expanded during expansion, which occurs after parsing. This means that the previous directive will be "replaced" by `mod foo { <items> }` at the AST level. In order to achieve this, we need to be able to modify a previously parsed instance of an AST element. In rustc, this is done [here](https://github.com/rust-lang/rust/blob/2939249f294dd54a9ce78a8ee1f2922a44e7fb7c/compiler/rustc_expand/src/expand.rs#L1427), where `mod_kind` was previously `ModKind::Unloaded` and becomes `ModKind::Loaded(parsed_items, ...)`. Co-authored-by: CohenArthur <arthur.cohen@epita.fr>
2021-08-04Merge #606bors[bot]2-0/+46
606: Always check the result of expect_token while parsing r=dkm a=dkm From Mark Wielaard : https://gcc.gnu.org/pipermail/gcc-rust/2021-August/000111.html > When expect_token fails it produces an error and return a > nullptr. Make sure to always check the result of expect_token so we > don't use a nullptr token and crash. > > Resolves: https://github.com/Rust-GCC/gccrs/issues/603 Co-authored-by: Mark Wielaard <mark@klomp.org> Co-authored-by: Thomas Schwinge <thomas@codesourcery.com>
2021-08-04Add 'rust/compile/torture/identifier-missing-impl-1.rs' [#603]Thomas Schwinge1-0/+19
2021-08-04Always check the result of expect_token while parsingMark Wielaard1-0/+27
When expect_token fails it produces an error and return a nullptr. Make sure to always check the result of expect_token so we don't use a nullptr token and crash. Resolves: https://github.com/Rust-GCC/gccrs/issues/603
2021-08-03Remove split-stack from backendMark Wielaard3-60/+4
The backend was derived from the go backend which enables split stack support by default. This inserts a __morestack call at the start of each function. This is not needed for the rust backend. Remove the split stack support code from the rust backend and spec.
2021-08-03expand: Merge both implementations for both module typesCohenArthur1-16/+10
2021-08-03parser: Use Module constructor instead of both versionsCohenArthur1-8/+8
2021-08-03ast-visitors: Remove declaration for both module typesCohenArthur3-6/+3
2021-08-03module: Merge both as_string() implementationsCohenArthur1-27/+9
2021-08-03ast: Merge both Module kinds in one classCohenArthur2-181/+170
2021-08-02Merge #602bors[bot]4-19/+18
602: Add locus to TupleField and pass it and union variants to HIR class r=philberty a=dkm From Mark Wielaard : https://gcc.gnu.org/pipermail/gcc-rust/2021-August/000108.html > TupleField was missing a Location field and we dropped to locus when > lowering Union fields to HIR. Co-authored-by: Mark Wielaard <mark@klomp.org>
2021-08-02Handle 'UnsafeBlockExpr' in liveness analysisThomas Schwinge4-3/+30
We may then remove the '{ dg-options "-w" }' as discussed in <http://mid.mail-archive.com/YQciMeKNpCH+ZMsJ@wildebeest.org> and #601.
2021-08-02Add locus to TupleField and pass it and union variants to HIR classMark Wielaard4-19/+18
TupleField was missing a Location field and we dropped to locus when lowering Union fields to HIR.
2021-08-01union support for hir type checking and gcc backendMark Wielaard21-55/+529
Treat a union as a Struct variant like a tuple struct. Add an iterator and get_identifier functions to the AST Union class. Same for the HIR Union class, plus a get_generics_params method. Add a new ADTKind enum and adt_kind field to the ADTType to select the underlying abstract data type (struct struct, tuple struct or union, with enum as possible future variant). An union constructor can have only one field. Add an union_index field to StructExprStruct which is set during type checking in the TypeCheckStructExpr HIR StructExprStructFields visitor. For the Gcc_backend class rename fill_in_struct to fill_in_fields and use it from a new union_type method. Handle union_index in constructor_expression (so only one field is initialized).
2021-07-30Use correct lookahead to peek after 'while' token when parsing expression ↵Alexey Sakovets1-1/+1
with block (parse_expr_with_block).
2021-07-27Merge #598bors[bot]19-46/+513
598: Hello world r=philberty a=philberty ```rust extern "C" { fn puts(s: *const i8); } fn main() { unsafe { let a = "Hello World\0"; let b = a as *const str; let c = b as *const i8; puts(c); } } ``` Fixes #421 Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2021-07-27Add support for varadic extern "c" functions like printfPhilip Herron9-26/+144
Varadic functions are only allowed in extern functions as far as I know.
2021-07-27Adds support for compilation of extern "C" functions.Philip Herron3-0/+174
This adds extern block compilation support. It currently assumes the C abi and does not perform any name mangling. It does not support varadic arguments yet but its the initial support to get this working. Fixes #421
2021-07-27Fix assertion for trait item mappingsPhilip Herron1-1/+1
2021-07-27Add flags for FnType FNTYPE_IS_METHOD_FLAG FNTYPE_IS_EXTERN_FLAGPhilip Herron4-16/+125
2021-07-27Add mappings for external itemsPhilip Herron5-11/+75
2021-07-26Add resolution for extern function itemsPhilip Herron2-2/+4
2021-07-26Add name-resolution and HIR lowering for extern blocksPhilip Herron10-56/+345
This is the initial patch to do the ground work to support extern blocks. Type resolution and Generic output still needs to be done to actually support extern blocks. Addresses #421
2021-07-26Merge #596bors[bot]1-1/+2
596: Fix crash when extern function item has no return type r=philberty a=philberty Addresses #421 Fixes #595 Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2021-07-26Fix crash when extern function item has no return typePhilip Herron1-1/+2
Return types are optional in rust and extern fn items can be a ZST for the result. Addresses #421 Fixes #595
2021-07-26Initial TypeCast RulesPhilip Herron8-0/+1450
This gives us full explicit control for all casting. Just like other rules. More test cases are needed to close out type-casts by the the end of the traits milestone. Fixes #592
2021-07-26Add GENERIC support for TypeCastExpr to call fold_convert_locPhilip Herron1-0/+18
2021-07-26Lowering Cast Expressions from AST to HIR.Mark Wielaard4-4/+46
This allows for type resolution for TypeCasts.
2021-07-26Add name resolution for TypeCastExprPhilip Herron1-0/+6
This adds name checking and lookups in side tables for the expression and types involved in the compiler pipeline.
2021-07-25Merge #593bors[bot]1-0/+15
593: Support RangeFrom ([x..]) and RangeFromTo ([x..y]) in the parser r=philberty a=dkm Parsing the .. (DOT_DOT) operator to get a range had two issues. Trying to compile: let block = [1,2,3,4,5]; let _rf = &block[1..]; let _rt = &block[..3]; let _rft = &block[2..4]; range.rs:4:23: error: found unexpected token ‘]’ in null denotation 4 | let _rf = &block[1..]; | ^ range.rs:4:24: error: expecting ‘]’ but ‘;’ found 4 | let _rf = &block[1..]; | ^ Since .. can represent either a range from or a range from-to it can be followed by an expression or not. We do have a hack in our pratt-parser so that it is allowed to return a nullptr. But even in that case it will have swallowed the next token. Add another hack to the pratt-parser so that if the next token is one that cannot start an expression and the caller allows a nullptr return then don't skip the token and return immediately. After this patch we can parse the above range expressions, but we still don't handle them fully: range.rs:4:20: fatal error: Failed to lower expr: [1..] 4 | let _rf = &block[1..]; | ^ Ranges are actually syntactic sugar for std::ops::Range[From|To]. Co-authored-by: Mark Wielaard <mark@klomp.org>
2021-07-25Support RangeFrom ([x..]) and RangeFromTo ([x..y]) in the parserMark Wielaard1-0/+15
Parsing the .. (DOT_DOT) operator to get a range had two issues. Trying to compile: let block = [1,2,3,4,5]; let _rf = &block[1..]; let _rt = &block[..3]; let _rft = &block[2..4]; range.rs:4:23: error: found unexpected token ‘]’ in null denotation 4 | let _rf = &block[1..]; | ^ range.rs:4:24: error: expecting ‘]’ but ‘;’ found 4 | let _rf = &block[1..]; | ^ Since .. can represent either a range from or a range from-to it can be followed by an expression or not. We do have a hack in our pratt-parser so that it is allowed to return a nullptr. But even in that case it will have swallowed the next token. Add another hack to the pratt-parser so that if the next token is one that cannot start an expression and the caller allows a nullptr return then don't skip the token and return immediately. After this patch we can parse the above range expressions, but we still don't handle them fully: range.rs:4:20: fatal error: Failed to lower expr: [1..] 4 | let _rf = &block[1..]; | ^ Ranges are actually syntactic sugar for std::ops::Range[From|To].
2021-07-25Support byte and byte string literalsMark Wielaard6-1/+55
A byte literal is an u8 created as a ascii char or hex escape e.g. b'X'. A byte string literal is a string created from ascii or hex chars. bytes are represented as u8 and byte strings as str (with just ascii < 256 chars), but it should really be &'static [u8; n].
2021-07-23Merge #591bors[bot]1-7/+0
591: Remove error handling in parse_type_no_bounds for PLUS token r=philberty a=philberty parse_type_no_bounds tries to be helpful and greedily looks for a PLUS token after having parsed a typepath so it can produce an error. But that error breaks parsing expressions that contain "as" Cast Expressions like "a as usize + b as usize". Drop the explicit error on seeing a PLUS token and just return the type path parsed. Co-authored-by: Mark Wielaard <mark@klomp.org>
2021-07-23Remove error handling in parse_type_no_bounds for PLUS tokenMark Wielaard1-7/+0
parse_type_no_bounds tries to be helpful and greedily looks for a PLUS token after having parsed a typepath so it can produce an error. But that error breaks parsing expressions that contain "as" Cast Expressions like "a as usize + b as usize". Drop the explicit error on seeing a PLUS token and just return the type path parsed.
2021-07-23Better union support in the parserMark Wielaard1-8/+8
union is a weak keyword which means it isn't reserved and can be used as a generic identifier. When we see an identifier where a union could be declared we check whether the identifier is "union", but only when the next token is also an identifier. In parse_union we shouldn't skip the first identifier token, because it is already skipped when we call expect_token.
2021-07-22Merge #587 #589bors[bot]3-3/+35
587: Add testcase to cover parse errors in unsafe expressions r=philberty a=philberty Fixes #584 589: Support dereference of pointers r=philberty a=philberty Dereference expressions can also be pointer types not just references. Fixes #588 Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2021-07-22Merge #585 #586bors[bot]3-8/+76
585: Add iterate impl_blocks helper r=philberty a=philberty This helper will allow use to use mappings to iterate all impl blocks within the specified crate. 586: Add mappings for trait items r=philberty a=philberty Add mappings for trait items that can be used for query-based compilation and type checking Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2021-07-22Support dereference of pointersPhilip Herron2-3/+26
Dereference expressions can also be pointer types not just references. Fixes #588
2021-07-22Add testcase to cover parse errors in unsafe expressionsPhilip Herron1-0/+9
We had a bug in the parser with unsafe expression this adds a test case to cover the parser issue. Fixes #584
2021-07-22Add mappings for trait itemsPhilip Herron3-8/+58
2021-07-22unsafe blocks can be used in expressionsMark Wielaard2-5/+15
To use an unsafe block expression handle it in null_denotation for the pratt parser. Adjust parse_unsafe_block_expr to take a pratt_parse bool that defaults to false.
2021-07-21Add iterate impl_blocks helperPhilip Herron2-0/+18