aboutsummaryrefslogtreecommitdiff
path: root/gcc
AgeCommit message (Collapse)AuthorFilesLines
2021-07-10The type system has a function can_eq this adds a with_errors flagPhilip Herron7-132/+440
With the type system we can check for equality explicitly which is useful. When it comes to TypeParameters or Placeholders can_eq allows for: fn bla<T>() -> <T> fn bla() -> i32 The type parameter can be subsituted which means the generic function can equal the subsituted one if it was given the right substituion arguments. This can emit errors such as expected [X] got [Y] or we might want to have silent errors so we can filter impl items such as the impl item overlapping pass
2021-07-10Introduce placeholder typePhilip Herron11-3/+126
This is used in Traits with associated types that can contain TypeBounds but provides an ability to reuse out type system to check that trait items are compatible with their respective ImplBlock Items
2021-07-10Refactor CanonicalPath so we can iterate the segmentsPhilip Herron9-52/+102
This adds the associated NodeId into each CanonicalPath segment which references their respective TypePathSegment or PathExprSegment.
2021-07-10Add toplevel resolution for type aliasPhilip Herron2-3/+30
TypeAliases can be contained within ImplBlocks and need their full canonical path to be resolved.
2021-07-10ImplBlocks can contain TypeAlias'sPhilip Herron1-0/+32
This lowers TypeAliases into ImplItem for HIR::ImplBlocks.
2021-07-10Assert that impl items are non null when translated to hirPhilip Herron1-0/+2
When we translate AST::InherentImplItems or AST::TraitImplItem's these get lowered into a generic ImplBlock with ImplItems these must be non null. TraitImpl blocks can contains associated types but normal InherentImpl's do not this unifies the path to turn both into an HIR::ImplBlock
2021-07-09replace all variable name ret to okThomas Young1-8/+8
2021-07-09revert visit_path_segment return type to boolThomas Young2-18/+16
2021-07-07rust_assert to check return valueThomas Young1-16/+23
2021-07-07use rust_assert in dead code pass instead of rust_error_atThomas Young2-40/+21
2021-07-06Merge #548bors[bot]2-7/+26
548: Fix bad naming of primitive types such as u64 which ended up as usize r=philberty a=philberty In #547 it was found that u64's ended up as usize in gimple which confuses debugging sessions. This take the original implementation of named type from gccgo showing it was the TYPE_NAME tree getting confused. Addresses #547 Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2021-07-06make the warning msg be searched easierThomas Young1-8/+8
2021-07-05Remove has_utf8bom flag from AST and HIR Crate classesMark Wielaard6-34/+9
The lexer deals with the UTF-8 BOM and the parser cannot detect whether there is or isn't a BOM at the start of a file. The flag isn't relevant or useful in the AST and HIR Crate classes.
2021-07-05Handle UTF-8 BOM in lexerMark Wielaard5-0/+20
The very first thing in a rust source file might be the optional UTF-8 BOM. This is the 3 bytes 0xEF 0xBB 0xBF. They can simply be skipped, they just mark the file as UTF-8. Add some testcases to show we now handle such files.
2021-07-05Merge #546bors[bot]15-54/+107
546: shebang handling r=philberty a=dkm Mark Wielaard: > Shebang handling, the first line starting with #! was not done fully > correct and it isn't necessary to keep track of the shebang line in > the AST or HIR Crate classes. > > Because an inner attribute also starts with #! the first line isn't > regarded as a shebang line if the #! is followed by (optional) > whitespace and comments and a [. In that case the #! is seen as the > start of an inner attribute. > > I added various testcases that hopefully show the funny things you can > get when the first line starts with #!. Co-authored-by: Mark Wielaard <mark@klomp.org>
2021-07-05Fix bad naming of primitive types such as u64 which ended up as usizePhilip Herron2-7/+26
There was a bad port over of the gccgo named_type implementation to try be simple but this ended up overwriting the names of other primitive types leading to confusing gimple debug sessions. In debugging this I have added a set of ids which are the builtin primitive types ids and we assert that this range of ids will never be overriten by other types during compilation.
2021-07-04Remove has_shebang flag from AST and HIR Crate classesMark Wielaard6-35/+18
The lexer deals with the shebang and the parser cannot detect whether there is or isn't a shebang line. The flag isn't relevant or useful in the AST and HIR Crate classes.
2021-07-04Handle shebang line, plus any whitespace and comment skipping in lexerMark Wielaard9-19/+89
The lexer tried to handle the shebang line but used loc directly, instead of the current_column. And it assumed a '/' should immediately follow the "#!". But if the "#!" is followed by whitespace and/or comments and a '[' character, then the first line isn't see as a shebang line (even if the kernel or shell would) but as the start of an inner attribute. Add various tests for when the first line starting with "#!" is seen as a shebang line (and should be skipped). And some tests there is a '[' character following some whitespace and/or comments and the "#!" is seen as part of an inner attribute.
2021-07-04mark live symbol support type alias and tuple structThomas Young8-8/+40
2021-07-03mark live symbol in if expr family except if let exprThomas Young4-0/+78
2021-07-02detect unused struct field.Thomas Young25-63/+207
2021-07-02make struct field carry the location infoThomas Young4-13/+15
2021-07-01Remove HIR::Method this finishes the desugaring of methods into HIRPhilip Herron18-743/+86
Methods are just functions with a self param. This simplifies typecheck and GENERIC generation code. Addresses #470 #473
2021-06-30Implicit Self on TraitsPhilip Herron8-68/+263
Self is actually an implicit inherited type parameter on Trait declarations. This adds this akin to impl blocks, and substitutes the actual impl self type into the trait-impl item for type checking. Fixes #473
2021-06-30exit immediately when the type checker find a errorThomas Young1-0/+3
2021-06-30Merge #536bors[bot]4-22/+10
536: Revert change to ScanUnused to not scan Types r=philberty a=philberty The scan dead-code pass will take over this role, but let's keep both running for a while and then we can update ScanUnused to only scan for unused labels and variables. Dead Code pass is important as it is not possible to rely on name resolution to know what symbols are used or not used. Further resolution occurs during type resolution and the dead code pass runs after type resolution. Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2021-06-30Remove unused have_more_segments from TypeCheckExpr::resolve_root_pathMark Wielaard1-1/+0
It isn't necessary to know whether there are more segments while iteration through the expression segments.
2021-06-29Remove unused default_ty_param from TypeResolveGenericParam::visitMark Wielaard1-4/+2
The default_ty_param was set, but not used. We do need to call TypeCheckType::Resolve on the default param, but don't need the result.
2021-06-29Revert change to ScanUnused to not scan TypesPhilip Herron4-22/+10
The scan dead-code pass will take over this role, but lets keep both running for a while and then we can update ScanUnused to only scan for unused labels and variables. Its not possible to rely on name resolution to know what symbols are used or not used. Further resolution occurs during type resolution and the dead code pass runs after type resolution.
2021-06-29Merge #535bors[bot]1-0/+2
535: Suppress warning in rust-ast-lower-type.h ASTLowerGenericParam.visit. r=philberty a=dkm Translating the AST LifetimeType to the HIR LifetimeType causes a warning: warning: ‘ltt’ may be used uninitialized Add a default clause to the switch statement calling gcc_unreachable. This will suppress the warning and make sure that if the AST lifetime type is invalid or a new unknown type we immediately know when lowering the AST. Co-authored-by: Mark Wielaard <mark@klomp.org>
2021-06-29Marking live symbol for struct construction.Thomas Young7-38/+88
Comment iterate_type_ribs of UnusedScan in order to resolve multiple struct unused report.
2021-06-28Suppress warning in rust-ast-lower-type.h ASTLowerGenericParam.visit.Mark Wielaard1-0/+2
Translating the AST LifetimeType to the HIR LifetimeType causes a warning: warning: ‘ltt’ may be used uninitialized Add a default clause to the switch statement calling gcc_unreachable. This will suppress the warning and make sure that if the AST lifetime type is invalid or a new unknown type we immediately know when lowering the AST.
2021-06-27Merge #530bors[bot]2-1/+4
530: Fix inner attribute parsing r=philberty a=dkm parse_inner_attribute tried to skip the right square token twice. This caused odd error messages in case there were multiple inner attributes. This bug masked another bug in parse_attr_input where when the (optional) attr input was an assignment to a literal the parser failed to skip the literal. The existing top_attr.rs testcase relied on the two bugs cancelling each other out. Add a new testcase inner_attributes.rs for the first bug. Resolves: https://github.com/Rust-GCC/gccrs/issues/510 Co-authored-by: Mark Wielaard <mark@klomp.org>
2021-06-27Merge #502bors[bot]10-19/+653
502: Trait Obligations building block r=philberty a=philberty This is a building block for actually enforcing the obligations of a trait. It includes a query-based lookup of the trait to avoid reloading it so we only do the hard work once. Then provides the enforcement for basic functions. Constants, methods and associated types are still WIP. Addresses: #440 Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2021-06-27Initial Trait Obligations to enforce trait-impl-items are part of the traitPhilip Herron10-19/+653
When we create an impl for a trait each item must be part of the trait, these are the obligations of the trait. This means we know this type definetly implements the trait. This only supports functions so far. Methods, constants and associated types are still in progress. This is an isolated building block that can be merged without any regression so far. Addresses #440
2021-06-27Fix inner attribute parsingMark Wielaard2-1/+4
parse_inner_attribute tried to skip the right square token twice. This caused odd error messages in case there were multiple inner attributes. This bug masked another bug in parse_attr_input where when the (optional) attr input was an assignment to a literal the parser failed to skip the literal. The existing top_attr.rs testcase relied on the two bugs cancelling each other out. Add a new testcase inner_attributes.rs for the first bug. Resolves: https://github.com/Rust-GCC/gccrs/issues/510
2021-06-27mark live symbol in for expr without test caseThomas Young2-0/+8
2021-06-27mark live symbol in whilelet expr without test caseThomas Young2-0/+8
2021-06-27mark live symbol in while exprThomas Young2-0/+16
2021-06-27mark live symbol in return exprThomas Young2-0/+11
2021-06-27mark live symbol in break exprThomas Young2-0/+21
2021-06-26Merge #527bors[bot]7-13/+139
527: Reject non-pure decimal tuple indexes. r=philberty a=dkm Tuple indexes should be pure decimal integer literals. But the parser just sees an integer literal. Fix this by introducing a new type hint CORETYPE_PURE_DECIMAL. This doesn't conflict with any existing type hints since a pure decimal doesn't have a type suffix. Introduce a new method is_pure_decimal that the parser can use in parse_tuple_index_expr. get_type_hint will return CORETYPE_UNKNOWN for pure decimals. parse_decimal_int_or_float will check whether there are no execissive leading zeros. parse_in_decimal checks the literal doesn't contain any underscores. Add two testcases. bad_tuple_index.rs with all variants of integer literals which aren't pure decimals. And tuple_index.rs with various correct tuple indexes. Resolves: https://github.com/Rust-GCC/gccrs/issues/511 Co-authored-by: Mark Wielaard <mark@klomp.org>
2021-06-26mark live symbol in tuple exprThomas Young3-4/+27
2021-06-26mark live symbol in array exprThomas Young2-0/+21
2021-06-26mark live symbol in groupedExprThomas Young2-0/+11
2021-06-26mark live symbol in type cast exprThomas Young1-2/+7
2021-06-26mark live symbol in lazyBooleanExprThomas Young2-0/+20
2021-06-25Reject non-pure decimal tuple indexes.Mark Wielaard7-13/+139
Tuple indexes should be pure decimal integer literals. But the parser just sees an integer literal. Fix this by introducing a new type hint CORETYPE_PURE_DECIMAL. This doesn't conflict with any existing type hints since a pure decimal doesn't have a type suffix. Introduce a new method is_pure_decimal that the parser can use in parse_tuple_index_expr. get_type_hint will return CORETYPE_UNKNOWN for pure decimals. parse_decimal_int_or_float will check whether there are no execissive leading zeros. parse_in_decimal checks the literal doesn't contain any underscores. Add two testcases. bad_tuple_index.rs with all variants of integer literals which aren't pure decimals. And tuple_index.rs with various correct tuple indexes. Resolves: https://github.com/Rust-GCC/gccrs/issues/511
2021-06-25Add support for empty struct initilizerPhilip Herron5-0/+60
Rust supports unit struct initilization such as S{} this takes this tree and resolves it fully. This should really be all desugared via HIR but that is in progress in another PR.
2021-06-25Add support for unit-structPhilip Herron3-12/+74
IdentifierExpr's can reference types like a unit-struct, referencing other structs actually form a function item type which is not supported yet.