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

Fix parsing and behaviour of ->foo.[] and other operators #7334

Merged
merged 3 commits into from
Mar 6, 2019

Conversation

asterite
Copy link
Member

Fixes #7319

Split into several commits, but basically:

  • parsing of ->foo.op where op was [], +, etc. didn't work, so that's fixed
  • after fixing that I tried taking a proc pointer where the variable was an integer and it crashed. The reasons are many: most of these methods (like +) are primitives and inlined by the compiler, and this didn't work when used as proc pointer. Another reason is that primitives are not passed by reference (pointer) and that's needed when the proc pointer closures over something (it's a pointer). Both of these things are fixed.
  • there's another commit that improves something by making it include Indexable

The code in this PR feels slightly hacky, but primitives are a special case in the language and so they usually need special code to handle them, so it's probably fine.

@asterite asterite added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:parser topic:compiler:semantic labels Jan 23, 2019
@asterite
Copy link
Member Author

@bcardiff It seems something overflows in the codegen debug code...

@bcardiff
Copy link
Member

@asterite yup debugging in CI since nightly also failed, it seems LibC::PthreadMutexT#@__align offset is 5998840007512307828 sometimes. Which triggers the overflow in even in u64. I'm trying to narrow it down...

@asterite
Copy link
Member Author

@bcardiff The plot thickens :-)

But I can't find anywhere where __align is used in the code... it's a bit strange.

@bcardiff
Copy link
Member

It's https://github.com/crystal-lang/crystal/blob/master/src/lib_c/x86_64-linux-gnu/c/sys/types.cr#L45-L49 that is required in the prelude , now I need to CI to fail again in my fork 👷 🛠 ...

@@ -366,8 +366,8 @@ class Crystal::CodeGenVisitor
end

private def codegen_raise_overflow
location = @call_location.not_nil!
set_current_debug_location(location) if @debug.line_numbers?
location = @call_location
Copy link
Member

Choose a reason for hiding this comment

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

Using #not_nil! is intentional here. Having debug location information is mandatory for when debug information is wanted to be emitted. Otherwise the program will fail with --debug but run ok, so it was to catch that missing information even when not using --debug.

Copy link
Member Author

Choose a reason for hiding this comment

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

That makes sense. However, with this PR this code can now be triggered when there's no call at all. For example:

a = 1
f = ->a.+(Int32) # this ends up generation a function that implements + and can raise overflow
f.call(Int32::MAX)

The ->a.+(Int32) can happen multiple times in code so there's no single "call" to use, unlike when you write a + 1. I don't know how to handle this...

Copy link
Member

Choose a reason for hiding this comment

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

Can't we reach the location of the proc literal when inlining the primitive?

Copy link
Member Author

Choose a reason for hiding this comment

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

We could. But that will not always work correctly because two proc literals that point to the same method will result in the same function being generated, so the location will point to the first literal, which is not always correct.

Maybe we need a reproducible test case to check for when this breaks.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I see. Well the story needs to continue with more support for debugging information then.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll see what I can do :-)

Copy link
Member

Choose a reason for hiding this comment

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

I mean in a future PR, but if you want to tackle that now I wont interfere :-P

Copy link
Member

@bcardiff bcardiff left a comment

Choose a reason for hiding this comment

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

A rebase to make (hopefully) the CI happy and GTG.

@sdogruyol
Copy link
Member

sdogruyol commented Feb 9, 2019

This seems good to 🚢 👍

@straight-shoota
Copy link
Member

@asterite Can you rebase this branch on master to make sure it's all still good?

@asterite
Copy link
Member Author

@straight-shoota Rebased and green.

@straight-shoota
Copy link
Member

Hm, should the last commit be squashed and then merge three indivdual commits?

@asterite
Copy link
Member Author

@straight-shoota Done

@straight-shoota straight-shoota added this to the 0.28.0 milestone Feb 15, 2019
@straight-shoota
Copy link
Member

Awesome! Thanks @asterite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:parser topic:compiler:semantic
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Can't create Proc from index operator
4 participants