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

Change the order of compilation passes, transformation is made lazy at code gen #8489

Merged
merged 57 commits into from
Oct 18, 2018

Conversation

cooldome
Copy link
Member

@cooldome cooldome commented Jul 31, 2018

Ready for the first review.

Original goal was to make getImpl return semantically checked AST but before transf pass.
Transformations can change regularly (examples: closure iterators and destructors) and user does not need to know about them. I have added getImplTransformed for backwards compatibility, in case someone needs it and requires time to migrate.

Performance numbers are actually pleasing:

Running koch boot -d:release second time (no invocation of c compiler).

Before:

  iteration 2: (116369 lines compiled; 8.146 sec total; 423.016MiB peakmem; Release Build)
  iteration 3: (116369 lines compiled; 7.532 sec total; 422.594MiB peakmem; Release Build)

After:

  iteration 2 :(116506 lines compiled; 7.563 sec total; 340.949MiB peakmem; Release Build)
  iteration 3: (116506 lines compiled; 7.104 sec total; 340.949MiB peakmem; Release Build)

I have noticed much bigger performance improvements for projects importing a lot but using a little. Quite common these days. Nim compiler is not one of them.

I also noticed startup time for nimsuggest improved.

P.S.
I have made also a good progress to reorder transf and lambdalifting passes, almost everything works
except closure iterators work. Changes in this PRs are required to make it happen anyway, it is easier
to split the work and unblock my project.

@cooldome cooldome changed the title [WIP] Change the order compilation passes, tranformation is made lazy at code gen [WIP] Change the order of compilation passes, transformation is made lazy at code gen Jul 31, 2018
@Araq
Copy link
Member

Araq commented Jul 31, 2018

Sure, but it already fails at bootstrapping and that's usually easy enough to test locally. ;-)

@cooldome
Copy link
Member Author

cooldome commented Sep 2, 2018

This now bootstrap's compiler.
I will look into remaining failures

@cooldome
Copy link
Member Author

cooldome commented Sep 11, 2018

checkConstructedType it is. Added a change

@cooldome
Copy link
Member Author

Could you please review this change? Is it the release that blocks the review, in this it can wait?

@Araq
Copy link
Member

Araq commented Sep 26, 2018

Could you please review this change?

I reviewed it, it's mostly fine but
a) will be merged after the release
b) has merge conflicts.

@cooldome
Copy link
Member Author

cooldome commented Oct 6, 2018

I have merged the conflicts, ready for review.

There is one problem, travis has failed with error that seems related to my change. But I can't replicate it on any of my machines. Need help to progress, can't travis give at least stack trace of the problem's location? Can somesome try on their linux desks and say where is the problem if any?

Much appreciated.

@Araq
Copy link
Member

Araq commented Oct 9, 2018

The failure is:

�[1m�[31mFAIL: �[36mnimprof.nim C�[0m
�[1m�[36mTest "lib/pure/nimprof.nim" in category "lib"�[0m
�[1m�[31mFailure: reNimcCrash�[0m
�[33mExpected:�[0m
�[1m
�[0m
�[33mGotten:�[0m
�[1mtype mismatch: got <proc (): bool{.gcsafe, locks: <unknown>.}> but expected 'proc (): bool{.gcsafe, locks: 0.}'
�[0m

@Araq
Copy link
Member

Araq commented Oct 14, 2018

Now fails with cannot open 'C:\projects\nim\tests\testament\tester.nim', please rebase I want to merge this asap now, my move optimizer also would be better with this refactoring. :-)

@cooldome
Copy link
Member Author

Ready for review.
I had to split tprevent_assign2 test into 2 tests, because transformation is now done at codegen and nim check does do codegen hence does not call destructor inject code.

I had to add silly locks: 0 to nimprof as I simply can't replicate this bug on any of my machines. It just works as expected for me so I can't progress on the better fix. If someone will post a better test case I will jump onto it.

@@ -30,6 +30,11 @@ proc checkConstructedType*(conf: ConfigRef; info: TLineInfo, typ: PType) =
localError(conf, info, "type 'var var' is not allowed")
elif computeSize(conf, t) == szIllegalRecursion:
localError(conf, info, "illegal recursion in type '" & typeToString(t) & "'")

t = typ.skipTypes({tyGenericInst})
if t.kind == tyArray and tfUncheckedArray in t.flags:
Copy link
Member

Choose a reason for hiding this comment

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

tyUncheckedArray here?

@@ -145,7 +145,7 @@ else:
else:
dec gTicker

proc hook(st: StackTrace) {.nimcall.} =
proc hook(st: StackTrace) {.nimcall locks: 0.} =
Copy link
Member

Choose a reason for hiding this comment

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

Minor: use a comma here.

@Araq
Copy link
Member

Araq commented Oct 18, 2018

I had to split tprevent_assign2 test into 2 tests, because transformation is now done at codegen and nim check does do codegen hence does not call destructor inject code.

That's not good but we'll find a better solution for this later. :-)

@Araq Araq merged commit eaca5be into nim-lang:devel Oct 18, 2018
This was referenced Oct 18, 2018
narimiran pushed a commit to narimiran/Nim that referenced this pull request Oct 31, 2018
…t code gen (nim-lang#8489)

* Ast no transformation
* Add getImplNoTransform to the macros module
* progress on delaying transf
* Fix methods tranformation
* Fix lazy lambdalifting
* fix create thread wrapper
* transform for lambda lifting
* improve getImplTransformed
* Fix destructor tests
* try to fix nimprof for linux
@@ -237,6 +237,10 @@ else: # bootstrapping substitute
else:
n.strValOld

when defined(nimSymImplTransform):
proc getImplTransformed*(symbol: NimNode): NimNode {.magic: "GetImplTransf", noSideEffect.}
## for a typed proc returns the AST after transformation pass
Copy link
Contributor

Choose a reason for hiding this comment

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

To this day, there is not a single test for this proc in the entire test suite.

Copy link
Member

Choose a reason for hiding this comment

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

fixing it in 14924

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants