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

new .d file parser for stage1 compiler #2182

Merged
merged 2 commits into from
May 30, 2019
Merged

Conversation

mikdusan
Copy link
Member

@mikdusan mikdusan commented Apr 4, 2019

PR is not yet ready; placing here for review/feedback

@andrewrk
Copy link
Member

andrewrk commented Apr 4, 2019

I think it's time to make enough progress on #1964 that it can apply to this pull request. I'd rather solve this in userland than add an optional cmake thing. Plus we need a self hosted implementation anyway. Why solve it twice?

@andrewrk
Copy link
Member

andrewrk commented Apr 6, 2019

I will help you with this @mikdusan. Sorry, been real busy with the upcoming release!

@andrewrk
Copy link
Member

I haven't forgotten about this, will be working on a proof of concept soon that should clear up the path forward here.

@andrewrk
Copy link
Member

@mikdusan now that #2295 is merged, is it clear to you how you can write this .d file parser in userland, with userland tests, without having to modify the cmake build to add an optional unit tests target?

@@ -0,0 +1,32 @@
#ifndef ZIG_DEP_TOKENIZER_HPP
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All this stuff should be in userland.h.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. I'm holding off pushing to PR branch until I resolve a windows test failure.

@andrewrk andrewrk added the work in progress This pull request is not ready for review yet. label Apr 29, 2019
- wip for ziglang#2046
- clang .d output must be created with `clang -MV` switch
- implemented in Zig
- hybridized for zig stage0 and stage1
- zig test src-self-hosted/dep_tokenizer.zig
@andrewrk
Copy link
Member

@mikdusan let me know when this is ready for review

@mikdusan
Copy link
Member Author

ready for review

@andrewrk andrewrk removed the work in progress This pull request is not ready for review yet. label May 29, 2019
Copy link
Member

@andrewrk andrewrk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love how many tests there are. -55 +1,131 makes me a little nervous but I think all those tests are worth it.

};

// stage1 compiler support
var stage2_da = std.heap.DirectAllocator.init();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should use std.heap.c_allocator

var stage2_da = std.heap.DirectAllocator.init();

export fn stage2_DepTokenizer_init(input: [*]const u8, len: usize) stage2_DepTokenizer {
const t = stage2_da.allocator.create(Tokenizer) catch unreachable;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't invoke undefined behavior when out of memory occurs. You can panic - that's what stage1 currently does on OOM.

const otoken = self.handle.next() catch {
return stage2_DepNextResult{
.ent = 0,
.textz = (std.Buffer.init(&self.handle.arena.allocator, self.handle.error_text) catch unreachable).toSlice().ptr,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

catch unreachable is not justified here

Copy link
Member Author

@mikdusan mikdusan May 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please clarify; is that to mean instead use @Panic() or to mean coding around it and return an error with some kind of hardcoded text?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@panic is fine - that's what stage1 currently does on OOM. But catch unreachable invokes undefined behavior in release builds. We definitely don't want that since we can't guarantee that memory allocation will always succeed.

};
return stage2_DepNextResult{
.ent = @enumToInt(token.id) + u8(2),
.textz = (std.Buffer.init(&self.handle.arena.allocator, token.bytes) catch unreachable).toSlice().ptr,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

catch unreachable is not justified here

};

export const stage2_DepNextResult = extern struct {
// 0=error, 1=null, 2=token=target, 3=token=prereq
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not model this with an extern enum?

- use std.heap.c_allocator
- use @Panic instead of unreachable
- use extern enum for tokenizer result type
@mikdusan
Copy link
Member Author

mikdusan commented May 29, 2019

all the review requests are implemented. should i just hit the "resolve conversation" buttons?

@andrewrk
Copy link
Member

should i just hit the "resolve conversation" buttons?

either way, I'll have another look!

@andrewrk andrewrk merged commit 5954d52 into ziglang:master May 30, 2019
@andrewrk
Copy link
Member

Well I know that was a wild ride. Thanks for your hard work!

@mikdusan mikdusan deleted the issue.2046 branch May 31, 2019 18:32
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.

2 participants