aboutsummaryrefslogtreecommitdiff
path: root/gcc
AgeCommit message (Collapse)AuthorFilesLines
2021-09-10Merge #666bors[bot]7-73/+207
666: Super Traits Support r=philberty a=philberty This adds initial super traits support. Super traits are implemented by explicitly adding the super trait bound to the implicit Self type parameter on traits. This will improve as we enhance the type system to handle bounds and where constraints in general as they reuse all that same code path. Fixes #565 Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2021-09-10Merge #661 #663bors[bot]13-60/+163
661: Add support for choosing other builtin GCC calling conventions r=philberty a=philberty Add support for some other ABI options. I was able to test this with linking against some C code but these options like stdcall seem to be limited to 32 bit mode ```rust extern "stdcall" { pub fn test(a: i32) -> i32; } extern "C" { fn printf(s: *const i8, ...); } fn main() -> i32 { unsafe { let a = 3; let res = test(a); let a = "%i\n\0"; let b = a as *const str; let c = b as *const i8; printf(c, res); } 0 } ``` ```c __attribute__ ((stdcall)) int test(int x) { return x + 3; } ``` Compiling like this: ``` $ gccrs -g -O0 -m32 -c test.rs -o test.o $ gcc -g -O0 -m32 -c lib.c -o lib.o $ gcc -m32 -o test test.o lib.o ``` More testing will be required over time here but this was kind of fun to see that it worked. 663: Move module output test case from compile/ to execute/ r=philberty a=CohenArthur Fixes [this issue](https://github.com/Rust-GCC/gccrs/pull/639#discussion_r705922519) by `@tschwinge` I think this shows that we need to figure out a better way to keep test files and their modules, as pointed out by `@dkm` [here](https://github.com/Rust-GCC/gccrs/pull/639#issuecomment-905457557). Here, the modules/ directory is a straight up duplicate of the other one in compile/ which I'm not a fan of. I have no experience with having a separate .exp in the subdir but I can try and I think that it would be better. Maybe it can also be simpler if the regex to match *.rs files only looks inside one level of subdirectories? But I can think of a few places where this might be an issue Co-authored-by: Philip Herron <philip.herron@embecosm.com> Co-authored-by: CohenArthur <arthur.cohen@epita.fr>
2021-09-10Add initial support to specify Super TraitsPhilip Herron6-5/+129
Super Traits are simply TraitBounds upon the implict Self TypeParameter, such that a trait with a super trait bound almost ends up looking like this trait A : B { } -> trait A where Self: B { }
2021-09-10Make override context permissive when the TypeParam cannot resolvePhilip Herron1-1/+2
When we have generic code that calls other generic code the type system will have already setup the side tables for substituions and at this point the referenced generic code does not need to be substituted again.
2021-09-10Add getter for Trait TypeBoundsPhilip Herron1-0/+11
2021-09-10Fix formatting in HIR::TraitPhilip Herron1-67/+65
2021-09-10modules: Fix usage of path attributes and early returnsCohenArthur2-13/+34
path attributes were used wrongly in two ways: 1/ The attribute's value would still contain extra data such as an equal sign and whitespaces, which need to be discarded in order to fetch the proper file path. 2/ #[path]s are relative to the directory where the current source file is located. So we actually need to compute them later on down the line, once the including directory has been figured out. Another issue was that in the case that no candidates were found, or too many were founds, the function `process_file_path` would still return "successfully" despite erroring out. This causes the function to return early and thus not assign any string to the `module_file` member. We also have the ability to emit an error for the module's location, which looks better for the user, instead of using a new `Location()` like the session manager does (because it can't do otherwise)
2021-09-10modules: Move test case from compile/ to execute/CohenArthur2-1/+6
Co-authored-by: Thomas Schwinge <thomas@schwinge.name>
2021-09-09Add HIR lowering for Trait BoundsPhilip Herron1-0/+9
Super trait bounds need to be lowered to HIR.
2021-09-09Add name resolution for Trait boundsPhilip Herron1-0/+8
Trait bounds signify super-traits this adds name resolution for them.
2021-09-09type-bounds wipPhilip Herron1-0/+4
2021-09-09Add support for choosing stdcall fastcall and cdecl in the extern optionsPhilip Herron11-59/+157
GCC adds these as options to the function type as far as I can see, I was able to test this with linking against some C code. More testing is required here.
2021-09-09Merge #659bors[bot]14-319/+473
659: Initial intrinsics builtin block r=philberty a=philberty This is the initial piece to get the simple intrinsic's mapped over to GCC ones. The GCC wrapper contains a mapping system of rust names over to the builtin gcc names as far as I can tell gcc will allow for fallback onto linking against -lm. I think this will be a nice piece of work for new contributors, given the number of intrinsics Addresses #658 Co-authored-by: Philip Herron <philip.herron@embecosm.com> Co-authored-by: Thomas Schwinge <thomas@codesourcery.com>
2021-09-09Merge #639bors[bot]10-26/+103
639: External module expansion r=philberty a=CohenArthur Needs #638 This PR parses the file associated with an external module and allows their compilation. The two test cases are not currently passing, and the locations will be inexact (the filename for the parsed module will just show as random characters), so the PR is still a draft. Co-authored-by: CohenArthur <arthur.cohen@epita.fr>
2021-09-09module: Rename get_filename() -> process_file_path()CohenArthur2-4/+4
2021-09-09Turn 'rust/execute/torture/sinf32.rs', 'rust/execute/torture/sqrtf32.rs' ↵Thomas Schwinge3-44/+16
into 'rust/compile/torture/intrinsics-1.rs' Avoid proliferation of such execution tests: such builtins typically are mapped to regular function calls (which we already do have confidence that they work correctly), so it ought to suffice to just scan '-fdump-tree-original'.
2021-09-09Merge commit 'bca1debe33bf477df850db5979e4206627b3790b' into HEADThomas Schwinge8-107/+235
2021-09-09module: Add two test cases for external modulesCohenArthur6-14/+42
2021-09-09Support '-fdump-tree-original' before 'cgraph_node::finalize_function'Thomas Schwinge1-0/+1
2021-09-09Add builting block for simple intrinsicsPhilip Herron9-285/+414
We need a way to be able to turn intrinsic function prototypes and associated function calls into the GCC builtin. The GCC wrapper was reused from GO and the math builtin's don't seem to be correct, here I changed __builtin_sin to __builtin_sinf to get the float version. See builtins.def for the other builtins.
2021-09-08Keep track of the ABI in function typesPhilip Herron6-34/+87
We need to know the specified ABI in order to determine the linkage, it might be a plain old rust function, an extern C function or a compiler intrinsic and each of these needed to be handled differently.
2021-09-08Merge #656bors[bot]7-107/+234
656: Add mangling switch r=philberty a=CohenArthur Add option to choose mangling scheme. Closes #429 This PR splits the `Mangler` class in its own set of header and source and adds the base for v0 name mangling. You are now able to specify the mangling scheme to use using `-frust-mangling=<value>`. When inputting an invalid value, the compiler errors out using `unrecognized command-line option `-frust-mangling=<not_valid>`. Is there a better way to do this? Is there also a way to test this behaviour using dejagnu? Co-authored-by: CohenArthur <arthur.cohen@epita.fr>
2021-09-06module: Load items if module is unloaded and not marked for stripCohenArthur3-19/+31
2021-09-06module: Add load_items() functionCohenArthur2-0/+35
2021-09-06parser: Expose get_errors() functionCohenArthur1-1/+3
2021-09-06mangling: Use Enum(frust_mangling) for option instead of stringCohenArthur3-14/+17
Co-authored-by: Marc Poulhies <dkm@kataplop.net>
2021-09-06Add EnumItem HIR loweringMark Wielaard8-112/+406
Make HIT EnumItem class an Item, not VisItem like in the AST. At the HIR level EnumItems shouldn't have visibility anymore. Move struct_field_name_exists to rust-ast-lower.cc with the declaration in rust-ast-lower.h to make it reusable in the different visitors. Add a new ASTLoweringEnumItem that can be used from ASTLoweringItem and ASTLoweringStmt. It checks the EnumItems don't have visibility and that EnumItemStruct fields are not duplicated. Add a new testcase 'bad_pub_enumitems.rs' to check the no-visibility and no-duplicates properties hold.
2021-09-06Resolve Enums and EnumItemsMark Wielaard6-4/+254
Generate paths for Enum and EnumItem AST NodeIds and resolve the types of tuple and struct enum items. EnumItems always have the Enum as prefix. To make this work for ResolveStms (declaration statements are not given a canonical path) we add an enum_prefix to be used when resolving EnumItems. For ResolveType the tuple and struct fields get resolved using the Enum type scope. Add tests for toplevel or stmt enums with duplicate variant names. And adjust the tuple_enum_variants.rs testcase to expect unused name warnings.
2021-09-06Parse optional visibility for enum itemMark Wielaard3-38/+38
Syntactically enum items can have a visibility. The visibility has to be removed (through a cfg attribute or macro) before they get lowered. The semantic checking will be done when we implement lowering enum items. Make the AST EnumItem class a VisItem. This simplifies things a little for cloning items, handling outer attributes and will help when adding EnumItem (sub)classes to AST visitors (so they can be handled as Items). Also add a get_identifier method to Enum and EnumItem.
2021-09-05mangling: Add option to choose mangling versionCohenArthur5-15/+35
2021-09-05name_mangling: Add Mangler class with multiple versionsCohenArthur5-107/+211
2021-09-05Merge #655bors[bot]30-170/+915
655: Generic Qualified Paths r=philberty a=philberty This fixes how we handle associated types in relation to generic traits. Generic traits are interesting because, a TypePath usually resolves to a normal TyTy type which can be substituted using the mapper classes, but a trait is a definition of behaviour which is made up of types, constants or functions. In order to handle generic traits we must add substitution support to the associated types which are represented by projections see this commit for detail on the changes 0798add3d3c1bf4b20ecc1b4fa1047ba4ba19759 Also see https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/sty/struct.ProjectionTy.html Fixes #434 Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2021-09-05Support Generic Traits in qualified pathsPhilip Herron19-102/+375
This extends the ProjectionType which represents an implemented associated type with its own substitution mappings. The problem is a TypePath to a trait does not represent a single TyTy primitive type, the type system handles generics in an interesting way. Take for instance the case of a generic impl block: impl<T> Foo<T> { fn Bar<Y>(self, a:T, b:Y) {} } The compiler treats an impl block as the parent so that all items inherit from this, which is why rustc calls these inherent-impl-blocks. So in order to handle generic arguments we need to "bind" them, and in rust only some types actually support generic argument binding, at the moment for gccrs it is, ADTTypes, FnTypes and Projections. Going back to the example the TyTy for this function turns into: fn Bar<T,Y>(Foo<T>, T, Y) So when it comes to the generic traits its a similar process but the difference is that traits contain associated types, these must be able to bind the generic arguments such that we can substitute any covariant types fully. But there is a layer of complexity and indirection here consider the following example: trait Foo<T> { type A; fn test(a: T, b: Self::A) -> (T, Self::A) { (a, b) } } struct Bar<T>(T); impl<T> Foo<T> for Bar<T> { type A = T; } When we deal with a trait with an optional trait function that uses the associated types what actually happens here is that the type A in this trait context is considered just a simple PlaceHolder which gets setup within relation to its relevant impl block, so when we setup the associated types it turns into: Placeholder(A) -> Projection<T>(Bar<T> as Foo<T>) -> T So it forms an recursive chain that must be substituted in relation to what the paticular query is.
2021-09-05Fix name resolution for generic trait referencesPhilip Herron1-14/+11
The canonical path for a traits does not include the generic arguments but they must be resolved. This ensures we can actually resolve a generic trait reference to the correct trait.
2021-09-05Add helpers to as clause of QualifiedPaths to get the generic argsPhilip Herron1-0/+21
When we resolve a TypePath we expect this to resolve to a TyTy and to substitute arguments accordingly. Qualified paths contain a trait reference which can contain generic arguments, the problem here is that traits are not a TyTy type since traits define behaviour not types. In order to actually apply the substitutions in a future commit we must be able to access these arguments in a sensible way first.
2021-09-05Ensure the implicit Self is first in the generic argumentsPhilip Herron1-1/+10
Traits implement self by creating an implicit Self TypeParam but when we need to support generic arguments we must ensure Self is substituted first so that the reset of the arguments are handled as we expect.
2021-09-01Remove Enumeration Expression, EnumExpr, classesMark Wielaard16-954/+0
An Enumeration Expression is just like a Struct Expression. Old versions of the Rust Reference described them separately. But since they are syntactically exactly like a Struct Expression they are never actually parsed. A Struct Expression can also be used to initialize enums (and unions). Remove the AST and HIR classes EnumExprField, EnumExprFieldIdentifier, EnumExprFieldWithVal, EnumExprFieldIdentifierValue, EnumExprFieldIndexValue, EnumExprStruct, EnumExprTuple, EnumExprFieldless and EnumVariantExpr.
2021-08-31StructExprUnit doesn't really existMark Wielaard16-105/+0
A StructExprUnit is parsed as an IdentifierExpr. An IdentifierExpr, which is what we call a single segment PathInExpression. After type checking, when generating gcc generic trees, if the IdentifierExpr is a type reference (which must be a unit struct), then a unit expression is generated. Remove the AST and HIR StructExprUnit classes which are never used.
2021-08-31StructExprTuple doesn't really existMark Wielaard16-287/+0
A StructExprTuple is parsed as a CallExpr. Both (can) start with a PathInExpression followed by zero or more Expressions between brackets. Only, after type checking, when actually generating gcc generic trees is a distinction made between a function call or tuple constructor. Remove the AST and HIR StructExprTuple classes which are never used.
2021-08-31Add type resolution for qualified-type-pathsPhilip Herron5-66/+284
Qualified type paths are similar to qualified path expressions, in that they must resolve the projection of the trait onto a type to receive the correct associated type information.
2021-08-31Placeholder is not a unit-typePhilip Herron1-1/+5
Placeholder types are containers for associated types, the code-generation pass has a check for is_unit on return types for functions so we can inject void_type_node. This was a false positive for placeholders, placeholders must resolve to check what their concrete implementation type actually is for this type of query.
2021-08-31Add HIR lowering for QualifiedPathInTypePhilip Herron3-1/+101
2021-08-31Add name resolution for QualifiedPathInTypePhilip Herron2-2/+116
Qualified path types allow for TypePaths qualified with a paticular associated impl and type;
2021-08-31Add iterate helper for TypePathsPhilip Herron1-0/+9
2021-08-31Merge #651bors[bot]2-8/+13
651: Qualified paths have a mandatory initial segment r=philberty a=philberty see https://doc.rust-lang.org/reference/paths.html#qualified-paths The initial segment is mandatory this changes the AST to reflect this it simplifies error handling down the line. Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2021-08-29Remove GetLocusFromImplItem visitorMark Wielaard1-43/+2
Simply use get_locus () on the ImplItem. Both the generics7.rs and generics8.rs testcase still pass.
2021-08-29Replace HIRItem::get_impl_locus with HirItem::get_locusMark Wielaard2-7/+1
HIRItem::get_impl_locus wasn't used and all subclasses already implement get_locus.
2021-08-29Use location when lowering TupleFieldMark Wielaard1-4/+2
2021-08-27Qualified paths have a mandatory initial segmentPhilip Herron2-8/+13
Qualified path in type's initial segment is mandatory (+) any other segments are optional after the fact. see https://doc.rust-lang.org/reference/paths.html#qualified-paths This change makes the AST have a mandatory field for the initial segment the segment list now only contains the optional remaining segments.
2021-08-27Stop shadowing of hir mappings with substitution mappingsPhilip Herron1-9/+14
Name shadowing in C++ is annoying, it can cause subtle errors like here, the mappings which are substitition mappings, for example from an impl block, impl<X,Y> Foo(X), the type resolver here looks for any unconstrained type parameters by passing the relative mappings which can be null. Since the util mappings class shadowed this we never actually got this hidden nullptr segv. For QualifiedTypes we need to resolve the path similar to path expressions and we will need to be able to access the shadowed util hir mappings class.