-
Notifications
You must be signed in to change notification settings - Fork 151
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
Initial support for module #509
Conversation
This is still on going.
Is segfaulting and
gives:
Looks like even simple cases are not working, I must have broken something during a rebase. Still progressing slowly :) |
Can you share the segv? I think your really close to getting this right, It will take me a while to review this and the segv backtrace might give me some hints |
Awesome work though thanks for bearing with this. As I said in the other PR, I think you can see that the structures your working with are not that "nice" yet. So I think we should start thinking about better ways to improve the API's and interfaces in the front-end. I could really do with help in that area. |
Sure I can share the segfault :) I'm in the process of rebasing/cleaning my working tree (hence the other small PRs). |
Beware that I have not yet looked into it as I am more focused on the "nearly working" case.
|
mappings->get_next_localdef_id (crate_num)); | ||
|
||
// should be lowered from module.get_vis() | ||
HIR::Visibility vis = HIR::Visibility::create_public (); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is a case to make a much simpler HIR::visibility, an enum might just work: https://doc.rust-lang.org/stable/nightly-rustc/rustc_hir/hir/enum.VisibilityKind.html
void visit (AST::ModuleBodied& module) override { | ||
auto path = prefix.append (CanonicalPath(module.get_name())); | ||
resolver->get_name_scope ().insert ( | ||
path, module.get_node_id (), module.get_locus (), false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the name resolution stuff could be extracted into a single commit a test case like:
mod foo {
struct A;
}
fn main() {}
Might work since the path expression stuff will not be invoked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, added in a dedicated test and checked it works with only the changes for name resolution applied.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks really good, I am going to check out your branch and try something since I think your 99% of the way there.
I think the only change needed would be to potentially extract this into 2-3 commits.
- name resolution
- HIR lowering
- Type resolution and finish PathExpression work + testcases
Nice job :)
I've pushed this commit onto a branch: c361bec you should be able to cherry-pick in and squash if you like. It allows for the compilation of: pub struct Bar {
pub f: i32,
}
mod foomod {
pub struct Foo {
pub prout: i32,
}
pub fn totoprout() -> i32 {
return 3i32;
}
}
pub fn toto() {}
fn test() -> Bar {
Bar { f: 23i32 }
}
fn main() {
let a;
a = foomod::Foo { prout: 3i32 };
toto();
let b;
b = foomod::totoprout();
} |
Ok ! I'll first add few tests and if everything is fine, I'll split the changes in 3. I'll squash your changes and mark you as co-author if that's ok with you ? |
0aacddc
to
13883b1
Compare
0cf5ecc
to
da90546
Compare
Haven't had much time for this :/
raises this error:
The error comes from the lookup method And for other simple case like:
GCC will ICE after getting |
cc18e0f
to
273b784
Compare
lookup = prefix.append (canonical_path); | ||
|
||
auto resolver = Resolver::get (); | ||
NodeId resolved_node = UNKNOWN_NODEID; | ||
|
||
// Lookup type in the following priority order: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think here, I need to do what's documented here : https://github.com/rust-lang/rust/blob/1f94abcda6884893d4723304102089198caa0839/compiler/rustc_resolve/src/lib.rs#L1722
When the type can't be found in the type NS, then we need to look for it in modules (and others element as documented). Is my understanding correct here? Currently, I'm trying to see if this would work by doing a global search in all Ribs (instead of targeting only the ones related to the module). It seems to work, but then a similar lookup is done so I need do apply the same workaround.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is interesting to read, I was thinking the fixup we added yesterday here:
which will do a scan toplevel with an empty path prefix a 2nd time which was causing an assertion inside insert_new_definition which was fixed with my PR earlier today should solve this.
I think I would like to see if you can revert this change to the type path name scope resolution and see if the fixes from yesterday and today still allow your test cases to pass.
Basically what happens is when the name resolver starts at the moment we endup with all the AST::Items canonical path's within the top-level scope so for example:
mod foo {
pub struct Foo {
pub f: i32,
}
pub fn foofn() -> i32 {
return 3i32;
}
}
struct Bar {b:i32}
The first scan toplevel gives us the paths:
[foo::Foo , foo:foofn, Bar]
But when we do the ResolveItems and we hit the Module we should do the resolve toplevel on each item then resolve item on each item so we end up with:
[Foo, foofn]
[foo::Foo , foo:foofn, Bar]
This means the relative paths of each item should be resolveable within the new rib that has been created.
The solution inside rustc here is kind of clever. The name resolver inside gccrs might need some thought because, one of the cases we don't funny support properly is the case of AST:::Items within blocks which can be forward declared and constantly having to do scan toplevel is getting a bit confusing.
Lets revert this change, see how it works and maintain a comment to the piece of source code from rustc which might provide a cleaner solution down the line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're right, removing the use of iterate_type_ribs
does not break anything now.
} | ||
return true; | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where the defId is looked up only in the type NS and where it should probably use the same search behavior (ie. search in modules if not found in type NS).
265e4a7
to
a3d7606
Compare
This was so close:
|
c0cbd69
to
1f2ce22
Compare
Nice work! The build is passing. |
I did some cleanup in tests to remove unnecessary dups. I've also added an execution test that is currently FAIL (but must be minor). |
f: -23i32, | ||
}; | ||
|
||
a.f - b.f |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should it not be a.f + b.f so that we return 0? I could be wrong but looking at this it looks like this to me:
23 - (-23)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
woops
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM to merge I think the commit message still references WIP.
Thanks for reviewing it even in draft state. Let me do a last proof reading, remove the draft state and reword first PR message :D |
Hope to have everything in order now. All commits should still be correct and should not cause failure in buildbot. |
bools and chars can be cast to any integer type, but not to floats or each other. Adjust the BoolCastRule and CharCastRule to allow these casts. Add a postive test "as_bool_char.rs" and negative test "bad_as_bool_char.rs" to check the correct casts are accepted and the illegal casts produce errors. Resolves: Rust-GCC#629
The gcc constant folding code uses the type_for_size langhook. Use the default implementation instead of crashing when the langhook is called. Add a new testcase "prims_struct_eq.rs" that creates trees that triggers the constant folding. Also remove the write_globals langhook which was removed when early debug was integrated into gcc.
Add module map and required methods to access it. refs Rust-GCC#432
Allow for getting a module's name. ref Rust-GCC#432
Implement required visitor methods for resolving names in modules. ref Rust-GCC#432 Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Lower AST::Module to HIR::ModuleBodied. Add HIR::ModuleBodied::get_items to access module's items. Fix tests that are already using module. ref Rust-GCC#432
Typechecking and backend for Modules. ref Rust-GCC#432 Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Add tests for Module support. ref Rust-GCC#432
bors r+ |
Build succeeded: |
Adds name resolution, HIR lowering and type checking. For modules
which should allow for initial multiple file parsing support.
Fixes #432